Merge pull request #285 from ennorehling/feature/bug-2136-large-scores

Bug 2136: large score values
This commit is contained in:
Enno Rehling 2015-09-06 19:14:37 +02:00
commit e2b78cd8d8
13 changed files with 61 additions and 60 deletions

View File

@ -841,11 +841,11 @@
</message> </message>
<message name="nr_score" section="nr"> <message name="nr_score" section="nr">
<type> <type>
<arg name="score" type="int"/> <arg name="score" type="string"/>
<arg name="average" type="int"/> <arg name="average" type="string"/>
</type> </type>
<text locale="de">"Deine Partei hat $int($score) Punkte. Der Durchschnitt für Parteien ähnlichen Alters ist $int($average) Punkte."</text> <text locale="de">"Deine Partei hat ${score} Punkte. Der Durchschnitt für Parteien ähnlichen Alters ist ${average} Punkte."</text>
<text locale="en">"Your faction has a score of $int($score). The average score for similar factions is $int($average)."</text> <text locale="en">"Your faction has a score of ${score}. The average score for similar factions is ${average}."</text>
</message> </message>
<message name="nr_header_date" section="nr"> <message name="nr_header_date" section="nr">
<type> <type>

View File

@ -98,7 +98,7 @@ static int tolua_faction_get_heroes(lua_State * L)
static int tolua_faction_get_score(lua_State * L) static int tolua_faction_get_score(lua_State * L)
{ {
faction *self = (faction *)tolua_tousertype(L, 1, 0); faction *self = (faction *)tolua_tousertype(L, 1, 0);
lua_pushinteger(L, self->score); lua_pushnumber(L, (lua_Number)self->score);
return 1; return 1;
} }

View File

@ -1,3 +1,3 @@
#define VERSION_MAJOR 3 #define VERSION_MAJOR 3
#define VERSION_MINOR 6 #define VERSION_MINOR 7
#define VERSION_BUILD 2 #define VERSION_BUILD 0

View File

@ -753,6 +753,7 @@ void cr_output_unit(stream *out, const region * r, const faction * f,
const char *prefix; const char *prefix;
assert(u && u->number); 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)) if (fval(u_race(u), RCF_INVISIBLE))
return; return;
@ -942,13 +943,14 @@ void cr_output_unit(stream *out, const region * r, const faction * f,
pr = 0; pr = 0;
for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) { for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
if (sv->level > 0) { if (sv->level > 0) {
int esk = eff_skill(u, sv, r); skill_t sk = sv->id;
int esk = effskill(u, sk, 0);
if (!pr) { if (!pr) {
pr = 1; pr = 1;
stream_printf(out, "TALENTE\n"); stream_printf(out, "TALENTE\n");
} }
stream_printf(out, "%d %d;%s\n", u->number * level_days(sv->level), esk, 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))); 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 char *mailto = LOC(f->locale, "mailto");
const attrib *a; const attrib *a;
seen_region *sr = NULL; seen_region *sr = NULL;
#if SCORE_MODULE
int score = 0, avgscore = 0;
#endif
FILE *F = fopen(filename, "wt"); FILE *F = fopen(filename, "wt");
if (era < 0) { 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;age\n", f->age);
fprintf(F, "%d;Optionen\n", f->options); fprintf(F, "%d;Optionen\n", f->options);
#if SCORE_MODULE
if (f->options & want(O_SCORE) && f->age > DISPLAYSCORE) { if (f->options & want(O_SCORE) && f->age > DISPLAYSCORE) {
score = f->score; char score[32];
avgscore = average_score_of_age(f->age, f->age / 24 + 1); 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); const char *zRace = rc_name_s(f->race, NAME_PLURAL);
fprintf(F, "\"%s\";Typ\n", translate(zRace, LOC(f->locale, zRace))); fprintf(F, "\"%s\";Typ\n", translate(zRace, LOC(f->locale, zRace)));

View File

@ -94,7 +94,7 @@ int json_export(stream * out, int flags) {
cJSON_AddItemToObject(json, itoa36(f->no), data = cJSON_CreateObject()); cJSON_AddItemToObject(json, itoa36(f->no), data = cJSON_CreateObject());
cJSON_AddStringToObject(data, "name", f->name); cJSON_AddStringToObject(data, "name", f->name);
cJSON_AddStringToObject(data, "email", f->email); cJSON_AddStringToObject(data, "email", f->email);
cJSON_AddNumberToObject(data, "score", f->score); cJSON_AddNumberToObject(data, "score", (double)f->score);
} }
} }
if (flags) { if (flags) {

View File

@ -21,7 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "skill.h" #include "skill.h"
#include "types.h" #include "types.h"
#include <modules/score.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -84,9 +84,7 @@ extern "C" {
struct group *groups; struct group *groups;
int nregions; int nregions;
int money; int money;
#if SCORE_MODULE score_t score;
int score;
#endif
struct alliance *alliance; struct alliance *alliance;
int alliance_joindate; /* the turn on which the faction joined its current alliance (or left the last one) */ int alliance_joindate; /* the turn on which the faction joined its current alliance (or left the last one) */
#ifdef VICTORY_DELAY #ifdef VICTORY_DELAY

View File

@ -143,9 +143,7 @@ extern "C" {
const struct item_type * itype, int amount, struct order * ord); const struct item_type * itype, int amount, struct order * ord);
int(*give) (struct unit * src, struct unit * dest, int(*give) (struct unit * src, struct unit * dest,
const struct item_type * itm, int number, struct order * ord); const struct item_type * itm, int number, struct order * ord);
#if SCORE_MODULE
int score; int score;
#endif
} item_type; } item_type;
const item_type *finditemtype(const char *name, const struct locale *lang); const item_type *finditemtype(const char *name, const struct locale *lang);

