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

SWTypeExt::ExtData Class Reference

#include <src/Ext/SWType/Body.h>

Inheritance diagram for SWTypeExt::ExtData:
Extension< TT >

List of all members.

Public Member Functions

 ExtData (const DWORD Canary, TT *const OwnerObject)
virtual ~ExtData ()
virtual size_t Size () const
virtual void LoadFromRulesFile (TT *pThis, CCINIClass *pINI)
virtual void LoadFromINIFile (TT *pThis, CCINIClass *pINI)
virtual void InitializeConstants (TT *pThis)
virtual void InitializeRuled (TT *pThis)
bool ChangeLighting ()
bool IsAnimVisible (HouseClass *pFirer)
bool CanFireAt (CellStruct *pCoords)
bool IsHouseAffected (HouseClass *pFirer, HouseClass *pHouse)
bool IsHouseAffected (HouseClass *pFirer, HouseClass *pHouse, SuperWeaponAffectedHouse::Value value)
bool IsTechnoAffected (TechnoClass *pTechno)
void PrintMessage (char *Message, HouseClass *pFirer)
NewSWTypeGetNewSWType ()
virtual void InvalidatePointer (void *ptr)

Public Attributes

ValueableIdx< int,
AircraftTypeClass > 
SpyPlane_TypeIndex
Valueable< int > SpyPlane_Count
ValueableIdx< int, MissionClass > SpyPlane_Mission
Valueable< int > Weather_Duration
Valueable< int > Weather_HitDelay
Valueable< int > Weather_ScatterDelay
Valueable< int > Weather_ScatterCount
Valueable< int > Weather_Separation
Valueable< int > Weather_CloudHeight
Valueable< int > Weather_RadarOutage
Valueable< int > Weather_DebrisMin
Valueable< int > Weather_DebrisMax
Valueable< bool > Weather_PrintText
Valueable< bool > Weather_IgnoreLightningRod
Valueable< AnimTypeClass * > Weather_BoltExplosion
TypeList< AnimTypeClass * > Weather_Clouds
TypeList< AnimTypeClass * > Weather_Bolts
TypeList< AnimTypeClass * > Weather_Debris
TypeList< int > Weather_Sounds
ValueableEnum
< SuperWeaponAffectedHouse
Weather_RadarOutageAffects
Valueable< WeaponTypeClass * > Nuke_Payload
Valueable< AnimTypeClass * > Nuke_PsiWarning
Valueable< AnimTypeClass * > Nuke_TakeOff
Valueable< bool > Nuke_SiloLaunch
hash_map< AbstractTypeClass
*, DynamicVectorClass
< ParadropPlane * > > 
ParaDrop
DynamicVectorClass
< ParadropPlane * > 
ParaDropPlanes
Customizable< int > Protect_Duration
Customizable< int > Protect_PlayFadeSoundTime
Customizable< int > Protect_PowerOutageDuration
Valueable< bool > Protect_IsForceShield
Valueable< AnimTypeClass * > Chronosphere_BlastSrc
Valueable< AnimTypeClass * > Chronosphere_BlastDest
Valueable< bool > Chronosphere_KillOrganic
Valueable< bool > Chronosphere_KillTeleporters
Valueable< bool > Chronosphere_AffectUndeployable
Valueable< bool > Chronosphere_AffectBuildings
Valueable< bool > Chronosphere_AffectUnwarpable
Valueable< bool > Chronosphere_AffectIronCurtain
Valueable< bool > Chronosphere_BlowUnplaceable
Valueable< bool > Chronosphere_ReconsiderBuildings
Valueable< bool > Mutate_Explosion
Valueable< bool > Mutate_IgnoreCyborg
Valueable< bool > Mutate_IgnoreNotHuman
Valueable< bool > Mutate_KillNatural
Valueable< bool > Dominator_Capture
Valueable< int > Dominator_FireAtPercentage
Valueable< int > Dominator_FirstAnimHeight
Valueable< int > Dominator_SecondAnimHeight
Customizable< AnimTypeClass * > Dominator_FirstAnim
Customizable< AnimTypeClass * > Dominator_SecondAnim
Customizable< AnimTypeClass * > Dominator_ControlAnim
Valueable< bool > Dominator_Ripple
Valueable< bool > Dominator_CaptureMindControlled
Valueable< bool > Dominator_CapturePermaMindControlled
Valueable< bool > Dominator_CaptureImmuneToPsionics
Valueable< bool > Dominator_PermanentCapture
Valueable< int > Sonar_Delay
Valueable< int > Money_Amount
Valueable< int > Money_DrainAmount
Valueable< int > Money_DrainDelay
ValueableIdx< int, VoxClass > EVA_Ready
ValueableIdx< int, VoxClass > EVA_Activated
ValueableIdx< int, VoxClass > EVA_Detected
ValueableIdx< int, VoxClass > EVA_Impatient
ValueableIdx< int, VoxClass > EVA_InsufficientFunds
ValueableIdx< int, VocClass > SW_Sound
ValueableIdx< int, VocClass > SW_ActivationSound
Valueable< AnimTypeClass * > SW_Anim
Valueable< int > SW_AnimHeight
ValueableEnum
< SuperWeaponAffectedHouse
SW_AnimVisibility
Valueable< bool > SW_TypeCustom
Valueable< bool > SW_AutoFire
Valueable< bool > SW_ManualFire
Valueable< bool > SW_FireToShroud
Valueable< bool > SW_RadarEvent
Valueable< bool > SW_ShowCameo
Valueable< bool > SW_Unstoppable
Valueable< MouseCursor > SW_Cursor
Valueable< MouseCursor > SW_NoCursor
char SW_PostDependent [0x18]
ValueableEnum
< SuperWeaponAITargetingMode
SW_AITargetingType
Customizable< double > SW_ChargeToDrainRatio
Valueable< float > SW_WidthOrRange
Valueable< int > SW_Height
ValueableEnum
< SuperWeaponAffectedHouse
SW_AffectsHouse
ValueableEnum
< SuperWeaponAffectedHouse
SW_RequiresHouse
ValueableEnum< SuperWeaponTargetSW_AffectsTarget
ValueableEnum< SuperWeaponTargetSW_RequiresTarget
Customizable< WarheadTypeClass * > SW_Warhead
Valueable< int > SW_Damage
Valueable< int > SW_Deferment
Valueable< bool > Lighting_Enabled
Customizable< int > Lighting_Ambient
Customizable< int > Lighting_Green
Customizable< int > Lighting_Blue
Customizable< int > Lighting_Red
char Message_Detected [0x20]
char Message_Ready [0x20]
char Message_Launch [0x20]
char Message_Activate [0x20]
char Message_Abort [0x20]
char Message_InsufficientFunds [0x20]
Valueable< int > Message_ColorScheme
Valueable< bool > Message_FirerColor
char Text_Preparing [0x20]
char Text_Hold [0x20]
char Text_Ready [0x20]
char Text_Charging [0x20]
char Text_Active [0x20]
CustomPalette CameoPal
DynamicVectorClass
< TechnoTypeClass * > 
SW_Deliverables
Valueable< bool > SW_DeliverBuildups
char SidebarPCX [0x20]
int HandledByNewSWType
int LastAction

