From e939b5fdc9123bf2758ad91c0149b6aad196caca Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 5 Jun 2009 22:54:50 +0000 Subject: [PATCH] - vampirism - stamina -> nat. armor --- src/common/kernel/battle.c | 40 +++++++++++++++++++++++++++++++++++++- src/common/kernel/race.c | 2 ++ src/common/kernel/race.h | 3 +++ src/res/e2k9.xml | 1 + src/res/e2k9/races.xml | 3 ++- 5 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/common/kernel/battle.c b/src/common/kernel/battle.c index 544f71d4b..ee45d5223 100644 --- a/src/common/kernel/battle.c +++ b/src/common/kernel/battle.c @@ -1022,6 +1022,41 @@ rel_dam(int dam, int hp) return "eine kleine Wunde"; } +static void vampirism(troop at, int damage) +{ + static int vampire = -1; + if (vampire<0) vampire = get_param_int(global.parameters, "rules.combat.demon_vampire", 0); + if (vampire>0) { + int gain = damage/vampire; + int chance = damage - vampire * gain; + if (chance>0 && (rng_int() % vampire < chance)) ++gain; + if (gain>0) { + int maxhp = unit_max_hp(at.fighter->unit); + at.fighter->person[at.index].hp = MIN(gain+at.fighter->person[at.index].hp, maxhp); + } + } +} + +static int +natural_armor(unit * du) +{ + static int * bonus = 0; + int an = du->race->armor; + if (bonus==0) { + bonus = calloc(sizeof(int), num_races); + } + if (bonus[du->race->index]==0) { + bonus[du->race->index] = get_param_int(du->race->parameters, "armor.stamina", -1); + if (bonus[du->race->index]==0) bonus[du->race->index] = -1; + } + if (bonus[du->race->index]>0) { + int sk = effskill(du, SK_STAMINA); + sk /= bonus[du->race->index]; + an += sk; + } + return an; +} + boolean terminate(troop dt, troop at, int type, const char *damage, boolean missile) { @@ -1097,7 +1132,7 @@ terminate(troop dt, troop at, int type, const char *damage, boolean missile) } /* natürliche Rüstung */ - an = du->race->armor; + an = natural_armor(du); /* magische Rüstung durch Artefakte oder Sprüche */ /* Momentan nur Trollgürtel und Werwolf-Eigenschaft */ @@ -1243,6 +1278,9 @@ terminate(troop dt, troop at, int type, const char *damage, boolean missile) assert(dt.indexnumber); df->person[dt.index].hp -= rda; + if (au->race==new_race[RC_DAEMON]) { + vampirism(at, rda); + } if (df->person[dt.index].hp > 0) { /* Hat überlebt */ if (bdebug) { diff --git a/src/common/kernel/race.c b/src/common/kernel/race.c index 80411b928..dce50a583 100644 --- a/src/common/kernel/race.c +++ b/src/common/kernel/race.c @@ -64,6 +64,7 @@ /** external variables **/ race * races; +int num_races = 0; race_list * get_familiarraces(void) @@ -131,6 +132,7 @@ rc_new(const char * zName) race * rc_add(race * rc) { + rc->index = num_races++; rc->next = races; return races = rc; } diff --git a/src/common/kernel/race.h b/src/common/kernel/race.h index e67486eb4..1484e69d9 100644 --- a/src/common/kernel/race.h +++ b/src/common/kernel/race.h @@ -52,6 +52,8 @@ typedef struct att { struct param; +extern int num_races; + typedef struct race { struct param * parameters; const char *_name[4]; /* neu: name[4]völker */ @@ -59,6 +61,7 @@ typedef struct race { float maxaura; /* Faktor auf Maximale Aura */ float regaura; /* Faktor auf Regeneration */ float recruit_multi; /* Faktor für Bauernverbrauch */ + int index; int recruitcost; int maintenance; int splitsize; diff --git a/src/res/e2k9.xml b/src/res/e2k9.xml index 88a20cb93..37b119d8e 100644 --- a/src/res/e2k9.xml +++ b/src/res/e2k9.xml @@ -129,6 +129,7 @@ + diff --git a/src/res/e2k9/races.xml b/src/res/e2k9/races.xml index 39cfd4844..8bf803128 100644 --- a/src/res/e2k9/races.xml +++ b/src/res/e2k9/races.xml @@ -84,7 +84,7 @@ - + @@ -151,6 +151,7 @@ +