diff --git a/src/common/kernel/plane.c b/src/common/kernel/plane.c
index ac5513344..1fa75e0d5 100644
--- a/src/common/kernel/plane.c
+++ b/src/common/kernel/plane.c
@@ -61,7 +61,7 @@ static plane * home_plane = NULL;
plane *
get_homeplane(void)
{
- return home_plane;
+ return getplanebyid(0);
}
diff --git a/src/eressea/gmtool.c b/src/eressea/gmtool.c
index 73d6ebb46..67eea5669 100644
--- a/src/eressea/gmtool.c
+++ b/src/eressea/gmtool.c
@@ -859,7 +859,7 @@ handlekey(state * st, int c)
while (pl && pl!=cursor->pl) {
pl = pl->next;
}
- if (pl->next) {
+ if (pl && pl->next) {
cursor->pl = pl->next;
} else {
cursor->pl = get_homeplane();
diff --git a/src/eressea/tolua/bind_gmtool.c b/src/eressea/tolua/bind_gmtool.c
index c2e9302ca..589343a50 100644
--- a/src/eressea/tolua/bind_gmtool.c
+++ b/src/eressea/tolua/bind_gmtool.c
@@ -43,8 +43,6 @@ tolua_select_coordinate(lua_State* L)
int nx = (int)tolua_tonumber(L, 1, 0);
int ny = (int)tolua_tonumber(L, 2, 0);
int select = tolua_toboolean(L, 3, 0);
- plane * pl = findplane(nx, ny);
- pnormalize(&nx, &ny, pl);
if (current_state) {
select_coordinate(current_state->selected, nx, ny, select);
}
@@ -157,12 +155,11 @@ tolua_state_close(lua_State* L)
static int
tolua_make_island(lua_State * L)
{
- plane * pl = (plane *)tolua_tousertype(L, 1, 0);
- int x = (int)tolua_tonumber(L, 2, 0);
- int y = (int)tolua_tonumber(L, 3, 0);
- int s = (int)tolua_tonumber(L, 4, 0);
- int n = (int)tolua_tonumber(L, 5, s / 3);
- if (pl) pnormalize(&x, &y, pl);
+ int x = (int)tolua_tonumber(L, 1, 0);
+ int y = (int)tolua_tonumber(L, 2, 0);
+ int s = (int)tolua_tonumber(L, 3, 0);
+ int n = (int)tolua_tonumber(L, 4, s / 3);
+
n = build_island_e3(x, y, n, s);
tolua_pushnumber(L, n);
return 1;
@@ -171,13 +168,12 @@ tolua_make_island(lua_State * L)
static int
tolua_make_block(lua_State * L)
{
- plane * pl = (plane *)tolua_tousertype(L, 1, 0);
- int x = (int)tolua_tonumber(L, 2, 0);
- int y = (int)tolua_tonumber(L, 3, 0);
- int r = (int)tolua_tonumber(L, 4, 6);
- const char * str = tolua_tostring(L, 5, "ocean");
+ int x = (int)tolua_tonumber(L, 1, 0);
+ int y = (int)tolua_tonumber(L, 2, 0);
+ int r = (int)tolua_tonumber(L, 3, 6);
+ const char * str = tolua_tostring(L, 4, "ocean");
const struct terrain_type * ter = get_terrain(str);
- if (pl) pnormalize(&x, &y, pl);
+
make_block(x, y, r, ter);
return 0;
}
diff --git a/src/eressea/tolua/bind_region.c b/src/eressea/tolua/bind_region.c
index 56b50fe00..35c3da1d8 100644
--- a/src/eressea/tolua/bind_region.c
+++ b/src/eressea/tolua/bind_region.c
@@ -39,10 +39,10 @@ without prior permission by the authors of Eressea.
int tolua_regionlist_next(lua_State *L)
{
region** region_ptr = (region **)lua_touserdata(L, lua_upvalueindex(1));
- region * u = *region_ptr;
- if (u != NULL) {
- tolua_pushusertype(L, (void*)u, "region");
- *region_ptr = u->next;
+ region * r = *region_ptr;
+ if (r != NULL) {
+ tolua_pushusertype(L, (void*)r, "region");
+ *region_ptr = r->next;
return 1;
}
else return 0; /* no more values to return */
@@ -215,18 +215,25 @@ tolua_region_get_objects(lua_State* L)
return 1;
}
+static int
+tolua_region_destroy(lua_State* L)
+{
+ region * self = (region *)tolua_tousertype(L, 1, 0);
+ remove_region(®ions, self);
+ return 0;
+}
+
static int
tolua_region_create(lua_State* L)
{
int x = (int)tolua_tonumber(L, 1, 0);
int y = (int)tolua_tonumber(L, 2, 0);
const char * tname = tolua_tostring(L, 3, 0);
- plane * pl = (plane *)tolua_tousertype(L, 4, 0);
+ plane * pl = findplane(x, y);
const terrain_type * terrain = get_terrain(tname);
region * r, * result;
- if (!pl) pl = findplane(x, y);
- pnormalize(&x, &y, pl);
+ assert(!pnormalize(&x, &y, pl));
r = result = findregion(x, y);
if (terrain==NULL) {
@@ -392,6 +399,18 @@ tolua_plane_get_id(lua_State* L)
return 1;
}
+static int
+tolua_plane_normalize(lua_State* L)
+{
+ plane * self = (plane *)tolua_tousertype(L, 1, 0);
+ int x = (int)tolua_tonumber(L, 2, 0);
+ int y = (int)tolua_tonumber(L, 3, 0);
+ pnormalize(&x, &y, self);
+ tolua_pushnumber(L, (lua_Number)x);
+ tolua_pushnumber(L, (lua_Number)y);
+ return 2;
+}
+
static int
tolua_plane_tostring(lua_State *L)
{
@@ -434,6 +453,7 @@ tolua_region_open(lua_State* L)
tolua_beginmodule(L, "region");
{
tolua_function(L, "create", tolua_region_create);
+ tolua_function(L, "destroy", tolua_region_destroy);
tolua_function(L, "__tostring", tolua_region_tostring);
tolua_variable(L, "id", tolua_region_get_id, NULL);
@@ -480,6 +500,7 @@ tolua_region_open(lua_State* L)
tolua_function(L, "__tostring", tolua_plane_tostring);
tolua_variable(L, "id", tolua_plane_get_id, NULL);
+ tolua_function(L, "normalize", tolua_plane_normalize);
tolua_variable(L, "name", tolua_plane_get_name, tolua_plane_set_name);
}
tolua_endmodule(L);
diff --git a/src/eressea/tolua/bindings.c b/src/eressea/tolua/bindings.c
index 67f244a96..d2d952707 100644
--- a/src/eressea/tolua/bindings.c
+++ b/src/eressea/tolua/bindings.c
@@ -605,10 +605,9 @@ tolua_get_region(lua_State* L)
{
int x = (int)tolua_tonumber(L, 1, 0);
int y = (int)tolua_tonumber(L, 2, 0);
- struct plane * pl = (struct plane *)tolua_tousertype(L, 3, 0);
+ struct plane * pl = findplane(x, y);
region * r;
- if (!pl) pl = findplane(x, y);
- pnormalize(&x, &y, pl);
+ assert(!pnormalize(&x, &y, pl));
r = findregion(x, y);
tolua_pushusertype(L, r, "region");
diff --git a/src/res/e2k9/terrains.xml b/src/res/e2k9/terrains.xml
index 2a7684d1f..6713d04d4 100644
--- a/src/res/e2k9/terrains.xml
+++ b/src/res/e2k9/terrains.xml
@@ -4,13 +4,18 @@
+
+
+
+
+
@@ -18,6 +23,7 @@
+
@@ -25,6 +31,7 @@
+
@@ -32,6 +39,7 @@
+
@@ -39,13 +47,15 @@
+
-
+
+
@@ -53,11 +63,12 @@
+
-
+