server/src/common/modules/xmas.c

163 lines
4.1 KiB
C
Raw Normal View History

2001-12-30 09:29:04 +01:00
/* vi: set ts=2:
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
| | Enno Rehling <enno@eressea-pbem.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
| (c) 1998 - 2003 | Henning Peters <faroul@beyond.kn-bremen.de>
2001-12-30 09:29:04 +01:00
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
+-------------------+ Stefan Reich <reich@halbling.de>
This program may not be used, modified or distributed
without prior permission by the authors of Eressea.
*/
#include <config.h>
#include <eressea.h>
#include "xmas.h"
/* kernel includes */
#include <unit.h>
2003-08-03 19:56:17 +02:00
#include <building.h>
2001-12-30 09:29:04 +01:00
#include <region.h>
2003-08-03 19:56:17 +02:00
#include <event.h>
2001-12-30 09:29:04 +01:00
#include <movement.h>
#include <faction.h>
2001-12-30 11:07:11 +01:00
#include <item.h>
2001-12-30 09:29:04 +01:00
#include <race.h>
/* util includes */
#include <base36.h>
2003-08-03 19:56:17 +02:00
#include <goodies.h>
2001-12-30 09:29:04 +01:00
2003-08-03 19:56:17 +02:00
/* libc includes */
#include <stdlib.h>
2001-12-30 09:29:04 +01:00
void
santa_comes_to_town(region * r, unit * santa, void (*action)(unit*))
{
faction * f;
2001-12-30 11:07:11 +01:00
const item_type * roi = it_find("roi");
assert(roi);
2001-12-30 09:29:04 +01:00
for (f = factions;f;f=f->next) {
unit * u;
unit * senior = f->units;
if (!playerrace(f->race)) continue;
for (u = f->units; u; u=u->nextF) {
2001-12-30 11:07:11 +01:00
if (senior->age < u->age || effstealth(senior) > effstealth(u) || i_get(senior->items, roi)) senior = u;
2001-12-30 09:29:04 +01:00
}
if (!senior) continue;
sprintf(buf, "von %s: 'Ho ho ho. Frohe Weihnachten, und alles Gute f<>r dein Volk, %s.'", unitname(santa), unitname(senior));
addmessage(senior->region, 0, buf, MSG_MESSAGE, ML_IMPORTANT);
travelthru(santa, senior->region);
if (action) action(senior);
}
}
unit *
make_santa(region * r)
{
unit * santa = ufindhash(atoi36("xmas"));
while (santa && santa->race!=new_race[RC_ILLUSION]) {
uunhash(santa);
santa->no = newunitid();
uhash(santa);
santa = ufindhash(atoi36("xmas"));
}
if (!santa) {
faction * f = findfaction(atoi36("rr"));
2001-12-30 10:30:48 +01:00
if (f==NULL) f = findfaction(MONSTER_FACTION);
2001-12-30 09:29:04 +01:00
if (f==NULL) return NULL;
f->alive = true;
santa = createunit(r, f, 1, new_race[RC_ILLUSION]);
uunhash(santa);
santa->no = atoi36("xmas");
uhash(santa);
fset(santa, UFL_PARTEITARNUNG);
2001-12-30 09:29:04 +01:00
santa->irace = new_race[RC_GNOME];
set_string(&santa->name, "Ein dicker Gnom mit einem Rentierschlitten");
set_string(&santa->display, "hat: 12 Rentiere, Schlitten, Sack mit Geschenken, Kekse f<>r Khorne");
}
return santa;
}
2003-08-03 19:56:17 +02:00
static int
xmasgate_handle(trigger * t, void * data)
{
/* call an event handler on xmasgate.
* data.v -> ( variant event, int timer )
*/
unit * santa = ufindhash(atoi36("xmas"));
building *b = (building *)t->data.v;
if (santa && b) {
unit ** up = &b->region->units;
if (santa->region!=b->region) santa = NULL;
while (*up) {
unit * u = *up;
if (u->building==b) {
region * r = u->region;
faction * f = u->faction;
unit * home = f->units;
unit * u2 = r->units;
while (u2) {
if (u2->faction==f && u2!=u && u2->number) break;
u2 = u2->next;
}
while (home && (home->region==b->region || home->region->land==NULL)) home = home->nextF;
if (home==NULL) continue;
if (santa!=NULL && u2==NULL) {
char zText[256];
item_type * itype = olditemtype[(rand() % 4) + I_KEKS];
i_change(&u->items, itype, 1);
sprintf(zText, "%s gibt %d %s an %s.", unitname(santa), 1, locale_string(f->locale, resourcename(itype->rtype, GR_PLURAL)), unitname(u));
i_change(&u->items, itype, 1);
addmessage(home->region, u->faction, zText, MSG_COMMERCE, ML_INFO);
}
move_unit(u, home->region, NULL);
}
if (*up==u) up = &u->next;
}
} else
log_error(("could not perform xmasgate::handle()\n"));
unused(data);
return 0;
}
static void
xmasgate_write(const trigger * t, FILE * F)
{
building *b = (building *)t->data.v;
fprintf(F, "%s ", itoa36(b->no));
}
static int
xmasgate_read(trigger * t, FILE * F)
{
return read_building_reference((building**)&t->data.v, F);
}
struct trigger_type tt_xmasgate = {
"xmasgate",
NULL,
NULL,
xmasgate_handle,
xmasgate_write,
xmasgate_read
};
trigger *
trigger_xmasgate(building * b)
{
trigger * t = t_new(&tt_xmasgate);
t->data.v = b;
return t;
}
void
init_xmas(void)
{
tt_register(&tt_xmasgate);
}