Freeciv-3.3: /fast/freeciv/nightly/main/common/disaster.c Source File

Freeciv-3.3

Loading...
Searching...
No Matches
disaster.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/* utility */
19#include "fcintl.h"
20
21/* common */
22#include "fc_types.h"
23#include "game.h"
24#include "name_translation.h"
25
26#include "disaster.h"
27
28 static struct disaster_type disaster_types[MAX_DISASTER_TYPES];
29
30/************************************************************************/
33 void disaster_types_init(void)
34{
35 int i;
36
37 for (i = 0; i < ARRAY_SIZE(disaster_types); i++) {
38 disaster_types[i].id = i;
39 requirement_vector_init(&disaster_types[i].reqs);
40 }
41}
42
43/************************************************************************/
46 void disaster_types_free(void)
47{
48 disaster_type_iterate(pdis) {
49 requirement_vector_free(&pdis->reqs);
50 } disaster_type_iterate_end;
51}
52
53/************************************************************************/
56 Disaster_type_id disaster_number(const struct disaster_type *pdis)
57{
58 fc_assert_ret_val(NULL != pdis, -1);
59
60 return pdis->id;
61}
62
63/************************************************************************/
69 Disaster_type_id disaster_index(const struct disaster_type *pdis)
70{
71 fc_assert_ret_val(NULL != pdis, -1);
72
73 return pdis - disaster_types;
74}
75
76/************************************************************************/
79 Disaster_type_id disaster_count(void)
80{
81 return game.control.num_disaster_types;
82}
83
84/************************************************************************/
87 struct disaster_type *disaster_by_number(Disaster_type_id id)
88{
89 fc_assert_ret_val(id >= 0 && id < game.control.num_disaster_types, NULL);
90
91 return &disaster_types[id];
92}
93
94/************************************************************************/
97 const char *disaster_name_translation(struct disaster_type *pdis)
98{
99 return name_translation_get(&pdis->name);
100}
101
102/************************************************************************/
105 const char *disaster_rule_name(struct disaster_type *pdis)
106{
107 return rule_name_get(&pdis->name);
108}
109
110/************************************************************************/
114 struct disaster_type *disaster_by_rule_name(const char *name)
115{
116 const char *qs = Qn_(name);
117
118 disaster_type_iterate(pdis) {
119 if (!fc_strcasecmp(disaster_rule_name(pdis), qs)) {
120 return pdis;
121 }
122 } disaster_type_iterate_end;
123
124 return NULL;
125}
126
127/************************************************************************/
130 bool disaster_has_effect(const struct disaster_type *pdis,
131 enum disaster_effect_id effect)
132{
133 return BV_ISSET(pdis->effects, effect);
134}
135
136/************************************************************************/
139 bool can_disaster_happen(const struct disaster_type *pdis,
140 const struct city *pcity)
141{
142 return are_reqs_active(&(const struct req_context) {
143 .player = city_owner(pcity),
144 .city = pcity,
145 .tile = city_tile(pcity),
146 },
147 NULL,
148 &pdis->reqs, RPT_POSSIBLE);
149}
BV_ISSET
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
city_tile
#define city_tile(_pcity_)
Definition city.h:564
city_owner
#define city_owner(_pcity_)
Definition city.h:563
incite_cost
char * incite_cost
Definition comments.c:74
disaster_rule_name
const char * disaster_rule_name(struct disaster_type *pdis)
Definition disaster.c:105
can_disaster_happen
bool can_disaster_happen(const struct disaster_type *pdis, const struct city *pcity)
Definition disaster.c:139
disaster_types
static struct disaster_type disaster_types[MAX_DISASTER_TYPES]
Definition disaster.c:28
disaster_number
Disaster_type_id disaster_number(const struct disaster_type *pdis)
Definition disaster.c:56
disaster_index
Disaster_type_id disaster_index(const struct disaster_type *pdis)
Definition disaster.c:69
disaster_by_rule_name
struct disaster_type * disaster_by_rule_name(const char *name)
Definition disaster.c:114
disaster_name_translation
const char * disaster_name_translation(struct disaster_type *pdis)
Definition disaster.c:97
disaster_by_number
struct disaster_type * disaster_by_number(Disaster_type_id id)
Definition disaster.c:87
disaster_count
Disaster_type_id disaster_count(void)
Definition disaster.c:79
disaster_has_effect
bool disaster_has_effect(const struct disaster_type *pdis, enum disaster_effect_id effect)
Definition disaster.c:130
disaster_types_init
void disaster_types_init(void)
Definition disaster.c:33
disaster_types_free
void disaster_types_free(void)
Definition disaster.c:46
disaster.h
disaster_type_iterate
#define disaster_type_iterate(_p)
Definition disaster.h:82
disaster_type_iterate_end
#define disaster_type_iterate_end
Definition disaster.h:88
id
int int id
Definition editgui_g.h:28
reqs
struct @21::@22 reqs
fc_types.h
MAX_DISASTER_TYPES
#define MAX_DISASTER_TYPES
Definition fc_types.h:52
RPT_POSSIBLE
@ RPT_POSSIBLE
Definition fc_types.h:707
Disaster_type_id
int Disaster_type_id
Definition fc_types.h:389
fcintl.h
Qn_
#define Qn_(String)
Definition fcintl.h:89
game
struct civ_game game
Definition game.c:62
game.h
name
const char * name
Definition inputfile.c:127
fc_assert_ret_val
#define fc_assert_ret_val(condition, val)
Definition log.h:194
name_translation.h
rule_name_get
static const char * rule_name_get(const struct name_translation *ptrans)
Definition name_translation.h:112
name_translation_get
static const char * name_translation_get(const struct name_translation *ptrans)
Definition name_translation.h:121
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:5705
ARRAY_SIZE
#define ARRAY_SIZE(x)
Definition shared.h:85
city
Definition city.h:320
city::tile
struct tile * tile
Definition city.h:322
civ_game::control
struct packet_ruleset_control control
Definition game.h:83
disaster_type
Definition disaster.h:48
disaster_type::id
int id
Definition disaster.h:49
effect
Definition effects.h:40
packet_ruleset_control::num_disaster_types
int num_disaster_types
Definition packets_gen.h:1468
req_context
Definition requirements.h:100
fc_strcasecmp
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:186