Freeciv-3.3
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 "hand_gen.h"
29#include "plrhand.h"
30#include "report.h"
31
32/* server/scripting */
33#include "script_server.h"
34
36
37/**********************************************************************/
41 const char *tname)
42{
43 enum trait tr;
44
46 LUASCRIPT_CHECK_SELF(L, pplayer, -1);
47 LUASCRIPT_CHECK_ARG_NIL(L, tname, 3, string, 0);
48
50
51 LUASCRIPT_CHECK_ARG(L, trait_is_valid(tr), 3, "no such trait", 0);
52
53 return ai_trait_get_value(tr, pplayer);
54}
55
56/**********************************************************************/
60 const char *tname)
61{
62 enum trait tr;
63
65 LUASCRIPT_CHECK_SELF(L, pplayer, -1);
66 LUASCRIPT_CHECK_ARG_NIL(L, tname, 3, string, 0);
67
69
70 LUASCRIPT_CHECK_ARG(L, trait_is_valid(tr), 3, "no such trait", 0);
71
72 return pplayer->ai_common.traits[tr].val;
73}
74
75/**********************************************************************/
80 const char *tname)
81{
82 enum trait tr;
83
85 LUASCRIPT_CHECK_SELF(L, pplayer, -1);
86 LUASCRIPT_CHECK_ARG_NIL(L, tname, 3, string, 0);
87
89
90 LUASCRIPT_CHECK_ARG(L, trait_is_valid(tr), 3, "no such trait", 0);
91
92 return pplayer->ai_common.traits[tr].mod;
93}
94
95/**********************************************************************/
102{
104 LUASCRIPT_CHECK_SELF(L, pplayer);
105 LUASCRIPT_CHECK_ARG(L, pplayer->is_alive, 2, "the player has already lost");
106
107 if (looter) {
108 LUASCRIPT_CHECK_ARG(L, looter->is_alive, 3, "dead players can't loot");
109 player_loot_player(looter, pplayer);
110 }
112}
113
114/**********************************************************************/
118 const char *tname)
119{
120 enum trait tr;
121
123 LUASCRIPT_CHECK_SELF(L, pnation, -1);
124 LUASCRIPT_CHECK_ARG_NIL(L, tname, 3, string, 0);
125
127
128 LUASCRIPT_CHECK_ARG(L, trait_is_valid(tr), 3, "no such trait", 0);
129
130 return pnation->server.traits[tr].min;
131}
132
133/**********************************************************************/
137 const char *tname)
138{
139 enum trait tr;
140
142 LUASCRIPT_CHECK_SELF(L, pnation, -1);
143 LUASCRIPT_CHECK_ARG_NIL(L, tname, 3, string, 0);
144
146
147 LUASCRIPT_CHECK_ARG(L, trait_is_valid(tr), 3, "no such trait", 0);
148
149 return pnation->server.traits[tr].max;
150}
151
152/**********************************************************************/
156 const char *tname)
157{
158 enum trait tr;
159
161 LUASCRIPT_CHECK_SELF(L, pnation, -1);
162 LUASCRIPT_CHECK_ARG_NIL(L, tname, 3, string, 0);
163
165
166 LUASCRIPT_CHECK_ARG(L, trait_is_valid(tr), 3, "no such trait", 0);
167
168 return pnation->server.traits[tr].fixed;
169}
170
171/**********************************************************************/
178 Tech_Type *tech)
179{
180 const struct research *presearch;
182
184 LUASCRIPT_CHECK_SELF(L, pplayer, 0);
185 LUASCRIPT_CHECK_ARG_NIL(L, tech, 3, Tech_Type, 0);
186 tn = advance_number(tech);
187 presearch = research_get(pplayer);
188 LUASCRIPT_CHECK(L, presearch, "player's research not set", 0);
189
191 return presearch->inventions[tn].bulbs_researched_saved;
192 } else {
193 if (presearch->researching_saved == tn) {
194 return
195 presearch->bulbs_researching_saved - presearch->bulbs_researched;
196 } else if (tn != presearch->researching
197 && presearch->bulbs_researched > 0) {
198 int bound_bulbs = presearch->bulbs_researched - presearch->free_bulbs;
199 int penalty;
200
201 if (bound_bulbs <= 0) {
202 return 0;
203 }
205
206 return -MIN(penalty, presearch->bulbs_researched);
207 } else {
208 return 0;
209 }
210 }
211}
212
213/**********************************************************************/
217{
218 const struct research *presearch;
219
221 LUASCRIPT_CHECK_SELF(L, pplayer, 0);
222 presearch = research_get(pplayer);
223 LUASCRIPT_CHECK(L, presearch, "player's research not set", 0);
224
225 return presearch->free_bulbs;
226}
227
228/**********************************************************************/
231int api_methods_tag_score(lua_State *L, Player *pplayer, const char *tag)
232{
234 LUASCRIPT_CHECK_SELF(L, pplayer, -1);
235
236 return get_tag_score(tag, pplayer);
237}
238
239/**********************************************************************/
243{
245 LUASCRIPT_CHECK_SELF(L, pplayer, 0);
247
248 return pplayer->ai_common.love[player_number(towards)] * 1000 / MAX_AI_LOVE;
249}
250
251/**********************************************************************/
255 int amount)
256{
258 LUASCRIPT_CHECK_SELF(L, pplayer);
260
262 += amount * MAX_AI_LOVE / 1000;
263}
264
265/**********************************************************************/
int ai_trait_get_value(enum trait tr, struct player *pplayer)
Definition aitraits.c:68
void api_methods_player_lose(lua_State *L, Player *pplayer, Player *looter)
int api_methods_love(lua_State *L, Player *pplayer, Player *towards)
void api_methods_add_love(lua_State *L, Player *pplayer, Player *towards, int amount)
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)
void api_methods_cancel_pact(lua_State *L, Player *pplayer, Player *towards)
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)
int api_methods_tag_score(lua_State *L, Player *pplayer, const char *tag)
char * incite_cost
Definition comments.c:76
#define CLAUSE_LAST
Definition diptreaty.h:51
int Tech_type_id
Definition fc_types.h:236
struct civ_game game
Definition game.c:61
void handle_diplomacy_cancel_pact(struct player *pplayer, int other_player_id, enum clause_type clause)
Definition plrhand.c:882
#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
int player_number(const struct player *pplayer)
Definition player.c:837
#define MAX_AI_LOVE
Definition player.h:566
void player_status_add(struct player *plr, enum player_status pstatus)
Definition plrhand.c:3217
void player_loot_player(struct player *pvictor, struct player *pvictim)
Definition plrhand.c:410
int get_tag_score(const char *tag, const struct player *pplayer)
Definition report.c:1867
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:170
struct civ_game::@32::@36 server
int techpenalty
Definition game.h:203
struct trait_limits * traits
Definition nation.h:145
struct nation_type::@54::@56 server
struct ai_trait * traits
Definition player.h:126
int love[MAX_NUM_PLAYER_SLOTS]
Definition player.h:124
struct player_ai ai_common
Definition player.h:288
bool is_alive
Definition player.h:268
int fixed
Definition traits.h:46
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:186
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:98