Freeciv-3.2: /fast/freeciv/nightly/S3_2/server/animals.c Source File

Freeciv-3.2

Loading...
Searching...
No Matches
animals.c
Go to the documentation of this file.
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.
7
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
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* common */
19#include "ai.h"
20#include "game.h"
21#include "map.h"
22#include "movement.h"
23#include "player.h"
24#include "research.h"
25#include "tech.h"
26#include "tile.h"
27
28/* server */
29#include "aiiface.h"
30#include "barbarian.h"
31#include "nation.h"
32#include "plrhand.h"
33#include "srv_main.h"
34#include "stdinhand.h"
35#include "techtools.h"
36#include "unittools.h"
37
38/* ai */
39#include "difficulty.h"
40
41#include "animals.h"
42
43/************************************************************************/
46 static const struct unit_type *animal_for_terrain(struct terrain *pterr)
47{
48 return pterr->animal;
49}
50
51/************************************************************************/
54 static void place_animal(struct player *plr, int sqrdist)
55{
56 struct tile *ptile = rand_map_pos(&(wld.map));
57 const struct unit_type *ptype;
58
59 extra_type_by_rmcause_iterate(ERM_ENTER, pextra) {
60 if (tile_has_extra(ptile, pextra)) {
61 /* Animals should not displace huts */
62 /* FIXME: could animals not entering nor frightening huts appear here? */
63 return;
64 }
65 } extra_type_by_rmcause_iterate_end;
66
67 if (unit_list_size(ptile->units) > 0) {
68 /* Below we check against enemy units nearby. Here we make sure
69 * there's no multiple animals in the very same tile. */
70 return;
71 }
72
73 circle_iterate(&(wld.map), ptile, sqrdist, check) {
74 if (tile_city(check) || is_non_allied_unit_tile(check, plr)) {
75 return;
76 }
77 } circle_iterate_end;
78
79 ptype = animal_for_terrain(tile_terrain(ptile));
80
81 if (ptype != NULL && !utype_player_already_has_this_unique(plr, ptype)) {
82 struct unit *punit;
83
84 fc_assert_ret(can_exist_at_tile(&(wld.map), ptype, ptile));
85
86 punit = create_unit(plr, ptile, ptype, 0, 0, -1);
87
88 send_unit_info(NULL, punit);
89 }
90}
91
92/************************************************************************/
95 void create_animals(void)
96{
97 struct nation_type *anination;
98 struct player *plr;
99 struct research *presearch;
100 int i;
101
102 if (wld.map.server.animals <= 0) {
103 return;
104 }
105
106 anination = pick_a_nation(NULL, FALSE, TRUE, ANIMAL_BARBARIAN);
107
108 if (anination == NO_NATION_SELECTED) {
109 return;
110 }
111
112 plr = server_create_player(-1, default_ai_type_name(), NULL, FALSE);
113 if (plr == NULL) {
114 return;
115 }
116 /* Freeciv-web depends on AI-status being set already before server_player_init() */
117 set_as_ai(plr);
118 server_player_init(plr, TRUE, TRUE);
119
120 player_set_nation(plr, anination);
121 player_nation_defaults(plr, anination, TRUE);
122
123 assign_player_colors();
124
125 server.nbarbarians++;
126
127 sz_strlcpy(plr->username, _(ANON_USER_NAME));
128 plr->unassigned_user = TRUE;
129 plr->is_connected = FALSE;
130 plr->government = init_government_of_nation(anination);
131 plr->economic.gold = 100;
132
133 plr->phase_done = TRUE;
134
135 plr->ai_common.barbarian_type = ANIMAL_BARBARIAN;
136 set_ai_level_directer(plr, game.info.skill_level);
137
138 presearch = research_get(plr);
139 init_tech(presearch, TRUE);
140 give_initial_techs(presearch, 0);
141
142 /* Ensure that we are at war with everyone else */
143 barbarian_initial_wars(plr);
144
145 CALL_PLR_AI_FUNC(gained_control, plr, plr);
146
147 send_player_all_c(plr, NULL);
148 /* Send research info after player info, else the client will complain
149 * about invalid team. */
150 send_research_info(presearch, NULL);
151
152 for (i = 0;
153 i < wld.map.xsize * wld.map.ysize * wld.map.server.animals / 1000;
154 i++) {
155 place_animal(plr, 2 * 2 + 1 * 1);
156 }
157}
ai.h
CALL_PLR_AI_FUNC
#define CALL_PLR_AI_FUNC(_func, _player,...)
Definition ai.h:374
default_ai_type_name
const char * default_ai_type_name(void)
Definition aiiface.c:266
aiiface.h
animal_for_terrain
static const struct unit_type * animal_for_terrain(struct terrain *pterr)
Definition animals.c:46
create_animals
void create_animals(void)
Definition animals.c:95
place_animal
static void place_animal(struct player *plr, int sqrdist)
Definition animals.c:54
animals.h
barbarian_initial_wars
void barbarian_initial_wars(struct player *barbarians)
Definition barbarian.c:765
barbarian.h
incite_cost
char * incite_cost
Definition comments.c:74
punit
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
set_ai_level_directer
void set_ai_level_directer(struct player *pplayer, enum ai_level level)
Definition difficulty.c:39
difficulty.h
extra_type_by_rmcause_iterate_end
#define extra_type_by_rmcause_iterate_end
Definition extras.h:358
extra_type_by_rmcause_iterate
#define extra_type_by_rmcause_iterate(_rmcause, _extra)
Definition extras.h:353
_
#define _(String)
Definition fcintl.h:67
game
struct civ_game game
Definition game.c:62
wld
struct world wld
Definition game.c:63
game.h
fc_assert_ret
#define fc_assert_ret(condition)
Definition log.h:191
rand_map_pos
struct tile * rand_map_pos(const struct civ_map *nmap)
Definition map.c:1088
map.h
circle_iterate
#define circle_iterate(nmap, center_tile, sq_radius, tile_itr)
Definition map.h:401
circle_iterate_end
#define circle_iterate_end
Definition map.h:404
can_exist_at_tile
bool can_exist_at_tile(const struct civ_map *nmap, const struct unit_type *utype, const struct tile *ptile)
Definition movement.c:290
movement.h
init_government_of_nation
struct government * init_government_of_nation(const struct nation_type *pnation)
Definition nation.c:659
nation.h
NO_NATION_SELECTED
#define NO_NATION_SELECTED
Definition nation.h:30
player_set_nation
bool player_set_nation(struct player *pplayer, struct nation_type *pnation)
Definition player.c:861
player.h
ANON_USER_NAME
#define ANON_USER_NAME
Definition player.h:48
set_as_ai
#define set_as_ai(plr)
Definition player.h:232
send_player_all_c
void send_player_all_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1125
server_create_player
struct player * server_create_player(int player_id, const char *ai_tname, struct rgbcolor *prgbcolor, bool allow_ai_type_fallbacking)
Definition plrhand.c:1889
pick_a_nation
struct nation_type * pick_a_nation(const struct nation_list *choices, bool ignore_conflicts, bool needs_startpos, enum barbarian_type barb_type)
Definition plrhand.c:2448
server_player_init
void server_player_init(struct player *pplayer, bool initmap, bool needs_team)
Definition plrhand.c:1614
assign_player_colors
void assign_player_colors(void)
Definition plrhand.c:1729
plrhand.h
research_get
struct research * research_get(const struct player *pplayer)
Definition research.c:128
research.h
player_nation_defaults
void player_nation_defaults(struct player *pplayer, struct nation_type *pnation, bool set_name)
Definition srv_main.c:2579
srv_main.h
stdinhand.h
civ_game::info
struct packet_game_info info
Definition game.h:89
civ_map::animals
int animals
Definition map_types.h:96
civ_map::xsize
int xsize
Definition map_types.h:78
civ_map::ysize
int ysize
Definition map_types.h:78
civ_map::server
struct civ_map::@42::@44 server
nation_type
Definition nation.h:98
packet_game_info::skill_level
enum ai_level skill_level
Definition packets_gen.h:222
player_ai::barbarian_type
enum barbarian_type barbarian_type
Definition player.h:120
player_economic::gold
int gold
Definition player.h:61
player
Definition player.h:247
player::ai_common
struct player_ai ai_common
Definition player.h:286
player::username
char username[MAX_LEN_NAME]
Definition player.h:250
player::is_connected
bool is_connected
Definition player.h:294
player::government
struct government * government
Definition player.h:256
player::economic
struct player_economic economic
Definition player.h:282
player::phase_done
bool phase_done
Definition player.h:261
player::unassigned_user
bool unassigned_user
Definition player.h:251
research
Definition research.h:39
server
Definition servers.h:29
terrain
Definition terrain.h:182
tile
Definition tile.h:50
tile::units
struct unit_list * units
Definition tile.h:58
unit_type
Definition unittype.h:500
unit
Definition unit.h:138
world::map
struct civ_map map
Definition world_object.h:38
sz_strlcpy
#define sz_strlcpy(dest, src)
Definition support.h:189
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
tech.h
init_tech
void init_tech(struct research *research, bool update)
Definition techtools.c:1093
send_research_info
void send_research_info(const struct research *presearch, const struct conn_list *dest)
Definition techtools.c:293
give_initial_techs
void give_initial_techs(struct research *presearch, int num_random_techs)
Definition techtools.c:1187
techtools.h
tile_city
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
tile.h
tile_terrain
#define tile_terrain(_tile)
Definition tile.h:110
tile_has_extra
#define tile_has_extra(ptile, pextra)
Definition tile.h:147
is_non_allied_unit_tile
static bool is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:425
send_unit_info
void send_unit_info(struct conn_list *dest, struct unit *punit)
Definition unittools.c:2725
create_unit
struct unit * create_unit(struct player *pplayer, struct tile *ptile, const struct unit_type *type, int veteran_level, int homecity_id, int moves_left)
Definition unittools.c:1601
unittools.h
utype_player_already_has_this_unique
bool utype_player_already_has_this_unique(const struct player *pplayer, const struct unit_type *putype)
Definition unittype.c:1927