diff --git a/src/common/attributes/attributes.vcproj b/src/common/attributes/attributes.vcproj index 0757bcc70..52df7690e 100644 --- a/src/common/attributes/attributes.vcproj +++ b/src/common/attributes/attributes.vcproj @@ -24,7 +24,7 @@ AdditionalIncludeDirectories="../kernel,../util,../..,.." PreprocessorDefinitions="_WINDOWS,WIN32,_DEBUG" BasicRuntimeChecks="0" - RuntimeLibrary="5" + RuntimeLibrary="3" DisableLanguageExtensions="TRUE" UsePrecompiledHeader="0" PrecompiledHeaderThrough="stdafx.h" @@ -76,7 +76,7 @@ AdditionalIncludeDirectories="../kernel,../util,../..,.." PreprocessorDefinitions="WIN32,NDEBUG,_WINDOWS" StringPooling="TRUE" - RuntimeLibrary="4" + RuntimeLibrary="2" EnableFunctionLevelLinking="TRUE" DisableLanguageExtensions="TRUE" UsePrecompiledHeader="2" diff --git a/src/common/gamecode/creport.c b/src/common/gamecode/creport.c index 11af139ac..ca2d68741 100644 --- a/src/common/gamecode/creport.c +++ b/src/common/gamecode/creport.c @@ -78,7 +78,7 @@ extern const char *directions[]; extern const char *spelldata[]; extern int quiet; -extern boolean opt_cr_absolute_coords; +boolean opt_cr_absolute_coords = false; /* globals */ #define C_REPORT_VERSION 64 diff --git a/src/common/gamecode/economy.c b/src/common/gamecode/economy.c index f43b36541..c4a9882f8 100644 --- a/src/common/gamecode/economy.c +++ b/src/common/gamecode/economy.c @@ -1144,7 +1144,7 @@ maintain(building * b, boolean first) boolean paid = true, work = first; unit * u; if (fval(b, BLD_MAINTAINED)) return true; - if (b->type->maintenance==NULL) return true; + if (b->type==NULL || b->type->maintenance==NULL) return true; if (is_cursed(b->attribs, C_NOCOST, 0)) { fset(b, BLD_MAINTAINED); fset(b, BLD_WORKING); diff --git a/src/common/gamecode/gamecode.vcproj b/src/common/gamecode/gamecode.vcproj index 8e02c0de6..fd629c312 100644 --- a/src/common/gamecode/gamecode.vcproj +++ b/src/common/gamecode/gamecode.vcproj @@ -24,7 +24,7 @@ AdditionalIncludeDirectories="../kernel,../util,../..,.." PreprocessorDefinitions="WIN32,NDEBUG,_WINDOWS" StringPooling="TRUE" - RuntimeLibrary="4" + RuntimeLibrary="2" EnableFunctionLevelLinking="TRUE" DisableLanguageExtensions="TRUE" UsePrecompiledHeader="2" @@ -128,7 +128,7 @@ AdditionalIncludeDirectories="../kernel,../util,../..,.." PreprocessorDefinitions="_WINDOWS,WIN32" BasicRuntimeChecks="0" - RuntimeLibrary="5" + RuntimeLibrary="3" DisableLanguageExtensions="TRUE" UsePrecompiledHeader="0" PrecompiledHeaderThrough="stdafx.h" diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index e955f6cca..abb7bad83 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -113,8 +113,8 @@ RemoveNMRNewbie(void) { static void restart(unit *u, const race * rc) { - faction *f = addplayer(u->region, u->faction->email, u->faction->passw, rc, u->faction->locale, u->faction->subscription)->faction; - unit * nu = f->units; + faction *f = addfaction(u->faction->email, u->faction->passw, rc, u->faction->locale, u->faction->subscription); + unit * nu = addplayer(u->region, f); strlist ** o=&u->orders; f->subscription = u->faction->subscription; fset(f, FFL_RESTART); diff --git a/src/common/items/birthday_firework.c b/src/common/items/birthday_firework.c index 54fbf6fa2..b5f4690cc 100644 --- a/src/common/items/birthday_firework.c +++ b/src/common/items/birthday_firework.c @@ -30,6 +30,7 @@ /* libc includes */ #include +#include const int FIREWORK_RANGE=10; diff --git a/src/common/items/items.vcproj b/src/common/items/items.vcproj index 1b6a29963..e06b8fcc5 100644 --- a/src/common/items/items.vcproj +++ b/src/common/items/items.vcproj @@ -24,7 +24,7 @@ AdditionalIncludeDirectories="../kernel,../util,../..,.." PreprocessorDefinitions="WIN32,NDEBUG,_WINDOWS" StringPooling="TRUE" - RuntimeLibrary="4" + RuntimeLibrary="2" EnableFunctionLevelLinking="TRUE" DisableLanguageExtensions="TRUE" UsePrecompiledHeader="2" @@ -75,7 +75,7 @@ AdditionalIncludeDirectories="../kernel,../util,../..,.." PreprocessorDefinitions="_WINDOWS,WIN32" BasicRuntimeChecks="0" - RuntimeLibrary="5" + RuntimeLibrary="3" DisableLanguageExtensions="TRUE" UsePrecompiledHeader="0" PrecompiledHeaderThrough="stdafx.h" diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index 4908ad241..5ddfff294 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -86,6 +86,14 @@ const struct race * new_race[MAXRACES]; boolean sqlpatch = false; int turn; +char * +strnzcpy(char * dst, const char *src, size_t len) +{ + strncpy(dst, src, len); + dst[len]=0; + return dst; +} + static attrib_type at_creator = { "creator" /* Rest ist NULL; temporäres, nicht alterndes Attribut */ @@ -2066,7 +2074,7 @@ kernel_done(void) } const char * localenames[] = { - "de", "en", "fr", + "de", "en", NULL }; diff --git a/src/common/kernel/faction.c b/src/common/kernel/faction.c index e532d664c..7ed16f65f 100644 --- a/src/common/kernel/faction.c +++ b/src/common/kernel/faction.c @@ -30,6 +30,7 @@ /* libc includes */ #include +#include #include const unit * @@ -86,49 +87,56 @@ unused_faction_id(void) return id; } -unit * -addplayer(region *r, const char *email, const char * password, - const struct race * frace, const struct locale *loc, - int subscription) +faction * +addfaction(const char *email, const char * password, + const struct race * frace, const struct locale *loc, + int subscription) +{ + int i; + faction *f; + assert(frace != new_race[RC_ORC]); + f = calloc(sizeof(faction), 1); + + set_string(&f->email, email); + + if (password) { + set_string(&f->passw, password); + } else { + for (i = 0; i < 6; i++) buf[i] = (char) (97 + rand() % 26); buf[i] = 0; + set_string(&f->passw, buf); + } + for (i = 0; i < 6; i++) buf[i] = (char) (97 + rand() % 26); buf[i] = 0; + set_string(&f->override, buf); + + f->lastorders = turn; + f->alive = 1; + f->age = 0; + f->race = frace; + f->magiegebiet = 0; + f->locale = loc; + f->subscription = subscription; + + f->options = Pow(O_REPORT) | Pow(O_ZUGVORLAGE) | Pow(O_SILBERPOOL) | Pow(O_COMPUTER) | Pow(O_COMPRESS) | Pow(O_ADRESSEN) | Pow(O_STATISTICS); + + f->no = unused_faction_id(); + register_faction_id(f->no); + + sprintf(buf, "%s %s", LOC(loc, "factiondefault"), factionid(f)); + set_string(&f->name, buf); + fset(f, FL_UNNAMED); + + addlist(&factions, f); + + return f; +} + +unit * +addplayer(region *r, faction * f) { - int i; unit *u; - faction *f; - - assert(frace != new_race[RC_ORC]); - f = calloc(sizeof(faction), 1); - - set_string(&f->email, email); - - if (password) { - set_string(&f->passw, password); - } else { - for (i = 0; i < 6; i++) buf[i] = (char) (97 + rand() % 26); buf[i] = 0; - set_string(&f->passw, buf); - } - for (i = 0; i < 6; i++) buf[i] = (char) (97 + rand() % 26); buf[i] = 0; - set_string(&f->override, buf); - - f->lastorders = turn; - f->alive = 1; - f->age = 0; - f->race = frace; - f->magiegebiet = 0; - f->locale = loc; - f->subscription = subscription; - set_ursprung(f, 0, r->x, r->y); - - f->options = Pow(O_REPORT) | Pow(O_ZUGVORLAGE) | Pow(O_SILBERPOOL) | Pow(O_COMPUTER) | Pow(O_COMPRESS) | Pow(O_ADRESSEN) | Pow(O_STATISTICS); - - f->no = unused_faction_id(); - register_faction_id(f->no); - - sprintf(buf, "%s %s", LOC(loc, "factiondefault"), factionid(f)); - set_string(&f->name, buf); - fset(f, FL_UNNAMED); - - addlist(&factions, f); + assert(f->units==NULL); + set_ursprung(f, 0, r->x, r->y); u = createunit(r, f, 1, f->race); give_starting_equipment(r, u); fset(u, UFL_ISNEW); diff --git a/src/common/kernel/faction.h b/src/common/kernel/faction.h index e1c6fa26f..af9fcb37e 100644 --- a/src/common/kernel/faction.h +++ b/src/common/kernel/faction.h @@ -106,9 +106,10 @@ typedef struct faction_list { extern const struct unit * random_unit_in_faction(const struct faction *f); extern const char * factionname(const struct faction * f); extern void * resolve_faction(void * data); -extern struct unit * addplayer(struct region *r, const char *email, - const char* password, const struct race * frace, - const struct locale *loc, int subscription); +extern struct unit * addplayer(struct region *r, faction * f); +extern struct faction * addfaction(const char *email, const char* password, + const struct race * frace, + const struct locale *loc, int subscription); extern boolean checkpasswd(const faction * f, const char * passwd, boolean shortp); extern void destroyfaction(faction * f); diff --git a/src/common/kernel/kernel.vcproj b/src/common/kernel/kernel.vcproj index 4cd8cfb81..4e159285e 100644 --- a/src/common/kernel/kernel.vcproj +++ b/src/common/kernel/kernel.vcproj @@ -76,7 +76,7 @@ AdditionalIncludeDirectories="../util,../..,.." PreprocessorDefinitions="_WINDOWS,WIN32" BasicRuntimeChecks="0" - RuntimeLibrary="5" + RuntimeLibrary="3" DisableLanguageExtensions="TRUE" UsePrecompiledHeader="0" PrecompiledHeaderThrough="stdafx.h" @@ -128,7 +128,7 @@ AdditionalIncludeDirectories="../util,../..,.." PreprocessorDefinitions="WIN32,NDEBUG,_WINDOWS" StringPooling="TRUE" - RuntimeLibrary="4" + RuntimeLibrary="2" EnableFunctionLevelLinking="TRUE" DisableLanguageExtensions="TRUE" UsePrecompiledHeader="2" diff --git a/src/common/kernel/magic.c b/src/common/kernel/magic.c index f780681ca..dd2dd9c32 100644 --- a/src/common/kernel/magic.c +++ b/src/common/kernel/magic.c @@ -1130,7 +1130,7 @@ spellpower(region * r, unit * u, spell * sp, int cast_level) } #ifdef MAGICPOWER - force = force * MAGICPOWER; + force = (int)(force * MAGICPOWER); #endif return max(force, 0); @@ -1498,7 +1498,7 @@ regeneration(unit * u) aura = (rand() % d + rand() % d)/2 + 1; #ifdef MAGICREGEN - aura = aura * MAGICREGEN; + aura = (int)(aura * MAGICREGEN); #endif return aura; diff --git a/src/config.h b/src/config.h index ad4569382..4eae21601 100644 --- a/src/config.h +++ b/src/config.h @@ -150,20 +150,16 @@ # define HAVE_SNPRINTF /* MSVC has _access */ -_CRTIMP int __cdecl _access(const char *, int); # define access(f, m) _access(f, m) # define HAVE_ACCESS /* MSVC has _strdup */ -_CRTIMP char * __cdecl _strdup(const char *); # define strdup(s) _strdup(s) # define HAVE_STRDUP -_CRTIMP int __cdecl _stricmp(const char *, const char *); # define stricmp(a, b) _stricmp(a, b) # define HAVE_STRICMP -_CRTIMP int __cdecl _strnicmp(const char *, const char *, size_t); # define strnicmp(a, b, c) _strnicmp(a, b, c) # define HAVE_STRNICMP # undef HAVE_STRCASECMP @@ -236,6 +232,7 @@ extern char * strdup(const char *s); # define true ((boolean)!false) #endif -#define strnzcpy(dst, src, len) (strncpy(dst, src, len), len?dst[len]=0:0, dst) +/* this function must be implemented in a .o file */ +extern char * strnzcpy(char * dst, const char *src, size_t len); #endif diff --git a/src/eressea/lua/alliance.cpp b/src/eressea/lua/alliance.cpp new file mode 100644 index 000000000..5faff1c75 --- /dev/null +++ b/src/eressea/lua/alliance.cpp @@ -0,0 +1,32 @@ +#include +#include +#include "list.h" + +// kernel includes +#include +#include + +// lua includes +#include +#include +#include + +using namespace luabind; + +static eressea::list +get_alliances(void) { + return eressea::list(alliances); +} + +void +bind_alliance(lua_State * L) +{ + module(L)[ + def("alliances", &get_alliances, return_stl_iterator), + def("get_alliance", &findalliance), + + class_("alliance") + .def_readonly("name", &alliance::name) + .def_readonly("id", &alliance::id) + ]; +} diff --git a/src/eressea/lua/bindings.h b/src/eressea/lua/bindings.h index c90e6a683..549742fd6 100644 --- a/src/eressea/lua/bindings.h +++ b/src/eressea/lua/bindings.h @@ -1,5 +1,5 @@ -#ifndef BINDINGS_H -#define BINDINGS_H +#ifndef LUA_BINDINGS_H +#define LUA_BINDINGS_H struct lua_State; @@ -7,33 +7,8 @@ extern void bind_region(struct lua_State * L); extern void bind_unit(struct lua_State * L); extern void bind_ship(struct lua_State * L); extern void bind_building(struct lua_State * L); - -namespace eressea { - template - class list { - public: - class iterator { - public: - iterator(T * index) : m_index(index) {} - T * operator*() { return m_index; } - bool operator==(const iterator& iter) { - return iter.m_index==m_index; - } - iterator& operator++() { - if (m_index) m_index = m_index->next; - return *this; - } - private: - T * m_index; - }; - typedef iterator const_iterator; - list(T * clist) : m_clist(clist) {} - iterator begin() const { return iterator(m_clist); } - iterator end() const { return iterator(NULL); } - - public: - T * m_clist; - }; -}; +extern void bind_faction(struct lua_State * L); +extern void bind_alliance(struct lua_State * L); +extern void bind_eressea(struct lua_State * L); #endif diff --git a/src/eressea/lua/building.cpp b/src/eressea/lua/building.cpp index 932520aff..d862bd17e 100644 --- a/src/eressea/lua/building.cpp +++ b/src/eressea/lua/building.cpp @@ -1,6 +1,6 @@ #include +#include #include -#include "bindings.h" // kernel includes #include @@ -11,7 +11,6 @@ #include using namespace luabind; -using namespace eressea; void bind_building(lua_State * L) diff --git a/src/eressea/lua/eressea.cpp b/src/eressea/lua/eressea.cpp new file mode 100644 index 000000000..eeb0000c0 --- /dev/null +++ b/src/eressea/lua/eressea.cpp @@ -0,0 +1,49 @@ +#include +#include +#include + +// kernel includes +#include +#include +#include +#include +#include + +// lua includes +#include +#include +#include + +using namespace luabind; + +static faction * +add_faction(const char * email, const char * passwd, const char * racename, const char * lang) +{ + const race * frace = findrace(racename, default_locale); + locale * loc = find_locale(lang); + faction * f = addfaction(email, passwd, frace, loc, 0); + return f; +} + +static unit * +add_unit(faction * f, region * r) +{ + if (f->units==NULL) return addplayer(r, f); + return createunit(r, f, 0, f->race); +} + +static alliance * +add_alliance(int id, const char * name) +{ + return makealliance(id, name); +} + +void +bind_eressea(lua_State * L) +{ + module(L)[ + def("add_unit", &add_unit), + def("add_faction", &add_faction), + def("add_alliance", &add_alliance) + ]; +} diff --git a/src/eressea/lua/export.h b/src/eressea/lua/export.h new file mode 100644 index 000000000..ee52356a1 --- /dev/null +++ b/src/eressea/lua/export.h @@ -0,0 +1,12 @@ +#ifndef LUA_EXPORT_H +#define LUA_EXPORT_H + +struct lua_State; + +extern void bind_region(struct lua_State * L); +extern void bind_unit(struct lua_State * L); +extern void bind_ship(struct lua_State * L); +extern void bind_building(struct lua_State * L); +extern void bind_faction(struct lua_State * L); + +#endif diff --git a/src/eressea/lua/faction.cpp b/src/eressea/lua/faction.cpp new file mode 100644 index 000000000..5f7414add --- /dev/null +++ b/src/eressea/lua/faction.cpp @@ -0,0 +1,61 @@ +#include +#include +#include "list.h" + +// kernel includes +#include +#include +#include + +// lua includes +#include +#include +#include + +using namespace luabind; + +static eressea::list +get_factions(void) { + return eressea::list(factions); +} + +class factionunit { +public: + static unit * next(unit * node) { return node->nextF; } + static unit * value(unit * node) { return node; } +}; + +static eressea::list +faction_units(const faction& f) +{ + return eressea::list(f.units); +} + +static void +faction_setalliance(faction& f, alliance * team) +{ + if (f.alliance==0) setalliance(&f, team); +} + +static alliance * +faction_getalliance(const faction& f) +{ + return f.alliance; +} + + + +void +bind_faction(lua_State * L) +{ + module(L)[ + def("factions", &get_factions, return_stl_iterator), + def("get_faction", &findfaction), + + class_("faction") + .def_readonly("name", &faction::name) + .def_readonly("id", &faction::no) + .property("units", &faction_units, return_stl_iterator) + .property("alliance", &faction_getalliance, &faction_setalliance) + ]; +} diff --git a/src/eressea/lua/list.h b/src/eressea/lua/list.h new file mode 100644 index 000000000..39c61a457 --- /dev/null +++ b/src/eressea/lua/list.h @@ -0,0 +1,41 @@ +#ifndef LUA_LIST_H +#define LUA_LIST_H + +namespace eressea { + + template + class listnode { + public: + static N * next(N * node) { return node->next; } + static T * value(N * node) { return node; } + }; + + template > + class list { + public: + class iterator { + public: + iterator(N * index) : m_index(index) {} + T * operator*() { return nodetype::value(m_index); } + bool operator==(const iterator& iter) { + return iter.m_index==m_index; + } + iterator& operator++() { + if (m_index) m_index = nodetype::next(m_index); + return *this; + } + private: + N * m_index; + }; + typedef iterator const_iterator; + list(N * clist) : m_clist(clist) {} + iterator begin() const { return iterator(m_clist); } + iterator end() const { return iterator(NULL); } + + public: + N * m_clist; + }; + +}; + +#endif diff --git a/src/eressea/lua/region.cpp b/src/eressea/lua/region.cpp index b3931a0a8..be311ac87 100644 --- a/src/eressea/lua/region.cpp +++ b/src/eressea/lua/region.cpp @@ -1,6 +1,6 @@ #include #include -#include "bindings.h" +#include "list.h" // kernel includes #include @@ -14,7 +14,6 @@ #include using namespace luabind; -using namespace eressea; static eressea::list get_regions(void) { @@ -44,25 +43,24 @@ region_setname(region& r, const char * name) { static const char * region_getname(const region& r) { if (r.land) return r.land->name; - return r.terrain->name; + return terrain[r.terrain].name; } static void region_setinfo(region& r, const char * info) { - if (r.land) set_string(&r.land->display, info); + set_string(&r.display, info); } static const char * region_getinfo(const region& r) { - if (r.land) return r.land->display; - return NULL; + return r.display; } void bind_region(lua_State * L) { module(L)[ - def("get_regions", &get_regions, return_stl_iterator), + def("regions", &get_regions, return_stl_iterator), def("get_region", &findregion), class_("region") diff --git a/src/eressea/lua/ship.cpp b/src/eressea/lua/ship.cpp index 6ee9e565f..e744b00fc 100644 --- a/src/eressea/lua/ship.cpp +++ b/src/eressea/lua/ship.cpp @@ -1,6 +1,5 @@ #include #include -#include "bindings.h" // kernel includes #include @@ -12,7 +11,6 @@ #include using namespace luabind; -using namespace eressea; void bind_ship(lua_State * L) diff --git a/src/eressea/lua/unit.cpp b/src/eressea/lua/unit.cpp index ad699e883..ea1c4bf50 100644 --- a/src/eressea/lua/unit.cpp +++ b/src/eressea/lua/unit.cpp @@ -1,10 +1,12 @@ #include #include -#include "bindings.h" // kernel includes -#include -#include +#include +#include +#include +#include +#include // lua includes #include @@ -12,7 +14,71 @@ #include using namespace luabind; -using namespace eressea; + +static void +unit_setnumber(unit& u, int number) +{ + if (u.number==0) set_number(&u, number); +} + +static int +unit_getnumber(const unit& u) +{ + return u.number; +} + +static int +unit_getitem(const unit& u, const char * iname) +{ + const item_type * itype = it_find(iname); + if (itype!=NULL) { + return i_get(u.items, itype); + } + return -1; +} + +static int +unit_additem(unit& u, const char * iname, int number) +{ + const item_type * itype = it_find(iname); + if (itype!=NULL) { + item * i = i_change(&u.items, itype, number); + return i?i->number:0; + } // if (itype!=NULL) + return -1; +} + +static int +unit_getskill(const unit& u, const char * skname) +{ + skill_t sk = sk_find(skname); + if (sk!=NOSKILL) { + skill * sv = get_skill(&u, sk); + return sv->level; + } + return -1; +} + +static int +unit_effskill(const unit& u, const char * skname) +{ + skill_t sk = sk_find(skname); + if (sk!=NOSKILL) { + return effskill(&u, sk); + } + return -1; +} + +static int +unit_setskill(unit& u, const char * skname, int level) +{ + skill_t sk = sk_find(skname); + if (sk!=NOSKILL) { + set_level(&u, sk, level); + return level; + } // if (sk!=NULL) + return -1; +} void bind_unit(lua_State * L) @@ -23,6 +89,13 @@ bind_unit(lua_State * L) class_("unit") .def_readonly("name", &unit::name) .def_readonly("region", &unit::region) + .def_readonly("faction", &unit::faction) .def_readonly("id", &unit::no) + .def("get_item", &unit_getitem) + .def("add_item", &unit_additem) + .def("get_skill", &unit_getskill) + .def("eff_skill", &unit_effskill) + .def("set_skill", &unit_setskill) + .property("number", &unit_getnumber, &unit_setnumber) ]; } diff --git a/src/lua.hpp b/src/lua.hpp new file mode 100644 index 000000000..5ea348161 --- /dev/null +++ b/src/lua.hpp @@ -0,0 +1,5 @@ +extern "C" { +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" +}