Private Member Functions

bool IsCellEligible (CellClass *pCell, SuperWeaponTarget::Value allowed)
bool IsTechnoEligible (TechnoClass *pTechno, SuperWeaponTarget::Value allowed)

Static Private Member Functions

static
SuperWeaponAffectedHouse::Value 
GetRelation (HouseClass *pFirer, HouseClass *pHouse)

Constructor & Destructor Documentation

SWTypeExt::ExtData::ExtData ( const DWORD  Canary,
TT *const  OwnerObject 
) [inline]
SWTypeExt::ExtData::~ExtData ( ) [virtual]
                           {
        this->ParaDrop.clear();

        for(int i=this->ParaDropPlanes.Count-1; i>=0; --i) {
                delete this->ParaDropPlanes.Items[i];
                this->ParaDropPlanes.Items[i] = NULL;
        }
};

Member Function Documentation

bool SWTypeExt::ExtData::CanFireAt ( CellStruct *  pCoords)
                                                    {
        if(CellClass *pCell = MapClass::Instance->GetCellAt(pCoords)) {

                // check cell type
                if(!IsCellEligible(pCell, this->SW_RequiresTarget)) {
                        return false;
                }

                // check for techno type match
                TechnoClass *pTechno = generic_cast<TechnoClass*>(pCell->GetContent());
                if(pTechno && this->SW_RequiresHouse != SuperWeaponAffectedHouse::None) {
                        if(!IsHouseAffected(HouseClass::Player, pTechno->Owner, this->SW_RequiresHouse)) {
                                return false;
                        }
                }

                if(!IsTechnoEligible(pTechno, this->SW_RequiresTarget)) {
                        return false;
                }
        }

        // no restriction
        return true;
}
bool SWTypeExt::ExtData::ChangeLighting ( )
                                      {
        if(this->Lighting_Enabled.Get()) {
                auto getValue = [](int value, int def) -> int {
                        return (value < 0) ? def : value;
                };

                ScenarioClass* scen = ScenarioClass::Instance;
                scen->AmbientTarget = getValue(this->Lighting_Ambient, scen->AmbientOriginal);
                int cG = 1000 * getValue(this->Lighting_Green, scen->Green) / 100;
                int cB = 1000 * getValue(this->Lighting_Blue, scen->Blue)  / 100;
                int cR = 1000 * getValue(this->Lighting_Red, scen->Red)  / 100;
                scen->RecalcLighting(cR, cG, cB, 1);
                return true;
        }

        return false;
}
NewSWType * SWTypeExt::ExtData::GetNewSWType ( )
                                          {
        int TypeIdx = (this->HandledByNewSWType != -1 ? this->HandledByNewSWType : this->AttachedToObject->Type);
        RET_UNLESS(TypeIdx >= FIRST_SW_TYPE);

        if(NewSWType* pSW = NewSWType::GetNthItem(TypeIdx)) {
                return pSW;
        }

        return NULL;
}
SuperWeaponAffectedHouse::Value SWTypeExt::ExtData::GetRelation ( HouseClass *  pFirer,
HouseClass *  pHouse 
) [static, private]
                                                                                                  {
        // that's me!
        if(pFirer == pHouse) {
                return SuperWeaponAffectedHouse::Owner;
        }

        if(pFirer->IsAlliedWith(pHouse)) {
                // only friendly houses
                return SuperWeaponAffectedHouse::Allies;
        }

        // the bad guys
        return SuperWeaponAffectedHouse::Enemies;
}
void SWTypeExt::ExtData::InitializeConstants ( TT pThis) [virtual]
{
        if(!NewSWType::Array.Count) {
                NewSWType::Init();
        }

        MouseCursor *Cursor = &this->SW_Cursor;
        Cursor->Frame = 53; // Attack
        Cursor->Count = 5;
        Cursor->Interval = 5; // test?
        Cursor->MiniFrame = 52;
        Cursor->MiniCount = 1;
        Cursor->HotX = hotspx_center;
        Cursor->HotY = hotspy_middle;

        Cursor = &this->SW_NoCursor;
        Cursor->Frame = 0;
        Cursor->Count = 1;
        Cursor->Interval = 5;
        Cursor->MiniFrame = 1;
        Cursor->MiniCount = 1;
        Cursor->HotX = hotspx_center;
        Cursor->HotY = hotspy_middle;

        AresCRT::strCopy(this->Text_Ready, "TXT_READY", 0x20);
        AresCRT::strCopy(this->Text_Hold, "TXT_HOLD", 0x20);
        AresCRT::strCopy(this->Text_Charging, "TXT_CHARGING", 0x20);
        AresCRT::strCopy(this->Text_Active, "TXT_FIRESTORM_ON", 0x20);

        EVA_InsufficientFunds = VoxClass::FindIndex("EVA_InsufficientFunds");
}
void SWTypeExt::ExtData::InitializeRuled ( TT pThis) [virtual]
{
}
virtual void SWTypeExt::ExtData::InvalidatePointer ( void *  ptr) [inline, virtual]

