Fixed movement of multiple entities.
Changed std::unique_ptr<Entity> to std::shared_ptr<Entity>. Fixed pathfinding away from targets TODO : - Fix oscillation around destination - Fix fleeing from adjacent target - Win conditions - GUI
This commit is contained in:
parent
293a564a29
commit
5ccd7d0c13
6 changed files with 33 additions and 21 deletions
|
@ -14,7 +14,7 @@ Level::Level(const pugi::xml_document& xmlDoc, const pro_maat::TextureStore& tex
|
|||
{
|
||||
if(!strncmp(child.name(),"Entity",6))
|
||||
{
|
||||
entities.emplace_back(std::make_unique<Entity>(child,textures.at(child.attribute("textureId").as_int(0)).get()));
|
||||
entities.emplace_back(std::make_shared<Entity>(child,textures.at(child.attribute("textureId").as_int(0)).get()));
|
||||
|
||||
// Initialize the occupied squares vector with the new entity's squares
|
||||
std::vector<pro_maat::GridPos> entitySquares = entities.rbegin()->get()->getOccupiedSquares();
|
||||
|
@ -23,7 +23,8 @@ Level::Level(const pugi::xml_document& xmlDoc, const pro_maat::TextureStore& tex
|
|||
}
|
||||
|
||||
// FIXME : For testing purposes
|
||||
addRule(EntityType::Significant,State::Moving,EntityType::Citizen);
|
||||
addRule(EntityType::Significant,State::Fleeing,EntityType::Citizen);
|
||||
addRule(EntityType::Citizen,State::Moving,EntityType::Significant);
|
||||
}
|
||||
|
||||
void Level::addRule(EntityType affectedEntities, const State targetState, EntityType targetEntities)
|
||||
|
@ -32,7 +33,7 @@ void Level::addRule(EntityType affectedEntities, const State targetState, Entity
|
|||
{
|
||||
if(entity->getType() == affectedEntities)
|
||||
{
|
||||
entity = std::make_unique<Rule>(entity.release(),targetState,targetEntities,entities,occupiedSquares,size);
|
||||
entity = std::make_shared<Rule>(entity,targetState,targetEntities,entities,occupiedSquares,size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -189,7 +190,7 @@ Orientation Level::findPath(pro_maat::GridPos start, pro_maat::GridPos goal, int
|
|||
}
|
||||
|
||||
pathCosts.insert_or_assign(neighbour,newPathCost);
|
||||
estimatedCosts.insert_or_assign(neighbour,newPathCost + pro_maat::manhattanDistance(neighbour,goal));
|
||||
estimatedCosts.insert_or_assign(neighbour,newPathCost + pro_maat::manhattanDistance(neighbour,goal)*sign);
|
||||
paths.insert_or_assign(neighbour,currentNode);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue