1 /**********************************************************************
2  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
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 #ifndef FC__DISASTER_H
14 #define FC__DISASTER_H
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif /* __cplusplus */
19 
20 /* common */
21 #include "name_translation.h"
22 #include "requirements.h"
23 
24 /* Used in the network protocol. */
25 #define SPECENUM_NAME disaster_effect_id
26 #define SPECENUM_VALUE0 DE_DESTROY_BUILDING
27 #define SPECENUM_VALUE0NAME "DestroyBuilding"
28 #define SPECENUM_VALUE1 DE_REDUCE_POP
29 #define SPECENUM_VALUE1NAME "ReducePopulation"
30 #define SPECENUM_VALUE2 DE_EMPTY_FOODSTOCK
31 #define SPECENUM_VALUE2NAME "EmptyFoodStock"
32 #define SPECENUM_VALUE3 DE_EMPTY_PRODSTOCK
33 #define SPECENUM_VALUE3NAME "EmptyProdStock"
34 #define SPECENUM_VALUE4 DE_POLLUTION
35 #define SPECENUM_VALUE4NAME "Pollution"
36 #define SPECENUM_VALUE5 DE_FALLOUT
37 #define SPECENUM_VALUE5NAME "Fallout"
38 #define SPECENUM_VALUE6 DE_REDUCE_DESTROY
39 #define SPECENUM_VALUE6NAME "ReducePopDestroy"
40 #define SPECENUM_COUNT DE_COUNT
41 #define SPECENUM_BITVECTOR bv_disaster_effects
42 #include "specenum_gen.h"
43 
44 #define DISASTER_BASE_RARITY 1000000
45 
46 struct disaster_type {
47   int id;
48   struct name_translation name;
49 
50   struct requirement_vector reqs;
51 
52   /* Final probability for each city each turn is
53    * this frequency * game.info.disasters frequency setting / DISASTER_BASE_RARITY */
54   int frequency;
55 
56   bv_disaster_effects effects;
57 };
58 
59 /* Initialization and iteration */
60 void disaster_types_init(void);
61 void disaster_types_free(void);
62 
63 /* General disaster type accessor functions. */
64 Disaster_type_id disaster_count(void);
65 Disaster_type_id disaster_index(const struct disaster_type *pdis);
66 Disaster_type_id disaster_number(const struct disaster_type *proad);
67 
68 struct disaster_type *disaster_by_number(Disaster_type_id id);
69 
70 const char *disaster_name_translation(struct disaster_type *pdis);
71 const char *disaster_rule_name(struct disaster_type *pdis);
72 
73 bool disaster_has_effect(const struct disaster_type *pdis,
74                          enum disaster_effect_id effect);
75 
76 bool can_disaster_happen(const struct disaster_type *pdis,
77                          const struct city *pcity);
78 
79 #define disaster_type_iterate(_p)                                \
80 {                                                                \
81   int _i_;                                                       \
82   for (_i_ = 0; _i_ < game.control.num_disaster_types ; _i_++) { \
83     struct disaster_type *_p = disaster_by_number(_i_);
84 
85 #define disaster_type_iterate_end                       \
86   }}
87 
88 #ifdef __cplusplus
89 }
90 #endif /* __cplusplus */
91 
92 #endif  /* FC__DISASTER_H */
93