Implements Extension< TT >.

                                                          {
                }
bool SWTypeExt::ExtData::IsAnimVisible ( HouseClass *  pFirer)
                                                       {
        SuperWeaponAffectedHouse::Value relation = GetRelation(pFirer, HouseClass::Player);
        return (this->SW_AnimVisibility & relation) == relation;
}
bool SWTypeExt::ExtData::IsCellEligible ( CellClass *  pCell,
SuperWeaponTarget::Value  allowed 
) [private]
                                                                                      {
        if(allowed & SuperWeaponTarget::AllCells) {
                bool isWater = (pCell->LandType == lt_Water);
                if(isWater && !(allowed & SuperWeaponTarget::Water)) {
                        // doesn't support water
                        return false;
                } else if(!isWater && !(allowed & SuperWeaponTarget::Land)) {
                        // doesn't support non-water
                        return false;
                }
        }
        return true;
}
bool SWTypeExt::ExtData::IsHouseAffected ( HouseClass *  pFirer,
HouseClass *  pHouse 
)
                                                                             {
        return IsHouseAffected(pFirer, pHouse, this->SW_AffectsHouse);
}
bool SWTypeExt::ExtData::IsHouseAffected ( HouseClass *  pFirer,
HouseClass *  pHouse,
SuperWeaponAffectedHouse::Value  value 
)
                                                                                                                  {
        SuperWeaponAffectedHouse::Value relation = GetRelation(pFirer, pHouse);
        return (value & relation) == relation;
}
bool SWTypeExt::ExtData::IsTechnoAffected ( TechnoClass *  pTechno)
                                                            {
        // check land and water cells
        if(!IsCellEligible(pTechno->GetCell(), this->SW_AffectsTarget)) {
                return false;
        }

        // check for specific techno type
        if(!IsTechnoEligible(pTechno, this->SW_AffectsTarget)) {
                return false;
        }

        // no restriction
        return true;
}
bool SWTypeExt::ExtData::IsTechnoEligible ( TechnoClass *  pTechno,
SuperWeaponTarget::Value  allowed 
) [private]
                                                                                            {
        if(allowed & SuperWeaponTarget::AllContents) {
                if(pTechno) {
                        eAbstractType abs_Techno = pTechno->WhatAmI();
                        if((abs_Techno == abs_Infantry) && !(allowed & SuperWeaponTarget::Infantry)) {
                                return false;
                        } else if(((abs_Techno == abs_Unit) || (abs_Techno == abs_Aircraft)) && !(allowed & SuperWeaponTarget::Unit)) {
                                return false;
                        } else if((abs_Techno == abs_Building) && !(allowed & SuperWeaponTarget::Building)) {
                                return false;
                        }
                } else {
                        // is the target cell allowed to be empty?
                        return (allowed & SuperWeaponTarget::NoContent) != 0;
                }
        }
        return true;
}
void SWTypeExt::ExtData::LoadFromINIFile ( TT pThis,
CCINIClass *  pINI 
) [virtual]
{
        const char * section = pThis->get_ID();

        if(!pINI->GetSection(section)) {
                return;
        }

        INI_EX exINI(pINI);

        // read general properties
        this->EVA_Ready.Read(&exINI, section, "EVA.Ready");
        this->EVA_Activated.Read(&exINI, section, "EVA.Activated");
        this->EVA_Detected.Read(&exINI, section, "EVA.Detected");
        this->EVA_Impatient.Read(&exINI, section, "EVA.Impatient");
        this->EVA_InsufficientFunds.Read(&exINI, section, "EVA.InsufficientFunds");

        this->SW_FireToShroud.Read(&exINI, section, "SW.FireIntoShroud");
        this->SW_AutoFire.Read(&exINI, section, "SW.AutoFire");
        this->SW_ManualFire.Read(&exINI, section, "SW.ManualFire");
        this->SW_RadarEvent.Read(&exINI, section, "SW.CreateRadarEvent");
        this->SW_ShowCameo.Read(&exINI, section, "SW.ShowCameo");
        this->SW_Unstoppable.Read(&exINI, section, "SW.Unstoppable");

        this->Money_Amount.Read(&exINI, section, "Money.Amount");
        this->Money_DrainAmount.Read(&exINI, section, "Money.DrainAmount");
        this->Money_DrainDelay.Read(&exINI, section, "Money.DrainDelay");

        this->SW_Sound.Read(&exINI, section, "SW.Sound");
        this->SW_ActivationSound.Read(&exINI, section, "SW.ActivationSound");

        this->SW_Anim.Parse(&exINI, section, "SW.Animation");
        this->SW_AnimHeight.Read(&exINI, section, "SW.AnimationHeight");

        this->SW_AnimVisibility.Read(&exINI, section, "SW.AnimationVisibility");
        this->SW_AffectsHouse.Read(&exINI, section, "SW.AffectsHouse");
        this->SW_AITargetingType.Read(&exINI, section, "SW.AITargeting");
        this->SW_AffectsTarget.Read(&exINI, section, "SW.AffectsTarget");
        this->SW_RequiresTarget.Read(&exINI, section, "SW.RequiresTarget");
        this->SW_RequiresHouse.Read(&exINI, section, "SW.RequiresHouse");

        this->SW_Deferment.Read(&exINI, section, "SW.Deferment");
        this->SW_ChargeToDrainRatio.Read(&exINI, section, "SW.ChargeToDrainRatio");

        this->SW_Cursor.Read(&exINI, section, "Cursor");
        this->SW_NoCursor.Read(&exINI, section, "NoCursor");

        this->SW_Warhead.Parse(&exINI, section, "SW.Warhead");
        this->SW_Damage.Read(&exINI, section, "SW.Damage");

        if(pINI->ReadString(section, "SW.Range", Ares::readDefval, Ares::readBuffer, Ares::readLength)) {
                char* p = strtok(Ares::readBuffer, Ares::readDelims);
                if(p && *p) {
                        this->SW_WidthOrRange = (float)atof(p);
                        this->SW_Height = -1;

                        p = strtok(NULL, Ares::readDelims);
                        if(p && *p) {
                                this->SW_Height = atoi(p);
                        }
                }
        }

        // lighting
        this->Lighting_Enabled.Read(&exINI, section, "Light.Enabled");
        this->Lighting_Ambient.Read(&exINI, section, "Light.Ambient");
        this->Lighting_Red.Read(&exINI, section, "Light.Red");
        this->Lighting_Green.Read(&exINI, section, "Light.Green");
        this->Lighting_Blue.Read(&exINI, section, "Light.Blue");

        auto readString = [&](char* value, char* key) {
                if(pINI->ReadString(section, key, Ares::readDefval, Ares::readBuffer, Ares::readLength)) {
                        AresCRT::strCopy(value, Ares::readBuffer, 0x20);
                }
        };

        // messages and their properties
        this->Message_FirerColor.Read(&exINI, section, "Message.FirerColor");
        if(pINI->ReadString(section, "Message.Color", Ares::readDefval, Ares::readBuffer, Ares::readLength)) {
                this->Message_ColorScheme = ColorScheme::FindIndex(Ares::readBuffer);
                if(!this->Message_ColorScheme) {
                        Debug::INIParseFailed(section, "Message.Color", Ares::readBuffer, "Expected a valid color scheme name.");
                }
        }

        readString(this->Message_Detected, "Message.Detected");
        readString(this->Message_Ready, "Message.Ready");
        readString(this->Message_Launch, "Message.Launch");
        readString(this->Message_Activate, "Message.Activate");
        readString(this->Message_Abort, "Message.Abort");
        readString(this->Message_InsufficientFunds, "Message.InsufficientFunds");

        readString(this->Text_Preparing, "Text.Preparing");
        readString(this->Text_Ready, "Text.Ready");
        readString(this->Text_Hold, "Text.Hold");
        readString(this->Text_Charging, "Text.Charging");
        readString(this->Text_Active, "Text.Active");

        // the fallback is handled in the PreDependent SW's code
        if(pINI->ReadString(section, "SW.PostDependent", Ares::readDefval, Ares::readBuffer, Ares::readLength)) {
                AresCRT::strCopy(this->SW_PostDependent, Ares::readBuffer, 0x18);
        }

        // find a NewSWType that handles this original one.
        int idxNewSWType = ((pThis->Type < FIRST_SW_TYPE) ? this->HandledByNewSWType : pThis->Type);

        // initialize the NewSWType that handles this SWType.
        int Type = idxNewSWType - FIRST_SW_TYPE;
        if(Type >= 0 && Type < NewSWType::Array.Count) {
                pThis->Action = this->LastAction;
                NewSWType *swt = NewSWType::GetNthItem(idxNewSWType);
                swt->LoadFromINI(this, pThis, pINI);
                this->LastAction = pThis->Action;

                // whatever the user does, we take care of the stupid tags.
                // there is no need to have them not hardcoded.
                SuperWeaponFlags::Value flags = swt->Flags();
                pThis->PreClick = ((flags & SuperWeaponFlags::PreClick) != 0);
                pThis->PostClick = ((flags & SuperWeaponFlags::PostClick) != 0);
                pThis->PreDependent = -1;
        }

        this->CameoPal.LoadFromINI(pINI, pThis->ID, "SidebarPalette");

        if(pINI->ReadString(section, "SidebarPCX", "", Ares::readBuffer, Ares::readLength)) {
                AresCRT::strCopy(this->SidebarPCX, Ares::readBuffer, 0x20);
                _strlwr_s(this->SidebarPCX, 0x20);
                if(!PCX::Instance->LoadFile(this->SidebarPCX)) {
                        Debug::INIParseFailed(section, "SidebarPCX", this->SidebarPCX);
                }
        }
}
void SWTypeExt::ExtData::LoadFromRulesFile ( TT pThis,
CCINIClass *  pINI 
) [virtual]
{
        const char * section = pThis->get_ID();

        if(!pINI->GetSection(section)) {
                return;
        }

        INI_EX exINI(pINI);

        if(exINI.ReadString(section, "Action") && !_strcmpi(exINI.value(), "Custom")) {
                pThis->Action = SW_YES_CURSOR;
        }

        if(exINI.ReadString(section, "Type")) {
                int customType = NewSWType::FindIndex(exINI.value());
                if(customType > -1) {
                        pThis->Type = customType;
                }
        }

        // find a NewSWType that handles this original one.
        int idxNewSWType = -1;
        if(pThis->Type < FIRST_SW_TYPE) {
                this->HandledByNewSWType = NewSWType::FindHandler(pThis->Type);
                idxNewSWType = this->HandledByNewSWType;
        } else {
                idxNewSWType = pThis->Type;
        }

        // if this is handled by a NewSWType, initialize it.
        if(idxNewSWType != -1) {
                pThis->Action = SW_YES_CURSOR;
                if(NewSWType *swt = NewSWType::GetNthItem(idxNewSWType)) {
                        swt->Initialize(this, pThis);
                }
        }
        this->LastAction = pThis->Action;
}
void SWTypeExt::ExtData::PrintMessage ( char *  Message,
HouseClass *  pFirer 
)
                                                                      {
        if(!pMessage || !*pMessage) {
                return;
        }

        int color = ColorScheme::FindIndex("Gold");
        if(this->Message_FirerColor.Get()) {
                // firer color
                if(pFirer) {
                        color = pFirer->ColorSchemeIndex;
                }
        } else {
                if(this->Message_ColorScheme > -1) {
                        // user defined color
                        color = this->Message_ColorScheme;
                } else if(HouseClass::Player) {
                        // default way: the current player's color
                        color = HouseClass::Player->ColorSchemeIndex;
                }
        }

        // print the message
        const wchar_t* label = StringTable::LoadStringA(pMessage);
        if(label && *label) {
                MessageListClass::Instance->PrintMessage(label, color);
        }
}
virtual size_t SWTypeExt::ExtData::Size ( ) const [inline, virtual]

Implements Extension< TT >.

{ return sizeof(*this); };

Member Data Documentation

hash_map<AbstractTypeClass*, DynamicVectorClass<ParadropPlane*> > SWTypeExt::ExtData::ParaDrop
DynamicVectorClass<TechnoTypeClass *> SWTypeExt::ExtData::SW_Deliverables
TypeList<AnimTypeClass*> SWTypeExt::ExtData::Weather_Bolts
TypeList<AnimTypeClass*> SWTypeExt::ExtData::Weather_Clouds
TypeList<AnimTypeClass*> SWTypeExt::ExtData::Weather_Debris

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