From 4988d0f425482ead9ff709fdec06759ac3d32f74 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 24 May 2008 17:34:55 +0000 Subject: [PATCH] fixing killunit (triggering dead units) --- src/Jamrules | 3 +- src/common/gamecode/spy.c | 15 -------- src/common/kernel/unit.c | 1 + src/common/triggers/killunit.c | 7 ++-- src/common/util/parser.c | 20 ++++++----- src/scripts/hse4-run.lua | 65 ++++++++++++++++++++-------------- src/scripts/run-tests.lua | 17 ++++++--- 7 files changed, 66 insertions(+), 62 deletions(-) diff --git a/src/Jamrules b/src/Jamrules index 2bffa5687..063761db9 100644 --- a/src/Jamrules +++ b/src/Jamrules @@ -67,7 +67,6 @@ CCFLAGS += -Wwrite-strings # -Wconversion # -Wunreachable-code -Werror - -fstrict-aliasing ; # this require the latet luabind from CVS @@ -148,7 +147,7 @@ rule TargetDirectory else { SubDirCcFlags -DNDEBUG -mtune=$(CPU) ; SubDirC++Flags -DNDEBUG -mtune=$(CPU) ; - OPTIM = -O3 ; + OPTIM = -O3 -fno-strict-aliasing ; } } diff --git a/src/common/gamecode/spy.c b/src/common/gamecode/spy.c index c5771b036..44b9372be 100644 --- a/src/common/gamecode/spy.c +++ b/src/common/gamecode/spy.c @@ -375,21 +375,6 @@ setstealth_cmd(unit * u, struct order * ord) return 0; } -static int -faction_skill(region * r, faction * f, skill_t sk) -{ - int value = 0; - unit *u; - - for (u=r->units; u; u=u->next) { - if (u->faction == f) { - int s = eff_skill(u, sk, r); - value = max(value, s); - } - } - return value; -} - static int crew_skill(region * r, faction * f, ship * sh, skill_t sk) { diff --git a/src/common/kernel/unit.c b/src/common/kernel/unit.c index 56d04b2b0..8179a10e3 100644 --- a/src/common/kernel/unit.c +++ b/src/common/kernel/unit.c @@ -345,6 +345,7 @@ remove_unit(unit ** ulist, unit * u) dhash(u->no, u->faction); u_setfaction(u, NULL); + u->region = NULL; return 0; } diff --git a/src/common/triggers/killunit.c b/src/common/triggers/killunit.c index 193d393ec..02cad7e9d 100644 --- a/src/common/triggers/killunit.c +++ b/src/common/triggers/killunit.c @@ -40,10 +40,9 @@ killunit_handle(trigger * t, void * data) * data.v -> ( variant event, int timer ) */ unit * u = (unit*)t->data.v; - if (u!=NULL) { - remove_unit(&u->region->units, u); - } else { - log_warning(("could not perform killunit::handle()\n")); + if (u) { + /* we can't remove_unit() here, because that's what's calling us. */ + set_number(u, 0); } unused(data); return 0; diff --git a/src/common/util/parser.c b/src/common/util/parser.c index 8d2fdf87b..7c8391547 100644 --- a/src/common/util/parser.c +++ b/src/common/util/parser.c @@ -20,29 +20,31 @@ typedef struct parser_state { static parser_state * state; static int -eatwhitespace_c(const char ** str) +eatwhitespace_c(const char ** str_p) { - int ret; + int ret = 0; ucs4_t ucs; size_t len; + const char * str = *str_p; /* skip over potential whitespace */ for (;;) { - unsigned char utf8_character = (*(unsigned char**)str)[0]; + unsigned char utf8_character = (unsigned char)*str; if (~utf8_character & 0x80) { if (!iswspace(utf8_character)) break; - ++*str; + ++str; } else { - ret = unicode_utf8_to_ucs4(&ucs, *str, &len); + ret = unicode_utf8_to_ucs4(&ucs, str, &len); if (ret!=0) { - log_warning(("illegal character sequence in UTF8 string: %s\n", *str)); - return ret; + log_warning(("illegal character sequence in UTF8 string: %s\n", str)); + break; } if (!iswspace((wint_t)ucs)) break; - *str+=len; + str+=len; } } - return 0; + *str_p = str; + return ret; } void diff --git a/src/scripts/hse4-run.lua b/src/scripts/hse4-run.lua index becdcbdb3..ec311dd5c 100644 --- a/src/scripts/hse4-run.lua +++ b/src/scripts/hse4-run.lua @@ -1,8 +1,18 @@ +-- the locales that this gameworld supports. local locales = { "de", "en" } -function run_scripts() +function loadscript(name) + local script = scriptpath .. "/" .. name + print("- loading " .. script) + if pcall(dofile, script)==0 then + print("Could not load " .. script) + end +end + +loadscript("default.lua") + +function load_scripts() scripts = { - "default.lua", "spells.lua", "extensions.lua", "familiars.lua", @@ -10,11 +20,7 @@ function run_scripts() "hse/stats.lua" } for index, value in pairs(scripts) do - local script = scriptpath .. "/" .. value - print("- loading " .. script) - if pcall(dofile, script)==0 then - print("Could not load " .. script) - end + loadscript(value) end end @@ -22,43 +28,48 @@ function refresh_pool() for f in factions() do f:add_item("money", 50) end -end - +end + function process(orders) - file = "" .. get_turn() - if read_game(file)~=0 then + -- initialize starting equipment for new players + if open_game(get_turn())~=0 then print("could not read game") return -1 end init_summary() + -- kill multi-players (external script) + -- loadscript("eressea/multis.lua") + -- run the turn: - read_orders(orders) - run_scripts() - - spawn_braineaters(0.25) - plan_monsters() - process_orders() - - refresh_pool() - - write_files(locales) - - file = "" .. get_turn() - if write_game(file)~=0 then - print("could not write game") + set_encoding("utf8") + if read_orders(orders) ~= 0 then + print("could not read " .. orders) return -1 end - write_stats("grails.txt") -end + plan_monsters() + process_orders() + -- create new monsters: + spawn_braineaters(0.25) + + refresh_pool() + write_files(locales) + + file = "" .. get_turn() .. ".dat" + if write_game(file, "binary")~=0 then + print("could not write game") + return -1 + end +end -- -- main body of script -- -- orderfile: contains the name of the orders. +load_scripts() if orderfile==nil then print "you must specify an orderfile" else diff --git a/src/scripts/run-tests.lua b/src/scripts/run-tests.lua index e66e60e10..837a9b494 100644 --- a/src/scripts/run-tests.lua +++ b/src/scripts/run-tests.lua @@ -51,9 +51,8 @@ function test_free() end function test_hse() - read_game("50", "text") - write_game("50.dat", "binary") - write_game("50.txt.1", "text") + read_game("50", "text") + write_game("50.dat", "binary") end function test_realloc() @@ -76,14 +75,22 @@ function test_bmark() print(os.clock() - t1) end +function test_md5() + read_game("571.dat", "binary") + -- read_orders("orders.571") + run_turn() + write_game("572.txt", "text") +end + loadscript("default.lua") run_scripts() -- go -- test_free() -- test_bmark() -test_realloc() +-- test_realloc() -- test_hse() -io.stdin:read("*line") +test_md5() +-- io.stdin:read("*line") -- text: 50.574 -- bin0: 19.547 -- bin1: 18.953