2010-08-08 10:06:34 +02:00
|
|
|
/*
|
2015-01-30 20:37:14 +01:00
|
|
|
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
2014-10-18 18:37:44 +02:00
|
|
|
Katja Zedel <katze@felidae.kn-bremen.de
|
|
|
|
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include <platform.h>
|
|
|
|
#include <kernel/config.h>
|
|
|
|
#include "removecurse.h"
|
|
|
|
|
|
|
|
/* kernel includes */
|
|
|
|
#include <kernel/curse.h>
|
|
|
|
#include <kernel/unit.h>
|
|
|
|
|
|
|
|
/* util includes */
|
|
|
|
#include <util/attrib.h>
|
2013-12-31 10:06:28 +01:00
|
|
|
#include <util/base36.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <util/event.h>
|
|
|
|
#include <util/log.h>
|
|
|
|
#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>
|
|
|
|
|
|
|
|
typedef struct removecurse_data {
|
2014-10-18 18:37:44 +02:00
|
|
|
curse *curse;
|
|
|
|
unit *target;
|
2010-08-08 10:06:34 +02:00
|
|
|
} removecurse_data;
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static void removecurse_init(trigger * t)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-10-18 18:37:44 +02:00
|
|
|
t->data.v = calloc(sizeof(removecurse_data), 1);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static void removecurse_free(trigger * t)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-10-18 18:37:44 +02:00
|
|
|
free(t->data.v);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int removecurse_handle(trigger * t, void *data)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-10-18 18:37:44 +02:00
|
|
|
/* call an event handler on removecurse.
|
|
|
|
* data.v -> ( variant event, int timer )
|
|
|
|
*/
|
|
|
|
removecurse_data *td = (removecurse_data *)t->data.v;
|
|
|
|
if (td->curse && td->target) {
|
|
|
|
if (!remove_curse(&td->target->attribs, td->curse)) {
|
|
|
|
log_error("could not perform removecurse::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 removecurse_write(const trigger * t, struct storage *store)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-10-18 18:37:44 +02:00
|
|
|
removecurse_data *td = (removecurse_data *)t->data.v;
|
|
|
|
WRITE_TOK(store, td->target ? itoa36(td->target->no) : 0);
|
|
|
|
WRITE_INT(store, td->curse ? td->curse->no : 0);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int removecurse_read(trigger * t, struct storage *store)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-10-18 18:37:44 +02:00
|
|
|
removecurse_data *td = (removecurse_data *)t->data.v;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-10-18 18:37:44 +02:00
|
|
|
read_reference(&td->target, store, read_unit_reference, resolve_unit);
|
|
|
|
read_reference(&td->curse, store, read_int, resolve_curse);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
2014-10-18 18:37:44 +02:00
|
|
|
return AT_READ_OK;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
trigger_type tt_removecurse = {
|
2014-10-18 18:37:44 +02:00
|
|
|
"removecurse",
|
|
|
|
removecurse_init,
|
|
|
|
removecurse_free,
|
|
|
|
removecurse_handle,
|
|
|
|
removecurse_write,
|
|
|
|
removecurse_read
|
2010-08-08 10:06:34 +02:00
|
|
|
};
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
trigger *trigger_removecurse(curse * c, unit * target)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-10-18 18:37:44 +02:00
|
|
|
trigger *t = t_new(&tt_removecurse);
|
|
|
|
removecurse_data *td = (removecurse_data *)t->data.v;
|
|
|
|
td->curse = c;
|
|
|
|
td->target = target;
|
|
|
|
return t;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|