forked from github/server
bug 2463 fix xmastrees, fix get_key/set_key
This commit is contained in:
parent
d9f800f444
commit
89b10ee63d
|
@ -27,7 +27,6 @@ end
|
|||
local function tunnel_action(b, param)
|
||||
local units = tunnel_travelers(b)
|
||||
local rto = get_target(param)
|
||||
print("tunnel from " .. tostring(b.region) .. " to " .. tostring(rto))
|
||||
if rto and units then
|
||||
eressea.log.debug("Tunnel from " .. tostring(b) .. " [" .. param .. "]")
|
||||
for key, u in pairs(units) do
|
||||
|
|
|
@ -74,7 +74,7 @@ function use_xmastree(u, amount)
|
|||
if u.region.herb~=nil then
|
||||
-- TODO: else?
|
||||
local trees = u.region:get_resource("tree")
|
||||
u.region:set_key("xm06", true)
|
||||
u.region:set_key("xm06", get_turn())
|
||||
u.region:set_resource("tree", 10+trees)
|
||||
local msg = usepotion_message(u, "xmastree")
|
||||
msg:send_region(u.region)
|
||||
|
@ -107,7 +107,7 @@ function self.update()
|
|||
-- we celebrate knut and kick out the trees.
|
||||
for r in regions() do
|
||||
if r:get_key("xm06") then
|
||||
r:set_key("xm06", false)
|
||||
r:set_key("xm06", 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1135,3 +1135,24 @@ function test_immunity_stops_guard()
|
|||
assert_equal(f.age, 2)
|
||||
assert_true(u.guard)
|
||||
end
|
||||
|
||||
function test_region_keys()
|
||||
local r = region.create(0, 0, 'plain')
|
||||
assert_nil(r:get_key('test'))
|
||||
assert_nil(r:get_key('more'))
|
||||
r:set_key('test', 42)
|
||||
r:set_key('more') -- default is 1
|
||||
assert_equal(42, r:get_key('test'))
|
||||
assert_equal(1, r:get_key('more'))
|
||||
end
|
||||
|
||||
function test_faction_keys()
|
||||
local f = faction.create('human')
|
||||
assert_nil(f:get_key('test'))
|
||||
assert_nil(f:get_key('more'))
|
||||
f:set_key('test', 42)
|
||||
f:set_key('more') -- default is 1
|
||||
assert_equal(42, f:get_key('test'))
|
||||
assert_equal(1, f:get_key('more'))
|
||||
end
|
||||
|
||||
|
|
|
@ -75,9 +75,11 @@ end
|
|||
function test_xmastree()
|
||||
local r
|
||||
r = use_tree("ocean")
|
||||
assert_nil(r:get_key("xm06"))
|
||||
assert_equal(0, r:get_resource("tree"))
|
||||
eressea.free_game()
|
||||
r = use_tree("plain")
|
||||
assert_equal(get_turn(), r:get_key("xm06"))
|
||||
assert_equal(10, r:get_resource("tree"))
|
||||
end
|
||||
|
||||
|
|
|
@ -340,7 +340,7 @@ bool helping(const side * as, const side * ds)
|
|||
{
|
||||
if (as->faction == ds->faction)
|
||||
return true;
|
||||
return (bool)(!enemy(as, ds) && alliedside(as, ds->faction, HELP_FIGHT));
|
||||
return (!enemy(as, ds) && alliedside(as, ds->faction, HELP_FIGHT));
|
||||
}
|
||||
|
||||
int statusrow(int status)
|
||||
|
@ -2640,7 +2640,7 @@ static void aftermath(battle * b)
|
|||
side *s;
|
||||
int dead_players = 0;
|
||||
bfaction *bf;
|
||||
bool ships_damaged = (bool)(b->turn + (b->has_tactics_turn ? 1 : 0) > 2); /* only used for ship damage! */
|
||||
bool ships_damaged = (b->turn + (b->has_tactics_turn ? 1 : 0) > 2); /* only used for ship damage! */
|
||||
|
||||
for (s = b->sides; s != b->sides + b->nsides; ++s) {
|
||||
fighter *df;
|
||||
|
|
|
@ -59,7 +59,7 @@ int tolua_factionlist_next(lua_State * L)
|
|||
|
||||
static int tolua_faction_get_units(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
unit **unit_ptr = (unit **)lua_newuserdata(L, sizeof(unit *));
|
||||
|
||||
luaL_getmetatable(L, TOLUA_CAST "unit");
|
||||
|
@ -73,8 +73,8 @@ static int tolua_faction_get_units(lua_State * L)
|
|||
|
||||
int tolua_faction_add_item(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
const char *iname = tolua_tostring(L, 2, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
const char *iname = tolua_tostring(L, 2, NULL);
|
||||
int number = (int)tolua_tonumber(L, 3, 0);
|
||||
int result = -1;
|
||||
|
||||
|
@ -91,35 +91,35 @@ int tolua_faction_add_item(lua_State * L)
|
|||
|
||||
static int tolua_faction_get_maxheroes(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
lua_pushinteger(L, maxheroes(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_heroes(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
lua_pushinteger(L, countheroes(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_score(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
lua_pushnumber(L, (lua_Number)self->score);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_id(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
lua_pushinteger(L, self->no);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_id(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
int id = (int)tolua_tonumber(L, 2, 0);
|
||||
if (findfaction(id) == NULL) {
|
||||
renumber_faction(self, id);
|
||||
|
@ -133,15 +133,15 @@ static int tolua_faction_set_id(lua_State * L)
|
|||
|
||||
static int tolua_faction_get_magic(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
lua_pushstring(L, magic_school[self->magiegebiet]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_magic(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
const char *type = tolua_tostring(L, 2, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
const char *type = tolua_tostring(L, 2, NULL);
|
||||
int mtype;
|
||||
|
||||
for (mtype = 0; mtype != MAXMAGIETYP; ++mtype) {
|
||||
|
@ -155,14 +155,14 @@ static int tolua_faction_set_magic(lua_State * L)
|
|||
|
||||
static int tolua_faction_get_age(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
lua_pushinteger(L, self->age);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_age(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
int age = (int)tolua_tonumber(L, 2, 0);
|
||||
self->age = age;
|
||||
return 0;
|
||||
|
@ -170,14 +170,14 @@ static int tolua_faction_set_age(lua_State * L)
|
|||
|
||||
static int tolua_faction_get_flags(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
lua_pushinteger(L, self->flags);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_flags(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
int flags = (int)tolua_tonumber(L, 2, self->flags);
|
||||
self->flags = flags;
|
||||
return 1;
|
||||
|
@ -185,14 +185,14 @@ static int tolua_faction_set_flags(lua_State * L)
|
|||
|
||||
static int tolua_faction_get_options(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
lua_pushinteger(L, self->options);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_options(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
int options = (int)tolua_tonumber(L, 2, self->options);
|
||||
self->options = options;
|
||||
return 1;
|
||||
|
@ -200,14 +200,14 @@ static int tolua_faction_set_options(lua_State * L)
|
|||
|
||||
static int tolua_faction_get_lastturn(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
lua_pushinteger(L, self->lastorders);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_lastturn(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
if (self) {
|
||||
self->lastorders = (int)tolua_tonumber(L, 2, self->lastorders);
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ static int tolua_faction_set_lastturn(lua_State * L)
|
|||
|
||||
static int tolua_faction_renumber(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
int no = (int)tolua_tonumber(L, 2, 0);
|
||||
|
||||
renumber_faction(self, no);
|
||||
|
@ -225,8 +225,8 @@ static int tolua_faction_renumber(lua_State * L)
|
|||
|
||||
static int tolua_faction_addnotice(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
const char *str = tolua_tostring(L, 2, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
const char *str = tolua_tostring(L, 2, NULL);
|
||||
|
||||
addmessage(NULL, self, str, MSG_MESSAGE, ML_IMPORTANT);
|
||||
return 0;
|
||||
|
@ -234,19 +234,22 @@ static int tolua_faction_addnotice(lua_State * L)
|
|||
|
||||
static int tolua_faction_getkey(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
const char *name = tolua_tostring(L, 2, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
const char *name = tolua_tostring(L, 2, NULL);
|
||||
int flag = atoi36(name);
|
||||
|
||||
lua_pushinteger(L, key_get(self->attribs, flag));
|
||||
return 1;
|
||||
int value = key_get(self->attribs, flag);
|
||||
if (value != 0) {
|
||||
lua_pushinteger(L, value);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_setkey(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
const char *name = tolua_tostring(L, 2, 0);
|
||||
int value = (int)tolua_tonumber(L, 3, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
const char *name = tolua_tostring(L, 2, NULL);
|
||||
int value = (int)tolua_tonumber(L, 3, 1);
|
||||
int flag = atoi36(name);
|
||||
|
||||
if (value) {
|
||||
|
@ -260,7 +263,7 @@ static int tolua_faction_setkey(lua_State * L)
|
|||
|
||||
static int tolua_faction_get_messages(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
int i = 1;
|
||||
mlist *ml;
|
||||
if (!self->msgs) {
|
||||
|
@ -276,8 +279,8 @@ static int tolua_faction_get_messages(lua_State * L)
|
|||
}
|
||||
|
||||
static int tolua_faction_count_msg_type(lua_State *L) {
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
const char *str = tolua_tostring(L, 2, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
const char *str = tolua_tostring(L, 2, NULL);
|
||||
int n = 0;
|
||||
if (self->msgs) {
|
||||
mlist * ml = self->msgs->begin;
|
||||
|
@ -294,8 +297,8 @@ static int tolua_faction_count_msg_type(lua_State *L) {
|
|||
|
||||
static int tolua_faction_normalize(lua_State * L)
|
||||
{
|
||||
faction *f = (faction *)tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *)tolua_tousertype(L, 2, 0);
|
||||
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
region *r = (region *)tolua_tousertype(L, 2, NULL);
|
||||
if (r) {
|
||||
plane *pl = rplane(r);
|
||||
int nx = r->x, ny = r->y;
|
||||
|
@ -310,8 +313,8 @@ static int tolua_faction_normalize(lua_State * L)
|
|||
|
||||
static int tolua_faction_set_origin(lua_State * L)
|
||||
{
|
||||
faction *f = (faction *)tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *)tolua_tousertype(L, 2, 0);
|
||||
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
region *r = (region *)tolua_tousertype(L, 2, NULL);
|
||||
plane *pl = rplane(r);
|
||||
int id = pl ? pl->id : 0;
|
||||
|
||||
|
@ -321,7 +324,7 @@ static int tolua_faction_set_origin(lua_State * L)
|
|||
|
||||
static int tolua_faction_get_origin(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
int x = 0, y = 0;
|
||||
faction_getorigin(self, 0, &x, &y);
|
||||
|
||||
|
@ -332,7 +335,7 @@ static int tolua_faction_get_origin(lua_State * L)
|
|||
|
||||
static int tolua_faction_destroy(lua_State * L)
|
||||
{
|
||||
faction **fp, *f = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction **fp, *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
/* TODO: this loop is slow af, but what can we do? */
|
||||
for (fp = &factions; *fp; fp = &(*fp)->next) {
|
||||
if (*fp == f) {
|
||||
|
@ -353,9 +356,9 @@ static int tolua_faction_get(lua_State * L)
|
|||
|
||||
static int tolua_faction_create(lua_State * L)
|
||||
{
|
||||
const char *racename = tolua_tostring(L, 1, 0);
|
||||
const char *email = tolua_tostring(L, 2, 0);
|
||||
const char *lang = tolua_tostring(L, 3, 0);
|
||||
const char *racename = tolua_tostring(L, 1, NULL);
|
||||
const char *email = tolua_tostring(L, 2, NULL);
|
||||
const char *lang = tolua_tostring(L, 3, NULL);
|
||||
struct locale *loc = lang ? get_locale(lang) : default_locale;
|
||||
faction *f = NULL;
|
||||
const struct race *frace = rc_find(racename ? racename : "human");
|
||||
|
@ -371,44 +374,44 @@ static int tolua_faction_create(lua_State * L)
|
|||
|
||||
static int tolua_faction_get_password(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
tolua_pushstring(L, faction_getpassword(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_password(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
const char * passw = tolua_tostring(L, 2, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
const char * passw = tolua_tostring(L, 2, NULL);
|
||||
faction_setpassword(self, password_hash(passw, PASSWORD_DEFAULT));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_email(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
tolua_pushstring(L, faction_getemail(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_email(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction_setemail(self, tolua_tostring(L, 2, 0));
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
faction_setemail(self, tolua_tostring(L, 2, NULL));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_locale(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
tolua_pushstring(L, locale_name(self->locale));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_locale(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
const char *name = tolua_tostring(L, 2, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
const char *name = tolua_tostring(L, 2, NULL);
|
||||
const struct locale *loc = get_locale(name);
|
||||
if (loc) {
|
||||
self->locale = loc;
|
||||
|
@ -422,15 +425,15 @@ static int tolua_faction_set_locale(lua_State * L)
|
|||
|
||||
static int tolua_faction_get_race(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
tolua_pushstring(L, self->race->_name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_race(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
const char *name = tolua_tostring(L, 2, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
const char *name = tolua_tostring(L, 2, NULL);
|
||||
const race *rc = rc_find(name);
|
||||
if (rc != NULL) {
|
||||
self->race = rc;
|
||||
|
@ -441,57 +444,57 @@ static int tolua_faction_set_race(lua_State * L)
|
|||
|
||||
static int tolua_faction_get_name(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
tolua_pushstring(L, faction_getname(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_name(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction_setname(self, tolua_tostring(L, 2, 0));
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
faction_setname(self, tolua_tostring(L, 2, NULL));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_uid(lua_State * L)
|
||||
{
|
||||
faction *f = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
lua_pushinteger(L, f->uid);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_uid(lua_State * L)
|
||||
{
|
||||
faction *f = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
f->uid = (int)tolua_tonumber(L, 2, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_info(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
tolua_pushstring(L, faction_getbanner(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_info(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction_setbanner(self, tolua_tostring(L, 2, 0));
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
faction_setbanner(self, tolua_tostring(L, 2, NULL));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_alliance(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
tolua_pushusertype(L, f_get_alliance(self), TOLUA_CAST "alliance");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_alliance(lua_State * L)
|
||||
{
|
||||
struct faction *self = (struct faction *)tolua_tousertype(L, 1, 0);
|
||||
struct alliance *alli = (struct alliance *) tolua_tousertype(L, 2, 0);
|
||||
struct faction *self = (struct faction *)tolua_tousertype(L, 1, NULL);
|
||||
struct alliance *alli = (struct alliance *) tolua_tousertype(L, 2, NULL);
|
||||
|
||||
setalliance(self, alli);
|
||||
|
||||
|
@ -500,7 +503,7 @@ static int tolua_faction_set_alliance(lua_State * L)
|
|||
|
||||
static int tolua_faction_get_items(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
item **item_ptr = (item **)lua_newuserdata(L, sizeof(item *));
|
||||
|
||||
luaL_getmetatable(L, TOLUA_CAST "item");
|
||||
|
@ -515,7 +518,7 @@ static int tolua_faction_get_items(lua_State * L)
|
|||
|
||||
static int tolua_faction_tostring(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
||||
lua_pushstring(L, factionname(self));
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -42,8 +42,8 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
static int tolua_region_count_msg_type(lua_State *L) {
|
||||
region *self = (region *)tolua_tousertype(L, 1, 0);
|
||||
const char *str = tolua_tostring(L, 2, 0);
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
const char *str = tolua_tostring(L, 2, NULL);
|
||||
int n = 0;
|
||||
if (self->msgs) {
|
||||
mlist * ml = self->msgs->begin;
|
||||
|
@ -73,21 +73,21 @@ int tolua_regionlist_next(lua_State * L)
|
|||
|
||||
static int tolua_region_get_id(lua_State * L)
|
||||
{
|
||||
region *self = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
lua_pushinteger(L, self->uid);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_get_blocked(lua_State * L)
|
||||
{
|
||||
region *self = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
lua_pushboolean(L, (self->flags&RF_BLOCKED) != 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_set_blocked(lua_State * L)
|
||||
{
|
||||
region *self = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
bool flag = !!tolua_toboolean(L, 2, 1);
|
||||
if (flag) self->flags |= RF_BLOCKED;
|
||||
else self->flags &= ~RF_BLOCKED;
|
||||
|
@ -96,36 +96,36 @@ static int tolua_region_set_blocked(lua_State * L)
|
|||
|
||||
static int tolua_region_get_x(lua_State * L)
|
||||
{
|
||||
region *self = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
lua_pushinteger(L, self->x);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_get_y(lua_State * L)
|
||||
{
|
||||
region *self = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
lua_pushinteger(L, self->y);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_get_plane(lua_State * L)
|
||||
{
|
||||
region *r = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *)tolua_tousertype(L, 1, NULL);
|
||||
tolua_pushusertype(L, rplane(r), TOLUA_CAST "plane");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_get_terrain(lua_State * L)
|
||||
{
|
||||
region *self = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
tolua_pushstring(L, self->terrain->_name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_set_terrain(lua_State * L)
|
||||
{
|
||||
region *r = (region *)tolua_tousertype(L, 1, 0);
|
||||
const char *tname = tolua_tostring(L, 2, 0);
|
||||
region *r = (region *)tolua_tousertype(L, 1, NULL);
|
||||
const char *tname = tolua_tostring(L, 2, NULL);
|
||||
if (tname) {
|
||||
const terrain_type *terrain = get_terrain(tname);
|
||||
if (terrain) {
|
||||
|
@ -137,7 +137,7 @@ static int tolua_region_set_terrain(lua_State * L)
|
|||
|
||||
static int tolua_region_get_terrainname(lua_State * L)
|
||||
{
|
||||
region *self = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
attrib *a = a_find(self->attribs, &at_racename);
|
||||
if (a) {
|
||||
tolua_pushstring(L, get_racename(a));
|
||||
|
@ -148,8 +148,8 @@ static int tolua_region_get_terrainname(lua_State * L)
|
|||
|
||||
static int tolua_region_set_owner(lua_State * L)
|
||||
{
|
||||
region *r = (region *)tolua_tousertype(L, 1, 0);
|
||||
struct faction *f = (struct faction *)tolua_tousertype(L, 2, 0);
|
||||
region *r = (region *)tolua_tousertype(L, 1, NULL);
|
||||
struct faction *f = (struct faction *)tolua_tousertype(L, 2, NULL);
|
||||
if (r) {
|
||||
region_set_owner(r, f, turn);
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ static int tolua_region_set_owner(lua_State * L)
|
|||
|
||||
static int tolua_region_get_owner(lua_State * L)
|
||||
{
|
||||
region *r = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *)tolua_tousertype(L, 1, NULL);
|
||||
if (r) {
|
||||
struct faction *f = region_get_owner(r);
|
||||
tolua_pushusertype(L, f, TOLUA_CAST "faction");
|
||||
|
@ -169,8 +169,8 @@ static int tolua_region_get_owner(lua_State * L)
|
|||
|
||||
static int tolua_region_set_terrainname(lua_State * L)
|
||||
{
|
||||
region *self = (region *)tolua_tousertype(L, 1, 0);
|
||||
const char *name = tolua_tostring(L, 2, 0);
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
const char *name = tolua_tostring(L, 2, NULL);
|
||||
if (name == NULL) {
|
||||
a_removeall(&self->attribs, &at_racename);
|
||||
}
|
||||
|
@ -182,42 +182,42 @@ static int tolua_region_set_terrainname(lua_State * L)
|
|||
|
||||
static int tolua_region_get_info(lua_State * L)
|
||||
{
|
||||
region *self = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
tolua_pushstring(L, region_getinfo(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_set_info(lua_State * L)
|
||||
{
|
||||
region *self = (region *)tolua_tousertype(L, 1, 0);
|
||||
region_setinfo(self, tolua_tostring(L, 2, 0));
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
region_setinfo(self, tolua_tostring(L, 2, NULL));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_region_get_name(lua_State * L)
|
||||
{
|
||||
region *self = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
tolua_pushstring(L, region_getname(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_set_name(lua_State * L)
|
||||
{
|
||||
region *self = (region *)tolua_tousertype(L, 1, 0);
|
||||
region_setname(self, tolua_tostring(L, 2, 0));
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
region_setname(self, tolua_tostring(L, 2, NULL));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_region_get_morale(lua_State * L)
|
||||
{
|
||||
region *r = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *)tolua_tousertype(L, 1, NULL);
|
||||
lua_pushinteger(L, region_get_morale(r));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_set_morale(lua_State * L)
|
||||
{
|
||||
region *r = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *)tolua_tousertype(L, 1, NULL);
|
||||
region_set_morale(r, (int)tolua_tonumber(L, 2, 0), turn);
|
||||
return 0;
|
||||
}
|
||||
|
@ -225,14 +225,14 @@ static int tolua_region_set_morale(lua_State * L)
|
|||
/* region mourning this turn */
|
||||
static int tolua_region_get_is_mourning(lua_State * L)
|
||||
{
|
||||
region *r = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *)tolua_tousertype(L, 1, NULL);
|
||||
lua_pushboolean(L, is_mourning(r, turn+1));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_get_adj(lua_State * L)
|
||||
{
|
||||
region *r = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *)tolua_tousertype(L, 1, NULL);
|
||||
region *rn[MAXDIRECTIONS];
|
||||
int d, idx;
|
||||
get_neighbours(r, rn);
|
||||
|
@ -249,7 +249,7 @@ static int tolua_region_get_adj(lua_State * L)
|
|||
|
||||
static int tolua_region_get_luxury(lua_State * L)
|
||||
{
|
||||
region *r = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *)tolua_tousertype(L, 1, NULL);
|
||||
if (r->land) {
|
||||
const item_type *lux = r_luxury(r);
|
||||
if (lux) {
|
||||
|
@ -263,8 +263,8 @@ static int tolua_region_get_luxury(lua_State * L)
|
|||
|
||||
static int tolua_region_set_luxury(lua_State * L)
|
||||
{
|
||||
region *r = (region *)tolua_tousertype(L, 1, 0);
|
||||
const char *name = tolua_tostring(L, 2, 0);
|
||||
region *r = (region *)tolua_tousertype(L, 1, NULL);
|
||||
const char *name = tolua_tostring(L, 2, NULL);
|
||||
if (r->land && name) {
|
||||
const item_type *lux = r_luxury(r);
|
||||
const item_type *itype = it_find(name);
|
||||
|
@ -278,9 +278,9 @@ static int tolua_region_set_luxury(lua_State * L)
|
|||
|
||||
static int tolua_region_set_herb(lua_State * L)
|
||||
{
|
||||
region *r = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *)tolua_tousertype(L, 1, NULL);
|
||||
if (r->land) {
|
||||
const char *name = tolua_tostring(L, 2, 0);
|
||||
const char *name = tolua_tostring(L, 2, NULL);
|
||||
const item_type *itype = it_find(name);
|
||||
if (itype && (itype->flags & ITF_HERB)) {
|
||||
r->land->herbtype = itype;
|
||||
|
@ -291,7 +291,7 @@ static int tolua_region_set_herb(lua_State * L)
|
|||
|
||||
static int tolua_region_get_herb(lua_State * L)
|
||||
{
|
||||
region *r = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *)tolua_tousertype(L, 1, NULL);
|
||||
if (r->land && r->land->herbtype) {
|
||||
const char *name = r->land->herbtype->rtype->_name;
|
||||
tolua_pushstring(L, name);
|
||||
|
@ -302,7 +302,7 @@ static int tolua_region_get_herb(lua_State * L)
|
|||
|
||||
static int tolua_region_get_next(lua_State * L)
|
||||
{
|
||||
region *self = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
direction_t dir = (direction_t)tolua_tonumber(L, 2, 0);
|
||||
|
||||
if (dir >= 0 && dir < MAXDIRECTIONS) {
|
||||
|
@ -314,7 +314,7 @@ static int tolua_region_get_next(lua_State * L)
|
|||
|
||||
static int tolua_region_get_flag(lua_State * L)
|
||||
{
|
||||
region *self = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
int bit = (int)tolua_tonumber(L, 2, 0);
|
||||
|
||||
lua_pushboolean(L, (self->flags & (1 << bit)));
|
||||
|
@ -323,7 +323,7 @@ static int tolua_region_get_flag(lua_State * L)
|
|||
|
||||
static int tolua_region_set_flag(lua_State * L)
|
||||
{
|
||||
region *self = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
int bit = (int)tolua_tonumber(L, 2, 0);
|
||||
int set = tolua_toboolean(L, 3, 1);
|
||||
|
||||
|
@ -336,8 +336,8 @@ static int tolua_region_set_flag(lua_State * L)
|
|||
|
||||
static int tolua_region_get_resourcelevel(lua_State * L)
|
||||
{
|
||||
region *r = (region *)tolua_tousertype(L, 1, 0);
|
||||
const char *type = tolua_tostring(L, 2, 0);
|
||||
region *r = (region *)tolua_tousertype(L, 1, NULL);
|
||||
const char *type = tolua_tostring(L, 2, NULL);
|
||||
const resource_type *rtype = rt_find(type);
|
||||
if (rtype != NULL) {
|
||||
const rawmaterial *rm;
|
||||
|
@ -372,9 +372,9 @@ static int tolua_region_get_resource(lua_State * L)
|
|||
const resource_type *rtype;
|
||||
int result;
|
||||
|
||||
r = (region *)tolua_tousertype(L, 1, 0);
|
||||
r = (region *)tolua_tousertype(L, 1, NULL);
|
||||
LUA_ASSERT(r != NULL, "invalid parameter");
|
||||
type = tolua_tostring(L, 2, 0);
|
||||
type = tolua_tostring(L, 2, NULL);
|
||||
LUA_ASSERT(type != NULL, "invalid parameter");
|
||||
|
||||
result = special_resource(type);
|
||||
|
@ -403,8 +403,8 @@ static int tolua_region_get_resource(lua_State * L)
|
|||
|
||||
static int tolua_region_set_resource(lua_State * L)
|
||||
{
|
||||
region *r = (region *)tolua_tousertype(L, 1, 0);
|
||||
const char *type = tolua_tostring(L, 2, 0);
|
||||
region *r = (region *)tolua_tousertype(L, 1, NULL);
|
||||
const char *type = tolua_tostring(L, 2, NULL);
|
||||
int result, value = (int)tolua_tonumber(L, 3, 0);
|
||||
const resource_type *rtype;
|
||||
|
||||
|
@ -429,7 +429,7 @@ static int tolua_region_set_resource(lua_State * L)
|
|||
|
||||
static int tolua_region_destroy(lua_State * L)
|
||||
{
|
||||
region *self = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
remove_region(®ions, self);
|
||||
return 0;
|
||||
}
|
||||
|
@ -438,7 +438,7 @@ static int tolua_region_create(lua_State * L)
|
|||
{
|
||||
int x = (int)tolua_tonumber(L, 1, 0);
|
||||
int y = (int)tolua_tonumber(L, 2, 0);
|
||||
const char *tname = tolua_tostring(L, 3, 0);
|
||||
const char *tname = tolua_tostring(L, 3, NULL);
|
||||
if (tname) {
|
||||
plane *pl = findplane(x, y);
|
||||
const terrain_type *terrain = get_terrain(tname);
|
||||
|
@ -471,7 +471,7 @@ static int tolua_region_create(lua_State * L)
|
|||
|
||||
static int tolua_region_get_units(lua_State * L)
|
||||
{
|
||||
region *self = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
unit **unit_ptr = (unit **)lua_newuserdata(L, sizeof(unit *));
|
||||
|
||||
luaL_getmetatable(L, "unit");
|
||||
|
@ -485,7 +485,7 @@ static int tolua_region_get_units(lua_State * L)
|
|||
|
||||
static int tolua_region_get_buildings(lua_State * L)
|
||||
{
|
||||
region *self = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
building **building_ptr =
|
||||
(building **)lua_newuserdata(L, sizeof(building *));
|
||||
|
||||
|
@ -500,7 +500,7 @@ static int tolua_region_get_buildings(lua_State * L)
|
|||
|
||||
static int tolua_region_get_ships(lua_State * L)
|
||||
{
|
||||
region *self = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
ship **ship_ptr = (ship **)lua_newuserdata(L, sizeof(ship *));
|
||||
|
||||
luaL_getmetatable(L, "ship");
|
||||
|
@ -514,7 +514,7 @@ static int tolua_region_get_ships(lua_State * L)
|
|||
|
||||
static int tolua_region_get_age(lua_State * L)
|
||||
{
|
||||
region *self = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
|
||||
if (self) {
|
||||
lua_pushinteger(L, self->age);
|
||||
|
@ -525,7 +525,7 @@ static int tolua_region_get_age(lua_State * L)
|
|||
|
||||
static int tolua_region_get_peasants(lua_State * L)
|
||||
{
|
||||
region *self = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
|
||||
if (self) {
|
||||
lua_pushinteger(L, self->land ? self->land->peasants : 0);
|
||||
|
@ -536,7 +536,7 @@ static int tolua_region_get_peasants(lua_State * L)
|
|||
|
||||
static int tolua_region_set_peasants(lua_State * L)
|
||||
{
|
||||
region *self = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
|
||||
if (self && self->land) {
|
||||
self->land->peasants = lua_tointeger(L, 2);
|
||||
|
@ -546,37 +546,22 @@ static int tolua_region_set_peasants(lua_State * L)
|
|||
|
||||
static int tolua_region_getkey(lua_State * L)
|
||||
{
|
||||
region *self = (region *)tolua_tousertype(L, 1, 0);
|
||||
const char *name = tolua_tostring(L, 2, 0);
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
const char *name = tolua_tostring(L, 2, NULL);
|
||||
int flag = atoi36(name);
|
||||
|
||||
lua_pushboolean(L, key_get(self->attribs, flag));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_getastral(lua_State * L)
|
||||
{
|
||||
region *r = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *rt = r_standard_to_astral(r);
|
||||
|
||||
if (!rt) {
|
||||
const char *tname = tolua_tostring(L, 2, 0);
|
||||
plane *pl = get_astralplane();
|
||||
rt = new_region(real2tp(r->x), real2tp(r->y), pl, 0);
|
||||
if (tname) {
|
||||
const terrain_type *terrain = get_terrain(tname);
|
||||
terraform_region(rt, terrain);
|
||||
}
|
||||
int value = key_get(self->attribs, flag);
|
||||
if (value != 0) {
|
||||
lua_pushinteger(L, value);
|
||||
return 1;
|
||||
}
|
||||
tolua_pushusertype(L, rt, TOLUA_CAST "region");
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_region_setkey(lua_State * L)
|
||||
{
|
||||
region *self = (region *)tolua_tousertype(L, 1, 0);
|
||||
const char *name = tolua_tostring(L, 2, 0);
|
||||
int value = (int)tolua_tonumber(L, 3, 0);
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
const char *name = tolua_tostring(L, 2, NULL);
|
||||
int value = (int)tolua_tonumber(L, 3, 1);
|
||||
int flag = atoi36(name);
|
||||
|
||||
if (value) {
|
||||
|
@ -588,9 +573,27 @@ static int tolua_region_setkey(lua_State * L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_region_getastral(lua_State * L)
|
||||
{
|
||||
region *r = (region *)tolua_tousertype(L, 1, NULL);
|
||||
region *rt = r_standard_to_astral(r);
|
||||
|
||||
if (!rt) {
|
||||
const char *tname = tolua_tostring(L, 2, NULL);
|
||||
plane *pl = get_astralplane();
|
||||
rt = new_region(real2tp(r->x), real2tp(r->y), pl, 0);
|
||||
if (tname) {
|
||||
const terrain_type *terrain = get_terrain(tname);
|
||||
terraform_region(rt, terrain);
|
||||
}
|
||||
}
|
||||
tolua_pushusertype(L, rt, TOLUA_CAST "region");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_tostring(lua_State * L)
|
||||
{
|
||||
region *self = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
lua_pushstring(L, regionname(self, NULL));
|
||||
return 1;
|
||||
}
|
||||
|
@ -606,7 +609,7 @@ static int tolua_plane_get(lua_State * L)
|
|||
|
||||
static int tolua_plane_erase(lua_State *L)
|
||||
{
|
||||
plane *self = (plane *)tolua_tousertype(L, 1, 0);
|
||||
plane *self = (plane *)tolua_tousertype(L, 1, NULL);
|
||||
remove_plane(self);
|
||||
return 0;
|
||||
}
|
||||
|
@ -618,7 +621,7 @@ static int tolua_plane_create(lua_State * L)
|
|||
int y = (int)tolua_tonumber(L, 3, 0);
|
||||
int width = (int)tolua_tonumber(L, 4, 0);
|
||||
int height = (int)tolua_tonumber(L, 5, 0);
|
||||
const char *name = tolua_tostring(L, 6, 0);
|
||||
const char *name = tolua_tostring(L, 6, NULL);
|
||||
plane *pl;
|
||||
|
||||
pl = create_new_plane(id, name, x, x + width - 1, y, y + height - 1, 0);
|
||||
|
@ -629,15 +632,15 @@ static int tolua_plane_create(lua_State * L)
|
|||
|
||||
static int tolua_plane_get_name(lua_State * L)
|
||||
{
|
||||
plane *self = (plane *)tolua_tousertype(L, 1, 0);
|
||||
plane *self = (plane *)tolua_tousertype(L, 1, NULL);
|
||||
tolua_pushstring(L, self->name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_plane_set_name(lua_State * L)
|
||||
{
|
||||
plane *self = (plane *)tolua_tousertype(L, 1, 0);
|
||||
const char *str = tolua_tostring(L, 2, 0);
|
||||
plane *self = (plane *)tolua_tousertype(L, 1, NULL);
|
||||
const char *str = tolua_tostring(L, 2, NULL);
|
||||
free(self->name);
|
||||
if (str)
|
||||
self->name = str_strdup(str);
|
||||
|
@ -648,14 +651,14 @@ static int tolua_plane_set_name(lua_State * L)
|
|||
|
||||
static int tolua_plane_get_id(lua_State * L)
|
||||
{
|
||||
plane *self = (plane *)tolua_tousertype(L, 1, 0);
|
||||
plane *self = (plane *)tolua_tousertype(L, 1, NULL);
|
||||
lua_pushinteger(L, self->id);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_plane_normalize(lua_State * L)
|
||||
{
|
||||
plane *self = (plane *)tolua_tousertype(L, 1, 0);
|
||||
plane *self = (plane *)tolua_tousertype(L, 1, NULL);
|
||||
int x = (int)tolua_tonumber(L, 2, 0);
|
||||
int y = (int)tolua_tonumber(L, 3, 0);
|
||||
pnormalize(&x, &y, self);
|
||||
|
@ -666,14 +669,14 @@ static int tolua_plane_normalize(lua_State * L)
|
|||
|
||||
static int tolua_plane_tostring(lua_State * L)
|
||||
{
|
||||
plane *self = (plane *)tolua_tousertype(L, 1, 0);
|
||||
plane *self = (plane *)tolua_tousertype(L, 1, NULL);
|
||||
lua_pushstring(L, self->name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_plane_get_size(lua_State * L)
|
||||
{
|
||||
plane *pl = (plane *)tolua_tousertype(L, 1, 0);
|
||||
plane *pl = (plane *)tolua_tousertype(L, 1, NULL);
|
||||
lua_pushinteger(L, plane_width(pl));
|
||||
lua_pushinteger(L, plane_height(pl));
|
||||
return 2;
|
||||
|
@ -698,8 +701,8 @@ static int tolua_distance(lua_State * L)
|
|||
}
|
||||
|
||||
static int tolua_region_get_curse(lua_State *L) {
|
||||
region *self = (region *)tolua_tousertype(L, 1, 0);
|
||||
const char *name = tolua_tostring(L, 2, 0);
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
const char *name = tolua_tostring(L, 2, NULL);
|
||||
if (self->attribs) {
|
||||
curse * c = get_curse(self->attribs, ct_find(name));
|
||||
if (c) {
|
||||
|
@ -711,8 +714,8 @@ static int tolua_region_get_curse(lua_State *L) {
|
|||
}
|
||||
|
||||
static int tolua_region_has_attrib(lua_State *L) {
|
||||
region *self = (region *)tolua_tousertype(L, 1, 0);
|
||||
const char *name = tolua_tostring(L, 2, 0);
|
||||
region *self = (region *)tolua_tousertype(L, 1, NULL);
|
||||
const char *name = tolua_tostring(L, 2, NULL);
|
||||
attrib * a = a_find(self->attribs, at_find(name));
|
||||
lua_pushboolean(L, a != NULL);
|
||||
return 1;
|
||||
|
|
|
@ -178,7 +178,7 @@ static bool lua_equipunit(unit *u, const char *eqname, int mask) {
|
|||
lua_pop(L, 1);
|
||||
}
|
||||
else {
|
||||
result = (bool)lua_toboolean(L, -1);
|
||||
result = lua_toboolean(L, -1) != 0;
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -263,7 +263,7 @@ bool b_blocknone(const connection * b, const unit * u, const region * r)
|
|||
|
||||
bool b_rvisible(const connection * b, const region * r)
|
||||
{
|
||||
return (bool)(b->to == r || b->from == r);
|
||||
return (b->to == r || b->from == r);
|
||||
}
|
||||
|
||||
bool b_fvisible(const connection * b, const struct faction * f,
|
||||
|
@ -412,7 +412,7 @@ b_blockfogwall(const connection * b, const unit * u, const region * r)
|
|||
UNUSED_ARG(b);
|
||||
if (!u)
|
||||
return true;
|
||||
return (bool)(effskill(u, SK_PERCEPTION, r) > 4); /* Das ist die alte Nebelwand */
|
||||
return (effskill(u, SK_PERCEPTION, r) > 4); /* Das ist die alte Nebelwand */
|
||||
}
|
||||
|
||||
/** Legacy type used in old Eressea games, no longer in use. */
|
||||
|
|
|
@ -1213,7 +1213,7 @@ target_resists_magic(unit * magician, void *obj, int objtyp, int t_bonus)
|
|||
|
||||
bool is_magic_resistant(unit * magician, unit * target, int resist_bonus)
|
||||
{
|
||||
return (bool)target_resists_magic(magician, target, TYP_UNIT,
|
||||
return target_resists_magic(magician, target, TYP_UNIT,
|
||||
resist_bonus);
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ attrib_type at_market = {
|
|||
|
||||
bool markets_module(void)
|
||||
{
|
||||
return (bool)config_get_int("modules.market", 0);
|
||||
return config_get_int("modules.market", 0) != 0;
|
||||
}
|
||||
|
||||
void do_markets(void)
|
||||
|
|
|
@ -892,7 +892,7 @@ static void drifting_ships(region * r)
|
|||
|
||||
static bool present(region * r, unit * u)
|
||||
{
|
||||
return (bool)(u && u->region == r);
|
||||
return (u && u->region == r);
|
||||
}
|
||||
|
||||
static void caught_target(region * r, unit * u)
|
||||
|
|
|
@ -683,7 +683,7 @@ bufunit(const faction * f, const unit * u, seen_mode mode, char *buf,
|
|||
int i, dh;
|
||||
int getarnt = fval(u, UFL_ANON_FACTION);
|
||||
const char *pzTmp, *str;
|
||||
bool isbattle = (bool)(mode == seen_battle);
|
||||
bool isbattle = (mode == seen_battle);
|
||||
item *itm, *show = NULL;
|
||||
faction *fv;
|
||||
char *bufp = buf;
|
||||
|
|
|
@ -58,8 +58,8 @@ static const char *getbuf_utf8(FILE * F)
|
|||
eatwhite(bp, &white); /* decoding errors will get caught later on, don't have to check */
|
||||
bp += white;
|
||||
|
||||
comment = (bool)(comment && cont);
|
||||
quote = (bool)(quote && cont);
|
||||
comment = (comment && cont);
|
||||
quote = (quote && cont);
|
||||
|
||||
if (tail[1] == 0) {
|
||||
/* we read the maximum number of bytes! */
|
||||
|
|
Loading…
Reference in New Issue