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
# -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 ;
}
}

View File

@ -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)
{

View File

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

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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