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/************************************************************************/
46static const struct unit_type *animal_for_terrain(struct terrain *pterr)
47{
48 return pterr->animal;
49}
50
51/************************************************************************/
54static 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
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 }
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) {
75 return;
76 }
78
80
82 struct unit *punit;
83
85
86 punit = create_unit(plr, ptile, ptype, 0, 0, -1);
87
89 }
90}
91
92/************************************************************************/
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
107
109 return;
110 }
111
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);
119
122
124
125 server.nbarbarians++;
126
128 plr->unassigned_user = TRUE;
129 plr->is_connected = FALSE;
131 plr->economic.gold = 100;
132
133 plr->phase_done = TRUE;
134
137
138 presearch = research_get(plr);
141
142 /* Ensure that we are at war with everyone else */
144
145 CALL_PLR_AI_FUNC(gained_control, plr, plr);
146
148 /* Send research info after player info, else the client will complain
149 * about invalid team. */
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}
#define CALL_PLR_AI_FUNC(_func, _player,...)
Definition ai.h:377
const char * default_ai_type_name(void)
Definition aiiface.c:266
static const struct unit_type * animal_for_terrain(struct terrain *pterr)
Definition animals.c:46
void create_animals(void)
Definition animals.c:95
static void place_animal(struct player *plr, int sqrdist)
Definition animals.c:54
void barbarian_initial_wars(struct player *barbarians)
Definition barbarian.c:765
char * incite_cost
Definition comments.c:75
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
void set_ai_level_directer(struct player *pplayer, enum ai_level level)
Definition difficulty.c:39
#define extra_type_by_rmcause_iterate_end
Definition extras.h:358
#define extra_type_by_rmcause_iterate(_rmcause, _extra)
Definition extras.h:353
#define _(String)
Definition fcintl.h:67
struct civ_game game
Definition game.c:62
struct world wld
Definition game.c:63
#define fc_assert_ret(condition)
Definition log.h:191
struct tile * rand_map_pos(const struct civ_map *nmap)
Definition map.c:1088
#define circle_iterate(nmap, center_tile, sq_radius, tile_itr)
Definition map.h:401
#define circle_iterate_end
Definition map.h:404
bool can_exist_at_tile(const struct civ_map *nmap, const struct unit_type *utype, const struct tile *ptile)
Definition movement.c:290
struct government * init_government_of_nation(const struct nation_type *pnation)
Definition nation.c:659
#define NO_NATION_SELECTED
Definition nation.h:30
bool player_set_nation(struct player *pplayer, struct nation_type *pnation)
Definition player.c:861
#define ANON_USER_NAME
Definition player.h:48
#define set_as_ai(plr)
Definition player.h:232
void send_player_all_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1129
struct player * server_create_player(int player_id, const char *ai_tname, struct rgbcolor *prgbcolor, bool allow_ai_type_fallbacking)
Definition plrhand.c:1893
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:2452
void server_player_init(struct player *pplayer, bool initmap, bool needs_team)
Definition plrhand.c:1618
void assign_player_colors(void)
Definition plrhand.c:1733
struct research * research_get(const struct player *pplayer)
Definition research.c:128
void player_nation_defaults(struct player *pplayer, struct nation_type *pnation, bool set_name)
Definition srv_main.c:2580
struct packet_game_info info
Definition game.h:89
int animals
Definition map_types.h:96
int xsize
Definition map_types.h:78
int ysize
Definition map_types.h:78
struct civ_map::@42::@44 server
enum ai_level skill_level
enum barbarian_type barbarian_type
Definition player.h:120
struct player_ai ai_common
Definition player.h:286
char username[MAX_LEN_NAME]
Definition player.h:250
bool is_connected
Definition player.h:294
struct government * government
Definition player.h:256
struct player_economic economic
Definition player.h:282
bool phase_done
Definition player.h:261
bool unassigned_user
Definition player.h:251
Definition tile.h:50
struct unit_list * units
Definition tile.h:58
Definition unit.h:138
struct civ_map map
#define sz_strlcpy(dest, src)
Definition support.h:195
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
void init_tech(struct research *research, bool update)
Definition techtools.c:1094
void send_research_info(const struct research *presearch, const struct conn_list *dest)
Definition techtools.c:293
void give_initial_techs(struct research *presearch, int num_random_techs)
Definition techtools.c:1188
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_terrain(_tile)
Definition tile.h:110
#define tile_has_extra(ptile, pextra)
Definition tile.h:147
static bool is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:432
void send_unit_info(struct conn_list *dest, struct unit *punit)
Definition unittools.c:2722
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:1597
bool utype_player_already_has_this_unique(const struct player *pplayer, const struct unit_type *putype)
Definition unittype.c:1927