forked from github/server
refactor the resurrection code. There is more work to be done here, too much duplicaton between battle and volcano.
This commit is contained in:
parent
a9375200e4
commit
ad86e69e6b
30
src/battle.c
30
src/battle.c
|
@ -1130,6 +1130,21 @@ int calculate_armor(troop dt, const weapon_type *dwtype, const weapon_type *awty
|
||||||
return ar;
|
return ar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool resurrect_troop(troop dt)
|
||||||
|
{
|
||||||
|
fighter *df = dt.fighter;
|
||||||
|
unit *du = df->unit;
|
||||||
|
if (oldpotiontype[P_HEAL] && !fval(&df->person[dt.index], FL_HEALING_USED)) {
|
||||||
|
if (i_get(du->items, oldpotiontype[P_HEAL]) > 0) {
|
||||||
|
fset(&df->person[dt.index], FL_HEALING_USED);
|
||||||
|
i_change(&du->items, oldpotiontype[P_HEAL], -1);
|
||||||
|
df->person[dt.index].hp = u_race(du)->hitpoints * 5; /* give the person a buffer */
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
terminate(troop dt, troop at, int type, const char *damage, bool missile)
|
terminate(troop dt, troop at, int type, const char *damage, bool missile)
|
||||||
{
|
{
|
||||||
|
@ -1301,16 +1316,11 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* healing potions can avert a killing blow */
|
/* healing potions can avert a killing blow */
|
||||||
if (oldpotiontype[P_HEAL] && !fval(&df->person[dt.index], FL_HEALING_USED)) {
|
if (resurrect_troop(dt)) {
|
||||||
if (i_get(du->items, oldpotiontype[P_HEAL]) > 0) {
|
message *m = msg_message("potionsave", "unit", du);
|
||||||
message *m = msg_message("potionsave", "unit", du);
|
battle_message_faction(b, du->faction, m);
|
||||||
battle_message_faction(b, du->faction, m);
|
msg_release(m);
|
||||||
msg_release(m);
|
return false;
|
||||||
i_change(&du->items, oldpotiontype[P_HEAL], -1);
|
|
||||||
fset(&df->person[dt.index], FL_HEALING_USED);
|
|
||||||
df->person[dt.index].hp = u_race(du)->hitpoints * 5; /* give the person a buffer */
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
++at.fighter->kills;
|
++at.fighter->kills;
|
||||||
|
|
||||||
|
|
|
@ -12,11 +12,16 @@ without prior permission by the authors of Eressea.
|
||||||
|
|
||||||
#ifndef H_KRNL_ITEMS
|
#ifndef H_KRNL_ITEMS
|
||||||
#define H_KRNL_ITEMS
|
#define H_KRNL_ITEMS
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
struct unit;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern void register_itemfunctions(void);
|
void register_itemfunctions(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,12 +74,31 @@ static int nb_armor(const unit * u, int index)
|
||||||
return av;
|
return av;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool resurrect_unit(unit *u) {
|
||||||
|
if (oldpotiontype[P_HEAL]) {
|
||||||
|
bool heiltrank = false;
|
||||||
|
if (get_effect(u, oldpotiontype[P_HEAL]) > 0) {
|
||||||
|
change_effect(u, oldpotiontype[P_HEAL], -1);
|
||||||
|
heiltrank = true;
|
||||||
|
}
|
||||||
|
else if (i_get(u->items, oldpotiontype[P_HEAL]) > 0) {
|
||||||
|
i_change(&u->items, oldpotiontype[P_HEAL], -1);
|
||||||
|
change_effect(u, oldpotiontype[P_HEAL], 3);
|
||||||
|
heiltrank = true;
|
||||||
|
}
|
||||||
|
if (heiltrank && chance(0.50)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
damage_unit(unit * u, const char *dam, bool physical, bool magic)
|
damage_unit(unit * u, const char *dam, bool physical, bool magic)
|
||||||
{
|
{
|
||||||
int *hp, hpstack[20];
|
int *hp, hpstack[20];
|
||||||
int h;
|
int h;
|
||||||
int i, dead = 0, hp_rem = 0, heiltrank;
|
int i, dead = 0, hp_rem = 0;
|
||||||
|
|
||||||
assert(u->number);
|
assert(u->number);
|
||||||
if (fval(u_race(u), RCF_ILLUSIONARY)) {
|
if (fval(u_race(u), RCF_ILLUSIONARY)) {
|
||||||
|
@ -118,33 +137,19 @@ damage_unit(unit * u, const char *dam, bool physical, bool magic)
|
||||||
/* Auswirkungen */
|
/* Auswirkungen */
|
||||||
for (i = 0; i < u->number; i++) {
|
for (i = 0; i < u->number; i++) {
|
||||||
if (hp[i] <= 0) {
|
if (hp[i] <= 0) {
|
||||||
heiltrank = 0;
|
|
||||||
|
|
||||||
/* Sieben Leben */
|
/* Sieben Leben */
|
||||||
if (u_race(u) == get_race(RC_CAT) && (chance(1.0 / 7))) {
|
if (u_race(u) == get_race(RC_CAT) && (chance(1.0 / 7))) {
|
||||||
hp[i] = u->hp / u->number;
|
hp[i] = u->hp / u->number;
|
||||||
hp_rem += hp[i];
|
hp_rem += hp[i];
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
else if (resurrect_unit(u)) {
|
||||||
/* Heiltrank */
|
/* Heiltrank */
|
||||||
if (oldpotiontype[P_HEAL]) {
|
hp[i] = u->hp / u->number;
|
||||||
if (get_effect(u, oldpotiontype[P_HEAL]) > 0) {
|
hp_rem += hp[i];
|
||||||
change_effect(u, oldpotiontype[P_HEAL], -1);
|
}
|
||||||
heiltrank = 1;
|
else {
|
||||||
}
|
++dead;
|
||||||
else if (i_get(u->items, oldpotiontype[P_HEAL]) > 0) {
|
|
||||||
i_change(&u->items, oldpotiontype[P_HEAL], -1);
|
|
||||||
change_effect(u, oldpotiontype[P_HEAL], 3);
|
|
||||||
heiltrank = 1;
|
|
||||||
}
|
|
||||||
if (heiltrank && (chance(0.50))) {
|
|
||||||
hp[i] = u->hp / u->number;
|
|
||||||
hp_rem += hp[i];
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
dead++;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
hp_rem += hp[i];
|
hp_rem += hp[i];
|
||||||
|
|
Loading…
Reference in New Issue