garrisoning bugfixes

This commit is contained in:
devZoGok
2023-11-11 12:16:38 +02:00
parent d996ffff3d
commit be8c6f534f
4 changed files with 33 additions and 14 deletions
+13 -1
View File
@@ -303,6 +303,15 @@ namespace battleship{
for (int i = 0; i < mainPlayer->getNumSelectedUnits(); ++i) {
Unit *u = mainPlayer->getSelectedUnit(i);
bool targetingSelf = false;
for(Order::Target &targ : targets)
if(targ.unit && targ.unit == u){
targetingSelf = true;
break;
}
if(targetingSelf) continue;
lineRenderer->addLine(u->getPos(), targets[i].pos, color);
vector<LineRenderer::Line> lines = lineRenderer->getLines();
@@ -390,8 +399,11 @@ namespace battleship{
}
else{
bool canSelect = canSelectHoveredOnGameObj();
bool ownGameObj = (gameObjHoveredOn && gameObjHoveredOn->getPlayer()->getSide() == mainPlayer->getSide());
if(gameObjHoveredOn && (controlPressed || (gameObjHoveredOn->getPlayer()->getSide() != mainPlayer->getSide())))
if(gameObjHoveredOn && (gameObjHoveredOn->getType() == GameObject::Type::UNIT && ((Unit*)gameObjHoveredOn)->getNumGarrisonSlots() > 0 && ownGameObj))
issueOrder(Order::TYPE::GARRISON, vector<Order::Target>{Order::Target((Unit*)gameObjHoveredOn, gameObjHoveredOn->getPos())}, shiftPressed);
else if(gameObjHoveredOn && (controlPressed || !ownGameObj))
issueOrder(Order::TYPE::ATTACK, vector<Order::Target>{Order::Target((Unit*)gameObjHoveredOn, gameObjHoveredOn->getPos())}, shiftPressed);
else if(controlPressed && !gameObjHoveredOn){
castRayToTerrain();
+1
View File
@@ -72,6 +72,7 @@ namespace battleship{
std::vector<Projectile*> getProjectiles();
virtual void addOrder(Order);
virtual void reinit();
inline int getNumGarrisonSlots(){return garrisonSlots.size();}
inline const std::vector<GarrisonSlot>& getGarrisonSlots(){return garrisonSlots;}
inline vb01::Vector3* getPosPtr() {return &pos;}
inline float getLineOfSight() {return lineOfSight;}
+18 -13
View File
@@ -193,6 +193,7 @@ namespace battleship{
if(!pursuingTarget){
Vector3 targPos = (orders[0].targets[0].unit ? orders[0].targets[0].unit->getPos() : orders[0].targets[0].pos);
preparePathpoints(targPos);
addPathpoint(targPos);
pursuingTarget = true;
}
@@ -200,9 +201,8 @@ namespace battleship{
}
void Vehicle::garrison(Order order){
float garrisonDist = 1.25 * Map::getSingleton()->getCellSize().x;
Unit *targUnit = order.targets[0].unit;
float distToGarrisonable = pos.getDistanceFrom(targUnit->getPos());
float distToGarrisonable = pos.getDistanceFrom(targUnit->getPos()), garrisonDist = .1;
if(distToGarrisonable > garrisonDist)
navigateToTarget(garrisonDist);
@@ -219,6 +219,20 @@ namespace battleship{
navigate(.5 * Map::getSingleton()->getCellSize().x);
}
void Vehicle::addPathpoint(Vector3 pointPos){
pathPoints.push_back(pointPos);
Box *b = new Box(Vector3::VEC_IJK);
b->setMaterial(debugMat);
Node *n = new Node(pointPos);
n->attachMesh(b);
Root::getSingleton()->getRootNode()->attachChild(n);
debugPathPoints.push_back(n);
}
void Vehicle::preparePathpoints(Vector3 destPos){
removeAllPathpoints();
@@ -237,18 +251,9 @@ namespace battleship{
Pathfinder *pathfinder = Pathfinder::getSingleton();
vector<int> path = pathfinder->findPath(cells, source, dest, (int)type);
Node *rootNode = Root::getSingleton()->getRootNode();
for(int p : path){
pathPoints.push_back(cells[p].pos);
Box *b = new Box(Vector3::VEC_IJK);
b->setMaterial(debugMat);
Node *n = new Node(cells[p].pos);
n->attachMesh(b);
rootNode->attachChild(n);
debugPathPoints.push_back(n);
}
for(int p : path)
addPathpoint(cells[p].pos);
}
void Vehicle::removePathpoint(int i){
+1
View File
@@ -34,6 +34,7 @@ namespace battleship{
void turn(float);
void addOrder(Order);
void advance(float, MoveDir = MoveDir::FORW);
void addPathpoint(vb01::Vector3);
void preparePathpoints(vb01::Vector3);
void removePathpoint(int = 0);
void removeAllPathpoints();