1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-30 05:07:46 +00:00

fix warnings:

- using static casts
- comparing floating point with "==" or "!=" is not correct (Chara.cpp)
This commit is contained in:
kbasikhin 2019-12-25 17:45:51 +03:00
parent 51d29df7ac
commit bf757cbf03
9 changed files with 56 additions and 55 deletions

View file

@ -45,14 +45,14 @@ Action::Action::Action( Entity::CharaPtr caster, uint32_t actionId, uint16_t seq
Action::Action::Action( Entity::CharaPtr caster, uint32_t actionId, uint16_t sequence,
Data::ActionPtr actionData, FrameworkPtr fw ) :
m_pSource( std::move( caster ) ),
m_pFw( std::move( fw ) ),
m_actionData( std::move( actionData ) ),
m_id( actionId ),
m_targetId( 0 ),
m_sequence( sequence ),
m_startTime( 0 ),
m_pSource( std::move( caster ) ),
m_targetId( 0 ),
m_interruptType( Common::ActionInterruptType::None ),
m_sequence( sequence )
m_pFw( std::move( fw ) ),
m_actionData( std::move( actionData ) )
{
}
@ -101,10 +101,11 @@ bool Action::Action::init()
case Common::ClassJob::Bard:
case Common::ClassJob::Archer:
m_range = 25;
break;
// anything that isnt ranged
default:
m_range = 3;
break;
}
}
@ -206,7 +207,7 @@ bool Action::Action::update()
uint64_t tickCount = Common::Util::getTimeMs();
if( !hasCastTime() || std::difftime( tickCount, m_startTime ) > m_castTimeMs )
if( !hasCastTime() || std::difftime( static_cast<time_t>(tickCount), static_cast<time_t>(m_startTime) ) > m_castTimeMs )
{
execute();
return true;
@ -257,7 +258,7 @@ void Action::Action::start()
auto pScriptMgr = m_pFw->get< Scripting::ScriptMgr >();
// check the lut too and see if we have something usable, otherwise cancel the cast
if( !pScriptMgr->onStart( *this ) && !ActionLut::validEntryExists( getId() ) )
if( !pScriptMgr->onStart( *this ) && !ActionLut::validEntryExists( static_cast<uint16_t>( getId() ) ) )
{
// script not implemented and insufficient lut data (no potencies)
interrupt();
@ -392,7 +393,7 @@ void Action::Action::buildEffects()
auto pScriptMgr = m_pFw->get< Scripting::ScriptMgr >();
if( !pScriptMgr->onExecute( *this ) && !ActionLut::validEntryExists( getId() ) )
if( !pScriptMgr->onExecute( *this ) && !ActionLut::validEntryExists( static_cast<uint16_t>( getId() ) ) )
{
if( auto player = m_pSource->getAsPlayer() )
{
@ -405,7 +406,7 @@ void Action::Action::buildEffects()
if( m_hitActors.empty() )
return;
auto lutEntry = ActionLut::getEntry( getId() );
auto lutEntry = ActionLut::getEntry( static_cast<uint16_t>( getId() ) );
// no script exists but we have a valid lut entry
if( auto player = getSourceChara()->getAsPlayer() )
@ -545,11 +546,11 @@ bool Action::Action::primaryCostCheck( bool subtractCosts )
auto cost = m_primaryCost * 100;
if( curMp < cost )
if( curMp < static_cast<uint32_t>(cost) )
return false;
if( subtractCosts )
m_pSource->setMp( curMp - cost );
m_pSource->setMp( curMp - static_cast<uint32_t>(cost) );
return true;
}
@ -565,7 +566,7 @@ bool Action::Action::primaryCostCheck( bool subtractCosts )
}
}
bool Action::Action::secondaryCostCheck( bool subtractCosts )
bool Action::Action::secondaryCostCheck( bool /*subtractCosts*/ )
{
// todo: these need to be mapped
return true;
@ -679,4 +680,4 @@ Sapphire::Entity::CharaPtr Action::Action::getHitChara()
}
return nullptr;
}
}

View file

