Freeciv-3.3
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/************************************************************************/
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 &(const struct req_context) {
47 .player = tile_owner(ptile),
48 },
49 &pextra->reqs, RPT_POSSIBLE);
50}
51
52/************************************************************************/
55bool can_build_base(const struct unit *punit, const struct base_type *pbase,
56 const struct tile *ptile)
57{
58 struct extra_type *pextra = base_extra_get(pbase);
59 struct player *pplayer = unit_owner(punit);
60
61 if (!can_build_extra_base(pextra, pplayer, ptile)) {
62 return FALSE;
63 }
64
65 return are_reqs_active(&(const struct req_context) {
66 .player = pplayer,
67 .tile = ptile,
68 .unit = punit,
69 .unittype = unit_type_get(punit),
70 },
71 &(const struct req_context) {
72 .player = tile_owner(ptile),
73 },
74 &pextra->reqs, RPT_CERTAIN);
75}
76
77/************************************************************************/
92
93/************************************************************************/
97{
99 return pbase->item_number;
100}
101
102/************************************************************************/
106{
107 return pbase->self;
108}
109
110/************************************************************************/
117
118/************************************************************************/
121void base_type_init(struct extra_type *pextra, int idx)
122{
123 struct base_type *pbase;
124
125 pbase = fc_malloc(sizeof(*pbase));
126
127 pextra->data.base = pbase;
128
129 pbase->item_number = idx;
130 pbase->self = pextra;
131}
132
133/************************************************************************/
137{
138}
139
140/************************************************************************/
144 const struct unit *punit,
145 const struct tile *ptile)
146{
148 struct base_type *pbase = extra_base_get(pextra);
149
150 if (type == pbase->gui_type
151 && (punit == NULL || can_build_base(punit, pbase, ptile))) {
152 return pbase;
153 }
155
156 return NULL;
157}
158
159/************************************************************************/
163{
164 return pbase->border_sq >= 0;
165}
Base_type_id base_number(const struct base_type *pbase)
Definition base.c:96
void base_type_init(struct extra_type *pextra, int idx)
Definition base.c:121
void base_types_free(void)
Definition base.c:136
bool player_can_build_base(const struct base_type *pbase, const struct player *pplayer, const struct tile *ptile)
Definition base.c:30
Base_type_id base_count(void)
Definition base.c:113
struct extra_type * base_extra_get(const struct base_type *pbase)
Definition base.c:105
struct base_type * get_base_by_gui_type(enum base_gui_type type, const struct unit *punit, const struct tile *ptile)
Definition base.c:143
bool can_build_base(const struct unit *punit, const struct base_type *pbase, const struct tile *ptile)
Definition base.c:55
struct base_type * base_by_number(const Base_type_id id)
Definition base.c:80
bool territory_claiming_base(const struct base_type *pbase)
Definition base.c:162
char * bases
Definition comments.c:39
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
bool can_build_extra_base(const struct extra_type *pextra, const struct player *pplayer, const struct tile *ptile)
Definition extras.c:413
struct extra_type_list * extra_type_list_by_cause(enum extra_cause cause)
Definition extras.c:249
#define extra_base_get(_e_)
Definition extras.h:190
#define extra_type_by_cause_iterate_end
Definition extras.h:339
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:333
@ RPT_CERTAIN
Definition fc_types.h:533
@ RPT_POSSIBLE
Definition fc_types.h:532
int Base_type_id
Definition fc_types.h:242
struct civ_game game
Definition game.c:61
GType type
Definition repodlgs.c:1313
#define fc_assert_ret_val(condition, val)
Definition log.h:195
#define fc_malloc(sz)
Definition mem.h:34
bool are_reqs_active(const struct req_context *context, const struct req_context *other_context, const struct requirement_vector *reqs, const enum req_problem_type prob_type)
Base_type_id item_number
Definition base.h:42
struct packet_ruleset_control control
Definition game.h:83
struct extra_type::@26 data
struct requirement_vector reqs
Definition extras.h:106
struct base_type * base
Definition extras.h:154
Definition tile.h:50
Definition unit.h:140
#define FALSE
Definition support.h:47
#define tile_owner(_tile)
Definition tile.h:97
#define unit_owner(_pu)
Definition unit.h:403
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123