2010-08-08 10:06:34 +02:00
|
|
|
|
/*
|
|
|
|
|
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
|
|
|
|
Katja Zedel <katze@felidae.kn-bremen.de
|
|
|
|
|
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
|
|
|
|
|
|
|
|
|
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 "shock.h"
|
|
|
|
|
|
2014-11-01 12:57:01 +01:00
|
|
|
|
#include "magic.h"
|
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* kernel includes */
|
|
|
|
|
#include <kernel/curse.h>
|
|
|
|
|
#include <kernel/faction.h>
|
2014-06-09 18:54:48 +02:00
|
|
|
|
#include <kernel/messages.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include <kernel/spell.h>
|
|
|
|
|
#include <kernel/unit.h>
|
|
|
|
|
|
|
|
|
|
/* util includes */
|
|
|
|
|
#include <util/attrib.h>
|
|
|
|
|
#include <util/base36.h>
|
|
|
|
|
#include <util/event.h>
|
|
|
|
|
#include <util/log.h>
|
|
|
|
|
#include <util/resolve.h>
|
|
|
|
|
#include <util/rng.h>
|
2013-12-31 10:06:28 +01:00
|
|
|
|
|
|
|
|
|
#include <storage.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
/* libc includes */
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
/***
|
|
|
|
|
** shock
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
/* do_shock - Schockt die Einheit, z.B. bei Verlust eines */
|
|
|
|
|
/* Vertrauten. */
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void do_shock(unit * u, const char *reason)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if (u->number > 0) {
|
|
|
|
|
/* HP - Verlust */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
u->hp = (unit_max_hp(u) * u->number) / 10;
|
2014-03-16 05:03:17 +01:00
|
|
|
|
u->hp = _max(1, u->hp);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Aura - Verlust */
|
|
|
|
|
if (is_mage(u)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
set_spellpoints(u, max_spellpoints(u->region, u) / 10);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Evt. Talenttageverlust */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
for (i = 0; i != u->skill_size; ++i)
|
|
|
|
|
if (rng_int() % 5 == 0) {
|
|
|
|
|
skill *sv = u->skills + i;
|
|
|
|
|
int weeks = (sv->level * sv->level - sv->level) / 2;
|
|
|
|
|
int change = (weeks + 9) / 10;
|
|
|
|
|
reduce_skill(u, sv, change);
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
/* Dies ist ein Hack, um das skillmod und familiar-Attribut beim Mage
|
2011-03-07 08:02:35 +01:00
|
|
|
|
* zu l<EFBFBD>schen wenn der Familiar get<EFBFBD>tet wird. Da sollten wir <EFBFBD>ber eine
|
|
|
|
|
* saubere Implementation nachdenken. */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (strcmp(reason, "trigger") == 0) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
remove_familiar(u);
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (u->faction != NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("shock",
|
2013-12-29 14:38:58 +01:00
|
|
|
|
"mage reason", u, _strdup(reason)));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static int shock_handle(trigger * t, void *data)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
|
|
|
|
/* destroy the unit */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
unit *u = (unit *) t->data.v;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
if (u && u->number) {
|
|
|
|
|
do_shock(u, "trigger");
|
|
|
|
|
}
|
2014-04-12 04:20:20 +02:00
|
|
|
|
unused_arg(data);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static void shock_write(const trigger * t, struct storage *store)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
unit *u = (unit *) t->data.v;
|
|
|
|
|
trigger *next = t->next;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
while (next) {
|
|
|
|
|
/* make sure it is unique! */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
if (next->type == t->type && next->data.v == t->data.v)
|
|
|
|
|
break;
|
|
|
|
|
next = next->next;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
if (next && u) {
|
2012-05-17 01:52:01 +02:00
|
|
|
|
log_error("more than one shock-attribut for %s on a unit. FIXED.\n", unitid(u));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
write_unit_reference(NULL, store);
|
|
|
|
|
} else {
|
|
|
|
|
write_unit_reference(u, store);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static int shock_read(trigger * t, struct storage *store)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int result =
|
|
|
|
|
read_reference(&t->data.v, store, read_unit_reference, resolve_unit);
|
|
|
|
|
if (result == 0 && t->data.v == NULL) {
|
2010-08-08 10:06:34 +02:00
|
|
|
|
return AT_READ_FAIL;
|
|
|
|
|
}
|
|
|
|
|
return AT_READ_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
trigger_type tt_shock = {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
"shock",
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
shock_handle,
|
|
|
|
|
shock_write,
|
|
|
|
|
shock_read
|
2010-08-08 10:06:34 +02:00
|
|
|
|
};
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
trigger *trigger_shock(unit * u)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
|
trigger *t = t_new(&tt_shock);
|
|
|
|
|
t->data.v = (void *)u;
|
|
|
|
|
return t;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|