diff --git a/res/core/messages.xml b/res/core/messages.xml index 6dbb8974a..084ffd20a 100644 --- a/res/core/messages.xml +++ b/res/core/messages.xml @@ -841,11 +841,11 @@ - - + + - "Deine Partei hat $int($score) Punkte. Der Durchschnitt für Parteien ähnlichen Alters ist $int($average) Punkte." - "Your faction has a score of $int($score). The average score for similar factions is $int($average)." + "Deine Partei hat ${score} Punkte. Der Durchschnitt für Parteien ähnlichen Alters ist ${average} Punkte." + "Your faction has a score of ${score}. The average score for similar factions is ${average}." diff --git a/src/bind_faction.c b/src/bind_faction.c index 585cdcf35..8cfc21718 100644 --- a/src/bind_faction.c +++ b/src/bind_faction.c @@ -98,7 +98,7 @@ static int tolua_faction_get_heroes(lua_State * L) static int tolua_faction_get_score(lua_State * L) { faction *self = (faction *)tolua_tousertype(L, 1, 0); - lua_pushinteger(L, self->score); + lua_pushnumber(L, (lua_Number)self->score); return 1; } diff --git a/src/creport.c b/src/creport.c index ec81c26c9..1678d5d47 100644 --- a/src/creport.c +++ b/src/creport.c @@ -753,6 +753,7 @@ void cr_output_unit(stream *out, const region * r, const faction * f, const char *prefix; assert(u && u->number); + assert(u->region == r); // TODO: if this holds true, then why did we pass in r? if (fval(u_race(u), RCF_INVISIBLE)) return; @@ -942,13 +943,14 @@ void cr_output_unit(stream *out, const region * r, const faction * f, pr = 0; for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) { if (sv->level > 0) { - int esk = eff_skill(u, sv, r); + skill_t sk = sv->id; + int esk = effskill(u, sk, 0); if (!pr) { pr = 1; stream_printf(out, "TALENTE\n"); } stream_printf(out, "%d %d;%s\n", u->number * level_days(sv->level), esk, - translate(mkname("skill", skillnames[sv->id]), skillname(sv->id, + translate(mkname("skill", skillnames[sk]), skillname(sk, f->locale))); } } @@ -1506,9 +1508,6 @@ report_computer(const char *filename, report_context * ctx, const char *charset) const char *mailto = LOC(f->locale, "mailto"); const attrib *a; seen_region *sr = NULL; -#if SCORE_MODULE - int score = 0, avgscore = 0; -#endif FILE *F = fopen(filename, "wt"); if (era < 0) { @@ -1555,14 +1554,13 @@ report_computer(const char *filename, report_context * ctx, const char *charset) } fprintf(F, "%d;age\n", f->age); fprintf(F, "%d;Optionen\n", f->options); -#if SCORE_MODULE if (f->options & want(O_SCORE) && f->age > DISPLAYSCORE) { - score = f->score; - avgscore = average_score_of_age(f->age, f->age / 24 + 1); + char score[32]; + write_score(score, sizeof(score), f->score); + fprintf(F, "%s;Punkte\n", score); + write_score(score, sizeof(score), average_score_of_age(f->age, f->age / 24 + 1)); + fprintf(F, "%s;Punktedurchschnitt\n", score); } - fprintf(F, "%d;Punkte\n", score); - fprintf(F, "%d;Punktedurchschnitt\n", avgscore); -#endif { const char *zRace = rc_name_s(f->race, NAME_PLURAL); fprintf(F, "\"%s\";Typ\n", translate(zRace, LOC(f->locale, zRace))); diff --git a/src/json.c b/src/json.c index 1fb2adb27..007c3aeda 100644 --- a/src/json.c +++ b/src/json.c @@ -94,7 +94,7 @@ int json_export(stream * out, int flags) { cJSON_AddItemToObject(json, itoa36(f->no), data = cJSON_CreateObject()); cJSON_AddStringToObject(data, "name", f->name); cJSON_AddStringToObject(data, "email", f->email); - cJSON_AddNumberToObject(data, "score", f->score); + cJSON_AddNumberToObject(data, "score", (double)f->score); } } if (flags) { diff --git a/src/kernel/faction.h b/src/kernel/faction.h index 614b50d75..2dbce4c86 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -21,7 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "skill.h" #include "types.h" - +#include #ifdef __cplusplus extern "C" { #endif @@ -84,9 +84,7 @@ extern "C" { struct group *groups; int nregions; int money; -#if SCORE_MODULE - int score; -#endif + score_t score; struct alliance *alliance; int alliance_joindate; /* the turn on which the faction joined its current alliance (or left the last one) */ #ifdef VICTORY_DELAY diff --git a/src/kernel/item.h b/src/kernel/item.h index 32ca01342..449445a7d 100644 --- a/src/kernel/item.h +++ b/src/kernel/item.h @@ -143,9 +143,7 @@ extern "C" { const struct item_type * itype, int amount, struct order * ord); int(*give) (struct unit * src, struct unit * dest, const struct item_type * itm, int number, struct order * ord); -#if SCORE_MODULE int score; -#endif } item_type; const item_type *finditemtype(const char *name, const struct locale *lang); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index da1fed792..eb122e116 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -31,9 +31,7 @@ without prior permission by the authors of Eressea. #include "vortex.h" -#if SCORE_MODULE #include -#endif /* util includes */ #include @@ -857,10 +855,8 @@ 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/arena.c b/src/modules/arena.c index fea4743de..73b57d416 100644 --- a/src/modules/arena.c +++ b/src/modules/arena.c @@ -122,12 +122,19 @@ enter_arena(unit * u, const item_type * itype, int amount, order * ord) skill_t sk; region *r = u->region; unit *u2; - int fee = u->faction->score / 5; + int fee = 2000; unused_arg(ord); unused_arg(amount); unused_arg(itype); - if (fee > 2000) - fee = 2000; + if (u->faction->score > fee * 5) { + score_t score = u->faction->score / 5; + if (score < INT_MAX) { + fee = (int)score; + } + else { + fee = INT_MAX; + } + } if (getplane(r) == arena) return -1; if (u->number != 1 && enter_fail(u)) diff --git a/src/modules/score.c b/src/modules/score.c index 26788199c..55a26b72c 100644 --- a/src/modules/score.c +++ b/src/modules/score.c @@ -18,7 +18,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#if SCORE_MODULE #include "score.h" /* kernel includes */ @@ -35,16 +34,17 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* util includes */ #include +#include #include /* libc includes */ #include #include -int average_score_of_age(int age, int a) +score_t average_score_of_age(int age, int a) { faction *f; - int sum = 0, count = 0; + score_t sum = 0, count = 0; for (f = factions; f; f = f->next) { if (!fval(f, FFL_NPC) && f->age <= age + a @@ -65,7 +65,7 @@ void score(void) FILE *scoreFP; region *r; faction *fc; - int allscores = 0; + score_t allscores = 0; char path[MAX_PATH]; for (fc = factions; fc; fc = fc->next) @@ -124,18 +124,18 @@ void score(void) skill *sv = u->skills + i; switch (sv->id) { case SK_MAGIC: - f->score += (int)(u->number * pow(sv->level, 4)); + f->score += (score_t)(u->number * pow(sv->level, 4)); break; case SK_TACTICS: - f->score += (int)(u->number * pow(sv->level, 3)); + f->score += (score_t)(u->number * pow(sv->level, 3)); break; case SK_SPY: case SK_ALCHEMY: case SK_HERBALISM: - f->score += (int)(u->number * pow(sv->level, 2.5)); + f->score += (score_t)(u->number * pow(sv->level, 2.5)); break; default: - f->score += (int)(u->number * pow(sv->level, 2.5) / 10); + f->score += (score_t)(u->number * pow(sv->level, 2.5) / 10); break; } } @@ -159,12 +159,16 @@ void score(void) faction *f; fwrite(utf8_bom, 1, 3, scoreFP); for (f = factions; f; f = f->next) - if (f->num_total != 0) { - fprintf(scoreFP, "%8d (%8d/%4.2f%%/%5.2f) %30.30s (%3.3s) %5s (%3d)\n", - f->score, f->score - average_score_of_age(f->age, f->age / 24 + 1), - ((double)f->score / allscores) * 100, - (double)f->score / f->num_total, - f->name, LOC(default_locale, rc_name_s(f->race, NAME_SINGULAR)), factionid(f), + if (!fval(f, FFL_NPC) && f->num_total != 0) { + char score[32]; + write_score(score, sizeof(score), f->score); + fprintf(scoreFP, "%s ", score); + write_score(score, sizeof(score), average_score_of_age(f->age, f->age / 24 + 1)); + fprintf(scoreFP, "(%s) ", score); + fprintf(scoreFP, "%30.30s (%3.3s) %5s (%3d)\n", + f->name, + rc_name_s(f->race, NAME_SINGULAR), + factionid(f), f->age); } fclose(scoreFP); @@ -182,8 +186,8 @@ void score(void) fprintf(scoreFP, "# alliance:factions:persons:score\n"); for (a = alliances; a; a = a->next) { - int alliance_score = 0, alliance_number = 0, alliance_factions = 0; - int grails = 0; + score_t alliance_score = 0; + int alliance_number = 0, alliance_factions = 0, grails = 0; faction *f; for (f = factions; f; f = f->next) { @@ -231,4 +235,6 @@ int default_score(const item_type *itype) { return result; } -#endif +void write_score(char *buffer, size_t size, score_t score) { + slprintf(buffer, size, "%lld", score); +} diff --git a/src/modules/score.h b/src/modules/score.h index 7ffdf64e5..b0f1b2a91 100644 --- a/src/modules/score.h +++ b/src/modules/score.h @@ -20,17 +20,15 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define SCORE_H #ifdef __cplusplus extern "C" { -#endif - -#if SCORE_MODULE == 0 -#error "must define SCORE_MODULE to use this module" #endif struct item_type; + typedef long long score_t; void score(void); - int average_score_of_age(int age, int a); + score_t average_score_of_age(int age, int a); int default_score(const struct item_type *itype); + void write_score(char *buffer, size_t size, score_t score); #ifdef __cplusplus } diff --git a/src/report.c b/src/report.c index f62e3d728..039dc8353 100644 --- a/src/report.c +++ b/src/report.c @@ -2117,13 +2117,13 @@ const char *charset) } } newline(out); -#if SCORE_MODULE if (f->options & want(O_SCORE) && f->age > DISPLAYSCORE) { - RENDER(f, buf, sizeof(buf), ("nr_score", "score average", f->score, - average_score_of_age(f->age, f->age / 24 + 1))); + char score[32], avg[32]; + write_score(score, sizeof(score), f->score); + write_score(avg, sizeof(avg), average_score_of_age(f->age, f->age / 24 + 1)); + RENDER(f, buf, sizeof(buf), ("nr_score", "score average", score, avg)); centre(out, buf, true); } -#endif #ifdef COUNT_AGAIN no_units = 0; no_people = 0; diff --git a/src/settings.h b/src/settings.h index d31dbccbf..7f97eb8a8 100644 --- a/src/settings.h +++ b/src/settings.h @@ -35,7 +35,6 @@ * configuration variables (XML), script extensions (lua), * or both. We don't want separate binaries for different games */ -#define SCORE_MODULE 1 #define MUSEUM_MODULE 1 #define ARENA_MODULE 1 #define CHANGED_CROSSBOWS 0 /* use the WTF_ARMORPIERCING flag */