fixing killunit (triggering dead units)

This commit is contained in:
Enno Rehling 2008-05-24 17:34:55 +00:00
parent 32097e56cb
commit 4988d0f425
7 changed files with 66 additions and 62 deletions

View File

@ -67,7 +67,6 @@ CCFLAGS += -Wwrite-strings
# -Wconversion # -Wconversion
# -Wunreachable-code # -Wunreachable-code
-Werror -Werror
-fstrict-aliasing
; ;
# this require the latet luabind from CVS # this require the latet luabind from CVS
@ -148,7 +147,7 @@ rule TargetDirectory
else { else {
SubDirCcFlags -DNDEBUG -mtune=$(CPU) ; SubDirCcFlags -DNDEBUG -mtune=$(CPU) ;
SubDirC++Flags -DNDEBUG -mtune=$(CPU) ; SubDirC++Flags -DNDEBUG -mtune=$(CPU) ;
OPTIM = -O3 ; OPTIM = -O3 -fno-strict-aliasing ;
} }
} }

View File

@ -375,21 +375,6 @@ setstealth_cmd(unit * u, struct order * ord)
return 0; 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 static int
crew_skill(region * r, faction * f, ship * sh, skill_t sk) crew_skill(region * r, faction * f, ship * sh, skill_t sk)
{ {

View File

@ -345,6 +345,7 @@ remove_unit(unit ** ulist, unit * u)
dhash(u->no, u->faction); dhash(u->no, u->faction);
u_setfaction(u, NULL); u_setfaction(u, NULL);
u->region = NULL;
return 0; return 0;
} }

View File

@ -40,10 +40,9 @@ killunit_handle(trigger * t, void * data)
* data.v -> ( variant event, int timer ) * data.v -> ( variant event, int timer )
*/ */
unit * u = (unit*)t->data.v; unit * u = (unit*)t->data.v;
if (u!=NULL) { if (u) {
remove_unit(&u->region->units, u); /* we can't remove_unit() here, because that's what's calling us. */
} else { set_number(u, 0);
log_warning(("could not perform killunit::handle()\n"));
} }
unused(data); unused(data);
return 0; return 0;

View File

@ -20,29 +20,31 @@ typedef struct parser_state {
static parser_state * state; static parser_state * state;
static int static int
eatwhitespace_c(const char ** str) eatwhitespace_c(const char ** str_p)
{ {
int ret; int ret = 0;
ucs4_t ucs; ucs4_t ucs;
size_t len; size_t len;
const char * str = *str_p;
/* skip over potential whitespace */ /* skip over potential whitespace */
for (;;) { for (;;) {
unsigned char utf8_character = (*(unsigned char**)str)[0]; unsigned char utf8_character = (unsigned char)*str;
if (~utf8_character & 0x80) { if (~utf8_character & 0x80) {
if (!iswspace(utf8_character)) break; if (!iswspace(utf8_character)) break;
++*str; ++str;
} else { } else {
ret = unicode_utf8_to_ucs4(&ucs, *str, &len); ret = unicode_utf8_to_ucs4(&ucs, str, &len);
if (ret!=0) { if (ret!=0) {
log_warning(("illegal character sequence in UTF8 string: %s\n", *str)); log_warning(("illegal character sequence in UTF8 string: %s\n", str));
return ret; break;
} }
if (!iswspace((wint_t)ucs)) break; if (!iswspace((wint_t)ucs)) break;
*str+=len; str+=len;
} }
} }
return 0; *str_p = str;
return ret;
} }
void void

View File

@ -1,8 +1,18 @@
-- the locales that this gameworld supports.
local locales = { "de", "en" } 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 = { scripts = {
"default.lua",
"spells.lua", "spells.lua",
"extensions.lua", "extensions.lua",
"familiars.lua", "familiars.lua",
@ -10,11 +20,7 @@ function run_scripts()
"hse/stats.lua" "hse/stats.lua"
} }
for index, value in pairs(scripts) do for index, value in pairs(scripts) do
local script = scriptpath .. "/" .. value loadscript(value)
print("- loading " .. script)
if pcall(dofile, script)==0 then
print("Could not load " .. script)
end
end end
end end
@ -22,43 +28,48 @@ function refresh_pool()
for f in factions() do for f in factions() do
f:add_item("money", 50) f:add_item("money", 50)
end end
end end
function process(orders) function process(orders)
file = "" .. get_turn() -- initialize starting equipment for new players
if read_game(file)~=0 then if open_game(get_turn())~=0 then
print("could not read game") print("could not read game")
return -1 return -1
end end
init_summary() init_summary()
-- kill multi-players (external script)
-- loadscript("eressea/multis.lua")
-- run the turn: -- run the turn:
read_orders(orders) set_encoding("utf8")
run_scripts() if read_orders(orders) ~= 0 then
print("could not read " .. orders)
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")
return -1 return -1
end end
write_stats("grails.txt") plan_monsters()
end 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 -- main body of script
-- --
-- orderfile: contains the name of the orders. -- orderfile: contains the name of the orders.
load_scripts()
if orderfile==nil then if orderfile==nil then
print "you must specify an orderfile" print "you must specify an orderfile"
else else

View File

@ -51,9 +51,8 @@ function test_free()
end end
function test_hse() function test_hse()
read_game("50", "text") read_game("50", "text")
write_game("50.dat", "binary") write_game("50.dat", "binary")
write_game("50.txt.1", "text")
end end
function test_realloc() function test_realloc()
@ -76,14 +75,22 @@ function test_bmark()
print(os.clock() - t1) print(os.clock() - t1)
end end
function test_md5()
read_game("571.dat", "binary")
-- read_orders("orders.571")
run_turn()
write_game("572.txt", "text")
end
loadscript("default.lua") loadscript("default.lua")
run_scripts() run_scripts()
-- go -- go
-- test_free() -- test_free()
-- test_bmark() -- test_bmark()
test_realloc() -- test_realloc()
-- test_hse() -- test_hse()
io.stdin:read("*line") test_md5()
-- io.stdin:read("*line")
-- text: 50.574 -- text: 50.574
-- bin0: 19.547 -- bin0: 19.547
-- bin1: 18.953 -- bin1: 18.953