fixed freeze in simple behavior
This commit is contained in:
parent
ff64c7b780
commit
fed5b48afe
@ -90,10 +90,17 @@ extern "C" void think(Action *action, char *memory, const Info *info)
|
||||
}
|
||||
}
|
||||
|
||||
int blockedCount = 0;
|
||||
action->type = Action::MOVE;
|
||||
do{
|
||||
action->dir = Dir((data->last_dir + rand()%3)%4);
|
||||
type = info->getNear(action->dir);
|
||||
++blockedCount;
|
||||
if(blockedCount > 3)
|
||||
{
|
||||
action->type = Action::WAIT;
|
||||
break;
|
||||
}
|
||||
}while(!PixelProperty::isWalkable(type));
|
||||
|
||||
data->last_dir = action->dir;
|
||||
|
@ -37,17 +37,14 @@ void Simulation::update()
|
||||
if(t.updateSpawn())
|
||||
{
|
||||
Coord spawnPos = p_map->team(i) + Coord(Dir(rand()%4));
|
||||
std::cout << p_map->getPixel(spawnPos).type << std::endl;
|
||||
if(PixelProperty::isWalkable(p_map->getPixel(spawnPos).type))
|
||||
{
|
||||
t.popDude();
|
||||
Dude *dude = new Dude(spawnPos,p_map,i);
|
||||
(*p_map)[spawnPos].data.dudePtr = dude;
|
||||
p_map->updatePixel(spawnPos);
|
||||
m_dudes.push_back(dude);
|
||||
}
|
||||
else
|
||||
std::cout << "Unpopable" << std::endl;
|
||||
// TODO check other case or delay the spawning
|
||||
}
|
||||
}
|
||||
}
|
||||
|
10
src/team.cpp
10
src/team.cpp
@ -6,6 +6,7 @@ Team::Team(const glm::vec3 &spawnColor, const glm::vec3 &dudeColor, BehaviorFunc
|
||||
m_dudeColor(dudeColor),
|
||||
m_spawnCooldown(1),
|
||||
m_foodQuantity(NB_STARTING_FOOD),
|
||||
m_dudesReady(0),
|
||||
m_behavior(_behavior)
|
||||
{
|
||||
}
|
||||
@ -19,10 +20,15 @@ bool Team::updateSpawn()
|
||||
{
|
||||
m_spawnCooldown = SPAWN_COOLDOWN;
|
||||
--m_foodQuantity;
|
||||
return true;
|
||||
++m_dudesReady;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return m_dudesReady > 0;
|
||||
}
|
||||
|
||||
void Team::popDude()
|
||||
{
|
||||
--m_dudesReady;
|
||||
}
|
||||
|
||||
void Team::destroySpawn(){
|
||||
|
@ -19,10 +19,12 @@ class Team
|
||||
glm::vec3 m_dudeColor;
|
||||
int m_spawnCooldown;
|
||||
int m_foodQuantity;
|
||||
int m_dudesReady;
|
||||
BehaviorFunction m_behavior;
|
||||
public:
|
||||
Team(const glm::vec3 &spawnColor, const glm::vec3 &dudeColor, BehaviorFunction _behavior);
|
||||
bool updateSpawn();
|
||||
void popDude();
|
||||
void addFood() {m_foodQuantity++; }
|
||||
void destroySpawn();
|
||||
Action* update(Dude*);
|
||||
|
Loading…
x
Reference in New Issue
Block a user