Freeciv-3.3: /fast/freeciv/nightly/main/common/scriptcore/api_game_effects.c Source File

Freeciv-3.3

Loading...
Searching...
No Matches
api_game_effects.c
Go to the documentation of this file.
1/*****************************************************************************
2 Freeciv - Copyright (C) 2005 - The Freeciv Project
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 "effects.h"
20
21/* common/scriptcore */
22#include "luascript.h"
23
24#include "api_game_effects.h"
25
26/**********************************************************************/
29 int api_effects_world_bonus(lua_State *L, const char *effect_type)
30{
31 enum effect_type etype = EFT_COUNT;
32
33 LUASCRIPT_CHECK_STATE(L, 0);
34 LUASCRIPT_CHECK_ARG_NIL(L, effect_type, 2, string, 0);
35
36 etype = effect_type_by_name(effect_type, fc_strcasecmp);
37 if (!effect_type_is_valid(etype)) {
38 return 0;
39 }
40 return get_world_bonus(etype);
41}
42
43/**********************************************************************/
46 int api_effects_player_bonus(lua_State *L, Player *pplayer,
47 const char *effect_type)
48{
49 enum effect_type etype = EFT_COUNT;
50
51 LUASCRIPT_CHECK_STATE(L, 0);
52 LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player, 0);
53 LUASCRIPT_CHECK_ARG_NIL(L, effect_type, 3, string, 0);
54
55 etype = effect_type_by_name(effect_type, fc_strcasecmp);
56 if (!effect_type_is_valid(etype)) {
57 return 0;
58 }
59 return get_player_bonus(pplayer, etype);
60}
61
62/**********************************************************************/
65 int api_effects_city_bonus(lua_State *L, City *pcity,
66 const char *effect_type)
67{
68 enum effect_type etype = EFT_COUNT;
69
70 LUASCRIPT_CHECK_STATE(L, 0);
71 LUASCRIPT_CHECK_ARG_NIL(L, pcity, 2, City, 0);
72 LUASCRIPT_CHECK_ARG_NIL(L, effect_type, 3, string, 0);
73
74 etype = effect_type_by_name(effect_type, fc_strcasecmp);
75 if (!effect_type_is_valid(etype)) {
76 return 0;
77 }
78 return get_city_bonus(pcity, etype);
79}
80
81/**********************************************************************/
85 int api_effects_unit_bonus(lua_State *L, Unit *punit, Player *other_player,
86 const char *effect_type)
87{
88 enum effect_type etype = EFT_COUNT;
89
90 LUASCRIPT_CHECK_STATE(L, 0);
91 LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit, 0);
92 LUASCRIPT_CHECK_ARG_NIL(L, effect_type, 4, string, 0);
93
94 etype = effect_type_by_name(effect_type, fc_strcasecmp);
95 if (!effect_type_is_valid(etype)) {
96 return 0;
97 }
98
99 return get_target_bonus_effects(NULL,
100 &(const struct req_context) {
101 .player = unit_owner(punit),
102 .city = unit_tile(punit)
103 ? tile_city(unit_tile(punit)) : NULL,
104 .tile = unit_tile(punit),
105 .unit = punit,
106 .unittype = unit_type_get(punit),
107 },
108 &(const struct req_context) {
109 .player = other_player,
110 },
111 etype);
112}
113
114/***********************************************************************/
126 int api_effects_tile_bonus(lua_State *L, Tile *ptile, City *pcity,
127 const char *output_id, const char *effect_type)
128{
129 const struct player *pplayer;
130 const struct output_type *poutput = NULL;
131 enum effect_type etype;
132
133 LUASCRIPT_CHECK_STATE(L, 0);
134 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 2, Tile, 0);
135 LUASCRIPT_CHECK_ARG_NIL(L, effect_type, 5, string, 0);
136
137 etype = effect_type_by_name(effect_type, fc_strcasecmp);
138 if (!effect_type_is_valid(etype)) {
139 return 0;
140 }
141
142 if (output_id != NULL) {
143 enum output_type_id id = output_type_by_identifier(output_id);
144
145 if (id != O_LAST) {
146 poutput = get_output_type(id);
147 } else {
148 log_warn(_("Unknown output identifier \"%s\""), output_id);
149 }
150 }
151
152 pplayer = (pcity != NULL ? city_owner(pcity) : NULL);
153
154 return get_target_bonus_effects(NULL,
155 &(const struct req_context) {
156 .player = pplayer,
157 .city = pcity,
158 .tile = ptile,
159 .output = poutput,
160 },
161 NULL,
162 etype);
163}
164
165/***********************************************************************/
170 int api_effects_unit_vs_tile_bonus(lua_State *L, Unit *punit, Tile *ptile,
171 const char *effect_type)
172{
173 enum effect_type etype = EFT_COUNT;
174
175 LUASCRIPT_CHECK_STATE(L, 0);
176 LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit, 0);
177 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 3, Tile, 0);
178 LUASCRIPT_CHECK_ARG_NIL(L, effect_type, 4, string, 0);
179
180 etype = effect_type_by_name(effect_type, fc_strcasecmp);
181 if (!effect_type_is_valid(etype)) {
182 return 0;
183 }
184
185 return get_unit_vs_tile_bonus(ptile, punit, etype);
186}
api_effects_tile_bonus
int api_effects_tile_bonus(lua_State *L, Tile *ptile, City *pcity, const char *output_id, const char *effect_type)
Definition api_game_effects.c:126
api_effects_unit_vs_tile_bonus
int api_effects_unit_vs_tile_bonus(lua_State *L, Unit *punit, Tile *ptile, const char *effect_type)
Definition api_game_effects.c:170
api_effects_player_bonus
int api_effects_player_bonus(lua_State *L, Player *pplayer, const char *effect_type)
Definition api_game_effects.c:46
api_effects_city_bonus
int api_effects_city_bonus(lua_State *L, City *pcity, const char *effect_type)
Definition api_game_effects.c:65
api_effects_unit_bonus
int api_effects_unit_bonus(lua_State *L, Unit *punit, Player *other_player, const char *effect_type)
Definition api_game_effects.c:85
api_effects_world_bonus
int api_effects_world_bonus(lua_State *L, const char *effect_type)
Definition api_game_effects.c:29
api_game_effects.h
output_type_by_identifier
Output_type_id output_type_by_identifier(const char *id)
Definition city.c:647
get_output_type
struct output_type * get_output_type(Output_type_id output)
Definition city.c:638
city_owner
#define city_owner(_pcity_)
Definition city.h:563
incite_cost
char * incite_cost
Definition comments.c:74
punit
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
get_city_bonus
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:842
get_unit_vs_tile_bonus
int get_unit_vs_tile_bonus(const struct tile *ptile, const struct unit *punit, enum effect_type etype)
Definition effects.c:1090
get_target_bonus_effects
int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, const struct req_context *other_context, enum effect_type effect_type)
Definition effects.c:744
get_world_bonus
int get_world_bonus(enum effect_type effect_type)
Definition effects.c:812
get_player_bonus
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:824
effects.h
output_type_id
output_type_id
Definition fc_types.h:100
O_LAST
@ O_LAST
Definition fc_types.h:101
_
#define _(String)
Definition fcintl.h:67
log_warn
#define log_warn(message,...)
Definition log.h:105
luascript.h
LUASCRIPT_CHECK_STATE
#define LUASCRIPT_CHECK_STATE(L,...)
Definition luascript.h:117
LUASCRIPT_CHECK_ARG_NIL
#define LUASCRIPT_CHECK_ARG_NIL(L, value, narg, type,...)
Definition luascript.h:138
city
Definition city.h:320
city::tile
struct tile * tile
Definition city.h:322
output_type
Definition city.h:259
player
Definition player.h:249
req_context
Definition requirements.h:100
tile
Definition tile.h:50
unit
Definition unit.h:140
fc_strcasecmp
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:186
tile_city
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
unit_tile
#define unit_tile(_pu)
Definition unit.h:397
unit_owner
#define unit_owner(_pu)
Definition unit.h:396
unit_type_get
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123