From 120508716ec0296b9961e62b0d804aadf8a9d6ae Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 18 May 2009 20:50:19 +0000 Subject: [PATCH] - equipping newly recruited units - cavalry skill bonus - chargers - configurable hunger --- src/common/gamecode/economy.c | 10 +++-- src/common/kernel/battle.c | 78 +++++++++++++++++++++++++++++++---- src/common/kernel/eressea.c | 15 ++++++- src/common/kernel/magic.h | 2 +- src/common/kernel/xmlreader.c | 5 +++ src/res/e2k9.xml | 4 ++ src/res/e2k9/items.xml | 1 + src/res/e2k9/races.xml | 13 +++--- src/res/e2k9/strings.xml | 9 ++++ src/res/e2k9/weapons.xml | 24 +++++++++++ src/res/eressea.xml | 1 + src/res/races.xml | 1 + 12 files changed, 143 insertions(+), 20 deletions(-) diff --git a/src/common/gamecode/economy.c b/src/common/gamecode/economy.c index 7ce5f0703..5369e5492 100644 --- a/src/common/gamecode/economy.c +++ b/src/common/gamecode/economy.c @@ -234,6 +234,8 @@ add_recruits(unit * u, int number, int wanted) assert(number<=wanted); if (number > 0) { unit * unew; + char equipment[64]; + #if KARMA_MODULE int i = fspecial(u->faction, FS_MILITIA); #endif /* KARMA_MODULE */ @@ -246,10 +248,10 @@ add_recruits(unit * u, int number, int wanted) unew = create_unit(r, u->faction, number, u->race, 0, NULL, u); } - if (unew->race == new_race[RC_URUK]) { - change_level(unew, SK_MELEE, 1); - change_level(unew, SK_SPEAR, 1); - } + snprintf(equipment, sizeof(equipment), "new_%s_unit", u->race->_name[0]); + equip_unit(unew, get_equipment(equipment)); + + if (unew->race->ec_flags & ECF_REC_HORSES) { change_level(unew, SK_RIDING, 1); } diff --git a/src/common/kernel/battle.c b/src/common/kernel/battle.c index e9bf0805d..8a593795b 100644 --- a/src/common/kernel/battle.c +++ b/src/common/kernel/battle.c @@ -699,6 +699,34 @@ weapon_skill(const weapon_type * wtype, const unit * u, boolean attacking) return skill; } +static int CavalrySkill(void) +{ + static int skill = -1; + + if (skill<0) { + skill = get_param_int(global.parameters, "rules.cavalry.skill", 2); + } + return skill; +} + +static int +CavalryBonus(const unit * u) +{ + static int mode = -1; + if (mode<0) { + mode = get_param_int(global.parameters, "rules.cavalry.mode", 1); + } + if (mode==0) { + /* old rule, Eressea 1.0 compat */ + return 2; + } else { + /* new rule, chargers in Eressea 1.1 */ + int skl = effskill(u, SK_RIDING); + skl = skl*3/2-3; + return MAX(skl, 0); + } +} + static int weapon_effskill(troop t, troop enemy, const weapon * w, boolean attacking, boolean missile) /* effektiver Waffenskill während des Kampfes */ @@ -747,7 +775,7 @@ weapon_effskill(troop t, troop enemy, const weapon * w, boolean attacking, boole /* Burgenbonus, Pferdebonus */ if (is_riding(t) && (wtype==NULL || (fval(wtype, WTF_HORSEBONUS) && !fval(wtype, WTF_MISSILE)))) { - skill += 2; + skill += CavalryBonus(tu); if (wtype) skill = skillmod(urace(tu)->attribs, tu, tu->region, wtype->skill, skill, SMF_RIDING); } @@ -2191,6 +2219,37 @@ add_tactics(tactics * ta, fighter * fig, int value) ta->value = value; } +static double horsebonus(const unit * u) +{ + static const item_type * it_horse = 0; + static const item_type * it_elvenhorse = 0; + static const item_type * it_charger = 0; + region * r = u->region; + int n1 = 0, n2 = 0, n3 = 0; + item * itm = u->items; + int skl = eff_skill(u, SK_RIDING, r); + + if (skl<1) return 0.0; + + if (it_horse==0) { + it_horse = it_find("horse"); + it_elvenhorse = it_find("elvenhorse"); + it_charger = it_find("charger"); + } + + while (itm) { + if (itm->type->flags&ITF_ANIMAL) { + if (itm->type==it_elvenhorse) n3 +=itm->number; + else if (itm->type==it_charger) n2 +=itm->number; + else if (itm->type==it_horse) n1 +=itm->number; + } + } + if (skl >= 5 && n3>=u->number) return 0.30; + if (skl >= 3 && n2+n3>=u->number) return 0.20; + if (skl >= 1 && n1+n2+n3>=u->number) return 0.10; + return 0.0F; +} + double fleechance(unit * u) { @@ -2200,11 +2259,7 @@ fleechance(unit * u) /* Einheit u versucht, dem Getümmel zu entkommen */ c += (eff_skill(u, SK_STEALTH, r) * 0.05); - - if (get_item(u, I_ELVENHORSE) >= u->number && eff_skill(u, SK_RIDING, r) >= 5) - c += 0.30; - else if (get_item(u, I_HORSE) >= u->number && eff_skill(u, SK_RIDING, r) >= 1) - c += 0.10; + c += horsebonus(u); if (u->race == new_race[RC_HALFLING]) { c += 0.20; @@ -3214,7 +3269,14 @@ make_fighter(battle * b, unit * u, side * s1, boolean attack) fig->horses = fig->unit->number; fig->elvenhorses = 0; } else { - fig->horses = get_item(u, I_HORSE); + static const item_type * it_charger = 0; + if (it_charger==0) { + it_charger = it_find("charger"); + if (!it_charger) { + it_charger = it_find("horse"); + } + } + fig->horses = i_get(u->items, it_charger); fig->elvenhorses = get_item(u, I_ELVENHORSE); } @@ -3244,7 +3306,7 @@ make_fighter(battle * b, unit * u, side * s1, boolean attack) if (fig->horses) { if (!fval(r->terrain, CAVALRY_REGION) || r_isforest(r) - || eff_skill(u, SK_RIDING, r) < 2 || u->race == new_race[RC_TROLL] || fval(u, UFL_WERE)) + || eff_skill(u, SK_RIDING, r) < CavalrySkill() || u->race == new_race[RC_TROLL] || fval(u, UFL_WERE)) fig->horses = 0; } diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index aad474e5a..c43396b18 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -63,6 +63,7 @@ #include #include #include +#include #include #include #include @@ -2509,9 +2510,21 @@ hunger(int number, unit * u) region * r = u->region; int dead = 0, hpsub = 0; int hp = u->hp / u->number; + static const char * damage = 0; + static const char * rcdamage = 0; + static const race * rc = 0; + + if (!damage) { + damage = get_param(global.parameters, "hunger.damage"); + if (damage==NULL) damage = "1d12+12"; + } + if (rc!=u->race) { + rcdamage = get_param(u->race->parameters, "hunger.damage"); + rc = u->race; + } while (number--) { - int dam = u->race==new_race[RC_HALFLING]?15+rng_int()%14:(13+rng_int()%12); + int dam = dice_rand(rcdamage?rcdamage:damage); if (dam >= hp) { ++dead; } else { diff --git a/src/common/kernel/magic.h b/src/common/kernel/magic.h index 77389b761..53cec18a4 100644 --- a/src/common/kernel/magic.h +++ b/src/common/kernel/magic.h @@ -171,7 +171,7 @@ typedef struct spell { typedef struct spell_list { struct spell_list * next; - spell * data; + spell * data; /* TODO: should be const */ } spell_list; extern void spelllist_add(spell_list ** lspells, struct spell * sp); diff --git a/src/common/kernel/xmlreader.c b/src/common/kernel/xmlreader.c index b13289ef2..9e2846b80 100644 --- a/src/common/kernel/xmlreader.c +++ b/src/common/kernel/xmlreader.c @@ -1332,22 +1332,27 @@ parse_equipment(xmlDocPtr doc) xpath->node = node; xpathResult = xmlXPathEvalExpression(BAD_CAST "callback", xpath); + assert(!eq->callback); add_callbacks(eq, xpathResult->nodesetval); xmlXPathFreeObject(xpathResult); xpathResult = xmlXPathEvalExpression(BAD_CAST "item", xpath); + assert(!eq->items); add_items(eq, xpathResult->nodesetval); xmlXPathFreeObject(xpathResult); xpathResult = xmlXPathEvalExpression(BAD_CAST "spell", xpath); + assert(!eq->spells); add_spells(eq, xpathResult->nodesetval); xmlXPathFreeObject(xpathResult); xpathResult = xmlXPathEvalExpression(BAD_CAST "skill", xpath); + assert(!eq->skills); add_skills(eq, xpathResult->nodesetval); xmlXPathFreeObject(xpathResult); xpathResult = xmlXPathEvalExpression(BAD_CAST "subset", xpath); + assert(!eq->subsets); add_subsets(doc, eq, xpathResult->nodesetval); xmlXPathFreeObject(xpathResult); diff --git a/src/res/e2k9.xml b/src/res/e2k9.xml index 30f570829..fb6b8bb4d 100644 --- a/src/res/e2k9.xml +++ b/src/res/e2k9.xml @@ -26,6 +26,7 @@ + @@ -108,11 +109,14 @@ + + + diff --git a/src/res/e2k9/items.xml b/src/res/e2k9/items.xml index 9fde522db..9b2c517e5 100644 --- a/src/res/e2k9/items.xml +++ b/src/res/e2k9/items.xml @@ -6,6 +6,7 @@ + diff --git a/src/res/e2k9/races.xml b/src/res/e2k9/races.xml index bfe91263d..b08027677 100644 --- a/src/res/e2k9/races.xml +++ b/src/res/e2k9/races.xml @@ -6,6 +6,7 @@ + @@ -24,7 +25,7 @@ - + @@ -64,7 +65,7 @@ - + @@ -91,7 +92,7 @@ - + @@ -114,7 +115,7 @@ - + @@ -136,7 +137,7 @@ - + @@ -159,7 +160,7 @@ - + diff --git a/src/res/e2k9/strings.xml b/src/res/e2k9/strings.xml index bb050831b..d04113a11 100644 --- a/src/res/e2k9/strings.xml +++ b/src/res/e2k9/strings.xml @@ -19,4 +19,13 @@ Wache watch + + + Streitross + charger + + + Streitrösser + chargers + diff --git a/src/res/e2k9/weapons.xml b/src/res/e2k9/weapons.xml index acb3b9b48..4810f3688 100644 --- a/src/res/e2k9/weapons.xml +++ b/src/res/e2k9/weapons.xml @@ -28,4 +28,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/res/eressea.xml b/src/res/eressea.xml index c6bd55360..7bbe7408a 100644 --- a/src/res/eressea.xml +++ b/src/res/eressea.xml @@ -19,6 +19,7 @@ + diff --git a/src/res/races.xml b/src/res/races.xml index affd7ef7a..8235c8307 100644 --- a/src/res/races.xml +++ b/src/res/races.xml @@ -807,6 +807,7 @@ +