@ -269,7 +269,6 @@ void Sapphire::Entity::BNpc::sendPositionUpdate()
void Sapphire::Entity::BNpc::hateListClear()
{
auto it = m_hateList.begin();
for( auto& listEntry : m_hateList )
{
if( isInRangeSet( listEntry->m_pChara ) )
@ -301,7 +300,7 @@ Sapphire::Entity::CharaPtr Sapphire::Entity::BNpc::hateListGetHighest()
void Sapphire::Entity::BNpc::hateListAdd( Sapphire::Entity::CharaPtr pChara, int32_t hateAmount )
{
auto hateEntry = std::make_shared< HateListEntry >();
hateEntry->m_hateAmount = hateAmount;
hateEntry->m_hateAmount = static_cast<uint32_t>(hateAmount);
hateEntry->m_pChara = pChara;
m_hateList.insert( hateEntry );
@ -318,13 +317,13 @@ void Sapphire::Entity::BNpc::hateListUpdate( Sapphire::Entity::CharaPtr pChara,
{
if( listEntry->m_pChara == pChara )
{
listEntry->m_hateAmount += hateAmount;
listEntry->m_hateAmount += static_cast<uint32_t>(hateAmount);
return;
}
}
auto hateEntry = std::make_shared< HateListEntry >();
hateEntry->m_hateAmount = hateAmount;
hateEntry->m_hateAmount = static_cast<uint32_t>(hateAmount);
hateEntry->m_pChara = pChara;
m_hateList.insert( hateEntry );
}
@ -482,6 +481,7 @@ void Sapphire::Entity::BNpc::update( uint64_t tickCount )
checkAggro();
}
break;
case BNpcState::Combat:
{
@ -590,7 +590,7 @@ void Sapphire::Entity::BNpc::onDeath()
// TODO: handle drops
auto pPlayer = pHateEntry->m_pChara->getAsPlayer();
if( pPlayer )
pPlayer->onMobKill( m_bNpcNameId );
pPlayer->onMobKill( static_cast<uint16_t>(m_bNpcNameId) );
}
hateListClear();
}
@ -654,7 +654,7 @@ void Sapphire::Entity::BNpc::setOwner( Sapphire::Entity::CharaPtr m_pChara )
{
auto setOwnerPacket = makeZonePacket< FFXIVIpcActorOwner >( getId() );
setOwnerPacket->data().type = 0x01;
setOwnerPacket->data().actorId = INVALID_GAME_OBJECT_ID;
setOwnerPacket->data().actorId = static_cast<uint32_t>(INVALID_GAME_OBJECT_ID);
sendToInRangeSet( setOwnerPacket );
}
}
@ -697,7 +697,7 @@ void Sapphire::Entity::BNpc::autoAttack( CharaPtr pTarget )
auto effectPacket = std::make_shared< Server::EffectPacket >( getId(), pTarget->getId(), 7 );
effectPacket->setRotation( Util::floatToUInt16Rot( getRot() ) );
Common::EffectEntry effectEntry{};
effectEntry.value = damage;
effectEntry.value = static_cast<int16_t>(damage);
effectEntry.effectType = ActionEffectType::Damage;
effectEntry.hitSeverity = ActionHitSeverityType::NormalDamage;
effectEntry.param = 0x71;
@ -705,7 +705,7 @@ void Sapphire::Entity::BNpc::autoAttack( CharaPtr pTarget )
sendToInRangeSet( effectPacket );
pTarget->takeDamage( damage );
pTarget->takeDamage( static_cast<uint16_t>(damage) );
}
}
@ -731,15 +731,15 @@ void Sapphire::Entity::BNpc::calculateStats()
m_baseStats.determination = static_cast< uint32_t >( base );
m_baseStats.pie = static_cast< uint32_t >( base );
m_baseStats.skillSpeed = paramGrowthInfo->baseSpeed;
m_baseStats.spellSpeed = paramGrowthInfo->baseSpeed;
m_baseStats.accuracy = paramGrowthInfo->baseSpeed;
m_baseStats.critHitRate = paramGrowthInfo->baseSpeed;
m_baseStats.attackPotMagic = paramGrowthInfo->baseSpeed;
m_baseStats.healingPotMagic = paramGrowthInfo->baseSpeed;
m_baseStats.tenacity = paramGrowthInfo->baseSpeed;
m_baseStats.skillSpeed = static_cast<uint32_t>(paramGrowthInfo->baseSpeed);
m_baseStats.spellSpeed = static_cast<uint32_t>(paramGrowthInfo->baseSpeed);
m_baseStats.accuracy = static_cast<uint32_t>(paramGrowthInfo->baseSpeed);
m_baseStats.critHitRate = static_cast<uint32_t>(paramGrowthInfo->baseSpeed);
m_baseStats.attackPotMagic = static_cast<uint32_t>(paramGrowthInfo->baseSpeed);
m_baseStats.healingPotMagic = static_cast<uint32_t>(paramGrowthInfo->baseSpeed);
m_baseStats.tenacity = static_cast<uint32_t>(paramGrowthInfo->baseSpeed);
m_baseStats.attack = m_baseStats.str;
m_baseStats.attackPotMagic = m_baseStats.inte;
m_baseStats.healingPotMagic = m_baseStats.mnd;
}
}

