Skip to content

Commit

Permalink
Use place_starting_unit() to place nation specific start units
Browse files Browse the repository at this point in the history
This makes sure nation specific starting units are placed on a
tile where they can exist, and any hut extras on the tile will
get cleared.

Reported by Jacob Nevins

See hrm Bug #767129

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
  • Loading branch information
cazfi committed Jun 24, 2019
1 parent a26e669 commit 64c1c3e
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions server/gamehand.c
Expand Up @@ -139,16 +139,23 @@ struct unit_type *crole_to_unit_type(char crole, struct player *pplayer)

/****************************************************************************
Place a starting unit for the player. Returns tile where unit was really
placed.
placed. By default the ptype is used and crole does not matter, but if
former is NULL, crole will be used instead.
****************************************************************************/
static struct tile *place_starting_unit(struct tile *starttile,
struct player *pplayer,
char crole)
struct unit_type *ptype, char crole)
{
struct tile *ptile = NULL;
struct unit_type *utype = crole_to_unit_type(crole, pplayer);
struct unit_type *utype;
bool hut_present = FALSE;

if (ptype != NULL) {
utype = ptype;
} else {
utype = crole_to_unit_type(crole, pplayer);
}

if (utype != NULL) {
iterate_outward(starttile, game.map.xsize + game.map.ysize, itertile) {
if (!is_non_allied_unit_tile(itertile, pplayer)
Expand Down Expand Up @@ -778,7 +785,7 @@ void init_new_game(void)

if (sulen > 0) {
/* Place the first unit. */
if (place_starting_unit(ptile, pplayer,
if (place_starting_unit(ptile, pplayer, NULL,
game.server.start_units[0]) != NULL) {
placed_units[player_index(pplayer)] = 1;
} else {
Expand All @@ -802,7 +809,7 @@ void init_new_game(void)
struct tile *rand_tile = find_dispersed_position(pplayer, ptile);

/* Create the unit of an appropriate type. */
if (place_starting_unit(rand_tile, pplayer,
if (place_starting_unit(rand_tile, pplayer, NULL,
game.server.start_units[i]) != NULL) {
placed_units[player_index(pplayer)]++;
}
Expand All @@ -813,8 +820,10 @@ void init_new_game(void)
while (NULL != nation->init_units[i] && MAX_NUM_UNIT_LIST > i) {
struct tile *rand_tile = find_dispersed_position(pplayer, ptile);

create_unit(pplayer, rand_tile, nation->init_units[i], FALSE, 0, 0);
placed_units[player_index(pplayer)]++;
if (place_starting_unit(rand_tile, pplayer,
nation->init_units[i], '\0') != NULL) {
placed_units[player_index(pplayer)]++;
}
i++;
}
} players_iterate_end;
Expand Down

0 comments on commit 64c1c3e

Please sign in to comment.