units that have no factions crashed the score-module

This commit is contained in:
Enno Rehling 2007-02-09 22:41:28 +00:00
parent 4f5c8e1878
commit 869c17bf39
1 changed files with 115 additions and 108 deletions

View File

@ -1,7 +1,7 @@
/* vi: set ts=2: /* vi: set ts=2:
* *
* *
* Eressea PB(E)M host Copyright (C) 1998-2003 * Eressea PB(E)M host Copyright (C) 1998-2003
* Christian Schlittchen (corwin@amber.kn-bremen.de) * Christian Schlittchen (corwin@amber.kn-bremen.de)
* Katja Zedel (katze@felidae.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de)
* Henning Peters (faroul@beyond.kn-bremen.de) * Henning Peters (faroul@beyond.kn-bremen.de)
@ -47,83 +47,89 @@
int int
average_score_of_age(int age, int a) average_score_of_age(int age, int a)
{ {
faction *f; faction *f;
int sum = 0, count = 0; int sum = 0, count = 0;
for (f = factions; f; f = f->next) { for (f = factions; f; f = f->next) {
if (f->no != MONSTER_FACTION && f->race != new_race[RC_TEMPLATE] && f->age <= age + a && f->age >= age - a) { if (f->no != MONSTER_FACTION && f->race != new_race[RC_TEMPLATE] && f->age <= age + a && f->age >= age - a) {
sum += f->score; sum += f->score;
count++; count++;
} }
} }
if (count == 0) { if (count == 0) {
return 0; return 0;
} }
return sum / count; return sum / count;
} }
void void
score(void) score(void)
{ {
FILE *scoreFP; FILE *scoreFP;
region *r; region *r;
unit *u, *u2; faction *f;
faction *f, *fbo; int allscores = 0;
building *b;
ship *s;
int allscores = 0;
int c;
for (f = factions; f; f = f->next) f->score = 0; for (f = factions; f; f = f->next) f->score = 0;
for (r = regions; r; r = r->next) { for (r = regions; r; r = r->next) {
for (b = r->buildings; b; b = b->next) { unit * u;
if ((u = buildingowner(r, b)) != 0) { building * b;
fbo = u->faction; ship * s;
if (u->number <= b->size) for (b = r->buildings; b; b = b->next) {
fbo->score += u->number * 5; u = buildingowner(r, b);
if (u!=NULL) {
unit * u2;
faction * fbo = u->faction;
int c = b->size - u->number;
fbo->score += b->size; if (fbo) {
if (u->number <= b->size)
fbo->score += u->number * 5;
c = b->size - u->number; fbo->score += b->size;
}
for (u2 = r->units; u2 && c > 0; u2 = u2->next) { for (u2 = r->units; u2 && c > 0; u2 = u2->next) {
if (u2->building == b && u2 != u && u2->number <= c) { if (u2->building == b && u2 != u && u2->number <= c) {
c -= u2->number; c -= u2->number;
if (u2->faction == fbo) { if (u2->faction) {
u2->faction->score += u2->number * 5; if (u2->faction == fbo) {
} else { u2->faction->score += u2->number * 5;
u2->faction->score += u2->number * 3; } else {
} u2->faction->score += u2->number * 3;
} }
} }
} }
} }
for (s = r->ships; s; s = s->next) { }
if ((u = shipowner(s)) != 0) { }
u->faction->score += s->size * 2; for (s = r->ships; s; s = s->next) {
} unit * u = shipowner(s);
} if (u && u->faction) {
for (u = r->units; u; u = u->next) { u->faction->score += s->size * 2;
item * itm; }
}
for (u = r->units; u; u = u->next) {
item * itm;
int itemscore = 0; int itemscore = 0;
int i; int i;
faction * f = u->faction;
if (u->race == new_race[RC_SPELL] || u->race == new_race[RC_BIRTHDAYDRAGON]) if (f==NULL || u->race == new_race[RC_SPELL] || u->race == new_race[RC_BIRTHDAYDRAGON]) {
continue; continue;
}
f = u->faction; if (old_race(u->race) <= RC_AQUARIAN) {
f->score += (u->race->recruitcost * u->number) / 50;
if (old_race(u->race) <= RC_AQUARIAN) { }
f->score += (u->race->recruitcost * u->number) / 50; f->score += get_money(u) / 50;
} for (itm=u->items; itm; itm=itm->next) {
f->score += get_money(u) / 50;
for (itm=u->items; itm; itm=itm->next) {
itemscore += itm->number * itm->type->score; itemscore += itm->number * itm->type->score;
} }
f->score += itemscore / 10; f->score += itemscore / 10;
for (i=0;i!=u->skill_size;++i) { for (i=0;i!=u->skill_size;++i) {
@ -145,65 +151,66 @@ score(void)
break; break;
} }
} }
} }
} }
for (f = factions; f; f = f->next) { for (f = factions; f; f = f->next) {
f->score = f->score / 5; f->score = f->score / 5;
if (f->no != MONSTER_FACTION && f->race != new_race[RC_TEMPLATE]) if (f->no != MONSTER_FACTION && f->race != new_race[RC_TEMPLATE]) {
allscores += f->score; allscores += f->score;
} }
if( allscores == 0 ) }
allscores = 1; if (allscores == 0) {
allscores = 1;
}
sprintf(buf, "%s/score", basepath()); sprintf(buf, "%s/score", basepath());
scoreFP = fopen(buf, "w"); scoreFP = fopen(buf, "w");
for (f = factions; f; f = f->next) if (f->num_total != 0) { 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", 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), f->score, f->score - average_score_of_age(f->age, f->age / 24 + 1),
((float) f->score / (float) allscores) * 100.0, ((float) f->score / (float) allscores) * 100.0,
(float) f->score / f->num_total, (float) f->score / f->num_total,
f->name, LOC(default_locale, rc_name(f->race, 0)), factionid(f), f->age); f->name, LOC(default_locale, rc_name(f->race, 0)), factionid(f), f->age);
} }
fclose(scoreFP); fclose(scoreFP);
if (alliances!=NULL) { if (alliances!=NULL) {
alliance *a; alliance *a;
const item_type * token = it_find("conquesttoken"); const item_type * token = it_find("conquesttoken");
sprintf(buf, "%s/score.alliances", basepath()); sprintf(buf, "%s/score.alliances", basepath());
scoreFP = fopen(buf, "w"); scoreFP = fopen(buf, "w");
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; int alliance_score = 0, alliance_number = 0, alliance_factions = 0;
int grails = 0; int grails = 0;
for (f = factions; f; f = f->next) { for (f = factions; f; f = f->next) {
if(f->alliance && f->alliance->id == a->id) { if (f->alliance && f->alliance->id == a->id) {
alliance_factions++; alliance_factions++;
alliance_score += f->score; alliance_score += f->score;
alliance_number += f->num_total; alliance_number += f->num_total;
if (token!=NULL) { if (token!=NULL) {
unit * u = f->units; unit * u = f->units;
while (u!=NULL) { while (u!=NULL) {
item ** iitem = i_find(&u->items, token); item ** iitem = i_find(&u->items, token);
if (iitem!=NULL && *iitem!=NULL) { if (iitem!=NULL && *iitem!=NULL) {
grails += (*iitem)->number; grails += (*iitem)->number;
} }
u=u->nextF; u=u->nextF;
} }
} }
} }
} }
fprintf(scoreFP, "%d:%d:%d:%d", a->id, alliance_factions, alliance_number, alliance_score); fprintf(scoreFP, "%d:%d:%d:%d", a->id, alliance_factions, alliance_number, alliance_score);
if (token!=NULL) fprintf(scoreFP, ":%d", grails); if (token!=NULL) fprintf(scoreFP, ":%d", grails);
fputc('\n', scoreFP); fputc('\n', scoreFP);
} }
fclose(scoreFP); fclose(scoreFP);
} }
} }
#endif #endif