calculate simple default scores for items that do not have one defined in XML.

This commit is contained in:
Enno Rehling 2015-06-08 21:15:07 +02:00
parent 2967cd59cf
commit 84f8a9f746
3 changed files with 30 additions and 5 deletions

View File

@ -31,6 +31,10 @@ 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>
#include <util/bsdstring.h>
@ -766,9 +770,6 @@ static item_type *xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype)
itype->weight = xml_ivalue(node, "weight", 0);
itype->capacity = xml_ivalue(node, "capacity", 0);
itype->flags |= flags;
#if SCORE_MODULE
itype->score = xml_ivalue(node, "score", 0);
#endif
/* reading item/construction */
xpath->node = node;
@ -855,6 +856,10 @@ 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;

View File

@ -24,6 +24,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* kernel includes */
#include <kernel/alliance.h>
#include <kernel/building.h>
#include <kernel/build.h>
#include <kernel/faction.h>
#include <kernel/item.h>
#include <kernel/race.h>
@ -214,4 +215,20 @@ void score(void)
}
}
int default_score(const item_type *itype) {
int result = 0;
if (itype->construction) {
requirement *req = itype->construction->materials;
while (req->number) {
int score = req->rtype->itype ? req->rtype->itype->score : 10;
result += score * req->number * 2;
++req;
}
}
else {
result = 10;
}
return result;
}
#endif

View File

@ -26,8 +26,11 @@ extern "C" {
#error "must define SCORE_MODULE to use this module"
#endif
extern void score(void);
extern int average_score_of_age(int age, int a);
struct item_type;
void score(void);
int average_score_of_age(int age, int a);
int default_score(const struct item_type *itype);
#ifdef __cplusplus
}