summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Entities/Entity.cpp3
-rw-r--r--src/Entities/Entity.h6
-rw-r--r--src/Entities/ProjectileEntity.cpp8
-rw-r--r--src/Entities/SplashPotionEntity.cpp20
-rw-r--r--src/Entities/SplashPotionEntity.h20
-rw-r--r--src/LineBlockTracer.cpp40
-rw-r--r--src/Mobs/Monster.cpp10
-rw-r--r--src/Mobs/Monster.h2
-rw-r--r--src/Mobs/Skeleton.h2
-rw-r--r--src/Mobs/Wither.h2
-rw-r--r--src/Mobs/Zombie.h6
-rw-r--r--src/Mobs/ZombiePigman.h2
-rw-r--r--src/OSSupport/Socket.cpp9
-rw-r--r--src/OSSupport/Socket.h1
-rw-r--r--src/Root.cpp10
-rw-r--r--src/Root.h2
-rw-r--r--src/Server.cpp2
-rw-r--r--src/WorldStorage/NBTChunkSerializer.cpp1
-rw-r--r--src/main.cpp14
19 files changed, 92 insertions, 68 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index f9331ede8..5a3bbcdc4 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -49,6 +49,7 @@ cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, d
, m_IsSubmerged(false)
, m_AirLevel(0)
, m_AirTickTimer(0)
+ , m_TicksAlive(0)
, m_HeadYaw(0.0)
, m_Rot(0.0, 0.0, 0.0)
, m_Pos(a_X, a_Y, a_Z)
@@ -559,6 +560,8 @@ void cEntity::SetHealth(int a_Health)
void cEntity::Tick(float a_Dt, cChunk & a_Chunk)
{
+ m_TicksAlive++;
+
if (m_InvulnerableTicks > 0)
{
m_InvulnerableTicks--;
diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h
index 88f8528e9..83fe76e7e 100644
--- a/src/Entities/Entity.h
+++ b/src/Entities/Entity.h
@@ -416,6 +416,9 @@ public:
/** Gets remaining air of a monster */
int GetAirLevel(void) const { return m_AirLevel; }
+ /** Gets number of ticks this entity has existed for */
+ long int GetTicksAlive(void) const { return m_TicksAlive; }
+
/** Gets the invulnerable ticks from the entity */
int GetInvulnerableTicks(void) const { return m_InvulnerableTicks; }
@@ -521,6 +524,9 @@ protected:
int m_AirLevel;
int m_AirTickTimer;
+ /** The number of ticks this entity has been alive for */
+ long int m_TicksAlive;
+
private:
/** Measured in degrees, [-180, +180) */
double m_HeadYaw;
diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp
index a55c9b895..b5e81bc0c 100644
--- a/src/Entities/ProjectileEntity.cpp
+++ b/src/Entities/ProjectileEntity.cpp
@@ -146,9 +146,11 @@ public:
(a_Entity->GetUniqueID() == m_Projectile->GetCreatorUniqueID()) // Do not check whoever shot the projectile
)
{
- // TODO: Don't check creator only for the first 5 ticks
- // so that arrows stuck in ground and dug up can hurt the player
- return false;
+ // Don't check creator only for the first 5 ticks so that projectiles can collide with the creator
+ if (m_Projectile->GetTicksAlive() <= 5)
+ {
+ return false;
+ }
}
cBoundingBox EntBox(a_Entity->GetPosition(), a_Entity->GetWidth() / 2, a_Entity->GetHeight());
diff --git a/src/Entities/SplashPotionEntity.cpp b/src/Entities/SplashPotionEntity.cpp
index 13cbcb0fc..6d874e957 100644
--- a/src/Entities/SplashPotionEntity.cpp
+++ b/src/Entities/SplashPotionEntity.cpp
@@ -33,15 +33,16 @@ public:
/** Called by cWorld::ForEachEntity(), adds the stored entity effect to the entity, if it is close enough. */
virtual bool Item(cEntity * a_Entity) override
{
- double SplashDistance = (a_Entity->GetPosition() - m_HitPos).Length();
- if (SplashDistance >= 20)
+ if (!a_Entity->IsPawn())
{
- // Too far away
+ // Not an entity that can take effects
return false;
}
- if (!a_Entity->IsPawn())
+
+ double SplashDistance = (a_Entity->GetPosition() - m_HitPos).Length();
+ if (SplashDistance >= 20)
{
- // Not an entity that can take effects
+ // Too far away
return false;
}
@@ -78,7 +79,8 @@ cSplashPotionEntity::cSplashPotionEntity(
super(pkSplashPotion, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25),
m_EntityEffectType(a_EntityEffectType),
m_EntityEffect(a_EntityEffect),
- m_PotionColor(a_PotionColor)
+ m_PotionColor(a_PotionColor),
+ m_DestroyTimer(-1)
{
SetSpeed(a_Speed);
}
@@ -90,7 +92,7 @@ cSplashPotionEntity::cSplashPotionEntity(
void cSplashPotionEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace)
{
Splash(a_HitPos);
- Destroy();
+ m_DestroyTimer = 2;
}
@@ -101,7 +103,7 @@ void cSplashPotionEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_
{
a_EntityHit.TakeDamage(dtRangedAttack, this, 0, 1);
Splash(a_HitPos);
- Destroy(true);
+ m_DestroyTimer = 5;
}
@@ -113,7 +115,7 @@ void cSplashPotionEntity::Splash(const Vector3d & a_HitPos)
cSplashPotionCallback Callback(a_HitPos, m_EntityEffectType, m_EntityEffect);
m_World->ForEachEntity(Callback);
- m_World->BroadcastSoundParticleEffect(2002, (int)a_HitPos.x, (int)a_HitPos.y, (int)a_HitPos.z, m_PotionColor);
+ m_World->BroadcastSoundParticleEffect(2002, (int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z), m_PotionColor);
}
diff --git a/src/Entities/SplashPotionEntity.h b/src/Entities/SplashPotionEntity.h
index a33b06990..290dd81d4 100644
--- a/src/Entities/SplashPotionEntity.h
+++ b/src/Entities/SplashPotionEntity.h
@@ -52,10 +52,30 @@ protected:
// cProjectileEntity overrides:
virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override;
virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override;
+ virtual void Tick (float a_Dt, cChunk & a_Chunk) override
+ {
+ if (m_DestroyTimer > 0)
+ {
+ m_DestroyTimer--;
+ if (m_DestroyTimer == 0)
+ {
+ Destroy();
+ return;
+ }
+ }
+ else
+ {
+ super::Tick(a_Dt, a_Chunk);
+ }
+ }
/** Splashes the potion, fires its particle effects and sounds
@param a_HitPos The position where the potion will splash */
void Splash(const Vector3d & a_HitPos);
virtual void SpawnOn(cClientHandle & a_Client) override;
+
+private:
+ /** Time in ticks to wait for the hit animation to begin before destroying */
+ int m_DestroyTimer;
} ; // tolua_export
diff --git a/src/LineBlockTracer.cpp b/src/LineBlockTracer.cpp
index 2395aa43e..f03e796d1 100644
--- a/src/LineBlockTracer.cpp
+++ b/src/LineBlockTracer.cpp
@@ -212,6 +212,26 @@ bool cLineBlockTracer::Item(cChunk * a_Chunk)
return true;
}
+ if ((m_CurrentY < 0) || (m_CurrentY >= cChunkDef::Height))
+ {
+ // We've gone out of the world, that's the end of this trace
+ double IntersectX, IntersectZ;
+ CalcXZIntersection(m_CurrentY, IntersectX, IntersectZ);
+ if (m_Callbacks->OnOutOfWorld(IntersectX, m_CurrentY, IntersectZ))
+ {
+ // The callback terminated the trace
+ return false;
+ }
+ m_Callbacks->OnNoMoreHits();
+ return true;
+ }
+
+ // Update the current chunk
+ if (a_Chunk != NULL)
+ {
+ a_Chunk = a_Chunk->GetNeighborChunk(m_CurrentX, m_CurrentZ);
+ }
+
if (a_Chunk->IsValid())
{
BLOCKTYPE BlockType;
@@ -233,26 +253,6 @@ bool cLineBlockTracer::Item(cChunk * a_Chunk)
return false;
}
}
-
- // Update the current chunk
- if (a_Chunk != NULL)
- {
- a_Chunk = a_Chunk->GetNeighborChunk(m_CurrentX, m_CurrentZ);
- }
-
- if ((m_CurrentY < 0) || (m_CurrentY >= cChunkDef::Height))
- {
- // We've gone out of the world, that's the end of this trace
- double IntersectX, IntersectZ;
- CalcXZIntersection(m_CurrentY, IntersectX, IntersectZ);
- if (m_Callbacks->OnOutOfWorld(IntersectX, m_CurrentY, IntersectZ))
- {
- // The callback terminated the trace
- return false;
- }
- m_Callbacks->OnNoMoreHits();
- return true;
- }
}
}
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index db45db5b9..753a44914 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -680,16 +680,6 @@ void cMonster::GetMonsterConfig(const AString & a_Name)
bool cMonster::IsUndead(void)
{
- switch (GetMobType())
- {
- case mtZombie:
- case mtZombiePigman:
- case mtSkeleton:
- case mtWither:
- {
- return true;
- }
- }
return false;
}
diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h
index bbc3ebd35..ffd078505 100644
--- a/src/Mobs/Monster.h
+++ b/src/Mobs/Monster.h
@@ -107,7 +107,7 @@ public:
void GetMonsterConfig(const AString & a_Name);
/** Returns whether this mob is undead (skeleton, zombie, etc.) */
- bool IsUndead(void);
+ virtual bool IsUndead(void);
virtual void EventLosePlayer(void);
virtual void CheckEventLostPlayer(void);
diff --git a/src/Mobs/Skeleton.h b/src/Mobs/Skeleton.h
index efb670c83..9a121ef48 100644
--- a/src/Mobs/Skeleton.h
+++ b/src/Mobs/Skeleton.h
@@ -22,6 +22,8 @@ public:
virtual void Attack(float a_Dt) override;
virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
+ virtual bool IsUndead(void) override { return true; }
+
bool IsWither(void) const { return m_bIsWither; };
private:
diff --git a/src/Mobs/Wither.h b/src/Mobs/Wither.h
index 7d76f70f5..cc8d1459b 100644
--- a/src/Mobs/Wither.h
+++ b/src/Mobs/Wither.h
@@ -30,6 +30,8 @@ public:
virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override;
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
virtual void KilledBy(TakeDamageInfo & a_TDI) override;
+
+ virtual bool IsUndead(void) override { return true; }
private:
diff --git a/src/Mobs/Zombie.h b/src/Mobs/Zombie.h
index c56409570..082573d8b 100644
--- a/src/Mobs/Zombie.h
+++ b/src/Mobs/Zombie.h
@@ -19,8 +19,10 @@ public:
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override;
virtual void MoveToPosition(const Vector3d & a_Position) override;
- bool IsVillagerZombie(void) const {return m_IsVillagerZombie; }
- bool IsConverting (void) const {return m_IsConverting; }
+ virtual bool IsUndead(void) override { return true; }
+
+ bool IsVillagerZombie(void) const { return m_IsVillagerZombie; }
+ bool IsConverting (void) const { return m_IsConverting; }
private:
diff --git a/src/Mobs/ZombiePigman.h b/src/Mobs/ZombiePigman.h
index a2ebc87cb..a4bad7efb 100644
--- a/src/Mobs/ZombiePigman.h
+++ b/src/Mobs/ZombiePigman.h
@@ -18,6 +18,8 @@ public:
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override;
virtual void KilledBy(TakeDamageInfo & a_TDI) override;
+
+ virtual bool IsUndead(void) override { return true; }
} ;
diff --git a/src/OSSupport/Socket.cpp b/src/OSSupport/Socket.cpp
index 47d9f331d..c07d31c8b 100644
--- a/src/OSSupport/Socket.cpp
+++ b/src/OSSupport/Socket.cpp
@@ -25,15 +25,6 @@ cSocket::cSocket(xSocket a_Socket)
-cSocket::~cSocket()
-{
- // Do NOT close the socket; this class is an API wrapper, not a RAII!
-}
-
-
-
-
-
cSocket::operator cSocket::xSocket() const
{
return m_Socket;
diff --git a/src/OSSupport/Socket.h b/src/OSSupport/Socket.h
index 35ecadfa0..e4ec895cb 100644
--- a/src/OSSupport/Socket.h
+++ b/src/OSSupport/Socket.h
@@ -41,7 +41,6 @@ public:
cSocket(void) : m_Socket(INVALID_SOCKET) {}
cSocket(xSocket a_Socket);
- ~cSocket();
bool IsValid(void) const { return IsValidSocket(m_Socket); }
void CloseSocket(void);
diff --git a/src/Root.cpp b/src/Root.cpp
index 6347adcf0..ba25b97eb 100644
--- a/src/Root.cpp
+++ b/src/Root.cpp
@@ -30,8 +30,6 @@
#include <mach/mach.h>
#endif
-extern bool g_TERMINATE_EVENT_RAISED;
-
@@ -79,7 +77,7 @@ void cRoot::InputThread(void * a_Params)
cLogCommandOutputCallback Output;
- while (!self.m_bStop && !self.m_bRestart && !g_TERMINATE_EVENT_RAISED && std::cin.good())
+ while (!self.m_bStop && !self.m_bRestart && !m_TerminateEventRaised && std::cin.good())
{
AString Command;
std::getline(std::cin, Command);
@@ -89,7 +87,7 @@ void cRoot::InputThread(void * a_Params)
}
}
- if (g_TERMINATE_EVENT_RAISED || !std::cin.good())
+ if (m_TerminateEventRaised || !std::cin.good())
{
// We have come here because the std::cin has received an EOF / a terminate signal has been sent, and the server is still running; stop the server:
self.m_bStop = true;
@@ -205,12 +203,12 @@ void cRoot::Start(void)
EnableMenuItem(hmenu, SC_CLOSE, MF_ENABLED); // Re-enable close button
#endif
- while (!m_bStop && !m_bRestart && !g_TERMINATE_EVENT_RAISED) // These are modified by external threads
+ while (!m_bStop && !m_bRestart && !m_TerminateEventRaised) // These are modified by external threads
{
cSleep::MilliSleep(1000);
}
- if (g_TERMINATE_EVENT_RAISED)
+ if (m_TerminateEventRaised)
{
m_bStop = true;
}
diff --git a/src/Root.h b/src/Root.h
index acd3e9754..08aafe3c9 100644
--- a/src/Root.h
+++ b/src/Root.h
@@ -40,6 +40,8 @@ namespace Json
class cRoot
{
public:
+ static bool m_TerminateEventRaised;
+
static cRoot * Get() { return s_Root; }
// tolua_end
diff --git a/src/Server.cpp b/src/Server.cpp
index 367d507bf..180ec2ca6 100644
--- a/src/Server.cpp
+++ b/src/Server.cpp
@@ -222,12 +222,14 @@ bool cServer::InitServer(cIniFile & a_SettingsIni)
bool HasAnyPorts = false;
AString Ports = a_SettingsIni.GetValueSet("Server", "Port", "25565");
+ m_ListenThreadIPv4.SetReuseAddr(true);
if (m_ListenThreadIPv4.Initialize(Ports))
{
HasAnyPorts = true;
}
Ports = a_SettingsIni.GetValueSet("Server", "PortsIPv6", "25565");
+ m_ListenThreadIPv6.SetReuseAddr(true);
if (m_ListenThreadIPv6.Initialize(Ports))
{
HasAnyPorts = true;
diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp
index 62db302ef..4857da1b6 100644
--- a/src/WorldStorage/NBTChunkSerializer.cpp
+++ b/src/WorldStorage/NBTChunkSerializer.cpp
@@ -614,6 +614,7 @@ void cNBTChunkSerializer::AddProjectileEntity(cProjectileEntity * a_Projectile)
m_Writer.AddShort("EffectIntensity", Potion->GetEntityEffect().GetIntensity());
m_Writer.AddDouble("EffectDistanceModifier", Potion->GetEntityEffect().GetDistanceModifier());
m_Writer.AddInt("PotionName", Potion->GetPotionColor());
+ break;
}
case cProjectileEntity::pkGhastFireball:
{
diff --git a/src/main.cpp b/src/main.cpp
index 0ff9361be..3e91149af 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -11,9 +11,9 @@
#include <dbghelp.h>
#endif // _MSC_VER
-// Here, we have some ALL CAPS variables, to give the impression that this is deeeep, gritty programming :P
-bool g_TERMINATE_EVENT_RAISED = false; // If something has told the server to stop; checked periodically in cRoot
-bool g_SERVER_TERMINATED = false; // Set to true when the server terminates, so our CTRL handler can then tell Windows to close the console
+
+bool cRoot::m_TerminateEventRaised = false; // If something has told the server to stop; checked periodically in cRoot
+static bool g_ServerTerminated = false; // Set to true when the server terminates, so our CTRL handler can then tell the OS to close the console
@@ -52,7 +52,7 @@ bool g_ShouldLogCommOut;
void NonCtrlHandler(int a_Signal)
{
LOGD("Terminate event raised from std::signal");
- g_TERMINATE_EVENT_RAISED = true;
+ cRoot::m_TerminateEventRaised = true;
switch (a_Signal)
{
@@ -155,12 +155,12 @@ LONG WINAPI LastChanceExceptionFilter(__in struct _EXCEPTION_POINTERS * a_Except
// Handle CTRL events in windows, including console window close
BOOL CtrlHandler(DWORD fdwCtrlType)
{
- g_TERMINATE_EVENT_RAISED = true;
+ cRoot::m_TerminateEventRaised = true;
LOGD("Terminate event raised from the Windows CtrlHandler");
if (fdwCtrlType == CTRL_CLOSE_EVENT) // Console window closed via 'x' button, Windows will try to close immediately, therefore...
{
- while (!g_SERVER_TERMINATED) { cSleep::MilliSleep(100); } // Delay as much as possible to try to get the server to shut down cleanly
+ while (!g_ServerTerminated) { cSleep::MilliSleep(100); } // Delay as much as possible to try to get the server to shut down cleanly
}
return TRUE;
@@ -296,7 +296,7 @@ int main( int argc, char **argv )
DeinitLeakFinder();
#endif
- g_SERVER_TERMINATED = true;
+ g_ServerTerminated = true;
return EXIT_SUCCESS;
}