#include #include #include "list.h" // kernel includes #include #include #include #include #include // lua includes #include #include #include #ifdef HAVE_LUABIND_B7 # include #endif #include using namespace luabind; static eressea::list get_regions(void) { return eressea::list(regions); } static eressea::list region_units(const region& r) { return eressea::list(r.units); } static eressea::list region_buildings(const region& r) { return eressea::list(r.buildings); } static eressea::list region_ships(const region& r) { return eressea::list(r.ships); } static void region_setname(region& r, const char * name) { if (r.land) rsetname((&r), name); } static const char * region_getterrain(const region& r) { return terrain[r.terrain].name; } static const char * region_getname(const region& r) { if (r.land) return r.land->name; return terrain[r.terrain].name; } static void region_setinfo(region& r, const char * info) { set_string(&r.display, info); } static const char * region_getinfo(const region& r) { return r.display; } static int region_plane(const region& r) { if (r.planep==NULL) return 0; return r.planep->id; } static void region_addnotice(region& r, const char * str) { addmessage(&r, NULL, str, MSG_MESSAGE, ML_IMPORTANT); } static std::ostream& operator<<(std::ostream& stream, const region& r) { stream << regionname(&r, NULL) << ", " << region_getterrain(r); return stream; } static bool operator==(const region& a, const region&b) { return a.x==b.x && a.y==b.y; } static bool region_getflag(const region& r, int bit) { if (r.flags & (1<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; } static region * region_next(const region& r, int dir) { if (dir<0 || dir >=MAXDIRECTIONS) return NULL; 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; } static void region_remove(region& r) { region ** rp = ®ions; while (*rp) { if (*rp==&r) { unit * u; while (r.units) { destroy_unit(r.units); } *rp = r.next; #ifdef FAST_CONNECT direction_t dir; for (dir=0;dir!=MAXDIRECTIONS;++dir) { region * rn = r.connect[dir]; if (rn) { direction_t reldir = reldirection(rn, &r); r.connect[dir] = NULL; rn->connect[reldir] = NULL; } } #endif runhash(&r); break; } rp = &(*rp)->next; } } void region_move(region& r, int x, int y) { #ifdef FAST_CONNECT direction_t dir; for (dir=0;dir!=MAXDIRECTIONS;++dir) { region * rn = r.connect[dir]; if (rn!=NULL) { direction_t reldir = reldirection(rn, &r); rn->connect[reldir] = NULL; } rn = findregion(x+delta_x[dir], y+delta_y[dir]); if (rn!=NULL) { direction_t reldir = reldirection(rn, &r); rn->connect[reldir] = &r; } r.connect[dir] = rn; } #endif runhash(&r); r.x = x; r.y = y; rhash(&r); } void bind_region(lua_State * L) { module(L)[ def("regions", &get_regions, return_stl_iterator), def("get_region", &findregion), def("terraform", &terraform_region), class_("region") .def(tostring(self)) .def(self == region()) .property("name", ®ion_getname, ®ion_setname) .property("info", ®ion_getinfo, ®ion_setinfo) .property("terrain", ®ion_getterrain) .def("add_notice", ®ion_addnotice) .def("add_direction", ®ion_adddirection) .def("get_flag", ®ion_getflag) .def("set_flag", ®ion_setflag) .def("remove", ®ion_remove) .def("move", ®ion_move) .def("get_road", ®ion_getroad) .def("set_road", ®ion_setroad) .def("next", ®ion_next) .def_readonly("x", ®ion::x) .def_readonly("y", ®ion::y) .def_readwrite("age", ®ion::age) .property("plane_id", ®ion_plane) .property("units", ®ion_units, return_stl_iterator) .property("buildings", ®ion_buildings, return_stl_iterator) .property("ships", ®ion_ships, return_stl_iterator) ]; }