1 // _____________________________________________________ 2 // 3 // RAI - Skirmish AI for Spring 4 // Author: Reth / Michael Vadovszki 5 // _____________________________________________________ 6 7 #ifndef RAI_BUILDER_H 8 #define RAI_BUILDER_H 9 10 struct sBuildQuarry; 11 class cBuilder; 12 13 #include "RAI.h" 14 #include "PowerManager.h" 15 #include <deque> 16 #include <list> 17 18 struct sBuildQuarry 19 { 20 sBuildQuarry(sRAIBuildList *buildlist); 21 ~sBuildQuarry(); 22 bool IsValid(int frame); 23 void SetRS(ResourceSiteExt *rs); 24 25 int builderID; // ID of the assigned builder, otherwise -1 26 UnitInfo *builderUI; // valid if 'builderID' is set 27 list<int> creationID; // ID of who is being built, I defined this as an array to work around a bug involving misordered calls of UnitDestroyed, UnitCreated - in other words at rare temporary moments this list will hold 2 unit ids. Spring-Version(v0.72b1-0.73b1) 28 int creationUDID; // ID of what is being built 29 sRAIUnitDef *creationUD;// always valid 30 ResourceSiteExt *RS; // The resource this must be built at 31 sRAIBuildList *BL; // used to update unitsActive 32 33 int index; // stores the index value of its own array 34 int type; // 1=Normal,2=Energy,3=Metal,4=Constructor,5=Energy Storage,6=Metal Storage,7=prerequisite 35 int deletionFrame; // If a unit does not choose to build the option by this frame, then delete the Build Quarry 36 int tryCount; // failed to build, probably due to enemy attacks 37 }; 38 39 #define BUILD_QUARRY_SIZE 40 40 41 class cBuilder 42 { 43 public: 44 cBuilder(IAICallback *callback, cRAI *global); 45 virtual ~cBuilder(); 46 47 void UnitCreated(const int& unit, UnitInfo *U); 48 void UnitFinished(const int& unit, UnitInfo *U); 49 void UnitDestroyed(const int& unit, UnitInfo *U); 50 void UnitAssignBuildList(const int& unit, UnitInfo *U, bool bInitialized=false); // bInitialized is unused, was ment to support a unit changing tasks 51 52 void UBuilderFinished(const int& unit, UnitInfo *U); 53 void UBuilderDestroyed(const int& unit, UnitInfo *U); 54 void UBuilderIdle(const int& unit, UnitInfo *U); 55 // void UBuilderDamaged(const int& unit,int attacker,float3 dir); 56 bool UBuilderMoveFailed(const int& unit, UnitInfo *U); // returns true if a solution was found 57 void HandleEvent(const IGlobalAI::PlayerCommandEvent *pce); 58 void UpdateUDRCost(); 59 void UpdateKnownFeatures(const int& unit, UnitInfo *U); 60 61 bool bInitiated; // initialized as false, set to true after set conditions have been meet, usually about 30-60 frames into the game 62 cPowerManager *PM; 63 cBuilderPlacement *BP; 64 65 map<int,UnitInfo*> UBuilder; // List of builders, key value = unit ID 66 map<int,UnitInfo*> UNanos; 67 set<int> Decomission; // Builders will reclaim these units in there free time 68 private: 69 cRAI *G; 70 cRAIUnitDefHandler *UDR;// G->UDH 71 cLogFile *l; // G->l 72 IAICallback *cb; // G->cb 73 74 void CreateBuildOrders() const; 75 int LastBuildOrder; 76 77 float MCostLimit; 78 float ECostLimit; 79 // float MCostUpdate; 80 // float ECostUpdate; 81 82 // Work-Around for bugs functions GetMetalUsage() & GetEnergyUsage() 83 // spring does not update the values by the time build idle is called, as a result the 84 // economy would think that the resources are more strained than they really are. 85 float BuilderEnergyDebug; // updated at the beginning of UBuilderIdle 86 float BuilderMetalDebug; // updated at the beginning of UBuilderIdle 87 int BuilderIDDebug; // ID of the last builder to finish a task 88 int BuilderFrameDebug; // the frame that 'BuilderIDDebug' was last changed 89 // double ConstructMetalUsage; 90 // double ConstructEnergyUsage; 91 92 int ConEnergyLost; 93 int ConMetalLost; 94 int ConEnergyDrain; // How much Energy will be drained when all constructions have started, positive value, does not include contructions that have already begun 95 int ConMetalDrain; // How much Metal will be drained when all constructions have started, positive value, does not include contructions that have already begun 96 int ConEnergyRate; // How much extra Energy will be produced when all constructions have completed 97 int ConMetalRate; // How much extra Metal will be produced when all constructions have completed 98 int ConEnergyStorage; // How much extra Energy Storage will there be when all constructions have completed 99 int ConMetalStorage; // How much extra Metal Storage will there be when all constructions have completed 100 bool MetalIsFavorable(float storage=0.50f,float production=1.0f); // returns true if there is no metal production or the ratio of both is met 101 bool EnergyIsFavorable(float storage=0.50f,float production=1.0f); // returns true if there is no energy production or the ratio of both is met 102 103 sBuildQuarry *BQ[BUILD_QUARRY_SIZE]; 104 sBuildQuarry *Prerequisite; // Limits RAI from building more than one at a time 105 int BQSize[8]; // index 0 = total, other indexs accessed by iType. Value of index is equal to counter 106 void BQAssignBuilder(int index, const int& unit, UnitInfo* U); 107 // void BQAssignConstruct(int index, const int& unit, sRAIUnitDef *udr); 108 void BQAdd(sRAIUnitDef *udr, sRAIBuildList *BL, int type); 109 void BQRemove(int index); 110 111 struct UnitConstructionInfo 112 { UnitConstructionInfoUnitConstructionInfo113 UnitConstructionInfo(sBuildQuarry *BuildQuarry, const int& unit, UnitInfo* UI) 114 { 115 U=UI; 116 unitID = unit; 117 BQ = BuildQuarry; 118 BQ->creationID.push_front(unit); 119 BQAbandoned=false; 120 }; ~UnitConstructionInfoUnitConstructionInfo121 ~UnitConstructionInfo() 122 { 123 }; 124 125 bool BQAbandoned; 126 sBuildQuarry *BQ; // valid if BQAbandoned=false 127 UnitInfo *U; // Always valid 128 int unitID; 129 }; 130 map<int,UnitConstructionInfo> UConstruction; // List of what is being built, key value = unit ID 131 132 // due to crash bugs in spring 0.74b3, the position is about the only safe information that could be gathered and stored. 133 typedef pair<int,float3> ifPair; 134 map<int,float3> FeatureDebris; // List of features that are blocking the paths of our units 135 typedef pair<int,FeatureDef*> ifdPair; 136 map<int,float3> MetalDebris; // List of metal reclaimables found 137 map<int,float3> EnergyDebris; // List of energy reclaimables found 138 map<int,float3> ResDebris; // List of resurrectables found 139 typedef pair<string,sRAIUnitDef*> srPair; 140 map<string,sRAIUnitDef*> UDRResurrect; // List of what can be resurrected 141 }; 142 143 #endif 144