/* vi: set ts=2: * * * Eressea PB(E)M host Copyright (C) 1998-2003 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) * Henning Peters (faroul@beyond.kn-bremen.de) * Enno Rehling (enno@eressea-pbem.de) * Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de) * * This program may not be used, modified or distributed without * prior permission by the authors of Eressea. */ #include #include #include "unitmessage.h" /* kernel includes */ #include /* util includes */ #include #include #include #include /* ansi includes */ #include #include #include #include /*** ** give an item to someone **/ typedef struct unitmessage_data { struct unit * target; char * string; int type; int level; } unitmessage_data; static void unitmessage_init(trigger * t) { t->data.v = calloc(sizeof(unitmessage_data), 1); } static void unitmessage_free(trigger * t) { unitmessage_data * sd = (unitmessage_data*)t->data.v; free(sd->string); free(t->data.v); } static int unitmessage_handle(trigger * t, void * data) { /* call an event handler on unitmessage. * data.v -> ( variant event, int timer ) */ unitmessage_data * td = (unitmessage_data*)t->data.v; if (td->target!=NULL) { addmessage(td->target->region, td->target->faction, td->string, td->type, td->level); } else log_error(("could not perform unitmessage::handle()\n")); unused(data); return 0; } static void unitmessage_write(const trigger * t, FILE * F) { unitmessage_data * td = (unitmessage_data*)t->data.v; fprintf(F, "%s ", itoa36(td->target->no)); fwritestr(F, td->string); fprintf(F, " %d %d ", td->type, td->level); } static int unitmessage_read(trigger * t, FILE * F) { unitmessage_data * td = (unitmessage_data*)t->data.v; char zText[256]; int i; fscanf(F, "%s", zText); i = atoi36(zText); td->target = findunit(i); if (td->target==NULL) ur_add((void*)i, (void**)&td->target, resolve_unit); freadstr(F, zText, sizeof(zText)); fscanf(F, "%d %d ", &td->type, &td->level); td->string = strdup(zText); return AT_READ_OK; } trigger_type tt_unitmessage = { "unitmessage", unitmessage_init, unitmessage_free, unitmessage_handle, unitmessage_write, unitmessage_read }; trigger * trigger_unitmessage(unit * target, const char * string, int type, int level) { trigger * t = t_new(&tt_unitmessage); unitmessage_data * td = (unitmessage_data*)t->data.v; td->target = target; td->string = strdup(string); td->type = type; td->level = level; return t; }