Moved make_escapes() and remove_escapes() to support.c.
[freeciv.git] / server / animals.c
blob8eb5cc0bc15343e73ae1c7907442cc33413f06c3
1 /**********************************************************************
2 Freeciv - Copyright (C) 1996 - 2004 The Freeciv Project Team
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 ***********************************************************************/
13 #ifdef HAVE_CONFIG_H
14 #include <fc_config.h>
15 #endif
17 /* common */
18 #include "ai.h"
19 #include "game.h"
20 #include "map.h"
21 #include "movement.h"
22 #include "player.h"
23 #include "research.h"
24 #include "tech.h"
25 #include "tile.h"
26 #include "unittype.h"
28 /* server */
29 #include "aiiface.h"
30 #include "plrhand.h"
31 #include "srv_main.h"
32 #include "stdinhand.h"
33 #include "techtools.h"
34 #include "unittools.h"
36 /* ai */
37 #include "difficulty.h"
39 #include "animals.h"
41 /****************************************************************************
42 Return suitable animal type for the terrain
43 ****************************************************************************/
44 static struct unit_type *animal_for_terrain(struct terrain *pterr)
46 return pterr->animal;
49 /****************************************************************************
50 Try to add one animal to the map.
51 ****************************************************************************/
52 static void place_animal(struct player *plr)
54 struct tile *ptile = rand_map_pos();
55 struct unit_type *ptype;
57 extra_type_by_cause_iterate(EC_HUT, pextra) {
58 if (tile_has_extra(ptile, pextra)) {
59 /* Animals should not displace huts */
60 return;
62 } extra_type_by_cause_iterate_end;
64 if (unit_list_size(ptile->units) > 0 || tile_city(ptile)) {
65 return;
67 adjc_iterate(ptile, padj) {
68 if (unit_list_size(padj->units) > 0 || tile_city(padj)) {
69 /* No animals next to start units or start city */
70 return;
72 } adjc_iterate_end;
74 ptype = animal_for_terrain(tile_terrain(ptile));
76 if (ptype != NULL) {
77 struct unit *punit;
79 fc_assert_ret(can_exist_at_tile(ptype, ptile));
81 punit = create_unit(plr, ptile, ptype, 0, 0, -1);
83 send_unit_info(NULL, punit);
87 /****************************************************************************
88 Create animal kingdom player and his units.
89 ****************************************************************************/
90 void create_animals(void)
92 struct nation_type *anination;
93 struct player *plr;
94 struct research *presearch;
95 int i;
97 if (game.map.server.animals <= 0) {
98 return;
101 anination = pick_a_nation(NULL, FALSE, TRUE, ANIMAL_BARBARIAN);
103 if (anination == NO_NATION_SELECTED) {
104 return;
107 plr = server_create_player(-1, default_ai_type_name(), NULL, FALSE);
108 if (plr == NULL) {
109 return;
111 server_player_init(plr, TRUE, TRUE);
113 player_set_nation(plr, anination);
114 player_nation_defaults(plr, anination, TRUE);
116 assign_player_colors();
118 server.nbarbarians++;
120 sz_strlcpy(plr->username, _(ANON_USER_NAME));
121 plr->unassigned_user = TRUE;
122 plr->is_connected = FALSE;
123 plr->government = init_government_of_nation(anination);
124 plr->economic.gold = 100;
126 plr->phase_done = TRUE;
128 plr->ai_controlled = TRUE;
129 plr->ai_common.barbarian_type = ANIMAL_BARBARIAN;
130 set_ai_level_directer(plr, game.info.skill_level);
132 presearch = research_get(plr);
133 init_tech(presearch, TRUE);
134 give_initial_techs(presearch, 0);
136 /* Ensure that we are at war with everyone else */
137 players_iterate(pplayer) {
138 if (pplayer != plr) {
139 player_diplstate_get(pplayer, plr)->type = DS_WAR;
140 player_diplstate_get(plr, pplayer)->type = DS_WAR;
142 } players_iterate_end;
144 CALL_PLR_AI_FUNC(gained_control, plr, plr);
146 send_player_all_c(plr, NULL);
147 /* Send research info after player info, else the client will complain
148 * about invalid team. */
149 send_research_info(presearch, NULL);
151 for (i = 0; i < game.map.xsize * game.map.ysize * game.map.server.animals / 1000; i++) {
152 place_animal(plr);