server/src/common/triggers/changerace.c

117 lines
2.6 KiB
C
Raw Normal View History

2001-01-25 10:37:55 +01:00
/* vi: set ts=2:
*
*
* Eressea PB(E)M host Copyright (C) 1998-2003
2001-01-25 10:37:55 +01:00
* Christian Schlittchen (corwin@amber.kn-bremen.de)
* Katja Zedel (katze@felidae.kn-bremen.de)
* Henning Peters (faroul@beyond.kn-bremen.de)
* Enno Rehling (enno@eressea.de)
2001-01-25 10:37:55 +01:00
* Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
*
* This program may not be used, modified or distributed without
* prior permission by the authors of Eressea.
*/
#include <config.h>
#include <kernel/eressea.h>
2001-01-25 10:37:55 +01:00
#include "changerace.h"
/* kernel includes */
#include <kernel/unit.h>
#include <kernel/race.h>
2001-01-25 10:37:55 +01:00
/* util includes */
2007-06-20 02:34:02 +02:00
#include <util/attrib.h>
#include <util/event.h>
2007-08-05 14:19:56 +02:00
#include <util/log.h>
2007-06-20 02:34:02 +02:00
#include <util/resolve.h>
#include <util/storage.h>
2007-06-20 02:34:02 +02:00
#include <util/base36.h>
2001-01-25 10:37:55 +01:00
/* ansi includes */
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
/***
** restore a mage that was turned into a toad
**/
typedef struct changerace_data {
struct unit * u;
const struct race * race;
const struct race * irace;
2001-01-25 10:37:55 +01:00
} changerace_data;
static void
changerace_init(trigger * t)
{
t->data.v = calloc(sizeof(changerace_data), 1);
}
static void
changerace_free(trigger * t)
{
free(t->data.v);
}
static int
changerace_handle(trigger * t, void * data)
{
/* call an event handler on changerace.
* data.v -> ( variant event, int timer )
*/
changerace_data * td = (changerace_data*)t->data.v;
if (td->u) {
if (td->race!=NULL) td->u->race = td->race;
if (td->irace!=NULL) td->u->irace = td->irace;
2001-01-25 10:37:55 +01:00
} else {
log_error(("could not perform changerace::handle()\n"));
2001-01-25 10:37:55 +01:00
}
unused(data);
return 0;
}
static void
changerace_write(const trigger * t, struct storage * store)
2001-01-25 10:37:55 +01:00
{
changerace_data * td = (changerace_data*)t->data.v;
write_unit_reference(td->u, store);
write_race_reference(td->race, store);
write_race_reference(td->irace, store);
2001-01-25 10:37:55 +01:00
}
static int
changerace_read(trigger * t, struct storage * store)
2001-01-25 10:37:55 +01:00
{
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;
return AT_READ_OK;
2001-01-25 10:37:55 +01:00
}
trigger_type tt_changerace = {
"changerace",
changerace_init,
changerace_free,
changerace_handle,
changerace_write,
changerace_read
};
trigger *
trigger_changerace(struct unit * u, const struct race * prace, const struct race * irace)
2001-01-25 10:37:55 +01:00
{
trigger * t = t_new(&tt_changerace);
changerace_data * td = (changerace_data*)t->data.v;
assert(u->race==u->irace || "!changerace-triggers cannot stack!");
2001-01-25 10:37:55 +01:00
td->u = u;
td->race = prace;
2001-01-25 10:37:55 +01:00
td->irace = irace;
return t;
}