2001-01-27 12:32:32 +01:00
|
|
|
|
/* vi: set ts=2:
|
|
|
|
|
*
|
2001-12-10 01:13:39 +01:00
|
|
|
|
*
|
2003-07-29 11:48:03 +02:00
|
|
|
|
* Eressea PB(E)M host Copyright (C) 1998-2003
|
2001-01-27 12:32:32 +01:00
|
|
|
|
* Christian Schlittchen (corwin@amber.kn-bremen.de)
|
|
|
|
|
* Katja Zedel (katze@felidae.kn-bremen.de)
|
|
|
|
|
* Henning Peters (faroul@beyond.kn-bremen.de)
|
|
|
|
|
* Enno Rehling (enno@eressea-pbem.de)
|
|
|
|
|
* Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
|
|
|
|
|
*
|
|
|
|
|
* based on:
|
|
|
|
|
*
|
|
|
|
|
* Atlantis v1.0 13 September 1993 Copyright 1993 by Russell Wallace
|
|
|
|
|
* Atlantis v1.7 Copyright 1996 by Alex Schr<EFBFBD>der
|
|
|
|
|
*
|
|
|
|
|
* This program may not be used, modified or distributed without
|
|
|
|
|
* prior permission by the authors of Eressea.
|
|
|
|
|
* This program may not be sold or used commercially without prior written
|
|
|
|
|
* permission from the authors.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#include "eressea.h"
|
2005-07-31 18:07:02 +02:00
|
|
|
|
#ifdef SCORE_MODULE
|
2005-11-20 13:58:59 +01:00
|
|
|
|
#include "score.h"
|
2001-01-27 12:32:32 +01:00
|
|
|
|
|
2003-07-29 11:48:03 +02:00
|
|
|
|
/* kernel includes */
|
2004-06-27 18:56:01 +02:00
|
|
|
|
#include <kernel/alliance.h>
|
2004-06-11 21:59:02 +02:00
|
|
|
|
#include <kernel/building.h>
|
|
|
|
|
#include <kernel/faction.h>
|
|
|
|
|
#include <kernel/item.h>
|
|
|
|
|
#include <kernel/magic.h>
|
|
|
|
|
#include <kernel/race.h>
|
|
|
|
|
#include <kernel/region.h>
|
|
|
|
|
#include <kernel/ship.h>
|
|
|
|
|
#include <kernel/skill.h>
|
|
|
|
|
#include <kernel/unit.h>
|
|
|
|
|
#include <kernel/pool.h>
|
2001-01-27 12:32:32 +01:00
|
|
|
|
|
|
|
|
|
/* util includes */
|
|
|
|
|
#include <base36.h>
|
2003-07-29 11:48:03 +02:00
|
|
|
|
#include <goodies.h>
|
2001-01-27 12:32:32 +01:00
|
|
|
|
|
|
|
|
|
/* libc includes */
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
average_score_of_age(int age, int a)
|
|
|
|
|
{
|
|
|
|
|
faction *f;
|
|
|
|
|
int sum = 0, count = 0;
|
|
|
|
|
|
|
|
|
|
for (f = factions; f; f = f->next) {
|
2001-12-30 14:33:45 +01:00
|
|
|
|
if (f->no != MONSTER_FACTION && f->race != new_race[RC_TEMPLATE] && f->age <= age + a && f->age >= age - a) {
|
2001-01-27 12:32:32 +01:00
|
|
|
|
sum += f->score;
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (count == 0) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return sum / count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
score(void)
|
|
|
|
|
{
|
|
|
|
|
FILE *scoreFP;
|
|
|
|
|
region *r;
|
|
|
|
|
unit *u, *u2;
|
|
|
|
|
faction *f, *fbo;
|
|
|
|
|
building *b;
|
|
|
|
|
ship *s;
|
|
|
|
|
int allscores = 0;
|
|
|
|
|
int c;
|
|
|
|
|
|
|
|
|
|
for (f = factions; f; f = f->next) f->score = 0;
|
|
|
|
|
|
|
|
|
|
for (r = regions; r; r = r->next) {
|
|
|
|
|
for (b = r->buildings; b; b = b->next) {
|
|
|
|
|
if ((u = buildingowner(r, b)) != 0) {
|
|
|
|
|
fbo = u->faction;
|
|
|
|
|
|
|
|
|
|
if (u->number <= b->size)
|
|
|
|
|
fbo->score += u->number * 5;
|
|
|
|
|
|
|
|
|
|
fbo->score += b->size;
|
|
|
|
|
|
|
|
|
|
c = b->size - u->number;
|
|
|
|
|
|
|
|
|
|
for (u2 = r->units; u2 && c > 0; u2 = u2->next) {
|
|
|
|
|
if (u2->building == b && u2 != u && u2->number <= c) {
|
|
|
|
|
c -= u2->number;
|
|
|
|
|
|
|
|
|
|
if (u2->faction == fbo) {
|
|
|
|
|
u2->faction->score += u2->number * 5;
|
|
|
|
|
} else {
|
|
|
|
|
u2->faction->score += u2->number * 3;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (s = r->ships; s; s = s->next) {
|
2004-06-21 18:45:27 +02:00
|
|
|
|
if ((u = shipowner(s)) != 0) {
|
2001-01-27 12:32:32 +01:00
|
|
|
|
u->faction->score += s->size * 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (u = r->units; u; u = u->next) {
|
|
|
|
|
item * itm;
|
2005-07-31 18:07:02 +02:00
|
|
|
|
int itemscore = 0;
|
2005-10-09 22:36:44 +02:00
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if (u->race == new_race[RC_SPELL] || u->race == new_race[RC_BIRTHDAYDRAGON])
|
2001-01-27 12:32:32 +01:00
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
f = u->faction;
|
|
|
|
|
|
2002-01-21 02:20:45 +01:00
|
|
|
|
if (old_race(u->race) <= RC_AQUARIAN) {
|
2001-12-10 01:13:39 +01:00
|
|
|
|
f->score += (u->race->recruitcost * u->number) / 50;
|
2001-01-27 12:32:32 +01:00
|
|
|
|
}
|
|
|
|
|
f->score += get_money(u) / 50;
|
|
|
|
|
for (itm=u->items; itm; itm=itm->next) {
|
2005-07-31 21:22:14 +02:00
|
|
|
|
itemscore += itm->number * itm->type->score;
|
2001-01-27 12:32:32 +01:00
|
|
|
|
}
|
2005-07-31 18:07:02 +02:00
|
|
|
|
f->score += itemscore / 10;
|
2001-01-27 12:32:32 +01:00
|
|
|
|
|
2005-10-09 22:36:44 +02:00
|
|
|
|
for (i=0;i!=u->skill_size;++i) {
|
|
|
|
|
skill * sv = u->skills+i;
|
|
|
|
|
switch (sv->id) {
|
|
|
|
|
case SK_MAGIC:
|
|
|
|
|
f->score += (int)(u->number * pow(sv->level, 4));
|
|
|
|
|
break;
|
|
|
|
|
case SK_TACTICS:
|
|
|
|
|
f->score += (int)(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));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
f->score += (int)(u->number * pow(sv->level, 2.5) / 10);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-01-27 12:32:32 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (f = factions; f; f = f->next) {
|
|
|
|
|
f->score = f->score / 5;
|
2001-12-30 14:33:45 +01:00
|
|
|
|
if (f->no != MONSTER_FACTION && f->race != new_race[RC_TEMPLATE])
|
2001-01-27 12:32:32 +01:00
|
|
|
|
allscores += f->score;
|
|
|
|
|
}
|
|
|
|
|
if( allscores == 0 )
|
|
|
|
|
allscores = 1;
|
|
|
|
|
|
|
|
|
|
sprintf(buf, "%s/score", basepath());
|
|
|
|
|
scoreFP = fopen(buf, "w");
|
2005-03-06 14:47:23 +01:00
|
|
|
|
for (f = factions; f; f = f->next) if (f->num_total != 0) {
|
2001-09-05 21:40:40 +02:00
|
|
|
|
fprintf(scoreFP, "%8d (%8d/%4.2f%%/%5.2f) %30.30s (%3.3s) %5s (%3d)\n",
|
2001-01-27 12:32:32 +01:00
|
|
|
|
f->score, f->score - average_score_of_age(f->age, f->age / 24 + 1),
|
2001-09-05 21:40:40 +02:00
|
|
|
|
((float) f->score / (float) allscores) * 100.0,
|
2005-03-06 14:47:23 +01:00
|
|
|
|
(float) f->score / f->num_total,
|
2001-12-10 01:13:39 +01:00
|
|
|
|
f->name, LOC(default_locale, rc_name(f->race, 0)), factionid(f), f->age);
|
2001-01-27 12:32:32 +01:00
|
|
|
|
}
|
|
|
|
|
fclose(scoreFP);
|
2002-11-04 20:16:45 +01:00
|
|
|
|
|
2004-06-27 18:56:01 +02:00
|
|
|
|
if (alliances!=NULL) {
|
2002-11-04 20:16:45 +01:00
|
|
|
|
alliance *a;
|
2003-05-27 21:49:19 +02:00
|
|
|
|
const item_type * token = it_find("conquesttoken");
|
2002-11-04 20:16:45 +01:00
|
|
|
|
|
|
|
|
|
sprintf(buf, "%s/score.alliances", basepath());
|
|
|
|
|
scoreFP = fopen(buf, "w");
|
2003-01-19 10:00:00 +01:00
|
|
|
|
fprintf(scoreFP, "# alliance:factions:persons:score\n");
|
2002-11-04 20:16:45 +01:00
|
|
|
|
|
|
|
|
|
for (a = alliances; a; a = a->next) {
|
2003-01-19 11:13:41 +01:00
|
|
|
|
int alliance_score = 0, alliance_number = 0, alliance_factions = 0;
|
2003-05-28 00:12:54 +02:00
|
|
|
|
int grails = 0;
|
2002-11-04 20:16:45 +01:00
|
|
|
|
|
|
|
|
|
for (f = factions; f; f = f->next) {
|
|
|
|
|
if(f->alliance && f->alliance->id == a->id) {
|
2003-01-19 11:13:41 +01:00
|
|
|
|
alliance_factions++;
|
2002-11-04 21:19:17 +01:00
|
|
|
|
alliance_score += f->score;
|
2005-03-06 14:47:23 +01:00
|
|
|
|
alliance_number += f->num_total;
|
2003-05-28 00:12:54 +02:00
|
|
|
|
if (token!=NULL) {
|
|
|
|
|
unit * u = f->units;
|
|
|
|
|
while (u!=NULL) {
|
|
|
|
|
item ** iitem = i_find(&u->items, token);
|
|
|
|
|
if (iitem!=NULL && *iitem!=NULL) {
|
|
|
|
|
grails += (*iitem)->number;
|
|
|
|
|
}
|
|
|
|
|
u=u->nextF;
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-11-04 20:16:45 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-27 21:49:19 +02:00
|
|
|
|
fprintf(scoreFP, "%d:%d:%d:%d", a->id, alliance_factions, alliance_number, alliance_score);
|
|
|
|
|
if (token!=NULL) fprintf(scoreFP, ":%d", grails);
|
|
|
|
|
fputc('\n', scoreFP);
|
2002-11-04 20:16:45 +01:00
|
|
|
|
}
|
|
|
|
|
fclose(scoreFP);
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-27 12:32:32 +01:00
|
|
|
|
}
|
2002-11-04 20:16:45 +01:00
|
|
|
|
|
2005-07-31 18:07:02 +02:00
|
|
|
|
#endif
|