View File

@ -31,9 +31,7 @@ without prior permission by the authors of Eressea.
#include "vortex.h" #include "vortex.h"
#if SCORE_MODULE
#include <modules/score.h> #include <modules/score.h>
#endif
/* util includes */ /* util includes */
#include <util/attrib.h> #include <util/attrib.h>
@ -857,10 +855,8 @@ static item_type *xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype)
} }
xmlFree(propValue); xmlFree(propValue);
} }
#if SCORE_MODULE
itype->score = xml_ivalue(node, "score", 0); itype->score = xml_ivalue(node, "score", 0);
if (!itype->score) itype->score = default_score(itype); if (!itype->score) itype->score = default_score(itype);
#endif
xmlXPathFreeObject(result); xmlXPathFreeObject(result);
return itype; return itype;

View File

@ -61,6 +61,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <limits.h>
/* exports: */ /* exports: */
plane *arena = NULL; plane *arena = NULL;
@ -122,12 +123,19 @@ enter_arena(unit * u, const item_type * itype, int amount, order * ord)
skill_t sk; skill_t sk;
region *r = u->region; region *r = u->region;
unit *u2; unit *u2;
int fee = u->faction->score / 5; int fee = 2000;
unused_arg(ord); unused_arg(ord);
unused_arg(amount); unused_arg(amount);
unused_arg(itype); unused_arg(itype);
if (fee > 2000) if (u->faction->score > fee * 5) {
fee = 2000; score_t score = u->faction->score / 5;
if (score < INT_MAX) {
fee = (int)score;
}
else {
fee = INT_MAX;
}
}
if (getplane(r) == arena) if (getplane(r) == arena)
return -1; return -1;
if (u->number != 1 && enter_fail(u)) if (u->number != 1 && enter_fail(u))

View File

