diff --git a/src/chaos.c b/src/chaos.c index 58cd7af73..abd74b5d9 100644 --- a/src/chaos.c +++ b/src/chaos.c @@ -53,6 +53,19 @@ attrib_type at_chaoscount = { ATF_UNIQUE }; +void set_chaoscount(struct region *r, int deaths) +{ + if (deaths==0) { + a_removeall(&r->attribs, &at_chaoscount); + } else { + attrib *a = a_find(r->attribs, &at_chaoscount); + if (!a) { + a = a_add(&r->attribs, a_new(&at_chaoscount)); + } + a->data.i = deaths; + } +} + int get_chaoscount(const region * r) { attrib *a = a_find(r->attribs, &at_chaoscount); diff --git a/src/chaos.h b/src/chaos.h index 6e62a0d17..0c2667083 100644 --- a/src/chaos.h +++ b/src/chaos.h @@ -29,6 +29,7 @@ extern "C" { void chaos_register(void); void chaos_update(void); + void set_chaoscount(struct region *r, int deaths); int get_chaoscount(const struct region * r); void add_chaoscount(struct region * r, int deaths); diff --git a/src/gmtool.c b/src/gmtool.c index d9afd738e..24c1735e8 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -15,6 +15,7 @@ #include "gmtool.h" #include "gmtool_structs.h" +#include "chaos.h" #include "console.h" #include "listbox.h" #include "wormhole.h" @@ -45,6 +46,7 @@ #include #include +#include #include #include #include @@ -515,6 +517,46 @@ static void statusline(WINDOW * win, const char *str) wnoutrefresh(win); } +static void reset_region(region *r) { + set_chaoscount(r, 0); + r->flags = 0; + a_removeall(&r->attribs, NULL); + while (r->units) { + remove_unit(&r->units, r->units); + } + while (r->ships) { + remove_ship(&r->ships, r->ships); + } + while (r->buildings) { + remove_building(&r->buildings, r->buildings); + } +} + +static void reset_cursor(state *st) { + int nx = st->cursor.x; + int ny = st->cursor.y; + region *r; + pnormalize(&nx, &ny, st->cursor.pl); + if ((r = findregion(nx, ny)) != NULL) { + reset_region(r); + } +} + +static void reset_rect(state *st) { + int x, y, bs = 3; + for (x=0;x!=bs;++x) { + for (y = 0; y != bs; ++y) { + region *r; + int nx = st->cursor.x + x; + int ny = st->cursor.y + y; + pnormalize(&nx, &ny, st->cursor.pl); + if ((r = findregion(nx, ny)) != NULL) { + reset_region(r); + } + } + } +} + static void terraform_at(coordinate * c, const terrain_type * terrain) { if (terrain != NULL) { @@ -934,6 +976,12 @@ static void handlekey(state * st, int c) st->wnd_status->update |= 1; st->wnd_map->update |= 1; break; + case 'c': /* clear/reset */ + reset_cursor(st); + break; + case 'C': /* clear/reset */ + reset_rect(st); + break; case 0x09: /* tab = next selected */ if (regions != NULL) { map_region *mr = cursor_region(&st->display, cursor);