map::agent_startpos(): Introduce, abstract out from main loop

This commit is contained in:
Petr Baudis 2011-11-27 00:38:31 +01:00
parent ea4f18b642
commit ec3897b29b
3 changed files with 16 additions and 6 deletions

14
map.cc
View file

@ -1,5 +1,6 @@
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <iostream>
#include "agent.h"
#include "map.h"
@ -47,6 +48,17 @@ tile::tile_in_dir(int dir_x, int dir_y)
}
class tile &
map::agent_startpos(void)
{
/* Find a random starting tile that is not occupied yet. */
class tile *tile;
do {
tile = &tile_at(random() % w, random() % h);
} while (tile->agent);
return *tile;
}
void
map::on_tick(void)
{