server/src/triggers/changefaction.c

94 lines
2.1 KiB
C
Raw Normal View History

2010-08-08 10:06:34 +02:00
#include <platform.h>
#include "changefaction.h"
/* kernel includes */
#include <kernel/unit.h>
#include <kernel/faction.h>
2010-08-08 10:06:34 +02:00
/* util includes */
#include <kernel/attrib.h>
#include <util/base36.h>
#include <kernel/event.h>
2018-09-29 13:21:46 +02:00
#include <kernel/gamedata.h>
2010-08-08 10:06:34 +02:00
#include <util/log.h>
#include <util/macros.h>
2010-08-08 10:06:34 +02:00
#include <util/resolve.h>
#include <storage.h>
2010-08-08 10:06:34 +02: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 changefaction_data {
struct unit *unit;
struct faction *faction;
2010-08-08 10:06:34 +02:00
} changefaction_data;
2011-03-07 08:02:35 +01:00
static void changefaction_init(trigger * t)
2010-08-08 10:06:34 +02:00
{
t->data.v = calloc(1, sizeof(changefaction_data));
2010-08-08 10:06:34 +02:00
}
2011-03-07 08:02:35 +01:00
static void changefaction_free(trigger * t)
2010-08-08 10:06:34 +02:00
{
free(t->data.v);
2010-08-08 10:06:34 +02:00
}
2011-03-07 08:02:35 +01:00
static int changefaction_handle(trigger * t, void *data)
2010-08-08 10:06:34 +02:00
{
/* call an event handler on changefaction.
* data.v -> ( variant event, int timer )
*/
changefaction_data *td = (changefaction_data *)t->data.v;
if (td->unit && td->faction) {
unit * u = td->unit;
u_setfaction(u, td->faction);
u_freeorders(u);
}
else {
log_error("could not perform changefaction::handle()\n");
}
UNUSED_ARG(data);
return 0;
2010-08-08 10:06:34 +02:00
}
2011-03-07 08:02:35 +01:00
static void changefaction_write(const trigger * t, struct storage *store)
2010-08-08 10:06:34 +02:00
{
changefaction_data *td = (changefaction_data *)t->data.v;
write_unit_reference(td->unit, store);
write_faction_reference(td->faction->_alive ? td->faction : NULL, store);
2010-08-08 10:06:34 +02:00
}
static int changefaction_read(trigger * t, gamedata *data)
2010-08-08 10:06:34 +02:00
{
changefaction_data *td = (changefaction_data *)t->data.v;
2017-09-21 16:26:53 +02:00
read_unit_reference(data, &td->unit, NULL);
return read_faction_reference(data, &td->faction) > 0 ? AT_READ_OK : AT_READ_FAIL;
2010-08-08 10:06:34 +02:00
}
trigger_type tt_changefaction = {
"changefaction",
changefaction_init,
changefaction_free,
changefaction_handle,
changefaction_write,
changefaction_read
2010-08-08 10:06:34 +02:00
};
2011-03-07 08:02:35 +01:00
trigger *trigger_changefaction(unit * u, struct faction * f)
2010-08-08 10:06:34 +02:00
{
trigger *t = t_new(&tt_changefaction);
changefaction_data *td = (changefaction_data *)t->data.v;
td->unit = u;
td->faction = f;
return t;
2010-08-08 10:06:34 +02:00
}