forked from github/server
lua: resource-level, read_game w/ one parameter
This commit is contained in:
parent
93bb27fb07
commit
4e2abeb559
3 changed files with 25 additions and 5 deletions
|
@ -17,6 +17,7 @@ without prior permission by the authors of Eressea.
|
|||
#include "bind_building.h"
|
||||
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/resources.h>
|
||||
#include <kernel/unit.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/item.h>
|
||||
|
@ -128,6 +129,24 @@ static int tolua_region_set_flag(lua_State* tolua_S)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_get_resourcelevel(lua_State* tolua_S)
|
||||
{
|
||||
region * r = (region *)tolua_tousertype(tolua_S, 1, 0);
|
||||
const char * type = tolua_tostring(tolua_S, 2, 0);
|
||||
const resource_type * rtype = rt_find(type);
|
||||
if (rtype!=NULL) {
|
||||
const rawmaterial * rm;
|
||||
for (rm=r->resources;rm;rm=rm->next) {
|
||||
if (rm->type->rtype==rtype) {
|
||||
tolua_pushnumber(tolua_S, (lua_Number)rm->level);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_get_resource(lua_State* tolua_S)
|
||||
{
|
||||
|
@ -320,6 +339,7 @@ tolua_region_open(lua_State* tolua_S)
|
|||
tolua_variable(tolua_S, "ships", tolua_region_get_ships, NULL);
|
||||
tolua_variable(tolua_S, "buildings", tolua_region_get_buildings, NULL);
|
||||
tolua_variable(tolua_S, "terrain", tolua_region_get_terrain, NULL);
|
||||
tolua_function(tolua_S, "get_resourcelevel", tolua_region_get_resourcelevel);
|
||||
tolua_function(tolua_S, "get_resource", tolua_region_get_resource);
|
||||
tolua_function(tolua_S, "set_resource", tolua_region_set_resource);
|
||||
tolua_function(tolua_S, "get_flag", tolua_region_get_flag);
|
||||
|
|
|
@ -15,7 +15,7 @@ without prior permission by the authors of Eressea.
|
|||
#include "bind_unit.h"
|
||||
#include "bindings.h"
|
||||
|
||||
// Atributes includes
|
||||
// attributes includes
|
||||
#include <attributes/racename.h>
|
||||
#include <attributes/key.h>
|
||||
|
||||
|
|
|
@ -543,8 +543,8 @@ tolua_write_game(lua_State* tolua_S)
|
|||
const char * filename = tolua_tostring(tolua_S, 1, 0);
|
||||
const char * mode = tolua_tostring(tolua_S, 2, 0);
|
||||
|
||||
int result, m = IO_TEXT;
|
||||
if (strcmp(mode, "text")!=0) m = IO_BINARY;
|
||||
int result, m = IO_BINARY;
|
||||
if (mode && strcmp(mode, "text")==0) m = IO_TEXT;
|
||||
remove_empty_factions(true);
|
||||
result = writegame(filename, m);
|
||||
|
||||
|
@ -558,8 +558,8 @@ tolua_read_game(lua_State* tolua_S)
|
|||
const char * filename = tolua_tostring(tolua_S, 1, 0);
|
||||
const char * mode = tolua_tostring(tolua_S, 2, 0);
|
||||
|
||||
int rv, m = IO_TEXT;
|
||||
if (strcmp(mode, "text")!=0) m = IO_BINARY;
|
||||
int rv, m = IO_BINARY;
|
||||
if (mode && strcmp(mode, "text")==0) m = IO_TEXT;
|
||||
rv = readgame(filename, m, false);
|
||||
|
||||
tolua_pushnumber(tolua_S, (lua_Number)rv);
|
||||
|
|
Loading…
Reference in a new issue