From 7563f57432a046ae6af9d24c05278be45cf038c5 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 11 Jul 2009 22:27:31 +0000 Subject: [PATCH] - tolua: destroying objects is good. - begin taking care of multis. --- src/common/kernel/reports.c | 2 +- src/eressea.sln | 7 --- src/eressea/tolua/bind_faction.c | 13 +++++- src/eressea/tolua/bind_region.c | 16 ++++++- src/eressea/tolua/bind_unit.c | 11 +++++ src/eressea/tolua/bindings.c | 4 +- src/scripts/e3a/multi.lua | 2 +- src/scripts/run-e3a.lua | 75 ++++++++++++++++++++++++++++++-- 8 files changed, 112 insertions(+), 18 deletions(-) diff --git a/src/common/kernel/reports.c b/src/common/kernel/reports.c index b0d8d952f..d89c925f8 100644 --- a/src/common/kernel/reports.c +++ b/src/common/kernel/reports.c @@ -200,7 +200,7 @@ update_nmrs(void) for (f = factions; f; f = f->next) { if (fval(f, FFL_ISNEW)) { ++newplayers; - } else if (!is_monsters(f)) { + } else if (!is_monsters(f) && f->alive) { int nmr = turn-f->lastorders+1; if (nmr<0 || nmr>NMRTimeout()) { log_error(("faction %s has %d NMRS\n", factionid(f), nmr)); diff --git a/src/eressea.sln b/src/eressea.sln index 03173a5c8..01b4c779e 100644 --- a/src/eressea.sln +++ b/src/eressea.sln @@ -6,8 +6,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "kernel", "common\kernel.vcp EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gamecode", "common\gamecode.vcproj", "{1E8BFF9E-3044-0742-992F-C5765B80FE65}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bindings", "eressea\lua\bindings.vcproj", "{74B1CBD4-3B6E-E544-9475-33FBB0BCE165}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "editor", "eressea\editor.vcproj", "{D893D6B3-805D-9848-8EA4-CDA1B79151F6}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "eressea-lua", "eressea\eressea-lua.vcproj", "{75501170-51C2-E641-BA8B-EDC008184192}" @@ -16,7 +14,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "eressea-lua", "eressea\eres {F70CFB27-8A2F-E447-B452-4E1C590EDA6D} = {F70CFB27-8A2F-E447-B452-4E1C590EDA6D} {1E8BFF9E-3044-0742-992F-C5765B80FE65} = {1E8BFF9E-3044-0742-992F-C5765B80FE65} {D893D6B3-805D-9848-8EA4-CDA1B79151F6} = {D893D6B3-805D-9848-8EA4-CDA1B79151F6} - {74B1CBD4-3B6E-E544-9475-33FBB0BCE165} = {74B1CBD4-3B6E-E544-9475-33FBB0BCE165} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "eressea", "eressea.vcproj", "{AD80EB0B-7CB4-42F2-9C95-8CCEF68DB387}" @@ -44,10 +41,6 @@ Global {1E8BFF9E-3044-0742-992F-C5765B80FE65}.Profile|Win32.ActiveCfg = Profile|Win32 {1E8BFF9E-3044-0742-992F-C5765B80FE65}.Profile|Win32.Build.0 = Profile|Win32 {1E8BFF9E-3044-0742-992F-C5765B80FE65}.Release|Win32.ActiveCfg = Release|Win32 - {74B1CBD4-3B6E-E544-9475-33FBB0BCE165}.Debug|Win32.ActiveCfg = Debug|Win32 - {74B1CBD4-3B6E-E544-9475-33FBB0BCE165}.Profile|Win32.ActiveCfg = Profile|Win32 - {74B1CBD4-3B6E-E544-9475-33FBB0BCE165}.Profile|Win32.Build.0 = Profile|Win32 - {74B1CBD4-3B6E-E544-9475-33FBB0BCE165}.Release|Win32.ActiveCfg = Release|Win32 {D893D6B3-805D-9848-8EA4-CDA1B79151F6}.Debug|Win32.ActiveCfg = Debug|Win32 {D893D6B3-805D-9848-8EA4-CDA1B79151F6}.Profile|Win32.ActiveCfg = Profile|Win32 {D893D6B3-805D-9848-8EA4-CDA1B79151F6}.Profile|Win32.Build.0 = Profile|Win32 diff --git a/src/eressea/tolua/bind_faction.c b/src/eressea/tolua/bind_faction.c index e0e597ef0..6d4ff8c65 100644 --- a/src/eressea/tolua/bind_faction.c +++ b/src/eressea/tolua/bind_faction.c @@ -274,6 +274,14 @@ tolua_faction_get_origin(lua_State* L) return 2; } +static int +tolua_faction_destroy(lua_State* L) +{ + faction* f = (faction*) tolua_tousertype(L, 1, 0); + destroyfaction(f); + return 0; +} + static int tolua_faction_create(lua_State* L) { @@ -482,8 +490,9 @@ tolua_faction_open(lua_State* L) tolua_function(L, TOLUA_CAST "add_item", tolua_faction_add_item); tolua_variable(L, TOLUA_CAST "items", tolua_faction_get_items, NULL); - tolua_function(L, TOLUA_CAST "renumber", tolua_faction_renumber); - tolua_function(L, TOLUA_CAST "create", tolua_faction_create); + tolua_function(L, TOLUA_CAST "renumber", &tolua_faction_renumber); + tolua_function(L, TOLUA_CAST "create", &tolua_faction_create); + tolua_function(L, TOLUA_CAST "destroy", &tolua_faction_destroy); #ifdef TODO def("faction_origin", &faction_getorigin, pure_out_value(_2) + pure_out_value(_3)), diff --git a/src/eressea/tolua/bind_region.c b/src/eressea/tolua/bind_region.c index 0aeb67cd6..b614f3f5b 100644 --- a/src/eressea/tolua/bind_region.c +++ b/src/eressea/tolua/bind_region.c @@ -84,6 +84,20 @@ tolua_region_get_terrain(lua_State* L) 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); + if (tname) { + const terrain_type * terrain = get_terrain(tname); + if (terrain) { + terraform_region(r, terrain); + } + } + return 0; +} + static int tolua_region_get_terrainname(lua_State* L) { @@ -494,7 +508,7 @@ tolua_region_open(lua_State* L) tolua_variable(L, TOLUA_CAST "ships", tolua_region_get_ships, NULL); tolua_variable(L, TOLUA_CAST "age", tolua_region_get_age, NULL); tolua_variable(L, TOLUA_CAST "buildings", tolua_region_get_buildings, NULL); - tolua_variable(L, TOLUA_CAST "terrain", tolua_region_get_terrain, NULL); + tolua_variable(L, TOLUA_CAST "terrain", tolua_region_get_terrain, tolua_region_set_terrain); tolua_function(L, TOLUA_CAST "get_resourcelevel", tolua_region_get_resourcelevel); tolua_function(L, TOLUA_CAST "get_resource", tolua_region_get_resource); tolua_function(L, TOLUA_CAST "set_resource", tolua_region_set_resource); diff --git a/src/eressea/tolua/bind_unit.c b/src/eressea/tolua/bind_unit.c index 95c017102..ad5937e2d 100644 --- a/src/eressea/tolua/bind_unit.c +++ b/src/eressea/tolua/bind_unit.c @@ -843,6 +843,16 @@ static int tolua_unit_set_race(lua_State* L) return 0; } +static int +tolua_unit_destroy(lua_State* L) +{ + unit * self = (unit *)tolua_tousertype(L, 1, 0); + if (self) { + remove_unit(&self->region->units, self); + } + return 0; +} + static int tolua_unit_create(lua_State* L) { @@ -927,6 +937,7 @@ tolua_unit_open(lua_State * L) { tolua_function(L, TOLUA_CAST "__tostring", &tolua_unit_tostring); tolua_function(L, TOLUA_CAST "create", &tolua_unit_create); + tolua_function(L, TOLUA_CAST "destroy", &tolua_unit_destroy); tolua_variable(L, TOLUA_CAST "name", &tolua_unit_get_name, tolua_unit_set_name); tolua_variable(L, TOLUA_CAST "faction", &tolua_unit_get_faction, tolua_unit_set_faction); diff --git a/src/eressea/tolua/bindings.c b/src/eressea/tolua/bindings.c index 03f500e64..46514dd3a 100644 --- a/src/eressea/tolua/bindings.c +++ b/src/eressea/tolua/bindings.c @@ -363,11 +363,11 @@ tolua_get_nmrs(lua_State * L) { int result = -1; int n = (int)tolua_tonumber(L, 1, 0); - if (n<=NMRTimeout()) { + if (n>=0 && n<=NMRTimeout()) { if (nmrs==NULL) { update_nmrs(); - result = nmrs[n]; } + result = nmrs[n]; } tolua_pushnumber(L, (lua_Number)result); return 1; diff --git a/src/scripts/e3a/multi.lua b/src/scripts/e3a/multi.lua index c605d0ec0..fddfa055c 100644 --- a/src/scripts/e3a/multi.lua +++ b/src/scripts/e3a/multi.lua @@ -1,4 +1,4 @@ -function multi(f) +function mark_multi(f) f.password = "doppelspieler" f.email = "doppelspieler@eressea.de" f.banner = "Diese Partei steht wegen vermuteten Doppelspiels unter Beobachtung." diff --git a/src/scripts/run-e3a.lua b/src/scripts/run-e3a.lua index dab91dc0b..99d2453ea 100644 --- a/src/scripts/run-e3a.lua +++ b/src/scripts/run-e3a.lua @@ -1,18 +1,52 @@ -- the locales that this gameworld supports. local locales = { "de", "en" } -local multis = { +local confirmed_multis = { "agve", "dbgi", "7jfa", "qbki", "gu8y", "wgxe", "iwp0", "r8vz", "78xt", "34fu", "z33r", "fLkr", "yuok" } +local suspected_multis = { +} -function kill_multis() +-- destroy a faction and all of its buildings. +-- destroy the home region, too +function kill_faction(f) + for u in f.units do + if u.building~=nil then + building.destroy(u.building) + u.region.terrain = "firewall" + u.region.terrain_name = nil + end + unit.destroy(u) + end + faction.destroy(f) +end + +function kill_nonstarters() + for f in factions() do + if f.lastturn==1 then + print(f, f.lastturn) + kill_faction(f) + end + end +end + +function kill_multis(multis) + for idx, fno in ipairs(multis) do + local f = get_faction(fno) + if f~=nil and f.email=="doppelspieler@eressea.de" then + kill_faction(f) + end + end +end + +function mark_multis(multis) if multi~=nil and multis~=nil then for idx, fno in ipairs(multis) do local f = get_faction(fno) if f~=nil and f.email~="doppelspieler@eressea.de" then - multi(f) + mark_multi(f) end end end @@ -52,6 +86,35 @@ function load_scripts() end end +function best_scores(n) + local f, numf, top + + numf = 0 + top = { } + for f in factions() do + numf = numf + 1 + local r = 0 + local score = f.score + for i = 1,n do + if top[i]==nil then + top[i] = f + break + end + if top[i].score= 80 then print("Shit. More than 80 factions with 1 NMR (" .. nmrs .. ")") write_summary() + write_game("aborted.dat") return -1 end print (nmrs .. " Factions with 1 NMR") @@ -88,7 +154,7 @@ function process(orders) -- spawn_braineaters(0.25) -- spawn_ents() - kill_multis() + mark_multis(suspected_multis) -- post-turn updates: update_guards() update_scores() @@ -99,6 +165,7 @@ function process(orders) -- autoseed(basepath .. "/newfactions", false) write_files(locales) + write_statistics() file = "" .. get_turn() .. ".dat" if write_game(file, "binary")~=0 then