special_direction jetzt von LUA aus benutzbar. Neuer Testcode für special directions.

This commit is contained in:
Enno Rehling 2005-01-01 11:48:36 +00:00
parent 70237ce12f
commit df26ef19be
7 changed files with 46 additions and 28 deletions

View File

@ -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)
{

View File

@ -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;

View File

@ -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;
}

View File

@ -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);

View File

@ -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");

View File

@ -3,11 +3,11 @@
#include "list.h"
// kernel includes
#include <kernel/building.h>
#include <kernel/plane.h>
#include <kernel/region.h>
#include <kernel/unit.h>
#include <kernel/building.h>
#include <kernel/ship.h>
#include <kernel/unit.h>
// lua includes
#include <lua.hpp>
@ -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", &region_getinfo, &region_setinfo)
.property("terrain", &region_getterrain)
.def("add_notice", &region_addnotice)
.def("add_direction", &region_adddirection)
.def("get_flag", &region_getflag)
.def("set_flag", &region_setflag)

View File

@ -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