lua: resource-level, read_game w/ one parameter

This commit is contained in:
Enno Rehling 2009-01-21 08:25:43 +00:00
parent 93bb27fb07
commit 4e2abeb559
3 changed files with 25 additions and 5 deletions

View File

@ -17,6 +17,7 @@ without prior permission by the authors of Eressea.
#include "bind_building.h" #include "bind_building.h"
#include <kernel/region.h> #include <kernel/region.h>
#include <kernel/resources.h>
#include <kernel/unit.h> #include <kernel/unit.h>
#include <kernel/region.h> #include <kernel/region.h>
#include <kernel/item.h> #include <kernel/item.h>
@ -128,6 +129,24 @@ static int tolua_region_set_flag(lua_State* tolua_S)
return 0; 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 static int
tolua_region_get_resource(lua_State* tolua_S) 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, "ships", tolua_region_get_ships, NULL);
tolua_variable(tolua_S, "buildings", tolua_region_get_buildings, NULL); tolua_variable(tolua_S, "buildings", tolua_region_get_buildings, NULL);
tolua_variable(tolua_S, "terrain", tolua_region_get_terrain, 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, "get_resource", tolua_region_get_resource);
tolua_function(tolua_S, "set_resource", tolua_region_set_resource); tolua_function(tolua_S, "set_resource", tolua_region_set_resource);
tolua_function(tolua_S, "get_flag", tolua_region_get_flag); tolua_function(tolua_S, "get_flag", tolua_region_get_flag);

View File

@ -15,7 +15,7 @@ without prior permission by the authors of Eressea.
#include "bind_unit.h" #include "bind_unit.h"
#include "bindings.h" #include "bindings.h"
// Atributes includes // attributes includes
#include <attributes/racename.h> #include <attributes/racename.h>
#include <attributes/key.h> #include <attributes/key.h>

View File

@ -543,8 +543,8 @@ tolua_write_game(lua_State* tolua_S)
const char * filename = tolua_tostring(tolua_S, 1, 0); const char * filename = tolua_tostring(tolua_S, 1, 0);
const char * mode = tolua_tostring(tolua_S, 2, 0); const char * mode = tolua_tostring(tolua_S, 2, 0);
int result, m = IO_TEXT; int result, m = IO_BINARY;
if (strcmp(mode, "text")!=0) m = IO_BINARY; if (mode && strcmp(mode, "text")==0) m = IO_TEXT;
remove_empty_factions(true); remove_empty_factions(true);
result = writegame(filename, m); 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 * filename = tolua_tostring(tolua_S, 1, 0);
const char * mode = tolua_tostring(tolua_S, 2, 0); const char * mode = tolua_tostring(tolua_S, 2, 0);
int rv, m = IO_TEXT; int rv, m = IO_BINARY;
if (strcmp(mode, "text")!=0) m = IO_BINARY; if (mode && strcmp(mode, "text")==0) m = IO_TEXT;
rv = readgame(filename, m, false); rv = readgame(filename, m, false);
tolua_pushnumber(tolua_S, (lua_Number)rv); tolua_pushnumber(tolua_S, (lua_Number)rv);