Freeciv-3.1
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/**********************************************************************/
29int api_effects_world_bonus(lua_State *L, const char *effect_type)
30{
31 enum effect_type etype = EFT_COUNT;
32
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/**********************************************************************/
46int api_effects_player_bonus(lua_State *L, Player *pplayer,
47 const char *effect_type)
48{
49 enum effect_type etype = EFT_COUNT;
50
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/**********************************************************************/
65int api_effects_city_bonus(lua_State *L, City *pcity,
66 const char *effect_type)
67{
68 enum effect_type etype = EFT_COUNT;
69
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/**********************************************************************/
85int 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
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 other_player,
109 etype);
110}
111
112/***********************************************************************/
118 const char *effect_type)
119{
120 enum effect_type etype = EFT_COUNT;
121
124 LUASCRIPT_CHECK_ARG_NIL(L, ptile, 3, Tile, 0);
125 LUASCRIPT_CHECK_ARG_NIL(L, effect_type, 4, string, 0);
126
127 etype = effect_type_by_name(effect_type, fc_strcasecmp);
128 if (!effect_type_is_valid(etype)) {
129 return 0;
130 }
131
132 return get_unit_vs_tile_bonus(ptile, punit, etype);
133}
int api_effects_unit_vs_tile_bonus(lua_State *L, Unit *punit, Tile *ptile, const char *effect_type)
int api_effects_player_bonus(lua_State *L, Player *pplayer, const char *effect_type)
int api_effects_city_bonus(lua_State *L, City *pcity, const char *effect_type)
int api_effects_unit_bonus(lua_State *L, Unit *punit, Player *other_player, const char *effect_type)
int api_effects_world_bonus(lua_State *L, const char *effect_type)
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:73
int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, const struct player *other_player, enum effect_type effect_type)
Definition effects.c:691
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:789
int get_unit_vs_tile_bonus(const struct tile *ptile, const struct unit *punit, enum effect_type etype)
Definition effects.c:1016
int get_world_bonus(enum effect_type effect_type)
Definition effects.c:759
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:771
#define LUASCRIPT_CHECK_STATE(L,...)
Definition luascript.h:117
#define LUASCRIPT_CHECK_ARG_NIL(L, value, narg, type,...)
Definition luascript.h:138
Definition city.h:309
Definition tile.h:49
Definition unit.h:138
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define unit_tile(_pu)
Definition unit.h:395
#define unit_owner(_pu)
Definition unit.h:394
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123