Stop sharing requirement_unit_state_ereq().
[freeciv.git] / common / multipliers.c
blobe52a73bb36be27391f1b3d8b529258a2f58fdc53
1 /***********************************************************************
2 Freeciv - Copyright (C) 2014 Lach SÅ‚awomir
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 /* common */
19 #include "game.h"
21 #include "multipliers.h"
23 static struct multiplier multipliers[MAX_NUM_MULTIPLIERS];
25 /****************************************************************************
26 Initialize all multipliers
27 ****************************************************************************/
28 void multipliers_init(void)
30 int i;
32 for (i = 0; i < ARRAY_SIZE(multipliers); i++) {
33 name_init(&multipliers[i].name);
34 multipliers[i].helptext = NULL;
38 /****************************************************************************
39 Free all multipliers
40 ****************************************************************************/
41 void multipliers_free(void)
43 multipliers_iterate(pmul) {
44 if (pmul->helptext) {
45 strvec_destroy(pmul->helptext);
46 pmul->helptext = NULL;
48 } multipliers_iterate_end;
51 /****************************************************************************
52 Returns multiplier associated to given number
53 ****************************************************************************/
54 struct multiplier *multiplier_by_number(Multiplier_type_id id)
56 fc_assert_ret_val(id >= 0 && id < game.control.num_multipliers, NULL);
58 return &multipliers[id];
61 /****************************************************************************
62 Returns multiplier number.
63 ****************************************************************************/
64 Multiplier_type_id multiplier_number(const struct multiplier *pmul)
66 fc_assert_ret_val(NULL != pmul, -1);
68 return pmul - multipliers;
71 /****************************************************************************
72 Returns multiplier index.
74 Currently same as multiplier_number(), paired with multiplier_count()
75 indicates use as an array index.
76 ****************************************************************************/
77 Multiplier_type_id multiplier_index(const struct multiplier *pmul)
79 return multiplier_number(pmul);
82 /****************************************************************************
83 Return number of loaded multipliers in the ruleset.
84 ****************************************************************************/
85 Multiplier_type_id multiplier_count(void)
87 return game.control.num_multipliers;
90 /**************************************************************************
91 Return the (translated) name of the multiplier.
92 You don't have to free the return pointer.
93 **************************************************************************/
94 const char *multiplier_name_translation(const struct multiplier *pmul)
96 return name_translation_get(&pmul->name);
99 /**************************************************************************
100 Return the (untranslated) rule name of the multiplier.
101 You don't have to free the return pointer.
102 **************************************************************************/
103 const char *multiplier_rule_name(const struct multiplier *pmul)
105 return rule_name_get(&pmul->name);
108 /**************************************************************************
109 Returns multiplier matching rule name, or NULL if there is no multiplier
110 with such a name.
111 **************************************************************************/
112 struct multiplier *multiplier_by_rule_name(const char *name)
114 const char *qs;
116 if (name == NULL) {
117 return NULL;
120 qs = Qn_(name);
122 multipliers_iterate(pmul) {
123 if (!fc_strcasecmp(multiplier_rule_name(pmul), qs)) {
124 return pmul;
126 } multipliers_iterate_end;
128 return NULL;