Use "exit first" logic and check_blocking_decision() in common_try_block().
@@ -25230,22 +25230,37 @@ int common_try_runattack(entity *target)
return 0;
}
+// Passive blocking (AI takes block position before attack
+// hits like a player would).
int common_try_block(entity *target)
{
- if(self->modeldata.nopassiveblock == 0 ||
- (rand32()&self->modeldata.blockodds) != 1 ||
- !validanim(self, ANI_BLOCK))
+ // Must have block animation.
+ if (!validanim(self, ANI_BLOCK))
{
return 0;
}
+ // Exit if we choose not to block. This function includes
+ // the check for passive blocking flag.
+ if (!check_blocking_decision(self))
+ {
+ return 0;
+ }
+
+ // If no current target, use block range.
+ if(!target)
+ {
+ target = block_find_target(ANI_BLOCK, 0);
+ }
+
+ // Still no target? Nothing to do, so exit.
if (!target)
{
- target = block_find_target(ANI_BLOCK, 0); // temporary fix, other wise ranges never work
+ return 0;
}
- // no passive block, so block by himself :)
- if(target && target->attacking != ATTACKING_INACTIVE)
+ // If target is attacking, let's block and return true.
+ if(target->attacking != ATTACKING_INACTIVE)
{
self->takeaction = common_block;
set_blocking(self);
@@ -25253,6 +25268,7 @@ int common_try_block(entity *target)
ent_set_anim(self, ANI_BLOCK, 0);
return 1;
}
+
return 0;
}
