mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-03 20:49:41 +00:00
Centralized "fish can't attack non-swimmer" logic.
This commit is contained in:
parent
7aa0f887c0
commit
458b82c308
4 changed files with 31 additions and 9 deletions
|
@ -37,6 +37,7 @@
|
||||||
|
|
||||||
#include "actor.hpp"
|
#include "actor.hpp"
|
||||||
#include "summoning.hpp"
|
#include "summoning.hpp"
|
||||||
|
#include "combat.hpp"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
@ -309,10 +310,10 @@ namespace MWMechanics
|
||||||
// pure water creatures won't try to fight with the target on the ground
|
// pure water creatures won't try to fight with the target on the ground
|
||||||
// except that creature is already hostile
|
// except that creature is already hostile
|
||||||
if ((againstPlayer || !creatureStats.getAiSequence().isInCombat())
|
if ((againstPlayer || !creatureStats.getAiSequence().isInCombat())
|
||||||
&& ((actor1.getClass().isPureWaterCreature(actor1)
|
&& !MWMechanics::isEnvironmentCompatible(actor1, actor2)) // creature can't swim to target
|
||||||
&& !MWBase::Environment::get().getWorld()->isWading(actor2))
|
{
|
||||||
|| (!actor1.getClass().canSwim(actor1) && MWBase::Environment::get().getWorld()->isSwimming(actor2)))) // creature can't swim to target
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
bool aggressive;
|
bool aggressive;
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "character.hpp" // fixme: for getActiveWeapon
|
#include "character.hpp" // fixme: for getActiveWeapon
|
||||||
|
|
||||||
#include "aicombataction.hpp"
|
#include "aicombataction.hpp"
|
||||||
|
#include "combat.hpp"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
@ -206,12 +207,8 @@ namespace MWMechanics
|
||||||
const MWWorld::Class& actorClass = actor.getClass();
|
const MWWorld::Class& actorClass = actor.getClass();
|
||||||
MWBase::World* world = MWBase::Environment::get().getWorld();
|
MWBase::World* world = MWBase::Environment::get().getWorld();
|
||||||
|
|
||||||
if (!actorClass.isNpc() &&
|
// can't fight if attacker can't go where target is. E.g. A fish can't attack person on land.
|
||||||
// 1. pure water creature and Player moved out of water
|
if (!actorClass.isNpc() && !MWMechanics::isEnvironmentCompatible(actor, target))
|
||||||
((target == world->getPlayerPtr() &&
|
|
||||||
actorClass.isPureWaterCreature(actor) && !world->isWading(target))
|
|
||||||
// 2. creature can't swim to target
|
|
||||||
|| (!actorClass.canSwim(actor) && world->isSwimming(target))))
|
|
||||||
{
|
{
|
||||||
actorClass.getCreatureStats(actor).setAttackingOrSpell(false);
|
actorClass.getCreatureStats(actor).setAttackingOrSpell(false);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -367,4 +367,24 @@ namespace MWMechanics
|
||||||
else
|
else
|
||||||
sndMgr->playSound3D(victim, "Hand To Hand Hit", 1.0f, 1.0f);
|
sndMgr->playSound3D(victim, "Hand To Hand Hit", 1.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isEnvironmentCompatible(const MWWorld::Ptr& attacker, const MWWorld::Ptr& victim)
|
||||||
|
{
|
||||||
|
const MWWorld::Class& attackerClass = attacker.getClass();
|
||||||
|
MWBase::World* world = MWBase::Environment::get().getWorld();
|
||||||
|
|
||||||
|
// If attacker is fish, victim must be in water
|
||||||
|
if (attackerClass.isPureWaterCreature(attacker))
|
||||||
|
{
|
||||||
|
return world->isWading(victim);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If attacker can't swim, victim must not be in water
|
||||||
|
if (!attackerClass.canSwim(attacker))
|
||||||
|
{
|
||||||
|
return !world->isSwimming(victim);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,10 @@ void adjustWeaponDamage (float& damage, const MWWorld::Ptr& weapon);
|
||||||
|
|
||||||
void getHandToHandDamage (const MWWorld::Ptr& attacker, const MWWorld::Ptr& victim, float& damage, bool& healthdmg);
|
void getHandToHandDamage (const MWWorld::Ptr& attacker, const MWWorld::Ptr& victim, float& damage, bool& healthdmg);
|
||||||
|
|
||||||
|
/// Can attacker operate in victim's environment?
|
||||||
|
/// e.g. If attacker is a fish, is victim in water? Or, if attacker can't swim, is victim on land?
|
||||||
|
bool isEnvironmentCompatible(const MWWorld::Ptr& attacker, const MWWorld::Ptr& victim);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue