Ares
Classes | Public Types | Static Public Member Functions | Static Public Attributes

BuildingExt Class Reference

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

List of all members.

Classes

class  cPrismForwarding
class  ExtData

Public Types

typedef BuildingClass TT

Static Public Member Functions

static DWORD GetFirewallFlags (BuildingClass *pThis)
static void buildLines (BuildingClass *, CellStruct, HouseClass *)
static void UpdateDisplayTo (BuildingClass *pThis)
static signed int GetImageFrameIndex (BuildingClass *pThis)
static void KickOutHospitalArmory (BuildingClass *pThis)
static DWORD FoundationLength (CellStruct *StartCell)
static void Cleanup ()

Static Public Attributes

static Container< BuildingExtExtMap
static CellStruct * TempFoundationData1 = NULL
static CellStruct * TempFoundationData2 = NULL

Member Typedef Documentation

typedef BuildingClass BuildingExt::TT

Member Function Documentation

void BuildingExt::buildLines ( BuildingClass *  theBuilding,
CellStruct  selectedCell,
HouseClass *  buildingOwner 
) [static]
Parameters:
theBuildingthe building which we're trying to link to existing buildings.
selectedCellthe cell at which we're trying to build.
buildingOwnerthe owner of the building we're trying to link.
See also:
isLinkable()
canLinkTo()
Author:
DCoder, Renegade
Date:
26.12.09+
                                                                                                           {
        BuildingExt::ExtData* buildingExtData = BuildingExt::ExtMap.Find(theBuilding);
        //BuildingTypeExt::ExtData* buildingTypeExtData = BuildingTypeExt::ExtMap.Find(theBuilding->Type);

        // check if this building is linkable at all and abort if it isn't
        if(!buildingExtData->isLinkable()) {
                return;
        }

        short maxLinkDistance = theBuilding->Type->GuardRange / 256; // GuardRange governs how far the link can go, is saved in leptons

        for(int direction = 0; direction <= 7; direction += 2) { // the 4 straight directions of the simple compass
                CellStruct directionOffset = CellSpread::GetNeighbourOffset(direction); // coordinates of the neighboring cell in the given direction relative to the current cell (e.g. 0,1)
                int linkLength = 0; // how many cells to build on from center in direction to link up with a found building

                CellStruct cellToCheck = selectedCell;
                for(short distanceFromCenter = 1; distanceFromCenter <= maxLinkDistance; ++distanceFromCenter) {
                        cellToCheck += directionOffset; // adjust the cell to check based on current distance, relative to the selected cell

                        if(!MapClass::Instance->CellExists(&cellToCheck)) { // don't parse this cell if it doesn't exist (duh)
                                break;
                        }

                        CellClass *cell = MapClass::Instance->GetCellAt(&cellToCheck);

                        if(BuildingClass *OtherEnd = cell->GetBuilding()) { // if we find a building...
                                if(buildingExtData->canLinkTo(OtherEnd)) { // ...and it is linkable, we found what we needed
                                        linkLength = distanceFromCenter - 1; // distanceFromCenter directly would be on top of the found building
                                        break;
                                }

                                break; // we found a building, but it's not linkable
                        }

                        if(!cell->CanThisExistHere(theBuilding->Type->SpeedType, theBuilding->Type, buildingOwner)) { // abort if that buildingtype is not allowed to be built there
                                break;
                        }

                }

                // build a line of this buildingtype from the found building (if any) to the newly built one
                CellStruct cellToBuildOn = selectedCell;
                for(int distanceFromCenter = 1; distanceFromCenter <= linkLength; ++distanceFromCenter) {
                        cellToBuildOn += directionOffset;

                        if(CellClass *cell = MapClass::Instance->GetCellAt(&cellToBuildOn)) {
                                if(BuildingClass *tempBuilding = specific_cast<BuildingClass *>(theBuilding->Type->CreateObject(buildingOwner))) {
                                        CoordStruct coordBuffer;
                                        CellClass::Cell2Coord(&cellToBuildOn, &coordBuffer);

                                        ++Unsorted::IKnowWhatImDoing; // put the building there even if normal rules would deny - e.g. under units
                                        bool Put = tempBuilding->Put(&coordBuffer, 0);
                                        --Unsorted::IKnowWhatImDoing;

                                        if(Put) {
                                                tempBuilding->QueueMission(mission_Construction, false);
                                                tempBuilding->UpdateOwner(buildingOwner);
                                                tempBuilding->unknown_bool_6DD = 1;
                                        } else {
                                                GAME_DEALLOC(tempBuilding);
                                        }
                                }
                        }
                }
        }
}
void BuildingExt::Cleanup ( ) [static]
DWORD BuildingExt::FoundationLength ( CellStruct *  StartCell) [static]
                                                          {
        DWORD Len = 0;
        bool End = false;
        do {
                ++Len;
                End = StartCell->X == 32767 && StartCell->Y == 32767;
                ++StartCell;
        } while(!End);
        return Len;
}
DWORD BuildingExt::GetFirewallFlags ( BuildingClass *  pThis) [static]
                                                        {
        CellClass *MyCell = MapClass::Instance->GetCellAt(&pThis->Location);
        DWORD flags = 0;
        for(int direction = 0; direction < 8; direction += 2) {
                CellClass *Neighbour = MyCell->GetNeighbourCell(direction);
                if(BuildingClass *B = Neighbour->GetBuilding()) {
                        BuildingTypeExt::ExtData* pTypeData = BuildingTypeExt::ExtMap.Find(B->Type);
                        if(pTypeData->Firewall_Is && B->Owner == pThis->Owner && !B->InLimbo && B->IsAlive) {
                                flags |= 1 << (direction >> 1);
                        }
                }
        }
        return flags;
}
signed int BuildingExt::GetImageFrameIndex ( BuildingClass *  pThis) [static]
                                                               {
        BuildingTypeExt::ExtData *pData = BuildingTypeExt::ExtMap.Find(pThis->Type);

        if(pData->Firewall_Is) {
                return pThis->FirestormWallFrame;

                /* this is the code the game uses to calculate the firewall's frame number when you place/remove sections... should be a good base for trench frames

                        int frameIdx = 0;
                        CellClass *Cell = this->GetCell();
                        for(int direction = 0; direction <= 7; direction += 2) {
                                if(BuildingClass *B = Cell->GetNeighbourCell(direction)->GetBuilding()) {
                                        if(B->IsAlive && !B->InLimbo) {
                                                frameIdx |= (1 << (direction >> 1));
                                        }
                                }
                        }

                */
        }

        if(pData->IsTrench > -1) {
                return 0;
        }

        return -1;
}
void BuildingExt::KickOutHospitalArmory ( BuildingClass *  pThis) [static]
{
        if(pThis->Type->Hospital || pThis->Type->Armory) {
                if(FootClass * Passenger = pThis->Passengers.RemoveFirstPassenger()) {
                        pThis->KickOutUnit(Passenger, &BuildingClass::DefaultCellCoords);
                }
        }
}
void BuildingExt::UpdateDisplayTo ( BuildingClass *  pThis) [static]
                                                      {
        if(pThis->Type->Radar) {
                HouseClass *H = pThis->Owner;
                H->RadarVisibleTo.Clear();
                for(int i = 0; i < H->Buildings.Count; ++i) {
                        BuildingClass *currentB = H->Buildings.GetItem(i);
                        if(!currentB->InLimbo) {
                                if(BuildingTypeExt::ExtMap.Find(currentB->Type)->RevealRadar) {
                                        H->RadarVisibleTo.data |= currentB->DisplayProductionTo.data;
                                }
                        }
                }
                MapClass::Instance->RedrawSidebar(2);
        }
}

Member Data Documentation

CellStruct * BuildingExt::TempFoundationData1 = NULL [static]
CellStruct * BuildingExt::TempFoundationData2 = NULL [static]

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