diff --git a/game.cpp b/game.cpp index 25183bc..b4d8703 100644 --- a/game.cpp +++ b/game.cpp @@ -49,7 +49,6 @@ namespace battleship{ for(int i = 0; i < getCpuPlayers().size(); i++) { string plStr = "game.cpuPlayers[" + to_string(i + 1) + "]"; SOL_LUA_VIEW.script("executeBtNode(" + plStr + ", " + plStr + ".behaviour)"); - SOL_LUA_VIEW.collect_garbage(); } int numPlayersWithUnits = 0; diff --git a/unit.cpp b/unit.cpp index 70e4537..16452c9 100755 --- a/unit.cpp +++ b/unit.cpp @@ -515,22 +515,8 @@ namespace battleship{ //TODO select only the closest cells based on unit size void Unit::placeAt(Vector3 p){ - Map *map = Map::getSingleton(); - - if(alignToSurface){ - vector res = map->raycastTerrain(Vector3(p.x, 100, p.z), -Vector3::VEC_J, true); - - if(res.empty() || res[0].mesh->getNode() != map->getNodeParent()->getChild(0)) - model->lookAt(Vector3(dirVec.x, 0, dirVec.z).norm(), Vector3::VEC_J); - else if(res[0].mesh->getNode() == map->getNodeParent()->getChild(0)){ - float angle = upVec.getAngleBetween(res[0].norm); - - //if(angle > 0) - model->lookAt(leftVec.cross(res[0].norm), res[0].norm); - } - } - ActiveGameState *activeState = (ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE); + Map *map = Map::getSingleton(); //check twice in case the unit is warped over a long distance if(activeState) map->blockCells(this); diff --git a/unit.h b/unit.h index 0bcf425..d1a58ac 100755 --- a/unit.h +++ b/unit.h @@ -148,9 +148,10 @@ namespace battleship{ sf::SoundBuffer *selectionSfxBuffer; sf::Sound *selectionSfx = nullptr; vb01::Node *losLightNode = nullptr; - bool vehicle, currOrderStarted = false, alignToSurface = false; + bool vehicle, currOrderStarted = false; Condition condition = Condition::ABLE; protected: + bool alignToSurface = false; UnitType type; UnitClass unitClass; std::vector orders; diff --git a/vehicle.cpp b/vehicle.cpp index 4956e6d..7be0c21 100644 --- a/vehicle.cpp +++ b/vehicle.cpp @@ -148,12 +148,16 @@ namespace battleship{ // y = ax + b float a = hypVec.z / hypVec.x; float b = pos.z - a * pos.x; + Vector3 c1 = terrQuad->getSubquadCorner(sqIds[0], sqIds[1], numVertDiv, numHorDiv, true, false); //top left + Vector3 c2 = terrQuad->getSubquadCorner(sqIds[0], sqIds[1], numVertDiv, numHorDiv, true, true); //top right + Vector3 c3 = terrQuad->getSubquadCorner(sqIds[0], sqIds[1], numVertDiv, numHorDiv, false, false); //bottom left + Vector3 c4 = terrQuad->getSubquadCorner(sqIds[0], sqIds[1], numVertDiv, numHorDiv, false, true); //bottom right while(!(sqIds[0] == (int)sqIdsEndVec.x && sqIds[1] == (int)sqIdsEndVec.y)){ - Vector3 c1 = terrQuad->getSubquadCorner(sqIds[0], sqIds[1], numVertDiv, numHorDiv, true, false); //top left - Vector3 c2 = terrQuad->getSubquadCorner(sqIds[0], sqIds[1], numVertDiv, numHorDiv, true, true); //top right - Vector3 c3 = terrQuad->getSubquadCorner(sqIds[0], sqIds[1], numVertDiv, numHorDiv, false, false); //bottom left - Vector3 c4 = terrQuad->getSubquadCorner(sqIds[0], sqIds[1], numVertDiv, numHorDiv, false, true); //bottom right + c1 = terrQuad->getSubquadCorner(sqIds[0], sqIds[1], numVertDiv, numHorDiv, true, false); //top left + c2 = terrQuad->getSubquadCorner(sqIds[0], sqIds[1], numVertDiv, numHorDiv, true, true); //top right + c3 = terrQuad->getSubquadCorner(sqIds[0], sqIds[1], numVertDiv, numHorDiv, false, false); //bottom left + c4 = terrQuad->getSubquadCorner(sqIds[0], sqIds[1], numVertDiv, numHorDiv, false, true); //bottom right float minX = c1.x, maxX = c2.x, minY = c1.z, maxY = c3.z; bool bottom = (hypVec.z > 0), left = (hypVec.x < 0); @@ -208,6 +212,12 @@ namespace battleship{ placeAt(endPos); + if(alignToSurface){ + Vector3 normal = (c3 - c1).norm().cross((c2 - c1).norm()); + float angle = upVec.getAngleBetween(normal); + model->lookAt(leftVec.cross(normal), normal); + } + if(fabs(pathPoints[0].x - pos.x) <= destOffset && fabs(pathPoints[0].z - pos.z) <= destOffset) arrivedAtPathpoint(false); }