summaryrefslogtreecommitdiffstats
path: root/src/Mobs/Monster.cpp
diff options
context:
space:
mode:
authorLogicParrot <LogicParrot@users.noreply.github.com>2017-09-02 17:15:22 +0200
committerLogicParrot <LogicParrot@users.noreply.github.com>2017-09-02 17:15:22 +0200
commit17c5d4e0c9532ac8381f098dc3629b3066e720ec (patch)
tree0da08711b16e4babf636b6c9dc7ee1e42db33410 /src/Mobs/Monster.cpp
parentImplemented creepers using Behaviors (diff)
downloadcuberite-17c5d4e0c9532ac8381f098dc3629b3066e720ec.tar
cuberite-17c5d4e0c9532ac8381f098dc3629b3066e720ec.tar.gz
cuberite-17c5d4e0c9532ac8381f098dc3629b3066e720ec.tar.bz2
cuberite-17c5d4e0c9532ac8381f098dc3629b3066e720ec.tar.lz
cuberite-17c5d4e0c9532ac8381f098dc3629b3066e720ec.tar.xz
cuberite-17c5d4e0c9532ac8381f098dc3629b3066e720ec.tar.zst
cuberite-17c5d4e0c9532ac8381f098dc3629b3066e720ec.zip
Diffstat (limited to '')
-rw-r--r--src/Mobs/Monster.cpp41
1 files changed, 23 insertions, 18 deletions
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index ae2d601cc..bf6eda50c 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -332,31 +332,37 @@ void cMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
// do not tick behaviors
// mobTodo temporary leash special case. Needs a behavior eventually.
}
- else if (m_PinnedBehavior != nullptr)
- {
- // A behavior is pinned. We give it control automatically.
- ASSERT(m_CurrentTickControllingBehavior == m_PinnedBehavior);
- m_CurrentTickControllingBehavior->Tick(a_Dt, a_Chunk);
- }
else
{
- // ask the behaviors sequentially if they are interested in controlling this mob
- // Stop at the first one that says yes.
- m_NewTickControllingBehavior = nullptr;
- for (cBehavior * Behavior : m_AttachedTickBehaviors)
+ // STEP 1: Decide who'll control us this tick
+
+ if (m_PinnedBehavior != nullptr)
+ {
+ // A behavior is pinned. We give it control automatically.
+ m_NewTickControllingBehavior = m_PinnedBehavior;
+ }
+ else
{
- if (Behavior->IsControlDesired(a_Dt, a_Chunk))
+ // ask the behaviors sequentially if they are interested in controlling this mob
+ // Stop at the first one that says yes.
+ m_NewTickControllingBehavior = nullptr;
+ for (cBehavior * Behavior : m_AttachedTickBehaviors)
{
- m_NewTickControllingBehavior = Behavior;
- break;
+ if (Behavior->IsControlDesired(a_Dt, a_Chunk))
+ {
+ m_NewTickControllingBehavior = Behavior;
+ break;
+ }
}
}
ASSERT(m_NewTickControllingBehavior != nullptr); // it's not OK if no one asks for control
+
+ // STEP 2: decide whether to tick or do behavior swapping
+
if (m_CurrentTickControllingBehavior == m_NewTickControllingBehavior)
{
// The Behavior asking for control is the same as the behavior from last tick.
// Nothing special, just tick it.
- // LOGD("mobDebug - Tick");
m_CurrentTickControllingBehavior->Tick(a_Dt, a_Chunk);
}
else if (m_CurrentTickControllingBehavior == nullptr)
@@ -374,6 +380,8 @@ void cMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
}
+ // STEP 3: Behavior swapping if needed
+
// Make the current controlling behavior clean up
if (m_TickControllingBehaviorState == OldControlEnding)
{
@@ -1359,9 +1367,7 @@ void cMonster::AttachDoTakeDamageBehavior(cBehavior * a_Behavior)
void cMonster::PinBehavior(cBehavior * a_Behavior)
{
- ASSERT(m_TickControllingBehaviorState == Normal);
m_PinnedBehavior = a_Behavior;
- ASSERT(m_CurrentTickControllingBehavior == m_PinnedBehavior);
}
@@ -1370,8 +1376,7 @@ void cMonster::PinBehavior(cBehavior * a_Behavior)
void cMonster::UnpinBehavior(cBehavior * a_Behavior)
{
- ASSERT(m_TickControllingBehaviorState == Normal);
- ASSERT(m_PinnedBehavior = a_Behavior);
+ ASSERT(m_PinnedBehavior == a_Behavior);
m_PinnedBehavior = nullptr;
}