summaryrefslogtreecommitdiffstats
path: root/src/Entities/Entity.cpp
diff options
context:
space:
mode:
authorJulian Laubstein <julianlaubstein@yahoo.de>2015-07-29 18:45:36 +0200
committerJulian Laubstein <julianlaubstein@yahoo.de>2015-07-29 18:45:36 +0200
commit735d590abf7f804a4504b70c84a289ba86c5f8e3 (patch)
tree13b603c8bbf8177da92ce87f5413fb646d204f3f /src/Entities/Entity.cpp
parentMerge pull request #2376 from mjhanninen/fix-freebsd-build (diff)
parentSilenced and fixed many warning messages across multiple files. (diff)
downloadcuberite-735d590abf7f804a4504b70c84a289ba86c5f8e3.tar
cuberite-735d590abf7f804a4504b70c84a289ba86c5f8e3.tar.gz
cuberite-735d590abf7f804a4504b70c84a289ba86c5f8e3.tar.bz2
cuberite-735d590abf7f804a4504b70c84a289ba86c5f8e3.tar.lz
cuberite-735d590abf7f804a4504b70c84a289ba86c5f8e3.tar.xz
cuberite-735d590abf7f804a4504b70c84a289ba86c5f8e3.tar.zst
cuberite-735d590abf7f804a4504b70c84a289ba86c5f8e3.zip
Diffstat (limited to '')
-rw-r--r--src/Entities/Entity.cpp98
1 files changed, 49 insertions, 49 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index bb9d3c44b..23cc487f6 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -313,7 +313,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
if ((a_TDI.Attacker != nullptr) && (a_TDI.Attacker->IsPlayer()))
{
- cPlayer * Player = (cPlayer *)a_TDI.Attacker;
+ cPlayer * Player = reinterpret_cast<cPlayer *>(a_TDI.Attacker);
Player->GetEquippedItem().GetHandler()->OnEntityAttack(Player, this);
@@ -321,19 +321,19 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
// TODO: Better damage increase, and check for enchantments (and use magic critical instead of plain)
const cEnchantments & Enchantments = Player->GetEquippedItem().m_Enchantments;
- int SharpnessLevel = Enchantments.GetLevel(cEnchantments::enchSharpness);
- int SmiteLevel = Enchantments.GetLevel(cEnchantments::enchSmite);
- int BaneOfArthropodsLevel = Enchantments.GetLevel(cEnchantments::enchBaneOfArthropods);
+ int SharpnessLevel = static_cast<int>(Enchantments.GetLevel(cEnchantments::enchSharpness));
+ int SmiteLevel = static_cast<int>(Enchantments.GetLevel(cEnchantments::enchSmite));
+ int BaneOfArthropodsLevel = static_cast<int>(Enchantments.GetLevel(cEnchantments::enchBaneOfArthropods));
if (SharpnessLevel > 0)
{
- a_TDI.FinalDamage += (int)ceil(1.25 * SharpnessLevel);
+ a_TDI.FinalDamage += static_cast<int>(ceil(1.25 * SharpnessLevel));
}
else if (SmiteLevel > 0)
{
if (IsMob())
{
- cMonster * Monster = (cMonster *)this;
+ cMonster * Monster = reinterpret_cast<cMonster *>(this);
switch (Monster->GetMobType())
{
case mtSkeleton:
@@ -341,7 +341,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
case mtWither:
case mtZombiePigman:
{
- a_TDI.FinalDamage += (int)ceil(2.5 * SmiteLevel);
+ a_TDI.FinalDamage += static_cast<int>(ceil(2.5 * SmiteLevel));
break;
}
default: break;
@@ -352,14 +352,14 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
{
if (IsMob())
{
- cMonster * Monster = (cMonster *)this;
+ cMonster * Monster = reinterpret_cast<cMonster *>(this);
switch (Monster->GetMobType())
{
case mtSpider:
case mtCaveSpider:
case mtSilverfish:
{
- a_TDI.RawDamage += (int)ceil(2.5 * BaneOfArthropodsLevel);
+ a_TDI.RawDamage += static_cast<int>(ceil(2.5 * BaneOfArthropodsLevel));
// TODO: Add slowness effect
break;
@@ -369,7 +369,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
}
}
- int FireAspectLevel = Enchantments.GetLevel(cEnchantments::enchFireAspect);
+ int FireAspectLevel = static_cast<int>(Enchantments.GetLevel(cEnchantments::enchFireAspect));
if (FireAspectLevel > 0)
{
int BurnTicks = 3;
@@ -384,7 +384,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
}
else if (IsMob() && !IsSubmerged() && !IsSwimming())
{
- cMonster * Monster = (cMonster *)this;
+ cMonster * Monster = reinterpret_cast<cMonster *>(this);
switch (Monster->GetMobType())
{
case mtGhast:
@@ -408,7 +408,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
if (ThornsLevel > 0)
{
- int Chance = ThornsLevel * 15;
+ int Chance = static_cast<int>(ThornsLevel * 15);
cFastRandom Random;
int RandomValue = Random.GenerateRandomInteger(0, 100);
@@ -428,7 +428,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
}
}
- Player->GetStatManager().AddValue(statDamageDealt, (StatValue)floor(a_TDI.FinalDamage * 10 + 0.5));
+ Player->GetStatManager().AddValue(statDamageDealt, static_cast<StatValue>(floor(a_TDI.FinalDamage * 10 + 0.5)));
}
if (IsPlayer())
@@ -444,31 +444,31 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
for (size_t i = 0; i < ARRAYCOUNT(ArmorItems); i++)
{
const cItem & Item = ArmorItems[i];
- int Level = Item.m_Enchantments.GetLevel(cEnchantments::enchProtection);
+ int Level = static_cast<int>(Item.m_Enchantments.GetLevel(cEnchantments::enchProtection));
if (Level > 0)
{
EPFProtection += (6 + Level * Level) * 0.75 / 3;
}
- Level = Item.m_Enchantments.GetLevel(cEnchantments::enchFireProtection);
+ Level = static_cast<int>(Item.m_Enchantments.GetLevel(cEnchantments::enchFireProtection));
if (Level > 0)
{
EPFFireProtection += (6 + Level * Level) * 1.25 / 3;
}
- Level = Item.m_Enchantments.GetLevel(cEnchantments::enchFeatherFalling);
+ Level = static_cast<int>(Item.m_Enchantments.GetLevel(cEnchantments::enchFeatherFalling));
if (Level > 0)
{
EPFFeatherFalling += (6 + Level * Level) * 2.5 / 3;
}
- Level = Item.m_Enchantments.GetLevel(cEnchantments::enchBlastProtection);
+ Level = static_cast<int>(Item.m_Enchantments.GetLevel(cEnchantments::enchBlastProtection));
if (Level > 0)
{
EPFBlastProtection += (6 + Level * Level) * 1.5 / 3;
}
- Level = Item.m_Enchantments.GetLevel(cEnchantments::enchProjectileProtection);
+ Level = static_cast<int>(Item.m_Enchantments.GetLevel(cEnchantments::enchProjectileProtection));
if (Level > 0)
{
EPFProjectileProtection += (6 + Level * Level) * 1.5 / 3;
@@ -509,27 +509,27 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
if ((a_TDI.DamageType != dtInVoid) && (a_TDI.DamageType != dtAdmin))
{
- RemovedDamage += (int)ceil(EPFProtection * 0.04 * a_TDI.FinalDamage);
+ RemovedDamage += CeilC(EPFProtection * 0.04 * a_TDI.FinalDamage);
}
if ((a_TDI.DamageType == dtFalling) || (a_TDI.DamageType == dtFall) || (a_TDI.DamageType == dtEnderPearl))
{
- RemovedDamage += (int)ceil(EPFFeatherFalling * 0.04 * a_TDI.FinalDamage);
+ RemovedDamage += CeilC(EPFFeatherFalling * 0.04 * a_TDI.FinalDamage);
}
if (a_TDI.DamageType == dtBurning)
{
- RemovedDamage += (int)ceil(EPFFireProtection * 0.04 * a_TDI.FinalDamage);
+ RemovedDamage += CeilC(EPFFireProtection * 0.04 * a_TDI.FinalDamage);
}
if (a_TDI.DamageType == dtExplosion)
{
- RemovedDamage += (int)ceil(EPFBlastProtection * 0.04 * a_TDI.FinalDamage);
+ RemovedDamage += CeilC(EPFBlastProtection * 0.04 * a_TDI.FinalDamage);
}
if (a_TDI.DamageType == dtProjectile)
{
- RemovedDamage += (int)ceil(EPFBlastProtection * 0.04 * a_TDI.FinalDamage);
+ RemovedDamage += CeilC(EPFBlastProtection * 0.04 * a_TDI.FinalDamage);
}
if (a_TDI.FinalDamage < RemovedDamage)
@@ -540,7 +540,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
a_TDI.FinalDamage -= RemovedDamage;
}
- m_Health -= (short)a_TDI.FinalDamage;
+ m_Health -= static_cast<short>(a_TDI.FinalDamage);
// TODO: Apply damage to armor
@@ -549,11 +549,11 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
// Add knockback:
if ((IsMob() || IsPlayer()) && (a_TDI.Attacker != nullptr))
{
- int KnockbackLevel = a_TDI.Attacker->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchKnockback); // More common enchantment
+ int KnockbackLevel = static_cast<int>(a_TDI.Attacker->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchKnockback)); // More common enchantment
if (KnockbackLevel < 1)
{
// We support punch on swords and vice versa! :)
- KnockbackLevel = a_TDI.Attacker->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchPunch);
+ KnockbackLevel = static_cast<int>(a_TDI.Attacker->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchPunch));
}
Vector3d AdditionalSpeed(0, 0, 0);
@@ -800,7 +800,7 @@ void cEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
if (IsPlayer())
{
- cPlayer * Player = (cPlayer *)this;
+ cPlayer * Player = reinterpret_cast<cPlayer *>(this);
Player->UpdateMovementStats(DeltaPos);
}
}
@@ -1013,7 +1013,7 @@ void cEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
cTracer Tracer(GetWorld());
// Distance traced is an integer, so we round up from the distance we should go (Speed * Delta), else we will encounter collision detection failurse
- int DistanceToTrace = (int)(ceil((NextSpeed * DtSec.count()).SqrLength()) * 2);
+ int DistanceToTrace = CeilC((NextSpeed * DtSec.count()).SqrLength()) * 2;
bool HasHit = Tracer.Trace(NextPos, NextSpeed, DistanceToTrace);
if (HasHit)
@@ -1123,12 +1123,12 @@ void cEntity::TickBurning(cChunk & a_Chunk)
}
// Update the burning times, based on surroundings:
- int MinRelX = (int)floor(GetPosX() - m_Width / 2) - a_Chunk.GetPosX() * cChunkDef::Width;
- int MaxRelX = (int)floor(GetPosX() + m_Width / 2) - a_Chunk.GetPosX() * cChunkDef::Width;
- int MinRelZ = (int)floor(GetPosZ() - m_Width / 2) - a_Chunk.GetPosZ() * cChunkDef::Width;
- int MaxRelZ = (int)floor(GetPosZ() + m_Width / 2) - a_Chunk.GetPosZ() * cChunkDef::Width;
- int MinY = std::max(0, std::min(cChunkDef::Height - 1, POSY_TOINT));
- int MaxY = std::max(0, std::min(cChunkDef::Height - 1, (int)ceil (GetPosY() + m_Height)));
+ int MinRelX = FloorC(GetPosX() - m_Width / 2) - a_Chunk.GetPosX() * cChunkDef::Width;
+ int MaxRelX = FloorC(GetPosX() + m_Width / 2) - a_Chunk.GetPosX() * cChunkDef::Width;
+ int MinRelZ = FloorC(GetPosZ() - m_Width / 2) - a_Chunk.GetPosZ() * cChunkDef::Width;
+ int MaxRelZ = FloorC(GetPosZ() + m_Width / 2) - a_Chunk.GetPosZ() * cChunkDef::Width;
+ int MinY = Clamp(POSY_TOINT, 0, cChunkDef::Height - 1);
+ int MaxY = Clamp(CeilC(GetPosY() + m_Height), 0, cChunkDef::Height - 1);
bool HasWater = false;
bool HasLava = false;
bool HasFire = false;
@@ -1325,7 +1325,7 @@ bool cEntity::DetectPortal()
return false;
}
- if (IsPlayer() && !((cPlayer *)this)->IsGameModeCreative() && (m_PortalCooldownData.m_TicksDelayed != 80))
+ if (IsPlayer() && !(reinterpret_cast<cPlayer *>(this))->IsGameModeCreative() && (m_PortalCooldownData.m_TicksDelayed != 80))
{
// Delay teleportation for four seconds if the entity is a non-creative player
m_PortalCooldownData.m_TicksDelayed++;
@@ -1345,7 +1345,7 @@ bool cEntity::DetectPortal()
if (IsPlayer())
{
// Send a respawn packet before world is loaded / generated so the client isn't left in limbo
- ((cPlayer *)this)->GetClientHandle()->SendRespawn(dimOverworld);
+ (reinterpret_cast<cPlayer *>(this))->GetClientHandle()->SendRespawn(dimOverworld);
}
Vector3d TargetPos = GetPosition();
@@ -1368,8 +1368,8 @@ bool cEntity::DetectPortal()
if (IsPlayer())
{
- ((cPlayer *)this)->AwardAchievement(achEnterPortal);
- ((cPlayer *)this)->GetClientHandle()->SendRespawn(dimNether);
+ reinterpret_cast<cPlayer *>(this)->AwardAchievement(achEnterPortal);
+ reinterpret_cast<cPlayer *>(this)->GetClientHandle()->SendRespawn(dimNether);
}
Vector3d TargetPos = GetPosition();
@@ -1401,7 +1401,7 @@ bool cEntity::DetectPortal()
if (IsPlayer())
{
- cPlayer * Player = (cPlayer *)this;
+ cPlayer * Player = reinterpret_cast<cPlayer *>(this);
Player->TeleportToCoords(Player->GetLastBedPos().x, Player->GetLastBedPos().y, Player->GetLastBedPos().z);
Player->GetClientHandle()->SendRespawn(dimOverworld);
}
@@ -1419,8 +1419,8 @@ bool cEntity::DetectPortal()
if (IsPlayer())
{
- ((cPlayer *)this)->AwardAchievement(achEnterTheEnd);
- ((cPlayer *)this)->GetClientHandle()->SendRespawn(dimEnd);
+ reinterpret_cast<cPlayer *>(this)->AwardAchievement(achEnterTheEnd);
+ reinterpret_cast<cPlayer *>(this)->GetClientHandle()->SendRespawn(dimEnd);
}
return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetLinkedEndWorldName(), dimEnd, GetWorld()->GetName()), false);
@@ -1498,7 +1498,7 @@ bool cEntity::MoveToWorld(const AString & a_WorldName, bool a_ShouldSendRespawn)
void cEntity::SetSwimState(cChunk & a_Chunk)
{
- int RelY = (int)floor(GetPosY() + 0.1);
+ int RelY = FloorC(GetPosY() + 0.1);
if ((RelY < 0) || (RelY >= cChunkDef::Height - 1))
{
m_IsSwimming = false;
@@ -1550,7 +1550,7 @@ void cEntity::HandleAir(void)
// See if the entity is /submerged/ water (block above is water)
// Get the type of block the entity is standing in:
- int RespirationLevel = GetEquippedHelmet().m_Enchantments.GetLevel(cEnchantments::enchRespiration);
+ int RespirationLevel = static_cast<int>(GetEquippedHelmet().m_Enchantments.GetLevel(cEnchantments::enchRespiration));
if (IsSubmerged())
{
@@ -1561,7 +1561,7 @@ void cEntity::HandleAir(void)
if (RespirationLevel > 0)
{
- ((cPawn *)this)->AddEntityEffect(cEntityEffect::effNightVision, 200, 5, 0);
+ reinterpret_cast<cPawn *>(this)->AddEntityEffect(cEntityEffect::effNightVision, 200, 5, 0);
}
if (m_AirLevel <= 0)
@@ -1733,9 +1733,9 @@ void cEntity::BroadcastMovementUpdate(const cClientHandle * a_Exclude)
}
// TODO: Pickups move disgracefully if relative move packets are sent as opposed to just velocity. Have a system to send relmove only when SetPosXXX() is called with a large difference in position
- int DiffX = (int)(floor(GetPosX() * 32.0) - floor(m_LastPos.x * 32.0));
- int DiffY = (int)(floor(GetPosY() * 32.0) - floor(m_LastPos.y * 32.0));
- int DiffZ = (int)(floor(GetPosZ() * 32.0) - floor(m_LastPos.z * 32.0));
+ int DiffX = FloorC(GetPosX() * 32.0) - FloorC(m_LastPos.x * 32.0);
+ int DiffY = FloorC(GetPosY() * 32.0) - FloorC(m_LastPos.y * 32.0);
+ int DiffZ = FloorC(GetPosZ() * 32.0) - FloorC(m_LastPos.z * 32.0);
if ((DiffX != 0) || (DiffY != 0) || (DiffZ != 0)) // Have we moved?
{
@@ -1744,12 +1744,12 @@ void cEntity::BroadcastMovementUpdate(const cClientHandle * a_Exclude)
// Difference within Byte limitations, use a relative move packet
if (m_bDirtyOrientation)
{
- m_World->BroadcastEntityRelMoveLook(*this, (char)DiffX, (char)DiffY, (char)DiffZ, a_Exclude);
+ m_World->BroadcastEntityRelMoveLook(*this, static_cast<char>(DiffX), static_cast<char>(DiffY), static_cast<char>(DiffZ), a_Exclude);
m_bDirtyOrientation = false;
}
else
{
- m_World->BroadcastEntityRelMove(*this, (char)DiffX, (char)DiffY, (char)DiffZ, a_Exclude);
+ m_World->BroadcastEntityRelMove(*this, static_cast<char>(DiffX), static_cast<char>(DiffY), static_cast<char>(DiffZ), a_Exclude);
}
// Clients seem to store two positions, one for the velocity packet and one for the teleport / relmove packet
// The latter is only changed with a relmove / teleport, and m_LastPos stores this position