@ -18,7 +18,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <platform.h> #include <platform.h>
#include <kernel/config.h> #include <kernel/config.h>
#if SCORE_MODULE
#include "score.h" #include "score.h"
/* kernel includes */ /* kernel includes */
@ -35,16 +34,17 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* util includes */ /* util includes */
#include <util/base36.h> #include <util/base36.h>
#include <util/bsdstring.h>
#include <util/language.h> #include <util/language.h>
/* libc includes */ /* libc includes */
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
int average_score_of_age(int age, int a) score_t average_score_of_age(int age, int a)
{ {
faction *f; faction *f;
int sum = 0, count = 0; score_t sum = 0, count = 0;
for (f = factions; f; f = f->next) { for (f = factions; f; f = f->next) {
if (!fval(f, FFL_NPC) && f->age <= age + a if (!fval(f, FFL_NPC) && f->age <= age + a
@ -65,7 +65,7 @@ void score(void)
FILE *scoreFP; FILE *scoreFP;
region *r; region *r;
faction *fc; faction *fc;
int allscores = 0; score_t allscores = 0;
char path[MAX_PATH]; char path[MAX_PATH];
for (fc = factions; fc; fc = fc->next) for (fc = factions; fc; fc = fc->next)
@ -124,18 +124,18 @@ void score(void)
skill *sv = u->skills + i; skill *sv = u->skills + i;
switch (sv->id) { switch (sv->id) {
case SK_MAGIC: case SK_MAGIC:
f->score += (int)(u->number * pow(sv->level, 4)); f->score += (score_t)(u->number * pow(sv->level, 4));
break; break;
case SK_TACTICS: case SK_TACTICS:
f->score += (int)(u->number * pow(sv->level, 3)); f->score += (score_t)(u->number * pow(sv->level, 3));
break; break;
case SK_SPY: case SK_SPY:
case SK_ALCHEMY: case SK_ALCHEMY:
case SK_HERBALISM: 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; break;
default: 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; break;
} }
} }
@ -159,12 +159,16 @@ void score(void)
faction *f; faction *f;
fwrite(utf8_bom, 1, 3, scoreFP); fwrite(utf8_bom, 1, 3, scoreFP);
for (f = factions; f; f = f->next) for (f = factions; f; f = f->next)
if (f->num_total != 0) { if (!fval(f, FFL_NPC) && f->num_total != 0) {
fprintf(scoreFP, "%8d (%8d/%4.2f%%/%5.2f) %30.30s (%3.3s) %5s (%3d)\n", char score[32];
f->score, f->score - average_score_of_age(f->age, f->age / 24 + 1), write_score(score, sizeof(score), f->score);
((double)f->score / allscores) * 100, fprintf(scoreFP, "%s ", score);
(double)f->score / f->num_total, write_score(score, sizeof(score), average_score_of_age(f->age, f->age / 24 + 1));
f->name, LOC(default_locale, rc_name_s(f->race, NAME_SINGULAR)), factionid(f), 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); f->age);
} }
fclose(scoreFP); fclose(scoreFP);
@ -182,8 +186,8 @@ void score(void)
fprintf(scoreFP, "# alliance:factions:persons:score\n"); fprintf(scoreFP, "# alliance:factions:persons:score\n");
for (a = alliances; a; a = a->next) { for (a = alliances; a; a = a->next) {
int alliance_score = 0, alliance_number = 0, alliance_factions = 0; score_t alliance_score = 0;
int grails = 0; int alliance_number = 0, alliance_factions = 0, grails = 0;
faction *f; faction *f;
for (f = factions; f; f = f->next) { for (f = factions; f; f = f->next) {
@ -204,7 +208,7 @@ void score(void)
} }
} }
fprintf(scoreFP, "%d:%d:%d:%d", a->id, alliance_factions, fprintf(scoreFP, "%d:%d:%d:%lld", a->id, alliance_factions,
alliance_number, alliance_score); alliance_number, alliance_score);
if (token != NULL) if (token != NULL)
fprintf(scoreFP, ":%d", grails); fprintf(scoreFP, ":%d", grails);
@ -231,4 +235,6 @@ int default_score(const item_type *itype) {
return result; return result;
} }
#endif void write_score(char *buffer, size_t size, score_t score) {
slprintf(buffer, size, "%lld", score);
}

View File

@ -20,17 +20,15 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define SCORE_H #define SCORE_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif
#if SCORE_MODULE == 0
#error "must define SCORE_MODULE to use this module"
#endif #endif
struct item_type; struct item_type;
typedef long long score_t;
void score(void); 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); int default_score(const struct item_type *itype);
void write_score(char *buffer, size_t size, score_t score);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -2117,13 +2117,13 @@ const char *charset)
} }
} }
newline(out); newline(out);
#if SCORE_MODULE
if (f->options & want(O_SCORE) && f->age > DISPLAYSCORE) { if (f->options & want(O_SCORE) && f->age > DISPLAYSCORE) {
RENDER(f, buf, sizeof(buf), ("nr_score", "score average", f->score, char score[32], avg[32];
average_score_of_age(f->age, f->age / 24 + 1))); 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); centre(out, buf, true);
} }
#endif
#ifdef COUNT_AGAIN #ifdef COUNT_AGAIN
no_units = 0; no_units = 0;
no_people = 0; no_people = 0;

View File

@ -35,7 +35,6 @@
* configuration variables (XML), script extensions (lua), * configuration variables (XML), script extensions (lua),
* or both. We don't want separate binaries for different games * or both. We don't want separate binaries for different games
*/ */
#define SCORE_MODULE 1
#define MUSEUM_MODULE 1 #define MUSEUM_MODULE 1
#define ARENA_MODULE 1 #define ARENA_MODULE 1
#define CHANGED_CROSSBOWS 0 /* use the WTF_ARMORPIERCING flag */ #define CHANGED_CROSSBOWS 0 /* use the WTF_ARMORPIERCING flag */