refactored visible game object detection

checking whether the game object frame is on the right type of a cell
This commit is contained in:
devZoGok
2026-03-15 15:21:11 +02:00
parent 268ea14f4a
commit 580659aad5
5 changed files with 63 additions and 66 deletions
+33
View File
@@ -286,4 +286,37 @@ namespace battleship{
}
}
}
vector<Unit*> Player::getFriendlyUnits(bool includeOwn){
vector<Unit*> friendlyUnits;
for (Player *pl : Game::getSingleton()->getPlayers(true))
for (Unit *u : pl->getUnits())
if((includeOwn && pl == this) || pl->getTeam() == getTeam())
friendlyUnits.push_back(u);
return friendlyUnits;
}
//TODO improve this for greater accuracy
bool Player::isObjectVisible(GameObject *object, std::vector<Unit*> friendlyUnits) {
Player *objPlayer = object->getPlayer();
for(Unit *friendlyUnit : friendlyUnits){
if(objPlayer == this || objPlayer->getTeam() == getTeam())
return true;
Vector3 obsUnitPos = object->getPos();
obsUnitPos.y = 0;
Vector3 compUnitPos = friendlyUnit->getPos();
compUnitPos.y = 0;
float dist = compUnitPos.getDistanceFrom(obsUnitPos);
if(dist <= friendlyUnit->getLineOfSight())
return true;
}
return false;
}
}