Freeciv-3.3
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) {
74 if (tile_city(check) != NULL
76 return;
77 }
79
81
83 struct unit *punit;
84
86
87 punit = create_unit(plr, ptile, ptype, 0, 0, -1);
88
90 }
91}
92
93/************************************************************************/
97{
98 struct nation_type *anination;
99 struct player *plr;
100 struct research *presearch;
101 int i;
102
103 if (wld.map.server.animals <= 0) {
104 return;
105 }
106
108
110 return;
111 }
112
114 if (plr == NULL) {
115 return;
116 }
117 /* Freeciv-web depends on AI-status being set already before server_player_init() */
118 set_as_ai(plr);
120
123
125
126 server.nbarbarians++;
127
129 plr->unassigned_user = TRUE;
130 plr->is_connected = FALSE;
132 plr->economic.gold = 100;
133
134 plr->phase_done = TRUE;
135
138
139 presearch = research_get(plr);
142
143 /* Ensure that we are at war with everyone else */
145
146 CALL_PLR_AI_FUNC(gained_control, plr, plr);
147
149 /* Send research info after player info, else the client will complain
150 * about invalid team. */
152
153 for (i = 0;
155 i++) {
156 place_animal(plr, 2 * 2 + 1 * 1);
157 }
158}
#define CALL_PLR_AI_FUNC(_func, _player,...)
Definition ai.h:377
const char * default_ai_type_name(void)
Definition aiiface.c:264
static const struct unit_type * animal_for_terrain(struct terrain *pterr)
Definition animals.c:46
void create_animals(void)
Definition animals.c:96
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:76
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:61
struct world wld
Definition game.c:62
#define fc_assert_ret(condition)
Definition log.h:192
struct tile * rand_map_pos(const struct civ_map *nmap)
Definition map.c:1228
#define circle_iterate(nmap, center_tile, sq_radius, tile_itr)
Definition map.h:398
#define circle_iterate_end
Definition map.h:401
bool can_exist_at_tile(const struct civ_map *nmap, const struct unit_type *utype, const struct tile *ptile)
Definition movement.c:289
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:234
void send_player_all_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1131
struct player * server_create_player(int player_id, const char *ai_tname, struct rgbcolor *prgbcolor, bool allow_ai_type_fallbacking)
Definition plrhand.c:1896
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:2458
void server_player_init(struct player *pplayer, bool initmap, bool needs_team)
Definition plrhand.c:1620
void assign_player_colors(void)
Definition plrhand.c:1736
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:2621
struct packet_game_info info
Definition game.h:89
int animals
Definition map_types.h:109
struct civ_map::@44::@46 server
enum ai_level skill_level
enum barbarian_type barbarian_type
Definition player.h:122
struct player_ai ai_common
Definition player.h:288
char username[MAX_LEN_NAME]
Definition player.h:252
bool is_connected
Definition player.h:296
struct government * government
Definition player.h:258
struct player_economic economic
Definition player.h:284
bool phase_done
Definition player.h:263
bool unassigned_user
Definition player.h:253
Definition tile.h:50
struct unit_list * units
Definition tile.h:58
Definition unit.h:140
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:111
#define tile_has_extra(ptile, pextra)
Definition tile.h:148
static bool is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer, bool everyone_non_allied)
Definition unit.h:440
void send_unit_info(struct conn_list *dest, struct unit *punit)
Definition unittools.c:2877
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:1605
bool utype_player_already_has_this_unique(const struct player *pplayer, const struct unit_type *putype)
Definition unittype.c:1933
#define MAP_NATIVE_WIDTH
#define MAP_NATIVE_HEIGHT