Skip to content

Commit

Permalink
prevent tests writing stray score files
Browse files Browse the repository at this point in the history
  • Loading branch information
ennorehling committed Dec 30, 2023
1 parent abb5213 commit 344bf5f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/bindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,14 @@ static int tolua_create_curse(lua_State * L)
static int tolua_update_scores(lua_State * L)
{
UNUSED_ARG(L);
score();
update_scores();
return 0;
}

static int tolua_write_scores(lua_State * L)
{
UNUSED_ARG(L);
write_scores();
return 0;
}

Expand Down Expand Up @@ -994,6 +1001,7 @@ int tolua_bindings_open(lua_State * L, const dictionary *inifile)
tolua_function(L, "get_nmrs", tolua_get_nmrs);
tolua_function(L, "remove_empty_units", tolua_remove_empty_units);
tolua_function(L, "update_scores", tolua_update_scores);
tolua_function(L, "write_scores", tolua_write_scores);
tolua_function(L, "update_owners", tolua_update_owners);
tolua_function(L, "create_curse", tolua_create_curse);
tolua_function(L, "translate", &tolua_translate);
Expand Down
18 changes: 14 additions & 4 deletions src/modules/score.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,11 @@ score_t average_score_of_age(int age)
return sum / count;
}

void score(void)
void update_scores(void)
{
FILE *scoreFP;
region *r;
faction *fc;
score_t allscores = 0;
char path[4096];

for (fc = factions; fc; fc = fc->next)
fc->score = 0;
Expand Down Expand Up @@ -101,7 +99,7 @@ void score(void)
if (f == NULL) {
continue;
}
else if (rc->recruitcost>0) {
else if (rc->recruitcost > 0) {
f->score += (rc->recruitcost * u->number) / 50;
}
f->score += get_money(u) / 50;
Expand Down Expand Up @@ -141,6 +139,12 @@ void score(void)
if (allscores == 0) {
allscores = 1;
}
}

void write_scores(void)
{
FILE *scoreFP;
char path[4096];

path_join(basepath(), "score", path, sizeof(path));
scoreFP = fopen(path, "w");
Expand Down Expand Up @@ -205,6 +209,12 @@ void score(void)
}
}

void score(void)
{
update_scores();
write_scores();
}

int default_score(const item_type *itype) {
int result = 0;
if (itype->rtype->wtype || itype->rtype->atype) {
Expand Down
2 changes: 2 additions & 0 deletions src/modules/score.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ extern "C" {
struct item_type;
typedef long long score_t;

void update_scores(void);
void write_scores(void);
void score(void);
score_t average_score_of_age(int age);
int default_score(const struct item_type *itype);
Expand Down

0 comments on commit 344bf5f

Please sign in to comment.