Lua-Zugriff auf den item-pool

This commit is contained in:
Enno Rehling 2005-03-06 13:53:13 +00:00
parent d7cb8c517e
commit 1b62f53285
6 changed files with 25 additions and 15 deletions

View File

@ -1192,10 +1192,10 @@ count_all(const faction * f)
if (f->num_people != n) { if (f->num_people != n) {
log_error(("Anzahl Personen für (%s) ist != num_people: %d statt %d.\n", log_error(("Anzahl Personen für (%s) ist != num_people: %d statt %d.\n",
factionid(f), f->num_migrants, n)); factionid(f), f->num_migrants, n));
f->num_people = n; return n;
} }
#endif #endif
return n; return f->num_people;
} }
int int
@ -1216,7 +1216,7 @@ count_migrants (const faction * f)
if (f->num_migrants != n) { if (f->num_migrants != n) {
log_error(("Anzahl Migranten für (%s) ist != num_migrants: %d statt %d.\n", log_error(("Anzahl Migranten für (%s) ist != num_migrants: %d statt %d.\n",
factionid(f), f->num_migrants, n)); factionid(f), f->num_migrants, n));
f->num_migrants = n; return n;
} }
#endif #endif
return f->num_migrants; return f->num_migrants;

View File

@ -188,6 +188,10 @@ faction_setrace(faction& f, const char * rcname)
} }
} }
static eressea::list<std::string, item *, eressea::bind_items>
faction_items(const faction& f) {
return eressea::list<std::string, item *, eressea::bind_items>(f.items);
}
void void
bind_faction(lua_State * L) bind_faction(lua_State * L)
@ -213,7 +217,10 @@ bind_faction(lua_State * L)
.def_readwrite("age", &faction::age) .def_readwrite("age", &faction::age)
.def_readwrite("subscription", &faction::subscription) .def_readwrite("subscription", &faction::subscription)
.def_readwrite("lastturn", &faction::lastorders) .def_readwrite("lastturn", &faction::lastorders)
.def("add_item", &faction_additem) .def("add_item", &faction_additem)
.property("items", &faction_items, return_stl_iterator)
.def("add_notice", &faction_addnotice) .def("add_notice", &faction_addnotice)
.property("locale", &faction_getlocale, &faction_setlocale) .property("locale", &faction_getlocale, &faction_setlocale)
.property("units", &faction_units, return_stl_iterator) .property("units", &faction_units, return_stl_iterator)

View File

@ -1,6 +1,9 @@
#ifndef LUA_LIST_H #ifndef LUA_LIST_H
#define LUA_LIST_H #define LUA_LIST_H
#include <string>
#include <kernel/item.h>
namespace eressea { namespace eressea {
template<class T, class N = T> template<class T, class N = T>
@ -36,6 +39,14 @@ namespace eressea {
N m_clist; N m_clist;
}; };
class bind_items {
public:
static item * next(item * node) { return node->next; }
static std::string value(item * node) {
return std::string(node->type->rtype->_name[0]);
}
};
}; };
#endif #endif

View File

@ -80,17 +80,9 @@ unit_orders(const unit& u) {
return eressea::list<std::string, order *, bind_orders>(u.orders); return eressea::list<std::string, order *, bind_orders>(u.orders);
} }
class bind_items { static eressea::list<std::string, item *, eressea::bind_items>
public:
static item * next(item * node) { return node->next; }
static std::string value(item * node) {
return std::string(node->type->rtype->_name[0]);
}
};
static eressea::list<std::string, item *, bind_items>
unit_items(const unit& u) { unit_items(const unit& u) {
return eressea::list<std::string, item *, bind_items>(u.items); return eressea::list<std::string, item *, eressea::bind_items>(u.items);
} }
static unit * static unit *

View File

@ -441,7 +441,7 @@ create_region_menu(menulist ** menu, region * r)
f->num_people = f->no_units = 0; f->num_people = f->no_units = 0;
for (u = r->units; u; u = u->next) { for (u = r->units; u; u = u->next) {
u->faction->no_units++; u->faction->no_units++;
u->faction->num_people += u->number; u->faction->num_people += u->number;
} }
addmenulist(menu, buf, 0); addmenulist(menu, buf, 0);

View File

@ -602,7 +602,7 @@ ParteiListe(void)
u->faction->nregions++; u->faction->nregions++;
} }
u->faction->nunits++; u->faction->nunits++;
u->faction->num_people += u->number; u->faction->num_people += u->number;
u->faction->money += get_money(u); u->faction->money += get_money(u);
} }
} }