Freeciv-3.1
Loading...
Searching...
No Matches
api_server_game_methods.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996-2015 - Freeciv Development Team
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/scriptcore */
19#include "luascript.h"
20
21/* ai */
22#include "aitraits.h" /* ai_trait_get_value() */
23
24/* server/scripting */
25#include "script_server.h"
26
28
29/**********************************************************************/
32int api_methods_player_trait(lua_State *L, Player *pplayer,
33 const char *tname)
34{
35 enum trait tr;
36
38 LUASCRIPT_CHECK_SELF(L, pplayer, -1);
39 LUASCRIPT_CHECK_ARG_NIL(L, tname, 3, string, 0);
40
41 tr = trait_by_name(tname, fc_strcasecmp);
42
43 LUASCRIPT_CHECK_ARG(L, trait_is_valid(tr), 3, "no such trait", 0);
44
45 return ai_trait_get_value(tr, pplayer);
46}
47
48/**********************************************************************/
51int api_methods_player_trait_base(lua_State *L, Player *pplayer,
52 const char *tname)
53{
54 enum trait tr;
55
57 LUASCRIPT_CHECK_SELF(L, pplayer, -1);
58 LUASCRIPT_CHECK_ARG_NIL(L, tname, 3, string, 0);
59
60 tr = trait_by_name(tname, fc_strcasecmp);
61
62 LUASCRIPT_CHECK_ARG(L, trait_is_valid(tr), 3, "no such trait", 0);
63
64 return pplayer->ai_common.traits[tr].val;
65}
66
67/**********************************************************************/
72 const char *tname)
73{
74 enum trait tr;
75
77 LUASCRIPT_CHECK_SELF(L, pplayer, -1);
78 LUASCRIPT_CHECK_ARG_NIL(L, tname, 3, string, 0);
79
80 tr = trait_by_name(tname, fc_strcasecmp);
81
82 LUASCRIPT_CHECK_ARG(L, trait_is_valid(tr), 3, "no such trait", 0);
83
84 return pplayer->ai_common.traits[tr].mod;
85}
86
87/**********************************************************************/
90int api_methods_nation_trait_min(lua_State *L, Nation_Type *pnation,
91 const char *tname)
92{
93 enum trait tr;
94
96 LUASCRIPT_CHECK_SELF(L, pnation, -1);
97 LUASCRIPT_CHECK_ARG_NIL(L, tname, 3, string, 0);
98
99 tr = trait_by_name(tname, fc_strcasecmp);
100
101 LUASCRIPT_CHECK_ARG(L, trait_is_valid(tr), 3, "no such trait", 0);
102
103 return pnation->server.traits[tr].min;
104}
105
106/**********************************************************************/
109int api_methods_nation_trait_max(lua_State *L, Nation_Type *pnation,
110 const char *tname)
111{
112 enum trait tr;
113
115 LUASCRIPT_CHECK_SELF(L, pnation, -1);
116 LUASCRIPT_CHECK_ARG_NIL(L, tname, 3, string, 0);
117
118 tr = trait_by_name(tname, fc_strcasecmp);
119
120 LUASCRIPT_CHECK_ARG(L, trait_is_valid(tr), 3, "no such trait", 0);
121
122 return pnation->server.traits[tr].max;
123}
124
125/**********************************************************************/
129 const char *tname)
130{
131 enum trait tr;
132
134 LUASCRIPT_CHECK_SELF(L, pnation, -1);
135 LUASCRIPT_CHECK_ARG_NIL(L, tname, 3, string, 0);
136
137 tr = trait_by_name(tname, fc_strcasecmp);
138
139 LUASCRIPT_CHECK_ARG(L, trait_is_valid(tr), 3, "no such trait", 0);
140
141 return pnation->server.traits[tr].fixed;
142}
int ai_trait_get_value(enum trait tr, struct player *pplayer)
Definition aitraits.c:68
int api_methods_nation_trait_min(lua_State *L, Nation_Type *pnation, const char *tname)
int api_methods_player_trait_base(lua_State *L, Player *pplayer, const char *tname)
int api_methods_player_trait(lua_State *L, Player *pplayer, const char *tname)
int api_methods_nation_trait_default(lua_State *L, Nation_Type *pnation, const char *tname)
int api_methods_player_trait_current_mod(lua_State *L, Player *pplayer, const char *tname)
int api_methods_nation_trait_max(lua_State *L, Nation_Type *pnation, const char *tname)
#define LUASCRIPT_CHECK_STATE(L,...)
Definition luascript.h:117
#define LUASCRIPT_CHECK_SELF(L, value,...)
Definition luascript.h:146
#define LUASCRIPT_CHECK_ARG_NIL(L, value, narg, type,...)
Definition luascript.h:138
#define LUASCRIPT_CHECK_ARG(L, check, narg, msg,...)
Definition luascript.h:131
int val
Definition traits.h:38
int mod
Definition traits.h:39
struct trait_limits * traits
Definition nation.h:144
struct nation_type::@50::@52 server
struct ai_trait * traits
Definition player.h:132
struct player_ai ai_common
Definition player.h:288
int fixed
Definition traits.h:46
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189