Freeciv-3.1
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#include "unittype.h"
28
29/* server */
30#include "aiiface.h"
31#include "barbarian.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
59 extra_type_by_rmcause_iterate(ERM_ENTER, pextra) {
60 if (tile_has_extra(ptile, pextra)) {
61 /* Animals should not displace huts */
62 /* FIXME: might HUT_NOTHING animals 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) || is_non_allied_unit_tile(check, plr)) {
75 return;
76 }
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/************************************************************************/
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
113 if (plr == NULL) {
114 return;
115 }
117
118 player_set_nation(plr, anination);
119 player_nation_defaults(plr, anination, TRUE);
120
122
123 server.nbarbarians++;
124
126 plr->unassigned_user = TRUE;
127 plr->is_connected = FALSE;
128 plr->government = init_government_of_nation(anination);
129 plr->economic.gold = 100;
130
131 plr->phase_done = TRUE;
132
133 set_as_ai(plr);
134 plr->ai_common.barbarian_type = ANIMAL_BARBARIAN;
136
137 presearch = research_get(plr);
138 init_tech(presearch, TRUE);
139 give_initial_techs(presearch, 0);
140
141 /* Ensure that we are at war with everyone else */
143
144 CALL_PLR_AI_FUNC(gained_control, plr, plr);
145
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);
150
151 for (i = 0;
152 i < wld.map.xsize * wld.map.ysize * wld.map.server.animals / 1000;
153 i++) {
154 place_animal(plr, 2 * 2 + 1 * 1);
155 }
156}
#define CALL_PLR_AI_FUNC(_func, _player,...)
Definition ai.h:374
const char * default_ai_type_name(void)
Definition aiiface.c:262
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:759
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:73
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:334
#define extra_type_by_rmcause_iterate(_rmcause, _extra)
Definition extras.h:329
#define _(String)
Definition fcintl.h:67
struct civ_game game
Definition game.c:57
struct world wld
Definition game.c:58
#define fc_assert_ret(condition)
Definition log.h:191
struct tile * rand_map_pos(const struct civ_map *nmap)
Definition map.c:1086
#define circle_iterate(nmap, center_tile, sq_radius, tile_itr)
Definition map.h:395
#define circle_iterate_end
Definition map.h:398
bool can_exist_at_tile(const struct civ_map *nmap, const struct unit_type *utype, const struct tile *ptile)
Definition movement.c:275
struct government * init_government_of_nation(const struct nation_type *pnation)
Definition nation.c:658
#define NO_NATION_SELECTED
Definition nation.h:29
bool player_set_nation(struct player *pplayer, struct nation_type *pnation)
Definition player.c:852
#define ANON_USER_NAME
Definition player.h:48
#define set_as_ai(plr)
Definition player.h:236
void send_player_all_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:983
struct player * server_create_player(int player_id, const char *ai_tname, struct rgbcolor *prgbcolor, bool allow_ai_type_fallbacking)
Definition plrhand.c:1723
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:2282
void server_player_init(struct player *pplayer, bool initmap, bool needs_team)
Definition plrhand.c:1450
void assign_player_colors(void)
Definition plrhand.c:1563
struct research * research_get(const struct player *pplayer)
Definition research.c:126
void player_nation_defaults(struct player *pplayer, struct nation_type *pnation, bool set_name)
Definition srv_main.c:2510
struct packet_game_info info
Definition game.h:89
int animals
Definition map_types.h:93
int xsize
Definition map_types.h:77
int ysize
Definition map_types.h:77
struct civ_map::@41::@43 server
enum ai_level skill_level
enum barbarian_type barbarian_type
Definition player.h:128
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
const struct unit_type * animal
Definition terrain.h:223
Definition tile.h:49
struct unit_list * units
Definition tile.h:57
Definition unit.h:138
struct civ_map map
#define sz_strlcpy(dest, src)
Definition support.h:167
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
void init_tech(struct research *research, bool update)
Definition techtools.c:1070
void send_research_info(const struct research *presearch, const struct conn_list *dest)
Definition techtools.c:273
void give_initial_techs(struct research *presearch, int num_random_techs)
Definition techtools.c:1162
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_terrain(_tile)
Definition tile.h:109
#define tile_has_extra(ptile, pextra)
Definition tile.h:146
static bool is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:430
void send_unit_info(struct conn_list *dest, struct unit *punit)
Definition unittools.c:2794
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:1615
bool utype_player_already_has_this_unique(const struct player *pplayer, const struct unit_type *putype)
Definition unittype.c:1979