mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
map cells can be blocked to become impassible
added ice sheets and icebreakers
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include "unit.h"
|
||||
#include "util.h"
|
||||
#include "game.h"
|
||||
#include "map.h"
|
||||
#include "vehicle.h"
|
||||
#include "gameObjectFactory.h"
|
||||
#include "activeGameState.h"
|
||||
@@ -822,6 +823,29 @@ namespace battleship{
|
||||
}
|
||||
}
|
||||
|
||||
//TODO select only the closest cells based on unit size
|
||||
void Unit::placeAt(Vector3 p){
|
||||
GameObject::placeAt(p);
|
||||
|
||||
Map *map = Map::getSingleton();
|
||||
vector<Map::Cell> &cells = map->getCells();
|
||||
Vector3 cellSize = map->getCellSize();
|
||||
|
||||
for(Map::Cell &cell : cells){
|
||||
if(cell.blockedBy && cell.blockedBy != this) continue;
|
||||
|
||||
Vector3 cellDir = (cell.pos - pos);
|
||||
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 * (length + cellSize.x) && leftDist < .5 * (width + cellSize.z));
|
||||
cell.blockedBy = (within ? this : nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
vector<Player*> Unit::getSelectingPlayers(){
|
||||
vector<Player*> players = Game::getSingleton()->getPlayers(), selectingPlayers;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user