Freeciv-3.2
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
24
25/************************************************************************/
39
40/************************************************************************/
44{
46 requirement_vector_free(&(pmul->reqs));
47 if (pmul->helptext) {
48 strvec_destroy(pmul->helptext);
49 pmul->helptext = NULL;
50 }
52}
53
54/************************************************************************/
63
64/************************************************************************/
68{
69 fc_assert_ret_val(NULL != pmul, -1);
70
71 return pmul - multipliers;
72}
73
74/************************************************************************/
81{
82 return multiplier_number(pmul);
83}
84
85/************************************************************************/
92
93/************************************************************************/
97const char *multiplier_name_translation(const struct multiplier *pmul)
98{
99 return name_translation_get(&pmul->name);
100}
101
102/************************************************************************/
106const char *multiplier_rule_name(const struct multiplier *pmul)
107{
108 return rule_name_get(&pmul->name);
109}
110
111/************************************************************************/
116{
117 const char *qs;
118
119 if (name == NULL) {
120 return NULL;
121 }
122
123 qs = Qn_(name);
124
125 multipliers_iterate(pmul) {
127 return pmul;
128 }
130
131 return NULL;
132}
133
134/************************************************************************/
137bool 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}
char * incite_cost
Definition comments.c:75
int int id
Definition editgui_g.h:28
struct @21::@22 reqs
@ RPT_CERTAIN
Definition fc_types.h:701
#define MAX_NUM_MULTIPLIERS
Definition fc_types.h:55
int Multiplier_type_id
Definition fc_types.h:386
#define Qn_(String)
Definition fcintl.h:89
struct civ_game game
Definition game.c:62
const char * name
Definition inputfile.c:127
#define fc_assert_ret_val(condition, val)
Definition log.h:194
const char * multiplier_rule_name(const struct multiplier *pmul)
void multipliers_free(void)
Definition multipliers.c:43
Multiplier_type_id multiplier_count(void)
Definition multipliers.c:88
const char * multiplier_name_translation(const struct multiplier *pmul)
Definition multipliers.c:97
bool multiplier_can_be_changed(struct multiplier *pmul, struct player *pplayer)
Multiplier_type_id multiplier_number(const struct multiplier *pmul)
Definition multipliers.c:67
struct multiplier * multiplier_by_rule_name(const char *name)
static struct multiplier multipliers[MAX_NUM_MULTIPLIERS]
Definition multipliers.c:23
struct multiplier * multiplier_by_number(Multiplier_type_id id)
Definition multipliers.c:57
void multipliers_init(void)
Definition multipliers.c:28
Multiplier_type_id multiplier_index(const struct multiplier *pmul)
Definition multipliers.c:80
#define multipliers_iterate(_mul_)
Definition multipliers.h:61
#define multipliers_iterate_end
Definition multipliers.h:67
static const char * rule_name_get(const struct name_translation *ptrans)
static const char * name_translation_get(const struct name_translation *ptrans)
static void name_init(struct name_translation *ptrans)
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)
#define ARRAY_SIZE(x)
Definition shared.h:85
void strvec_destroy(struct strvec *psv)
struct packet_ruleset_control control
Definition game.h:83
struct packet_game_info info
Definition game.h:89
struct requirement_vector reqs
Definition multipliers.h:42
struct strvec * helptext
Definition multipliers.h:43
int minimum_turns
Definition multipliers.h:41
bool ruledit_disabled
Definition multipliers.h:34
struct name_translation name
Definition multipliers.h:33
struct multiplier_value multipliers[MAX_NUM_MULTIPLIERS]
Definition player.h:312
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
#define FALSE
Definition support.h:47