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)
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 ***********************************************************************/
14 #include <fc_config.h>
32 #include "stdinhand.h"
33 #include "techtools.h"
34 #include "unittools.h"
37 #include "difficulty.h"
41 /****************************************************************************
42 Return suitable animal type for the terrain
43 ****************************************************************************/
44 static struct unit_type
*animal_for_terrain(struct terrain
*pterr
)
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 */
62 } extra_type_by_cause_iterate_end
;
64 if (unit_list_size(ptile
->units
) > 0 || tile_city(ptile
)) {
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 */
74 ptype
= animal_for_terrain(tile_terrain(ptile
));
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
;
94 struct research
*presearch
;
97 if (game
.map
.server
.animals
<= 0) {
101 anination
= pick_a_nation(NULL
, FALSE
, TRUE
, ANIMAL_BARBARIAN
);
103 if (anination
== NO_NATION_SELECTED
) {
107 plr
= server_create_player(-1, default_ai_type_name(), NULL
, FALSE
);
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
++) {