forked from github/server
preloading lua files (for running tests.lua) from eressea.ini
fixed building taxes test
This commit is contained in:
parent
97daeead0c
commit
23b1d33f77
|
@ -61,7 +61,7 @@ typedef struct building_type {
|
||||||
void (*init)(struct building_type*);
|
void (*init)(struct building_type*);
|
||||||
void (*age)(struct building *);
|
void (*age)(struct building *);
|
||||||
int (*protection)(struct building *, struct unit *);
|
int (*protection)(struct building *, struct unit *);
|
||||||
float (*taxes)(struct building *);
|
double (*taxes)(struct building *);
|
||||||
struct attrib * attribs;
|
struct attrib * attribs;
|
||||||
} building_type;
|
} building_type;
|
||||||
|
|
||||||
|
|
|
@ -320,7 +320,7 @@ parse_buildings(xmlDocPtr doc)
|
||||||
} else if (strcmp((const char*)propValue, "protection")==0) {
|
} else if (strcmp((const char*)propValue, "protection")==0) {
|
||||||
btype->protection = (int (*)(struct building*, struct unit *))fun;
|
btype->protection = (int (*)(struct building*, struct unit *))fun;
|
||||||
} else if (strcmp((const char*)propValue, "taxes")==0) {
|
} else if (strcmp((const char*)propValue, "taxes")==0) {
|
||||||
btype->taxes = (float (*)(struct building*))fun;
|
btype->taxes = (double (*)(struct building*))fun;
|
||||||
} else if (strcmp((const char*)propValue, "age")==0) {
|
} else if (strcmp((const char*)propValue, "age")==0) {
|
||||||
btype->age = (void (*)(struct building*))fun;
|
btype->age = (void (*)(struct building*))fun;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -171,6 +171,7 @@ static boolean g_writemap = false;
|
||||||
static boolean g_ignore_errors = false;
|
static boolean g_ignore_errors = false;
|
||||||
static boolean opt_reportonly = false;
|
static boolean opt_reportonly = false;
|
||||||
static const char * luafile = NULL;
|
static const char * luafile = NULL;
|
||||||
|
static const char * preload = NULL;
|
||||||
static const char * script_path = "scripts";
|
static const char * script_path = "scripts";
|
||||||
static int memdebug = 0;
|
static int memdebug = 0;
|
||||||
|
|
||||||
|
@ -267,6 +268,10 @@ static const struct {
|
||||||
{LUA_IOLIBNAME, luaopen_io},
|
{LUA_IOLIBNAME, luaopen_io},
|
||||||
{LUA_STRLIBNAME, luaopen_string},
|
{LUA_STRLIBNAME, luaopen_string},
|
||||||
{LUA_MATHLIBNAME, luaopen_math},
|
{LUA_MATHLIBNAME, luaopen_math},
|
||||||
|
/*
|
||||||
|
{LUA_LOADLIBNAME, luaopen_package},
|
||||||
|
{LUA_DBLIBNAME, luaopen_debug},
|
||||||
|
*/
|
||||||
#if LUA_VERSION_NUM>=501
|
#if LUA_VERSION_NUM>=501
|
||||||
{LUA_OSLIBNAME, luaopen_os},
|
{LUA_OSLIBNAME, luaopen_os},
|
||||||
#endif
|
#endif
|
||||||
|
@ -588,6 +593,7 @@ load_inifile(const char * filename)
|
||||||
verbosity = iniparser_getint(d, "eressea:verbose", 2);
|
verbosity = iniparser_getint(d, "eressea:verbose", 2);
|
||||||
battledebug = iniparser_getint(d, "eressea:debug", battledebug)?1:0;
|
battledebug = iniparser_getint(d, "eressea:debug", battledebug)?1:0;
|
||||||
|
|
||||||
|
preload = iniparser_getstring(d, "eressea:preload", preload);
|
||||||
luafile = iniparser_getstring(d, "eressea:run", luafile);
|
luafile = iniparser_getstring(d, "eressea:run", luafile);
|
||||||
g_reportdir = iniparser_getstring(d, "eressea:report", g_reportdir);
|
g_reportdir = iniparser_getstring(d, "eressea:report", g_reportdir);
|
||||||
|
|
||||||
|
@ -657,7 +663,7 @@ main(int argc, char *argv[])
|
||||||
int i;
|
int i;
|
||||||
char * lc_ctype;
|
char * lc_ctype;
|
||||||
char * lc_numeric;
|
char * lc_numeric;
|
||||||
lua_State * luaState = lua_init();
|
lua_State * L = lua_init();
|
||||||
static int write_csv = 1;
|
static int write_csv = 1;
|
||||||
|
|
||||||
setup_signal_handler();
|
setup_signal_handler();
|
||||||
|
@ -671,14 +677,14 @@ main(int argc, char *argv[])
|
||||||
if (lc_ctype) lc_ctype = strdup(lc_ctype);
|
if (lc_ctype) lc_ctype = strdup(lc_ctype);
|
||||||
if (lc_numeric) lc_numeric = strdup(lc_numeric);
|
if (lc_numeric) lc_numeric = strdup(lc_numeric);
|
||||||
|
|
||||||
global.vm_state = luaState;
|
global.vm_state = L;
|
||||||
load_inifile("eressea.ini");
|
load_inifile("eressea.ini");
|
||||||
if (verbosity>=4) {
|
if (verbosity>=4) {
|
||||||
printf("\n%s PBEM host\n"
|
printf("\n%s PBEM host\n"
|
||||||
"Copyright (C) 1996-2005 C. Schlittchen, K. Zedel, E. Rehling, H. Peters.\n\n"
|
"Copyright (C) 1996-2005 C. Schlittchen, K. Zedel, E. Rehling, H. Peters.\n\n"
|
||||||
"Compilation: " __DATE__ " at " __TIME__ "\nVersion: %f\n\n", global.gamename, version());
|
"Compilation: " __DATE__ " at " __TIME__ "\nVersion: %f\n\n", global.gamename, version());
|
||||||
}
|
}
|
||||||
if ((i=read_args(argc, argv, luaState))!=0) return i;
|
if ((i=read_args(argc, argv, L))!=0) return i;
|
||||||
|
|
||||||
#ifdef CRTDBG
|
#ifdef CRTDBG
|
||||||
init_crtdbg();
|
init_crtdbg();
|
||||||
|
@ -692,7 +698,24 @@ main(int argc, char *argv[])
|
||||||
write_spells();
|
write_spells();
|
||||||
}
|
}
|
||||||
/* run the main script */
|
/* run the main script */
|
||||||
if (luafile==NULL) lua_console(luaState);
|
if (preload!=NULL) {
|
||||||
|
char * tokens = strdup(preload);
|
||||||
|
char * filename = strtok(tokens, ":");
|
||||||
|
while (filename) {
|
||||||
|
char buf[MAX_PATH];
|
||||||
|
if (script_path) {
|
||||||
|
sprintf(buf, "%s/%s", script_path, filename);
|
||||||
|
}
|
||||||
|
else strcpy(buf, filename);
|
||||||
|
lua_getglobal(L, "dofile");
|
||||||
|
lua_pushstring(L, buf);
|
||||||
|
if (lua_pcall(L, 1, 0, 0) != 0) {
|
||||||
|
my_lua_error(L);
|
||||||
|
}
|
||||||
|
filename = strtok(NULL, ":");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (luafile==NULL) lua_console(L);
|
||||||
else {
|
else {
|
||||||
char buf[MAX_PATH];
|
char buf[MAX_PATH];
|
||||||
if (script_path) {
|
if (script_path) {
|
||||||
|
@ -701,7 +724,7 @@ main(int argc, char *argv[])
|
||||||
else strcpy(buf, luafile);
|
else strcpy(buf, luafile);
|
||||||
#ifdef BINDINGS_LUABIND
|
#ifdef BINDINGS_LUABIND
|
||||||
try {
|
try {
|
||||||
luabind::call_function<int>(luaState, "dofile", buf);
|
luabind::call_function<int>(L, "dofile", buf);
|
||||||
}
|
}
|
||||||
catch (std::runtime_error& rte) {
|
catch (std::runtime_error& rte) {
|
||||||
log_error(("%s.\n", rte.what()));
|
log_error(("%s.\n", rte.what()));
|
||||||
|
@ -711,10 +734,10 @@ main(int argc, char *argv[])
|
||||||
my_lua_error(L);
|
my_lua_error(L);
|
||||||
}
|
}
|
||||||
#elif defined(BINDINGS_TOLUA)
|
#elif defined(BINDINGS_TOLUA)
|
||||||
lua_getglobal(luaState, "dofile");
|
lua_getglobal(L, "dofile");
|
||||||
lua_pushstring(luaState, buf);
|
lua_pushstring(L, buf);
|
||||||
if (lua_pcall(luaState, 1, 0, 0) != 0) {
|
if (lua_pcall(L, 1, 0, 0) != 0) {
|
||||||
my_lua_error(luaState);
|
my_lua_error(L);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -723,7 +746,7 @@ main(int argc, char *argv[])
|
||||||
#endif
|
#endif
|
||||||
game_done();
|
game_done();
|
||||||
kernel_done();
|
kernel_done();
|
||||||
lua_done(luaState);
|
lua_done(L);
|
||||||
log_close();
|
log_close();
|
||||||
|
|
||||||
setlocale(LC_CTYPE, lc_ctype);
|
setlocale(LC_CTYPE, lc_ctype);
|
||||||
|
|
|
@ -122,6 +122,14 @@ tolua_building_get_id(lua_State* L)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
tolua_building_get_type(lua_State* L)
|
||||||
|
{
|
||||||
|
building * self = (building *)tolua_tousertype(L, 1, 0);
|
||||||
|
tolua_pushstring(L, self->type->_name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
tolua_building_create(lua_State* L)
|
tolua_building_create(lua_State* L)
|
||||||
{
|
{
|
||||||
|
@ -160,6 +168,7 @@ tolua_building_open(lua_State* L)
|
||||||
tolua_function(L, "__tostring", tolua_building_tostring);
|
tolua_function(L, "__tostring", tolua_building_tostring);
|
||||||
|
|
||||||
tolua_variable(L, "id", tolua_building_get_id, NULL);
|
tolua_variable(L, "id", tolua_building_get_id, NULL);
|
||||||
|
tolua_variable(L, "type", tolua_building_get_type, NULL);
|
||||||
tolua_variable(L, "name", tolua_building_get_name, tolua_building_set_name);
|
tolua_variable(L, "name", tolua_building_get_name, tolua_building_set_name);
|
||||||
tolua_variable(L, "units", tolua_building_get_units, NULL);
|
tolua_variable(L, "units", tolua_building_get_units, NULL);
|
||||||
tolua_variable(L, "region", tolua_building_get_region, tolua_building_set_region);
|
tolua_variable(L, "region", tolua_building_get_region, tolua_building_set_region);
|
||||||
|
|
|
@ -435,12 +435,12 @@ lua_building_protection(building * b, unit * u)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static float
|
static double
|
||||||
lua_building_taxes(building * b)
|
lua_building_taxes(building * b)
|
||||||
{
|
{
|
||||||
lua_State * L = (lua_State *)global.vm_state;
|
lua_State * L = (lua_State *)global.vm_state;
|
||||||
const char * fname = "building_taxes";
|
const char * fname = "building_taxes";
|
||||||
float result = 0.0F;
|
double result = 0.0F;
|
||||||
|
|
||||||
lua_pushstring(L, fname);
|
lua_pushstring(L, fname);
|
||||||
lua_rawget(L, LUA_GLOBALSINDEX);
|
lua_rawget(L, LUA_GLOBALSINDEX);
|
||||||
|
@ -453,7 +453,7 @@ lua_building_taxes(building * b)
|
||||||
buildingname(b), fname, error));
|
buildingname(b), fname, error));
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
} else {
|
} else {
|
||||||
result = (float)lua_tonumber(L, -1);
|
result = (double)lua_tonumber(L, -1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log_error(("building_taxes(%s) calling '%s': not a function.\n",
|
log_error(("building_taxes(%s) calling '%s': not a function.\n",
|
||||||
|
|
|
@ -116,6 +116,11 @@
|
||||||
<param name="modules.wormholes" value="0"/>
|
<param name="modules.wormholes" value="0"/>
|
||||||
<param name="modules.markets" value="1"/>
|
<param name="modules.markets" value="1"/>
|
||||||
|
|
||||||
|
<!-- resource limitations -->
|
||||||
|
<param name="magic.regeneration" value="0.5"/>
|
||||||
|
<param name="magic.power" value="0.5"/>
|
||||||
|
<param name="resource.factor" value="0.25"/>
|
||||||
|
|
||||||
<param name="skills.cost" value="500"/>
|
<param name="skills.cost" value="500"/>
|
||||||
<param name="entertain.base" value="0"/>
|
<param name="entertain.base" value="0"/>
|
||||||
<param name="entertain.perlevel" value="20"/>
|
<param name="entertain.perlevel" value="20"/>
|
||||||
|
|
|
@ -9,8 +9,6 @@ function loadscript(name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
loadscript("default.lua")
|
|
||||||
|
|
||||||
function change_locales()
|
function change_locales()
|
||||||
-- local localechange = { }
|
-- local localechange = { }
|
||||||
local localechange = { de = { "rtph" } }
|
local localechange = { de = { "rtph" } }
|
||||||
|
@ -30,7 +28,6 @@ function load_scripts()
|
||||||
scripts = {
|
scripts = {
|
||||||
"spells.lua",
|
"spells.lua",
|
||||||
"extensions.lua",
|
"extensions.lua",
|
||||||
"e3a/rules.lua"
|
|
||||||
}
|
}
|
||||||
for index, value in pairs(scripts) do
|
for index, value in pairs(scripts) do
|
||||||
loadscript(value)
|
loadscript(value)
|
||||||
|
|
|
@ -360,7 +360,7 @@ function test_taxes()
|
||||||
u:clear_orders()
|
u:clear_orders()
|
||||||
u:add_order("LERNE Wahrnehmung")
|
u:add_order("LERNE Wahrnehmung")
|
||||||
local b = building.create(r, "watch")
|
local b = building.create(r, "watch")
|
||||||
b.size = 4
|
b.size = 10
|
||||||
u.building = b
|
u.building = b
|
||||||
update_owners()
|
update_owners()
|
||||||
process_orders()
|
process_orders()
|
||||||
|
|
Loading…
Reference in New Issue