Freeciv21
Develop your civilization from humble roots to a global empire
api_game_effects.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 1996-2020 Freeciv21 and Freeciv contributors. This file is
3  part of Freeciv21. Freeciv21 is free software: you can redistribute it
4  and/or modify it under the terms of the GNU General Public License as
5  published by the Free Software Foundation, either version 3 of the
6  License, or (at your option) any later version. You should have received
7  a copy of the GNU General Public License along with Freeciv21. If not,
8  see https://www.gnu.org/licenses/.
9  */
10 
11 // utility
12 #include "fcintl.h"
13 
14 // common
15 #include "effects.h"
16 
17 /* common/scriptcore */
18 #include "luascript.h"
19 
20 #include "api_game_effects.h"
21 
25 int api_effects_world_bonus(lua_State *L, const char *effect_type)
26 {
27  enum effect_type etype = EFT_COUNT;
28 
30  LUASCRIPT_CHECK_ARG_NIL(L, effect_type, 2, string, 0);
31 
32  etype = effect_type_by_name(effect_type, fc_strcasecmp);
33  if (!effect_type_is_valid(etype)) {
34  return 0;
35  }
36  return get_world_bonus(etype);
37 }
38 
42 int api_effects_player_bonus(lua_State *L, Player *pplayer,
43  const char *effect_type)
44 {
45  enum effect_type etype = EFT_COUNT;
46 
48  LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player, 0);
49  LUASCRIPT_CHECK_ARG_NIL(L, effect_type, 3, string, 0);
50 
51  etype = effect_type_by_name(effect_type, fc_strcasecmp);
52  if (!effect_type_is_valid(etype)) {
53  return 0;
54  }
55  return get_player_bonus(pplayer, etype);
56 }
57 
61 int api_effects_city_bonus(lua_State *L, City *pcity,
62  const char *effect_type)
63 {
64  enum effect_type etype = EFT_COUNT;
65 
67  LUASCRIPT_CHECK_ARG_NIL(L, pcity, 2, City, 0);
68  LUASCRIPT_CHECK_ARG_NIL(L, effect_type, 3, string, 0);
69 
70  etype = effect_type_by_name(effect_type, fc_strcasecmp);
71  if (!effect_type_is_valid(etype)) {
72  return 0;
73  }
74  return get_city_bonus(pcity, etype);
75 }
int api_effects_player_bonus(lua_State *L, Player *pplayer, const char *effect_type)
Returns the effect bonus for a player.
int api_effects_city_bonus(lua_State *L, City *pcity, const char *effect_type)
Returns the effect bonus at a city.
int api_effects_world_bonus(lua_State *L, const char *effect_type)
Returns the effect bonus in the world.
int get_world_bonus(enum effect_type effect_type)
Returns the effect bonus for the whole world.
Definition: effects.cpp:659
int get_city_bonus(const struct city *pcity, enum effect_type effect_type, enum vision_layer vlayer)
Returns the effect bonus at a city.
Definition: effects.cpp:688
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Returns the effect bonus for a player.
Definition: effects.cpp:673
#define LUASCRIPT_CHECK_STATE(L,...)
Definition: luascript.h:110
#define LUASCRIPT_CHECK_ARG_NIL(L, value, narg, type,...)
Definition: luascript.h:131
Definition: city.h:291
Definition: player.h:231
int fc_strcasecmp(const char *str0, const char *str1)
Compare strings like strcmp(), but ignoring case.
Definition: support.cpp:89