neue lua-exporte:

- region:tostring
- region:operator==
- faction:tostring
- faction:operator==
This commit is contained in:
Enno Rehling 2004-04-11 16:16:26 +00:00
parent 5d559840fa
commit 82119094a7
4 changed files with 45 additions and 14 deletions

View File

@ -9,11 +9,15 @@
# include <modules/alliance.h> # include <modules/alliance.h>
#endif #endif
// util includes
#include <util/base36.h>
// lua includes // lua includes
#include <lua.hpp> #include <lua.hpp>
#include <luabind/luabind.hpp> #include <luabind/luabind.hpp>
#include <luabind/iterator_policy.hpp> #include <luabind/iterator_policy.hpp>
#include <ostream>
using namespace luabind; using namespace luabind;
static faction * static faction *
@ -65,6 +69,19 @@ faction_locale(const faction& f)
return locale_name(f.locale); return locale_name(f.locale);
} }
static std::ostream&
operator<<(std::ostream& stream, faction& f)
{
stream << factionname(&f);
return stream;
}
static bool
operator==(const faction& a, const faction&b)
{
return a.no==b.no;
}
void void
bind_faction(lua_State * L) bind_faction(lua_State * L)
{ {
@ -74,6 +91,8 @@ bind_faction(lua_State * L)
def("add_faction", &add_faction), def("add_faction", &add_faction),
class_<struct faction>("faction") class_<struct faction>("faction")
.def(tostring(self))
.def(self == faction())
.def_readonly("name", &faction::name) .def_readonly("name", &faction::name)
.def_readonly("password", &faction::passw) .def_readonly("password", &faction::passw)
.def_readonly("email", &faction::email) .def_readonly("email", &faction::email)

View File

@ -14,6 +14,7 @@
#include <luabind/luabind.hpp> #include <luabind/luabind.hpp>
#include <luabind/iterator_policy.hpp> #include <luabind/iterator_policy.hpp>
#include <ostream>
using namespace luabind; using namespace luabind;
static eressea::list<region> static eressea::list<region>
@ -75,6 +76,19 @@ region_addnotice(region& r, const char * str)
addmessage(&r, NULL, str, MSG_MESSAGE, ML_IMPORTANT); addmessage(&r, NULL, str, MSG_MESSAGE, ML_IMPORTANT);
} }
static std::ostream&
operator<<(std::ostream& stream, 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;
}
void void
bind_region(lua_State * L) bind_region(lua_State * L)
{ {
@ -83,6 +97,8 @@ bind_region(lua_State * L)
def("get_region", &findregion), def("get_region", &findregion),
class_<struct region>("region") class_<struct region>("region")
.def(tostring(self))
.def(self == region())
.property("name", &region_getname, &region_setname) .property("name", &region_getname, &region_setname)
.property("info", &region_getinfo, &region_setinfo) .property("info", &region_getinfo, &region_setinfo)
.property("terrain", &region_getterrain) .property("terrain", &region_getterrain)

View File

@ -15,6 +15,7 @@
#include <kernel/magic.h> #include <kernel/magic.h>
#include <kernel/spell.h> #include <kernel/spell.h>
// util includes
#include <util/base36.h> #include <util/base36.h>
// lua includes // lua includes

View File

@ -1,18 +1,14 @@
function unitid(u)
return u.name .. " (" .. itoa36(u.id) .. ")"
end
function teleport_all(map, grave) function teleport_all(map, grave)
print("- teleporting all quest members to the grave") print("- teleporting all quest members to the grave")
local index local index
for index in map do for index in map do
local r = map[index] local r = map[index]
local u local u
for u in r.units do for u in r.units do
u.region = grave u.region = grave
print (" .teleported " .. unitid(u)) print (" .teleported " .. u)
grave:add_notice("Ein Portal öffnet sich, und " .. u.name .. " erscheint in " .. grave.name) grave:add_notice("Ein Portal öffnet sich, und " .. u.name .. " erscheint in " .. grave.name)
end end
end end
end end
@ -32,7 +28,7 @@ function wyrm()
for u in grave.units do for u in grave.units do
if u.faction.id~=atoi36("rr") then if u.faction.id~=atoi36("rr") then
teleport_all(map, grave) teleport_all(map, grave)
break break
end end
end end
@ -65,13 +61,13 @@ function write_emails()
local key local key
for key in locales do for key in locales do
local locale = locales[key] local locale = locales[key]
files[locale] = io.open(basepath .. "/emails." .. locale, "w") files[locale] = io.open(basepath .. "/emails." .. locale, "w")
end end
local faction local faction
for faction in factions() do for faction in factions() do
-- print(faction.id .. " - " .. faction.locale) -- print(faction.id .. " - " .. faction.locale)
files[faction.locale]:write(faction.email .. "\n") files[faction.locale]:write(faction.email .. "\n")
end end
for key in files do for key in files do
@ -110,7 +106,6 @@ function process(orders)
print("could not write game") print("could not write game")
return -1 return -1
end end
end end