lua-interface kann Befehle erzeugen ud löschen, terraformen

This commit is contained in:
Enno Rehling 2004-05-31 10:27:33 +00:00
parent aa76baab1c
commit 4dded69d03
2 changed files with 47 additions and 0 deletions

View File

@ -103,12 +103,44 @@ region_setflag(region& r, int bit, bool set)
else r.flags &= ~(1<<bit); else r.flags &= ~(1<<bit);
} }
static region *
terraform_region(int x, int y, const char * tname)
{
terrain_t t;
if (tname==NULL) {
t = NOTERRAIN;
} else {
for (t=0;t!=MAXTERRAINS;++t) {
if (strcmp(terrain[t].name, tname)==0) break;
}
if (t==MAXTERRAINS) return NULL;
}
region * r = findregion(x, y);
if (t==NOTERRAIN) {
if (r!=NULL) {
if (r->units!=NULL) {
// TODO: error message
return r;
}
terraform(r, T_FIREWALL);
// TODO: durch einen NULL-äquivalenten terraintyp ersetzen
}
return NULL;
}
if (r==NULL) r = new_region(x, y);
terraform(r, t);
return r;
}
void void
bind_region(lua_State * L) bind_region(lua_State * L)
{ {
module(L)[ module(L)[
def("regions", &get_regions, return_stl_iterator), def("regions", &get_regions, return_stl_iterator),
def("get_region", &findregion), def("get_region", &findregion),
def("terraform", &terraform_region),
class_<struct region>("region") class_<struct region>("region")
.def(tostring(self)) .def(tostring(self))

View File

@ -267,6 +267,19 @@ unit_setmagic(unit& u, const char * type)
} }
} }
static void
unit_addorder(unit& u, const char * str)
{
addstrlist(&u.orders, str);
}
static void
unit_clearorders(unit& u)
{
freestrlist(u.orders);
u.orders = NULL;
}
void void
bind_unit(lua_State * L) bind_unit(lua_State * L)
{ {
@ -282,6 +295,8 @@ bind_unit(lua_State * L)
.def_readonly("id", &unit::no) .def_readonly("id", &unit::no)
.def_readwrite("hp", &unit::hp) .def_readwrite("hp", &unit::hp)
.def_readwrite("status", &unit::status) .def_readwrite("status", &unit::status)
.def("add_order", &unit_addorder)
.def("clear_orders", &unit_clearorders)
.def("get_item", &unit_getitem) .def("get_item", &unit_getitem)
.def("add_item", &unit_additem) .def("add_item", &unit_additem)
.def("get_skill", &unit_getskill) .def("get_skill", &unit_getskill)