Freeciv21
Develop your civilization from humble roots to a global empire
disaster.h
Go to the documentation of this file.
1 /**************************************************************************
2  Copyright (c) 1996-2020 Freeciv21 and Freeciv contributors. This file is
3  __ __ part of Freeciv21. Freeciv21 is free software: you can
4 / \\..// \ redistribute it and/or modify it under the terms of the GNU
5  ( oo ) General Public License as published by the Free Software
6  \__/ Foundation, either version 3 of the License, or (at your
7  option) any later version. You should have received
8  a copy of the GNU General Public License along with Freeciv21. If not,
9  see https://www.gnu.org/licenses/.
10 **************************************************************************/
11 #pragma once
12 
13 #include "name_translation.h"
14 #include "requirements.h"
15 
16 // Used in the network protocol.
17 #define SPECENUM_NAME disaster_effect_id
18 #define SPECENUM_VALUE0 DE_DESTROY_BUILDING
19 #define SPECENUM_VALUE0NAME "DestroyBuilding"
20 #define SPECENUM_VALUE1 DE_REDUCE_POP
21 #define SPECENUM_VALUE1NAME "ReducePopulation"
22 #define SPECENUM_VALUE2 DE_EMPTY_FOODSTOCK
23 #define SPECENUM_VALUE2NAME "EmptyFoodStock"
24 #define SPECENUM_VALUE3 DE_EMPTY_PRODSTOCK
25 #define SPECENUM_VALUE3NAME "EmptyProdStock"
26 #define SPECENUM_VALUE4 DE_POLLUTION
27 #define SPECENUM_VALUE4NAME "Pollution"
28 #define SPECENUM_VALUE5 DE_FALLOUT
29 #define SPECENUM_VALUE5NAME "Fallout"
30 #define SPECENUM_VALUE6 DE_REDUCE_DESTROY
31 #define SPECENUM_VALUE6NAME "ReducePopDestroy"
32 #define SPECENUM_COUNT DE_COUNT
33 #define SPECENUM_BITVECTOR bv_disaster_effects
34 #include "specenum_gen.h"
35 
36 #define DISASTER_BASE_RARITY 1000000
37 
38 struct disaster_type {
39  int id;
40  struct name_translation name;
41 
42  struct requirement_vector reqs;
43 
44  /* Final probability for each city each turn is
45  * this frequency * game.info.disasters frequency setting /
46  * DISASTER_BASE_RARITY */
47  int frequency;
48 
49  bv_disaster_effects effects;
50 };
51 
52 // Initialization and iteration
53 void disaster_types_init();
54 void disaster_types_free();
55 
58 
60 
61 const char *disaster_name_translation(struct disaster_type *pdis);
62 const char *disaster_rule_name(struct disaster_type *pdis);
63 
64 bool disaster_has_effect(const struct disaster_type *pdis,
65  enum disaster_effect_id effect);
66 
67 bool can_disaster_happen(const struct disaster_type *pdis,
68  const struct city *pcity);
69 
70 #define disaster_type_iterate(_p) \
71  { \
72  int _i_; \
73  for (_i_ = 0; _i_ < game.control.num_disaster_types; _i_++) { \
74  struct disaster_type *_p = disaster_by_number(_i_);
75 
76 #define disaster_type_iterate_end \
77  } \
78  }
struct disaster_type * disaster_by_number(Disaster_type_id id)
Return disaster type of given id.
Definition: disaster.cpp:72
bool can_disaster_happen(const struct disaster_type *pdis, const struct city *pcity)
Whether disaster can happen in given city.
Definition: disaster.cpp:108
const char * disaster_rule_name(struct disaster_type *pdis)
Return untranslated name of this disaster type.
Definition: disaster.cpp:91
Disaster_type_id disaster_number(const struct disaster_type *pdis)
Return the disaster id.
Definition: disaster.cpp:49
Disaster_type_id disaster_index(const struct disaster_type *pdis)
Return the disaster index.
Definition: disaster.cpp:62
bool disaster_has_effect(const struct disaster_type *pdis, enum disaster_effect_id effect)
Check if disaster provides effect.
Definition: disaster.cpp:99
void disaster_types_init()
Initialize disaster_type structures.
Definition: disaster.cpp:27
void disaster_types_free()
Free the memory associated with disaster types.
Definition: disaster.cpp:40
const char * disaster_name_translation(struct disaster_type *pdis)
Return translated name of this disaster type.
Definition: disaster.cpp:83
int Disaster_type_id
Definition: fc_types.h:302
Definition: city.h:291
struct name_translation name
Definition: disaster.h:40
struct requirement_vector reqs
Definition: disaster.h:42
bv_disaster_effects effects
Definition: disaster.h:49
int frequency
Definition: disaster.h:47