From df26ef19be1219bbab5f28b0a339beeec6a51b54 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 1 Jan 2005 11:48:36 +0000 Subject: [PATCH] =?UTF-8?q?special=5Fdirection=20jetzt=20von=20LUA=20aus?= =?UTF-8?q?=20benutzbar.=20Neuer=20Testcode=20f=C3=BCr=20special=20directi?= =?UTF-8?q?ons.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/kernel/magic.c | 18 ------------------ src/common/kernel/magic.h | 2 -- src/common/kernel/region.c | 25 +++++++++++++++++++++---- src/common/kernel/region.h | 3 +++ src/common/kernel/spell.c | 4 ++-- src/eressea/lua/region.cpp | 13 +++++++++++-- src/scripts/samples.lua | 9 +++++++++ 7 files changed, 46 insertions(+), 28 deletions(-) diff --git a/src/common/kernel/magic.c b/src/common/kernel/magic.c index cc77305fe..b31be2510 100644 --- a/src/common/kernel/magic.c +++ b/src/common/kernel/magic.c @@ -2760,24 +2760,6 @@ magic(void) } } -attrib * -create_special_direction(region *r, int x, int y, int duration, - const char *desc, const char *keyword) - -{ - attrib *a = a_add(&r->attribs, a_new(&at_direction)); - spec_direction *d = (spec_direction *)(a->data.v); - - d->active = false; - d->x = x; - d->y = y; - d->duration = duration; - d->desc = strdup(desc); - d->keyword = strdup(keyword); - - return a; -} - const char * spell_info(const struct spell * sp, const struct locale * lang) { diff --git a/src/common/kernel/magic.h b/src/common/kernel/magic.h index c5bac0e8b..bef5ce342 100644 --- a/src/common/kernel/magic.h +++ b/src/common/kernel/magic.h @@ -365,8 +365,6 @@ extern void remove_familiar(struct unit * mage); extern void create_newfamiliar(struct unit * mage, struct unit * familiar); extern void create_newclone(struct unit * mage, struct unit * familiar); extern struct unit * has_clone(struct unit * mage); -extern struct attrib *create_special_direction(struct region *r, int x, int y, int duration, - const char *desc, const char *keyword); extern struct plane * astral_plane; diff --git a/src/common/kernel/region.c b/src/common/kernel/region.c index 757bfbcf4..3ab4b6f0a 100644 --- a/src/common/kernel/region.c +++ b/src/common/kernel/region.c @@ -221,6 +221,24 @@ attrib_type at_direction = { }; +attrib * +create_special_direction(region *r, region * rt, int duration, + const char *desc, const char *keyword) + +{ + attrib *a = a_add(&r->attribs, a_new(&at_direction)); + spec_direction *d = (spec_direction *)(a->data.v); + + d->active = false; + d->x = rt->x; + d->y = rt->y; + d->duration = duration; + d->desc = strdup(desc); + d->keyword = strdup(keyword); + + return a; +} + /* Moveblock wird zur Zeit nicht über Attribute, sondern ein Bitfeld r->moveblock gemacht. Sollte umgestellt werden, wenn kompliziertere Dinge gefragt werden. */ @@ -371,12 +389,11 @@ koor_reldirection(int ax, int ay, int bx, int by) spec_direction * special_direction(const region * from, const region * to) { - spec_direction *sd; const attrib *a = a_findc(from->attribs, &at_direction); while (a!=NULL) { - sd = (spec_direction *)a->data.v; - if (sd->active && sd->x==to->x && sd->y==to->y) return sd; + spec_direction * sd = (spec_direction *)a->data.v; + if (sd->x==to->x && sd->y==to->y) return sd; a = a->nexttype; } return NULL; @@ -389,7 +406,7 @@ reldirection(const region * from, const region * to) if (dir==NODIRECTION) { spec_direction *sd = special_direction(from, to); - if (sd!=NULL) return D_SPECIAL; + if (sd!=NULL && sd->active) return D_SPECIAL; } return dir; } diff --git a/src/common/kernel/region.h b/src/common/kernel/region.h index c7b388a9e..21adc564c 100644 --- a/src/common/kernel/region.h +++ b/src/common/kernel/region.h @@ -154,6 +154,9 @@ void runhash(struct region * r); void free_regionlist(region_list *rl); void add_regionlist(region_list **rl, struct region *r); extern struct spec_direction * special_direction(const region * from, const region * to); +extern struct attrib *create_special_direction(struct region *r, struct region *rt, + int duration, const char *desc, + const char *keyword); int woodcount(const struct region * r); int deathcount(const struct region * r); diff --git a/src/common/kernel/spell.c b/src/common/kernel/spell.c index 4ca79866c..78c1e143e 100644 --- a/src/common/kernel/spell.c +++ b/src/common/kernel/spell.c @@ -3621,10 +3621,10 @@ sp_chaossuction(castorder *co) return 0; } - create_special_direction(r, rt->x, rt->y, 2, + create_special_direction(r, rt, 2, "Ein Wirbel aus reinem Chaos zieht über die Region.", "Wirbel"); - create_special_direction(rt, r->x, r->y, 2, + create_special_direction(rt, r, 2, "Ein Wirbel aus reinem Chaos zieht über die Region.", "Wirbel"); diff --git a/src/eressea/lua/region.cpp b/src/eressea/lua/region.cpp index c301cec88..1e91b4e31 100644 --- a/src/eressea/lua/region.cpp +++ b/src/eressea/lua/region.cpp @@ -3,11 +3,11 @@ #include "list.h" // kernel includes +#include #include #include -#include -#include #include +#include // lua includes #include @@ -157,6 +157,14 @@ region_next(const region& r, int dir) return r_connect(&r, (direction_t)dir); } +static void +region_adddirection(region& r, region &rt, const char * name, const char * info) +{ + create_special_direction(&r, &rt, -1, info, name); + spec_direction * sd = special_direction(&r, &rt); + sd->active = 1; +} + void bind_region(lua_State * L) { @@ -172,6 +180,7 @@ bind_region(lua_State * L) .property("info", ®ion_getinfo, ®ion_setinfo) .property("terrain", ®ion_getterrain) .def("add_notice", ®ion_addnotice) + .def("add_direction", ®ion_adddirection) .def("get_flag", ®ion_getflag) .def("set_flag", ®ion_setflag) diff --git a/src/scripts/samples.lua b/src/scripts/samples.lua index 51d77f792..a2d92e65f 100644 --- a/src/scripts/samples.lua +++ b/src/scripts/samples.lua @@ -22,6 +22,8 @@ function test_movement() r3 = terraform(3, 0, "plain") r4 = terraform(4, 0, "glacier") + r0:add_direction(r4, "Wirbel", "Nimm die Abkürzung, Luke") + r0:set_road(east, 1.0) r1:set_road(west, 1.0) r1:set_road(east, 1.0) @@ -50,6 +52,10 @@ function test_movement() ships[i] = add_ship("boat", ocean) end + astra = mkunit(orcs, r0, 1) + astra:add_order("NACH Wirbel") + astra:add_order("NUMMER EINHEIT astr") + foot = mkunit(orcs, r0, 1) foot:add_order("ROUTE W W") foot:add_order("NUMMER EINHEIT foot") @@ -408,3 +414,6 @@ end if foot.region ~= w1 then print "ERROR: Fusseinheit hat ihr NACH nicht korrekt ausgeführt" end +if astra.region ~= r4 then + print "ERROR: Astraleinheit konnte Wirbel nicht benutzen" +end