The quest to remove resource_t from the game continues (finally)

This commit is contained in:
Enno Rehling 2005-10-29 11:17:21 +00:00
parent adbefd89c5
commit 91da1f6e89
18 changed files with 381 additions and 469 deletions

View file

@ -2,9 +2,12 @@ C++ = g++-3.3 ;
CC = gcc-3.3 ;
LINK = gcc-3.3 ;
#CC = tcc ;
#LINK = tcc ;
# ECHO $(JAMUNAME) ;
LINKFLAGS += -rdynamic ;
# LINKFLAGS += -rdynamic ;
if $(MSPACES) {
CCFLAGS += -DMSPACES ;

View file

@ -1229,7 +1229,7 @@ report_computer(FILE * F, faction * f, struct seen_region ** seen, const faction
fprintf(F, "ZUTATEN\n");
while (m->number) {
ch = resourcename(oldresourcetype[m->type], 0);
ch = resourcename(m->rtype, 0);
fprintf(F, "\"%s\"\n", add_translation(ch, locale_string(f->locale, ch)));
m++;
}

View file

@ -551,8 +551,6 @@ recruit(unit * u, struct order * ord, request ** recruitorders)
}
/* ------------------------------------------------------------- */
extern const char* resname(resource_t res, int i);
static void
give_cmd(unit * u, order * ord)
{
@ -1148,12 +1146,13 @@ manufacture(unit * u, const item_type * itype, int want)
char * ch = buf+strlen(buf);
assert(cons);
for (c=0;cons->materials[c].number; c++) {
requirement * m = cons->materials+c;
if (c!=0)
strcat(ch++, ",");
n=cons->materials[c].number / cons->reqsize;
n = m->number / cons->reqsize;
sprintf(ch, " %d %s", n?n:1,
locale_string(u->faction->locale,
resname(cons->materials[c].type, cons->materials[c].number!=1)));
resourcename(m->rtype, m->number!=1)));
ch = ch+strlen(ch);
}
mistake(u, u->thisorder, buf, MSG_PRODUCE);
@ -1584,12 +1583,13 @@ create_potion(unit * u, const potion_type * ptype, int want)
char * ch = buf+strlen(buf);
assert(cons);
for (c=0;cons->materials[c].number; c++) {
const requirement * m = cons->materials+c;
if (c!=0)
strcat(ch++, ",");
n=cons->materials[c].number / cons->reqsize;
n = m->number / cons->reqsize;
sprintf(ch, " %d %s", n?n:1,
locale_string(u->faction->locale,
resname(cons->materials[c].type, cons->materials[c].number!=1)));
LOC(u->faction->locale,
resourcename(m->rtype, m->number!=1)));
ch = ch+strlen(ch);
}
strcat(ch,".");

View file

