Freeciv21
Develop your civilization from humble roots to a global empire
api_server_game_methods.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
4 / \\..// \ redistribute it and/or modify it under the terms of the GNU
5  ( oo ) General Public License as published by the Free Software
6  \__/ Foundation, either version 3 of the License, or (at your
7  option) any later version. You should have received
8  a copy of the GNU General Public License along with Freeciv21. If not,
9  see https://www.gnu.org/licenses/.
10  */
11 
12 // utility
13 #include "fcintl.h"
14 
15 /* common/scriptcore */
16 #include "luascript.h"
17 
18 // ai
19 #include "aitraits.h" // ai_trait_get_value()
20 
21 /* server/scripting */
22 #include "script_server.h"
23 
25 
29 int api_methods_player_trait(lua_State *L, Player *pplayer,
30  const char *tname)
31 {
32  enum trait tr;
33 
34  LUASCRIPT_CHECK_STATE(L, -1);
35  LUASCRIPT_CHECK_SELF(L, pplayer, -1);
36  LUASCRIPT_CHECK_ARG_NIL(L, tname, 3, string, 0);
37 
38  tr = trait_by_name(tname, fc_strcasecmp);
39 
40  LUASCRIPT_CHECK_ARG(L, trait_is_valid(tr), 3, "no such trait", 0);
41 
42  return ai_trait_get_value(tr, pplayer);
43 }
44 
48 int api_methods_player_trait_base(lua_State *L, Player *pplayer,
49  const char *tname)
50 {
51  enum trait tr;
52 
53  LUASCRIPT_CHECK_STATE(L, -1);
54  LUASCRIPT_CHECK_SELF(L, pplayer, -1);
55  LUASCRIPT_CHECK_ARG_NIL(L, tname, 3, string, 0);
56 
57  tr = trait_by_name(tname, fc_strcasecmp);
58 
59  LUASCRIPT_CHECK_ARG(L, trait_is_valid(tr), 3, "no such trait", 0);
60 
61  return pplayer->ai_common.traits[tr].val;
62 }
63 
68 int api_methods_player_trait_current_mod(lua_State *L, Player *pplayer,
69  const char *tname)
70 {
71  enum trait tr;
72 
73  LUASCRIPT_CHECK_STATE(L, -1);
74  LUASCRIPT_CHECK_SELF(L, pplayer, -1);
75  LUASCRIPT_CHECK_ARG_NIL(L, tname, 3, string, 0);
76 
77  tr = trait_by_name(tname, fc_strcasecmp);
78 
79  LUASCRIPT_CHECK_ARG(L, trait_is_valid(tr), 3, "no such trait", 0);
80 
81  return pplayer->ai_common.traits[tr].mod;
82 }
83 
87 int api_methods_nation_trait_min(lua_State *L, Nation_Type *pnation,
88  const char *tname)
89 {
90  enum trait tr;
91 
92  LUASCRIPT_CHECK_STATE(L, -1);
93  LUASCRIPT_CHECK_SELF(L, pnation, -1);
94  LUASCRIPT_CHECK_ARG_NIL(L, tname, 3, string, 0);
95 
96  tr = trait_by_name(tname, fc_strcasecmp);
97 
98  LUASCRIPT_CHECK_ARG(L, trait_is_valid(tr), 3, "no such trait", 0);
99 
100  return pnation->server.traits[tr].min;
101 }
102 
106 int api_methods_nation_trait_max(lua_State *L, Nation_Type *pnation,
107  const char *tname)
108 {
109  enum trait tr;
110 
111  LUASCRIPT_CHECK_STATE(L, -1);
112  LUASCRIPT_CHECK_SELF(L, pnation, -1);
113  LUASCRIPT_CHECK_ARG_NIL(L, tname, 3, string, 0);
114 
115  tr = trait_by_name(tname, fc_strcasecmp);
116 
117  LUASCRIPT_CHECK_ARG(L, trait_is_valid(tr), 3, "no such trait", 0);
118 
119  return pnation->server.traits[tr].max;
120 }
121 
126  const char *tname)
127 {
128  enum trait tr;
129 
130  LUASCRIPT_CHECK_STATE(L, -1);
131  LUASCRIPT_CHECK_SELF(L, pnation, -1);
132  LUASCRIPT_CHECK_ARG_NIL(L, tname, 3, string, 0);
133 
134  tr = trait_by_name(tname, fc_strcasecmp);
135 
136  LUASCRIPT_CHECK_ARG(L, trait_is_valid(tr), 3, "no such trait", 0);
137 
138  return pnation->server.traits[tr].fixed;
139 }
int ai_trait_get_value(enum trait tr, struct player *pplayer)
Get current value of player trait.
Definition: aitraits.cpp:62
int api_methods_nation_trait_min(lua_State *L, Nation_Type *pnation, const char *tname)
Return the minimum random trait value that will be allocated for a nation.
int api_methods_player_trait_base(lua_State *L, Player *pplayer, const char *tname)
Return the current base value of an AI trait (not including Lua mod)
int api_methods_player_trait(lua_State *L, Player *pplayer, const char *tname)
Return the current value of an AI trait in force (base+mod)
int api_methods_nation_trait_default(lua_State *L, Nation_Type *pnation, const char *tname)
Return the default trait value that will be allocated for a nation.
int api_methods_player_trait_current_mod(lua_State *L, Player *pplayer, const char *tname)
Return the current Lua increment to an AI trait (can be changed with api_edit_trait_mod_set())
int api_methods_nation_trait_max(lua_State *L, Nation_Type *pnation, const char *tname)
Return the maximum random trait value that will be allocated for a nation.
#define LUASCRIPT_CHECK_STATE(L,...)
Definition: luascript.h:110
#define LUASCRIPT_CHECK_SELF(L, value,...)
Definition: luascript.h:139
#define LUASCRIPT_CHECK_ARG_NIL(L, value, narg, type,...)
Definition: luascript.h:131
#define LUASCRIPT_CHECK_ARG(L, check, narg, msg,...)
Definition: luascript.h:124
struct nation_type::@48::@50 server
std::vector< ai_trait > traits
Definition: player.h:119
Definition: player.h:231
struct player_ai ai_common
Definition: player.h:270
int fc_strcasecmp(const char *str0, const char *str1)
Compare strings like strcmp(), but ignoring case.
Definition: support.cpp:89