Merge branch 'develop' of github.com:ennorehling/eressea into develop

This commit is contained in:
Enno Rehling 2015-12-17 20:21:01 +01:00
commit b700cb5a2c
34 changed files with 139 additions and 139 deletions

View File

@ -7503,11 +7503,6 @@
</namespace> </namespace>
<string name="nr_reduced_production">
<text locale="de">Die Region ist verwüstet, der Boden karg.</text>
<text locale="en">The region is ravaged, the ground infertile.</text>
</string>
<string name="par_unit"> <string name="par_unit">
<text locale="de">Einheit-Nr</text> <text locale="de">Einheit-Nr</text>
<text locale="en">unitid</text> <text locale="en">unitid</text>

View File

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<messages> <messages>
<message name="reduced_production">
<text locale="de">Die Region ist verwüstet, der Boden karg.</text>
<text locale="en">The region is ravaged, the ground infertile.</text>
</message>
<message name="force_leave_ship" section="events"> <message name="force_leave_ship" section="events">
<type> <type>
<arg name="unit" type="unit"/> <arg name="unit" type="unit"/>

View File

@ -238,9 +238,10 @@ static void free_potiondelay(attrib * a)
free(a->data.v); free(a->data.v);
} }
static int age_potiondelay(attrib * a) static int age_potiondelay(attrib * a, void *owner)
{ {
potiondelay *pd = (potiondelay *)a->data.v; potiondelay *pd = (potiondelay *)a->data.v;
unused_arg(owner);
pd->amount = do_potion(pd->u, pd->r, pd->ptype, pd->amount); pd->amount = do_potion(pd->u, pd->r, pd->ptype, pd->amount);
return AT_AGE_REMOVE; return AT_AGE_REMOVE;
} }

View File

