Ares
Classes | Public Member Functions | Protected Attributes

ChronoWarpStateMachine Class Reference

#include <src/Misc/SWTypes.h>

Inheritance diagram for ChronoWarpStateMachine:
SWStateMachine

List of all members.

Classes

struct  ChronoWarpContainer

Public Member Functions

 ChronoWarpStateMachine (int Duration, CellStruct XY, SuperClass *pSuper, NewSWType *pSWType, DynamicVectorClass< ChronoWarpContainer > *Buildings)
virtual void Update ()
virtual void PointerGotInvalid (void *ptr)

Protected Attributes

DynamicVectorClass
< ChronoWarpContainer
Buildings
int Duration

Constructor & Destructor Documentation

ChronoWarpStateMachine::ChronoWarpStateMachine ( int  Duration,
CellStruct  XY,
SuperClass *  pSuper,
NewSWType pSWType,
DynamicVectorClass< ChronoWarpContainer > *  Buildings 
) [inline]
                        : SWStateMachine(Duration, XY, pSuper, pSWType)
                {
                        for(int i=0; i<Buildings->Count; ++i) {
                                this->Buildings.AddItem(Buildings->GetItem(i));
                        }
                        this->Duration = Duration;
                };

Member Function Documentation

void ChronoWarpStateMachine::PointerGotInvalid ( void *  ptr) [virtual]

Reimplemented from SWStateMachine.

                                                        {
        for(int i=0; i<this->Buildings.Count; ++i) {
                if(this->Buildings.GetItem(i).pBld == ptr) {
                        this->Buildings.RemoveItem(i);
                        break;
                }
        }
}
void ChronoWarpStateMachine::Update ( ) [virtual]

Reimplemented from SWStateMachine.

                                    {
        int passed = this->TimePassed();

        if(passed == 1) {
                // redraw all buildings
                for(int i=0; i<this->Buildings.Count; ++i) {
                        ChronoWarpContainer Container = this->Buildings.GetItem(i);
                        if(Container.pBld) {
                                Container.pBld->SetLayer(Layer::Ground);
                        }
                }
        } else if(passed == this->Duration - 1) {
                // copy the array so items can't get invalidated
                DynamicVectorClass<ChronoWarpContainer> buildings;
                for(int i=0; i<this->Buildings.Count; ++i) {
                        buildings.AddItem(this->Buildings.GetItem(i));
                }
                this->Buildings.Clear();

                // remove all buildings from the map at once
                for(int i=0; i<buildings.Count; ++i) {
                        ChronoWarpContainer* pContainer = &buildings.Items[i];
                        pContainer->pBld->Remove();
                        pContainer->pBld->ActuallyPlacedOnMap = false;
                }

                // bring back all buildings
                for(int i=0; i<buildings.Count; ++i) {
                        ChronoWarpContainer pContainer = buildings.GetItem(i);
                        if(BuildingClass* pBld = pContainer.pBld) {

                                if(!pBld->TemporalTargetingMe) {
                                        // use some logic to place this unit on some other
                                        // cell if the target cell is occupied. this emulates
                                        // the behavior of other units.
                                        bool success = false;
                                        int count = CellSpread::NumCells(10);
                                        int idx = 0;
                                        do {
                                                CellStruct cellNew = CellSpread::GetCell(idx) + pContainer.target;
                                                CellClass* pNewCell = MapClass::Instance->GetCellAt(&cellNew);
                                                CoordStruct coordsNew;
                                                pNewCell->GetCoordsWithBridge(&coordsNew);

                                                if(pBld->Type->CanCreateHere(&cellNew, 0)) {
                                                        if(pBld->Put(&coordsNew, Direction::North)) {
                                                                success = true;
                                                                break;
                                                        }
                                                }
                                                ++idx;
                                        } while(pContainer.isVehicle && (idx<count));

                                        if(!success) {
                                                // put it back where it was
                                                ++Unsorted::IKnowWhatImDoing;
                                                pBld->Put(&pContainer.origin, Direction::North);
                                                pBld->Place(false);
                                                --Unsorted::IKnowWhatImDoing;
                                        }

                                        // chronoshift ends
                                        pBld->BeingWarpedOut = false;
                                        pBld->Owner->PowerBlackout = true;
                                        pBld->Owner->ShouldRecheckTechTree = true;
                                        pBld->EnableTemporal();
                                        pBld->SetLayer(Layer::Ground);

                                        BuildingExt::ExtData* pBldExt = BuildingExt::ExtMap.Find(pBld);
                                        pBldExt->AboutToChronoshift = false;

                                        if(!success) {
                                                if(SWTypeExt::ExtData *pExt = SWTypeExt::ExtMap.Find(this->Super->Type)) {
                                                        // destroy (buildings only if they are supposed to)
                                                        if(pContainer.isVehicle || pExt->Chronosphere_BlowUnplaceable.Get()) {
                                                                int damage = pBld->Type->Strength;
                                                                pBld->ReceiveDamage(&damage, 0,
                                                                        RulesClass::Instance->C4Warhead, NULL, TRUE, TRUE, this->Super->Owner);
                                                        }
                                                }
                                        }
                                }
                        }
                }
        } else if(passed == this->Duration) {
                Super->Owner->PowerBlackout = true;
                Super->Owner->ShouldRecheckTechTree = true;
                Super->Owner->RadarBlackout = true;
        }
}

Member Data Documentation

DynamicVectorClass<ChronoWarpContainer> ChronoWarpStateMachine::Buildings [protected]

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