diff --git a/src/bind_storage.c b/src/bind_storage.c index fcf6c0ac9..0255b2982 100644 --- a/src/bind_storage.c +++ b/src/bind_storage.c @@ -101,7 +101,7 @@ static int tolua_storage_tostring(lua_State * L) { gamedata *data = (gamedata *)tolua_tousertype(L, 1, 0); char name[64]; - _snprintf(name, sizeof(name), "", data, data->version); + _snprintf(name, sizeof(name), "", (void *)data, data->version); lua_pushstring(L, name); return 1; } diff --git a/src/modules/arena.c b/src/modules/arena.c index cc4c6b4be..f7ec90f07 100644 --- a/src/modules/arena.c +++ b/src/modules/arena.c @@ -449,10 +449,10 @@ static void caldera_write(const trigger * t, struct storage *store) write_building_reference(b, store); } -static int caldera_read(trigger * t, struct storage *store) +static int caldera_read(trigger * t, struct gamedata *data) { int rb = - read_reference(&t->data.v, store, read_building_reference, + read_reference(&t->data.v, data->store, read_building_reference, resolve_building); if (rb == 0 && !t->data.v) { return AT_READ_FAIL; diff --git a/src/modules/xmas.c b/src/modules/xmas.c index 1aa8aaba7..657d97f8a 100644 --- a/src/modules/xmas.c +++ b/src/modules/xmas.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -47,10 +48,10 @@ static void xmasgate_write(const trigger * t, struct storage *store) WRITE_TOK(store, itoa36(b->no)); } -static int xmasgate_read(trigger * t, struct storage *store) +static int xmasgate_read(trigger * t, struct gamedata *data) { int bc = - read_reference(&t->data.v, store, read_building_reference, + read_reference(&t->data.v, data->store, read_building_reference, resolve_building); if (bc == 0 && !t->data.v) { return AT_READ_FAIL; diff --git a/src/triggers/changefaction.c b/src/triggers/changefaction.c index 47eee5874..dd0440435 100644 --- a/src/triggers/changefaction.c +++ b/src/triggers/changefaction.c @@ -28,6 +28,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* util includes */ #include #include +#include #include #include #include @@ -82,12 +83,13 @@ static void changefaction_write(const trigger * t, struct storage *store) write_faction_reference(td->faction->_alive ? td->faction : NULL, store); } -static int changefaction_read(trigger * t, struct storage *store) +static int changefaction_read(trigger * t, gamedata *data) { variant var; changefaction_data *td = (changefaction_data *)t->data.v; - read_reference(&td->unit, store, read_unit_reference, resolve_unit); - var = read_faction_reference(store); + + read_reference(&td->unit, data->store, read_unit_reference, resolve_unit); + var = read_faction_reference(data->store); if (var.i == 0) { return AT_READ_FAIL; } diff --git a/src/triggers/changerace.c b/src/triggers/changerace.c index d4937cc9f..9ed3bbf39 100644 --- a/src/triggers/changerace.c +++ b/src/triggers/changerace.c @@ -27,6 +27,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* util includes */ #include #include +#include #include #include #include @@ -86,12 +87,12 @@ static void changerace_write(const trigger * t, struct storage *store) write_race_reference(td->irace, store); } -static int changerace_read(trigger * t, struct storage *store) +static int changerace_read(trigger * t, gamedata *data) { changerace_data *td = (changerace_data *)t->data.v; - read_reference(&td->u, store, read_unit_reference, resolve_unit); - td->race = (const struct race *)read_race_reference(store).v; - td->irace = (const struct race *)read_race_reference(store).v; + read_reference(&td->u, data->store, read_unit_reference, resolve_unit); + td->race = (const struct race *)read_race_reference(data->store).v; + td->irace = (const struct race *)read_race_reference(data->store).v; return AT_READ_OK; } diff --git a/src/triggers/clonedied.c b/src/triggers/clonedied.c index 7a91ea514..96b6d76f4 100644 --- a/src/triggers/clonedied.c +++ b/src/triggers/clonedied.c @@ -29,6 +29,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* util includes */ #include #include +#include #include #include #include @@ -68,10 +69,10 @@ static void clonedied_write(const trigger * t, struct storage *store) write_unit_reference(u, store); } -static int clonedied_read(trigger * t, struct storage *store) +static int clonedied_read(trigger * t, gamedata *data) { int result = - read_reference(&t->data.v, store, read_unit_reference, resolve_unit); + read_reference(&t->data.v, data->store, read_unit_reference, resolve_unit); if (result == 0 && t->data.v == NULL) { return AT_READ_FAIL; } diff --git a/src/triggers/createcurse.c b/src/triggers/createcurse.c index 07e8a370e..53be8b6a9 100644 --- a/src/triggers/createcurse.c +++ b/src/triggers/createcurse.c @@ -28,6 +28,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* util includes */ #include #include +#include #include #include #include @@ -93,30 +94,30 @@ static void createcurse_write(const trigger * t, struct storage *store) WRITE_INT(store, td->men); } -static int createcurse_read(trigger * t, struct storage *store) +static int createcurse_read(trigger * t, gamedata *data) { createcurse_data *td = (createcurse_data *)t->data.v; char zText[128]; float flt; - read_reference(&td->mage, store, read_unit_reference, resolve_unit); - read_reference(&td->target, store, read_unit_reference, resolve_unit); + read_reference(&td->mage, data->store, read_unit_reference, resolve_unit); + read_reference(&td->target, data->store, read_unit_reference, resolve_unit); - READ_TOK(store, zText, sizeof(zText)); + READ_TOK(data->store, zText, sizeof(zText)); td->type = ct_find(zText); - READ_FLT(store, &flt); + READ_FLT(data->store, &flt); td->vigour = flt; - READ_INT(store, &td->duration); - if (global.data_version < CURSEFLOAT_VERSION) { + READ_INT(data->store, &td->duration); + if (data->version < CURSEFLOAT_VERSION) { int n; - READ_INT(store, &n); + READ_INT(data->store, &n); td->effect = (float)n; } else { - READ_FLT(store, &flt); + READ_FLT(data->store, &flt); td->effect = flt; } - READ_INT(store, &td->men); + READ_INT(data->store, &td->men); return AT_READ_OK; } diff --git a/src/triggers/createunit.c b/src/triggers/createunit.c index bd8595378..6628777f4 100644 --- a/src/triggers/createunit.c +++ b/src/triggers/createunit.c @@ -31,6 +31,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include @@ -88,12 +89,12 @@ static void createunit_write(const trigger * t, struct storage *store) WRITE_INT(store, td->number); } -static int createunit_read(trigger * t, struct storage *store) +static int createunit_read(trigger * t, gamedata *data) { createunit_data *td = (createunit_data *)t->data.v; variant var; int result = AT_READ_OK; - var = read_faction_reference(store); + var = read_faction_reference(data->store); if (var.i > 0) { td->f = findfaction(var.i); if (!td->f) { @@ -105,13 +106,13 @@ static int createunit_read(trigger * t, struct storage *store) } // read_reference(&td->f, store, read_faction_reference, resolve_faction); - read_reference(&td->r, store, read_region_reference, + read_reference(&td->r, data->store, read_region_reference, RESOLVE_REGION(global.data_version)); - td->race = (const struct race *)read_race_reference(store).v; + td->race = (const struct race *)read_race_reference(data->store).v; if (!td->race) { result = AT_READ_FAIL; } - READ_INT(store, &td->number); + READ_INT(data->store, &td->number); return result; } diff --git a/src/triggers/gate.c b/src/triggers/gate.c index 44d26e0ef..3f5552fa2 100644 --- a/src/triggers/gate.c +++ b/src/triggers/gate.c @@ -22,6 +22,7 @@ /* util includes */ #include #include +#include #include #include @@ -72,14 +73,14 @@ static void gate_write(const trigger * t, struct storage *store) write_region_reference(r, store); } -static int gate_read(trigger * t, struct storage *store) +static int gate_read(trigger * t, gamedata *data) { gate_data *gd = (gate_data *)t->data.v; int bc = - read_reference(&gd->gate, store, read_building_reference, resolve_building); + read_reference(&gd->gate, data->store, read_building_reference, resolve_building); int rc = - read_reference(&gd->target, store, read_region_reference, + read_reference(&gd->target, data->store, read_region_reference, RESOLVE_REGION(global.data_version)); if (bc == 0 && rc == 0) { diff --git a/src/triggers/giveitem.c b/src/triggers/giveitem.c index 02161775b..7cb11869f 100644 --- a/src/triggers/giveitem.c +++ b/src/triggers/giveitem.c @@ -28,6 +28,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include @@ -82,15 +83,15 @@ static void giveitem_write(const trigger * t, struct storage *store) WRITE_TOK(store, td->itype->rtype->_name); } -static int giveitem_read(trigger * t, struct storage *store) +static int giveitem_read(trigger * t, gamedata *data) { giveitem_data *td = (giveitem_data *)t->data.v; char zText[128]; - int result = read_reference(&td->u, store, read_unit_reference, resolve_unit); + int result = read_reference(&td->u, data->store, read_unit_reference, resolve_unit); - READ_INT(store, &td->number); - READ_TOK(store, zText, sizeof(zText)); + READ_INT(data->store, &td->number); + READ_TOK(data->store, zText, sizeof(zText)); td->itype = it_find(zText); assert(td->itype); diff --git a/src/triggers/killunit.c b/src/triggers/killunit.c index 866914835..25a990dbe 100644 --- a/src/triggers/killunit.c +++ b/src/triggers/killunit.c @@ -27,6 +27,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include @@ -58,10 +59,10 @@ static void killunit_write(const trigger * t, struct storage *store) write_unit_reference(u, store); } -static int killunit_read(trigger * t, struct storage *store) +static int killunit_read(trigger * t, gamedata *data) { int result = - read_reference(&t->data.v, store, read_unit_reference, resolve_unit); + read_reference(&t->data.v, data->store, read_unit_reference, resolve_unit); if (result == 0 && t->data.v == NULL) { return AT_READ_FAIL; } diff --git a/src/triggers/removecurse.c b/src/triggers/removecurse.c index 94819843a..97655ed5e 100644 --- a/src/triggers/removecurse.c +++ b/src/triggers/removecurse.c @@ -28,6 +28,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include @@ -77,12 +78,12 @@ static void removecurse_write(const trigger * t, struct storage *store) WRITE_INT(store, td->curse ? td->curse->no : 0); } -static int removecurse_read(trigger * t, struct storage *store) +static int removecurse_read(trigger * t, gamedata *data) { removecurse_data *td = (removecurse_data *)t->data.v; - read_reference(&td->target, store, read_unit_reference, resolve_unit); - read_reference(&td->curse, store, read_int, resolve_curse); + read_reference(&td->target, data->store, read_unit_reference, resolve_unit); + read_reference(&td->curse, data->store, read_int, resolve_curse); return AT_READ_OK; } diff --git a/src/triggers/shock.c b/src/triggers/shock.c index 95e7b61b6..1cfabc6c1 100644 --- a/src/triggers/shock.c +++ b/src/triggers/shock.c @@ -33,6 +33,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include #include @@ -125,10 +126,10 @@ static void shock_write(const trigger * t, struct storage *store) } } -static int shock_read(trigger * t, struct storage *store) +static int shock_read(trigger * t, gamedata *data) { int result = - read_reference(&t->data.v, store, read_unit_reference, resolve_unit); + read_reference(&t->data.v, data->store, read_unit_reference, resolve_unit); if (result == 0 && t->data.v == NULL) { return AT_READ_FAIL; } diff --git a/src/triggers/timeout.c b/src/triggers/timeout.c index 8f1778f21..06fa18363 100644 --- a/src/triggers/timeout.c +++ b/src/triggers/timeout.c @@ -23,6 +23,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* util includes */ #include #include +#include #include #include @@ -72,11 +73,11 @@ static void timeout_write(const trigger * t, struct storage *store) write_triggers(store, td->triggers); } -static int timeout_read(trigger * t, struct storage *store) +static int timeout_read(trigger * t, gamedata *data) { timeout_data *td = (timeout_data *)t->data.v; - READ_INT(store, &td->timer); - read_triggers(store, &td->triggers); + READ_INT(data->store, &td->timer); + read_triggers(data, &td->triggers); if (td->timer > 20) { trigger *tr = td->triggers; log_warning("there is a timeout lasting for another %d turns\n", td->timer); diff --git a/src/triggers/unguard.c b/src/triggers/unguard.c index 49cb6fe25..7ee306e4c 100644 --- a/src/triggers/unguard.c +++ b/src/triggers/unguard.c @@ -22,6 +22,7 @@ /* util includes */ #include #include +#include #include #include @@ -48,10 +49,10 @@ static void unguard_write(const trigger * t, struct storage *store) write_building_reference((building *)t->data.v, store); } -static int unguard_read(trigger * t, struct storage *store) +static int unguard_read(trigger * t, gamedata *data) { int rb = - read_reference(&t->data.v, store, read_building_reference, + read_reference(&t->data.v, data->store, read_building_reference, resolve_building); if (rb == 0 && !t->data.v) { return AT_READ_FAIL; diff --git a/src/triggers/unitmessage.c b/src/triggers/unitmessage.c index df227ed24..849cfd357 100644 --- a/src/triggers/unitmessage.c +++ b/src/triggers/unitmessage.c @@ -20,6 +20,7 @@ without prior permission by the authors of Eressea. #include #include #include +#include #include #include #include @@ -84,17 +85,17 @@ static void unitmessage_write(const trigger * t, struct storage *store) WRITE_INT(store, td->level); } -static int unitmessage_read(trigger * t, struct storage *store) +static int unitmessage_read(trigger * t, gamedata *data) { unitmessage_data *td = (unitmessage_data *)t->data.v; char zText[256]; int result = - read_reference(&td->target, store, read_unit_reference, resolve_unit); - READ_TOK(store, zText, sizeof(zText)); + read_reference(&td->target, data->store, read_unit_reference, resolve_unit); + READ_TOK(data->store, zText, sizeof(zText)); td->string = _strdup(zText); - READ_INT(store, &td->type); - READ_INT(store, &td->level); + READ_INT(data->store, &td->type); + READ_INT(data->store, &td->level); if (result == 0 && td->target == NULL) { return AT_READ_FAIL; diff --git a/src/util/event.c b/src/util/event.c index 72a2086af..b367081b3 100644 --- a/src/util/event.c +++ b/src/util/event.c @@ -43,20 +43,20 @@ void write_triggers(struct storage *store, const trigger * t) WRITE_TOK(store, "end"); } -int read_triggers(struct storage *store, trigger ** tp) +int read_triggers(struct gamedata *data, trigger ** tp) { for (;;) { trigger_type *ttype; char zText[128]; - READ_TOK(store, zText, sizeof(zText)); + READ_TOK(data->store, zText, sizeof(zText)); if (!strcmp(zText, "end")) break; ttype = tt_find(zText); assert(ttype || !"unknown trigger-type"); *tp = t_new(ttype); if (ttype->read) { - int i = ttype->read(*tp, store); + int i = ttype->read(*tp, data); switch (i) { case AT_READ_OK: tp = &(*tp)->next; @@ -152,7 +152,7 @@ static int read_handler(attrib * a, void *owner, gamedata *data) READ_TOK(store, zText, sizeof(zText)); hi->event = _strdup(zText); - read_triggers(store, &hi->triggers); + read_triggers(data, &hi->triggers); if (hi->triggers != NULL) { return AT_READ_OK; } diff --git a/src/util/event.h b/src/util/event.h index 2fb5f4806..ad4ca373d 100644 --- a/src/util/event.h +++ b/src/util/event.h @@ -27,6 +27,7 @@ extern "C" { struct attrib; struct trigger; struct storage; + struct gamedata; typedef struct trigger_type { const char *name; @@ -34,7 +35,7 @@ extern "C" { void(*finalize) (struct trigger *); int(*handle) (struct trigger *, void *); void(*write) (const struct trigger *, struct storage * store); - int(*read) (struct trigger *, struct storage * store); + int(*read) (struct trigger *, struct gamedata * store); struct trigger_type *next; } trigger_type; @@ -73,7 +74,7 @@ extern "C" { /* functions for making complex triggers: */ void free_triggers(trigger * triggers); /* release all these triggers */ void write_triggers(struct storage *store, const trigger * t); - int read_triggers(struct storage *store, trigger ** tp); + int read_triggers(struct gamedata *data, trigger ** tp); int handle_triggers(trigger ** triggers, void *data); extern struct attrib_type at_eventhandler;