forked from github/server
calculate simple default scores for items that do not have one defined in XML.
This commit is contained in:
parent
2967cd59cf
commit
84f8a9f746
3 changed files with 30 additions and 5 deletions
|
@ -31,6 +31,10 @@ without prior permission by the authors of Eressea.
|
||||||
|
|
||||||
#include "vortex.h"
|
#include "vortex.h"
|
||||||
|
|
||||||
|
#if SCORE_MODULE
|
||||||
|
#include <modules/score.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/* util includes */
|
/* util includes */
|
||||||
#include <util/attrib.h>
|
#include <util/attrib.h>
|
||||||
#include <util/bsdstring.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->weight = xml_ivalue(node, "weight", 0);
|
||||||
itype->capacity = xml_ivalue(node, "capacity", 0);
|
itype->capacity = xml_ivalue(node, "capacity", 0);
|
||||||
itype->flags |= flags;
|
itype->flags |= flags;
|
||||||
#if SCORE_MODULE
|
|
||||||
itype->score = xml_ivalue(node, "score", 0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* reading item/construction */
|
/* reading item/construction */
|
||||||
xpath->node = node;
|
xpath->node = node;
|
||||||
|
@ -855,6 +856,10 @@ static item_type *xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype)
|
||||||
}
|
}
|
||||||
xmlFree(propValue);
|
xmlFree(propValue);
|
||||||
}
|
}
|
||||||
|
#if SCORE_MODULE
|
||||||
|
itype->score = xml_ivalue(node, "score", 0);
|
||||||
|
if (!itype->score) itype->score = default_score(itype);
|
||||||
|
#endif
|
||||||
xmlXPathFreeObject(result);
|
xmlXPathFreeObject(result);
|
||||||
|
|
||||||
return itype;
|
return itype;
|
||||||
|
|
|
@ -24,6 +24,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
/* kernel includes */
|
/* kernel includes */
|
||||||
#include <kernel/alliance.h>
|
#include <kernel/alliance.h>
|
||||||
#include <kernel/building.h>
|
#include <kernel/building.h>
|
||||||
|
#include <kernel/build.h>
|
||||||
#include <kernel/faction.h>
|
#include <kernel/faction.h>
|
||||||
#include <kernel/item.h>
|
#include <kernel/item.h>
|
||||||
#include <kernel/race.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
|
#endif
|
||||||
|
|
|
@ -26,8 +26,11 @@ extern "C" {
|
||||||
#error "must define SCORE_MODULE to use this module"
|
#error "must define SCORE_MODULE to use this module"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern void score(void);
|
struct item_type;
|
||||||
extern int average_score_of_age(int age, int a);
|
|
||||||
|
void score(void);
|
||||||
|
int average_score_of_age(int age, int a);
|
||||||
|
int default_score(const struct item_type *itype);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue