File: disaster.c

package info (click to toggle)
freeciv 2.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 212,508 kB
  • sloc: ansic: 443,831; cpp: 29,541; sh: 7,982; makefile: 7,886; python: 1,933; xml: 945
file content (128 lines) | stat: -rw-r--r-- 4,535 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/****************************************************************************
 Freeciv - Copyright (C) 2004 - The Freeciv Team
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
****************************************************************************/

#ifdef HAVE_CONFIG_H
#include <fc_config.h>
#endif

/* utility */
#include "fcintl.h"

/* common */
#include "fc_types.h"
#include "game.h"
#include "name_translation.h"

#include "disaster.h"

static struct disaster_type disaster_types[MAX_DISASTER_TYPES];

/****************************************************************************
  Initialize disaster_type structures.
****************************************************************************/
void disaster_types_init(void)
{
  int i;

  for (i = 0; i < ARRAY_SIZE(disaster_types); i++) {
    disaster_types[i].id = i;
    requirement_vector_init(&disaster_types[i].reqs);
  }
}

/****************************************************************************
  Free the memory associated with disaster types
****************************************************************************/
void disaster_types_free(void)
{
  disaster_type_iterate(pdis) {
    requirement_vector_free(&pdis->reqs);
  } disaster_type_iterate_end;
}

/**************************************************************************
  Return the disaster id.
**************************************************************************/
Disaster_type_id disaster_number(const struct disaster_type *pdis)
{
  fc_assert_ret_val(NULL != pdis, -1);

  return pdis->id;
}

/**************************************************************************
  Return the disaster index.

  Currently same as disaster_number(), paired with disaster_count()
  indicates use as an array index.
**************************************************************************/
Disaster_type_id disaster_index(const struct disaster_type *pdis)
{
  fc_assert_ret_val(NULL != pdis, -1);

  return pdis - disaster_types;
}

/**************************************************************************
  Return the number of disaster_types.
**************************************************************************/
Disaster_type_id disaster_count(void)
{
  return game.control.num_disaster_types;
}

/****************************************************************************
  Return disaster type of given id.
****************************************************************************/
struct disaster_type *disaster_by_number(Disaster_type_id id)
{
  fc_assert_ret_val(id >= 0 && id < game.control.num_disaster_types, NULL);

  return &disaster_types[id];
}

/****************************************************************************
  Return translated name of this disaster type.
****************************************************************************/
const char *disaster_name_translation(struct disaster_type *pdis)
{
  return name_translation_get(&pdis->name);
}

/****************************************************************************
  Return untranslated name of this disaster type.
****************************************************************************/
const char *disaster_rule_name(struct disaster_type *pdis)
{
  return rule_name_get(&pdis->name);
}

/****************************************************************************
  Check if disaster provides effect
****************************************************************************/
bool disaster_has_effect(const struct disaster_type *pdis,
                         enum disaster_effect_id effect)
{
  return BV_ISSET(pdis->effects, effect);
}

/****************************************************************************
  Whether disaster can happen in given city.
****************************************************************************/
bool can_disaster_happen(const struct disaster_type *pdis,
                         const struct city *pcity)
{
  return are_reqs_active(city_owner(pcity), NULL, pcity, NULL,
                         city_tile(pcity), NULL, NULL, NULL, NULL,
                         &pdis->reqs, RPT_POSSIBLE);
}