diff --git a/src/common/kernel/unit.c b/src/common/kernel/unit.c index 1ae647be4..87f76a9e9 100644 --- a/src/common/kernel/unit.c +++ b/src/common/kernel/unit.c @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -524,10 +525,11 @@ free_units(void) } } + void write_unit_reference(const unit * u, FILE * F) { - assert(u->number>0); + assert(u==NULL || u->number>0); fprintf(F, "%s ", (u!=NULL && u->no!=0)?itoa36(u->no):"0"); } @@ -1406,10 +1408,18 @@ countheroes(const struct faction * f) { const unit * u = f->units; int n = 0; + int m = 0; + while (u) { if (fval(u, UFL_HERO)) n+= u->number; u = u->nextF; } +#ifndef NDEBUG + m = maxheroes(f); + if (n>m) { + log_warning(("%s has %d of %d heroes\n", factionname(f), n, m)); + } +#endif return n; } diff --git a/src/eressea/lua/faction.cpp b/src/eressea/lua/faction.cpp index 300101226..b4191add5 100644 --- a/src/eressea/lua/faction.cpp +++ b/src/eressea/lua/faction.cpp @@ -277,15 +277,27 @@ faction_setorigin_x(faction& f, short x) { f.ursprung->x = x; } -short +static short faction_getorigin_y(const faction& f) { return f.ursprung->y; } -void + +static void faction_setorigin_y(faction& f, short y) { f.ursprung->y = y; } +static int +faction_countheroes(const faction& f) +{ + return countheroes(&f); +} + +static int +faction_maxheroes(const faction& f) +{ + return maxheroes(&f); +} void bind_faction(lua_State * L) @@ -301,9 +313,16 @@ bind_faction(lua_State * L) .def(self == faction()) .def("set_policy", &faction_setpolicy) .def("get_policy", &faction_getpolicy) + + // temporary variables .def("set_variable", &faction_set_variable) .def("get_variable", &faction_get_variable) .def("delete_variable", &faction_delete_variable) + + // heroes + .def("heroes", &faction_countheroes) + .def("max_heroes", &faction_maxheroes) + .def_readonly("name", &faction::name) .def_readonly("score", &faction::score) .def_readonly("id", &faction::no)