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

JammerClass Class Reference

#include <src/Misc/JammerClass.h>

List of all members.

Public Member Functions

 JammerClass (TechnoClass *GameObject)
 JammerClass (TechnoClass *GameObject, TechnoExt::ExtData *pExt)
void UnjamAll ()
 Unregisters this Jammer on all structures.
void Update ()
 Updates this Jammer's status on all eligible structures.

Private Member Functions

bool InRangeOf (BuildingClass *)
 Calculates if the jammer is in range of this building.
bool IsEligible (BuildingClass *)
 Checks if this building can/should be jammed.
void Jam (BuildingClass *)
 Attempts to jam the given building. (Actually just registers the Jammer with it, the jamming happens in a hook.)
void Unjam (BuildingClass *)
 Attempts to unjam the given building. (Actually just unregisters the Jammer with it, the unjamming happens in a hook.)

Private Attributes

int LastScan
 Frame number when the last scan was performed.
TechnoClass * AttachedToObject
 Pointer to game object this jammer is on.
TechnoExt::ExtDataExt
 Pointer to the ExtData object this jammer is in.

Static Private Attributes

static const int ScanInterval = 30
 Minimum delay between scans in frames (two seconds/thirty frames).

Constructor & Destructor Documentation

JammerClass::JammerClass ( TechnoClass *  GameObject) [inline]
                                             : LastScan(0), AttachedToObject(NULL), Ext(NULL) {
                this->AttachedToObject = GameObject;
                this->Ext = TechnoExt::ExtMap.Find(GameObject);
        }
JammerClass::JammerClass ( TechnoClass *  GameObject,
TechnoExt::ExtData pExt 
) [inline]
                                                                     : LastScan(0), AttachedToObject(NULL), Ext(NULL) {
                this->AttachedToObject = GameObject;
                this->Ext = pExt;
        }

Member Function Documentation

bool JammerClass::InRangeOf ( BuildingClass *  TargetBuilding) [private]

Calculates if the jammer is in range of this building.

Parameters:
TargetBuildingThe building to check the distance to.
                                                         {
        TechnoTypeExt::ExtData* TTExt = TechnoTypeExt::ExtMap.Find(this->AttachedToObject->GetTechnoType());
        CoordStruct JammerLocation = this->AttachedToObject->Location;
        const double JamRadiusInLeptons = 256.0 * TTExt->RadarJamRadius;

        return (TargetBuilding->Location.DistanceFrom(JammerLocation) <= JamRadiusInLeptons);
}
bool JammerClass::IsEligible ( BuildingClass *  TargetBuilding) [private]

Checks if this building can/should be jammed.

Parameters:
TargetBuildingThe building whose eligibility to check.
                                                          {
        /* Current requirements for being eligible:
                - not an ally (includes ourselves)
                - either a radar or a spysat
        */
        return (!this->AttachedToObject->Owner->IsAlliedWith(TargetBuilding->Owner)
                        && (TargetBuilding->Type->Radar || TargetBuilding->Type->SpySat));
}
void JammerClass::Jam ( BuildingClass *  TargetBuilding) [private]

Attempts to jam the given building. (Actually just registers the Jammer with it, the jamming happens in a hook.)

Parameters:
TargetBuildingThe building to jam.
                                                   {
        BuildingExt::ExtData* TheBuildingExt = BuildingExt::ExtMap.Find(TargetBuilding);
        TheBuildingExt->RegisteredJammers.insert(this->AttachedToObject);
        TargetBuilding->Owner->RadarBlackout = true;
}
void JammerClass::Unjam ( BuildingClass *  TargetBuilding) [private]

Attempts to unjam the given building. (Actually just unregisters the Jammer with it, the unjamming happens in a hook.)

Parameters:
TargetBuildingThe building to unjam.
                                                     {
        BuildingExt::ExtData* TheBuildingExt = BuildingExt::ExtMap.Find(TargetBuilding);
        TheBuildingExt->RegisteredJammers.erase(this->AttachedToObject);
        TargetBuilding->Owner->RadarBlackout = true;
}
void JammerClass::UnjamAll ( )

Unregisters this Jammer on all structures.

                           {
        for(int i = 0; i < BuildingClass::Array->Count; ++i) {
                BuildingExt::ExtData* TheBuildingExt = BuildingExt::ExtMap.Find(BuildingClass::Array->GetItem(i));

                TheBuildingExt->RegisteredJammers.erase(this->AttachedToObject);
                TheBuildingExt->AttachedToObject->Owner->RadarBlackout = true;
        }
}
void JammerClass::Update ( )

Updates this Jammer's status on all eligible structures.

                         {
        // we don't want to scan & crunch numbers every frame - this limits it to ScanInterval frames
        if((Unsorted::CurrentFrame - this->LastScan) < this->ScanInterval) {
                return;
        }

        // walk through all buildings
        for(int i = 0; i < BuildingClass::Array->Count; ++i) {
                BuildingClass* curBuilding = BuildingClass::Array->GetItem(i);

                // for each jammable building ...
                if(this->IsEligible(curBuilding)) {
                        // ...check if it's in range, and jam or unjam based on that
                        if(this->InRangeOf(curBuilding)) {
                                this->Jam(curBuilding);
                        } else {
                                this->Unjam(curBuilding);
                        }
                } else {
                        this->Unjam(curBuilding); // doing this since it could be ineligible after a takeover, for example
                        // (e.g. we jammed it before as a hostile building, and then our Engineer took it over - wouldn't want it to be eternally jammed.)
                }
        }

        // lastly, save the current frame for future reference
        this->LastScan = Unsorted::CurrentFrame;
}

Member Data Documentation

TechnoClass* JammerClass::AttachedToObject [private]

Pointer to game object this jammer is on.

Pointer to the ExtData object this jammer is in.

int JammerClass::LastScan [private]

Frame number when the last scan was performed.

const int JammerClass::ScanInterval = 30 [static, private]

Minimum delay between scans in frames (two seconds/thirty frames).


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