forked from github/server
"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:
parent
b973330061
commit
e26700c8b1
16 changed files with 104 additions and 57 deletions
|
@ -24,7 +24,7 @@ age_reduceproduction(attrib *a)
|
||||||
int reduce = 100 - (5 * --a->data.sa[1]);
|
int reduce = 100 - (5 * --a->data.sa[1]);
|
||||||
if (reduce < 10) reduce = 10;
|
if (reduce < 10) reduce = 10;
|
||||||
a->data.sa[0] = (short)reduce;
|
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 = {
|
attrib_type at_reduceproduction = {
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
static int
|
static int
|
||||||
age_peaceimmune(attrib * a)
|
age_peaceimmune(attrib * a)
|
||||||
{
|
{
|
||||||
return --a->data.i;
|
return (--a->data.i>0)?AT_AGE_KEEP:AT_AGE_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static attrib_type at_peaceimmune = {
|
static attrib_type at_peaceimmune = {
|
||||||
|
|
|
@ -46,7 +46,7 @@ attrib_type at_faction_special = {
|
||||||
|
|
||||||
int
|
int
|
||||||
age_prayer_timeout(attrib *a) {
|
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 = {
|
attrib_type at_prayer_timeout = {
|
||||||
|
|
|
@ -151,10 +151,10 @@ a_ageicastle(struct attrib * a)
|
||||||
ADDMSG(&r->msgs, msg_message("icastle_dissolve", "building", b));
|
ADDMSG(&r->msgs, msg_message("icastle_dissolve", "building", b));
|
||||||
/* remove_building lets units leave the building */
|
/* remove_building lets units leave the building */
|
||||||
remove_building(&r->buildings, b);
|
remove_building(&r->buildings, b);
|
||||||
return 0;
|
return AT_AGE_REMOVE;
|
||||||
}
|
}
|
||||||
else data->time--;
|
else data->time--;
|
||||||
return 1;
|
return AT_AGE_KEEP;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -2345,7 +2345,7 @@ age_unit(attrib * a)
|
||||||
/* if unit is gone or dead, remove the attribute */
|
/* if unit is gone or dead, remove the attribute */
|
||||||
{
|
{
|
||||||
unit * u = (unit*)a->data.v;
|
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 = {
|
attrib_type at_familiarmage = {
|
||||||
|
|
|
@ -131,8 +131,7 @@ shiptrail_age(attrib *a)
|
||||||
traveldir *t = (traveldir *)(a->data.v);
|
traveldir *t = (traveldir *)(a->data.v);
|
||||||
|
|
||||||
t->age--;
|
t->age--;
|
||||||
if(t->age == 0) return 0;
|
return (t->age>0)?AT_AGE_KEEP:AT_AGE_REMOVE;
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -170,7 +169,7 @@ age_speedup(attrib *a)
|
||||||
if (a->data.sa[0] > 0) {
|
if (a->data.sa[0] > 0) {
|
||||||
a->data.sa[0] = a->data.sa[0] - a->data.sa[1];
|
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 = {
|
attrib_type at_speedup = {
|
||||||
|
|
|
@ -203,11 +203,8 @@ static int
|
||||||
a_agedirection(attrib *a)
|
a_agedirection(attrib *a)
|
||||||
{
|
{
|
||||||
spec_direction *d = (spec_direction *)(a->data.v);
|
spec_direction *d = (spec_direction *)(a->data.v);
|
||||||
|
--d->duration;
|
||||||
if (d->duration > 0) d->duration--;
|
return (d->duration>0)?AT_AGE_KEEP:AT_AGE_REMOVE;
|
||||||
else d->duration = 0;
|
|
||||||
|
|
||||||
return d->duration;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct dir_lookup {
|
typedef struct dir_lookup {
|
||||||
|
|
|
@ -720,7 +720,7 @@ leftship_age(struct attrib * a)
|
||||||
{
|
{
|
||||||
/* must be aged, so it doesn't affect report generation (cansee) */
|
/* must be aged, so it doesn't affect report generation (cansee) */
|
||||||
unused(a);
|
unused(a);
|
||||||
return 0; /* remove me */
|
return AT_AGE_REMOVE; /* remove me */
|
||||||
}
|
}
|
||||||
|
|
||||||
static attrib_type at_leftship = {
|
static attrib_type at_leftship = {
|
||||||
|
|
|
@ -197,7 +197,7 @@ age_hurting(attrib * a) {
|
||||||
building * b = (building *)a->data.v;
|
building * b = (building *)a->data.v;
|
||||||
unit * u;
|
unit * u;
|
||||||
int active = 0;
|
int active = 0;
|
||||||
if (b==NULL) return 0;
|
if (b==NULL) return AT_AGE_REMOVE;
|
||||||
for (u=b->region->units;u;u=u->next) {
|
for (u=b->region->units;u;u=u->next) {
|
||||||
if (u->building==b) {
|
if (u->building==b) {
|
||||||
if (u->faction->magiegebiet==M_CHAOS) {
|
if (u->faction->magiegebiet==M_CHAOS) {
|
||||||
|
@ -213,7 +213,7 @@ age_hurting(attrib * a) {
|
||||||
ADDMSG(&b->region->msgs, msg_message("cryinpain", "unit", u));
|
ADDMSG(&b->region->msgs, msg_message("cryinpain", "unit", u));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return AT_AGE_KEEP;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -98,7 +98,7 @@ wormhole_age(struct attrib * a)
|
||||||
ADDMSG(&r->msgs, msg_message("wormhole_dissolve", "region", r));
|
ADDMSG(&r->msgs, msg_message("wormhole_dissolve", "region", r));
|
||||||
|
|
||||||
/* age returns 0 if the attribute needs to be removed, !=0 otherwise */
|
/* age returns 0 if the attribute needs to be removed, !=0 otherwise */
|
||||||
return -1;
|
return AT_AGE_KEEP;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -2805,10 +2805,8 @@ static int
|
||||||
wall_age(border * b)
|
wall_age(border * b)
|
||||||
{
|
{
|
||||||
wall_data * fd = (wall_data*)b->data.v;
|
wall_data * fd = (wall_data*)b->data.v;
|
||||||
if (fd->countdown>0) {
|
--fd->countdown;
|
||||||
if (--fd->countdown==0) return 0;
|
return (fd->countdown>0)?AT_AGE_KEEP:AT_AGE_REMOVE;
|
||||||
}
|
|
||||||
return fd->countdown;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static region *
|
static region *
|
||||||
|
@ -3140,7 +3138,7 @@ dc_age(struct curse * c)
|
||||||
|
|
||||||
if (r==NULL || mage==NULL || mage->number==0) {
|
if (r==NULL || mage==NULL || mage->number==0) {
|
||||||
/* if the mage disappears, so does the spell. */
|
/* if the mage disappears, so does the spell. */
|
||||||
return -1;
|
return AT_AGE_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
up = &r->units;
|
up = &r->units;
|
||||||
|
@ -3161,7 +3159,7 @@ dc_age(struct curse * c)
|
||||||
if (*up==u) up=&u->next;
|
if (*up==u) up=&u->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return AT_AGE_KEEP;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct curse_type ct_deathcloud = {
|
static struct curse_type ct_deathcloud = {
|
||||||
|
|
|
@ -242,8 +242,15 @@ a_age(attrib ** p)
|
||||||
* hat Einfluß auf den Besitzer */
|
* hat Einfluß auf den Besitzer */
|
||||||
while(*ap) {
|
while(*ap) {
|
||||||
attrib * a = *ap;
|
attrib * a = *ap;
|
||||||
if (a->type->age && a->type->age(a)==0) a_remove(p, a);
|
if (a->type->age) {
|
||||||
else ap = &a->next;
|
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);
|
return (*p!=NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,6 +80,9 @@ extern void a_write(struct storage * store, const attrib * attribs);
|
||||||
#define AT_READ_OK 0
|
#define AT_READ_OK 0
|
||||||
#define AT_READ_FAIL -1
|
#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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -217,23 +217,29 @@ getbuf_utf8(FILE * F)
|
||||||
size_t size;
|
size_t size;
|
||||||
int ret;
|
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') {
|
if (*bp=='\n' || *bp=='\r') {
|
||||||
/* line breaks, shmine breaks */
|
/* line breaks, shmine breaks */
|
||||||
break;
|
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 (*bp=='"' || *bp=='\'') {
|
||||||
if (quote==*bp) {
|
if (quote==*bp) {
|
||||||
quote = 0;
|
quote = 0;
|
||||||
if (cp<fbuf+MAXLINE) *cp++ = *bp++;
|
if (cp<fbuf+MAXLINE) *cp++ = *bp;
|
||||||
|
++bp;
|
||||||
|
continue;
|
||||||
} else if (!quote) {
|
} else if (!quote) {
|
||||||
quote = *bp++;
|
quote = *bp++;
|
||||||
if (cp<fbuf+MAXLINE) *cp++ = quote;
|
if (cp<fbuf+MAXLINE) *cp++ = quote;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,16 +50,13 @@ lc_age(struct attrib * a)
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
|
|
||||||
assert(b!=NULL);
|
assert(b!=NULL);
|
||||||
if (fname==NULL) return -1;
|
if (fname!=NULL) {
|
||||||
|
|
||||||
lua_State * L = (lua_State *)global.vm_state;
|
lua_State * L = (lua_State *)global.vm_state;
|
||||||
if (is_function(L, fname)) {
|
if (is_function(L, fname)) {
|
||||||
try {
|
try {
|
||||||
if (fparam) {
|
if (fparam) {
|
||||||
#ifdef TUNNELS /* TODO: Why does this crash? */
|
|
||||||
std::string param(fparam);
|
std::string param(fparam);
|
||||||
retval = luabind::call_function<int>(L, fname, *b, param);
|
retval = luabind::call_function<int>(L, fname, *b, param);
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
retval = luabind::call_function<int>(L, fname, *b);
|
retval = luabind::call_function<int>(L, fname, *b);
|
||||||
}
|
}
|
||||||
|
@ -70,10 +67,11 @@ lc_age(struct attrib * a)
|
||||||
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
||||||
buildingname(b), fname, error));
|
buildingname(b), fname, error));
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
std::terminate();
|
/* std::terminate(); */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return retval;
|
}
|
||||||
|
return (retval!=0)?AT_AGE_KEEP:AT_AGE_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
|
@ -30,7 +30,7 @@ end
|
||||||
-- export, will be called from lc_age()
|
-- export, will be called from lc_age()
|
||||||
function tunnel_action(b, param)
|
function tunnel_action(b, param)
|
||||||
local r = nil
|
local r = nil
|
||||||
print("Tunnel from " .. b .. " [" .. param .. "]")
|
print("Tunnel from " .. tostring(b) .. " [" .. param .. "]")
|
||||||
if tonumber(param)~=nil then
|
if tonumber(param)~=nil then
|
||||||
r = get_region_by_id(tonumber(param))
|
r = get_region_by_id(tonumber(param))
|
||||||
end
|
end
|
||||||
|
@ -43,7 +43,7 @@ function tunnel_action(b, param)
|
||||||
end
|
end
|
||||||
if rto~=nil then
|
if rto~=nil then
|
||||||
u.region = rto
|
u.region = rto
|
||||||
print(" - teleported " .. u .. " to " .. rto)
|
print(" - teleported " .. tostring(u) .. " to " .. tostring(rto))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -94,13 +94,52 @@ function test_287()
|
||||||
write_game("287.dat", "binary")
|
write_game("287.dat", "binary")
|
||||||
end
|
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")
|
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()
|
||||||
|
test_tunnels()
|
||||||
-- test_md5()
|
-- test_md5()
|
||||||
-- test_287()
|
-- test_287()
|
||||||
-- io.stdin:read("*line")
|
-- io.stdin:read("*line")
|
||||||
|
|
Loading…
Reference in a new issue