forked from github/server
- new: get_* functions accept base36 strings
- new tests for that. - some fixes for create() calls with illegal parameters - removed unused growing_trees() function
This commit is contained in:
parent
27493d6b8d
commit
18e7e14fc9
10 changed files with 74 additions and 32 deletions
|
@ -675,7 +675,7 @@ count_race(const region *r, const race *rc)
|
|||
extern struct attrib_type at_germs;
|
||||
|
||||
static void
|
||||
trees(region * r, const int current_season, const int last_weeks_season)
|
||||
growing_trees(region * r, const int current_season, const int last_weeks_season)
|
||||
{
|
||||
int growth, grownup_trees, i, seeds, sprout;
|
||||
direction_t d;
|
||||
|
@ -852,7 +852,7 @@ demographics(void)
|
|||
plagues(r, false);
|
||||
horses(r);
|
||||
if (current_season != SEASON_WINTER) {
|
||||
trees(r, current_season, last_weeks_season);
|
||||
growing_trees(r, current_season, last_weeks_season);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -124,6 +124,7 @@ building_type *
|
|||
bt_find(const char* name)
|
||||
{
|
||||
const struct building_typelist * btl = buildingtypes;
|
||||
assert(name);
|
||||
while (btl && strcmp(btl->type->_name, name)) btl = btl->next;
|
||||
if (btl==NULL) {
|
||||
return NULL;
|
||||
|
|
|
@ -362,20 +362,6 @@ get_timeout(trigger * td, trigger * tfind)
|
|||
#include <triggers/shock.h>
|
||||
#include <triggers/killunit.h>
|
||||
|
||||
int
|
||||
growing_trees(void)
|
||||
{
|
||||
region *r;
|
||||
|
||||
for(r=regions; r; r=r->next) {
|
||||
if(rtrees(r, 2)) {
|
||||
rsettrees(r, 1, rtrees(r, 2)/4);
|
||||
rsettrees(r, 0, rtrees(r, 2)/2);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
fix_undead(void)
|
||||
{
|
||||
|
|
|
@ -127,10 +127,13 @@ tolua_building_create(lua_State* tolua_S)
|
|||
{
|
||||
region * r = (region *)tolua_tousertype(tolua_S, 1, 0);
|
||||
const char * bname = tolua_tostring(tolua_S, 2, 0);
|
||||
const building_type * btype = bt_find(bname);
|
||||
building * b = new_building(btype, r, NULL);
|
||||
tolua_pushusertype(tolua_S, (void*)b, "building");
|
||||
return 1;
|
||||
if (bname) {
|
||||
const building_type * btype = bt_find(bname);
|
||||
building * b = new_building(btype, r, NULL);
|
||||
tolua_pushusertype(tolua_S, (void*)b, "building");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
|
@ -108,11 +108,16 @@ tolua_ship_create(lua_State* tolua_S)
|
|||
{
|
||||
region * r = (region *)tolua_tousertype(tolua_S, 1, 0);
|
||||
const char * sname = tolua_tostring(tolua_S, 2, 0);
|
||||
const ship_type * stype = st_find(sname);
|
||||
ship * sh = new_ship(stype, NULL, r);
|
||||
sh->size = stype->construction->maxsize;
|
||||
tolua_pushusertype(tolua_S, (void*)sh, "ship");
|
||||
return 1;
|
||||
if (sname) {
|
||||
const ship_type * stype = st_find(sname);
|
||||
if (stype) {
|
||||
ship * sh = new_ship(stype, NULL, r);
|
||||
sh->size = stype->construction->maxsize;
|
||||
tolua_pushusertype(tolua_S, (void*)sh, "ship");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
|
@ -15,7 +15,7 @@ without prior permission by the authors of Eressea.
|
|||
#include "bind_unit.h"
|
||||
#include "bind_faction.h"
|
||||
#include "bind_region.h"
|
||||
|
||||
#include "helpers.h"
|
||||
|
||||
#include <kernel/eressea.h>
|
||||
|
||||
|
@ -581,7 +581,7 @@ tolua_read_game(lua_State* tolua_S)
|
|||
static int
|
||||
tolua_get_faction(lua_State* tolua_S)
|
||||
{
|
||||
int no = (int)tolua_tonumber(tolua_S, 1, 0);
|
||||
int no = tolua_toid(tolua_S, 1, 0);
|
||||
faction * f = findfaction(no);
|
||||
|
||||
tolua_pushusertype(tolua_S, f, "faction");
|
||||
|
@ -612,7 +612,7 @@ tolua_get_region_byid(lua_State* tolua_S)
|
|||
static int
|
||||
tolua_get_building(lua_State* tolua_S)
|
||||
{
|
||||
int no = (int)tolua_tonumber(tolua_S, 1, 0);
|
||||
int no = tolua_toid(tolua_S, 1, 0);
|
||||
building * b = findbuilding(no);
|
||||
|
||||
tolua_pushusertype(tolua_S, b, "building");
|
||||
|
@ -622,7 +622,7 @@ tolua_get_building(lua_State* tolua_S)
|
|||
static int
|
||||
tolua_get_ship(lua_State* tolua_S)
|
||||
{
|
||||
int no = (int)tolua_tonumber(tolua_S, 1, 0);
|
||||
int no = tolua_toid(tolua_S, 1, 0);
|
||||
ship * sh = findship(no);
|
||||
|
||||
tolua_pushusertype(tolua_S, sh, "ship");
|
||||
|
@ -632,7 +632,7 @@ tolua_get_ship(lua_State* tolua_S)
|
|||
static int
|
||||
tolua_get_alliance(lua_State* tolua_S)
|
||||
{
|
||||
int no = (int)tolua_tonumber(tolua_S, 1, 0);
|
||||
int no = tolua_toid(tolua_S, 1, 0);
|
||||
alliance * f = findalliance(no);
|
||||
|
||||
tolua_pushusertype(tolua_S, f, "alliance");
|
||||
|
@ -642,7 +642,7 @@ tolua_get_alliance(lua_State* tolua_S)
|
|||
static int
|
||||
tolua_get_unit(lua_State* tolua_S)
|
||||
{
|
||||
int no = (int)tolua_tonumber(tolua_S, 1, 0);
|
||||
int no = tolua_toid(tolua_S, 1, 0);
|
||||
unit * u = findunit(no);
|
||||
|
||||
tolua_pushusertype(tolua_S, u, "unit");
|
||||
|
|
|
@ -529,6 +529,20 @@ lua_recruit(struct unit * u, const struct archetype * arch, int amount)
|
|||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
tolua_toid(lua_State* tolua_S, int idx, int def)
|
||||
{
|
||||
int no = 0;
|
||||
int type = lua_type(tolua_S, idx);
|
||||
if (type==LUA_TNUMBER) {
|
||||
no = (int)tolua_tonumber(tolua_S, idx, def);
|
||||
} else {
|
||||
const char * str = tolua_tostring(tolua_S, idx, NULL);
|
||||
no = str?atoi36(str):def;
|
||||
}
|
||||
return no;
|
||||
}
|
||||
|
||||
void
|
||||
register_tolua_helpers(void)
|
||||
{
|
||||
|
|
|
@ -15,6 +15,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
void register_tolua_helpers(void);
|
||||
int tolua_toid(struct lua_State* tolua_S, int idx, int def);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -18,10 +18,11 @@
|
|||
<xi:include href="ships.xml"/>
|
||||
<xi:include href="buildings.xml"/>
|
||||
<xi:include href="equipment.xml"/>
|
||||
<xi:include href="terrains.xml"/>
|
||||
<!--xi:include href="terrains.xml"/-->
|
||||
<xi:include href="dungeons.xml"/>
|
||||
<xi:include href="directions.xml"/>
|
||||
|
||||
<xi:include href="e2k9/terrains.xml"/>
|
||||
<xi:include href="e2k9/calendar.xml"/>
|
||||
<xi:include href="e2k9/items.xml" />
|
||||
<xi:include href="e2k9/strings.xml"/>
|
||||
|
|
|
@ -416,6 +416,35 @@ function test_upkeep()
|
|||
assert(u:get_item("money")==u.number)
|
||||
end
|
||||
|
||||
function test_id()
|
||||
free_game()
|
||||
local r = region.create(0, 0, "plain")
|
||||
|
||||
local f = faction.create("enno@eressea.de", "human", "de")
|
||||
f.id = atoi36("42")
|
||||
assert(get_faction(42)~=f)
|
||||
assert(get_faction("42")==f)
|
||||
assert(get_faction(atoi36("42"))==f)
|
||||
|
||||
local u = unit.create(f, r, 1)
|
||||
u.id = atoi36("42")
|
||||
assert(get_unit(42)~=u)
|
||||
assert(get_unit("42")==u)
|
||||
assert(get_unit(atoi36("42"))==u)
|
||||
|
||||
local b = building.create(r, "castle")
|
||||
-- <not working> b.id = atoi36("42")
|
||||
local fortytwo = itoa36(b.id)
|
||||
assert(get_building(fortytwo)==b)
|
||||
assert(get_building(atoi36(fortytwo))==b)
|
||||
|
||||
local s = ship.create(r, "boat")
|
||||
-- <not working> s.id = atoi36("42")
|
||||
local fortytwo = itoa36(s.id)
|
||||
assert(get_ship(fortytwo)==s)
|
||||
assert(get_ship(atoi36(fortytwo))==s)
|
||||
end
|
||||
|
||||
function test_herbalism()
|
||||
free_game()
|
||||
local r = region.create(0, 0, "plain")
|
||||
|
@ -474,10 +503,12 @@ tests = {
|
|||
["storage"] = test_storage,
|
||||
["taxes"] = test_taxes,
|
||||
["upkeep"] = test_upkeep,
|
||||
["id"] = test_id,
|
||||
["work"] = test_work,
|
||||
["market"] = test_market
|
||||
}
|
||||
mytests = {
|
||||
["id"] = test_id,
|
||||
["upkeep"] = test_upkeep,
|
||||
["taxes"] = test_taxes
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue