From 2967cd59cf00ce236bb658e090525f3e527df746 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 8 Jun 2015 20:53:40 +0200 Subject: [PATCH 1/3] replace pushnumber with pushinteger where applicable (prep for Lua 5.3). also kill an unreferenced string. --- res/core/de/strings.xml | 5 ----- src/bind_building.c | 4 ++-- src/bind_faction.c | 28 ++++++++++++++-------------- src/bind_gmtool.c | 6 +++--- src/bind_message.c | 18 +++++++++--------- src/bind_monsters.c | 2 +- src/bind_region.c | 18 +++++++++--------- src/bind_ship.c | 6 +++--- src/bind_sqlite.c | 2 +- src/bind_storage.c | 4 ++-- src/bind_unit.c | 2 +- src/bindings.c | 26 +++++++++++++------------- src/helpers.c | 16 ++++++++-------- 13 files changed, 66 insertions(+), 71 deletions(-) diff --git a/res/core/de/strings.xml b/res/core/de/strings.xml index 51a24c4d4..351a7e376 100644 --- a/res/core/de/strings.xml +++ b/res/core/de/strings.xml @@ -275,11 +275,6 @@ - - Tresen - counter - - wenige few diff --git a/src/bind_building.c b/src/bind_building.c index 8b89d2618..f52789700 100644 --- a/src/bind_building.c +++ b/src/bind_building.c @@ -114,7 +114,7 @@ static int tolua_building_set_name(lua_State * L) static int tolua_building_get_size(lua_State * L) { building *self = (building *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, self->size); + lua_pushinteger(L, self->size); return 1; } @@ -145,7 +145,7 @@ static int tolua_building_get_units(lua_State * L) static int tolua_building_get_id(lua_State * L) { building *self = (building *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)self->no); + lua_pushinteger(L, self->no); return 1; } diff --git a/src/bind_faction.c b/src/bind_faction.c index 1846ea957..23b450618 100644 --- a/src/bind_faction.c +++ b/src/bind_faction.c @@ -84,28 +84,28 @@ int tolua_faction_add_item(lua_State * L) static int tolua_faction_get_maxheroes(lua_State * L) { faction *self = (faction *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)maxheroes(self)); + lua_pushinteger(L, maxheroes(self)); return 1; } static int tolua_faction_get_heroes(lua_State * L) { faction *self = (faction *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)countheroes(self)); + lua_pushinteger(L, countheroes(self)); return 1; } static int tolua_faction_get_score(lua_State * L) { faction *self = (faction *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)self->score); + lua_pushinteger(L, self->score); return 1; } static int tolua_faction_get_id(lua_State * L) { faction *self = (faction *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)self->no); + lua_pushinteger(L, self->no); return 1; } @@ -148,7 +148,7 @@ static int tolua_faction_set_magic(lua_State * L) static int tolua_faction_get_age(lua_State * L) { faction *self = (faction *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)self->age); + lua_pushinteger(L, self->age); return 1; } @@ -163,7 +163,7 @@ static int tolua_faction_set_age(lua_State * L) static int tolua_faction_get_flags(lua_State * L) { faction *self = (faction *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)self->flags); + lua_pushinteger(L, self->flags); return 1; } @@ -178,7 +178,7 @@ static int tolua_faction_set_flags(lua_State * L) static int tolua_faction_get_options(lua_State * L) { faction *self = (faction *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)self->options); + lua_pushinteger(L, self->options); return 1; } @@ -193,7 +193,7 @@ static int tolua_faction_set_options(lua_State * L) static int tolua_faction_get_lastturn(lua_State * L) { faction *self = (faction *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)self->lastorders); + lua_pushinteger(L, self->lastorders); return 1; } @@ -245,7 +245,7 @@ static int tolua_faction_get_policy(lua_State * L) } } - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -283,8 +283,8 @@ static int tolua_faction_normalize(lua_State * L) int nx = r->x, ny = r->y; pnormalize(&nx, &ny, pl); adjust_coordinates(f, &nx, &ny, pl); - tolua_pushnumber(L, (lua_Number)nx); - tolua_pushnumber(L, (lua_Number)ny); + lua_pushinteger(L, nx); + lua_pushinteger(L, ny); return 2; } return 0; @@ -319,8 +319,8 @@ static int tolua_faction_get_origin(lua_State * L) y = 0; } - tolua_pushnumber(L, (lua_Number)x); - tolua_pushnumber(L, (lua_Number)y); + lua_pushinteger(L, x); + lua_pushinteger(L, y); return 2; } @@ -443,7 +443,7 @@ static int tolua_faction_set_name(lua_State * L) static int tolua_faction_get_uid(lua_State * L) { faction *f = (faction *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, f->subscription); + lua_pushinteger(L, f->subscription); return 1; } diff --git a/src/bind_gmtool.c b/src/bind_gmtool.c index ec2535e16..3c07bb3b7 100644 --- a/src/bind_gmtool.c +++ b/src/bind_gmtool.c @@ -153,7 +153,7 @@ static int tolua_make_island(lua_State * L) int n = (int)tolua_tonumber(L, 4, s / 3); n = build_island_e3(NULL, x, y, n, s); - tolua_pushnumber(L, n); + lua_pushinteger(L, n); return 1; } @@ -166,8 +166,8 @@ static void lua_paint_info(struct window *wnd, const struct state *st) int nx = st->cursor.x, ny = st->cursor.y; pnormalize(&nx, &ny, st->cursor.pl); lua_rawgeti(L, LUA_REGISTRYINDEX, paint_handle); - tolua_pushnumber(L, nx); - tolua_pushnumber(L, ny); + lua_pushinteger(L, nx); + lua_pushinteger(L, ny); if (lua_pcall(L, 2, 1, 0) != 0) { const char *error = lua_tostring(L, -1); log_error("paint function failed: %s\n", error); diff --git a/src/bind_message.c b/src/bind_message.c index 75ff5821b..bbbd2bc0b 100644 --- a/src/bind_message.c +++ b/src/bind_message.c @@ -214,7 +214,7 @@ static int tolua_msg_set_string(lua_State * L) const char *param = tolua_tostring(L, 2, 0); const char *value = tolua_tostring(L, 3, 0); int result = msg_set_string(lmsg, param, value); - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -224,7 +224,7 @@ static int tolua_msg_set_int(lua_State * L) const char *param = tolua_tostring(L, 2, 0); int value = (int)tolua_tonumber(L, 3, 0); int result = msg_set_int(lmsg, param, value); - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -234,7 +234,7 @@ static int tolua_msg_set_resource(lua_State * L) const char *param = tolua_tostring(L, 2, 0); const char *value = tolua_tostring(L, 3, 0); int result = msg_set_resource(lmsg, param, value); - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -244,7 +244,7 @@ static int tolua_msg_set_unit(lua_State * L) const char *param = tolua_tostring(L, 2, 0); unit *value = (unit *)tolua_tousertype(L, 3, 0); int result = msg_set_unit(lmsg, param, value); - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -254,7 +254,7 @@ static int tolua_msg_set_region(lua_State * L) const char *param = tolua_tostring(L, 2, 0); region *value = (region *)tolua_tousertype(L, 3, 0); int result = msg_set_region(lmsg, param, value); - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -270,7 +270,7 @@ static int tolua_msg_set(lua_State * L) else if (tolua_isusertype(L, 3, TOLUA_CAST "unit", 0, &err)) { return tolua_msg_set_unit(L); } - tolua_pushnumber(L, (lua_Number)-1); + lua_pushinteger(L, -1); return 1; } @@ -279,7 +279,7 @@ static int tolua_msg_send_region(lua_State * L) lua_message *lmsg = (lua_message *)tolua_tousertype(L, 1, 0); region *r = (region *)tolua_tousertype(L, 2, 0); int result = msg_send_region(lmsg, r); - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -293,7 +293,7 @@ static int tolua_msg_report_action(lua_State * L) lmsg->msg = msg_create(lmsg->mtype, lmsg->args); } result = report_action(r, u, lmsg->msg, flags); - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -303,7 +303,7 @@ static int tolua_msg_send_faction(lua_State * L) faction *f = (faction *)tolua_tousertype(L, 2, 0); if (f && lmsg) { int result = msg_send_faction(lmsg, f); - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } return 0; diff --git a/src/bind_monsters.c b/src/bind_monsters.c index 8897da0d1..a106ec638 100644 --- a/src/bind_monsters.c +++ b/src/bind_monsters.c @@ -21,7 +21,7 @@ static int tolua_levitate_ship(lua_State * L) float power = (float)tolua_tonumber(L, 3, 0); int duration = (int)tolua_tonumber(L, 4, 0); int cno = levitate_ship(sh, mage, power, duration); - tolua_pushnumber(L, (lua_Number)cno); + lua_pushinteger(L, cno); return 1; } diff --git a/src/bind_region.c b/src/bind_region.c index 792f15ac0..1b0157718 100644 --- a/src/bind_region.c +++ b/src/bind_region.c @@ -62,7 +62,7 @@ int tolua_regionlist_next(lua_State * L) static int tolua_region_get_id(lua_State * L) { region *self = (region *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)self->uid); + lua_pushinteger(L, self->uid); return 1; } @@ -85,14 +85,14 @@ static int tolua_region_set_blocked(lua_State * L) static int tolua_region_get_x(lua_State * L) { region *self = (region *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)self->x); + lua_pushinteger(L, self->x); return 1; } static int tolua_region_get_y(lua_State * L) { region *self = (region *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)self->y); + lua_pushinteger(L, self->y); return 1; } @@ -199,7 +199,7 @@ static int tolua_region_set_name(lua_State * L) static int tolua_region_get_morale(lua_State * L) { region *r = (region *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, region_get_morale(r)); + lua_pushinteger(L, region_get_morale(r)); return 1; } @@ -323,7 +323,7 @@ static int tolua_region_get_resourcelevel(lua_State * L) const rawmaterial *rm; for (rm = r->resources; rm; rm = rm->next) { if (rm->type->rtype == rtype) { - tolua_pushnumber(L, (lua_Number)rm->level); + lua_pushinteger(L, rm->level); return 1; } } @@ -389,7 +389,7 @@ static int tolua_region_get_resource(lua_State * L) } } - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -613,7 +613,7 @@ static int tolua_plane_set_name(lua_State * L) static int tolua_plane_get_id(lua_State * L) { plane *self = (plane *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)self->id); + lua_pushinteger(L, self->id); return 1; } @@ -623,8 +623,8 @@ static int tolua_plane_normalize(lua_State * L) int x = (int)tolua_tonumber(L, 2, 0); int y = (int)tolua_tonumber(L, 3, 0); pnormalize(&x, &y, self); - tolua_pushnumber(L, (lua_Number)x); - tolua_pushnumber(L, (lua_Number)y); + lua_pushinteger(L, x); + lua_pushinteger(L, y); return 2; } diff --git a/src/bind_ship.c b/src/bind_ship.c index 7dd1b02f6..595be35dd 100644 --- a/src/bind_ship.c +++ b/src/bind_ship.c @@ -45,7 +45,7 @@ int tolua_shiplist_next(lua_State * L) static int tolua_ship_get_id(lua_State * L) { ship *self = (ship *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)self->no); + lua_pushinteger(L, self->no); return 1; } @@ -152,7 +152,7 @@ tolua_ship_tostring(lua_State * L) static int tolua_ship_get_flags(lua_State * L) { ship *self = (ship *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)self->flags); + lua_pushinteger(L, self->flags); return 1; } @@ -179,7 +179,7 @@ static int tolua_ship_get_coast(lua_State * L) { ship *self = (ship *)tolua_tousertype(L, 1, 0); if (self->coast) { - tolua_pushnumber(L, self->coast); + lua_pushinteger(L, self->coast); return 1; } return 0; diff --git a/src/bind_sqlite.c b/src/bind_sqlite.c index e2c0e69e3..e8c9b7565 100644 --- a/src/bind_sqlite.c +++ b/src/bind_sqlite.c @@ -44,7 +44,7 @@ static int tolua_db_execute(lua_State * L) int res = sqlite3_exec(db, sql, 0, 0, 0); - tolua_pushnumber(L, (LUA_NUMBER)res); + lua_pushinteger(L, res); return 1; } diff --git a/src/bind_storage.c b/src/bind_storage.c index d0fea8244..acdf1e046 100644 --- a/src/bind_storage.c +++ b/src/bind_storage.c @@ -77,7 +77,7 @@ static int tolua_storage_read_float(lua_State * L) gamedata *data = (gamedata *)tolua_tousertype(L, 1, 0); float num; READ_FLT(data->store, &num); - tolua_pushnumber(L, (lua_Number)num); + lua_pushnumber(L, num); return 1; } @@ -86,7 +86,7 @@ static int tolua_storage_read_int(lua_State * L) gamedata *data = (gamedata *)tolua_tousertype(L, 1, 0); int num; READ_INT(data->store, &num); - tolua_pushnumber(L, (lua_Number)num); + lua_pushinteger(L, num); return 1; } diff --git a/src/bind_unit.c b/src/bind_unit.c index 4f262114c..200c53b9b 100755 --- a/src/bind_unit.c +++ b/src/bind_unit.c @@ -160,7 +160,7 @@ static int tolua_unit_set_group(lua_State * L) { unit *self = (unit *)tolua_tousertype(L, 1, 0); int result = join_group(self, tolua_tostring(L, 2, 0)); - tolua_pushnumber(L, result); + lua_pushinteger(L, result); return 1; } diff --git a/src/bindings.c b/src/bindings.c index 098499a23..849678f25 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -123,7 +123,7 @@ static int tolua_quicklist_iter(lua_State * L) void *data = ql_get(ql, index); tolua_pushusertype(L, data, TOLUA_CAST type); ql_advance(qlp, &index, 1); - tolua_pushnumber(L, index); + lua_pushinteger(L, index); lua_replace(L, lua_upvalueindex(2)); return 1; } @@ -282,14 +282,14 @@ static int tolua_set_turn(lua_State * L) static int tolua_get_turn(lua_State * L) { - tolua_pushnumber(L, (lua_Number)turn); + lua_pushinteger(L, turn); return 1; } static int tolua_atoi36(lua_State * L) { const char *s = tolua_tostring(L, 1, 0); - tolua_pushnumber(L, (lua_Number)atoi36(s)); + lua_pushinteger(L, atoi36(s)); return 1; } @@ -303,7 +303,7 @@ static int tolua_itoa36(lua_State * L) static int tolua_dice_rand(lua_State * L) { const char *s = tolua_tostring(L, 1, 0); - tolua_pushnumber(L, dice_rand(s)); + lua_pushinteger(L, dice_rand(s)); return 1; } @@ -320,7 +320,7 @@ static int tolua_addequipment(lua_State * L) result = 0; } } - lua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -426,7 +426,7 @@ static int tolua_get_nmrs(lua_State * L) } result = nmrs[n]; } - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -451,7 +451,7 @@ static int tolua_equipment_setitem(lua_State * L) result = 0; } } - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -465,7 +465,7 @@ static int tolua_spawn_braineaters(lua_State * L) static int tolua_init_reports(lua_State * L) { int result = init_reports(); - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -475,7 +475,7 @@ static int tolua_write_report(lua_State * L) if (f) { time_t ltime = time(0); int result = write_reports(f, ltime); - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); } else { tolua_pushstring(L, "function expects a faction, got nil"); @@ -488,7 +488,7 @@ static int tolua_write_reports(lua_State * L) int result; init_reports(); result = reports(); - tolua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -568,7 +568,7 @@ static int tolua_write_map(lua_State * L) static int tolua_read_turn(lua_State * L) { int cturn = current_turn(); - tolua_pushnumber(L, (lua_Number)cturn); + lua_pushinteger(L, cturn); return 1; } @@ -661,7 +661,7 @@ static int tolua_get_alliance_factions(lua_State * L) static int tolua_get_alliance_id(lua_State * L) { alliance *self = (alliance *)tolua_tousertype(L, 1, 0); - tolua_pushnumber(L, (lua_Number)self->id); + lua_pushinteger(L, self->id); return 1; } @@ -1069,7 +1069,7 @@ static void parse_inifile(lua_State * L, dictionary * d, const char *section) tolua_pushstring(L, str_value); } else { - tolua_pushnumber(L, num_value); + lua_pushnumber(L, num_value); } lua_rawset(L, -3); } diff --git a/src/helpers.c b/src/helpers.c index 4690023e9..29038afb3 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -58,7 +58,7 @@ lua_giveitem(unit * s, unit * d, const item_type * itype, int n, struct order *o tolua_pushusertype(L, s, TOLUA_CAST "unit"); tolua_pushusertype(L, d, TOLUA_CAST "unit"); tolua_pushstring(L, iname); - tolua_pushnumber(L, (lua_Number)n); + lua_pushinteger(L, n); if (lua_pcall(L, 4, 1, 0) != 0) { const char *error = lua_tostring(L, -1); @@ -121,7 +121,7 @@ produce_resource(region * r, const resource_type * rtype, int norders) lua_getglobal(L, fname); if (lua_isfunction(L, -1)) { tolua_pushusertype(L, (void *)r, TOLUA_CAST "region"); - tolua_pushnumber(L, (lua_Number)norders); + lua_pushinteger(L, norders); if (lua_pcall(L, 2, 0, 0) != 0) { const char *error = lua_tostring(L, -1); @@ -177,8 +177,8 @@ static int lua_callspell(castorder * co) int nparam = 4; tolua_pushusertype(L, r, TOLUA_CAST "region"); tolua_pushusertype(L, caster, TOLUA_CAST "unit"); - tolua_pushnumber(L, (lua_Number)co->level); - tolua_pushnumber(L, (lua_Number)co->force); + lua_pushinteger(L, co->level); + lua_pushnumber(L, co->force); if (co->sp->parameter && co->par->length) { const char *synp = co->sp->parameter; int i = 0; @@ -267,7 +267,7 @@ lua_changeresource(unit * u, const struct resource_type *rtype, int delta) lua_getglobal(L, fname); if (lua_isfunction(L, -1)) { tolua_pushusertype(L, u, TOLUA_CAST "unit"); - tolua_pushnumber(L, (lua_Number)delta); + lua_pushinteger(L, delta); if (lua_pcall(L, 2, 1, 0) != 0) { const char *error = lua_tostring(L, -1); @@ -363,7 +363,7 @@ lua_wage(const region * r, const faction * f, const race * rc, int in_turn) tolua_pushusertype(L, (void *)r, TOLUA_CAST "region"); tolua_pushusertype(L, (void *)f, TOLUA_CAST "faction"); tolua_pushstring(L, rc ? rc->_name : 0); - tolua_pushnumber(L, (lua_Number)in_turn); + lua_pushinteger(L, in_turn); if (lua_pcall(L, 3, 1, 0) != 0) { const char *error = lua_tostring(L, -1); @@ -416,7 +416,7 @@ static double lua_building_taxes(building * b, int level) lua_getglobal(L, fname); if (lua_isfunction(L, -1)) { tolua_pushusertype(L, (void *)b, TOLUA_CAST "building"); - tolua_pushnumber(L, level); + lua_pushinteger(L, level); if (lua_pcall(L, 2, 1, 0) != 0) { const char *error = lua_tostring(L, -1); @@ -508,7 +508,7 @@ struct order *ord) lua_getglobal(L, fname); if (lua_isfunction(L, -1)) { tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); - tolua_pushnumber(L, (lua_Number)amount); + lua_pushinteger(L, amount); if (lua_pcall(L, 2, 1, 0) != 0) { const char *error = lua_tostring(L, -1); From 84f8a9f74618c7d85f77842c02ffdb413a5792d2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 8 Jun 2015 21:15:07 +0200 Subject: [PATCH 2/3] calculate simple default scores for items that do not have one defined in XML. --- src/kernel/xmlreader.c | 11 ++++++++--- src/modules/score.c | 17 +++++++++++++++++ src/modules/score.h | 7 +++++-- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 7179238ab..b4b1da708 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -31,6 +31,10 @@ without prior permission by the authors of Eressea. #include "vortex.h" +#if SCORE_MODULE +#include +#endif + /* util includes */ #include #include @@ -766,9 +770,6 @@ static item_type *xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype) itype->weight = xml_ivalue(node, "weight", 0); itype->capacity = xml_ivalue(node, "capacity", 0); itype->flags |= flags; -#if SCORE_MODULE - itype->score = xml_ivalue(node, "score", 0); -#endif /* reading item/construction */ xpath->node = node; @@ -855,6 +856,10 @@ static item_type *xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype) } xmlFree(propValue); } +#if SCORE_MODULE + itype->score = xml_ivalue(node, "score", 0); + if (!itype->score) itype->score = default_score(itype); +#endif xmlXPathFreeObject(result); return itype; diff --git a/src/modules/score.c b/src/modules/score.c index bf3e472e1..26788199c 100644 --- a/src/modules/score.c +++ b/src/modules/score.c @@ -24,6 +24,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* kernel includes */ #include #include +#include #include #include #include @@ -214,4 +215,20 @@ void score(void) } } +int default_score(const item_type *itype) { + int result = 0; + if (itype->construction) { + requirement *req = itype->construction->materials; + while (req->number) { + int score = req->rtype->itype ? req->rtype->itype->score : 10; + result += score * req->number * 2; + ++req; + } + } + else { + result = 10; + } + return result; +} + #endif diff --git a/src/modules/score.h b/src/modules/score.h index 0cbe6b749..7ffdf64e5 100644 --- a/src/modules/score.h +++ b/src/modules/score.h @@ -26,8 +26,11 @@ extern "C" { #error "must define SCORE_MODULE to use this module" #endif - extern void score(void); - extern int average_score_of_age(int age, int a); + struct item_type; + + void score(void); + int average_score_of_age(int age, int a); + int default_score(const struct item_type *itype); #ifdef __cplusplus } From 4e33e59d646647ab6ac87b4442ad70f27c271ab8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 8 Jun 2015 21:19:17 +0200 Subject: [PATCH 3/3] more lua_pushinteger conversion for lua 5.3 --- src/bind_dict.c | 2 +- src/bind_faction.c | 2 +- src/bind_region.c | 8 ++++---- src/bindings.c | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/bind_dict.c b/src/bind_dict.c index 28bcc5d81..32d3c498d 100644 --- a/src/bind_dict.c +++ b/src/bind_dict.c @@ -47,7 +47,7 @@ static int tolua_dict_get(lua_State * L) lua_pushnil(L); break; case TINTEGER: - lua_pushnumber(L, (lua_Number)val.i); + lua_pushinteger(L, val.i); break; case TREAL: lua_pushnumber(L, (lua_Number)val.f); diff --git a/src/bind_faction.c b/src/bind_faction.c index 23b450618..585cdcf35 100644 --- a/src/bind_faction.c +++ b/src/bind_faction.c @@ -77,7 +77,7 @@ int tolua_faction_add_item(lua_State * L) result = i ? i->number : 0; } /* if (itype!=NULL) */ } - lua_pushnumber(L, result); + lua_pushinteger(L, result); return 1; } diff --git a/src/bind_region.c b/src/bind_region.c index 1b0157718..f726bc8a6 100644 --- a/src/bind_region.c +++ b/src/bind_region.c @@ -524,7 +524,7 @@ static int tolua_region_get_age(lua_State * L) region *self = (region *)tolua_tousertype(L, 1, 0); if (self) { - lua_pushnumber(L, self->age); + lua_pushinteger(L, self->age); return 1; } return 0; @@ -638,8 +638,8 @@ static int tolua_plane_tostring(lua_State * L) static int tolua_plane_get_size(lua_State * L) { plane *pl = (plane *)tolua_tousertype(L, 1, 0); - lua_pushnumber(L, plane_width(pl)); - lua_pushnumber(L, plane_height(pl)); + lua_pushinteger(L, plane_width(pl)); + lua_pushinteger(L, plane_height(pl)); return 2; } @@ -657,7 +657,7 @@ static int tolua_distance(lua_State * L) pnormalize(&x1, &y1, pl); pnormalize(&x2, &y2, pl); result = koor_distance(x1, y1, x2, y2); - lua_pushnumber(L, result); + lua_pushinteger(L, result); return 1; } diff --git a/src/bindings.c b/src/bindings.c index 849678f25..6e61dc186 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -139,7 +139,7 @@ int tolua_quicklist_push(struct lua_State *L, const char *list_type, *qlist_ptr = list; luaL_getmetatable(L, list_type); lua_setmetatable(L, -2); - lua_pushnumber(L, 0); + lua_pushinteger(L, 0); lua_pushstring(L, elem_type); lua_pushcclosure(L, tolua_quicklist_iter, 3); /* OBS: this closure has multiple upvalues (list, index, type_name) */ } @@ -219,7 +219,7 @@ static int tolua_setkey(lua_State * L) static int tolua_rng_int(lua_State * L) { - lua_pushnumber(L, (lua_Number)rng_int()); + lua_pushinteger(L, rng_int()); return 1; } @@ -227,7 +227,7 @@ static int tolua_read_orders(lua_State * L) { const char *filename = tolua_tostring(L, 1, 0); int result = readorders(filename); - lua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 1; } @@ -534,7 +534,7 @@ static int tolua_process_orders(lua_State * L) static int tolua_write_passwords(lua_State * L) { int result = writepasswd(); - lua_pushnumber(L, (lua_Number)result); + lua_pushinteger(L, result); return 0; } @@ -982,7 +982,7 @@ static int tolua_get_spell_school(lua_State * L) static int tolua_get_spell_level(lua_State * L) { spell *self = (spell *) tolua_tousertype(L, 1, 0); - lua_pushnumber(L, self->level); + lua_pushinteger(L, self->level); return 1; } #endif