cleaning the lua interface.

world creation.
This commit is contained in:
Enno Rehling 2009-06-29 20:38:35 +00:00
parent 7d79d0bc00
commit 3fc0e27776
6 changed files with 55 additions and 28 deletions

View file

@ -61,7 +61,7 @@ static plane * home_plane = NULL;
plane *
get_homeplane(void)
{
return home_plane;
return getplanebyid(0);
}

View file

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

View file

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

View file

@ -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(&regions, 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);

View file

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

View file

@ -4,13 +4,18 @@
<terrain name="ocean" size="100" shallow="no" walk="no" swim="yes" land="no" sea="yes" />
<terrain name="plain" size="4000" road="50" shallow="no" forest="yes" cavalry="yes" seed="3">
<herb name="h0" />
<herb name="h1" />
<herb name="h2" />
<herb name="h3" />
<herb name="h4" />
<herb name="h5" />
<resource name="iron" chance="0.1" level="2d4-1" base="5d8" div="2d20+10" />
<resource name="stone" chance="0.15" level="1d4" base="5d8" div="2d30+20" />
<resource name="laen" chance="0.01" level="1d4" base="1d4" div="2d20+50" />
</terrain>
<terrain name="swamp" size="1200" road="75" seed="2">
<herb name="h6" />
<herb name="h7" />
<herb name="h8" />
<resource name="iron" chance="0.02" level="2d4-1" base="5d8" div="2d20+10" />
<resource name="stone" chance="0.02" level="1d4" base="5d8" div="2d30+20" />
@ -18,6 +23,7 @@
</terrain>
<terrain name="desert" size="400" road="100" cavalry="yes" seed="2">
<herb name="h9" />
<herb name="h10" />
<herb name="h11" />
<resource name="iron" chance="0.15" level="2d4-1" base="5d8" div="2d20+10" />
<resource name="stone" chance="0.25" level="1d4" base="5d8" div="2d30+20" />
@ -25,6 +31,7 @@
</terrain>
<terrain name="highland" size="2300" road="100" cavalry="yes" seed="2">
<herb name="h12" />
<herb name="h13" />
<herb name="h14" />
<resource name="iron" chance="0.15" level="2d4-1" base="5d8" div="2d20+10" />
<resource name="stone" chance="0.25" level="1d4" base="5d8" div="2d30+20" />
@ -32,6 +39,7 @@
</terrain>
<terrain name="mountain" size="600" road="250" seed="2">
<herb name="h15" />
<herb name="h16" />
<herb name="h17" />
<resource name="iron" chance="1.0" level="1" base="50" div="50" />
<resource name="stone" chance="1.0" level="1" base="100" div="100" />
@ -39,13 +47,15 @@
</terrain>
<terrain name="glacier" size="150" road="250" arctic="yes" seed="2">
<herb name="h18" />
<herb name="h19" />
<herb name="h20" />
<resource name="iron" chance="1.0" level="1" base="3" div="50" />
<resource name="stone" chance="1.0" level="1" base="2" div="100" />
<resource name="laen" chance="0.05" level="1" base="4" div="100" />
</terrain>
<terrain name="iceberg_sleep" size="105" road="250" arctic="yes">
<terrain name="iceberg_sleep" size="150" road="250" arctic="yes">
<herb name="h18" />
<herb name="h19" />
<herb name="h20" />
<resource name="iron" chance="0.9" level="1" base="3" div="50" />
<resource name="stone" chance="0.9" level="1" base="2" div="100" />
@ -53,11 +63,12 @@
</terrain>
<terrain name="iceberg" size="150" arctic="yes">
<herb name="h18" />
<herb name="h19" />
<herb name="h20" />
<resource name="iron" chance="0.9" level="1" base="3" div="50" />
<resource name="stone" chance="0.9" level="1" base="2" div="100" />
</terrain>
<terrain name="firewall" size="100" road="250" land="no" walk="no" sail="no" fly="no" forbidden="yes" />
<terrain name="firewall" road="250" land="no" walk="no" sail="no" fly="no" forbidden="yes" />
<terrain name="fog" sail="no" land="no" />
<terrain name="thickfog" forbidden="yes" sail="no" walk="no" fly="no" land="no" />
<terrain name="volcano" size="400" road="250" seed="1">