@ -76,13 +76,14 @@
static void
reduce_weight(unit * u)
{
int horses = get_resource(u,R_HORSE);
int horses = new_get_resource(u, oldresourcetype[R_HORSE]);
int capacity = walkingcapacity(u);
item ** itmp = &u->items;
int weight = 0;
if (horses > 0) {
change_resource(u, R_HORSE, - min(horses,(u->number*2)));
horses = min(horses, (u->number*2));
new_change_resource(u, oldresourcetype[R_HORSE], - horses);
}
/* 1. get rid of anything that isn't silver or really lightweight or helpful in combat */

View file

@ -1884,7 +1884,7 @@ report_building(FILE *F, const region * r, const building * b, const faction * f
assert(ctype->materials != NULL);
for (c=0;ctype->materials[c].number;c++) {
resource_t rtype = ctype->materials[c].type;
const resource_type * rtype = ctype->materials[c].rtype;
int number = ctype->materials[c].number;
if(c > 0) {
@ -1892,9 +1892,7 @@ report_building(FILE *F, const region * r, const building * b, const faction * f
}
icat(number);
scat(" ");
scat(locale_string(lang,
resourcename(oldresourcetype[rtype],
number!=1?GR_PLURAL:0)));
scat(locale_string(lang, resourcename(rtype, number!=1?GR_PLURAL:0)));
}
scat(".");
@ -2153,7 +2151,7 @@ report(FILE *F, faction * f, struct seen_region ** seen, const faction_list * ad
rnl(F);
sprintf(buf, "%s: ", LOC(f->locale, "nr_herbsrequired"));
while (m->number) {
scat(LOC(f->locale, resourcename(oldresourcetype[m->type], 0)));
scat(LOC(f->locale, resourcename(m->rtype, 0)));
++m;
if (m->number) scat(", ");
}

View file

@ -334,7 +334,7 @@ init_oldweapons(void)
if (itype->construction->materials==NULL) {
itype->score = 6000;
} else for (m=0;itype->construction->materials[m].number;++m) {
const resource_type * rtype = oldresourcetype[itype->construction->materials[m].type];
const resource_type * rtype = itype->construction->materials[m].rtype;
int score = rtype->itype?rtype->itype->score:5;
itype->score = 2*itype->construction->materials[m].number * score;
}

View file

@ -1019,7 +1019,7 @@ terminate(troop dt, troop at, int type, const char *damage, boolean missile)
int c;
for (c=0;weapon->type->itype->construction->materials[c].number; c++) {
if(weapon->type->itype->construction->materials[c].type == R_IRON) {
if(weapon->type->itype->construction->materials[c].rtype == oldresourcetype[R_IRON]) {
da += faerie_level;
break;
}

View file

@ -446,7 +446,7 @@ destroy_cmd(unit * u, struct order * ord)
const requirement * rq = con->materials+c;
int recycle = (int)(rq->recycle * rq->number * size/con->reqsize);
if (recycle)
change_resource(u, rq->type, recycle);
new_change_resource(u, rq->rtype, recycle);
}
}
#endif
@ -716,17 +716,17 @@ build(unit * u, const construction * ctype, int completed, int want)
}
if (type->materials) for (c=0;n>0 && type->materials[c].number;c++) {
resource_t rtype = type->materials[c].type;
const struct resource_type * rtype = type->materials[c].rtype;
int need;
int have = get_pooled(u, NULL, rtype);
int have = new_get_pooled(u, rtype, GET_DEFAULT);
int prebuilt;
int canuse = have;
if (inside_building(u)) {
canuse = matmod(u->building->type->attribs, u, oldresourcetype[rtype], canuse);
canuse = matmod(u->building->type->attribs, u, rtype, canuse);
#if 0
/* exploit-check */
} else if (u->building) {
int abuse = matmod(u->building->type->attribs, u, oldresourcetype[rtype], canuse);
int abuse = matmod(u->building->type->attribs, u, rtype, canuse);
if (abuse>canuse) {
log_printf("ABUSE: %s saves %u %s through exploit\n",
itoa36(u->faction->no), abuse-canuse,
@ -735,7 +735,7 @@ build(unit * u, const construction * ctype, int completed, int want)
#endif
}
if (canuse<0) return canuse; /* pass errors to caller */
canuse = matmod(type->attribs, u, oldresourcetype[rtype], canuse);
canuse = matmod(type->attribs, u, rtype, canuse);
if (type->reqsize>1) {
prebuilt = required(completed, type->reqsize, type->materials[c].number);
for (;n;) {
@ -753,20 +753,20 @@ build(unit * u, const construction * ctype, int completed, int want)
else break;
}
if (type->materials) for (c=0;type->materials[c].number;c++) {
resource_t rtype = type->materials[c].type;
const struct resource_type * rtype = type->materials[c].rtype;
int prebuilt = required(completed, type->reqsize, type->materials[c].number);
int need = required(completed + n, type->reqsize, type->materials[c].number);
int multi = 1;
int canuse = 100; /* normalization */
if (inside_building(u)) canuse = matmod(u->building->type->attribs, u, oldresourcetype[rtype], canuse);
if (inside_building(u)) canuse = matmod(u->building->type->attribs, u, rtype, canuse);
if (canuse<0) return canuse; /* pass errors to caller */
canuse = matmod(type->attribs, u, oldresourcetype[rtype], canuse);
canuse = matmod(type->attribs, u, rtype, canuse);
assert(canuse % 100 == 0 || !"only constant multipliers are implemented in build()");
multi = canuse/100;
if (canuse<0) return canuse; /* pass errors to caller */
use_pooled(u, NULL, rtype, (need-prebuilt+multi-1)/multi);
new_use_pooled(u, rtype, (need-prebuilt+multi-1)/multi, GET_DEFAULT);
}
made += n;
skills -= n * type->minskill;
@ -787,8 +787,8 @@ maxbuild(const unit * u, const construction * cons)
int c;
int maximum = INT_MAX;
for (c=0;cons->materials[c].number;c++) {
resource_t rtype = cons->materials[c].type;
int have = get_pooled(u, NULL, rtype);
const resource_type * rtype = cons->materials[c].rtype;
int have = new_get_pooled(u, rtype, GET_DEFAULT);
int need = required(1, cons->reqsize, cons->materials[c].number);
if (have<need) {
cmistake(u, u->thisorder, 88, MSG_PRODUCE);
@ -898,7 +898,7 @@ build_building(unit * u, const building_type * btype, int want, order * ord)
if (c!=0) strcat(ch++, ",");
n = cons->materials[c].number / cons->reqsize;
sprintf(ch, " %d %s", n?n:1,
LOC(lang, resname(cons->materials[c].type, cons->materials[c].number!=1)));
LOC(lang, resourcename(cons->materials[c].rtype, cons->materials[c].number!=1)));
ch = ch+strlen(ch);
}
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "build_required",

View file

@ -32,11 +32,7 @@ extern "C" {
struct xml_tag;
typedef struct requirement {
#ifdef NO_OLD_ITEMS
resource_type * rtype;
#else
resource_t type;
#endif
const struct resource_type * rtype;
int number;
double recycle; /* recycling quota */
} requirement;

View file

@ -38,6 +38,22 @@ extern "C" {
/* #define MSG_LEVELS -- msg-levels active */
/* basic types used in the eressea "kernel" */
#ifdef __TINYC__
#define order_t short
#define terrain_t short
#define direction_t short
#define race_t short
#define magic_t short
#define skill_t short
#define typ_t short
#define herb_t short
#define potion_t short
#define luxury_t short
#define weapon_t short
#define item_t short
#define resource_t short
#define spellid_t unsigned int
#else
typedef short order_t;
typedef short terrain_t;
typedef short direction_t;
@ -52,6 +68,7 @@ typedef short weapon_t;
typedef short item_t;
typedef short resource_t;
typedef unsigned int spellid_t;
#endif
struct plane;
struct order;

View file

@ -1138,7 +1138,7 @@ init_olditems(void)
con->materials = calloc(sizeof(requirement), n+1);
for (m=0, n=0;m!=M_MAX_MAT;++m) {
if (itemdata[i].material[m]>0) {
con->materials[n].type = matresource[m];
con->materials[n].rtype = oldresourcetype[matresource[m]];
con->materials[n].number = itemdata[i].material[m];
con->materials[n].recycle = 0.0;
++n;
@ -1773,27 +1773,6 @@ attrib_type at_resourcelimit = {
finalize_resourcelimit,
};
const char*
resname(resource_t res, int index)
{
const item_type * itype = resource2item(oldresourcetype[res]);
if (itype!=NULL) {
return locale_string(NULL, resourcename(oldresourcetype[res], index));
}
else if (res == R_AURA) {
return index?"aura_p":"aura";
} else if (res == R_PERMAURA) {
return index?"permaura_p":"permaura";
} else if (res == R_PEASANTS) {
return index?"peasant_p":"peasant";
} else if (res == R_UNIT) {
return index?"unit_p":"unit";
} else if (res == R_HITPOINTS) {
return index?"hp_p":"hp";
}
return NULL;
}
void
register_resources(void)
{

View file

@ -409,8 +409,6 @@ extern struct attrib_type at_seenitem; /* knows this potion's description, no ne
extern void register_resources(void);
extern void init_resources(void);
extern const char* resname(resource_t res, int index);
extern struct item_type *i_silver;
#ifdef __cplusplus

View file

@ -387,7 +387,7 @@ sacrifice_cmd(unit * u, struct order * ord)
cmistake(u, ord, 51, MSG_EVENT);
return 0;
}
change_resource(u, R_SILVER, n);
new_change_resource(u, oldresourcetype[R_SILVER], n);
karma = n/10000;
u->faction->karma += karma;
break;

View file

@ -270,70 +270,6 @@ new_use_pooled(unit * u, const resource_type * rtype, int mode, int count)
return count-use;
}
int
get_resource(const unit * u, resource_t res)
{
return new_get_resource(u, oldresourcetype[res]);
}
int
change_resource(unit * u, resource_t res, int change)
{
int i = 0;
const item_type * itype = resource2item(oldresourcetype[res]);
if (!rc_stonegolem) init_static();
if (res==R_STONE && u->race==rc_stonegolem) {
i = u->number - (change+GOLEM_STONE-1)/GOLEM_STONE;
scale_number(u, i);
}
else if (res==R_IRON && u->race==rc_irongolem) {
i = u->number - (change+GOLEM_IRON-1)/GOLEM_IRON;
scale_number(u, i);
}
else if (itype!=NULL) {
item * it = i_change(&u->items, itype, change);
if (it==NULL) return 0;
return it->number;
}
else if (res == R_AURA)
i = change_spellpoints(u, change);
else if (res == R_PERMAURA)
i = change_maxspellpoints(u, change);
else if (res == R_HITPOINTS)
i = change_hitpoints(u, change);
else if (res == R_PEASANTS) {
i = rpeasants(u->region) + change;
if(i < 0) i = 0;
rsetpeasants(u->region, i);
}
else
assert(!"unbekannte ressource entdeckt");
assert(i >= 0 && (i < 1000000)); /* Softer Test, daß kein Unfug
* * passiert */
return i;
}
int
get_resvalue(const unit * u, resource_t resource)
{
const resource_type * rtype = oldresourcetype[resource];
return new_get_resvalue(u, rtype);
}
static int
set_resvalue(unit * u, resource_t resource, int value)
{
return new_set_resvalue(u, oldresourcetype[resource], value);
}
int
change_resvalue(unit * u, resource_t resource, int value)
{
return set_resvalue(u, resource, get_resvalue(u, resource) + value);
}
int
get_reserved(const unit * u, resource_t resource)
{
@ -369,7 +305,7 @@ get_pooled(const unit * u, const region * r, resource_t resource)
int
use_pooled(unit * u, region * r, resource_t resource, int count)
{
return new_use_pooled(u, oldresourcetype[resource], GET_SLACK|GET_RESERVE|GET_POOLED_SLACK, count);
return new_use_pooled(u, oldresourcetype[resource], GET_DEFAULT, count);
}
int

View file

@ -80,12 +80,6 @@ int get_slack(const struct unit * u, resource_t itm);
* aus den nicht-reservierten Objekten der Einheit.
*/
int get_resource(const struct unit * u, resource_t res);
int change_resource(struct unit * u, resource_t res, int change);
int get_resvalue(const struct unit * u, resource_t resource);
int change_resvalue(struct unit * u, resource_t resource, int value);
int new_get_pooled(const struct unit * u, const struct resource_type * res, int mode);
int new_use_pooled(struct unit * u, const struct resource_type * res, int mode, int count);
/** use_pooled

View file

@ -86,8 +86,6 @@ extern void seen_done(struct seen_region * seehash[]);
extern void free_seen(void);
extern void get_seen_interval(struct seen_region ** seen, struct region ** first, struct region ** last);
extern const char* resname(resource_t res, int i);
extern void report_item(const struct unit * owner, const struct item * i, const struct faction * viewer, const char ** name, const char ** basename, int * number, boolean singular);
extern void report_building(FILE *F, const struct region * r, const struct building * b, const struct faction * f, int mode);
extern int bufunit(const struct faction * f, const struct unit * u, int indent, int mode);

View file

@ -160,20 +160,12 @@ xml_readrequirements(xmlNodePtr * nodeTab, int nodeNr, requirement ** reqArray)
for (req=0;req!=nodeNr;++req) {
xmlNodePtr node = nodeTab[req];
xmlChar * property;
const resource_type * rtype;
resource_t type;
radd->number = xml_ivalue(node, "quantity", 1);
radd->recycle = xml_fvalue(node, "recycle", 0.0);
property = xmlGetProp(node, BAD_CAST "type");
rtype = rt_findorcreate((const char*)property);
for (type=0;type!=MAX_RESOURCES;++type) {
if (oldresourcetype[type]==rtype) {
radd->type = type;
break;
}
}
radd->rtype = rt_findorcreate((const char*)property);
xmlFree(property);
++radd;

View file

@ -325,7 +325,7 @@ sp_combatrosthauch(fighter * fi, int level, double power, spell * sp)
requirement * mat = wp->type->itype->construction->materials;
boolean iron = false;
while (mat && mat->number>0) {
if (mat->type==R_IRON) {
if (mat->rtype==oldresourcetype[R_IRON]) {
iron = true;
break;
}