From 388794bca641cfecaf385e258190c40d8bf74405 Mon Sep 17 00:00:00 2001 From: Lendemor Date: Tue, 24 May 2016 23:31:00 +0200 Subject: [PATCH] small change --- src/simulation.cpp | 8 ++++---- src/team.cpp | 5 ++--- src/team.h | 3 ++- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/simulation.cpp b/src/simulation.cpp index b3e51cd..c826a39 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -23,9 +23,9 @@ Simulation::Simulation(MapScene *_map, std::vector &_behaviors void Simulation::update() { std::random_shuffle(m_dudes.begin(),m_dudes.end()); - //BUG : find segfault origin - if(m_dudes.empty()){ - for (Dude* dude : m_dudes){ + //TODO FIX : find segfault origin + if(!m_dudes.empty()){ + for (auto dude : m_dudes){ auto action = m_teams[dude->getTeam()].update(dude); //get action for this dude from behavior function in team handleAction(action,dude); } @@ -40,7 +40,6 @@ void Simulation::update() m_dudes.push_back(new Dude(spawnPos,p_map,i)); } } -// std::cerr << "Update..." << std::endl; } // TODO finish conversion of handleAction() @@ -49,6 +48,7 @@ void Simulation::handleAction(Action *action, Dude *dude){ Pixel target = p_map->getPixel(targetPos); Dude* targetDude; dude->setSuccess(false); + if(action == NULL) return; switch(action->type){ case Action::MOVE: if (isWalkable(target.type)) diff --git a/src/team.cpp b/src/team.cpp index 88f4f42..b54536a 100644 --- a/src/team.cpp +++ b/src/team.cpp @@ -1,4 +1,5 @@ #include "team.h" +#include "dude.h" Team::Team(const glm::vec3 &teamColor, const glm::vec3 &dudeColor, BehaviorFunction _behavior): m_teamColor(teamColor), @@ -32,8 +33,6 @@ void Team::destroySpawn(){ Action* Team::update(Dude *dude) { Action* action; - m_behavior(action, - dude->getMemory(), - (Info*) dude); + m_behavior(action, dude->getMemory(),(Info*) dude); return action; } diff --git a/src/team.h b/src/team.h index e548c76..3e1f76a 100644 --- a/src/team.h +++ b/src/team.h @@ -6,12 +6,13 @@ #include "glm/vec3.hpp" #include "coord.h" -#include "dude.h" #include "behavior.h" #define NB_STARTING_FOOD 5 #define SPAWN_COOLDOWN 30 +class Dude; + class Team { glm::vec3 m_teamColor;