mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
refactored checking if a point is within a cuboid
ice sheets can be crushed
This commit is contained in:
@@ -382,6 +382,28 @@ namespace battleship{
|
||||
return spawnPointsTbl.size();
|
||||
}
|
||||
|
||||
void Map::blockCells(Unit *unit){
|
||||
for(Cell &cell : cells){
|
||||
if(cell.blockedBy && cell.blockedBy != unit) continue;
|
||||
|
||||
Vector3 cellDir = (cell.pos - unit->getPos()), dirVec = unit->getDirVec(), leftVec = unit->getLeftVec();
|
||||
float forwAngle = std::min(dirVec.getAngleBetween(cellDir.norm()), (-dirVec).getAngleBetween(cellDir.norm()));
|
||||
float forwDist = cellDir.getLength() * cos(forwAngle);
|
||||
|
||||
float leftAngle = std::min(leftVec.getAngleBetween(cellDir.norm()), (-leftVec).getAngleBetween(cellDir.norm()));
|
||||
float leftDist = cellDir.getLength() * cos(leftAngle);
|
||||
|
||||
bool within = (forwDist < .5 * (unit->getLength() + CELL_SIZE.x) && leftDist < .5 * (unit->getWidth() + CELL_SIZE.z));
|
||||
cell.blockedBy = (within ? unit : nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void Map::unblockCells(Unit *unit){
|
||||
for(Cell &cell : cells)
|
||||
if(cell.blockedBy == unit)
|
||||
cell.blockedBy = nullptr;
|
||||
}
|
||||
|
||||
void Map::loadSpawnPoints(){
|
||||
sol::state_view SOL_LUA_VIEW = generateView();
|
||||
int numSpawnPoints = getNumMapSpawnPoints();
|
||||
|
||||
Reference in New Issue
Block a user