@ -28,8 +28,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <storage.h> #include <storage.h>
static int verify_hate(attrib * a) static int verify_hate(attrib * a, void *owner)
{ {
unused_arg(owner);
if (a->data.v == NULL) { if (a->data.v == NULL) {
return 0; return 0;
} }

View File

@ -24,8 +24,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <storage.h> #include <storage.h>
static int age_moved(attrib * a) static int age_moved(attrib * a, void *owner)
{ {
unused_arg(owner);
--a->data.i; --a->data.i;
return a->data.i > 0; return a->data.i > 0;
} }

View File

@ -65,8 +65,9 @@ void set_movement(attrib ** alist, int type)
a->data.i |= type; a->data.i |= type;
} }
static int age_speedup(attrib * a) static int age_speedup(attrib * a, void *owner)
{ {
unused_arg(owner);
if (a->data.sa[0] > 0) { if (a->data.sa[0] > 0) {
assert(a->data.sa[0] - a->data.sa[1] >= SHRT_MIN); assert(a->data.sa[0] - a->data.sa[1] >= SHRT_MIN);
assert(a->data.sa[0] - a->data.sa[1] <= SHRT_MAX); assert(a->data.sa[0] - a->data.sa[1] <= SHRT_MAX);

View File

@ -20,15 +20,26 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h> #include <kernel/config.h>
#include "reduceproduction.h" #include "reduceproduction.h"
#include <kernel/save.h> #include <kernel/save.h>
#include <kernel/region.h>
#include <kernel/messages.h>
#include <util/message.h>
#include <util/attrib.h> #include <util/attrib.h>
#include <assert.h>
static int age_reduceproduction(attrib * a) static int age_reduceproduction(attrib * a, void *owner)
{ {
region * r = (region *)owner;
int reduce = 100 - (5 * --a->data.sa[1]); int reduce = 100 - (5 * --a->data.sa[1]);
if (reduce < 10) assert(r);
if (reduce < 10) {
reduce = 10; reduce = 10;
}
a->data.sa[0] = (short)reduce; a->data.sa[0] = (short)reduce;
return (a->data.sa[1] > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE; if (a->data.sa[1] > 0) {
ADDMSG(&r->msgs, msg_message("reduced_production", ""));
return AT_AGE_KEEP;
}
return AT_AGE_REMOVE;
} }
attrib_type at_reduceproduction = { attrib_type at_reduceproduction = {

View File

@ -8,6 +8,7 @@
#include "log.pkg.c" #include "log.pkg.c"
#include "process.pkg.c" #include "process.pkg.c"
#include "settings.pkg.c" #include "settings.pkg.c"
#pragma warning(pop)
void tolua_bind_open(lua_State * L) { void tolua_bind_open(lua_State * L) {
tolua_eressea_open(L); tolua_eressea_open(L);

View File

@ -28,17 +28,16 @@ without prior permission by the authors of Eressea.
#include <string.h> #include <string.h>
typedef struct building_action { typedef struct building_action {
struct building *b;
char *fname; char *fname;
char *param; char *param;
} building_action; } building_action;
static int lc_age(struct attrib *a) static int lc_age(struct attrib *a, void *owner)
{ {
building_action *data = (building_action *)a->data.v; building_action *data = (building_action *)a->data.v;
const char *fname = data->fname; const char *fname = data->fname;
const char *fparam = data->param; const char *fparam = data->param;
building *b = data->b; building *b = (building *)owner;
int result = -1; int result = -1;
assert(b != NULL); assert(b != NULL);
@ -93,9 +92,8 @@ lc_write(const struct attrib *a, const void *owner, struct storage *store)
building_action *data = (building_action *)a->data.v; building_action *data = (building_action *)a->data.v;
const char *fname = data->fname; const char *fname = data->fname;
const char *fparam = data->param; const char *fparam = data->param;
building *b = data->b;
write_building_reference(b, store); unused_arg(owner);
WRITE_TOK(store, fname); WRITE_TOK(store, fname);
WRITE_TOK(store, fparam ? fparam : NULLSTRING); WRITE_TOK(store, fparam ? fparam : NULLSTRING);
} }
@ -104,13 +102,17 @@ static int lc_read(struct attrib *a, void *owner, struct storage *store)
{ {
char name[NAMESIZE]; char name[NAMESIZE];
building_action *data = (building_action *)a->data.v; building_action *data = (building_action *)a->data.v;
int result = building *b = (building *)owner;
read_reference(&data->b, store, read_building_reference, resolve_building); int result = 0;
if (global.data_version < ATTRIBOWNER_VERSION) {
result = read_reference(&b, store, read_building_reference, resolve_building);
assert(b == owner);
}
READ_TOK(store, name, sizeof(name)); READ_TOK(store, name, sizeof(name));
if (strcmp(name, "tunnel_action") == 0) { if (strcmp(name, "tunnel_action") == 0) {
/* E2: Weltentor has a new module, doesn't need this any longer */ /* E2: Weltentor has a new module, doesn't need this any longer */
result = 0; result = 0;
data->b = 0; b = 0;
} }
else { else {
data->fname = _strdup(name); data->fname = _strdup(name);
@ -119,14 +121,14 @@ static int lc_read(struct attrib *a, void *owner, struct storage *store)
if (strcmp(name, "tnnL") == 0) { if (strcmp(name, "tnnL") == 0) {
/* tunnel_action was the old Weltentore, their code has changed. ignore this object */ /* tunnel_action was the old Weltentore, their code has changed. ignore this object */
result = 0; result = 0;
data->b = 0; b = 0;
} }
if (strcmp(name, NULLSTRING) == 0) if (strcmp(name, NULLSTRING) == 0)
data->param = 0; data->param = 0;
else { else {
data->param = _strdup(name); data->param = _strdup(name);
} }
if (result == 0 && !data->b) { if (result == 0 && !b) {
return AT_READ_FAIL; return AT_READ_FAIL;
} }
return AT_READ_OK; return AT_READ_OK;
@ -143,7 +145,6 @@ void building_addaction(building * b, const char *fname, const char *param)
{ {
attrib *a = a_add(&b->attribs, a_new(&at_building_action)); attrib *a = a_add(&b->attribs, a_new(&at_building_action));
building_action *data = (building_action *)a->data.v; building_action *data = (building_action *)a->data.v;
data->b = b;
data->fname = _strdup(fname); data->fname = _strdup(fname);
if (param) { if (param) {
data->param = _strdup(param); data->param = _strdup(param);

View File

@ -45,8 +45,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define HORNDURATION 3 #define HORNDURATION 3
#define HORNIMMUNITY 30 #define HORNIMMUNITY 30
static int age_peaceimmune(attrib * a) static int age_peaceimmune(attrib * a, void *owner)
{ {
unused_arg(owner);
return (--a->data.i > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE; return (--a->data.i > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
} }

View File

@ -112,11 +112,12 @@ void curse_init(attrib * a)
a->data.v = calloc(1, sizeof(curse)); a->data.v = calloc(1, sizeof(curse));
} }
int curse_age(attrib * a) int curse_age(attrib * a, void *owner)
{ {
curse *c = (curse *)a->data.v; curse *c = (curse *)a->data.v;
int result = 0; int result = 0;
unused_arg(owner);
c_clearflag(c, CURSE_ISNEW); c_clearflag(c, CURSE_ISNEW);
if (c_flags(c) & CURSE_NOAGE) { if (c_flags(c) & CURSE_NOAGE) {

View File

@ -291,7 +291,7 @@ extern "C" {
void curse_init(struct attrib *a); void curse_init(struct attrib *a);
void curse_done(struct attrib *a); void curse_done(struct attrib *a);
int curse_age(struct attrib *a); int curse_age(struct attrib *a, void *owner);
double destr_curse(struct curse *c, int cast_level, double force); double destr_curse(struct curse *c, int cast_level, double force);

View File

@ -588,7 +588,9 @@ struct order *ord)
use += use +=
use_pooled(s, item2resource(itype), GET_RESERVE | GET_POOLED_SLACK, use_pooled(s, item2resource(itype), GET_RESERVE | GET_POOLED_SLACK,
n - use); n - use);
if (s->region->land) {
rsetmoney(s->region, rmoney(s->region) + use); rsetmoney(s->region, rmoney(s->region) + use);
}
return 0; return 0;
} }
return -1; /* use the mechanism */ return -1; /* use the mechanism */

View File

@ -603,8 +603,7 @@ void rsetpeasants(region * r, int value)
if (r->land) { if (r->land) {
assert(value >= 0); assert(value >= 0);
r->land->peasants = value; r->land->peasants = value;
} else }
assert(value == 0);
} }
int rmoney(const region * r) int rmoney(const region * r)
@ -617,8 +616,7 @@ void rsethorses(const region * r, int value)
if (r->land) { if (r->land) {
assert(value >= 0); assert(value >= 0);
r->land->horses = value; r->land->horses = value;
} else }
assert(value == 0);
} }
int rhorses(const region * r) int rhorses(const region * r)
@ -631,8 +629,7 @@ void rsetmoney(region * r, int value)
if (r->land) { if (r->land) {
assert(value >= 0); assert(value >= 0);
r->land->money = value; r->land->money = value;
} else }
assert(value == 0);
} }
int rherbs(const struct region *r) int rherbs(const struct region *r)
@ -645,8 +642,7 @@ void rsetherbs(const struct region *r, int value)
if (r->land) { if (r->land) {
assert(value >= 0); assert(value >= 0);
r->land->herbs = (short)(value); r->land->herbs = (short)(value);
} else }
assert(value == 0);
} }

View File

@ -20,7 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h> #include <kernel/config.h>
#include "save.h" #include "save.h"
#include "../buildno.h" #include <buildno.h>
#include "alchemy.h" #include "alchemy.h"
#include "alliance.h" #include "alliance.h"

View File

@ -742,10 +742,11 @@ void set_level(unit * u, skill_t sk, int value)
sk_set(add_skill(u, sk), value); sk_set(add_skill(u, sk), value);
} }
static int leftship_age(struct attrib *a) static int leftship_age(struct attrib *a, void *owner)
{ {
/* must be aged, so it doesn't affect report generation (cansee) */ /* must be aged, so it doesn't affect report generation (cansee) */
unused_arg(a); unused_arg(a);
unused_arg(owner);
return AT_AGE_REMOVE; /* remove me */ return AT_AGE_REMOVE; /* remove me */
} }

View File

@ -331,12 +331,12 @@ static void test_age_familiar(CuTest *tc) {
CuAssertIntEquals(tc, true, create_newfamiliar(mag, fam)); CuAssertIntEquals(tc, true, create_newfamiliar(mag, fam));
CuAssertPtrEquals(tc, fam, get_familiar(mag)); CuAssertPtrEquals(tc, fam, get_familiar(mag));
CuAssertPtrEquals(tc, mag, get_familiar_mage(fam)); CuAssertPtrEquals(tc, mag, get_familiar_mage(fam));
a_age(&fam->attribs); a_age(&fam->attribs, fam);
a_age(&mag->attribs); a_age(&mag->attribs, mag);
CuAssertPtrEquals(tc, fam, get_familiar(mag)); CuAssertPtrEquals(tc, fam, get_familiar(mag));
CuAssertPtrEquals(tc, mag, get_familiar_mage(fam)); CuAssertPtrEquals(tc, mag, get_familiar_mage(fam));
set_number(fam, 0); set_number(fam, 0);
a_age(&mag->attribs); a_age(&mag->attribs, mag);
CuAssertPtrEquals(tc, 0, get_familiar(mag)); CuAssertPtrEquals(tc, 0, get_familiar(mag));
test_cleanup(); test_cleanup();
} }

View File

@ -32,8 +32,9 @@
#define EXPLICIT_CURSE_ISNEW_VERSION 347 /* CURSE_ISNEW is not reset in read/write, but in age() */ #define EXPLICIT_CURSE_ISNEW_VERSION 347 /* CURSE_ISNEW is not reset in read/write, but in age() */
#define SPELL_LEVEL_VERSION 348 /* f->max_spelllevel gets stored, not calculated */ #define SPELL_LEVEL_VERSION 348 /* f->max_spelllevel gets stored, not calculated */
#define OWNER_3_VERSION 349 /* regions store last owner, not last alliance */ #define OWNER_3_VERSION 349 /* regions store last owner, not last alliance */
#define ATTRIBOWNER_VERSION 350 /* all attrib_type functions know who owns the attribute */
#define RELEASE_VERSION OWNER_3_VERSION /* current datafile */ #define RELEASE_VERSION ATTRIBOWNER_VERSION /* current datafile */
#define MIN_VERSION INTPAK_VERSION /* minimal datafile we support */ #define MIN_VERSION INTPAK_VERSION /* minimal datafile we support */
#define MAX_VERSION RELEASE_VERSION /* change this if we can need to read the future datafile, and we can do so */ #define MAX_VERSION RELEASE_VERSION /* change this if we can need to read the future datafile, and we can do so */

View File

@ -3087,7 +3087,7 @@ static building *age_building(building * b)
} }
} }
a_age(&b->attribs); a_age(&b->attribs, b);
handle_event(b->attribs, "timer", b); handle_event(b->attribs, "timer", b);
if (b->type->age) { if (b->type->age) {
@ -3099,7 +3099,7 @@ static building *age_building(building * b)
static void age_region(region * r) static void age_region(region * r)
{ {
a_age(&r->attribs); a_age(&r->attribs, r);
handle_event(r->attribs, "timer", r); handle_event(r->attribs, "timer", r);
if (!r->land) if (!r->land)
@ -3144,7 +3144,7 @@ static void ageing(void)
/* Factions */ /* Factions */
for (f = factions; f; f = f->next) { for (f = factions; f; f = f->next) {
a_age(&f->attribs); a_age(&f->attribs, f);
handle_event(f->attribs, "timer", f); handle_event(f->attribs, "timer", f);
} }
@ -3159,7 +3159,7 @@ static void ageing(void)
/* Einheiten */ /* Einheiten */
for (up = &r->units; *up;) { for (up = &r->units; *up;) {
unit *u = *up; unit *u = *up;
a_age(&u->attribs); a_age(&u->attribs, u);
if (u == *up) if (u == *up)
handle_event(u->attribs, "timer", u); handle_event(u->attribs, "timer", u);
if (u == *up) if (u == *up)
@ -3169,7 +3169,7 @@ static void ageing(void)
/* Schiffe */ /* Schiffe */
for (sp = &r->ships; *sp;) { for (sp = &r->ships; *sp;) {
ship *s = *sp; ship *s = *sp;
a_age(&s->attribs); a_age(&s->attribs, s);
if (s == *sp) if (s == *sp)
handle_event(s->attribs, "timer", s); handle_event(s->attribs, "timer", s);
if (s == *sp) if (s == *sp)

View File

@ -124,19 +124,20 @@ static double MagicPower(double force)
return 0; return 0;
} }
typedef struct icastle_data {
const struct building_type *type;
int time;
} icastle_data;
static int a_readicastle(attrib * a, void *owner, struct storage *store) static int a_readicastle(attrib * a, void *owner, struct storage *store)
{ {
icastle_data *data = (icastle_data *)a->data.v; icastle_data *data = (icastle_data *)a->data.v;
variant bno;
char token[32]; char token[32];
READ_TOK(store, token, sizeof(token)); READ_TOK(store, token, sizeof(token));
READ_INT(store, &bno.i); if (global.data_version < ATTRIBOWNER_VERSION) {
READ_INT(store, &data->time); READ_INT(store, NULL);
data->building = findbuilding(bno.i);
if (!data->building) {
/* this shouldn't happen, but just in case it does: */
ur_add(bno, &data->building, resolve_building);
} }
READ_INT(store, &data->time);
data->type = bt_find(token); data->type = bt_find(token);
return AT_READ_OK; return AT_READ_OK;
} }
@ -145,17 +146,18 @@ static void
a_writeicastle(const attrib * a, const void *owner, struct storage *store) a_writeicastle(const attrib * a, const void *owner, struct storage *store)
{ {
icastle_data *data = (icastle_data *)a->data.v; icastle_data *data = (icastle_data *)a->data.v;
unused_arg(owner);
WRITE_TOK(store, data->type->_name); WRITE_TOK(store, data->type->_name);
WRITE_INT(store, data->building->no);
WRITE_INT(store, data->time); WRITE_INT(store, data->time);
} }
static int a_ageicastle(struct attrib *a) static int a_ageicastle(struct attrib *a, void *owner)
{ {
icastle_data *data = (icastle_data *)a->data.v; icastle_data *data = (icastle_data *)a->data.v;
if (data->time <= 0) { if (data->time <= 0) {
building *b = data->building; building *b = (building *)owner;
region *r = b->region; region *r = b->region;
assert(owner == b);
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);
@ -185,6 +187,17 @@ attrib_type at_icastle = {
a_readicastle a_readicastle
}; };
void make_icastle(building *b, const building_type *btype, int timeout) {
attrib *a = a_add(&b->attribs, a_new(&at_icastle));
icastle_data *data = (icastle_data *)a->data.v;
data->type = btype;
data->time = timeout;
}
const building_type *icastle_type(const struct attrib *a) {
icastle_data *icastle = (icastle_data *)a->data.v;
return icastle->type;
}
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
extern int dice(int count, int value); extern int dice(int count, int value);
@ -2384,10 +2397,11 @@ static int read_magician(attrib * a, void *owner, struct storage *store)
return AT_READ_OK; return AT_READ_OK;
} }
static int age_unit(attrib * a) static int age_unit(attrib * a, void *owner)
/* 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;
unused_arg(owner);
return (u != NULL && u->number > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE; return (u != NULL && u->number > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
} }

View File

@ -206,11 +206,8 @@ extern "C" {
extern struct attrib_type at_reportspell; extern struct attrib_type at_reportspell;
extern struct attrib_type at_icastle; extern struct attrib_type at_icastle;
typedef struct icastle_data { void make_icastle(struct building *b, const struct building_type *btype, int timeout);
const struct building_type *type; const struct building_type *icastle_type(const struct attrib *a);
struct building *building; /* reverse pointer to dissolve the object */
int time;
} icastle_data;
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
/* Kommentare: /* Kommentare:

View File

@ -212,11 +212,12 @@ order * ord)
/** /**
* Tempel der Schreie, Demo-Gebäude **/ * Tempel der Schreie, Demo-Gebäude **/
static int age_hurting(attrib * a) static int age_hurting(attrib * a, void *owner)
{ {
building *b = (building *)a->data.v; building *b = (building *)a->data.v;
unit *u; unit *u;
int active = 0; int active = 0;
assert(owner == b);
if (b == NULL) if (b == NULL)
return AT_AGE_REMOVE; return AT_AGE_REMOVE;
for (u = b->region->units; u; u = u->next) { for (u = b->region->units; u; u = u->next) {

View File

@ -145,9 +145,10 @@ static void shiptrail_finalize(attrib * a)
free(a->data.v); free(a->data.v);
} }
static int shiptrail_age(attrib * a) static int shiptrail_age(attrib * a, void *owner)
{ {
traveldir *t = (traveldir *)(a->data.v); traveldir *t = (traveldir *)(a->data.v);
unused_arg(owner);
t->age--; t->age--;
return (t->age > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE; return (t->age > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;

View File

@ -271,9 +271,9 @@ static void test_age_trails(CuTest *tc) {
move_ship(sh, r1, r2, route); move_ship(sh, r1, r2, route);
CuAssertPtrNotNull(tc, r1->attribs); CuAssertPtrNotNull(tc, r1->attribs);
a_age(&r1->attribs); a_age(&r1->attribs, r1);
CuAssertPtrNotNull(tc, r1->attribs); CuAssertPtrNotNull(tc, r1->attribs);
a_age(&r1->attribs); a_age(&r1->attribs, r1);
CuAssertPtrEquals(tc, 0, r1->attribs); CuAssertPtrEquals(tc, 0, r1->attribs);
free_regionlist(route); free_regionlist(route);
test_cleanup(); test_cleanup();

View File

@ -1235,13 +1235,6 @@ static void describe(stream *out, const seen_region * sr, faction * f)
nr_curses(out, 0, f, TYP_REGION, r); nr_curses(out, 0, f, TYP_REGION, r);
n = 0; n = 0;
/* Produktionsreduktion */
a = a_find(r->attribs, &at_reduceproduction);
if (a) {
const char *str = LOC(f->locale, "nr_reduced_production");
paragraph(out, str, 0, 0, 0);
}
if (edges) if (edges)
newline(out); newline(out);
for (e = edges; e; e = e->next) { for (e = edges; e; e = e->next) {
@ -1268,6 +1261,7 @@ static void describe(stream *out, const seen_region * sr, faction * f)
first = false; first = false;
} }
// TODO name is localized? Works for roads anyway... // TODO name is localized? Works for roads anyway...
// TODO: creating messages during reporting makes them not show up in CR?
msg = msg_message("nr_borderlist_postfix", "transparent object", msg = msg_message("nr_borderlist_postfix", "transparent object",
e->transparent, e->name); e->transparent, e->name);
bytes = (int)nr_render(msg, f->locale, bufp, size, f); bytes = (int)nr_render(msg, f->locale, bufp, size, f);

View File

@ -356,8 +356,7 @@ const char **illusion)
if (bt_illusion && b->type == bt_illusion) { if (bt_illusion && b->type == bt_illusion) {
const attrib *a = a_findc(b->attribs, &at_icastle); const attrib *a = a_findc(b->attribs, &at_icastle);
if (a != NULL) { if (a != NULL) {
icastle_data *icastle = (icastle_data *)a->data.v; *illusion = buildingtype(icastle_type(a), b, b->size);
*illusion = buildingtype(icastle->type, b, b->size);
} }
} }
} }

View File

@ -4477,13 +4477,11 @@ int sp_icastle(castorder * co)
{ {
building *b; building *b;
const building_type *type; const building_type *type;
attrib *a;
region *r = co_get_region(co); region *r = co_get_region(co);
unit *mage = co->magician.u; unit *mage = co->magician.u;
int cast_level = co->level; int cast_level = co->level;
double power = co->force; double power = co->force;
spellparameter *pa = co->par; spellparameter *pa = co->par;
icastle_data *data;
const char *bname; const char *bname;
message *msg; message *msg;
const building_type *bt_illusion = bt_find("illusioncastle"); const building_type *bt_illusion = bt_find("illusioncastle");
@ -4519,12 +4517,7 @@ int sp_icastle(castorder * co)
building_setname(b, bname); building_setname(b, bname);
/* TODO: Auf timeout und action_destroy umstellen */ /* TODO: Auf timeout und action_destroy umstellen */
a = a_add(&b->attribs, a_new(&at_icastle)); make_icastle(b, type, 2 + (rng_int() % (int)(power)+1) * (rng_int() % (int)(power)+1));
data = (icastle_data *)a->data.v;
data->type = type;
data->building = b;
data->time =
2 + (rng_int() % (int)(power)+1) * (rng_int() % (int)(power)+1);
if (mage->region == r) { if (mage->region == r) {
if (leave(mage, false)) { if (leave(mage, false)) {

View File

@ -42,7 +42,7 @@ static void test_good_dreams(CuTest *tc) {
CuAssertTrue(tc, curse && curse->duration > 1); CuAssertTrue(tc, curse && curse->duration > 1);
CuAssertTrue(tc, curse->effect == 1); CuAssertTrue(tc, curse->effect == 1);
a_age(&r->attribs); a_age(&r->attribs, r);
CuAssertIntEquals_Msg(tc, "good dreams give +1 to allies", 1, get_modifier(u1, SK_MELEE, 11, r, false)); CuAssertIntEquals_Msg(tc, "good dreams give +1 to allies", 1, get_modifier(u1, SK_MELEE, 11, r, false));
CuAssertIntEquals_Msg(tc, "good dreams have no effect on non-allies", 0, get_modifier(u2, SK_MELEE, 11, r, false)); CuAssertIntEquals_Msg(tc, "good dreams have no effect on non-allies", 0, get_modifier(u2, SK_MELEE, 11, r, false));
free_castorder(&co); free_castorder(&co);
@ -67,7 +67,7 @@ static void test_dreams(CuTest *tc) {
sp_gooddreams(&co); sp_gooddreams(&co);
sp_baddreams(&co); sp_baddreams(&co);
a_age(&r->attribs); a_age(&r->attribs, r);
CuAssertIntEquals_Msg(tc, "good dreams in same region as bad dreams", 1, get_modifier(u1, SK_MELEE, 11, r, false)); CuAssertIntEquals_Msg(tc, "good dreams in same region as bad dreams", 1, get_modifier(u1, SK_MELEE, 11, r, false));
CuAssertIntEquals_Msg(tc, "bad dreams in same region as good dreams", -1, get_modifier(u2, SK_MELEE, 11, r, false)); CuAssertIntEquals_Msg(tc, "bad dreams in same region as good dreams", -1, get_modifier(u2, SK_MELEE, 11, r, false));
@ -98,7 +98,7 @@ static void test_bad_dreams(CuTest *tc) {
CuAssertTrue(tc, curse && curse->duration > 1); CuAssertTrue(tc, curse && curse->duration > 1);
CuAssertTrue(tc, curse->effect == -1); CuAssertTrue(tc, curse->effect == -1);
a_age(&r->attribs); a_age(&r->attribs, r);
CuAssertIntEquals_Msg(tc, "bad dreams have no effect on allies", 0, get_modifier(u1, SK_MELEE, 11, r, false)); CuAssertIntEquals_Msg(tc, "bad dreams have no effect on allies", 0, get_modifier(u1, SK_MELEE, 11, r, false));
CuAssertIntEquals_Msg(tc, "bad dreams give -1 to non-allies", -1, get_modifier(u2, SK_MELEE, 11, r, false)); CuAssertIntEquals_Msg(tc, "bad dreams give -1 to non-allies", -1, get_modifier(u2, SK_MELEE, 11, r, false));

View File

@ -46,7 +46,7 @@ extern const char *directions[];
typedef struct alp_data { typedef struct alp_data {
unit *mage; unit *mage;
unit *target; unit *target; // TODO: remove, use attribute-owner?
} alp_data; } alp_data;
static void alp_init(attrib * a) static void alp_init(attrib * a)
@ -59,9 +59,10 @@ static void alp_done(attrib * a)
free(a->data.v); free(a->data.v);
} }
static int alp_verify(attrib * a) static int alp_verify(attrib * a, void *owner)
{ {
alp_data *ad = (alp_data *)a->data.v; alp_data *ad = (alp_data *)a->data.v;
unused_arg(owner);
if (ad->mage && ad->target) if (ad->mage && ad->target)
return 1; return 1;
return 0; /* remove the attribute */ return 0; /* remove the attribute */

View File

@ -1,7 +1,7 @@
#include <platform.h> #include <platform.h>
#include "shock.h" #include "shock.h"
#include "../magic.h"
#include <magic.h>
#include <kernel/unit.h> #include <kernel/unit.h>
#include <kernel/faction.h> #include <kernel/faction.h>
#include <util/event.h> #include <util/event.h>

View File

@ -252,7 +252,7 @@ attrib *a_new(const attrib_type * at)
return a; return a;
} }
int a_age(attrib ** p) int a_age(attrib ** p, void *owner)
{ {
attrib **ap = p; attrib **ap = p;
/* Attribute altern, und die Entfernung (age()==0) eines Attributs /* Attribute altern, und die Entfernung (age()==0) eines Attributs
@ -260,7 +260,7 @@ int a_age(attrib ** p)
while (*ap) { while (*ap) {
attrib *a = *ap; attrib *a = *ap;
if (a->type->age) { if (a->type->age) {
int result = a->type->age(a); int result = a->type->age(a, owner);
assert(result >= 0 || !"age() returned a negative value"); assert(result >= 0 || !"age() returned a negative value");
if (result == AT_AGE_REMOVE) { if (result == AT_AGE_REMOVE) {
a_remove(p, a); a_remove(p, a);

View File

@ -52,7 +52,7 @@ extern "C" {
const char *name; const char *name;
void(*initialize) (struct attrib *); void(*initialize) (struct attrib *);
void(*finalize) (struct attrib *); void(*finalize) (struct attrib *);
int(*age) (struct attrib *); int(*age) (struct attrib *, void *owner);
/* age returns 0 if the attribute needs to be removed, !=0 otherwise */ /* age returns 0 if the attribute needs to be removed, !=0 otherwise */
void(*write) (const struct attrib *, const void *owner, struct storage *); void(*write) (const struct attrib *, const void *owner, struct storage *);
int(*read) (struct attrib *, void *owner, struct storage *); /* return AT_READ_OK on success, AT_READ_FAIL if attrib needs removal */ int(*read) (struct attrib *, void *owner, struct storage *); /* return AT_READ_OK on success, AT_READ_FAIL if attrib needs removal */
@ -74,7 +74,7 @@ extern "C" {
extern void a_removeall(attrib ** a, const attrib_type * at); extern void a_removeall(attrib ** a, const attrib_type * at);
extern attrib *a_new(const attrib_type * at); extern attrib *a_new(const attrib_type * at);
extern int a_age(attrib ** attribs); extern int a_age(attrib ** attribs, void *owner);
extern int a_read(struct storage *store, attrib ** attribs, void *owner); extern int a_read(struct storage *store, attrib ** attribs, void *owner);
extern void a_write(struct storage *store, const attrib * attribs, extern void a_write(struct storage *store, const attrib * attribs,
const void *owner); const void *owner);

View File

@ -66,9 +66,10 @@ static void a_freedirection(attrib * a)
free(d); free(d);
} }
static int a_agedirection(attrib * a) static int a_agedirection(attrib * a, void *owner)
{ {
spec_direction *d = (spec_direction *)(a->data.v); spec_direction *d = (spec_direction *)(a->data.v);
unused_arg(owner);
--d->duration; --d->duration;
return (d->duration > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE; return (d->duration > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
} }
@ -78,7 +79,7 @@ static int a_readdirection(attrib * a, void *owner, struct storage *store)
spec_direction *d = (spec_direction *)(a->data.v); spec_direction *d = (spec_direction *)(a->data.v);
char lbuf[32]; char lbuf[32];
(void)owner; unused_arg(owner);
READ_INT(store, &d->x); READ_INT(store, &d->x);
READ_INT(store, &d->y); READ_INT(store, &d->y);
READ_INT(store, &d->duration); READ_INT(store, &d->duration);
@ -95,7 +96,7 @@ a_writedirection(const attrib * a, const void *owner, struct storage *store)
{ {
spec_direction *d = (spec_direction *)(a->data.v); spec_direction *d = (spec_direction *)(a->data.v);
(void)owner; unused_arg(owner);
WRITE_INT(store, d->x); WRITE_INT(store, d->x);
WRITE_INT(store, d->y); WRITE_INT(store, d->y);
WRITE_INT(store, d->duration); WRITE_INT(store, d->duration);

View File

@ -55,39 +55,26 @@ static int cmp_age(const void *v1, const void *v2)
return 0; return 0;
} }
typedef struct wormhole_data { static int wormhole_age(struct attrib *a, void *owner)
building *entry;
region *exit;
} wormhole_data;
static void wormhole_init(struct attrib *a)
{ {
a->data.v = calloc(1, sizeof(wormhole_data)); building *entry = (building *)owner;
} region *exit = (region *)a->data.v;
int maxtransport = entry->size;
static void wormhole_done(struct attrib *a) region *r = entry->region;
{
free(a->data.v);
}
static int wormhole_age(struct attrib *a)
{
wormhole_data *data = (wormhole_data *)a->data.v;
int maxtransport = data->entry->size;
region *r = data->entry->region;
unit *u = r->units; unit *u = r->units;
unused_arg(owner);
for (; u != NULL && maxtransport != 0; u = u->next) { for (; u != NULL && maxtransport != 0; u = u->next) {
if (u->building == data->entry) { if (u->building == entry) {
message *m = NULL; message *m = NULL;
if (u->number > maxtransport || has_limited_skills(u)) { if (u->number > maxtransport || has_limited_skills(u)) {
m = msg_message("wormhole_requirements", "unit region", u, u->region); m = msg_message("wormhole_requirements", "unit region", u, u->region);
} }
else if (data->exit != NULL) { else if (exit != NULL) {
move_unit(u, data->exit, NULL); move_unit(u, exit, NULL);
maxtransport -= u->number; maxtransport -= u->number;
m = msg_message("wormhole_exit", "unit region", u, data->exit); m = msg_message("wormhole_exit", "unit region", u, exit);
add_message(&data->exit->msgs, m); add_message(&exit->msgs, m);
} }
if (m != NULL) { if (m != NULL) {
add_message(&u->faction->msgs, m); add_message(&u->faction->msgs, m);
@ -96,7 +83,7 @@ static int wormhole_age(struct attrib *a)
} }
} }
remove_building(&r->buildings, data->entry); remove_building(&r->buildings, entry);
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 */
@ -105,9 +92,8 @@ static int wormhole_age(struct attrib *a)
static void wormhole_write(const struct attrib *a, const void *owner, struct storage *store) static void wormhole_write(const struct attrib *a, const void *owner, struct storage *store)
{ {
wormhole_data *data = (wormhole_data *)a->data.v; region *exit = (region *)a->data.v;
write_building_reference(data->entry, store); write_region_reference(exit, store);
write_region_reference(data->exit, store);
} }
/** conversion code, turn 573, 2008-05-23 */ /** conversion code, turn 573, 2008-05-23 */
@ -125,18 +111,16 @@ static int resolve_exit(variant id, void *address)
static int wormhole_read(struct attrib *a, void *owner, struct storage *store) static int wormhole_read(struct attrib *a, void *owner, struct storage *store)
{ {
wormhole_data *data = (wormhole_data *)a->data.v;
resolve_fun resolver = (global.data_version < UIDHASH_VERSION) resolve_fun resolver = (global.data_version < UIDHASH_VERSION)
? resolve_exit : resolve_region_id; ? resolve_exit : resolve_region_id;
read_fun reader = (global.data_version < UIDHASH_VERSION) read_fun reader = (global.data_version < UIDHASH_VERSION)
? read_building_reference : read_region_reference; ? read_building_reference : read_region_reference;
int rb = if (global.data_version < ATTRIBOWNER_VERSION) {
read_reference(&data->entry, store, read_building_reference, READ_INT(store, NULL);
resolve_building); }
int rr = read_reference(&data->exit, store, reader, resolver); if (read_reference(&a->data.v, store, reader, resolver) == 0) {
if (rb == 0 && rr == 0) { if (!a->data.v) {
if (!data->exit || !data->entry) {
return AT_READ_FAIL; return AT_READ_FAIL;
} }
} }
@ -145,8 +129,8 @@ static int wormhole_read(struct attrib *a, void *owner, struct storage *store)
static attrib_type at_wormhole = { static attrib_type at_wormhole = {
"wormhole", "wormhole",
wormhole_init, NULL,
wormhole_done, NULL,
wormhole_age, wormhole_age,
wormhole_write, wormhole_write,
wormhole_read, wormhole_read,
@ -160,12 +144,8 @@ make_wormhole(const building_type * bt_wormhole, region * r1, region * r2)
building *b2 = new_building(bt_wormhole, r2, default_locale); building *b2 = new_building(bt_wormhole, r2, default_locale);
attrib *a1 = a_add(&b1->attribs, a_new(&at_wormhole)); attrib *a1 = a_add(&b1->attribs, a_new(&at_wormhole));
attrib *a2 = a_add(&b2->attribs, a_new(&at_wormhole)); attrib *a2 = a_add(&b2->attribs, a_new(&at_wormhole));
wormhole_data *d1 = (wormhole_data *)a1->data.v; a1->data.v = b2->region;
wormhole_data *d2 = (wormhole_data *)a2->data.v; a2->data.v = b1->region;
d1->entry = b1;
d2->entry = b2;
d1->exit = b2->region;
d2->exit = b1->region;
b1->size = bt_wormhole->maxsize; b1->size = bt_wormhole->maxsize;
b2->size = bt_wormhole->maxsize; b2->size = bt_wormhole->maxsize;
ADDMSG(&r1->msgs, msg_message("wormhole_appear", "region", r1)); ADDMSG(&r1->msgs, msg_message("wormhole_appear", "region", r1));