Freeciv-3.1: /fast/freeciv/nightly/S3_1/common/base.c Source File

Freeciv-3.1

Loading...
Searching...
No Matches
base.c
Go to the documentation of this file.
1/****************************************************************************
2 Freeciv - Copyright (C) 2004 - The Freeciv 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 "extras.h"
20#include "game.h"
21#include "map.h"
22#include "tile.h"
23#include "unit.h"
24
25#include "base.h"
26
27/************************************************************************/
30 bool player_can_build_base(const struct base_type *pbase,
31 const struct player *pplayer,
32 const struct tile *ptile)
33{
34 struct extra_type *pextra;
35
36 if (!can_build_extra_base(base_extra_get(pbase), pplayer, ptile)) {
37 return FALSE;
38 }
39
40 pextra = base_extra_get(pbase);
41
42 return are_reqs_active(&(const struct req_context) {
43 .player = pplayer,
44 .tile = ptile,
45 },
46 tile_owner(ptile),
47 &pextra->reqs, RPT_POSSIBLE);
48}
49
50/************************************************************************/
53 bool can_build_base(const struct unit *punit, const struct base_type *pbase,
54 const struct tile *ptile)
55{
56 struct extra_type *pextra = base_extra_get(pbase);
57 struct player *pplayer = unit_owner(punit);
58
59 if (!can_build_extra_base(pextra, pplayer, ptile)) {
60 return FALSE;
61 }
62
63 return are_reqs_active(&(const struct req_context) {
64 .player = pplayer,
65 .tile = ptile,
66 .unit = punit,
67 .unittype = unit_type_get(punit),
68 },
69 tile_owner(ptile),
70 &pextra->reqs, RPT_CERTAIN);
71}
72
73/************************************************************************/
76 struct base_type *base_by_number(const Base_type_id id)
77{
78 struct extra_type_list *bases;
79
80 bases = extra_type_list_by_cause(EC_BASE);
81
82 if (bases == NULL || id < 0 || id >= extra_type_list_size(bases)) {
83 return NULL;
84 }
85
86 return extra_base_get(extra_type_list_get(bases, id));
87}
88
89/************************************************************************/
92 Base_type_id base_number(const struct base_type *pbase)
93{
94 fc_assert_ret_val(NULL != pbase, -1);
95 return pbase->item_number;
96}
97
98/************************************************************************/
101 struct extra_type *base_extra_get(const struct base_type *pbase)
102{
103 return pbase->self;
104}
105
106/************************************************************************/
109 Base_type_id base_count(void)
110{
111 return game.control.num_base_types;
112}
113
114/************************************************************************/
117 void base_type_init(struct extra_type *pextra, int idx)
118{
119 struct base_type *pbase;
120
121 pbase = fc_malloc(sizeof(*pbase));
122
123 pextra->data.base = pbase;
124
125 pbase->item_number = idx;
126 pbase->self = pextra;
127}
128
129/************************************************************************/
132 void base_types_free(void)
133{
134}
135
136/************************************************************************/
139 struct base_type *get_base_by_gui_type(enum base_gui_type type,
140 const struct unit *punit,
141 const struct tile *ptile)
142{
143 extra_type_by_cause_iterate(EC_BASE, pextra) {
144 struct base_type *pbase = extra_base_get(pextra);
145
146 if (type == pbase->gui_type
147 && (punit == NULL || can_build_base(punit, pbase, ptile))) {
148 return pbase;
149 }
150 } extra_type_by_cause_iterate_end;
151
152 return NULL;
153}
154
155/************************************************************************/
158 bool territory_claiming_base(const struct base_type *pbase)
159{
160 return pbase->border_sq >= 0;
161}
base_number
Base_type_id base_number(const struct base_type *pbase)
Definition base.c:92
base_type_init
void base_type_init(struct extra_type *pextra, int idx)
Definition base.c:117
base_types_free
void base_types_free(void)
Definition base.c:132
player_can_build_base
bool player_can_build_base(const struct base_type *pbase, const struct player *pplayer, const struct tile *ptile)
Definition base.c:30
base_count
Base_type_id base_count(void)
Definition base.c:109
base_extra_get
struct extra_type * base_extra_get(const struct base_type *pbase)
Definition base.c:101
get_base_by_gui_type
struct base_type * get_base_by_gui_type(enum base_gui_type type, const struct unit *punit, const struct tile *ptile)
Definition base.c:139
can_build_base
bool can_build_base(const struct unit *punit, const struct base_type *pbase, const struct tile *ptile)
Definition base.c:53
base_by_number
struct base_type * base_by_number(const Base_type_id id)
Definition base.c:76
territory_claiming_base
bool territory_claiming_base(const struct base_type *pbase)
Definition base.c:158
base.h
bases
char * bases
Definition comments.c:37
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:73
can_build_extra_base
bool can_build_extra_base(const struct extra_type *pextra, const struct player *pplayer, const struct tile *ptile)
Definition extras.c:387
extra_type_list_by_cause
struct extra_type_list * extra_type_list_by_cause(enum extra_cause cause)
Definition extras.c:241
extras.h
extra_base_get
#define extra_base_get(_e_)
Definition extras.h:184
extra_type_by_cause_iterate_end
#define extra_type_by_cause_iterate_end
Definition extras.h:315
extra_type_by_cause_iterate
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:309
RPT_CERTAIN
@ RPT_CERTAIN
Definition fc_types.h:586
RPT_POSSIBLE
@ RPT_POSSIBLE
Definition fc_types.h:585
Base_type_id
int Base_type_id
Definition fc_types.h:353
game
struct civ_game game
Definition game.c:57
game.h
type
GType type
Definition repodlgs.c:1312
fc_assert_ret_val
#define fc_assert_ret_val(condition, val)
Definition log.h:194
map.h
fc_malloc
#define fc_malloc(sz)
Definition mem.h:34
are_reqs_active
bool are_reqs_active(const struct req_context *context, const struct player *other_player, const struct requirement_vector *reqs, const enum req_problem_type prob_type)
Definition requirements.c:4361
base_type
Definition base.h:41
base_type::border_sq
int border_sq
Definition base.h:44
base_type::gui_type
enum base_gui_type gui_type
Definition base.h:43
base_type::self
struct extra_type * self
Definition base.h:49
base_type::item_number
Base_type_id item_number
Definition base.h:42
civ_game::control
struct packet_ruleset_control control
Definition game.h:83
extra_type
Definition extras.h:85
extra_type::data
struct extra_type::@24 data
extra_type::reqs
struct requirement_vector reqs
Definition extras.h:102
extra_type::base
struct base_type * base
Definition extras.h:148
packet_ruleset_control::num_base_types
int num_base_types
Definition packets_gen.h:1461
player
Definition player.h:249
req_context
Definition requirements.h:99
tile
Definition tile.h:49
unit
Definition unit.h:138
FALSE
#define FALSE
Definition support.h:47
tile.h
tile_owner
#define tile_owner(_tile)
Definition tile.h:95
unit.h
unit_owner
#define unit_owner(_pu)
Definition unit.h:387
unit_type_get
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123