diff --git a/src/askalon/triggers.c b/src/askalon/triggers.c index c2a6fa59f..7ba8d4e27 100644 --- a/src/askalon/triggers.c +++ b/src/askalon/triggers.c @@ -1,6 +1,4 @@ /* vi: set ts=2: - * - * * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -29,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -50,6 +49,7 @@ register_triggers(void) tt_register(&tt_changerace); tt_register(&tt_createcurse); tt_register(&tt_createunit); + tt_register(&tt_gate); tt_register(&tt_giveitem); tt_register(&tt_killunit); tt_register(&tt_removecurse); diff --git a/src/common/kernel/building.c b/src/common/kernel/building.c index df6626ea4..dc6626427 100644 --- a/src/common/kernel/building.c +++ b/src/common/kernel/building.c @@ -881,13 +881,13 @@ resolve_building(void * id) { } void -building_write(const struct building * b, FILE * F) +write_building_reference(const struct building * b, FILE * F) { fprintf(F, "%s ", b?itoa36(b->no):"0"); } int -building_read(struct building ** b, FILE * F) +read_building_reference(struct building ** b, FILE * F) { int id; char zText[10]; diff --git a/src/common/kernel/building.h b/src/common/kernel/building.h index 264fc0344..f564aa2d4 100644 --- a/src/common/kernel/building.h +++ b/src/common/kernel/building.h @@ -135,8 +135,8 @@ extern const struct building_type * oldbuildings[MAXBUILDINGTYPES]; #define NOBUILDING NULL extern void * resolve_building(void * data); -extern void building_write(const struct building * b, FILE * F); -extern int building_read(struct building ** b, FILE * F); +extern void write_building_reference(const struct building * b, FILE * F); +extern int read_building_reference(struct building ** b, FILE * F); extern struct building *findbuilding(int n); diff --git a/src/common/kernel/unit.c b/src/common/kernel/unit.c index a2b7fdf84..c9af27f14 100644 --- a/src/common/kernel/unit.c +++ b/src/common/kernel/unit.c @@ -320,13 +320,13 @@ void a_writesiege(const attrib * a, FILE * f) { struct building * b = (struct building*)a->data.v; - building_write(b, f); + write_building_reference(b, f); } int a_readsiege(attrib * a, FILE * f) { - return building_read((struct building**)&a->data.v, f); + return read_building_reference((struct building**)&a->data.v, f); } attrib_type at_siege = { diff --git a/src/common/modules/gmcmd.c b/src/common/modules/gmcmd.c index 22250a5c8..b41b939f9 100644 --- a/src/common/modules/gmcmd.c +++ b/src/common/modules/gmcmd.c @@ -8,17 +8,20 @@ This program may not be used, modified or distributed without prior permission by the authors of Eressea. - - */ +*/ + #include #include #include "gmcmd.h" #include "command.h" +/* misc includes */ #include #include +#include /* kernel includes */ +#include #include #include #include @@ -27,9 +30,10 @@ #include /* util includes */ -#include -#include #include +#include +#include +#include /* libc includes */ #include @@ -122,6 +126,34 @@ gm_create(const char * str, void * data, const char * cmd) } } +/** + ** GM: GATE + ** requires: permission-key "gmgate" + **/ +static void +gm_gate(const char * str, void * data, const char * cmd) +{ + unit * u = (unit*)data; + const struct plane * p = rplane(u->region); + int id = atoi36(igetstrtoken(str)); + int x = rel_to_abs(p, u->faction, atoi(getstrtoken()), 0); + int y = rel_to_abs(p, u->faction, atoi(getstrtoken()), 1); + region * r = findregion(x, y); + building * b = findbuilding(id); + if (b==NULL || r==NULL || p!=rplane(b->region) || p!=rplane(r)) { + mistake(u, cmd, "Dieses Gebäude kann die Einheit nicht umwandeln.\n", 0); + return; + } else { + /* checking permissions */ + attrib * permissions = a_find(u->faction->attribs, &at_permissions); + if (!permissions || !find_key((attrib*)permissions->data.v, atoi36("gmgate"))) return; + else { + add_trigger(&u->attribs, "timer", trigger_gate(b, r)); + } + } +} + + /** ** GM: TERRAFORM ** requires: permission-key "gmterf" @@ -137,7 +169,7 @@ gm_terraform(const char * str, void * data, const char * cmd) region * r = findregion(x, y); terrain_t t; if (r==NULL || p!=rplane(r)) { - mistake(u, cmd, "Diese Regon kann die Einheit nicht umwandeln.\n", 0); + mistake(u, cmd, "Diese Region kann die Einheit nicht umwandeln.\n", 0); return; } else { /* checking permissions */ @@ -300,6 +332,7 @@ init_gmcmd(void) add_command(&g_keys, &g_cmds, "gm", &gm_command); add_command(&g_keys, &g_cmds, "terraform", &gm_terraform); add_command(&g_keys, &g_cmds, "create", &gm_create); + add_command(&g_keys, &g_cmds, "gate", &gm_gate); add_command(&g_keys, &g_cmds, "give", &gm_give); add_command(&g_keys, &g_cmds, "take", &gm_take); add_command(&g_keys, &g_cmds, "teleport", &gm_teleport); @@ -403,6 +436,7 @@ gm_addquest(const char * email, const char * name, int radius, unsigned int flag a = a_add(&f->attribs, a_new(&at_permissions)); a_add((attrib**)&a->data.v, make_key(atoi36("gmterf"))); + a_add((attrib**)&a->data.v, make_key(atoi36("gmgate"))); a_add((attrib**)&a->data.v, make_key(atoi36("gmtele"))); a_add((attrib**)&a->data.v, make_key(atoi36("gmgive"))); a_add((attrib**)&a->data.v, make_key(atoi36("gmskil"))); diff --git a/src/common/triggers/gate.c b/src/common/triggers/gate.c new file mode 100644 index 000000000..a7424edf1 --- /dev/null +++ b/src/common/triggers/gate.c @@ -0,0 +1,99 @@ +#include +#include +#include "gate.h" + +/* kernel includes */ +#include +#include +#include + +/* util includes */ +#include +#include + +/* libc includes */ +#include + +typedef struct gate_data { + struct building * gate; + struct region * target; +} gate_data; + +static int +gate_handle(trigger * t, void * data) +{ + /* call an event handler on gate. + * data.v -> ( variant event, int timer ) + */ + gate_data * gd = (gate_data*)t->data.v; + struct building * b = gd->gate; + struct region * r = gd->target; + + if (b && r) { + unit ** up = &b->region->units; + while (*up) { + unit * u = *up; + if (u->building==b) move_unit(u, r, NULL); + if (*up==u) up = &u->next; + } + } else { + log_error(("could not perform gate::handle()\n")); + return -1; + } + unused(data); + return 0; +} + +static void +gate_write(const trigger * t, FILE * F) +{ + gate_data * gd = (gate_data*)t->data.v; + building * b = gd->gate; + region * r = gd->target; + + write_building_reference(b, F); + write_region_reference(r, F); +} + +static int +gate_read(trigger * t, FILE * F) +{ + gate_data * gd = (gate_data*)t->data.v; + + read_building_reference(&gd->gate, F); + read_region_reference(&gd->target, F); + + return 1; +} + +static void +gate_init(trigger * t) +{ + t->data.v = calloc(sizeof(gate_data), 1); +} + +static void +gate_done(trigger * t) +{ + free(t->data.v); +} + + +struct trigger_type tt_gate = { + "gate", + gate_init, + gate_done, + gate_handle, + gate_write, + gate_read +}; + +trigger * +trigger_gate(building * b, region * target) +{ + trigger * t = t_new(&tt_gate); + gate_data * td = (gate_data*)t->data.v; + td->gate = b; + td->target = target; + return t; +} diff --git a/src/common/triggers/gate.h b/src/common/triggers/gate.h new file mode 100644 index 000000000..a318eda2f --- /dev/null +++ b/src/common/triggers/gate.h @@ -0,0 +1,26 @@ +/* vi: set ts=2: + +-------------------+ Christian Schlittchen + | | Enno Rehling + | Eressea PBEM host | Katja Zedel + | (c) 1998 - 2001 | Henning Peters + | | Ingo Wilken + +-------------------+ Stefan Reich + + This program may not be used, modified or distributed + without prior permission by the authors of Eressea. +*/ + +#ifndef GATE_H +#define GATE_H + +/* all types we use are defined here to reduce dependencies */ +struct trigger_type; +struct trigger; +struct region; +struct building; + +extern struct trigger_type tt_gate; + +extern struct trigger * trigger_gate(struct building * b, struct region * r); + +#endif diff --git a/src/common/triggers/triggers.c b/src/common/triggers/triggers.c index 83af19a90..e70e72543 100644 --- a/src/common/triggers/triggers.c +++ b/src/common/triggers/triggers.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -50,6 +51,7 @@ init_triggers(void) tt_register(&tt_changerace); tt_register(&tt_createcurse); tt_register(&tt_createunit); + tt_register(&tt_gate); tt_register(&tt_giveitem); tt_register(&tt_killunit); tt_register(&tt_removecurse); diff --git a/src/eressea/korrektur.c b/src/eressea/korrektur.c index 3973e020d..b635a0993 100644 --- a/src/eressea/korrektur.c +++ b/src/eressea/korrektur.c @@ -21,6 +21,8 @@ #include #include +/* misc includes */ +#include #include #include @@ -1322,18 +1324,15 @@ extern attrib * make_atpermissions(void); extern struct attrib_type at_permissions; static void -make_gms(void) +update_gms(void) { - faction * f = findfaction(atoi36("rr")); - if (f) { + faction * f; + for (f=factions;f;f=f->next) { attrib * a = a_find(f->attribs, &at_permissions); - if (!a) { - item_type * itype; - a = a_add(&f->attribs, make_atpermissions()); - for (itype=itemtypes;itype;itype=itype->next) { - a_add((attrib**)&a->data.v, make_atgmcreate(itype)); + if (a) { + if (!find_key((attrib*)a->data.v, atoi36("gmgate"))) { + a_add((attrib**)&a->data.v, make_key(atoi36("gmgate"))); } - a_add((attrib**)&a->data.v, make_key(atoi36("gmtf"))); } } } @@ -2245,8 +2244,7 @@ korrektur(void) #ifdef TEST_GM_COMMANDS setup_gm_faction(); #endif - make_gms(); - /* Wieder entfernen! */ + update_gms(); verify_owners(false); /* fix_herbtypes(); */ #ifdef CONVERT_TRIGGER diff --git a/src/eressea/triggers.c b/src/eressea/triggers.c index 83af19a90..e70e72543 100644 --- a/src/eressea/triggers.c +++ b/src/eressea/triggers.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -50,6 +51,7 @@ init_triggers(void) tt_register(&tt_changerace); tt_register(&tt_createcurse); tt_register(&tt_createunit); + tt_register(&tt_gate); tt_register(&tt_giveitem); tt_register(&tt_killunit); tt_register(&tt_removecurse); diff --git a/src/header.txt b/src/header.txt index 59164c68e..6afc5c36f 100644 --- a/src/header.txt +++ b/src/header.txt @@ -8,5 +8,4 @@ This program may not be used, modified or distributed without prior permission by the authors of Eressea. - - */ +*/ diff --git a/src/mapper/map_tools.c b/src/mapper/map_tools.c index b3a74c6a1..f5d77690b 100644 --- a/src/mapper/map_tools.c +++ b/src/mapper/map_tools.c @@ -146,7 +146,7 @@ void warnung(WINDOW * win, const char *text) { if (!win) { - win = openwin(strlen(text) + 4, 3, "< WARNUNG >"); + win = openwin(strlen(text) + 4, 3, "< WARNING >"); wmove(win, 1, 2); } wprintw(win, (NCURSES_CONST char*)"%s", text); @@ -185,7 +185,8 @@ my_input(WINDOW * win, int x, int y, const char *text, const char *def) if (!win) { win = openwin(SX - 10, 3, 0); - y = nw = 1; + nw = 1; + y = 1; x = 2; } @@ -230,8 +231,10 @@ my_input(WINDOW * win, int x, int y, const char *text, const char *def) beep(); wrefresh(win); } while (!(ch == '\n')); - if (nw) + if (nw) { + wclear(win); delwin(win); + } curs_set(0); lbuf[val] = 0; return lbuf; @@ -367,3 +370,21 @@ do_selection(selection * sel, const char * title, void (*perform)(selection *, v } } } + +FILE * +mapperFopen(const char *defName, const char *mode) +{ + char nameBuf[80]; + FILE *fileP; + + strncpy(nameBuf, my_input(0,0,0,"Ausgabe in File: ", defName), 79); + nameBuf[79] = 0; + + fileP = fopen(nameBuf, mode); + if(!fileP) { + warnung(NULL, "Can't open file for writing"); + } + + return fileP; +} + diff --git a/src/mapper/mapper.c b/src/mapper/mapper.c index 6a5cbdb8b..780c3372e 100644 --- a/src/mapper/mapper.c +++ b/src/mapper/mapper.c @@ -17,6 +17,7 @@ #define BOOL_DEFINED /* wenn config.h nicht vor curses included wird, kompiliert es unter windows nicht */ #include +#include #include #include #include "mapper.h" @@ -764,6 +765,25 @@ movearound(int rx, int ry) { } ch=-9; } break; + case 'W': + if(Tagged) { + FILE *mapFile = mapperFopen("mapper.map","w"); + const char *tname; + if(mapFile) { + tag=Tagged; + while(tag) { + fprintf(mapFile, "REGION %d %d\n",tag->r->x, tag->r->y); + if(r_isforest(tag->r)) { + tname = "forest"; + } else { + tname = terrain[rterrain(tag->r)].name; + } + fprintf(mapFile, "\"%s\"; Terrain\n", locale_string(NULL, tname)); + tag=tag->next; + } + fclose(mapFile); + } + } break; case 'G': rx=tx; ry=ty; recalc_everything(&x, &y, &rx, &ry); diff --git a/src/mapper/mapper.h b/src/mapper/mapper.h index faa7b51b4..dcb3b31b4 100644 --- a/src/mapper/mapper.h +++ b/src/mapper/mapper.h @@ -61,6 +61,7 @@ void make_new_region(int x, int y); int map_input(WINDOW * win, int x, int y, const char *text, int mn, int mx, int pre); boolean yes_no(WINDOW * win, const char *text, const char def); void warnung(WINDOW * win, const char *text); +FILE *mapperFopen(const char *defName, const char *mode); void adddbllist(dbllist ** S, const char *s); void ScrollRegList(int dir); void DisplayRegList(int neu);