From 1145f3797594b59af522b21cc87079ae7746eb0e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 3 Aug 2003 17:56:17 +0000 Subject: [PATCH] fix fuer das weihnachtsdesaster --- src/common/modules/xmas.c | 84 +++++++++++++++++++++++++++++++++++ src/common/modules/xmas.h | 3 ++ src/common/modules/xmas2000.c | 84 ++--------------------------------- src/common/modules/xmas2000.h | 1 - src/eressea/main.c | 4 +- src/mapper/mapper.c | 4 +- 6 files changed, 94 insertions(+), 86 deletions(-) diff --git a/src/common/modules/xmas.c b/src/common/modules/xmas.c index e67af2256..18a91c8ea 100644 --- a/src/common/modules/xmas.c +++ b/src/common/modules/xmas.c @@ -16,7 +16,9 @@ /* kernel includes */ #include +#include #include +#include #include #include #include @@ -24,7 +26,10 @@ /* util includes */ #include +#include +/* libc includes */ +#include void santa_comes_to_town(region * r, unit * santa, void (*action)(unit*)) { @@ -76,3 +81,82 @@ make_santa(region * r) } return santa; } + +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); +} + diff --git a/src/common/modules/xmas.h b/src/common/modules/xmas.h index 69f12cf52..208a22286 100644 --- a/src/common/modules/xmas.h +++ b/src/common/modules/xmas.h @@ -21,6 +21,9 @@ struct unit; extern void santa_comes_to_town(struct region * r, struct unit * santa, void (*action)(struct unit*)); extern struct unit * make_santa(struct region * r); +extern struct trigger *trigger_xmasgate(struct building * b); + +extern void init_xmas(void); #ifdef __cplusplus } diff --git a/src/common/modules/xmas2000.c b/src/common/modules/xmas2000.c index 689bd71ee..9d88fe0fa 100644 --- a/src/common/modules/xmas2000.c +++ b/src/common/modules/xmas2000.c @@ -16,6 +16,9 @@ #include #include "xmas2000.h" +/* modules includes */ +#include "xmas.h" + /* kernel includes */ #include #include @@ -27,9 +30,6 @@ #include #include -/* gamecode includes */ -#include "xmas.h" - /* util includes */ #include #include @@ -37,78 +37,6 @@ #include -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 -}; - -static trigger * -trigger_xmasgate(building * b) -{ - trigger * t = t_new(&tt_xmasgate); - t->data.v = b; - return t; -} - static void make_gates(region * r) { @@ -129,12 +57,6 @@ make_gates(region * r) add_trigger(&b->attribs, "timer", trigger_xmasgate(b)); } -void -init_xmas2000(void) -{ - tt_register(&tt_xmasgate); -} - void create_xmas2000(int x, int y) { diff --git a/src/common/modules/xmas2000.h b/src/common/modules/xmas2000.h index cad8d7675..3845a76f2 100644 --- a/src/common/modules/xmas2000.h +++ b/src/common/modules/xmas2000.h @@ -15,7 +15,6 @@ #ifndef XMAS2000_H #define XMAS2000_H -extern void init_xmas2000(void); extern void create_xmas2000(int x, int y); #endif diff --git a/src/eressea/main.c b/src/eressea/main.c index f5e9905cd..11db09fac 100644 --- a/src/eressea/main.c +++ b/src/eressea/main.c @@ -38,7 +38,7 @@ /* modules includes */ #include #include -#include +#include #include #include #ifdef MUSEUM_MODULE @@ -149,7 +149,7 @@ static void game_init(void) { init_triggers(); - init_xmas2000(); + init_xmas(); report_init(); creport_init(); diff --git a/src/mapper/mapper.c b/src/mapper/mapper.c index 8116f1a84..4168bb519 100644 --- a/src/mapper/mapper.c +++ b/src/mapper/mapper.c @@ -31,7 +31,7 @@ #include #include -#include +#include #ifdef ALLIANCES #include #endif @@ -1686,7 +1686,7 @@ main(int argc, char *argv[]) kernel_init(); init_triggers(); - init_xmas2000(); + init_xmas(); debug_language("locales.log"); register_races();