Stop sharing requirement_unit_state_ereq().
[freeciv.git] / common / disaster.c
blobc5f2e608aecfe3eba344ce7a094be1d70d62acea
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.
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 ****************************************************************************/
14 #ifdef HAVE_CONFIG_H
15 #include <fc_config.h>
16 #endif
18 /* utility */
19 #include "fcintl.h"
21 /* common */
22 #include "fc_types.h"
23 #include "game.h"
24 #include "name_translation.h"
26 #include "disaster.h"
28 static struct disaster_type disaster_types[MAX_DISASTER_TYPES];
30 /****************************************************************************
31 Initialize disaster_type structures.
32 ****************************************************************************/
33 void disaster_types_init(void)
35 int i;
37 for (i = 0; i < ARRAY_SIZE(disaster_types); i++) {
38 disaster_types[i].id = i;
39 requirement_vector_init(&disaster_types[i].reqs);
43 /****************************************************************************
44 Free the memory associated with disaster types
45 ****************************************************************************/
46 void disaster_types_free(void)
48 disaster_type_iterate(pdis) {
49 requirement_vector_free(&pdis->reqs);
50 } disaster_type_iterate_end;
53 /**************************************************************************
54 Return the disaster id.
55 **************************************************************************/
56 Disaster_type_id disaster_number(const struct disaster_type *pdis)
58 fc_assert_ret_val(NULL != pdis, -1);
60 return pdis->id;
63 /**************************************************************************
64 Return the disaster index.
66 Currently same as disaster_number(), paired with disaster_count()
67 indicates use as an array index.
68 **************************************************************************/
69 Disaster_type_id disaster_index(const struct disaster_type *pdis)
71 fc_assert_ret_val(NULL != pdis, -1);
73 return pdis - disaster_types;
76 /**************************************************************************
77 Return the number of disaster_types.
78 **************************************************************************/
79 Disaster_type_id disaster_count(void)
81 return game.control.num_disaster_types;
84 /****************************************************************************
85 Return disaster type of given id.
86 ****************************************************************************/
87 struct disaster_type *disaster_by_number(Disaster_type_id id)
89 fc_assert_ret_val(id >= 0 && id < game.control.num_disaster_types, NULL);
91 return &disaster_types[id];
94 /****************************************************************************
95 Return translated name of this disaster type.
96 ****************************************************************************/
97 const char *disaster_name_translation(struct disaster_type *pdis)
99 return name_translation_get(&pdis->name);
102 /****************************************************************************
103 Return untranslated name of this disaster type.
104 ****************************************************************************/
105 const char *disaster_rule_name(struct disaster_type *pdis)
107 return rule_name_get(&pdis->name);
110 /****************************************************************************
111 Check if disaster provides effect
112 ****************************************************************************/
113 bool disaster_has_effect(const struct disaster_type *pdis,
114 enum disaster_effect_id effect)
116 return BV_ISSET(pdis->effects, effect);
119 /****************************************************************************
120 Whether disaster can happen in given city.
121 ****************************************************************************/
122 bool can_disaster_happen(const struct disaster_type *pdis,
123 const struct city *pcity)
125 return are_reqs_active(city_owner(pcity), NULL, pcity, NULL,
126 city_tile(pcity), NULL, NULL, NULL, NULL, NULL,
127 &pdis->reqs, RPT_POSSIBLE);