View file

@ -35,10 +35,10 @@ using namespace Sapphire::Network::ActorControl;
Sapphire::Entity::Chara::Chara( ObjKind type, FrameworkPtr pFw ) :
Actor( type ),
m_pose( 0 ),
m_targetId( INVALID_GAME_OBJECT_ID64 ),
m_pFw( std::move( std::move( pFw ) ) ),
m_directorId( 0 ),
m_pose( 0 ),
m_pFw( std::move( std::move( pFw ) ) ),
m_radius( 1.f )
{
@ -245,14 +245,14 @@ void Sapphire::Entity::Chara::setMp( uint32_t mp )
/*! \param gp amount to set*/
void Sapphire::Entity::Chara::setGp( uint32_t gp )
{
m_gp = gp;
m_gp = static_cast<uint16_t>(gp);
sendStatusUpdate();
}
/*! \param tp amount to set*/
void Sapphire::Entity::Chara::setTp( uint32_t tp )
{
m_tp = tp;
m_tp = static_cast<uint16_t>(tp);
sendStatusUpdate();
}
@ -308,7 +308,7 @@ position
\param Position to look towards
*/
bool Sapphire::Entity::Chara::face( const Common::FFXIVARR_POSITION3& p )
bool Sapphire::Entity::Chara::face(const Common::FFXIVARR_POSITION3& p , float epsilon)
{
float oldRot = getRot();
float rot = Util::calcAngFrom( getPos().x, getPos().z, p.x, p.z );
@ -316,7 +316,7 @@ bool Sapphire::Entity::Chara::face( const Common::FFXIVARR_POSITION3& p )
setRot( newRot );
return oldRot != newRot;
return (fabs(oldRot - newRot) < epsilon);
}
/*!
@ -354,14 +354,14 @@ bool Sapphire::Entity::Chara::checkAction()
void Sapphire::Entity::Chara::update( uint64_t tickCount )
{
if( std::difftime( tickCount, m_lastTickTime ) > 3000 )
if( std::difftime( static_cast<time_t>(tickCount), m_lastTickTime ) > 3000 )
{
onTick();
m_lastTickTime = tickCount;
m_lastTickTime = static_cast<time_t>(tickCount);
}
m_lastUpdate = tickCount;
m_lastUpdate = static_cast<time_t>(tickCount);
}
/*!
@ -494,7 +494,7 @@ void Sapphire::Entity::Chara::autoAttack( CharaPtr pTarget )
auto effectPacket = std::make_shared< Server::EffectPacket >( getId(), pTarget->getId(), 7 );
effectPacket->setRotation( Util::floatToUInt16Rot( getRot() ) );
Common::EffectEntry effectEntry{};
effectEntry.value = damage;
effectEntry.value = static_cast<int16_t>(damage);
effectEntry.effectType = ActionEffectType::Damage;
effectEntry.hitSeverity = ActionHitSeverityType::NormalDamage;
effectEntry.param = 0x71;
@ -929,4 +929,4 @@ uint32_t Sapphire::Entity::Chara::getStatValue( Sapphire::Common::BaseParam base
}
return value + getBonusStat( baseParam );
}
}

View file

@ -183,7 +183,7 @@ namespace Sapphire::Entity
std::string getName() const;
bool face( const Common::FFXIVARR_POSITION3& p );
bool face( const Common::FFXIVARR_POSITION3& p , float epsilon = 0.005f);
Common::Stance getStance() const;

View file

@ -78,7 +78,7 @@ void World::Manager::ActionMgr::handleItemAction( Sapphire::Entity::Player& play
void World::Manager::ActionMgr::bootstrapAction( Entity::Player& player,
Action::ActionPtr currentAction,
Data::Action& actionData )
Data::Action& /*actionData*/ )
{
if( !currentAction->preCheck() )
{
@ -95,4 +95,4 @@ void World::Manager::ActionMgr::bootstrapAction( Entity::Player& player,
// todo: what do in cases of swiftcast/etc? script callback?
currentAction->start();
}
}

View file

@ -154,7 +154,7 @@ uint32_t CalcStats::calculateMaxHp( PlayerPtr pPlayer, Sapphire::FrameworkPtr pF
auto vitMod = pPlayer->getBonusStat( Common::BaseParam::Vitality );
float baseStat = calculateBaseStat( *pPlayer );
uint16_t vitStat = pPlayer->getStats().vit + static_cast< uint16_t >( vitMod );
uint16_t vitStat = static_cast< uint16_t >( pPlayer->getStats().vit ) + static_cast< uint16_t >( vitMod );
uint16_t hpMod = paramGrowthInfo->hpModifier;
uint16_t jobModHp = classInfo->modifierHitPoints;
float approxBaseHp = 0.0f; // Read above
@ -483,7 +483,7 @@ float CalcStats::calcActionDamage( const Sapphire::Entity::Chara& chara, uint32_
// D = ⌊ f(pot) × f(wd) × f(ap) × f(det) × f(tnc) × traits ⌋
// × f(chr) ⌋ × f(dhr) ⌋ × rand[ 0.95, 1.05 ] ⌋ buff_1 ⌋ × buff_1 ⌋ × buff... ⌋
auto pot = potency( ptc );
auto pot = potency( static_cast<uint16_t>(ptc) );
auto wd = weaponDamage( chara, wepDmg );
auto ap = getPrimaryAttackPower( chara );
auto det = determination( chara );
@ -513,4 +513,4 @@ float CalcStats::calcActionDamage( const Sapphire::Entity::Chara& chara, uint32_
uint32_t CalcStats::primaryStatValue( const Sapphire::Entity::Chara& chara )
{
return chara.getStatValue( chara.getPrimaryStat() );
}
}

View file

@ -38,7 +38,7 @@ void Sapphire::Network::GameConnection::actionHandler( FrameworkPtr pFw,
{
default:
{
player.sendDebug( "Skill type {0} not supported. Defaulting to normal action", type );
player.sendDebug( "Skill type {0} not supported. Defaulting to normal action", type ); break;
}
case Common::SkillType::Normal:
{

View file

@ -32,7 +32,7 @@ void Sapphire::Network::GameConnection::cfDutyInfoRequest( FrameworkPtr pFw,
// cap it since it's uint8_t in packets
penaltyMinutes = 255;
}
dutyInfoPacket->data().penaltyTime = penaltyMinutes;
dutyInfoPacket->data().penaltyTime = static_cast<uint8_t>(penaltyMinutes);
queueOutPacket( dutyInfoPacket );
auto inNeedsPacket = makeZonePacket< FFXIVIpcCFPlayerInNeed >( player.getId() );
@ -62,7 +62,7 @@ void Sapphire::Network::GameConnection::cfRegisterDuty( FrameworkPtr pFw,
}
// todo: rand bias problem, will do for now tho
auto index = std::rand() % selectedContent.size();
auto index = static_cast<uint32_t>(std::rand()) % selectedContent.size();
auto contentId = selectedContent.at( index );
player.sendDebug( "Duty register request for contentid#{0}", contentId );

View file

@ -11,10 +11,10 @@
Sapphire::Cell::Cell() :
m_bActive( false ),
m_bLoaded( false ),
m_playerCount( 0 ),
m_bUnloadPending( false )
m_bUnloadPending( false ),
m_playerCount( 0 )
{
m_bForcedActive = false;
m_bForcedActive = false;
}
Sapphire::Cell::~Cell()
@ -25,8 +25,8 @@ Sapphire::Cell::~Cell()
void Sapphire::Cell::init( uint32_t x, uint32_t y, TerritoryPtr pZone )
{
m_pZone = pZone;
m_posX = x;
m_posY = y;
m_posX = static_cast<uint16_t>(x);
m_posY = static_cast<uint16_t>(y);
m_actors.clear();
}