2010-08-08 10:06:34 +02:00
|
|
|
#include <platform.h>
|
|
|
|
#include "changefaction.h"
|
|
|
|
|
|
|
|
/* kernel includes */
|
|
|
|
#include <kernel/unit.h>
|
2014-12-10 09:39:11 +01:00
|
|
|
#include <kernel/faction.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
/* util includes */
|
2018-09-29 11:37:17 +02:00
|
|
|
#include <kernel/attrib.h>
|
2017-12-29 06:13:28 +01:00
|
|
|
#include <util/base36.h>
|
2018-09-29 11:37:17 +02:00
|
|
|
#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>
|
2017-12-29 06:13:28 +01:00
|
|
|
#include <util/macros.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <util/resolve.h>
|
2013-12-31 10:06:28 +01:00
|
|
|
|
|
|
|
#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 {
|
2015-01-30 20:37:14 +01:00
|
|
|
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
|
|
|
{
|
2018-12-15 19:38:40 +01: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
|
|
|
{
|
2015-01-30 20:37:14 +01: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
|
|
|
{
|
2015-01-30 20:37:14 +01: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) {
|
2019-11-24 16:39:21 +01:00
|
|
|
unit * u = td->unit;
|
|
|
|
u_setfaction(u, td->faction);
|
|
|
|
u_freeorders(u);
|
2015-01-30 20:37:14 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
log_error("could not perform changefaction::handle()\n");
|
|
|
|
}
|
2017-01-10 16:31:05 +01:00
|
|
|
UNUSED_ARG(data);
|
2015-01-30 20:37:14 +01:00
|
|
|
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
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
changefaction_data *td = (changefaction_data *)t->data.v;
|
|
|
|
write_unit_reference(td->unit, store);
|
2016-02-16 07:30:26 +01:00
|
|
|
write_faction_reference(td->faction->_alive ? td->faction : NULL, store);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2016-02-13 15:25:07 +01:00
|
|
|
static int changefaction_read(trigger * t, gamedata *data)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
changefaction_data *td = (changefaction_data *)t->data.v;
|
2016-02-13 15:25:07 +01:00
|
|
|
|
2017-09-21 16:26:53 +02:00
|
|
|
read_unit_reference(data, &td->unit, NULL);
|
2018-11-01 09:53:23 +01:00
|
|
|
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 = {
|
2015-01-30 20:37:14 +01:00
|
|
|
"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
|
|
|
{
|
2015-01-30 20:37:14 +01: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
|
|
|
}
|