Ares
Public Member Functions

UnitDeliveryStateMachine Class Reference

#include <src/Misc/SWTypes.h>

Inheritance diagram for UnitDeliveryStateMachine:
SWStateMachine

List of all members.

Public Member Functions

 UnitDeliveryStateMachine (int Duration, CellStruct XY, SuperClass *pSuper, NewSWType *pSWType)
virtual void Update ()
void PlaceUnits ()

Constructor & Destructor Documentation

UnitDeliveryStateMachine::UnitDeliveryStateMachine ( int  Duration,
CellStruct  XY,
SuperClass *  pSuper,
NewSWType pSWType 
) [inline]
                        : SWStateMachine(Duration, XY, pSuper, pSWType) {};

Member Function Documentation

void UnitDeliveryStateMachine::PlaceUnits ( )
                                          {
        int unitIdx = 0;
        SWTypeExt::ExtData *pData = this->FindExtData();

        if(!pData) {
                return;
        }

        while(unitIdx < pData->SW_Deliverables.Count) {
                TechnoTypeClass * Type = pData->SW_Deliverables[unitIdx];
                TechnoClass * Item = generic_cast<TechnoClass *>(Type->CreateObject(this->Super->Owner));
                BuildingClass * ItemBuilding = specific_cast<BuildingClass *>(Item);

                if(ItemBuilding && pData->SW_DeliverBuildups) {
                        ItemBuilding->QueueMission(mission_Construction, false);
                }

                int cellIdx = 0;
                bool Placed = false;
                do {
                        CellStruct tmpCell = CellSpread::GetCell(cellIdx) + this->Coords;
                        if(MapClass::Instance->CellExists(&tmpCell)) {
                                CellClass *cell = MapClass::Instance->GetCellAt(&tmpCell);
                                CoordStruct XYZ;
                                cell->GetCoordsWithBridge(&XYZ);

                                bool validCell = true;
                                if(cell->OverlayTypeIndex != -1) {
                                        // disallow placing on rocks, rubble and walls
                                        OverlayTypeClass *Overlay = OverlayTypeClass::Array->GetItem(cell->OverlayTypeIndex);
                                        validCell = !Overlay->Wall && !Overlay->IsARock && !Overlay->IsRubble;
                                }
                                if(AircraftClass * ItemAircraft = specific_cast<AircraftClass *>(Item)) {
                                        // for aircraft: cell must be empty: non-water, non-cliff, non-shore, non-anything
                                        validCell &= !cell->GetContent() && !cell->Tile_Is_Cliff()
                                                && !cell->Tile_Is_DestroyableCliff() && !cell->Tile_Is_Shore()
                                                && !cell->Tile_Is_Water() && !cell->ContainsBridge();
                                }
                                if(Type->Naval && validCell) {
                                        // naval types look stupid on bridges
                                        validCell = (!cell->ContainsBridge() && cell->LandType != lt_Road)
                                                || Type->SpeedType == st_Hover;
                                }

                                if(validCell) {
                                        Item->OnBridge = cell->ContainsBridge();
                                        if((Placed = Item->Put(&XYZ, (cellIdx & 7))) == true) {
                                                if(ItemBuilding) {
                                                        if (pData->SW_DeliverBuildups) {
                                                                ItemBuilding->UpdateOwner(this->Super->Owner);
                                                                ItemBuilding->unknown_bool_6DD = 1;
                                                        }
                                                } else {
                                                        if(Type->BalloonHover || Type->JumpJet) {
                                                                Item->Scatter(0xB1CFE8, 1, 0);
                                                        }
                                                }
                                        }
                                }
                        }

                        ++cellIdx;
                        if(cellIdx >= 100) { // 100 cells should be enough for any sane delivery
                                cellIdx = 0;
                                if(!Placed) {
                                        Item->UnInit();
                                }
                                break;
                        }
                } while(!Placed);
                ++unitIdx;
        }
}
void UnitDeliveryStateMachine::Update ( ) [virtual]

Reimplemented from SWStateMachine.

                                      {
        switch(this->TimePassed()) {
        case 1:
                // play anim
                break;
        case 20:
                this->PlaceUnits();
                break;
        case 100:
                // write message
                break;
        };
}

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