Freeciv-3.1: /fast/freeciv/nightly/S3_1/common/multipliers.c Source File

Freeciv-3.1

Loading...
Searching...
No Matches
multipliers.c
Go to the documentation of this file.
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.
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
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* common */
19#include "game.h"
20
21#include "multipliers.h"
22
23 static struct multiplier multipliers[MAX_NUM_MULTIPLIERS];
24
25/************************************************************************/
28 void multipliers_init(void)
29{
30 int i;
31
32 for (i = 0; i < ARRAY_SIZE(multipliers); i++) {
33 name_init(&multipliers[i].name);
34 requirement_vector_init(&multipliers[i].reqs);
35 multipliers[i].ruledit_disabled = FALSE;
36 multipliers[i].helptext = NULL;
37 }
38}
39
40/************************************************************************/
43 void multipliers_free(void)
44{
45 multipliers_iterate(pmul) {
46 requirement_vector_free(&(pmul->reqs));
47 if (pmul->helptext) {
48 strvec_destroy(pmul->helptext);
49 pmul->helptext = NULL;
50 }
51 } multipliers_iterate_end;
52}
53
54/************************************************************************/
57 struct multiplier *multiplier_by_number(Multiplier_type_id id)
58{
59 fc_assert_ret_val(id >= 0 && id < game.control.num_multipliers, NULL);
60
61 return &multipliers[id];
62}
63
64/************************************************************************/
67 Multiplier_type_id multiplier_number(const struct multiplier *pmul)
68{
69 fc_assert_ret_val(NULL != pmul, -1);
70
71 return pmul - multipliers;
72}
73
74/************************************************************************/
80 Multiplier_type_id multiplier_index(const struct multiplier *pmul)
81{
82 return multiplier_number(pmul);
83}
84
85/************************************************************************/
88 Multiplier_type_id multiplier_count(void)
89{
90 return game.control.num_multipliers;
91}
92
93/************************************************************************/
97 const char *multiplier_name_translation(const struct multiplier *pmul)
98{
99 return name_translation_get(&pmul->name);
100}
101
102/************************************************************************/
106 const char *multiplier_rule_name(const struct multiplier *pmul)
107{
108 return rule_name_get(&pmul->name);
109}
110
111/************************************************************************/
115 struct multiplier *multiplier_by_rule_name(const char *name)
116{
117 const char *qs;
118
119 if (name == NULL) {
120 return NULL;
121 }
122
123 qs = Qn_(name);
124
125 multipliers_iterate(pmul) {
126 if (!fc_strcasecmp(multiplier_rule_name(pmul), qs)) {
127 return pmul;
128 }
129 } multipliers_iterate_end;
130
131 return NULL;
132}
133
134/************************************************************************/
137 bool multiplier_can_be_changed(struct multiplier *pmul, struct player *pplayer)
138{
139 int idx = multiplier_index(pmul);
140
141 if (pplayer->multipliers[idx].changed > 0) {
142 /* It has been changed in the past, so require minimum_turns to have passed. */
143 if (game.info.turn - pplayer->multipliers[idx].changed < pmul->minimum_turns) {
144 return FALSE;
145 }
146 }
147
148 return are_reqs_active(&(const struct req_context) { .player = pplayer },
149 NULL, &pmul->reqs, RPT_CERTAIN);
150}
id
int int id
Definition editgui_g.h:28
reqs
struct @21::@22 reqs
RPT_CERTAIN
@ RPT_CERTAIN
Definition fc_types.h:586
MAX_NUM_MULTIPLIERS
#define MAX_NUM_MULTIPLIERS
Definition fc_types.h:55
Multiplier_type_id
int Multiplier_type_id
Definition fc_types.h:356
Qn_
#define Qn_(String)
Definition fcintl.h:89
game
struct civ_game game
Definition game.c:57
game.h
name
const char * name
Definition inputfile.c:127
fc_assert_ret_val
#define fc_assert_ret_val(condition, val)
Definition log.h:194
multiplier_rule_name
const char * multiplier_rule_name(const struct multiplier *pmul)
Definition multipliers.c:106
multipliers_free
void multipliers_free(void)
Definition multipliers.c:43
multiplier_count
Multiplier_type_id multiplier_count(void)
Definition multipliers.c:88
multiplier_name_translation
const char * multiplier_name_translation(const struct multiplier *pmul)
Definition multipliers.c:97
multiplier_can_be_changed
bool multiplier_can_be_changed(struct multiplier *pmul, struct player *pplayer)
Definition multipliers.c:137
multiplier_number
Multiplier_type_id multiplier_number(const struct multiplier *pmul)
Definition multipliers.c:67
multiplier_by_rule_name
struct multiplier * multiplier_by_rule_name(const char *name)
Definition multipliers.c:115
multipliers
static struct multiplier multipliers[MAX_NUM_MULTIPLIERS]
Definition multipliers.c:23
multiplier_by_number
struct multiplier * multiplier_by_number(Multiplier_type_id id)
Definition multipliers.c:57
multipliers_init
void multipliers_init(void)
Definition multipliers.c:28
multiplier_index
Multiplier_type_id multiplier_index(const struct multiplier *pmul)
Definition multipliers.c:80
multipliers.h
multipliers_iterate
#define multipliers_iterate(_mul_)
Definition multipliers.h:61
multipliers_iterate_end
#define multipliers_iterate_end
Definition multipliers.h:67
rule_name_get
static const char * rule_name_get(const struct name_translation *ptrans)
Definition name_translation.h:112
name_translation_get
static const char * name_translation_get(const struct name_translation *ptrans)
Definition name_translation.h:121
name_init
static void name_init(struct name_translation *ptrans)
Definition name_translation.h:49
are_reqs_active
bool are_reqs_active(const struct req_context *context, const struct player *other_player, const struct requirement_vector *reqs, const enum req_problem_type prob_type)
Definition requirements.c:4361
ARRAY_SIZE
#define ARRAY_SIZE(x)
Definition shared.h:85
strvec_destroy
void strvec_destroy(struct strvec *psv)
Definition string_vector.c:71
civ_game::control
struct packet_ruleset_control control
Definition game.h:83
civ_game::info
struct packet_game_info info
Definition game.h:89
multiplier_value::changed
int changed
Definition player.h:245
multiplier
Definition multipliers.h:31
multiplier::reqs
struct requirement_vector reqs
Definition multipliers.h:42
multiplier::helptext
struct strvec * helptext
Definition multipliers.h:43
multiplier::minimum_turns
int minimum_turns
Definition multipliers.h:41
multiplier::ruledit_disabled
bool ruledit_disabled
Definition multipliers.h:34
multiplier::name
struct name_translation name
Definition multipliers.h:33
packet_game_info::turn
int turn
Definition packets_gen.h:241
packet_ruleset_control::num_multipliers
int num_multipliers
Definition packets_gen.h:1467
player
Definition player.h:249
player::multipliers
struct multiplier_value multipliers[MAX_NUM_MULTIPLIERS]
Definition player.h:310
req_context
Definition requirements.h:99
fc_strcasecmp
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
FALSE
#define FALSE
Definition support.h:47