mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
corrected unit garrisoning and ejecting
This commit is contained in:
@@ -302,9 +302,26 @@ namespace battleship{
|
||||
}
|
||||
|
||||
void Unit::eject(Order order){
|
||||
Map *map = Map::getSingleton();
|
||||
int currCellId = map->getCellId(pos);
|
||||
vector<Map::Cell> &cells = map->getCells();
|
||||
int adjWaterCellId = -1, adjLandCellId = -1;
|
||||
|
||||
for(Map::Edge edge : cells[currCellId].edges){
|
||||
if(adjLandCellId == -1 && cells[edge.destCellId].type == Map::Cell::LAND)
|
||||
adjLandCellId = edge.destCellId;
|
||||
if(adjWaterCellId == -1 && cells[edge.destCellId].type == Map::Cell::WATER)
|
||||
adjWaterCellId = edge.destCellId;
|
||||
}
|
||||
|
||||
if(garrisonSlots.size() > 0){
|
||||
for(Order::Target targ : order.targets)
|
||||
((Vehicle*)targ.unit)->exitGarrisonable();
|
||||
for(Order::Target targ : order.targets){
|
||||
bool exitToLandCell = (targ.unit->getType() == UnitType::LAND && adjLandCellId != -1);
|
||||
bool exitToWaterCell = ((targ.unit->getType() == UnitType::SEA_LEVEL || targ.unit->getType() == UnitType::UNDERWATER) && adjWaterCellId != -1);
|
||||
|
||||
if(exitToLandCell || exitToWaterCell)
|
||||
((Vehicle*)targ.unit)->exitGarrisonable(cells[exitToLandCell ? adjLandCellId : adjWaterCellId].pos);
|
||||
}
|
||||
|
||||
removeOrder(0);
|
||||
}
|
||||
|
||||
+8
-5
@@ -165,8 +165,8 @@ namespace battleship{
|
||||
removeOrder(0);
|
||||
}
|
||||
|
||||
void Vehicle::exitGarrisonable(){
|
||||
placeAt(garrisonable->getPos());
|
||||
void Vehicle::exitGarrisonable(Vector3 exitPos){
|
||||
placeAt(exitPos);
|
||||
garrisonable->updateGarrison(this, false);
|
||||
garrisonable = nullptr;
|
||||
}
|
||||
@@ -196,7 +196,7 @@ namespace battleship{
|
||||
|
||||
void Vehicle::garrison(Order order){
|
||||
Unit *targUnit = order.targets[0].unit;
|
||||
float distToGarrisonable = pos.getDistanceFrom(targUnit->getPos()), garrisonDist = .5 * Map::getSingleton()->getCellSize().x;
|
||||
float distToGarrisonable = pos.getDistanceFrom(targUnit->getPos()), garrisonDist = Map::getSingleton()->getCellSize().x;
|
||||
|
||||
if(distToGarrisonable > garrisonDist)
|
||||
navigateToTarget(garrisonDist);
|
||||
@@ -244,13 +244,16 @@ namespace battleship{
|
||||
int dest = map->getCellId(destPos);
|
||||
vector<int> path = pathfinder->findPath(cells, source, dest, (int)type);
|
||||
|
||||
for(int i = 0; i < path.size(); i++)
|
||||
if((ship && cells[path[i]].type != Map::Cell::WATER) || (type == UnitType::LAND && cells[path[i]].type != Map::Cell::LAND)){
|
||||
for(int i = 0; i < path.size(); i++){
|
||||
if((ship && cells[path[i]].type != Map::Cell::WATER) || (order.type != Order::TYPE::GARRISON && type == UnitType::LAND && cells[path[i]].type != Map::Cell::LAND)){
|
||||
path = vector<int>(path.begin(), path.begin() + i);
|
||||
order.targets[0].unit = nullptr;
|
||||
order.targets[0].pos = cells[path[i - 1]].pos;
|
||||
break;
|
||||
}
|
||||
else if(order.type == Order::TYPE::GARRISON && type == UnitType::LAND && cells[path[i]].type != Map::Cell::LAND && path.size() - 1 != i)
|
||||
return;
|
||||
}
|
||||
|
||||
for(int p : path)
|
||||
addPathpoint(cells[p].pos);
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace battleship{
|
||||
~Vehicle();
|
||||
virtual void update();
|
||||
void move(Order);
|
||||
void exitGarrisonable();
|
||||
void exitGarrisonable(vb01::Vector3);
|
||||
inline Unit* getGarrisonable(){return garrisonable;}
|
||||
inline int getGarrisonCategory(){return garrisonCategory;}
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user