"Zeilenumbruch im Einheitennamen"
- prevented line breaks in unit names

http://eressea.upb.de/mantis/view.php?id=1436
"lc_age throws an exception"
- fixed adding tostring() in script.
- not calling std::terminate

also:
- added AT_AGE_* macros to be returned from attrib-age functions
This commit is contained in:
Enno Rehling 2008-06-03 07:28:32 +00:00
parent b973330061
commit e26700c8b1
16 changed files with 104 additions and 57 deletions

View File

@ -24,7 +24,7 @@ age_reduceproduction(attrib *a)
int reduce = 100 - (5 * --a->data.sa[1]);
if (reduce < 10) reduce = 10;
a->data.sa[0] = (short)reduce;
return a->data.sa[1];
return (a->data.sa[1]>0)?AT_AGE_KEEP:AT_AGE_REMOVE;
}
attrib_type at_reduceproduction = {

View File

@ -45,7 +45,7 @@
static int
age_peaceimmune(attrib * a)
{
return --a->data.i;
return (--a->data.i>0)?AT_AGE_KEEP:AT_AGE_REMOVE;
}
static attrib_type at_peaceimmune = {

View File

@ -46,7 +46,7 @@ attrib_type at_faction_special = {
int
age_prayer_timeout(attrib *a) {
return --a->data.sa[0];
return (--a->data.sa[0]>0)?AT_AGE_KEEP:AT_AGE_REMOVE;
}
attrib_type at_prayer_timeout = {

View File

@ -151,10 +151,10 @@ a_ageicastle(struct attrib * a)
ADDMSG(&r->msgs, msg_message("icastle_dissolve", "building", b));
/* remove_building lets units leave the building */
remove_building(&r->buildings, b);
return 0;
return AT_AGE_REMOVE;
}
else data->time--;
return 1;
return AT_AGE_KEEP;
}
static void
@ -2345,7 +2345,7 @@ age_unit(attrib * a)
/* if unit is gone or dead, remove the attribute */
{
unit * u = (unit*)a->data.v;
return (u!=NULL && u->number>0);
return (u!=NULL && u->number>0)?AT_AGE_KEEP:AT_AGE_REMOVE;
}
attrib_type at_familiarmage = {

View File

@ -131,8 +131,7 @@ shiptrail_age(attrib *a)
traveldir *t = (traveldir *)(a->data.v);
t->age--;
if(t->age == 0) return 0;
return 1;
return (t->age>0)?AT_AGE_KEEP:AT_AGE_REMOVE;
}
static int
@ -170,7 +169,7 @@ age_speedup(attrib *a)
if (a->data.sa[0] > 0) {
a->data.sa[0] = a->data.sa[0] - a->data.sa[1];
}
return a->data.sa[0]>0;
return (a->data.sa[0]>0)?AT_AGE_KEEP:AT_AGE_REMOVE;
}
attrib_type at_speedup = {

View File

@ -203,11 +203,8 @@ static int
a_agedirection(attrib *a)
{
spec_direction *d = (spec_direction *)(a->data.v);
if (d->duration > 0) d->duration--;
else d->duration = 0;
return d->duration;
--d->duration;
return (d->duration>0)?AT_AGE_KEEP:AT_AGE_REMOVE;
}
typedef struct dir_lookup {

View File

@ -720,7 +720,7 @@ leftship_age(struct attrib * a)
{
/* must be aged, so it doesn't affect report generation (cansee) */
unused(a);
return 0; /* remove me */
return AT_AGE_REMOVE; /* remove me */
}
static attrib_type at_leftship = {

View File

@ -197,7 +197,7 @@ age_hurting(attrib * a) {
building * b = (building *)a->data.v;
unit * u;
int active = 0;
if (b==NULL) return 0;
if (b==NULL) return AT_AGE_REMOVE;
for (u=b->region->units;u;u=u->next) {
if (u->building==b) {
if (u->faction->magiegebiet==M_CHAOS) {
@ -213,7 +213,7 @@ age_hurting(attrib * a) {
ADDMSG(&b->region->msgs, msg_message("cryinpain", "unit", u));
}
}
return 1;
return AT_AGE_KEEP;
}
static void

View File

@ -98,7 +98,7 @@ wormhole_age(struct attrib * a)
ADDMSG(&r->msgs, msg_message("wormhole_dissolve", "region", r));
/* age returns 0 if the attribute needs to be removed, !=0 otherwise */
return -1;
return AT_AGE_KEEP;
}
static void

View File

@ -2805,10 +2805,8 @@ static int
wall_age(border * b)
{
wall_data * fd = (wall_data*)b->data.v;
if (fd->countdown>0) {
if (--fd->countdown==0) return 0;
}
return fd->countdown;
--fd->countdown;
return (fd->countdown>0)?AT_AGE_KEEP:AT_AGE_REMOVE;
}
static region *
@ -3140,7 +3138,7 @@ dc_age(struct curse * c)
if (r==NULL || mage==NULL || mage->number==0) {
/* if the mage disappears, so does the spell. */
return -1;
return AT_AGE_REMOVE;
}
up = &r->units;
@ -3161,7 +3159,7 @@ dc_age(struct curse * c)
if (*up==u) up=&u->next;
}
return 0;
return AT_AGE_KEEP;
}
static struct curse_type ct_deathcloud = {

View File

@ -242,8 +242,15 @@ a_age(attrib ** p)
* hat Einfluß auf den Besitzer */
while(*ap) {
attrib * a = *ap;
if (a->type->age && a->type->age(a)==0) a_remove(p, a);
else ap = &a->next;
if (a->type->age) {
int result = a->type->age(a);
assert(result>=0 || !"age() returned a negative value");
if (result==0) {
a_remove(p, a);
continue;
}
}
ap = &a->next;
}
return (*p!=NULL);
}

View File

@ -18,7 +18,7 @@
extern "C" {
#endif
struct storage;
struct storage;
typedef void (*afun)(void);
typedef struct attrib {
@ -80,6 +80,9 @@ extern void a_write(struct storage * store, const attrib * attribs);
#define AT_READ_OK 0
#define AT_READ_FAIL -1
#define AT_AGE_REMOVE 0 /* remove the attribute after calling age() */
#define AT_AGE_KEEP 1 /* keep the attribute for another turn */
#ifdef __cplusplus
}
#endif

View File

@ -217,23 +217,29 @@ getbuf_utf8(FILE * F)
size_t size;
int ret;
if (!quote) {
while (*bp==COMMENT_CHAR) {
/* comment begins. we need to keep going, to look for CONTINUE_CHAR */
comment = true;
++bp;
}
}
if (*bp=='\n' || *bp=='\r') {
/* line breaks, shmine breaks */
break;
}
if (*bp==COMMENT_CHAR && !quote) {
/* comment begins. we need to keep going, to look for CONTINUE_CHAR */
comment = true;
++bp;
}
if (*bp=='"' || *bp=='\'') {
if (quote==*bp) {
quote = 0;
if (cp<fbuf+MAXLINE) *cp++ = *bp++;
if (cp<fbuf+MAXLINE) *cp++ = *bp;
++bp;
continue;
} else if (!quote) {
quote = *bp++;
if (cp<fbuf+MAXLINE) *cp++ = quote;
continue;
}
}

View File

@ -50,30 +50,28 @@ lc_age(struct attrib * a)
int retval = -1;
assert(b!=NULL);
if (fname==NULL) return -1;
lua_State * L = (lua_State *)global.vm_state;
if (is_function(L, fname)) {
try {
if (fparam) {
#ifdef TUNNELS /* TODO: Why does this crash? */
std::string param(fparam);
retval = luabind::call_function<int>(L, fname, *b, param);
#endif
} else {
retval = luabind::call_function<int>(L, fname, *b);
if (fname!=NULL) {
lua_State * L = (lua_State *)global.vm_state;
if (is_function(L, fname)) {
try {
if (fparam) {
std::string param(fparam);
retval = luabind::call_function<int>(L, fname, *b, param);
} else {
retval = luabind::call_function<int>(L, fname, *b);
}
}
catch (luabind::error& e) {
lua_State* L = e.state();
const char* error = lua_tostring(L, -1);
log_error(("An exception occured while %s tried to call '%s': %s.\n",
buildingname(b), fname, error));
lua_pop(L, 1);
/* std::terminate(); */
}
}
catch (luabind::error& e) {
lua_State* L = e.state();
const char* error = lua_tostring(L, -1);
log_error(("An exception occured while %s tried to call '%s': %s.\n",
buildingname(b), fname, error));
lua_pop(L, 1);
std::terminate();
}
}
return retval;
return (retval!=0)?AT_AGE_KEEP:AT_AGE_REMOVE;
}
static int

View File

@ -30,7 +30,7 @@ end
-- export, will be called from lc_age()
function tunnel_action(b, param)
local r = nil
print("Tunnel from " .. b .. " [" .. param .. "]")
print("Tunnel from " .. tostring(b) .. " [" .. param .. "]")
if tonumber(param)~=nil then
r = get_region_by_id(tonumber(param))
end
@ -43,7 +43,7 @@ function tunnel_action(b, param)
end
if rto~=nil then
u.region = rto
print(" - teleported " .. u .. " to " .. rto)
print(" - teleported " .. tostring(u) .. " to " .. tostring(rto))
end
end
end

View File

@ -94,13 +94,52 @@ function test_287()
write_game("287.dat", "binary")
end
function tunnel_action(b, param)
local r = nil
print("Tunnel from " .. tostring(b) .. " [" .. param .. "]")
if tonumber(param)~=nil then
r = get_region_by_id(tonumber(param))
end
if r~=nil then
local units = tunnel_travelers(b)
for key, u in pairs(units) do
local rto = r
if r==nil then
rto = get_target(param)
end
if rto~=nil then
u.region = rto
print(" - teleported " .. tostring(u) .. " to " .. tostring(rto))
end
end
end
return 1 -- return 0 to destroy
end
function action(b, param)
print(b)
print(param)
return 1
end
function test_tunnels()
r = terraform(0, 0, "glacier")
b = add_building(r, "portal")
b:add_action("tunnel_action", "tnnL")
r2 = terraform(5, 5, "plain")
r2:set_key("tnnL", true)
process_orders()
end
loadscript("default.lua")
run_scripts()
-- go
-- test_free()
-- test_bmark()
-- test_realloc()
test_hse()
-- test_hse()
test_tunnels()
-- test_md5()
-- test_287()
-- io.stdin:read("*line")