Freeciv-3.2
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 */
19#include "research.h"
20
21/* common/scriptcore */
22#include "luascript.h"
23
24/* ai */
25#include "aitraits.h" /* ai_trait_get_value() */
26
27/* server */
28#include "plrhand.h"
29
30/* server/scripting */
31#include "script_server.h"
32
34
35/**********************************************************************/
39 const char *tname)
40{
41 enum trait tr;
42
44 LUASCRIPT_CHECK_SELF(L, pplayer, -1);
45 LUASCRIPT_CHECK_ARG_NIL(L, tname, 3, string, 0);
46
48
49 LUASCRIPT_CHECK_ARG(L, trait_is_valid(tr), 3, "no such trait", 0);
50
51 return ai_trait_get_value(tr, pplayer);
52}
53
54/**********************************************************************/
58 const char *tname)
59{
60 enum trait tr;
61
63 LUASCRIPT_CHECK_SELF(L, pplayer, -1);
64 LUASCRIPT_CHECK_ARG_NIL(L, tname, 3, string, 0);
65
67
68 LUASCRIPT_CHECK_ARG(L, trait_is_valid(tr), 3, "no such trait", 0);
69
70 return pplayer->ai_common.traits[tr].val;
71}
72
73/**********************************************************************/
78 const char *tname)
79{
80 enum trait tr;
81
83 LUASCRIPT_CHECK_SELF(L, pplayer, -1);
84 LUASCRIPT_CHECK_ARG_NIL(L, tname, 3, string, 0);
85
87
88 LUASCRIPT_CHECK_ARG(L, trait_is_valid(tr), 3, "no such trait", 0);
89
90 return pplayer->ai_common.traits[tr].mod;
91}
92
93/**********************************************************************/
100{
102 LUASCRIPT_CHECK_SELF(L, pplayer);
103 LUASCRIPT_CHECK_ARG(L, pplayer->is_alive, 2, "the player has already lost");
104
105 if (looter) {
106 LUASCRIPT_CHECK_ARG(L, looter->is_alive, 3, "dead players can't loot");
107 player_loot_player(looter, pplayer);
108 }
110}
111
112/**********************************************************************/
116 const char *tname)
117{
118 enum trait tr;
119
121 LUASCRIPT_CHECK_SELF(L, pnation, -1);
122 LUASCRIPT_CHECK_ARG_NIL(L, tname, 3, string, 0);
123
125
126 LUASCRIPT_CHECK_ARG(L, trait_is_valid(tr), 3, "no such trait", 0);
127
128 return pnation->server.traits[tr].min;
129}
130
131/**********************************************************************/
135 const char *tname)
136{
137 enum trait tr;
138
140 LUASCRIPT_CHECK_SELF(L, pnation, -1);
141 LUASCRIPT_CHECK_ARG_NIL(L, tname, 3, string, 0);
142
144
145 LUASCRIPT_CHECK_ARG(L, trait_is_valid(tr), 3, "no such trait", 0);
146
147 return pnation->server.traits[tr].max;
148}
149
150/**********************************************************************/
154 const char *tname)
155{
156 enum trait tr;
157
159 LUASCRIPT_CHECK_SELF(L, pnation, -1);
160 LUASCRIPT_CHECK_ARG_NIL(L, tname, 3, string, 0);
161
163
164 LUASCRIPT_CHECK_ARG(L, trait_is_valid(tr), 3, "no such trait", 0);
165
166 return pnation->server.traits[tr].fixed;
167}
168
169/**********************************************************************/
176 Tech_Type *tech)
177{
178 const struct research *presearch;
180
182 LUASCRIPT_CHECK_SELF(L, pplayer, 0);
183 LUASCRIPT_CHECK_ARG_NIL(L, tech, 3, Tech_Type, 0);
184 tn = advance_number(tech);
185 presearch = research_get(pplayer);
186 LUASCRIPT_CHECK(L, presearch, "player's research not set", 0);
187
189 return presearch->inventions[tn].bulbs_researched_saved;
190 } else {
191 if (presearch->researching_saved == tn) {
192 return
193 presearch->bulbs_researching_saved - presearch->bulbs_researched;
194 } else if (tn != presearch->researching
195 && presearch->bulbs_researched > 0) {
196 int bound_bulbs = presearch->bulbs_researched - presearch->free_bulbs;
197 int penalty;
198
199 if (bound_bulbs <= 0) {
200 return 0;
201 }
203
204 return -MIN(penalty, presearch->bulbs_researched);
205 } else {
206 return 0;
207 }
208 }
209}
210
211/**********************************************************************/
215{
216 const struct research *presearch;
217
219 LUASCRIPT_CHECK_SELF(L, pplayer, 0);
220 presearch = research_get(pplayer);
221 LUASCRIPT_CHECK(L, presearch, "player's research not set", 0);
222
223 return presearch->free_bulbs;
224}
int ai_trait_get_value(enum trait tr, struct player *pplayer)
Definition aitraits.c:69
void api_methods_player_lose(lua_State *L, Player *pplayer, Player *looter)
int api_methods_nation_trait_min(lua_State *L, Nation_Type *pnation, const char *tname)
int api_methods_player_tech_bulbs(lua_State *L, Player *pplayer, Tech_Type *tech)
int api_methods_player_trait_base(lua_State *L, Player *pplayer, const char *tname)
int api_methods_player_free_bulbs(lua_State *L, Player *pplayer)
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)
char * incite_cost
Definition comments.c:75
int Tech_type_id
Definition fc_types.h:377
struct civ_game game
Definition game.c:62
#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
#define LUASCRIPT_CHECK(L, check, msg,...)
Definition luascript.h:124
void player_status_add(struct player *plr, enum player_status pstatus)
Definition plrhand.c:3212
void player_loot_player(struct player *pvictor, struct player *pvictim)
Definition plrhand.c:411
struct research * research_get(const struct player *pplayer)
Definition research.c:128
#define MIN(x, y)
Definition shared.h:55
int val
Definition traits.h:38
int mod
Definition traits.h:39
bool multiresearch
Definition game.h:167
struct civ_game::@31::@35 server
int techpenalty
Definition game.h:200
struct trait_limits * traits
Definition nation.h:145
struct nation_type::@51::@53 server
struct ai_trait * traits
Definition player.h:124
struct player_ai ai_common
Definition player.h:286
bool is_alive
Definition player.h:266
int fixed
Definition traits.h:46
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:98