mirror of
https://github.com/cuberite/cuberite.git
synced 2025-01-07 03:16:55 +08:00
Documentation
This commit is contained in:
parent
9ab5627a39
commit
40503ab891
@ -6,8 +6,17 @@ class cBehaviorAggressive;
|
||||
#include "Behavior.h"
|
||||
#include <functional>
|
||||
|
||||
/** The mob is agressive toward specific mobtypes, or toward the player.
|
||||
This Behavior has a dependency on BehaviorAttacker. */
|
||||
/** The mob is agressive toward specific mobtypes (mobTodo), or toward the player.
|
||||
*
|
||||
|
||||
Connections to other behaviors:
|
||||
- The mob should also have a cBehaviorAttacker, otherwise this behavior will not work.
|
||||
- This behavior does not make sense in combination with BehaviorCoward or cBehaviorBrave.
|
||||
|
||||
Special connections:
|
||||
- Relies on cMonster::GetAttackerBehavior to obtain the attacker behavior and alter its target.
|
||||
|
||||
*/
|
||||
|
||||
typedef std::function<bool(cBehaviorAggressive & a_Behavior, cMonster & a_Monster, cChunk & a_Chunk)> ShouldBeAggressiveFunction;
|
||||
|
||||
|
@ -8,7 +8,15 @@ class cBehaviorAttacker;
|
||||
/** Grants attack capability to the mob. Note that this is not the same as agression!
|
||||
The mob may possess this trait and not attack anyone or only attack when provoked.
|
||||
Unlike most traits, this one has several forms, and therefore it is an abstract type
|
||||
You should use one of its derived classes, and you cannot use it directly. */
|
||||
You should use one of its derived classes, and you cannot use it directly.
|
||||
|
||||
Connections to other behaviors:
|
||||
- Some behaviors may call cBehaviorAttacker::SetTarget
|
||||
|
||||
Special connections:
|
||||
- None.
|
||||
|
||||
*/
|
||||
class cBehaviorAttacker : public cBehavior
|
||||
{
|
||||
|
||||
|
@ -5,7 +5,16 @@
|
||||
class cBehaviorAttackerMelee;
|
||||
|
||||
/** Grants the mob that ability to approach a target and then melee attack it.
|
||||
Use BehaviorAttackerMelee::SetTarget to attack. */
|
||||
Use BehaviorAttackerMelee::SetTarget to attack.
|
||||
|
||||
|
||||
Connections to other behaviors:
|
||||
- See cBehaviorAttacker.
|
||||
|
||||
Special connections:
|
||||
- None.
|
||||
|
||||
*/
|
||||
typedef std::function<void(cBehaviorAttackerMelee & a_Behavior, cMonster & a_Attacker, cPawn & a_Attacked)> PostAttackFunction;
|
||||
class cBehaviorAttackerMelee : public cBehaviorAttacker
|
||||
{
|
||||
|
@ -5,7 +5,15 @@
|
||||
class cBehaviorAttackerRanged;
|
||||
|
||||
/** Grants the mob that ability to approach a target and then melee attack it.
|
||||
Use BehaviorAttackerMelee::SetTarget to attack. */
|
||||
Use cBehaviorAttackerRanged::SetTarget to attack.
|
||||
|
||||
Connections to other behaviors:
|
||||
- See cBehaviorAttacker.
|
||||
|
||||
Special connections:
|
||||
- None.
|
||||
|
||||
*/
|
||||
typedef std::function<void(cBehaviorAttackerRanged & a_Behavior,
|
||||
cMonster & a_Attacker, cPawn & a_Attacked)> RangedShootingFunction;
|
||||
|
||||
|
@ -9,10 +9,11 @@
|
||||
|
||||
|
||||
|
||||
cBehaviorAttackerSuicideBomber::cBehaviorAttackerSuicideBomber() :
|
||||
cBehaviorAttackerSuicideBomber::cBehaviorAttackerSuicideBomber(bool a_ShouldBroadcastEntityMetadata) :
|
||||
m_bIsBlowing(false),
|
||||
m_bIsCharged(false),
|
||||
m_BurnedWithFlintAndSteel(false)
|
||||
m_BurnedWithFlintAndSteel(false),
|
||||
m_ShouldBroadcastEntityMetadata(a_ShouldBroadcastEntityMetadata)
|
||||
{
|
||||
|
||||
}
|
||||
@ -42,8 +43,10 @@ bool cBehaviorAttackerSuicideBomber::DoStrike(int a_StrikeTickCnt)
|
||||
|
||||
m_Parent->GetWorld()->BroadcastSoundEffect("entity.creeper.primed", m_Parent->GetPosX(), m_Parent->GetPosY(), m_Parent->GetPosZ(), 1.f, (0.75f + (static_cast<float>((m_Parent->GetUniqueID() * 23) % 32)) / 64));
|
||||
m_bIsBlowing = true;
|
||||
m_Parent->GetWorld()->BroadcastEntityMetadata(*m_Parent);
|
||||
|
||||
if (m_ShouldBroadcastEntityMetadata)
|
||||
{
|
||||
m_Parent->GetWorld()->BroadcastEntityMetadata(*m_Parent);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -51,7 +54,10 @@ bool cBehaviorAttackerSuicideBomber::DoStrike(int a_StrikeTickCnt)
|
||||
if (((GetTarget() == nullptr) || (!TargetIsInStrikeRadius())) && (!m_BurnedWithFlintAndSteel))
|
||||
{
|
||||
m_bIsBlowing = false;
|
||||
m_Parent->GetWorld()->BroadcastEntityMetadata(*m_Parent);
|
||||
if (m_ShouldBroadcastEntityMetadata)
|
||||
{
|
||||
m_Parent->GetWorld()->BroadcastEntityMetadata(*m_Parent);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2,12 +2,22 @@
|
||||
|
||||
#include "BehaviorAttacker.h"
|
||||
|
||||
/** Grants the mob that ability to approach a target and then melee attack it.
|
||||
Use BehaviorAttackerMelee::SetTarget to attack. */
|
||||
/** Grants the mob that ability to approach a target and then blow up.
|
||||
Use cBehaviorAttackerSuicideBomber::SetTarget to attack.
|
||||
|
||||
Connections to other behaviors:
|
||||
- See cBehaviorAttacker.
|
||||
|
||||
Special connections:
|
||||
- The creeper will determine animation state by calling IsBlowing, IsCharged, and IsBurnedWithFlintAndSteel
|
||||
|
||||
*/
|
||||
class cBehaviorAttackerSuicideBomber : public cBehaviorAttacker
|
||||
{
|
||||
public:
|
||||
cBehaviorAttackerSuicideBomber();
|
||||
/** a_ShouldBroadcastEntityMetadata should only be true for creepers or
|
||||
any future mobs that animate explosions. */
|
||||
cBehaviorAttackerSuicideBomber(bool a_ShouldBroadcastEntityMetadata = false);
|
||||
void AttachToMonster(cMonster & a_Parent) override;
|
||||
// cBehaviorAttacker also implements those and we need to call super on them
|
||||
void DoTakeDamage(TakeDamageInfo & a_TDI) override;
|
||||
@ -21,4 +31,5 @@ public:
|
||||
|
||||
private:
|
||||
bool m_bIsBlowing, m_bIsCharged, m_BurnedWithFlintAndSteel;
|
||||
bool m_ShouldBroadcastEntityMetadata;
|
||||
};
|
||||
|
@ -2,8 +2,17 @@
|
||||
|
||||
#include "Behavior.h"
|
||||
|
||||
/** Makes the mob fight back any other mob that damages it. Mob should have BehaviorAttacker to work.
|
||||
This behavior does not make sense in combination with BehaviorCoward. */
|
||||
/** Makes the mob fight back any other mob that damages it. Unlike cBehaviorAggressive, it will
|
||||
not attack unless provoked.
|
||||
|
||||
Connections to other behaviors:
|
||||
- The mob should also have a cBehaviorAttacker, otherwise this behavior will not work.
|
||||
- This behavior does not make sense in combination with BehaviorCoward or cBehaviorAggressive.
|
||||
|
||||
Special connections:
|
||||
- Relies on cMonster::GetAttackerBehavior to obtain the attacker behavior and alter its target.
|
||||
|
||||
*/
|
||||
class cBehaviorBrave : cBehavior
|
||||
{
|
||||
public:
|
||||
|
@ -3,14 +3,25 @@
|
||||
class cBehaviorBreeder;
|
||||
|
||||
#include "Behavior.h"
|
||||
#include "BehaviorPet.h"
|
||||
|
||||
/** Grants breeding capabilities to the mob. */
|
||||
/** Grants breeding capabilities to the mob.
|
||||
Recommended combination with cBehaviorItemFollower.
|
||||
|
||||
Connections to other behaviors:
|
||||
- If the mob also has cBehaviorPet, this behavior is suppressed unless the mob has an owner.
|
||||
|
||||
Special connections:
|
||||
- Relies on the polymorphic cMonster::GetBreedingItems function to determine the breeding items.
|
||||
|
||||
|
||||
*/
|
||||
class cBehaviorBreeder : public cBehavior
|
||||
{
|
||||
|
||||
public:
|
||||
cBehaviorBreeder();
|
||||
void AttachToMonster(cMonster & a_Parent);
|
||||
void AttachToMonster(cMonster & a_Parent, cBehaviorPet * a_BehaviorPet = nullptr);
|
||||
|
||||
// Functions our host Monster should invoke:
|
||||
bool IsControlDesired(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
|
||||
@ -41,6 +52,9 @@ private:
|
||||
/** The monster's breeding partner. */
|
||||
cMonster * m_LovePartner;
|
||||
|
||||
/** The monster's pet behavior, if present. */
|
||||
cMonster * m_BehaviorPet;
|
||||
|
||||
/** If above 0, the monster is in love mode, and will breed if a nearby monster is also in love mode. Decrements by 1 per tick till reaching zero. */
|
||||
int m_LoveTimer;
|
||||
|
||||
|
@ -2,7 +2,16 @@
|
||||
|
||||
#include "Behavior.h"
|
||||
|
||||
/** Makes the mob run away from any other mob that damages it. */
|
||||
/** Makes the mob run away from any other mob that damages it.
|
||||
|
||||
Connections to other behaviors:
|
||||
- The mob should also have a cBehaviorAttacker, otherwise this behavior will not work.
|
||||
- This behavior does not make sense in combination with BehaviorAggressive or cBehaviorBrave.
|
||||
|
||||
Special connections:
|
||||
- None.
|
||||
|
||||
*/
|
||||
class cBehaviorCoward : cBehavior
|
||||
{
|
||||
public:
|
||||
|
@ -4,6 +4,16 @@
|
||||
#include "Behavior.h"
|
||||
#include "../../World.h"
|
||||
|
||||
/**
|
||||
The mob will burn in daylight.
|
||||
|
||||
Connections to other behaviors:
|
||||
- None.
|
||||
|
||||
Special connections:
|
||||
- Alters the pathfinder, so that the mob will try avoiding sunlight.
|
||||
|
||||
*/
|
||||
class cBehaviorDayLightBurner : cBehavior
|
||||
{
|
||||
public:
|
||||
|
@ -1,11 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
// Always takes control of the tick and does nothing. Used for unimplemented mobs like squids.
|
||||
|
||||
|
||||
class cBehaviorDoNothing;
|
||||
|
||||
#include "Behavior.h"
|
||||
|
||||
/** Always takes control of the tick and does nothing. Used for unimplemented mobs like squids. */
|
||||
class cBehaviorDoNothing : public cBehavior
|
||||
{
|
||||
public:
|
||||
|
@ -4,7 +4,15 @@
|
||||
|
||||
#include "Behavior.h"
|
||||
|
||||
/** Makes the mob periodically lay eggs. */
|
||||
/** Makes the mob periodically drop eggs. MobTodo: Make this more generic.
|
||||
|
||||
Connections to other behaviors:
|
||||
- None
|
||||
|
||||
Special connections:
|
||||
- None.
|
||||
|
||||
*/
|
||||
class cBehaviorItemDropper : cBehavior
|
||||
{
|
||||
public:
|
||||
|
@ -5,7 +5,15 @@ class cBehaviorItemFollower;
|
||||
|
||||
#include "Behavior.h"
|
||||
/** Makes the mob follow specific items when held by the player.
|
||||
Currently relies on cMonster::GetFollowedItems for the item list. */
|
||||
Currently relies on cMonster::GetFollowedItems for the item list.
|
||||
|
||||
Connections to other behaviors:
|
||||
- None
|
||||
|
||||
Special connections:
|
||||
- Relies on the polymorphic cMonster::GetFollowedItems function to determine the followed items.
|
||||
|
||||
*/
|
||||
class cBehaviorItemFollower : public cBehavior
|
||||
{
|
||||
public:
|
||||
|
@ -7,6 +7,13 @@ class cBehaviorItemReplacer;
|
||||
|
||||
/** When right clicked while holding a_OriginalItem, a mob having this behavior replaces the original item
|
||||
with a_NewItem. This is used for milking cows.
|
||||
|
||||
Connections to other behaviors:
|
||||
- None.
|
||||
|
||||
Special connections:
|
||||
- None.
|
||||
|
||||
*/
|
||||
class cBehaviorItemReplacer : public cBehavior
|
||||
{
|
||||
|
0
src/Mobs/Behaviors/BehaviorPet.cpp
Normal file
0
src/Mobs/Behaviors/BehaviorPet.cpp
Normal file
33
src/Mobs/Behaviors/BehaviorPet.h
Normal file
33
src/Mobs/Behaviors/BehaviorPet.h
Normal file
@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "Behavior.h"
|
||||
|
||||
/** Makes the mob tamable. Once tamed, the mob will have an owner and will follow it around.
|
||||
The mob can optionally be granted sitting ability via the CanSit flag, and the ability to defend
|
||||
its owner via the IsProtector flag.
|
||||
|
||||
If the mob is not sitting and the owner strays too far, the mob will teleport to the owner.
|
||||
|
||||
This base class behavior does not permit in-game taming (except when used by horses).
|
||||
The derived classes determine how the mob should be tamed and they should be used instead.
|
||||
|
||||
Connections to other behaviors:
|
||||
- Suppresses cBehaviorBreeder until the mob has an owner.
|
||||
- If IsProtecter is set to true, the mob should also have a cBehaviorAttacker
|
||||
|
||||
Special connections:
|
||||
- relies on cMonster::NeverDespawn (TODO) and ensures the mob never despawns if it has an owner.
|
||||
- mobTodo cMonster::NeverDespawn + cWorld changes
|
||||
- Horse taming is horse-specific, so the horse taming logic is in the horse class, and
|
||||
it will call cBehaviorBrave::SetOwner once tamed.
|
||||
|
||||
*/
|
||||
class cBehaviorBrave : cBehavior
|
||||
{
|
||||
public:
|
||||
void AttachToMonster(cMonster & a_Parent);
|
||||
void DoTakeDamage(TakeDamageInfo & a_TDI) override;
|
||||
|
||||
private:
|
||||
cMonster * m_Parent; // Our Parent
|
||||
};
|
0
src/Mobs/Behaviors/BehaviorPetTamableWithItem.cpp
Normal file
0
src/Mobs/Behaviors/BehaviorPetTamableWithItem.cpp
Normal file
0
src/Mobs/Behaviors/BehaviorPetTamableWithItem.h
Normal file
0
src/Mobs/Behaviors/BehaviorPetTamableWithItem.h
Normal file
0
src/Mobs/Behaviors/BehaviorPetTamableWithItemShy.h
Normal file
0
src/Mobs/Behaviors/BehaviorPetTamableWithItemShy.h
Normal file
@ -20,6 +20,9 @@ SET (SRCS
|
||||
BehaviorAttackerRanged.cpp
|
||||
BehaviorAttackerSuicideBomber.cpp
|
||||
BehaviorWanderer.cpp
|
||||
BehaviorPet.cpp
|
||||
BehaviorPetTamableWithItem.cpp
|
||||
BehaviorPetTamableWithItemShy.cpp
|
||||
)
|
||||
|
||||
SET (HDRS
|
||||
@ -38,6 +41,9 @@ SET (HDRS
|
||||
BehaviorAttackerRanged.h
|
||||
BehaviorAttackerSuicideBomber.h
|
||||
BehaviorWanderer.h
|
||||
BehaviorPet.h
|
||||
BehaviorPetTamableWithItem.h
|
||||
BehaviorPetTamableWithItemShy.h
|
||||
)
|
||||
|
||||
if(NOT MSVC)
|
||||
|
@ -1161,7 +1161,7 @@ void cWorld::TickMobs(std::chrono::milliseconds a_Dt)
|
||||
else
|
||||
{
|
||||
auto Wolf = static_cast<cWolf *>(Monster);
|
||||
if (Wolf->IsAngry())
|
||||
if (Wolf->IsAngry()) // mobTodo no need for special case, use neverDespawn
|
||||
{
|
||||
Monster->Destroy(true);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user