From 6b835e9b82e7de8805639d09c18cbd81677b0877 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 25 May 2006 22:34:58 +0000 Subject: [PATCH] - Making the new highlight/select bindings work - script to move selected regions --- src/common/kernel/eressea.c | 13 ++++++------- src/eressea/gmtool.c | 4 ++-- src/eressea/gmtool.h | 1 + src/scripts/gm/move.lua | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 src/scripts/gm/move.lua diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index fb2c47026..d0fe75d8b 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -523,17 +523,16 @@ max_magicians(const faction * f) int max_skill(faction * f, skill_t sk) { - int m = INT_MAX; - - if (allied_skilllimit(f, sk)) { + int m = INT_MAX; + int al = allied_skilllimit(f, sk); + if (al>0) { if (sk!=SK_ALCHEMY && sk!=SK_MAGIC) return INT_MAX; if (f->alliance!=NULL) { int ac = listlen(f->alliance->members); /* number of factions */ - int al = allied_skilllimit(f, sk); /* limit per alliance */ - int fl = (al+ac-1)/ac; /* faction limit */ - /* the following ist _very_ weird, please examine */ + int fl = (al+ac-1)/ac; /* faction limit, rounded up */ + /* the faction limit may not be achievable because it would break the alliance-limit */ int sc = al - allied_skillcount(f, sk); - if (sc==0) return count_skill(f, sk); + if (sc<=0) return 0; return fl; } } diff --git a/src/eressea/gmtool.c b/src/eressea/gmtool.c index 506981c0e..e3130a4fe 100644 --- a/src/eressea/gmtool.c +++ b/src/eressea/gmtool.c @@ -243,7 +243,7 @@ init_curses(void) if (has_colors() || force_color) { short bcol = COLOR_BLACK; - short hcol = COLOR_CYAN; + short hcol = COLOR_MAGENTA; start_color(); #ifdef WIN32 /* looks crap on putty with TERM=linux */ @@ -698,7 +698,7 @@ highlight_region(region *r) } void -select_coordinate(selection * selected, int x, int y) +select_coordinate(struct selection * selected, int x, int y) { coordinate coord = { 0 }; coord.x = x; diff --git a/src/eressea/gmtool.h b/src/eressea/gmtool.h index 7645da4f4..c16db50b0 100644 --- a/src/eressea/gmtool.h +++ b/src/eressea/gmtool.h @@ -15,6 +15,7 @@ extern "C" { #endif struct lua_State; + struct selection; extern int gmmain(int argc, char *argv[]); extern int curses_readline(struct lua_State * L, const char * prompt); diff --git a/src/scripts/gm/move.lua b/src/scripts/gm/move.lua new file mode 100644 index 000000000..17f063a34 --- /dev/null +++ b/src/scripts/gm/move.lua @@ -0,0 +1,32 @@ +swapx = 0 +swapy = 0 + +function swap_region(r, tr) + local sr = get_region(swapx, swapy) + while sr~=nil do + swapx = math.random(1000) + swapy = math.random(1000) + sr = get_region(swapx, swapy) + end + local tx = tr.x + local ty = tr.y + local x = r.x + local y = r.y + tr:move(swapx, swapy) + r:move(tx, ty) + tr:move(x, y) +end + +function move_selection(x, y) + for r in gmtool.selection() do + local tx = r.x+x + local ty = r.y+y + local tr = get_region(tx, ty) + if tr~=nil then + swap_region(r, tr) + else + r:move(tx, ty) + end + end +end +