Cleaned up some long lists of ifs

master
krzys-h 2015-08-18 12:29:41 +02:00
parent a5c84b9a1e
commit 28925106e4
9 changed files with 75 additions and 141 deletions

View File

@ -1891,11 +1891,21 @@ CObject* CRobotMain::DetectObject(Math::Point pos)
if (obj->GetProxyActivate()) continue;
CObject* target = obj;
if (obj->GetType() == OBJECT_POWER || obj->GetType() == OBJECT_ATOMIC)
if (obj->Implements(ObjectInterfaceType::PowerContainer) && obj->Implements(ObjectInterfaceType::Transportable))
{
assert(obj->Implements(ObjectInterfaceType::Transportable));
target = dynamic_cast<CTransportableObject*>(obj)->GetTransporter(); // battery connected
if (target == nullptr) target = obj; // standalone battery
if (target == nullptr)
{
target = obj; // standalone battery
}
else
{
if (!target->Implements(ObjectInterfaceType::Powered) || dynamic_cast<CPoweredObject*>(target)->GetPower() != obj)
{
// transported, but not in the power slot
target = obj;
}
}
}
if (!obj->Implements(ObjectInterfaceType::Old)) continue;

View File

@ -423,46 +423,7 @@ bool CAutoConvert::SearchVehicle()
for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects())
{
ObjectType type = obj->GetType();
if ( type != OBJECT_HUMAN &&
type != OBJECT_MOBILEfa &&
type != OBJECT_MOBILEta &&
type != OBJECT_MOBILEwa &&
type != OBJECT_MOBILEia &&
type != OBJECT_MOBILEfc &&
type != OBJECT_MOBILEtc &&
type != OBJECT_MOBILEwc &&
type != OBJECT_MOBILEic &&
type != OBJECT_MOBILEfi &&
type != OBJECT_MOBILEti &&
type != OBJECT_MOBILEwi &&
type != OBJECT_MOBILEii &&
type != OBJECT_MOBILEfs &&
type != OBJECT_MOBILEts &&
type != OBJECT_MOBILEws &&
type != OBJECT_MOBILEis &&
type != OBJECT_MOBILErt &&
type != OBJECT_MOBILErc &&
type != OBJECT_MOBILErr &&
type != OBJECT_MOBILErs &&
type != OBJECT_MOBILEsa &&
type != OBJECT_MOBILEtg &&
type != OBJECT_MOBILEft &&
type != OBJECT_MOBILEtt &&
type != OBJECT_MOBILEwt &&
type != OBJECT_MOBILEit &&
type != OBJECT_MOBILEdr &&
type != OBJECT_METAL &&
type != OBJECT_URANIUM &&
type != OBJECT_POWER &&
type != OBJECT_ATOMIC &&
type != OBJECT_BULLET &&
type != OBJECT_BBOX &&
type != OBJECT_TNT &&
type != OBJECT_MOTHER &&
type != OBJECT_ANT &&
type != OBJECT_SPIDER &&
type != OBJECT_BEE &&
type != OBJECT_WORM ) continue;
if ( type == OBJECT_STONE ) continue;
if (obj->GetCrashSphereCount() == 0) continue;

View File

@ -111,6 +111,35 @@ std::vector<CrashSphere> CObject::GetAllCrashSpheres()
return allCrashSpheres;
}
bool CObject::CanCollideWith(CObject* other)
{
ObjectType otherType = other->GetType();
if (m_type == OBJECT_WORM) return otherType == OBJECT_WORM;
if (m_type == OBJECT_MOTHER)
{
if (otherType == OBJECT_ANT) return false;
if (otherType == OBJECT_SPIDER) return false;
if (otherType == OBJECT_EGG) return false;
}
if (otherType == OBJECT_MOTHER)
{
if (m_type == OBJECT_ANT) return false;
if (m_type == OBJECT_SPIDER) return false;
if (m_type == OBJECT_EGG) return false;
}
if ( m_type == OBJECT_MOTHER ||
m_type == OBJECT_ANT ||
m_type == OBJECT_SPIDER ||
m_type == OBJECT_WORM ||
m_type == OBJECT_BEE )
{
if (other->Implements(ObjectInterfaceType::Transportable)) return false;
if (otherType >= OBJECT_PLANT0 && otherType <= OBJECT_PLANT19) return false;
if (otherType >= OBJECT_MUSHROOM1 && otherType <= OBJECT_MUSHROOM2) return false;
}
return true;
}
Math::Vector CObject::GetPosition() const
{
return m_position;

View File

@ -149,6 +149,8 @@ public:
std::vector<CrashSphere> GetAllCrashSpheres();
//! Removes all crash spheres
void DeleteAllCrashSpheres();
//! Returns true if this object can collide with the other one
bool CanCollideWith(CObject* other);
//! Returns sphere used to test for camera collisions
Math::Sphere GetCameraCollisionSphere();

View File

@ -537,14 +537,7 @@ void COldObject::DestroyObject(DestructionType type)
if ( m_botVar != nullptr )
{
if ( m_type == OBJECT_STONE ||
m_type == OBJECT_URANIUM ||
m_type == OBJECT_METAL ||
m_type == OBJECT_POWER ||
m_type == OBJECT_ATOMIC ||
m_type == OBJECT_BULLET ||
m_type == OBJECT_BBOX ||
m_type == OBJECT_TNT ) // (*)
if ( Implements(ObjectInterfaceType::Transportable) ) // (*)
{
CScriptFunctions::DestroyObjectVar(m_botVar, false);
}
@ -880,8 +873,10 @@ void COldObject::SetType(ObjectType type)
}
// TODO: Another one? :/
if ( m_type == OBJECT_POWER || // PowerCell
m_type == OBJECT_ATOMIC ) // NuclearCell
if ( m_type == OBJECT_POWER || // PowerCell
m_type == OBJECT_ATOMIC || // NuclearCell
m_type == OBJECT_STATION || // PowerStation
m_type == OBJECT_ENERGY ) // PowerPlant
{
m_implementedInterfaces[static_cast<int>(ObjectInterfaceType::PowerContainer)] = true;
}
@ -2171,10 +2166,7 @@ bool COldObject::EventFrame(const Event &event)
void COldObject::UpdateMapping()
{
if ( m_type == OBJECT_POWER ||
m_type == OBJECT_ATOMIC ||
m_type == OBJECT_STATION ||
m_type == OBJECT_ENERGY )
if ( Implements(ObjectInterfaceType::PowerContainer) )
{
UpdateEnergyMapping();
}

View File

@ -633,8 +633,7 @@ Error CTaskManip::IsEnded()
{
if ( (m_arm == TMA_OTHER ||
m_arm == TMA_POWER ) &&
(m_cargoType == OBJECT_POWER ||
m_cargoType == OBJECT_ATOMIC ) )
m_object->GetCargo()->Implements(ObjectInterfaceType::PowerContainer) )
{
m_sound->Play(SOUND_POWEROFF, m_object->GetPosition());
}
@ -656,8 +655,7 @@ Error CTaskManip::IsEnded()
{
if ( (m_arm == TMA_OTHER ||
m_arm == TMA_POWER ) &&
(m_cargoType == OBJECT_POWER ||
m_cargoType == OBJECT_ATOMIC ) )
cargo->Implements(ObjectInterfaceType::PowerContainer) )
{
m_sound->Play(SOUND_POWERON, m_object->GetPosition());
}

View File

@ -131,19 +131,10 @@ Error CTaskTake::Start()
if (other != nullptr && dynamic_cast<CPoweredObject*>(other)->GetPower() != nullptr)
{
type = dynamic_cast<CPoweredObject*>(other)->GetPower()->GetType();
CObject* power = dynamic_cast<CPoweredObject*>(other)->GetPower();
type = power->GetType();
if ( type == OBJECT_URANIUM ) return ERR_MANIP_RADIO;
if ( type != OBJECT_STONE &&
type != OBJECT_BULLET &&
type != OBJECT_METAL &&
type != OBJECT_POWER &&
type != OBJECT_ATOMIC &&
type != OBJECT_BBOX &&
type != OBJECT_KEYa &&
type != OBJECT_KEYb &&
type != OBJECT_KEYc &&
type != OBJECT_KEYd &&
type != OBJECT_TNT ) return ERR_MANIP_FRIEND;
if ( !power->Implements(ObjectInterfaceType::Transportable) ) return ERR_MANIP_FRIEND; // TODO: This makes no sense, probably redundant
//? m_camera->StartCentering(m_object, Math::PI*0.3f, -Math::PI*0.1f, 0.0f, 0.8f);
m_arm = TTA_FRIEND;
}
@ -240,8 +231,7 @@ Error CTaskTake::IsEnded()
if ( TransporterTakeObject() )
{
if ( m_arm == TTA_FRIEND &&
(m_cargoType == OBJECT_POWER ||
m_cargoType == OBJECT_ATOMIC ) )
m_object->GetCargo()->Implements(ObjectInterfaceType::PowerContainer) )
{
m_sound->Play(SOUND_POWEROFF, m_object->GetPosition());
}
@ -261,8 +251,7 @@ Error CTaskTake::IsEnded()
CObject* cargo = m_object->GetCargo();
TransporterDeposeObject();
if ( m_arm == TTA_FRIEND &&
(m_cargoType == OBJECT_POWER ||
m_cargoType == OBJECT_ATOMIC ) )
cargo->Implements(ObjectInterfaceType::PowerContainer) )
{
m_sound->Play(SOUND_POWERON, m_object->GetPosition());
}
@ -300,7 +289,6 @@ CObject* CTaskTake::SearchTakeObject(float &angle,
{
CObject *pBest;
Math::Vector iPos, oPos;
ObjectType type;
float min, iAngle, bAngle, a, distance;
iPos = m_object->GetPosition();
@ -312,20 +300,7 @@ CObject* CTaskTake::SearchTakeObject(float &angle,
bAngle = 0.0f;
for (CObject* pObj : CObjectManager::GetInstancePointer()->GetAllObjects())
{
type = pObj->GetType();
if ( type != OBJECT_STONE &&
type != OBJECT_URANIUM &&
type != OBJECT_BULLET &&
type != OBJECT_METAL &&
type != OBJECT_POWER &&
type != OBJECT_ATOMIC &&
type != OBJECT_BBOX &&
type != OBJECT_KEYa &&
type != OBJECT_KEYb &&
type != OBJECT_KEYc &&
type != OBJECT_KEYd &&
type != OBJECT_TNT ) continue;
if ( !pObj->Implements(ObjectInterfaceType::Transportable) ) continue;
if (IsObjectBeingTransported(pObj)) continue;
if ( pObj->GetLock() ) continue;

View File

@ -2496,45 +2496,14 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle)
if ( pObj->Implements(ObjectInterfaceType::Destroyable) && dynamic_cast<CDestroyableObject*>(pObj)->IsDying() ) continue; // is burning or exploding?
oType = pObj->GetType();
if ( oType == OBJECT_NULL ) continue;
if ( oType == OBJECT_TOTO ) continue;
//? if ( iType == OBJECT_BEE && oType == OBJECT_BEE ) continue;
if ( iType == OBJECT_WORM && oType != OBJECT_WORM ) continue;
if ( iType != OBJECT_WORM && oType == OBJECT_WORM ) continue;
if ( iType == OBJECT_MOTHER && oType == OBJECT_ANT ) continue;
if ( iType == OBJECT_ANT && oType == OBJECT_MOTHER ) continue;
if ( iType == OBJECT_MOTHER && oType == OBJECT_SPIDER ) continue;
if ( iType == OBJECT_SPIDER && oType == OBJECT_MOTHER ) continue;
if ( iType == OBJECT_MOTHER && oType == OBJECT_EGG ) continue;
if ( iType == OBJECT_EGG && oType == OBJECT_MOTHER ) continue;
if ( oType == OBJECT_TOTO ) continue;
if ( !m_object->CanCollideWith(pObj) ) continue;
if (pObj->Implements(ObjectInterfaceType::Jostleable))
{
JostleObject(dynamic_cast<CJostleableObject*>(pObj), iPos, iRad);
}
if ( iType == OBJECT_MOTHER ||
iType == OBJECT_ANT ||
iType == OBJECT_SPIDER ||
iType == OBJECT_WORM ||
iType == OBJECT_BEE ) // insect?
{
if ( oType == OBJECT_STONE ||
oType == OBJECT_URANIUM ||
oType == OBJECT_METAL ||
oType == OBJECT_POWER ||
oType == OBJECT_ATOMIC ||
oType == OBJECT_BULLET ||
oType == OBJECT_BBOX ||
oType == OBJECT_KEYa ||
oType == OBJECT_KEYb ||
oType == OBJECT_KEYc ||
oType == OBJECT_KEYd ||
oType == OBJECT_TNT ||
(oType >= OBJECT_PLANT0 && oType <= OBJECT_PLANT19 ) ||
(oType >= OBJECT_MUSHROOM1 && oType <= OBJECT_MUSHROOM2) ) continue;
}
if ( oType == OBJECT_WAYPOINT &&
!pObj->GetLock() &&
m_object->GetTrainer() ) // driving vehicle?
@ -2564,6 +2533,8 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle)
Math::Vector oPos = crashSphere.sphere.pos;
float oRad = crashSphere.sphere.radius;
// Aliens ignore small objects
// TODO: But why? :/
if ( iType == OBJECT_MOTHER && oRad <= 1.2f ) continue;
if ( iType == OBJECT_ANT && oRad <= 1.2f ) continue;
if ( iType == OBJECT_SPIDER && oRad <= 1.2f ) continue;
@ -2966,7 +2937,8 @@ void CPhysics::PowerParticle(float factor, bool bBreak)
if (m_object->Implements(ObjectInterfaceType::Carrier))
{
CObject* cargo = dynamic_cast<CCarrierObject*>(m_object)->GetCargo();
if ( cargo != nullptr && cargo->GetType() == OBJECT_POWER &&
if ( cargo != nullptr && cargo->Implements(ObjectInterfaceType::PowerContainer) &&
dynamic_cast<CPowerContainerObject*>(cargo)->IsRechargeable() &&
m_object->GetPartRotationZ(1) == ARM_STOCK_ANGLE1 )
{
bCarryPower = true; // carries a battery

View File

@ -140,12 +140,17 @@ CObject* CTarget::DetectFriendObject(Math::Point pos)
for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects())
{
if ( !obj->GetDetectable() ) continue;
if ( obj->GetProxyActivate() ) continue;
if ( obj->Implements(ObjectInterfaceType::Controllable) && dynamic_cast<CControllableObject*>(obj)->GetSelect() ) continue;
CObject* target = obj;
if ( obj->Implements(ObjectInterfaceType::PowerContainer) && IsObjectBeingTransported(obj) )
{
target = dynamic_cast<CTransportableObject*>(obj)->GetTransporter();
}
CObject* target = nullptr;
ObjectType type = obj->GetType();
if ( !target->GetDetectable() ) continue;
if ( target->GetProxyActivate() ) continue;
if ( target->Implements(ObjectInterfaceType::Controllable) && dynamic_cast<CControllableObject*>(target)->GetSelect() ) continue;
ObjectType type = target->GetType();
if ( type == OBJECT_DERRICK ||
type == OBJECT_FACTORY ||
type == OBJECT_REPAIR ||
@ -194,16 +199,6 @@ CObject* CTarget::DetectFriendObject(Math::Point pos)
{
target = obj;
}
else if ( (type == OBJECT_POWER ||
type == OBJECT_ATOMIC ) &&
IsObjectBeingTransported(obj) ) // battery used?
{
target = dynamic_cast<CTransportableObject*>(obj)->GetTransporter();
if ( target->GetType() == OBJECT_MOBILEtg )
{
target = nullptr;
}
}
for (int j=0 ; j<OBJECTMAXPART ; j++ )
{