forked from github/server
Merge pull request #285 from ennorehling/feature/bug-2136-large-scores
Bug 2136: large score values
This commit is contained in:
commit
e2b78cd8d8
|
@ -841,11 +841,11 @@
|
|||
</message>
|
||||
<message name="nr_score" section="nr">
|
||||
<type>
|
||||
<arg name="score" type="int"/>
|
||||
<arg name="average" type="int"/>
|
||||
<arg name="score" type="string"/>
|
||||
<arg name="average" type="string"/>
|
||||
</type>
|
||||
<text locale="de">"Deine Partei hat $int($score) Punkte. Der Durchschnitt für Parteien ähnlichen Alters ist $int($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="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 ${score}. The average score for similar factions is ${average}."</text>
|
||||
</message>
|
||||
<message name="nr_header_date" section="nr">
|
||||
<type>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
#define VERSION_MAJOR 3
|
||||
#define VERSION_MINOR 6
|
||||
#define VERSION_BUILD 2
|
||||
#define VERSION_MINOR 7
|
||||
#define VERSION_BUILD 0
|
||||
|
|
|
@ -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)));
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -21,7 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
#include "skill.h"
|
||||
#include "types.h"
|
||||
|
||||
#include <modules/score.h>
|
||||
#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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -31,9 +31,7 @@ without prior permission by the authors of Eressea.
|
|||
|
||||
#include "vortex.h"
|
||||
|
||||
#if SCORE_MODULE
|
||||
#include <modules/score.h>
|
||||
#endif
|
||||
|
||||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
|
@ -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;
|
||||
|
|
|
@ -61,6 +61,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
/* exports: */
|
||||
plane *arena = NULL;
|
||||
|
@ -122,12 +123,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))
|
||||
|
|
|
@ -18,7 +18,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
#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 <util/base36.h>
|
||||
#include <util/bsdstring.h>
|
||||
#include <util/language.h>
|
||||
|
||||
/* libc includes */
|
||||
#include <math.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;
|
||||
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) {
|
||||
|
@ -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);
|
||||
if (token != NULL)
|
||||
fprintf(scoreFP, ":%d", grails);
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in New Issue