diff --git a/src/common/kernel/region.c b/src/common/kernel/region.c index f09406bbe..266660efb 100644 --- a/src/common/kernel/region.c +++ b/src/common/kernel/region.c @@ -1497,5 +1497,12 @@ region_getname(const region * r) { int region_get_morale(const region * r) { - return r->land->morale; + return r->land?r->land->morale:0; +} + +void region_set_morale(region * r, int morale) +{ + if (r->land) { + r->land->morale = morale; + } } \ No newline at end of file diff --git a/src/common/kernel/region.h b/src/common/kernel/region.h index 08d4502a3..bbba845a1 100644 --- a/src/common/kernel/region.h +++ b/src/common/kernel/region.h @@ -252,6 +252,7 @@ struct region * r_connect(const struct region *, direction_t dir); void free_regions(void); int region_get_morale(const region * r); +void region_set_morale(region * r, int morale); void write_region_reference(const struct region * r, struct storage * store); variant read_region_reference(struct storage * store); diff --git a/src/eressea/tolua/bind_region.c b/src/eressea/tolua/bind_region.c index c334f117d..f6ae5b4a7 100644 --- a/src/eressea/tolua/bind_region.c +++ b/src/eressea/tolua/bind_region.c @@ -161,6 +161,20 @@ static int tolua_region_set_name(lua_State* L) } +static int tolua_region_get_morale(lua_State* L) +{ + region* r = (region*) tolua_tousertype(L, 1, 0); + tolua_pushnumber(L, region_get_morale(r)); + return 1; +} + +static int tolua_region_set_morale(lua_State* L) +{ + region* r = (region*)tolua_tousertype(L, 1, 0); + region_set_morale(r, (int)tolua_tonumber(L, 2, 0)); + return 0; +} + static int tolua_region_get_flag(lua_State* L) { region* self = (region*)tolua_tousertype(L, 1, 0); @@ -175,8 +189,11 @@ static int tolua_region_get_adj(lua_State* L) region* self = (region*)tolua_tousertype(L, 1, 0); direction_t dir = (direction_t)tolua_tonumber(L, 2, 0); - tolua_pushusertype(L, (void*)r_connect(self, dir), TOLUA_CAST "region"); - return 1; + if (dir>=0 && dir