summaryrefslogtreecommitdiffstats
path: root/src/Mobs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Mobs')
-rw-r--r--src/Mobs/AggressiveMonster.cpp11
-rw-r--r--src/Mobs/AggressiveMonster.h3
-rw-r--r--src/Mobs/Enderman.cpp17
-rw-r--r--src/Mobs/Monster.cpp15
-rw-r--r--src/Mobs/Monster.h2
-rw-r--r--src/Mobs/PassiveAggressiveMonster.cpp5
-rw-r--r--src/Mobs/PassiveAggressiveMonster.h2
-rw-r--r--src/Mobs/Spider.cpp6
-rw-r--r--src/Mobs/Spider.h2
9 files changed, 38 insertions, 25 deletions
diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp
index 109ad274c..d8bdc4af5 100644
--- a/src/Mobs/AggressiveMonster.cpp
+++ b/src/Mobs/AggressiveMonster.cpp
@@ -36,13 +36,16 @@ void cAggressiveMonster::InStateChasing(std::chrono::milliseconds a_Dt, cChunk &
-void cAggressiveMonster::EventSeePlayer(cEntity * a_Entity, cChunk & a_Chunk)
+
+void cAggressiveMonster::EventSeePlayer(cPlayer * a_Player, cChunk & a_Chunk)
{
- if (!static_cast<cPlayer *>(a_Entity)->IsGameModeCreative())
+ if (!a_Player->CanMobsTarget())
{
- super::EventSeePlayer(a_Entity, a_Chunk);
- m_EMState = CHASING;
+ return;
}
+
+ super::EventSeePlayer(a_Player, a_Chunk);
+ m_EMState = CHASING;
}
diff --git a/src/Mobs/AggressiveMonster.h b/src/Mobs/AggressiveMonster.h
index f2d6366e2..9ab8df06f 100644
--- a/src/Mobs/AggressiveMonster.h
+++ b/src/Mobs/AggressiveMonster.h
@@ -19,7 +19,8 @@ public:
virtual void Tick (std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
virtual void InStateChasing(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
- virtual void EventSeePlayer(cEntity * a_Player, cChunk & a_Chunk) override;
+
+ virtual void EventSeePlayer(cPlayer * a_Player, cChunk & a_Chunk) override;
/** Try to perform attack
returns true if attack was deemed successful (hit player, fired projectile, creeper exploded, etc.) even if it didn't actually do damage
diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp
index 2ff547c3c..4e2e67f8a 100644
--- a/src/Mobs/Enderman.cpp
+++ b/src/Mobs/Enderman.cpp
@@ -23,8 +23,8 @@ public:
virtual bool Item(cPlayer * a_Player) override
{
- // Don't check players who are in creative gamemode
- if (a_Player->IsGameModeCreative())
+ // Don't check players who cannot be targeted
+ if (!a_Player->CanMobsTarget())
{
return false;
}
@@ -124,13 +124,16 @@ void cEnderman::CheckEventSeePlayer(cChunk & a_Chunk)
return;
}
- if (!Callback.GetPlayer()->IsGameModeCreative())
+ if (!Callback.GetPlayer()->CanMobsTarget())
{
- cMonster::EventSeePlayer(Callback.GetPlayer(), a_Chunk);
- m_EMState = CHASING;
- m_bIsScreaming = true;
- GetWorld()->BroadcastEntityMetadata(*this);
+ return;
}
+
+ // Target the player
+ cMonster::EventSeePlayer(Callback.GetPlayer(), a_Chunk);
+ m_EMState = CHASING;
+ m_bIsScreaming = true;
+ GetWorld()->BroadcastEntityMetadata(*this);
}
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index acd8f0145..ece59828e 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -265,7 +265,7 @@ void cMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
if (GetTarget()->IsPlayer())
{
- if (static_cast<cPlayer *>(GetTarget())->IsGameModeCreative())
+ if (!static_cast<cPlayer *>(GetTarget())->CanMobsTarget())
{
SetTarget(nullptr);
m_EMState = IDLE;
@@ -471,7 +471,13 @@ bool cMonster::DoTakeDamage(TakeDamageInfo & a_TDI)
if ((a_TDI.Attacker != nullptr) && a_TDI.Attacker->IsPawn())
{
- SetTarget(static_cast<cPawn*>(a_TDI.Attacker));
+ if (
+ (!a_TDI.Attacker->IsPlayer()) ||
+ (static_cast<cPlayer *>(a_TDI.Attacker)->CanMobsTarget())
+ )
+ {
+ SetTarget(static_cast<cPawn*>(a_TDI.Attacker));
+ }
m_TicksSinceLastDamaged = 0;
}
return true;
@@ -617,11 +623,10 @@ void cMonster::CheckEventLostPlayer(void)
// What to do if player is seen
// default to change state to chasing
-void cMonster::EventSeePlayer(cEntity * a_SeenPlayer, cChunk & a_Chunk)
+void cMonster::EventSeePlayer(cPlayer * a_SeenPlayer, cChunk & a_Chunk)
{
UNUSED(a_Chunk);
- ASSERT(a_SeenPlayer->IsPlayer());
- SetTarget(static_cast<cPawn*>(a_SeenPlayer));
+ SetTarget(a_SeenPlayer);
}
diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h
index 03382e28e..1c3d9c37a 100644
--- a/src/Mobs/Monster.h
+++ b/src/Mobs/Monster.h
@@ -72,7 +72,7 @@ public:
// tolua_end
virtual void CheckEventSeePlayer(cChunk & a_Chunk);
- virtual void EventSeePlayer(cEntity * a_Entity, cChunk & a_Chunk);
+ virtual void EventSeePlayer(cPlayer * a_Player, cChunk & a_Chunk);
/** Reads the monster configuration for the specified monster name and assigns it to this object. */
void GetMonsterConfig(const AString & a_Name);
diff --git a/src/Mobs/PassiveAggressiveMonster.cpp b/src/Mobs/PassiveAggressiveMonster.cpp
index a1bb1138f..8715ba9c2 100644
--- a/src/Mobs/PassiveAggressiveMonster.cpp
+++ b/src/Mobs/PassiveAggressiveMonster.cpp
@@ -28,7 +28,7 @@ bool cPassiveAggressiveMonster::DoTakeDamage(TakeDamageInfo & a_TDI)
if ((GetTarget() != nullptr) && (GetTarget()->IsPlayer()))
{
- if (!static_cast<cPlayer *>(GetTarget())->IsGameModeCreative())
+ if (static_cast<cPlayer *>(GetTarget())->CanMobsTarget())
{
m_EMState = CHASING;
}
@@ -39,7 +39,8 @@ bool cPassiveAggressiveMonster::DoTakeDamage(TakeDamageInfo & a_TDI)
-void cPassiveAggressiveMonster::EventSeePlayer(cEntity *, cChunk & a_Chunk)
+
+void cPassiveAggressiveMonster::EventSeePlayer(cPlayer *, cChunk & a_Chunk)
{
// don't do anything, neutral mobs don't react to just seeing the player
}
diff --git a/src/Mobs/PassiveAggressiveMonster.h b/src/Mobs/PassiveAggressiveMonster.h
index 00db75385..764e27779 100644
--- a/src/Mobs/PassiveAggressiveMonster.h
+++ b/src/Mobs/PassiveAggressiveMonster.h
@@ -16,7 +16,7 @@ public:
cPassiveAggressiveMonster(const AString & a_ConfigName, eMonsterType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height);
virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override;
- virtual void EventSeePlayer(cEntity *, cChunk & a_Chunk) override;
+ virtual void EventSeePlayer(cPlayer *, cChunk & a_Chunk) override;
} ;
diff --git a/src/Mobs/Spider.cpp b/src/Mobs/Spider.cpp
index a5f0d6a89..5ee3e3294 100644
--- a/src/Mobs/Spider.cpp
+++ b/src/Mobs/Spider.cpp
@@ -35,7 +35,7 @@ void cSpider::GetDrops(cItems & a_Drops, cEntity * a_Killer)
-void cSpider::EventSeePlayer(cEntity * a_Entity, cChunk & a_Chunk)
+void cSpider::EventSeePlayer(cPlayer * a_Player, cChunk & a_Chunk)
{
if (!GetWorld()->IsChunkLighted(GetChunkX(), GetChunkZ()))
{
@@ -48,9 +48,9 @@ void cSpider::EventSeePlayer(cEntity * a_Entity, cChunk & a_Chunk)
return;
}
- if (!static_cast<cPlayer *>(a_Entity)->IsGameModeCreative() && (Chunk->GetSkyLightAltered(Rel.x, Rel.y, Rel.z) <= 9))
+ if (a_Player->CanMobsTarget() && (Chunk->GetSkyLightAltered(Rel.x, Rel.y, Rel.z) <= 9))
{
- super::EventSeePlayer(a_Entity, a_Chunk);
+ super::EventSeePlayer(a_Player, a_Chunk);
}
}
diff --git a/src/Mobs/Spider.h b/src/Mobs/Spider.h
index 85cae92fc..af2753012 100644
--- a/src/Mobs/Spider.h
+++ b/src/Mobs/Spider.h
@@ -18,7 +18,7 @@ public:
CLASS_PROTODEF(cSpider)
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
- virtual void EventSeePlayer(cEntity *, cChunk & a_Chunk) override;
+ virtual void EventSeePlayer(cPlayer *, cChunk & a_Chunk) override;
virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override;
} ;