Skip to content

Commit

Permalink
Merge branch 'fear' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
elunna committed Oct 5, 2023
2 parents f9b9ee8 + f18f741 commit 54e152a
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 47 deletions.
2 changes: 1 addition & 1 deletion include/extern.h
Original file line number Diff line number Diff line change
Expand Up @@ -2748,7 +2748,7 @@ E boolean FDECL(stucksteed, (BOOLEAN_P));
E void FDECL(adjtech, (int,int));
E int NDECL(dotech);
E void NDECL(docalm);
E void FDECL(shield_block, (int));
E int FDECL(shield_block, (struct monst *, int));
E boolean FDECL(shield_blockable, (struct monst *, struct attack *));
E int FDECL(tech_inuse, (int));
E void NDECL(tech_timeout);
Expand Down
9 changes: 9 additions & 0 deletions src/explode.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,15 @@ int expltype;
u.mh -= damu;
else
u.uhp -= damu;

/* Some fears are realized... */
if (rn2(3) && ((adtyp == AD_FIRE && Vulnerable_fire)
|| (adtyp == AD_COLD && Vulnerable_cold)
|| (adtyp == AD_ELEC && Vulnerable_elec)
|| (adtyp == AD_ACID && Vulnerable_acid)
|| (adtyp == AD_LOUD && Vulnerable_loud)))
make_afraid((HAfraid & TIMEOUT) + (long) rn1(7, 4), TRUE);

context.botl = 1;
}

Expand Down
22 changes: 10 additions & 12 deletions src/mhitu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2706,18 +2706,7 @@ register struct attack *mattk;
make_stunned((HStun & TIMEOUT) + (long) dmg, TRUE);
dmg /= 2;
}

if ((Upolyd ? u.mh : u.uhp) < 1) {
if (shield_blockable(mtmp, mattk)) {
You("block the attack with your shield.");
shield_block(dmg);
} else {
/* already dead? call rehumanize() or done_in_by() as appropriate */
mdamageu(mtmp, 1);
}
dmg = 0;
}


/* Negative armor class reduces damage done instead of fully protecting
* against hits.
*/
Expand Down Expand Up @@ -2767,6 +2756,15 @@ register struct attack *mattk;
if (mon_currwep && mon_currwep->otyp == TORCH)
burn_faster(mon_currwep);
}

if (shield_blockable(mtmp, mattk)) {
res = shield_block(mtmp, dmg);
} else {
/* already dead? call rehumanize() or done_in_by() as appropriate */
mdamageu(mtmp, 1);
}
dmg = 0;


if (dmg) {
if (Half_physical_damage
Expand Down
2 changes: 1 addition & 1 deletion src/mthrowu.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const char *name; /* if null, then format `*objp' */
pline("You block it with your shield");
else
You("block %s with your shield", onm);
shield_block(dam);
shield_block(0, dam);
return (0);
} else if (Role_if(PM_JEDI)
&& uwep
Expand Down
90 changes: 57 additions & 33 deletions src/tech.c
Original file line number Diff line number Diff line change
Expand Up @@ -1244,51 +1244,75 @@ int tech_no;
return res;
}

void
shield_block(dam)
/* Return 1 if the aggressing monster died as a result.
* Otherwise return 0 */
int
shield_block(mtmp, dam)
struct monst *mtmp;
int dam;
{
int i;
for (i = 0; i < MAXTECH; ++i) {
if (techid(i) == T_POWER_SHIELD)
break;
int res = 0, cost = dam;
int tech_no = get_tech_no(T_POWER_SHIELD);
int skillpoints = P_SKILL(P_SHIELD) + techlev(tech_no);

if (!uarms) {
impossible("no worn shield for power shield tech!");
return 0;
}
if (i == MAXTECH) {
impossible("no power shield tech");
return;
if (!tech_inuse(T_POWER_SHIELD))
return 0;

/* Counter attacks */
/* Does the shield have a property? */
if (!rn2(skillpoints))
You("%s the attack with your shield.",
rn2(2) ? "block" : "deflect");
else {
if (rn2(2))
You("force your shield into the %s attack!",
s_suffix(mon_nam(mtmp)));
else
You("smash the %s with your shield!", mon_nam(mtmp));

res = damage_mon(mtmp, dam, AD_PHYS);
}
if (tech_inuse(T_POWER_SHIELD)) {
u.uen -= dam;
if (u.uen <= 0) {
u.uen = 0;
You("can no longer block damage with %s.",
uarms ? yname(uarms) : "a shield");
for (i = 0; i < MAXTECH; ++i) {
if (techid(i) == T_POWER_SHIELD) {
techt_inuse(i) = 0;
break;
}
}
}
context.botl = 1;

if (res)
xkilled(mtmp, XKILL_GIVEMSG);
else if (!mtmp->mconf) {
if (canseemon(mtmp))
pline("%s looks dazed.", Monnam(mtmp));
mtmp->mconf = 1;
}

/* We should reward shield skill, so blocking will
* cost less the higher our ability */
if (P_SKILL(P_SHIELD) == P_SKILLED)
cost = cost - (cost / 5); /* 20% less */
else if (P_SKILL(P_SHIELD) == P_EXPERT)
cost /= 2; /* 50% less */

u.uen -= cost;
if (u.uen <= 0) {
u.uen = 0;
You("can no longer power shield with %s.",
uarms ? yname(uarms) : "a shield");
techt_inuse(tech_no) = 0;

}
context.botl = 1;
return res;
}

boolean
shield_blockable(mtmp, mattk)
struct monst *mtmp;
struct attack *mattk;
{
if (!tech_inuse(T_POWER_SHIELD) ||
/* Additional restrictions: */
!canspotmon(mtmp)
|| u.uhs >= 3
|| u.uswallow
|| u.usleep
|| Fumbling
|| Stunned
|| Confusion
|| Blind)
if (!tech_inuse(T_POWER_SHIELD) || !canspotmon(mtmp)
|| u.uhs >= 3 /* Weak, fainting, or worse */
|| u.uswallow || u.usleep || Fumbling
|| Stunned || Confusion || Blind)
return FALSE;
/* Assuming you took it off or had it stolen while tech is active */
if (!uarms)
Expand Down

0 comments on commit 54e152a

Please sign in to comment.