diff --git a/src/Jamrules b/src/Jamrules index fed183453..b62dde115 100644 --- a/src/Jamrules +++ b/src/Jamrules @@ -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 ; diff --git a/src/common/gamecode/creport.c b/src/common/gamecode/creport.c index d3b8422a2..5b2c39efc 100644 --- a/src/common/gamecode/creport.c +++ b/src/common/gamecode/creport.c @@ -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++; } diff --git a/src/common/gamecode/economy.c b/src/common/gamecode/economy.c index 7b6963ec5..2094b6961 100644 --- a/src/common/gamecode/economy.c +++ b/src/common/gamecode/economy.c @@ -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,"."); diff --git a/src/common/gamecode/monster.c b/src/common/gamecode/monster.c index c23755f98..763199afe 100644 --- a/src/common/gamecode/monster.c +++ b/src/common/gamecode/monster.c @@ -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 */ diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index 2f72187ff..9c978edc2 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -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(", "); } diff --git a/src/common/items/weapons.c b/src/common/items/weapons.c index b7e93183d..45b5b1296 100644 --- a/src/common/items/weapons.c +++ b/src/common/items/weapons.c @@ -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; } diff --git a/src/common/kernel/battle.c b/src/common/kernel/battle.c index 8bdb8accd..5c963bda0 100644 --- a/src/common/kernel/battle.c +++ b/src/common/kernel/battle.c @@ -909,233 +909,233 @@ terminate(troop dt, troop at, int type, const char *damage, boolean missile) #ifdef SMALL_BATTLE_MESSAGES char smallbuf[512]; #endif - item ** pitm; - fighter *df = dt.fighter; - fighter *af = at.fighter; - unit *au = af->unit; - unit *du = df->unit; - battle *b = df->side->battle; - int heiltrank = 0; - int faerie_level; - char debugbuf[512]; + item ** pitm; + fighter *df = dt.fighter; + fighter *af = at.fighter; + unit *au = af->unit; + unit *du = df->unit; + battle *b = df->side->battle; + int heiltrank = 0; + int faerie_level; + char debugbuf[512]; - /* Schild */ - void **si; - side *ds = df->side; - int hp; + /* Schild */ + void **si; + side *ds = df->side; + int hp; - int ar = 0, an, am; - const armor_type * armor = select_armor(dt, true); - const armor_type * shield = select_armor(dt, false); + int ar = 0, an, am; + const armor_type * armor = select_armor(dt, true); + const armor_type * shield = select_armor(dt, false); - const weapon_type *dwtype = NULL; - const weapon_type *awtype = NULL; - const weapon * weapon; + const weapon_type *dwtype = NULL; + const weapon_type *awtype = NULL; + const weapon * weapon; - int rda, sk = 0, sd; - boolean magic = false; - int da = dice_rand(damage); + int rda, sk = 0, sd; + boolean magic = false; + int da = dice_rand(damage); #ifdef SHOW_KILLS ++at.fighter->hits; #endif if (fval(au, UFL_WERE)) { - int level = fspecial(du->faction, FS_LYCANTROPE); - da += level; - } + int level = fspecial(du->faction, FS_LYCANTROPE); + da += level; + } - switch (type) { - case AT_STANDARD: - weapon = select_weapon(at, true, missile); - sk = weapon_effskill(at, dt, weapon, true, missile); - if (weapon) awtype = weapon->type; - if (awtype && fval(awtype, WTF_MAGICAL)) magic = true; - break; - case AT_NATURAL: - sk = weapon_effskill(at, dt, NULL, true, missile); - break; - case AT_SPELL: - case AT_COMBATSPELL: - magic = true; - break; - default: - break; - } - weapon = select_weapon(dt, false, true); /* missile=true to get the unmodified best weapon she has */ - sd = weapon_effskill(dt, at, weapon, false, false); - if (weapon!=NULL) dwtype=weapon->type; + switch (type) { + case AT_STANDARD: + weapon = select_weapon(at, true, missile); + sk = weapon_effskill(at, dt, weapon, true, missile); + if (weapon) awtype = weapon->type; + if (awtype && fval(awtype, WTF_MAGICAL)) magic = true; + break; + case AT_NATURAL: + sk = weapon_effskill(at, dt, NULL, true, missile); + break; + case AT_SPELL: + case AT_COMBATSPELL: + magic = true; + break; + default: + break; + } + weapon = select_weapon(dt, false, true); /* missile=true to get the unmodified best weapon she has */ + sd = weapon_effskill(dt, at, weapon, false, false); + if (weapon!=NULL) dwtype=weapon->type; - if (armor) ar += armor->prot; - if (shield) ar += shield->prot; + if (armor) ar += armor->prot; + if (shield) ar += shield->prot; - /* natürliche Rüstung */ - an = du->race->armor; + /* natürliche Rüstung */ + an = du->race->armor; - /* magische Rüstung durch Artefakte oder Sprüche */ - /* Momentan nur Trollgürtel und Werwolf-Eigenschaft */ - am = select_magicarmor(dt); - if(fval(du, UFL_WERE)) { - /* this counts as magical armor */ - int level = fspecial(du->faction, FS_LYCANTROPE); - am += level; - } + /* magische Rüstung durch Artefakte oder Sprüche */ + /* Momentan nur Trollgürtel und Werwolf-Eigenschaft */ + am = select_magicarmor(dt); + if(fval(du, UFL_WERE)) { + /* this counts as magical armor */ + int level = fspecial(du->faction, FS_LYCANTROPE); + am += level; + } #if CHANGED_CROSSBOWS == 1 - if(awtype && fval(awtype,WTF_ARMORPIERCING)) { - /* crossbows */ - ar /= 2; - an /= 2; - } + if(awtype && fval(awtype,WTF_ARMORPIERCING)) { + /* crossbows */ + ar /= 2; + an /= 2; + } #endif - /* natürliche Rüstung ist halbkumulativ */ - if (ar>0) { - ar += an/2; - } else { - ar = an; - } - ar += am; + /* natürliche Rüstung ist halbkumulativ */ + if (ar>0) { + ar += an/2; + } else { + ar = an; + } + ar += am; - if (type!=AT_COMBATSPELL && type!=AT_SPELL) /* Kein Zauber, normaler Waffenschaden */ - { - double kritchance = (sk * 3 - sd) / 200.0; - kritchance = max(kritchance, 0.005); - kritchance = min(0.9, kritchance); + if (type!=AT_COMBATSPELL && type!=AT_SPELL) /* Kein Zauber, normaler Waffenschaden */ + { + double kritchance = (sk * 3 - sd) / 200.0; + kritchance = max(kritchance, 0.005); + kritchance = min(0.9, kritchance); - while (chance(kritchance)) { - sprintf(debugbuf, - "%s/%d landet einen kritischen Treffer", unitid(au), at.index); - battledebug(debugbuf); - da += dice_rand(damage); - } + while (chance(kritchance)) { + sprintf(debugbuf, + "%s/%d landet einen kritischen Treffer", unitid(au), at.index); + battledebug(debugbuf); + da += dice_rand(damage); + } - da += rc_specialdamage(au->race, du->race, awtype); + da += rc_specialdamage(au->race, du->race, awtype); #ifdef KARMA_MODULE - da += jihad(au->faction, du->race); + da += jihad(au->faction, du->race); #endif - faerie_level = fspecial(du->faction, FS_FAERIE); - if (type == AT_STANDARD && faerie_level) { - int c; + faerie_level = fspecial(du->faction, FS_FAERIE); + if (type == AT_STANDARD && faerie_level) { + int c; - for (c=0;weapon->type->itype->construction->materials[c].number; c++) { - if(weapon->type->itype->construction->materials[c].type == R_IRON) { - da += faerie_level; - break; - } - } - } - - if (awtype!=NULL && fval(awtype, WTF_MISSILE)) { - /* Fernkampfschadenbonus */ - da += af->person[at.index].damage_rear; - } else if (awtype==NULL) { - /* Waffenloser kampf, bonus von talentwert*/ - da += effskill(au, SK_WEAPONLESS); - } else { - /* Nahkampfschadensbonus */ - da += af->person[at.index].damage; - } - - /* Skilldifferenzbonus */ - da += max(0, (sk-sd)/DAMAGE_QUOTIENT); + for (c=0;weapon->type->itype->construction->materials[c].number; c++) { + if(weapon->type->itype->construction->materials[c].rtype == oldresourcetype[R_IRON]) { + da += faerie_level; + break; + } } + } + + if (awtype!=NULL && fval(awtype, WTF_MISSILE)) { + /* Fernkampfschadenbonus */ + da += af->person[at.index].damage_rear; + } else if (awtype==NULL) { + /* Waffenloser kampf, bonus von talentwert*/ + da += effskill(au, SK_WEAPONLESS); + } else { + /* Nahkampfschadensbonus */ + da += af->person[at.index].damage; + } + + /* Skilldifferenzbonus */ + da += max(0, (sk-sd)/DAMAGE_QUOTIENT); + } - if (magic) /* Magischer Schaden durch Spruch oder magische Waffe */ - { - double res = 1.0; + if (magic) /* Magischer Schaden durch Spruch oder magische Waffe */ + { + double res = 1.0; - /* magic_resistance gib x% Resistenzbonus zurück */ - res -= magic_resistance(du)*3.0; + /* magic_resistance gib x% Resistenzbonus zurück */ + res -= magic_resistance(du)*3.0; - if (du->race->battle_flags & BF_EQUIPMENT) { + if (du->race->battle_flags & BF_EQUIPMENT) { #ifdef TODO_RUNESWORD - /* Runenschwert gibt im Kampf 80% Resistenzbonus */ - if (dwp == WP_RUNESWORD) res -= 0.80; + /* Runenschwert gibt im Kampf 80% Resistenzbonus */ + if (dwp == WP_RUNESWORD) res -= 0.80; #endif - /* der Effekt von Laen steigt nicht linear */ - if (armor && fval(armor, ATF_LAEN)) res *= (1-armor->magres); - if (shield && fval(shield, ATF_LAEN)) res *= (1-shield->magres); - if (dwtype) res *= (1-dwtype->magres); - } + /* der Effekt von Laen steigt nicht linear */ + if (armor && fval(armor, ATF_LAEN)) res *= (1-armor->magres); + if (shield && fval(shield, ATF_LAEN)) res *= (1-shield->magres); + if (dwtype) res *= (1-dwtype->magres); + } - if (res > 0) { - da = (int) (max(da * res, 0)); - } - /* gegen Magie wirkt nur natürliche und magische Rüstung */ - ar = an+am; - } + if (res > 0) { + da = (int) (max(da * res, 0)); + } + /* gegen Magie wirkt nur natürliche und magische Rüstung */ + ar = an+am; + } - rda = max(da - ar,0); + rda = max(da - ar,0); - if ((du->race->battle_flags & BF_INV_NONMAGIC) && !magic) rda = 0; - else { - unsigned int i = 0; - if (du->race->battle_flags & BF_RES_PIERCE) i |= WTF_PIERCE; - if (du->race->battle_flags & BF_RES_CUT) i |= WTF_CUT; - if (du->race->battle_flags & BF_RES_BASH) i |= WTF_BLUNT; + if ((du->race->battle_flags & BF_INV_NONMAGIC) && !magic) rda = 0; + else { + unsigned int i = 0; + if (du->race->battle_flags & BF_RES_PIERCE) i |= WTF_PIERCE; + if (du->race->battle_flags & BF_RES_CUT) i |= WTF_CUT; + if (du->race->battle_flags & BF_RES_BASH) i |= WTF_BLUNT; - if (i && awtype && fval(awtype, i)) rda /= 2; + if (i && awtype && fval(awtype, i)) rda /= 2; - /* Schilde */ - for (si = b->meffects.begin; si != b->meffects.end; ++si) { - meffect *meffect = *si; - if (meffect_protection(b, meffect, ds) != 0) { - assert(0 <= rda); /* rda sollte hier immer mindestens 0 sein */ + /* Schilde */ + for (si = b->meffects.begin; si != b->meffects.end; ++si) { + meffect *meffect = *si; + if (meffect_protection(b, meffect, ds) != 0) { + assert(0 <= rda); /* rda sollte hier immer mindestens 0 sein */ /* jeder Schaden wird um effect% reduziert bis der Schild duration * Trefferpunkte aufgefangen hat */ - if (meffect->typ == SHIELD_REDUCE) { - hp = rda * (meffect->effect/100); - rda -= hp; - meffect->duration -= hp; - } + if (meffect->typ == SHIELD_REDUCE) { + hp = rda * (meffect->effect/100); + rda -= hp; + meffect->duration -= hp; + } /* gibt Rüstung +effect für duration Treffer */ - if (meffect->typ == SHIELD_ARMOR) { - rda = max(rda - meffect->effect, 0); - meffect->duration--; - } - } - } + if (meffect->typ == SHIELD_ARMOR) { + rda = max(rda - meffect->effect, 0); + meffect->duration--; } + } + } + } - sprintf(debugbuf, "Verursacht %dTP, Rüstung %d: %d -> %d HP", - da, ar, df->person[dt.index].hp, df->person[dt.index].hp - rda); + sprintf(debugbuf, "Verursacht %dTP, Rüstung %d: %d -> %d HP", + da, ar, df->person[dt.index].hp, df->person[dt.index].hp - rda); #ifdef SMALL_BATTLE_MESSAGES - if (b->small) { - if (rda > 0) { - sprintf(smallbuf, "Der Treffer verursacht %s", - rel_dam(rda, df->person[dt.index].hp)); - } else { - sprintf(smallbuf, "Der Treffer verursacht keinen Schaden"); - } - } + if (b->small) { + if (rda > 0) { + sprintf(smallbuf, "Der Treffer verursacht %s", + rel_dam(rda, df->person[dt.index].hp)); + } else { + sprintf(smallbuf, "Der Treffer verursacht keinen Schaden"); + } + } #endif - assert(dt.indexnumber); - df->person[dt.index].hp -= rda; + assert(dt.indexnumber); + df->person[dt.index].hp -= rda; - if (df->person[dt.index].hp > 0) { /* Hat überlebt */ - battledebug(debugbuf); - if (au->race == new_race[RC_DAEMON]) { + if (df->person[dt.index].hp > 0) { /* Hat überlebt */ + battledebug(debugbuf); + if (au->race == new_race[RC_DAEMON]) { #ifdef TODO_RUNESWORD - if (select_weapon(dt, 0, -1) == WP_RUNESWORD) continue; + if (select_weapon(dt, 0, -1) == WP_RUNESWORD) continue; #endif - if (!(df->person[dt.index].flags & (FL_COURAGE|FL_DAZZLED))) { - df->person[dt.index].flags |= FL_DAZZLED; - df->person[dt.index].defence--; - } - } - df->person[dt.index].flags = (df->person[dt.index].flags & ~FL_SLEEPING); + if (!(df->person[dt.index].flags & (FL_COURAGE|FL_DAZZLED))) { + df->person[dt.index].flags |= FL_DAZZLED; + df->person[dt.index].defence--; + } + } + df->person[dt.index].flags = (df->person[dt.index].flags & ~FL_SLEEPING); #ifdef SMALL_BATTLE_MESSAGES - if (b->small) { - strcat(smallbuf, "."); - battlerecord(b, smallbuf); - } + if (b->small) { + strcat(smallbuf, "."); + battlerecord(b, smallbuf); + } #endif - return false; - } + return false; + } #ifdef SHOW_KILLS ++at.fighter->kills; #endif @@ -1146,8 +1146,8 @@ terminate(troop dt, troop at, int type, const char *damage, boolean missile) } #endif - /* Sieben Leben */ - if (du->race == new_race[RC_CAT] && (chance(1.0 / 7))) { + /* Sieben Leben */ + if (du->race == new_race[RC_CAT] && (chance(1.0 / 7))) { #ifdef SMALL_BATTLE_MESSAGES if (b->small) { strcat(smallbuf, ", doch die Katzengöttin ist gnädig"); @@ -1157,52 +1157,52 @@ terminate(troop dt, troop at, int type, const char *damage, boolean missile) assert(dt.index>=0 && dt.indexnumber); df->person[dt.index].hp = unit_max_hp(du); return false; - } + } - /* Heiltrank schluerfen und hoffen */ - if (get_effect(du, oldpotiontype[P_HEAL]) > 0) { - change_effect(du, oldpotiontype[P_HEAL], -1); - heiltrank = 1; - } else if (i_get(du->items, oldpotiontype[P_HEAL]->itype) > 0) { - i_change(&du->items, oldpotiontype[P_HEAL]->itype, -1); - change_effect(du, oldpotiontype[P_HEAL], 3); - heiltrank = 1; - } - if (heiltrank && (chance(0.50))) { + /* Heiltrank schluerfen und hoffen */ + if (get_effect(du, oldpotiontype[P_HEAL]) > 0) { + change_effect(du, oldpotiontype[P_HEAL], -1); + heiltrank = 1; + } else if (i_get(du->items, oldpotiontype[P_HEAL]->itype) > 0) { + i_change(&du->items, oldpotiontype[P_HEAL]->itype, -1); + change_effect(du, oldpotiontype[P_HEAL], 3); + heiltrank = 1; + } + if (heiltrank && (chance(0.50))) { #ifdef SMALL_BATTLE_MESSAGES - if (b->small) { - strcat(smallbuf, ", doch ein Heiltrank bringt Rettung"); - battlerecord(b, smallbuf); - } else + if (b->small) { + strcat(smallbuf, ", doch ein Heiltrank bringt Rettung"); + battlerecord(b, smallbuf); + } else #endif - { - message * m = msg_message("battle::potionsave", "unit", du); - message_faction(b, du->faction, m); - msg_release(m); - } + { + message * m = msg_message("battle::potionsave", "unit", du); + message_faction(b, du->faction, m); + msg_release(m); + } assert(dt.index>=0 && dt.indexnumber); df->person[dt.index].hp = du->race->hitpoints; return false; } - strcat(debugbuf, ", tot"); - battledebug(debugbuf); + strcat(debugbuf, ", tot"); + battledebug(debugbuf); #ifdef SMALL_BATTLE_MESSAGES - if (b->small) { - strcat(smallbuf, "."); - battlerecord(b, smallbuf); - } + if (b->small) { + strcat(smallbuf, "."); + battlerecord(b, smallbuf); + } #endif - for (pitm=&du->items; *pitm; pitm=&(*pitm)->next) { - const item_type * itype = (*pitm)->type; - if (!itype->flags & ITF_CURSED && dt.index < (*pitm)->number) { - /* 25% Grundchance, das ein Item kaputtgeht. */ - if (rand() % 4 < 1) i_change(pitm, itype, -1); - } - } - remove_troop(dt); + for (pitm=&du->items; *pitm; pitm=&(*pitm)->next) { + const item_type * itype = (*pitm)->type; + if (!itype->flags & ITF_CURSED && dt.index < (*pitm)->number) { + /* 25% Grundchance, das ein Item kaputtgeht. */ + if (rand() % 4 < 1) i_change(pitm, itype, -1); + } + } + remove_troop(dt); - return true; + return true; } static int diff --git a/src/common/kernel/build.c b/src/common/kernel/build.c index 0b777d4de..e2229bdd3 100644 --- a/src/common/kernel/build.c +++ b/src/common/kernel/build.c @@ -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 (havethisorder, 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", diff --git a/src/common/kernel/build.h b/src/common/kernel/build.h index 1a0e44096..e00cff43d 100644 --- a/src/common/kernel/build.h +++ b/src/common/kernel/build.h @@ -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; diff --git a/src/common/kernel/eressea.h b/src/common/kernel/eressea.h index d00ae038f..7b4b25794 100644 --- a/src/common/kernel/eressea.h +++ b/src/common/kernel/eressea.h @@ -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; diff --git a/src/common/kernel/item.c b/src/common/kernel/item.c index ccf14dc31..fcc8448de 100644 --- a/src/common/kernel/item.c +++ b/src/common/kernel/item.c @@ -1103,124 +1103,124 @@ static translate_t translation[] = { static void init_olditems(void) { - item_t i; - resource_type * rtype; + item_t i; + resource_type * rtype; - const struct locale * lang = find_locale("de"); - assert(lang); + const struct locale * lang = find_locale("de"); + assert(lang); - for (i=0; i!=MAXITEMS; ++i) { - int iflags = ITF_NONE; - int rflags = RTF_ITEM|RTF_POOLED; - int m, n; - const char * name[2]; - const char * appearance[2]; - int weight = itemdata[i].gewicht; - int capacity = 0; - int price; - attrib * a; - item_type * itype; - construction * con = calloc(sizeof(construction), 1); + for (i=0; i!=MAXITEMS; ++i) { + int iflags = ITF_NONE; + int rflags = RTF_ITEM|RTF_POOLED; + int m, n; + const char * name[2]; + const char * appearance[2]; + int weight = itemdata[i].gewicht; + int capacity = 0; + int price; + attrib * a; + item_type * itype; + construction * con = calloc(sizeof(construction), 1); - con->minskill = itemdata[i].minskill; - if (i==I_LAEN && SkillCap(SK_QUARRYING)) { - /* at least 4 levels on which you can mine laen */ - con->minskill = SkillCap(SK_QUARRYING)-3; - } - con->skill = itemdata[i].skill; - con->maxsize = -1; - con->reqsize = 1; - con->improvement = NULL; + con->minskill = itemdata[i].minskill; + if (i==I_LAEN && SkillCap(SK_QUARRYING)) { + /* at least 4 levels on which you can mine laen */ + con->minskill = SkillCap(SK_QUARRYING)-3; + } + con->skill = itemdata[i].skill; + con->maxsize = -1; + con->reqsize = 1; + con->improvement = NULL; - for (m=0, n=0;m!=M_MAX_MAT;++m) - if (itemdata[i].material[m]>0) ++n; - if (n>0) { - 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].number = itemdata[i].material[m]; - con->materials[n].recycle = 0.0; - ++n; - if (m==M_EISEN) { - } - } - } - } - if (itemdata[i].flags & FL_ITEM_CURSED) iflags |= ITF_CURSED; - if (itemdata[i].flags & FL_ITEM_NOTLOST) iflags |= ITF_NOTLOST; - if (itemdata[i].flags & FL_ITEM_NOTINBAG) iflags |= ITF_BIG; - if (itemdata[i].typ == IS_LUXURY) iflags |= ITF_LUXURY; - if (itemdata[i].flags & FL_ITEM_ANIMAL) iflags |= ITF_ANIMAL; - - name[0]=NULL; - { - int ci; - for (ci=0;translation[ci][0];++ci) { - if (!strcmp(translation[ci][0], itemdata[i].name[0])) { - name[0] = translation[ci][1]; - name[1] = translation[ci][2]; - appearance[0] = translation[ci][3]; - appearance[1] = translation[ci][4]; - } - } - } - if (name[0]==NULL) { - name[0] = reverse_lookup(lang, itemdata[i].name[0]); - name[1] = reverse_lookup(lang, itemdata[i].name[1]); - appearance[0] = reverse_lookup(lang, itemdata[i].name[2]); - appearance[1] = reverse_lookup(lang, itemdata[i].name[3]); - } - rtype = new_resourcetype(name, appearance, rflags); - itype = new_itemtype(rtype, iflags, weight, capacity); - - switch (i) { - case I_HORSE: - case I_UNICORN: - itype->capacity = HORSECAPACITY; - itype->give = give_horses; - break; - case I_WAGON: - itype->capacity = WAGONCAPACITY; - break; - case I_BAG_OF_HOLDING: - itype->capacity = BAGCAPACITY; - break; - case I_TROLLBELT: - /* This is wrong. according to the item description it multiplies - * the strength of the wearer by a factor of - * 50 (STRENGTHMULTIPLIER), not add a fixed 50000 */ - /* only used in battle.c for items of type ITF_ANIMAL */ - itype->capacity = STRENGTHCAPACITY; - break; - default: - if (itemdata[i].flags & FL_ITEM_MOUNT) itype->capacity = HORSECAPACITY; - } - - /* itemdata::typ Analyse. IS_PRODUCT und IS_MAGIC sind so gut wie egal. */ - switch (itemdata[i].typ) { - case IS_LUXURY: - price = itemdata[i].preis; - oldluxurytype[i-FIRSTLUXURY] = new_luxurytype(itype, price); - break; - case IS_RESOURCE: - rtype->flags |= RTF_LIMITED; - itype->flags |= ITF_NOBUILDBESIEGED; - a = a_add(&rtype->attribs, a_new(&at_resourcelimit)); - { - resource_limit * rdata = (resource_limit*)a->data.v; - rdata->limit = limit_oldtypes; - rdata->use = use_oldresource; - } - break; - } - if (itemdata[i].benutze_funktion) { - itype->use = use_olditem; - } - itype->construction = con; - olditemtype[i] = itype; - oldresourcetype[item2res(i)] = rtype; + for (m=0, n=0;m!=M_MAX_MAT;++m) + if (itemdata[i].material[m]>0) ++n; + if (n>0) { + 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].rtype = oldresourcetype[matresource[m]]; + con->materials[n].number = itemdata[i].material[m]; + con->materials[n].recycle = 0.0; + ++n; + if (m==M_EISEN) { + } } + } + } + if (itemdata[i].flags & FL_ITEM_CURSED) iflags |= ITF_CURSED; + if (itemdata[i].flags & FL_ITEM_NOTLOST) iflags |= ITF_NOTLOST; + if (itemdata[i].flags & FL_ITEM_NOTINBAG) iflags |= ITF_BIG; + if (itemdata[i].typ == IS_LUXURY) iflags |= ITF_LUXURY; + if (itemdata[i].flags & FL_ITEM_ANIMAL) iflags |= ITF_ANIMAL; + + name[0]=NULL; + { + int ci; + for (ci=0;translation[ci][0];++ci) { + if (!strcmp(translation[ci][0], itemdata[i].name[0])) { + name[0] = translation[ci][1]; + name[1] = translation[ci][2]; + appearance[0] = translation[ci][3]; + appearance[1] = translation[ci][4]; + } + } + } + if (name[0]==NULL) { + name[0] = reverse_lookup(lang, itemdata[i].name[0]); + name[1] = reverse_lookup(lang, itemdata[i].name[1]); + appearance[0] = reverse_lookup(lang, itemdata[i].name[2]); + appearance[1] = reverse_lookup(lang, itemdata[i].name[3]); + } + rtype = new_resourcetype(name, appearance, rflags); + itype = new_itemtype(rtype, iflags, weight, capacity); + + switch (i) { + case I_HORSE: + case I_UNICORN: + itype->capacity = HORSECAPACITY; + itype->give = give_horses; + break; + case I_WAGON: + itype->capacity = WAGONCAPACITY; + break; + case I_BAG_OF_HOLDING: + itype->capacity = BAGCAPACITY; + break; + case I_TROLLBELT: + /* This is wrong. according to the item description it multiplies + * the strength of the wearer by a factor of + * 50 (STRENGTHMULTIPLIER), not add a fixed 50000 */ + /* only used in battle.c for items of type ITF_ANIMAL */ + itype->capacity = STRENGTHCAPACITY; + break; + default: + if (itemdata[i].flags & FL_ITEM_MOUNT) itype->capacity = HORSECAPACITY; + } + + /* itemdata::typ Analyse. IS_PRODUCT und IS_MAGIC sind so gut wie egal. */ + switch (itemdata[i].typ) { + case IS_LUXURY: + price = itemdata[i].preis; + oldluxurytype[i-FIRSTLUXURY] = new_luxurytype(itype, price); + break; + case IS_RESOURCE: + rtype->flags |= RTF_LIMITED; + itype->flags |= ITF_NOBUILDBESIEGED; + a = a_add(&rtype->attribs, a_new(&at_resourcelimit)); + { + resource_limit * rdata = (resource_limit*)a->data.v; + rdata->limit = limit_oldtypes; + rdata->use = use_oldresource; + } + break; + } + if (itemdata[i].benutze_funktion) { + itype->use = use_olditem; + } + itype->construction = con; + olditemtype[i] = itype; + oldresourcetype[item2res(i)] = rtype; + } } static const char *potiontext[MAXPOTIONS] = @@ -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) { diff --git a/src/common/kernel/item.h b/src/common/kernel/item.h index e3589b7ec..9c1869b4e 100644 --- a/src/common/kernel/item.h +++ b/src/common/kernel/item.h @@ -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 diff --git a/src/common/kernel/karma.c b/src/common/kernel/karma.c index 173053332..a54d6c4b0 100644 --- a/src/common/kernel/karma.c +++ b/src/common/kernel/karma.c @@ -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; diff --git a/src/common/kernel/pool.c b/src/common/kernel/pool.c index 3e5b3e100..85f31a620 100644 --- a/src/common/kernel/pool.c +++ b/src/common/kernel/pool.c @@ -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 diff --git a/src/common/kernel/pool.h b/src/common/kernel/pool.h index ddd4fd9f7..6d3fe4b20 100644 --- a/src/common/kernel/pool.h +++ b/src/common/kernel/pool.h @@ -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 diff --git a/src/common/kernel/reports.h b/src/common/kernel/reports.h index 881bf6550..f724edab8 100644 --- a/src/common/kernel/reports.h +++ b/src/common/kernel/reports.h @@ -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); diff --git a/src/common/kernel/xmlreader.c b/src/common/kernel/xmlreader.c index 8b982a0a3..fe0b494c0 100644 --- a/src/common/kernel/xmlreader.c +++ b/src/common/kernel/xmlreader.c @@ -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; diff --git a/src/common/spells/combatspells.c b/src/common/spells/combatspells.c index 1b9821c0a..6b91a418a 100644 --- a/src/common/spells/combatspells.c +++ b/src/common/spells/combatspells.c @@ -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; }