Ares
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes

PoweredUnitClass Class Reference

#include <src/Misc/PoweredUnitClass.h>

List of all members.

Public Member Functions

 PoweredUnitClass (TechnoClass *Techno, TechnoTypeExt::ExtData *Ext)
 ~PoweredUnitClass ()
 Updates this Powered Unit's status.
void Update ()
 Whether the unit has a building providing power. NOT the same as being online.
bool IsPowered () const

Private Member Functions

bool IsPoweredBy (HouseClass *Owner) const
void PowerUp ()
void PowerDown ()

Private Attributes

TechnoClass * Techno
TechnoTypeExt::ExtDataExt
int LastScan
 Frame number when the last scan was performed.
bool Powered
 Whether the unit has a building providing power. NOT the same as being online.

Static Private Attributes

static const int ScanInterval = 15
 Minimum delay between scans in frames.

Constructor & Destructor Documentation

PoweredUnitClass::PoweredUnitClass ( TechnoClass *  Techno,
TechnoTypeExt::ExtData Ext 
) [inline]
                : Techno(Techno), Ext(Ext), LastScan(0), Powered(true) {
        }
PoweredUnitClass::~PoweredUnitClass ( ) [inline]

Updates this Powered Unit's status.


Member Function Documentation

bool PoweredUnitClass::IsPowered ( ) const [inline]
                                      {
                return this->Powered;
        }
bool PoweredUnitClass::IsPoweredBy ( HouseClass *  Owner) const [private]
{
        for(int i = 0; i < Owner->Buildings.Count; ++i) {
                auto Building  = Owner->Buildings.GetItem(i);
                auto BExt = TechnoExt::ExtMap.Find(Building);
                auto inArray = this->Ext->PoweredBy.FindItemIndex(&Building->Type) != -1;

                if(inArray && !Building->BeingWarpedOut && !Building->IsUnderEMP() && BExt->IsOperated() && Building->IsPowerOnline()) {
                        return true;
                }
        }
        
        return false;
}
void PoweredUnitClass::PowerDown ( ) [private]
{
        if( EMPulse::IsDeactivationAdvisable(this->Techno) && !EMPulse::EnableEMPEffect2(this->Techno) ) {
                // for EMP.Threshold=inair
                if( this->Ext->EMP_Threshold < 0 && this->Techno->IsInAir() )   {
                        this->Techno->Destroyed(NULL);
                        this->Techno->Crash(NULL);
                        
                        if (this->Techno->Owner == HouseClass::Player) {
                                VocClass::PlayAt(this->Techno->GetTechnoType()->VoiceCrashing, &this->Techno->Location, NULL);
                        }
                }
        }
}
void PoweredUnitClass::PowerUp ( ) [private]
{
        TechnoExt::ExtData* e = TechnoExt::ExtMap.Find(this->Techno);
        if( !this->Techno->IsUnderEMP() && e->IsOperated() ) {
                EMPulse::DisableEMPEffect2(this->Techno);
        }
}
void PoweredUnitClass::Update ( )

Whether the unit has a building providing power. NOT the same as being online.

{
        if( (Unsorted::CurrentFrame - this->LastScan) < this->ScanInterval ) return;
        
        HouseClass* Owner = this->Techno->Owner;
        bool HasPower     = this->IsPoweredBy(Owner);
        
        this->Powered = HasPower;
        
        if(HasPower && this->Techno->Deactivated) {
                this->PowerUp();
        } else if(!HasPower && !this->Techno->Deactivated) {
                // don't shutdown units inside buildings (warfac, barracks, shipyard) because that locks up the factory and the robot tank did it
                auto WhatAmI = this->Techno->WhatAmI();
                if((WhatAmI != InfantryClass::AbsID && WhatAmI != UnitClass::AbsID) || (!this->Techno->GetCell()->GetBuilding())) {
                        this->PowerDown();
                }
        }
        
        LastScan = Unsorted::CurrentFrame;
}

Member Data Documentation

Frame number when the last scan was performed.

bool PoweredUnitClass::Powered [private]

Whether the unit has a building providing power. NOT the same as being online.

const int PoweredUnitClass::ScanInterval = 15 [static, private]

Minimum delay between scans in frames.

TechnoClass* PoweredUnitClass::Techno [private]

The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines