changing region resources

This commit is contained in:
Enno Rehling 2008-06-08 21:40:12 +00:00
parent cc4d2a1026
commit 784a489830

View file

@ -9,6 +9,7 @@
#include <kernel/item.h>
#include <kernel/plane.h>
#include <kernel/region.h>
#include <kernel/resources.h>
#include <kernel/ship.h>
#include <kernel/terrain.h>
#include <kernel/unit.h>
@ -154,6 +155,12 @@ region_getresource(const region& r, const char * type)
{
const resource_type * rtype = rt_find(type);
if (rtype!=NULL) {
const rawmaterial * rm = r.resources;
while (rm) {
if (rm->type->rtype==rtype) {
return rm->amount;
}
}
if (rtype==rt_find("money")) return rmoney(&r);
if (rtype==rt_find("horse")) return rhorses(&r);
if (rtype==rt_find("peasant")) return rpeasants(&r);
@ -172,9 +179,18 @@ region_setresource(region& r, const char * type, int value)
{
const resource_type * rtype = rt_find(type);
if (rtype!=NULL) {
if (rtype==rt_find("money")) rsetmoney(&r, value);
else if (rtype==rt_find("peasant")) rsetpeasants(&r, value);
else if (rtype==rt_find("horse")) rsethorses(&r, value);
rawmaterial * rm = r.resources;
while (rm) {
if (rm->type->rtype==rtype) {
rm->amount = value;
break;
}
}
if (!rm) {
if (rtype==rt_find("money")) rsetmoney(&r, value);
else if (rtype==rt_find("peasant")) rsetpeasants(&r, value);
else if (rtype==rt_find("horse")) rsethorses(&r, value);
}
} else {
if (strcmp(type, "seed")==0) {
rsettrees(&r, 0, value);