113 removals
392 additions
1./////////////////////////////////////////////////////////////////////1./////////////////////////////////////////////////////////////////////
2.// general ai for skirmish game2.// general ai for skirmish game
3./////////////////////////////////////////////////////////////////////3./////////////////////////////////////////////////////////////////////
4.// Warzone2100, Pumpkin Studios,4.// Warzone2100, Pumpkin Studios,
5.// alex lee.98/99.5.// alex lee.98/99.
6.//6.//
7./////////////////////////////////////////////////////////////////////7./////////////////////////////////////////////////////////////////////
8.8.
9.//Tile in world units9.//Tile in world units
10.#define TILE 12810.#define TILE 128
11.#define NONE (-1)11.#define NONE (-1)
12.12.
13.// These are final rules of the lexical parser13.// These are final rules of the lexical parser
14.#define R_REQUEST_HELP "help me"14.#define R_REQUEST_HELP "help me"
15.#define R_REQUEST_BEACON "drop a beacon"15.#define R_REQUEST_BEACON "drop a beacon"
16.#define R_REPORT_SAFETY "i'm ok"16.#define R_REPORT_SAFETY "i'm ok"
17.#define R_REQUEST_ALLY "ally me"17.#define R_REQUEST_ALLY "ally me"
18.18.
19.// These are our own messages - lexical parser should be able to handle them19.// These are our own messages - lexical parser should be able to handle them
20.#define M_REQUEST_HELP "help me!!"20.#define M_REQUEST_HELP "help me!!"
21.#define M_REQUEST_BEACON "drop a beacon"21.#define M_REQUEST_BEACON "drop a beacon"
22.#define M_AFFIRMATIVE_OK "ok"22.#define M_AFFIRMATIVE_OK "ok"
23.#define M_AFFIRMATIVE_ROGER "roger"23.#define M_AFFIRMATIVE_ROGER "roger"
24.#define M_ANNOYED "bug off"24.#define M_ANNOYED "bug off"
25.#define M_HELPERS_KILLED "that was all I had.."25.#define M_HELPERS_KILLED "that was all I had.."
26.#define M_HELP_NO_UNITS "I don't have anything"26.#define M_HELP_NO_UNITS "I don't have anything"
27.27.
28.#define MAX_PROBABILITY 10028.#define MAX_PROBABILITY 100
29.29.
30.// Base threat range in world units30.// Base threat range in world units
31.#define W_BASE_THREAT_RANGE ((17 + (mapWidth + mapHeight) / 2 / 35) * TILE)31.#define W_BASE_THREAT_RANGE ((17 + (mapWidth + mapHeight) / 2 / 35) * TILE)
32.#define ALL_ALLIES -132.#define ALL_ALLIES -1
33.33.
34.#define BASE_DEFEND_DURATION (3 * 60)34.#define BASE_DEFEND_DURATION (3 * 60)
35.35.
36.// Delay before we repeat our request, in seconds36.// Delay before we repeat our request, in seconds
37.#define HELP_REQUEST_INTERVAL (3 * 60)37.#define HELP_REQUEST_INTERVAL (3 * 60)
38.38.
39.//in secs39.//in secs
40.#define BEACON_TIMEOUT 3040.#define BEACON_TIMEOUT 30
41.41.
42.#define MAX_DROIDS 15042.#define MAX_DROIDS 150
43.43.
44.//range for trucks to look for more oil44.//range for trucks to look for more oil
45.#define MORE_OIL_RANGE (10 * TILE)45.#define MORE_OIL_RANGE (10 * TILE)
46.//don't try to build on oil if there's threat within this range46.//don't try to build on oil if there's threat within this range
47.#define OIL_THREAT_RANGE (9 * TILE)47.#define OIL_THREAT_RANGE (9 * TILE)
48.48.
49.#define MAX_TRUCKS 1249.#define MAX_TRUCKS 15
50.#define MIN_TRUCKS 550.#define MIN_TRUCKS 12
51.51.
52.//Enter power saving mode when lower than this52.//Enter power saving mode when lower than this
53.#define LOW_POWER 25053.#define LOW_POWER 250
54.54.
55.//Target type values55.//Target type values
56.#define NO_TARGET_VALUE 056.#define NO_TARGET_VALUE 0
57.#define DROID_TARGET_VALUE 157.#define DROID_TARGET_VALUE 1
58.#define OTHER_TARGET_VALUE 258.#define OTHER_TARGET_VALUE 2
59.#define DEFENSE_TARGET_VALUE 359.#define DEFENSE_TARGET_VALUE 3
60.#define RESEARCH_TARGET_VALUE 460.#define RESEARCH_TARGET_VALUE 4
61.#define HQ_TARGET_VALUE 561.#define HQ_TARGET_VALUE 5
62.#define OIL_TARGET_VALUE 662.#define OIL_TARGET_VALUE 6
63.#define FACTORY_TARGET_VALUE 763.#define FACTORY_TARGET_VALUE 7
64.64.
65.#define UNLIMITED (-1)65.#define UNLIMITED (-1)
66.66.
67.#define AA_THREAT_RANGE (TILE * 12)67.#define AA_THREAT_RANGE (TILE * 12)
68.68.
69.#define MAX_DEFENDERS_RADIUS (TILE * 40)69.#define MAX_DEFENDERS_RADIUS (TILE * 40)
70.70.
71.#define MAX_VTOL_DEFEND_RADIUS (TILE * 25)71.#define MAX_VTOL_DEFEND_RADIUS (TILE * 25)
72.72.
73.// AI will remember max this number of structures73.// AI will remember max this number of structures
74.#define MAX_REBUILD_STRUCT 10074.#define MAX_REBUILD_STRUCT 100
75.75.
76.//Total number of technology branches76.//Total number of technology branches
77.#define TECHS 277.#define TECHS 2
78.78.
79.//How many best templates to choose from when deciding what template to build79.//How many best templates to choose from when deciding what template to build
80.#define MAX_RANDOM_TEMPLATES 480.#define MAX_RANDOM_TEMPLATES 6
81.81.
82.82.
83.83.
84.private int me; // player for this instance.84.private int me; // player for this instance.
85.public int tileExpand; // rate of exploration85.public int tileExpand; // rate of exploration
86.86.
87.public int numScouts[TECHS],maxScouts[TECHS]; // aim for...87.public int numScouts[TECHS],maxScouts[TECHS]; // aim for...
88.public int numDefenders[TECHS],maxDefenders[TECHS];88.public int numDefenders[TECHS],maxDefenders[TECHS];
89.public int numAttackers[TECHS],maxAttackers[TECHS];89.public int numAttackers[TECHS],maxAttackers[TECHS];
90.public int numCyborgs[TECHS],maxCyborgs[TECHS];90.public int numCyborgs[TECHS],maxCyborgs[TECHS];
91.91.
92.public int branchDefault,branchVTOL,techCount[TECHS],maxVtolFacs[TECHS],maxIdleRes[TECHS],92.public int branchDefault,branchVTOL,techCount[TECHS],maxVtolFacs[TECHS],maxIdleRes[TECHS],
93. maxVTOLs[TECHS],numVtolTargets,vtolTargetWeight[10],numRebuildStat[TECHS];93. maxVTOLs[TECHS],numVtolTargets,vtolTargetWeight[10],numRebuildStat[TECHS];
94.public RESEARCHSTAT tech[TECHS][30]; //technology for different research branches94.public RESEARCHSTAT tech[TECHS][30]; //technology for different research branches
95.public STRUCTURESTAT vtolTarget[10],rebuildStat[TECHS][2];95.public STRUCTURESTAT vtolTarget[10],rebuildStat[TECHS][2];
96.96.
97.// structures97.// structures
98.private int baseX,baseY,minx,miny,maxx,maxy;98.private int baseX,baseY,minx,miny,maxx,maxy;
99.public int numStructs,numIncendrys,numDefStructs,numExtraStructs[TECHS],numWallWeaps,numBaseStruct,numLightCyborgs,numFundamental;99.public int numStructs,numIncendrys,numDefStructs,numExtraStructs[TECHS],numWallWeaps,numBaseStruct,numLightCyborgs,numFundamental;
100.private STRUCTURESTAT structChoice[5];100.private STRUCTURESTAT structChoice[5];
101.public STRUCTURESTAT incendrys[8],structs[13],defStructs[26],extraStructs[TECHS][6],wallWeaps[11];101.public STRUCTURESTAT incendrys[10],structs[13],defStructs[26],extraStructs[TECHS][6],wallWeaps[11];
102.public STRUCTURESTAT sensorTower,wall,cornerWall,resLab,powGen,playerHQ,lassat,factory,derrick,cybFactory,102.public STRUCTURESTAT sensorTower,wall,cornerWall,resLab,powGen,playerHQ,lassat,factory,derrick,cybFactory,
103. vtolDefStruct[5],vtolPad,vtolFactory,uplink,baseStruct[8];103. vtolDefStruct[9],vtolPad,vtolFactory,uplink,baseStruct[8];
104.public STRUCTURESTAT powModule,facModule,resModule,vtolModule;104.public STRUCTURESTAT powModule,facModule,resModule,vtolModule;
105.public int extraStruct;105.public int extraStruct;
106.106.
107.// unit templates107.// unit templates
108.public int numTemplates[TECHS];108.public int numTemplates[TECHS];
109.public TEMPLATE tmpl[TECHS][70];109.public TEMPLATE tmpl[TECHS][70];
110.private TEMPLATE tmplChoice[5];110.private TEMPLATE tmplChoice[67];
111.111.
112.public TEMPLATE cybTempl[10],superCyb[4],cybMechanic,cybEngineer,hovertruck;112.public TEMPLATE cybTempl[7],superCyb[21],cybMechanic,cybEngineer,hovertruck;
113.113.
114.public TEMPLATE vtols[18];114.public TEMPLATE vtols[20];
115.public int numVtolTemplates;115.public int numVtolTemplates;
116.116.
117.public TEMPLATE sense[11];117.public TEMPLATE sense[8];
118.public int numSenseTemplates;118.public int numSenseTemplates;
119.119.
120.public TEMPLATE constructor,repair;120.public TEMPLATE constructor,repair[7];
121.public int numRepairUnits;121.public int numRepairUnits;
122.public int numSensorUnits;
123.public int numRepairTemplates;
122.124.
123.//defend125.//defend
124.private GROUP defendGroup;126.private GROUP defendGroup;
125.private bool defendbusy;127.private bool defendbusy;
126.private BASEOBJ defendObj;128.private BASEOBJ defendObj;
127.129.
128.public RESEARCHSTAT nexusDefence;130.public RESEARCHSTAT nexusDefence;
129.private RESEARCHSTAT research;131.private RESEARCHSTAT research;
130.132.
131.//build133.//build
132.private GROUP buildGroup;134.private GROUP buildGroup;
133.private int buildX,buildY,buildX2,buildY2;135.private int buildX,buildY,buildX2,buildY2;
134.public FEATURESTAT oilRes;136.public FEATURESTAT oilRes;
135.137.
136.// scout138.// scout
137.private GROUP scoutGroup;139.private GROUP scoutGroup;
138.private int scoutX,scoutY;140.private int scoutX,scoutY;
139.private int scoutTLX,scoutTLY,scoutW,scoutH;141.private int scoutTLX,scoutTLY,scoutW,scoutH;
140.142.
141.// attack143.// attack
142.private GROUP attackGroup;144.private GROUP attackGroup;
143.private BASEOBJ attackObj,allOutAttack,vtolGrAttackObj[10];145.private BASEOBJ attackObj,allOutAttack,vtolGrAttackObj[39];
144.146.
145.// vtols147.// vtols
146.private GROUP vtolDefendGr,vtolAttackGr[10];148.private GROUP vtolDefendGr,vtolAttackGr[10];
147.149.
148.// generic150.// generic
149.private STRUCTURE structure,structure2,rebuildObj[100];151.private STRUCTURE structure,structure2,rebuildObj[100];
150.private DROID droid;152.private DROID droid;
151.private FEATURE feature;153.private FEATURE feature;
152.private BASEOBJ baseobj,baseobj2;154.private BASEOBJ baseobj,baseobj2;
153.private int count,count2,result,result2,tempx,tempy;155.private int count,count2,result,result2,tempx,tempy;
154.private bool boolResult,boolResult2;156.private bool boolResult,boolResult2;
155.157.
156.private bool powerSave,_DEBUG,bRunning;158.private bool powerSave,_DEBUG,bRunning;
157.// Hopefully this will be at least as large as MAX_PLAYERS... Why can't I just use MAX_PLAYERS as the array size?!159.// Hopefully this will be at least as large as MAX_PLAYERS... Why can't I just use MAX_PLAYERS as the array size?!
158.// P.S. And why can't I put a comment on the same line as a #define??!! Gah, who cares if the lua2 branch works, lets switch to it, anyway.160.// P.S. And why can't I put a comment on the same line as a #define??!! Gah, who cares if the lua2 branch works, lets switch to it, anyway.
159.#define MAX_PLAYERS_HACK 17161.#define MAX_PLAYERS_HACK 17
160.private int allianceTime[MAX_PLAYERS_HACK];162.private int allianceTime[MAX_PLAYERS_HACK];
161.private int sender,x,y,beaconX[8],beaconY[8],tBeacon[8],163.private int sender,x,y,beaconX[8],beaconY[8],tBeacon[8],
162. tLastHelpRequest,lastHelpPlayer,tHelp,tHelpTimeout,helpX,helpY;164. tLastHelpRequest,lastHelpPlayer,tHelp,tHelpTimeout,helpX,helpY;
163.private string message;165.private string message;
164.166.
165.private int defendX,defendY,__defendRadiusUnused,tDefendStart,tDefendTimeout,167.private int defendX,defendY,__defendRadiusUnused,tDefendStart,tDefendTimeout,
166. defendMoveType,baseRange,curTech,numVtolAttackGroups,numAttackVtols,168. defendMoveType,baseRange,curTech,numVtolAttackGroups,numAttackVtols,
167. numDefendVtols,rebuildStructX[MAX_REBUILD_STRUCT],rebuildStructY[MAX_REBUILD_STRUCT],countRebuildStruct;169. numDefendVtols,rebuildStructX[MAX_REBUILD_STRUCT],rebuildStructY[MAX_REBUILD_STRUCT],countRebuildStruct;
168.private STRUCTURESTAT rebuildStructStat[MAX_REBUILD_STRUCT];170.private STRUCTURESTAT rebuildStructStat[MAX_REBUILD_STRUCT];
169.171.
170.private STRUCTURESTAT fundamentalBeingBuilt;172.private STRUCTURESTAT fundamentalBeingBuilt;
171.private int order; // callback global173.private int order; // callback global
172.174.
173./////////////////////////////////////////////////////////////////////175./////////////////////////////////////////////////////////////////////
174.// triggers.176.// triggers.
175.177.
176.#region triggers178.#region triggers
177.trigger reachedTr (CALL_DROID_REACH_LOCATION, me, ref droid, ref order);179.trigger reachedTr (CALL_DROID_REACH_LOCATION, me, ref droid, ref order);
178.trigger buildExpandTr (every, 600);180.trigger buildExpandTr (every, 300);
179.trigger fortifyTr (every, 1000);181.trigger fortifyTr (every, 400);
180.trigger upgradeStructuresTr (every, 360);182.trigger upgradeStructuresTr (every, 50);
181.trigger conDroidsTr (every, 900); // was 1400183.trigger conDroidsTr (every, 200); // was 1400
182.trigger repairDroidsTr (every, 2600);184.trigger repairDroidsTr (every, 400);
185.trigger sensorDroidsTr (every, 400);
183.trigger basedetailsTr (every, 600 );186.trigger basedetailsTr (every, 600 );
184.trigger buildDerrickTr (every, 80 );187.trigger buildDerrickTr (every, 80 );
185.trigger buildOilDefenseOrRetreatTr (every, 120 );188.trigger buildOilDefenseOrRetreatTr (every, 200 );
186.trigger incendryTr (every, 250 );189.trigger incendryTr (every, 120 );
187.trigger buildPowerGeneratorsTr (every, 80 );190.trigger buildPowerGeneratorsTr (every, 80 );
188.trigger buildBaseTr (every, 150 );191.trigger buildBaseTr (every, 150 );
189.trigger finishStructsTr (every, 210);192.trigger finishStructsTr (every, 210);
190.trigger droidBuiltTr (CALL_NEWDROID,me, ref droid,ref structure);193.trigger droidBuiltTr (CALL_NEWDROID,me, ref droid,ref structure);
191.trigger structBuiltTr (CALL_STRUCTBUILT, me, ref droid, ref structure);194.trigger structBuiltTr (CALL_STRUCTBUILT, me, ref droid, ref structure);
192.trigger droidDestroyedTr (CALL_DROID_DESTROYED, me, ref droid);195.trigger droidDestroyedTr (CALL_DROID_DESTROYED, me, ref droid);
193.trigger structureDestroyedTr (CALL_STRUCT_DESTROYED, me, ref structure);196.trigger structureDestroyedTr (CALL_STRUCT_DESTROYED, me, ref structure);
194.trigger rebuildStructureTr (every, 50);197.trigger rebuildStructureTr (every, 50);
195.trigger consolidateEventTr (every, 3100);198.trigger consolidateEventTr (every, 3100);
196.trigger factoryEventTr (every, 170 );199.trigger factoryEventTr (every, 90 );
197.trigger cyborgFactoryEventTr (every, 170 );200.trigger cyborgFactoryEventTr (every, 90 );
198.trigger chooseScoutAreaTr (every, 200 );201.trigger chooseScoutAreaTr (every, 200 );
199.trigger expandScoutAreaTr (every, 600 );202.trigger expandScoutAreaTr (every, 600 );
200.trigger scoutMainTr (every, 150 );203.trigger scoutMainTr (every, 150 );
201.trigger newObjectReportTr (CALL_OBJ_SEEN, me, ref baseobj, ref baseobj2);204.trigger newObjectReportTr (CALL_OBJ_SEEN, me, ref baseobj, ref baseobj2);
202.trigger attackStuffTr (every, 300 );205.trigger attackStuffTr (every, 200 );
203.trigger allOutAttackTr (every, 4000);206.trigger allOutAttackTr (every, 2000);
204.trigger defendWatchTr (CALL_STRUCT_ATTACKED, me, ref structure, ref baseobj);207.trigger defendWatchTr (CALL_STRUCT_ATTACKED, me, ref structure, ref baseobj);
205.trigger defendReturnTr (every, 500 );208.trigger defendReturnTr (every, 100000 );
206.trigger doResearchTr (CALL_RESEARCHCOMPLETED, ref research, ref structure, me);209.trigger doResearchTr (CALL_RESEARCHCOMPLETED, ref research, ref structure, me);
207.trigger vtolDefendTr (CALL_STRUCT_ATTACKED, me, ref structure, ref baseobj);210.trigger vtolDefendTr (CALL_STRUCT_ATTACKED, me, ref structure, ref baseobj);
208.trigger vtolStructsTr (every, 290);211.trigger vtolStructsTr (every, 600);
209.trigger buildVtolsTr (every, 360);212.trigger buildVtolsTr (every, 180);
210.trigger vtolAttackTr (every, 150);213.trigger vtolAttackTr (every, 10);
211.trigger vtolEnablerTr (every, 700);214.trigger vtolEnablerTr (every, 700);
212.trigger takeoverTr (CALL_UNITTAKEOVER, ref droid);215.trigger takeoverTr (CALL_UNITTAKEOVER, ref droid);
213.trigger useLassatTr (every, 3000);216.trigger useLassatTr (every, 3000);
214.trigger reassignTr (CALL_PLAYERLEFT,ref count);217.trigger reassignTr (CALL_PLAYERLEFT,ref count);
215.trigger formAllianceEventTr (every,170);218.trigger formAllianceEventTr (every,170);
216.trigger breakAllianceEventTr (every,3000);219.trigger breakAllianceEventTr (every,3000);
217.trigger difficultyModifierTr (every,600);220.trigger difficultyModifierTr (every,600);
218.trigger humanAllianceTr (CALL_ALLIANCEOFFER,ref count, ref count2);221.trigger humanAllianceTr (CALL_ALLIANCEOFFER,ref count, ref count2);
219.trigger multiMsgTr (CALL_AI_MSG, me, ref sender, ref message);222.trigger multiMsgTr (CALL_AI_MSG, me, ref sender, ref message);
220.trigger beaconTr (CALL_BEACON, me, ref sender, ref x, ref y, ref message);223.trigger beaconTr (CALL_BEACON, me, ref sender, ref x, ref y, ref message);
221.trigger consoleTr (CALL_CONSOLE, ref sender, ref message);224.trigger consoleTr (CALL_CONSOLE, ref sender, ref message);
222.trigger watchBaseThreatTr (every, 120);225.trigger watchBaseThreatTr (every, 120);
223.trigger manageAllyHelpTr (every, 80);226.trigger manageAllyHelpTr (every, 80);
224.trigger everySec (every, 10);227.trigger everySec (every, 10);
225.trigger manageDefendLocationTr (every, 70);228.trigger manageDefendLocationTr (every, 70);
226.trigger startLevelTr (CALL_START_NEXT_LEVEL);229.trigger startLevelTr (CALL_START_NEXT_LEVEL);
227.trigger chainloadTr (wait, 1);230.trigger chainloadTr (wait, 1);
228.trigger slowloadTr (wait, 13);231.trigger slowloadTr (wait, 13);
229.trigger checkResearchTr (every, 400);232.trigger checkResearchTr (every, 50);
230.233.
231./* Events */234./* Events */
232.event conDroids;235.event conDroids;
233.event multiMsgEv;236.event multiMsgEv;
234.event beaconEv;237.event beaconEv;
235.event watchBaseThreat;238.event watchBaseThreat;
236.event manageAllyHelp;239.event manageAllyHelp;
237.event everySecEv;240.event everySecEv;
238.event manageDefendLocationEv;241.event manageDefendLocationEv;
239.event structureDestroyed;242.event structureDestroyed;
240.event rebuildStructureEv;243.event rebuildStructureEv;
241.event doResearch;244.event doResearch;
242.event buildDerrick;245.event buildDerrick;
243.246.
244./* Function prototypes */247./* Function prototypes */
245.function bool haveBeacon(int _player);248.function bool haveBeacon(int _player);
246.function bool beaconTimeout(int _player);249.function bool beaconTimeout(int _player);
247.function void processCommand(string _message, int _sender, bool _bBlipMessage);250.function void processCommand(string _message, int _sender, bool _bBlipMessage);
248.function bool haveHelpers();251.function bool haveHelpers();
249.function bool attemptToHelp(int _playerToHelp, int _x, int _y);252.function bool attemptToHelp(int _playerToHelp, int _x, int _y);
250.function void helpPlayer(int _playerToHelp, int _helpX, int _helpY);253.function void helpPlayer(int _playerToHelp, int _helpX, int _helpY);
251.function bool canStopHelpingAlly();254.function bool canStopHelpingAlly();
252.function void stopHelpingAlly();255.function void stopHelpingAlly();
253.function bool helpingAlly();256.function bool helpingAlly();
254.function bool helpAllyTimeout();257.function bool helpAllyTimeout();
255.function void requestHelp(int _helpX, int _helpY);258.function void requestHelp(int _helpX, int _helpY);
256.function void doRequestHelp(int _helpX, int _helpY);259.function void doRequestHelp(int _helpX, int _helpY);
257.function bool allyBaseAtLoc(int _ally, int _x, int _y);260.function bool allyBaseAtLoc(int _ally, int _x, int _y);
258.function void messagePlayer(int _playerToMessage, string _message, int _probability);261.function void messagePlayer(int _playerToMessage, string _message, int _probability);
259.function void messagePlayerAddressed(int _playerToMessage, int _playersToAddress, string _message);262.function void messagePlayerAddressed(int _playerToMessage, int _playersToAddress, string _message);
260.function bool canSeeAllies();263.function bool canSeeAllies();
261.function bool baseInTrouble();264.function bool baseInTrouble();
262.function string m_affirmative();265.function string m_affirmative();
263.function void defendLocation(int _defendX, int _defendY, int _tDefendTimeout, bool _bMove);266.function void defendLocation(int _defendX, int _defendY, int _tDefendTimeout, bool _bMove);
264.function void stopDefendingLocation();267.function void stopDefendingLocation();
265.function bool defendingLocation();268.function bool defendingLocation();
266.function bool defendLocationTimeout();269.function bool defendLocationTimeout();
267.function bool friendlyPlayer(int _playerToCheck);270.function bool friendlyPlayer(int _playerToCheck);
268.function void factoryBuildDroid(STRUCTURE _factory);271.function void factoryBuildDroid(STRUCTURE _factory);
269.function void cybFactorBuildCyborg(STRUCTURE _factory);272.function void cybFactorBuildCyborg(STRUCTURE _factory);
270.function void vtolFactoryBuildVtol(STRUCTURE _factory);273.function void vtolFactoryBuildVtol(STRUCTURE _factory);
271.function bool insideBase(int _x, int _y);274.function bool insideBase(int _x, int _y);
272.function int numAlliesInBase(bool _bVtols);275.function int numAlliesInBase(bool _bVtols);
273.function int numEnemiesInBase(bool _bVtols);276.function int numEnemiesInBase(bool _bVtols);
274.function bool defendingOwnBase();277.function bool defendingOwnBase();
275.function int targetTypeValue(BASEOBJ _target);278.function int targetTypeValue(BASEOBJ _target);
276.function int numBitsSet(int _integer);279.function int numBitsSet(int _integer);
277.function int findResearch(int _searchStart, int _techTree);280.function int findResearch(int _searchStart, int _techTree);
278.function bool upgradeFactory(DROID _truck, int _maxBuilders);281.function bool upgradeFactory(DROID _truck, int _maxBuilders);
279.function bool upgradeVtolFactory(DROID _truck, int _maxBuilders);282.function bool upgradeVtolFactory(DROID _truck, int _maxBuilders);
280.function bool upgradeResearch(DROID _truck, int _maxBuilders);283.function bool upgradeResearch(DROID _truck, int _maxBuilders);
281.function bool upgradePowGen(DROID _truck, int _maxBuilders);284.function bool upgradePowGen(DROID _truck, int _maxBuilders);
282.function void buildRearmPads();285.function void buildRearmPads();
283.function int numEnemyAAInRange(int _x, int _y, int _range);286.function int numEnemyAAInRange(int _x, int _y, int _range);
284.function BASEOBJ chooseVtolTarget(bool bExclusiveTarget);287.function BASEOBJ chooseVtolTarget(bool bExclusiveTarget);
285.function int getVtolTargetWeight(BASEOBJ _target);288.function int getVtolTargetWeight(BASEOBJ _target);
286.function bool vtolTargetAssigned(BASEOBJ _target);289.function bool vtolTargetAssigned(BASEOBJ _target);
287.function int numBuildSameBuilding(STRUCTURESTAT _checkStat, int _x, int _y);290.function int numBuildSameBuilding(STRUCTURESTAT _checkStat, int _x, int _y);
288.function int totalVtols();291.function int totalVtols();
289.function bool needTank();292.function bool needTank();
290.function void setTechBranch(int _tech);293.function void setTechBranch(int _tech);
291.function DROID closestIdleTruck(int _x, int _y);294.function DROID closestIdleTruck(int _x, int _y);
292.function void buildOnExactLocation(DROID _truck, int _x, int _y, STRUCTURESTAT _stat);295.function void buildOnExactLocation(DROID _truck, int _x, int _y, STRUCTURESTAT _stat);
293.function void rebuildStructures();296.function void rebuildStructures();
294.function BASEOBJ chooseVtolDefenceTarget(int _x, int _y, int _range, bool bExclusiveTarget);297.function BASEOBJ chooseVtolDefenceTarget(int _x, int _y, int _range, bool bExclusiveTarget);
295.function int numGroupSameOrder(GROUP _group, int _orderIndex);298.function int numGroupSameOrder(GROUP _group, int _orderIndex);
296.function void rearrangeAttackVtols();299.function void rearrangeAttackVtols();
297.function int numStructBusyByType(STRUCTURESTAT _busyStructType);300.function int numStructBusyByType(STRUCTURESTAT _busyStructType);
298.function bool aiResponsibleForPlayer(int _player);301.function bool aiResponsibleForPlayer(int _player);
299.function void reassignAI();302.function void reassignAI();
300.function void shutDownAI();303.function void shutDownAI();
301.function bool buildUnit(TEMPLATE _tankTemplate, STRUCTURE _factory, STRUCTURESTAT _factoryType, bool _bIdleOnly);304.function bool buildUnit(TEMPLATE _tankTemplate, STRUCTURE _factory, STRUCTURESTAT _factoryType, bool _bIdleOnly);
302.function STRUCTURE findIdleStructure(STRUCTURESTAT _structType, bool _bIdleOnly);305.function STRUCTURE findIdleStructure(STRUCTURESTAT _structType, bool _bIdleOnly);
303.#endregion triggers306.#endregion triggers
304.307.
305./////////////////////////////////////////////////////////////////////308./////////////////////////////////////////////////////////////////////
306.// HouseKeeping309.// HouseKeeping
307.event initialisedEvent(CALL_GAMEINIT)310.event initialisedEvent(CALL_GAMEINIT)
308.{311.{
309. local int player;312. local int player;
310. // initialise313. // initialise
311. me = getPlayer("Nexus");314. me = getPlayer("Nexus");
312. _DEBUG = FALSE;315. _DEBUG = FALSE;
313. dbgMsgOn(me, _DEBUG);316. dbgMsgOn(me, _DEBUG);
314.317.
315. extraStruct = 0;318. extraStruct = 0;
316. numRepairUnits = 0;319. numRepairUnits = 0;
320. numSensorUnits = 0;
317. allOutAttack = NULLOBJECT;321. allOutAttack = NULLOBJECT;
318.322.
319. tLastHelpRequest = -1; //when we requested help for the last time323. tLastHelpRequest = -1; //when we requested help for the last time
320. lastHelpPlayer = -1; //we are not currently helping anyone324. lastHelpPlayer = -1; //we are not currently helping anyone
321. tHelp = -1; //when we started helping last time325. tHelp = -1; //when we started helping last time
322. tHelpTimeout = -1; //time when help times out326. tHelpTimeout = -1; //time when help times out
323. helpX = -1;327. helpX = -1;
324. helpY = -1;328. helpY = -1;
325. defendX = -1;329. defendX = -1;
326. defendY = -1;330. defendY = -1;
327. tDefendStart = -1;331. tDefendStart = -1;
328. tDefendTimeout = -1;332. tDefendTimeout = -1;
329. defendMoveType = -1; //move or scout333. defendMoveType = -1; //move or scout
330.334.
331. baseRange = 4 * TILE;335. baseRange = 4 * TILE;
332.336.
333. // set current research branch337. // set current research branch
334. setTechBranch(-1);338. setTechBranch(-1);
335.339.
336. numVtolAttackGroups = 10;340. numVtolAttackGroups = 10;
337. numAttackVtols = 10; //num vtols in an attack group341. numAttackVtols = 10; //num vtols in an attack group
338. numDefendVtols = 5; //num vtols in an attack group342. numDefendVtols = 5; //num vtols in an attack group
339.343.
340. // setup build group - all initial droids are in buildgroup!344. // setup build group - all initial droids are in buildgroup!
341. groupAddArea(buildGroup, me, 0, 0, (mapWidth*128), (mapHeight*128));345. groupAddArea(buildGroup, me, 0, 0, (mapWidth*128), (mapHeight*128));
342.346.
343. // note where our base is.347. // note where our base is.
344. getPlayerStartPosition(me, ref baseX, ref baseY);348. getPlayerStartPosition(me, ref baseX, ref baseY);
345.349.
346. // defence.350. // defence.
347. defendbusy = FALSE;351. defendbusy = FALSE;
348.352.
349. // setup scouts353. // setup scouts
350. structure = getStructure(factory, me);354. structure = getStructure(factory, me);
351. if(structure != NULLOBJECT)355. if(structure != NULLOBJECT)
352. {356. {
353. scoutTLX = structure.x;357. scoutTLX = structure.x;
354. scoutTLY = structure.y;358. scoutTLY = structure.y;
355. }359. }
356. else360. else
357. {361. {
358. scoutTLX = baseX;362. scoutTLX = baseX;
359. scoutTLY = baseY;363. scoutTLY = baseY;
360. }364. }
361. scoutW = 256;365. scoutW = 256;
362. scoutH = 256;366. scoutH = 256;
363. scoutX = scoutTLX;367. scoutX = scoutTLX;
364. scoutY = scoutTLY;368. scoutY = scoutTLY;
365.369.
366. // clear the alliance array...370. // clear the alliance array...
367. player = 0;371. player = 0;
368. while (player != MAX_PLAYERS)372. while (player != MAX_PLAYERS)
369. {373. {
370. allianceTime[player] = 0;374. allianceTime[player] = 0;
371. player = player + 1;375. player = player + 1;
372. }376. }
373.377.
374. fundamentalBeingBuilt = derrick; // to avoid ever being null378. fundamentalBeingBuilt = derrick; // to avoid ever being null
375. 379.
376. if(aiResponsibleForPlayer(me))380. if(aiResponsibleForPlayer(me))
377. {381. {
378. bRunning = true;382. bRunning = true;
379. }383. }
380. else384. else
381. {385. {
382. bRunning = false;386. bRunning = false;
383. shutDownAI();387. shutDownAI();
384. }388. }
385.}389.}
386.390.
387.// check whether we have at least one structure of that type391.// check whether we have at least one structure of that type
388.function bool haveStructure(STRUCTURESTAT type) 392.function bool haveStructure(STRUCTURESTAT type)
389.{393.{
390. return getStructure(type, me) != NULLOBJECT;394. return getStructure(type, me) != NULLOBJECT;
391.}395.}
392.396.
393.// check if we are getting any income397.// check if we are getting any income
394.function bool havePowerSource()398.function bool havePowerSource()
395.{399.{
396. // we don't check buildings being finished here400. // we don't check buildings being finished here
397. return haveStructure(powGen) and haveStructure(derrick);401. return haveStructure(powGen) and haveStructure(derrick);
398.}402.}
399.403.
400.// I am not sure why we need this hack, but the AI can still end up not researching anything at times404.// I am not sure why we need this hack, but the AI can still end up not researching anything at times
401.event checkResearch(checkResearchTr)405.event checkResearch(checkResearchTr)
402.{406.{
403. setEventTrigger(doResearch, chainloadTr);407. setEventTrigger(doResearch, chainloadTr);
404.}408.}
405.409.
406.function void dbgPlr(string message)410.function void dbgPlr(string message)
407.{411.{
408. setEventTrigger(doResearch, chainloadTr);412. setEventTrigger(doResearch, chainloadTr);
409. if (me == selectedPlayer)413. if (me == selectedPlayer)
410. {414. {
411. console(message);415. console(message);
412. }416. }
413.}417.}
414.418.
415.function void dbgObj(DROID obj, string message)419.function void dbgObj(DROID obj, string message)
416.{420.{
417. if (obj.selected)421. if (obj.selected)
418. {422. {
419. console(message);423. console(message);
420. }424. }
421.}425.}
422.426.
423.function bool conCanHelp(DROID mydroid, int bx, int by)427.function bool conCanHelp(DROID mydroid, int bx, int by)
424.{428.{
425. return (mydroid.order != DORDER_HELPBUILD and mydroid.order != DORDER_BUILD and mydroid.order != DORDER_LINEBUILD and droidCanReach(mydroid, bx, by));429. return (mydroid.order != DORDER_HELPBUILD and mydroid.order != DORDER_BUILD and mydroid.order != DORDER_LINEBUILD and droidCanReach(mydroid, bx, by));
426.}430.}
427.431.
428.// Build something in main base, grab trucks to do it within tiles range432.// Build something in main base, grab trucks to do it within tiles range
429.function bool grabTrucksAndBuild(int range, STRUCTURESTAT bstats, int maxBlockingTiles)433.function bool grabTrucksAndBuild(int range, STRUCTURESTAT bstats, int maxBlockingTiles)
430.{434.{
431. local DROID mydroid, closestDroid;435. local DROID mydroid, closestDroid;
432. local int closestDist, currDist, numHelpDroids, tilerange, bx, by;436. local int closestDist, currDist, numHelpDroids, tilerange, bx, by;
433.437.
434. initIterateGroup(buildGroup); // find idle droids in build group.438. initIterateGroup(buildGroup); // find idle droids in build group.
435. mydroid = iterateGroup(buildGroup);439. mydroid = iterateGroup(buildGroup);
436. closestDist = 99999;440. closestDist = 99999;
437. closestDroid = NULLOBJECT;441. closestDroid = NULLOBJECT;
438. numHelpDroids = 0;442. numHelpDroids = 0;
439. tilerange = range * TILE;443. tilerange = range * TILE;
440. while (mydroid != NULLOBJECT)444. while (mydroid != NULLOBJECT)
441. {445. {
442. if (conCanHelp(mydroid, baseX, baseY))446. if (conCanHelp(mydroid, baseX, baseY))
443. {447. {
444. bx = baseX;448. bx = baseX;
445. by = baseY;449. by = baseY;
446. if (pickDroidStructLocation(mydroid, bstats, ref bx, ref by, me, maxBlockingTiles))450. if (pickDroidStructLocation(mydroid, bstats, ref bx, ref by, me, maxBlockingTiles))
447. {451. {
448. currDist = distBetweenTwoPoints(bx, by, mydroid.x, mydroid.y);452. currDist = distBetweenTwoPoints(bx, by, mydroid.x, mydroid.y);
449. if (currDist < tilerange)453. if (currDist < tilerange)
450. {454. {
451. orderDroidStatsLoc(mydroid, DORDER_BUILD, bstats, bx, by); // close, so help build it455. orderDroidStatsLoc(mydroid, DORDER_BUILD, bstats, bx, by); // close, so help build it
452. numHelpDroids = numHelpDroids + 1;456. numHelpDroids = numHelpDroids + 1;
453. }457. }
454. else if (currDist < closestDist)458. else if (currDist < closestDist)
455. {459. {
456. closestDroid = mydroid; // record this droid as being closest so far460. closestDroid = mydroid; // record this droid as being closest so far
457. closestDist = currDist;461. closestDist = currDist;
458. }462. }
459. }463. }
460. }464. }
461. mydroid = iterateGroup(buildGroup);465. mydroid = iterateGroup(buildGroup);
462. }466. }
463. if (numHelpDroids == 0 and closestDroid != NULLOBJECT) // found none within help radius, so force someone to go long distance traveling467. if (numHelpDroids == 0 and closestDroid != NULLOBJECT) // found none within help radius, so force someone to go long distance traveling
464. {468. {
465. orderDroidStatsLoc(closestDroid, DORDER_BUILD, bstats, bx, by); // you, book a plane ticket and go!469. orderDroidStatsLoc(closestDroid, DORDER_BUILD, bstats, bx, by); // you, book a plane ticket and go!
466. return true;470. return true;
467. }471. }
468. return (numHelpDroids > 0);472. return (numHelpDroids > 0);
469.}473.}
470.474.
471.event arrived(reachedTr)475.event arrived(reachedTr)
472.{476.{
473. local bool found;477. local bool found;
474. local STRUCTURESTAT myChoice;478. local STRUCTURESTAT myChoice;
475.479.
476. if (droid.droidType == DROID_CONSTRUCT or droid.droidType == DROID_CYBORG_CONSTRUCT)480. if (droid.droidType == DROID_CONSTRUCT or droid.droidType == DROID_CYBORG_CONSTRUCT)
477. {481. {
478. dbgObj(droid, "Failed to build where we should - attempt to screw up enemy oil derrick");482. dbgObj(droid, "Failed to build where we should - attempt to screw up enemy oil derrick");
479.483.
480. // Check if at oil well, and it was taken by enemy484. // Check if at oil well, and it was taken by enemy
481. structure = structureBuiltInRange(derrick, droid.x, droid.y, (5 * 128), -1);485. structure = structureBuiltInRange(derrick, droid.x, droid.y, (5 * 128), -1);
482. if (structure != NULLOBJECT)486. if (structure != NULLOBJECT)
483. {487. {
484. if (not friendlyPlayer(structure.player) and droid.health == 100)488. if (not friendlyPlayer(structure.player) and droid.health == 100)
485. {489. {
486. // Ok, at enemy derrick, and nobody has hurt us yet. Start being nasty.490. // Ok, at enemy derrick, and nobody has hurt us yet. Start being nasty.
487. count = 0;491. count = 0;
488. found = false;492. found = false;
489. // find simplest/cheapest one available to build493. // find simplest/cheapest one available to build
490. while (count < numDefStructs and not found)494. while (count < numDefStructs and not found)
491. {495. {
492. if (isStructureAvailable(defStructs[count], me))496. if (isStructureAvailable(defStructs[count], me))
493. {497. {
494. found = true;498. found = true;
495. }499. }
496. else500. else
497. {501. {
498. count++;502. count++;
499. }503. }
500. }504. }
501. if (found)505. if (found)
502. {506. {
503. buildX = droid.x;507. buildX = droid.x;
504. buildY = droid.y;508. buildY = droid.y;
505. if (pickDroidStructLocation(droid, defStructs[count], ref buildX, ref buildY, me, -1))509. if (pickDroidStructLocation(droid, defStructs[count], ref buildX, ref buildY, me, -1))
506. {510. {
507. orderDroidStatsLoc(droid, DORDER_BUILD, defStructs[count], buildX, buildY);511. orderDroidStatsLoc(droid, DORDER_BUILD, defStructs[count], buildX, buildY);
508. }512. }
509. else513. else
510. {514. {
511. dbgObj(droid, "Wanted to be nasty, but found nowhere to build defense");515. dbgObj(droid, "Wanted to be nasty, but found nowhere to build defense");
512. orderDroid(droid, DORDER_RTB); // nothing more to do here.516. orderDroid(droid, DORDER_RTB); // nothing more to do here.
513. }517. }
514. }518. }
515. else519. else
516. {520. {
517. dbgObj(droid, "Wanted to be nasty, but had nothing nasty to build - returning to base");521. dbgObj(droid, "Wanted to be nasty, but had nothing nasty to build - returning to base");
518. orderDroid(droid, DORDER_RTB); // oh, well. nothing more to do here.522. orderDroid(droid, DORDER_RTB); // oh, well. nothing more to do here.
519. }523. }
520. exit;524. exit;
521. }525. }
522. else if (droid.health < 100 and !insideBase(droid.x, droid.y))526. else if (droid.health < 100 and !insideBase(droid.x, droid.y))
523. {527. {
524. orderDroid(droid, DORDER_RTR); // bolt back to base now!528. orderDroid(droid, DORDER_RTR); // bolt back to base now!
525. exit;529. exit;
526. }530. }
527. }531. }
528. }532. }
529.}533.}
530.534.
531.event buildFundamentals(inactive)535.event buildFundamentals(inactive)
532.{536.{
533. count = 0;537. count = 0;
534. while (count < numFundamental)538. while (count < numFundamental)
535. {539. {
536. // check that struct.540. // check that struct.
537. structure = getStructure(structs[count], me);541. structure = getStructure(structs[count], me);
538. if (structure == NULLOBJECT) // if missing build it.542. if (structure == NULLOBJECT) // if missing build it.
539. {543. {
540. if (isStructureAvailable(structs[count], me))544. if (isStructureAvailable(structs[count], me))
541. {545. {
542. if (grabTrucksAndBuild(12, structs[count], 0))546. if (grabTrucksAndBuild(12, structs[count], 0))
543. {547. {
544. exit; // no need to check more548. exit; // no need to check more
545. }549. }
546. }550. }
547. }551. }
548. count = count + 1;552. count = count + 1;
549. }553. }
550. fundamentalBeingBuilt = derrick;554. fundamentalBeingBuilt = derrick;
551. setEventTrigger(buildFundamentals, inactive);555. setEventTrigger(buildFundamentals, inactive);
552.}556.}
553.557.
554.event startLevel(startLevelTr)558.event startLevel(startLevelTr)
555.{559.{
556. setEventTrigger(buildFundamentals, slowloadTr);560. setEventTrigger(buildFundamentals, slowloadTr);
557. setEventTrigger(conDroids, chainloadTr);561. setEventTrigger(conDroids, chainloadTr);
558. setEventTrigger(doResearch, chainloadTr);562. setEventTrigger(doResearch, chainloadTr);
559. setEventTrigger(buildDerrick, slowloadTr);563. setEventTrigger(buildDerrick, slowloadTr);
560. setEventTrigger(startLevel, inactive);564. setEventTrigger(startLevel, inactive);
561.}565.}
562.566.
563.// decide what technology branch we will use567.// decide what technology branch we will use
564.function void setTechBranch(int _tech)568.function void setTechBranch(int _tech)
565.{569.{
566. local float _y2,_y1,_x2,_x1,_a,_y,_m,_rnd,_mapSize;570. local float _y2,_y1,_x2,_x1,_a,_y,_m,_rnd,_mapSize;
567.571.
568. _mapSize = (float)((mapWidth + mapHeight) / 2);572. _mapSize = (float)((mapWidth + mapHeight) / 2);
569.573.
570. if(_tech != -1)574. if(_tech != -1)
571. {575. {
572. curTech = _tech;576. curTech = _tech;
573. }577. }
574. else578. else
575. {579. {
576. //probability to choose vtol branch for map size 90 = 0; probability for map size 200 = 45580. //probability to choose vtol branch for map size 90 = 0; probability for map size 200 = 45
577. //build a linear function: y = ((y2 - y1) / (x2 - x1)) * x + a depending on two values given (short: y = mx+a)581. //build a linear function: y = ((y2 - y1) / (x2 - x1)) * x + a depending on two values given (short: y = mx+a)
578. _x1 = 90.0; _y1 = 0.0;582. _x1 = 90.0; _y1 = 0.0;
579. _x2 = 200.0; _y2 = 45.0;583. _x2 = 200.0; _y2 = 45.0;
580. _m = ((_y2 - _y1) / (_x2 - _x1));584. _m = ((_y2 - _y1) / (_x2 - _x1));
581. _a = -(_m * _x1);585. _a = -(_m * _x1);
582.586.
583. //calculate probability for the current map587. //calculate probability for the current map
584. _y = _m * _mapSize + _a;588. _y = _m * _mapSize + _a;
585.589.
586. dbg("_m = " & _m & ", a = " & _a, me);590. dbg("_m = " & _m & ", a = " & _a, me);
587.591.
588. _rnd = (float)random(100);592. _rnd = (float)random(100);
589. if(_rnd < _y)593. if(_rnd < _y)
590. {594. {
591. curTech = branchVTOL;595. curTech = branchVTOL;
592. dbg("going air (" & _y & "/" & _rnd & ")", me);596. dbg("going air (" & _y & "/" & _rnd & ")", me);
593. }597. }
594. else598. else
595. {599. {
596. curTech = branchDefault;600. curTech = branchDefault;
597. dbg("going land (" & _y & "/" & _rnd & ")", me);601. dbg("going land (" & _y & "/" & _rnd & ")", me);
598. }602. }
599. }603. }
600.}604.}
601.605.
602./* returns TRUE if AI is responsible for the _player */606./* returns TRUE if AI is responsible for the _player */
603.function bool aiResponsibleForPlayer(int _player)607.function bool aiResponsibleForPlayer(int _player)
604.{608.{
605. if(not _DEBUG and ((_player == selectedPlayer) or not myResponsibility(_player)))609. if(not _DEBUG and ((_player == selectedPlayer) or not myResponsibility(_player)))
606. {610. {
607. return FALSE;611. return FALSE;
608. }612. }
609.613.
610. return TRUE;614. return TRUE;
611.}615.}
612.616.
613./////////////////////////////////////////////////////////////////////617./////////////////////////////////////////////////////////////////////
614.// keep details about the size and postion of the ai players base618.// keep details about the size and postion of the ai players base
615.event basedetails(basedetailsTr)619.event basedetails(basedetailsTr)
616.{620.{
617. // clear old extremities.621. // clear old extremities.
618. maxy = 0;622. maxy = 0;
619. maxx = 0;623. maxx = 0;
620. miny = (mapHeight*128);624. miny = (mapHeight*128);
621. minx = (mapWidth*128);625. minx = (mapWidth*128);
622.626.
623. baseRange = 4 * TILE;627. baseRange = 4 * TILE;
624.628.
625. // now find the extremities of our vital structures.629. // now find the extremities of our vital structures.
626. count = 0;630. count = 0;
627. while(count < numBaseStruct)631. while(count < numBaseStruct)
628. {632. {
629. initEnumStruct(FALSE,baseStruct[count],me,me);633. initEnumStruct(FALSE,baseStruct[count],me,me);
630. structure= enumStruct();634. structure= enumStruct();
631. while(structure != NULLOBJECT)635. while(structure != NULLOBJECT)
632. {636. {
633. if(structure.x < minx)637. if(structure.x < minx)
634. {638. {
635. minx = structure.x;639. minx = structure.x;
636. }640. }
637. if(structure.x > maxx)641. if(structure.x > maxx)
638. {642. {
639. maxx = structure.x;643. maxx = structure.x;
640. }644. }
641. if(structure.y < miny)645. if(structure.y < miny)
642. {646. {
643. miny = structure.y;647. miny = structure.y;
644. }648. }
645. if(structure.y > maxy)649. if(structure.y > maxy)
646. {650. {
647. maxy = structure.y;651. maxy = structure.y;
648. }652. }
649.653.
650. result = distBetweenTwoPoints(baseX, baseY, structure.x, structure.y);654. result = distBetweenTwoPoints(baseX, baseY, structure.x, structure.y);
651.655.
652. if(result > baseRange){656. if(result > baseRange){
653. baseRange = result;657. baseRange = result;
654. }658. }
655.659.
656. structure= enumStruct();660. structure= enumStruct();
657. }661. }
658.662.
659. count = count + 1;663. count = count + 1;
660. }664. }
661.665.
662. result = 3 * 128;666. result = 3 * 128;
663. minx = minx - result;667. minx = minx - result;
664. maxx = maxx + result;668. maxx = maxx + result;
665. miny = miny - result;669. miny = miny - result;
666. maxy = maxy + result;670. maxy = maxy + result;
667.671.
668. baseRange = baseRange + (4 * 128);672. baseRange = baseRange + (4 * 128);
669.}673.}
670.674.
671./////////////////////////////////////////////////////////////////////675./////////////////////////////////////////////////////////////////////
672.// structure building rules676.// structure building rules
673.677.
674.// build derricks on oil.678.// build derricks on oil.
675.event buildDerrick(buildDerrickTr)679.event buildDerrick(buildDerrickTr)
676.{680.{
677. local bool foundOne, _same;681. local bool foundOne, _same;
678. local FEATURE _oil, _closestOil;682. local FEATURE _oil, _closestOil;
679. local int _bestDist, _newDist;683. local int _bestDist, _newDist;
680. local DROID _search;684. local DROID _search;
681.685.
682. // what if we can't waste power on building derricks because we don't have a gen yet?686. // what if we can't waste power on building derricks because we don't have a gen yet?
683. if (playerPower(me) < 300 and haveStructure(derrick) and not haveStructure(powGen))687. if (playerPower(me) < 300 and haveStructure(derrick) and not haveStructure(powGen))
684. {688. {
685. setEventTrigger(buildDerrick, slowloadTr);689. setEventTrigger(buildDerrick, slowloadTr);
686. exit;690. exit;
687. }691. }
688.692.
689. _bestDist = 99999;693. _bestDist = 99999;
690. _closestOil = NULLOBJECT;694. _closestOil = NULLOBJECT;
691. foundOne = false;695. foundOne = false;
692. initIterateGroup(buildGroup); // find all units in build group696. initIterateGroup(buildGroup); // find all units in build group
693. droid = iterateGroup(buildGroup);697. droid = iterateGroup(buildGroup);
694. while (droid != NULLOBJECT && !foundOne)698. while (droid != NULLOBJECT && !foundOne)
695. {699. {
696. if (droid.order != DORDER_BUILD and droid.order != DORDER_LINEBUILD and droid.order != DORDER_HELPBUILD)700. if (droid.order != DORDER_BUILD and droid.order != DORDER_LINEBUILD and droid.order != DORDER_HELPBUILD)
697. {701. {
698. foundOne = true;702. foundOne = true;
699. }703. }
700. else704. else
701. {705. {
702. droid = iterateGroup(buildGroup);706. droid = iterateGroup(buildGroup);
703. }707. }
704. }708. }
705. if (droid != NULLOBJECT)709. if (droid != NULLOBJECT)
706. {710. {
707. initGetFeature(oilRes, -1, me);711. initGetFeature(oilRes, -1, me);
708. _oil = getFeatureB(me);712. _oil = getFeatureB(me);
709. while (_oil != NULLOBJECT)713. while (_oil != NULLOBJECT)
710. {714. {
711. _newDist = distBetweenTwoPoints(droid.x, droid.y, _oil.x, _oil.y);715. _newDist = distBetweenTwoPoints(droid.x, droid.y, _oil.x, _oil.y);
712. _same = false;716. _same = false;
713.717.
714. if (_newDist < _bestDist and droidCanReach(droid, _oil.x, _oil.y)) // this one is closer718. if (_newDist < _bestDist and droidCanReach(droid, _oil.x, _oil.y)) // this one is closer
715. {719. {
716. if (!threatInRange(me, _oil.x, _oil.y, OIL_THREAT_RANGE, FALSE))720. if (!threatInRange(me, _oil.x, _oil.y, OIL_THREAT_RANGE, FALSE))
717. {721. {
718. initIterateGroup(buildGroup); // find all units in build group.722. initIterateGroup(buildGroup); // find all units in build group.
719. _search = iterateGroup(buildGroup);723. _search = iterateGroup(buildGroup);
720. foundOne = false;724. foundOne = false;
721. while (_search != NULLOBJECT && !foundOne)725. while (_search != NULLOBJECT && !foundOne)
722. {726. {
723. if (_search.orderx == _oil.x and _search.ordery == _oil.y and _search != droid)727. if (_search.orderx == _oil.x and _search.ordery == _oil.y and _search != droid)
724. {728. {
725. _same = true;729. _same = true;
726. foundOne = true;730. foundOne = true;
727. }731. }
728. _search = iterateGroup(buildGroup);732. _search = iterateGroup(buildGroup);
729. }733. }
730. if (!_same) // do not go to same spot as another droid734. if (!_same) // do not go to same spot as another droid
731. {735. {
732. _bestDist = _newDist;736. _bestDist = _newDist;
733. _closestOil = _oil;737. _closestOil = _oil;
734. }738. }
735. }739. }
736. }740. }
737. _oil = getFeatureB(me);741. _oil = getFeatureB(me);
738. }742. }
739. if (_closestOil != NULLOBJECT)743. if (_closestOil != NULLOBJECT)
740. {744. {
741. orderDroidStatsLoc(droid, DORDER_BUILD, derrick, _closestOil.x, _closestOil.y); // build a derick745. orderDroidStatsLoc(droid, DORDER_BUILD, derrick, _closestOil.x, _closestOil.y); // build a derick
742. if (idleGroup(buildGroup) > 0)746. if (idleGroup(buildGroup) > 0)
743. {747. {
744. setEventTrigger(buildDerrick, slowloadTr); // do it again for next droid748. setEventTrigger(buildDerrick, slowloadTr); // do it again for next droid
745. exit;749. exit;
746. }750. }
747. }751. }
748. }752. }
749. setEventTrigger(buildDerrick, buildDerrickTr);753. setEventTrigger(buildDerrick, buildDerrickTr);
750.}754.}
751.755.
752./////////////////////////////////////////////////////////////////////756./////////////////////////////////////////////////////////////////////
753.// if idle and derrick in range and no defense then build defense, else ret to base .757.// if idle and derrick in range and no defense then build defense, else ret to base .
754.event buildOilDefenseOrRetreat(buildOilDefenseOrRetreatTr)758.event buildOilDefenseOrRetreat(buildOilDefenseOrRetreatTr)
755.{759.{
756. local int _numBuilders,_maxBuilders;760. local int _numBuilders,_maxBuilders;
757.761.
758. _maxBuilders = 1;762. _maxBuilders = 1;
759.763.
760. // check idle.764. // check idle.
761. initIterateGroup(buildGroup); // find idle droids in build group.765. initIterateGroup(buildGroup); // find idle droids in build group.
762. droid = iterateGroup(buildGroup);766. droid = iterateGroup(buildGroup);
763. while(droid != NULLOBJECT)767. while(droid != NULLOBJECT)
764. {768. {
765. if (droid.order != DORDER_BUILD and droid.order != DORDER_LINEBUILD and droid.order != DORDER_HELPBUILD)769. if (droid.order != DORDER_BUILD and droid.order != DORDER_LINEBUILD and droid.order != DORDER_HELPBUILD)
766. {770. {
767. // if in range of a derrick771. // if in range of a derrick
768. structure = structureBuiltInRange(derrick, droid.x, droid.y, (5*128), me);772. structure = structureBuiltInRange(derrick, droid.x, droid.y, (5*128), me);
769.773.
770. // if inside base limits then presume ok..774. // if inside base limits then presume ok..
771. if( structure != NULLOBJECT)775. if( structure != NULLOBJECT)
772. {776. {
773. if((structure.x > minx) and (structure.y > miny) and (structure.x < maxx) and (structure.y <maxy))777. if((structure.x > minx) and (structure.y > miny) and (structure.x < maxx) and (structure.y <maxy))
774. {778. {
775. structure = NULLOBJECT;779. structure = NULLOBJECT;
776. }780. }
777. }781. }
778.782.
779. if(structure != NULLOBJECT)783. if(structure != NULLOBJECT)
780. {784. {
781. buildX = structure.x;785. buildX = structure.x;
782. buildY = structure.y;786. buildY = structure.y;
783.787.
784. // not many defenses nearby788. // not many defenses nearby
785. if(numFriendlyWeapStructsInRange(me, buildX, buildY, (3*128), FALSE) < 2)789. if(numFriendlyWeapStructsInRange(me, buildX, buildY, (3*128), FALSE) < 2)
786. {790. {
787. count = numDefStructs - 1; //pick a struct to build..791. count = numDefStructs - 1; //pick a struct to build..
788. count2 = 0;792. count2 = 0;
789. while( (count2 < 5) and (count >= 0) )793. while( (count2 < 5) and (count >= 0) )
790. {794. {
791. if( isStructureAvailable(defStructs[count],me))795. if( isStructureAvailable(defStructs[count],me))
792. {796. {
793. structChoice[count2] = defStructs[count];797. structChoice[count2] = defStructs[count];
794. count2 = count2 + 1;798. count2 = count2 + 1;
795. }799. }
796. count = count - 1;800. count = count - 1;
797. }801. }
798. count =0;802. count =0;
799. if(count2 > 0)803. if(count2 > 0)
800. {804. {
801. count = random(count2); //count = choice!805. count = random(count2); //count = choice!
802.806.
803. // pick a location807. // pick a location
804. boolResult = pickDroidStructLocation(droid, structChoice[count], ref buildX, ref buildY, me, -1);808. boolResult = pickDroidStructLocation(droid, structChoice[count], ref buildX, ref buildY, me, -1);
805.809.
806. _numBuilders = numBuildSameBuilding(NULLSTRUCTURESTAT, buildX, buildY);810. _numBuilders = numBuildSameBuilding(NULLSTRUCTURESTAT, buildX, buildY);
807.811.
808. if((boolResult == TRUE) and (_numBuilders < _maxBuilders) and droidCanReach(droid, buildX, buildY))812. if((boolResult == TRUE) and (_numBuilders < _maxBuilders) and droidCanReach(droid, buildX, buildY))
809. {813. {
810. // build it.814. // build it.
811. orderDroidStatsLoc(droid, DORDER_BUILD,structChoice[count], buildX,buildY);815. orderDroidStatsLoc(droid, DORDER_BUILD,structChoice[count], buildX,buildY);
812. _numBuilders++;816. _numBuilders++;
813. }817. }
814. }818. }
815. }819. }
816. else820. else
817. {821. {
818. structure = structureBuiltInRange(playerHQ, droid.x, droid.y, (5*128), me);822. structure = structureBuiltInRange(playerHQ, droid.x, droid.y, (5*128), me);
819. if(structure == NULLOBJECT)823. if(structure == NULLOBJECT)
820. {824. {
821. if(!insideBase(droid.x, droid.y))825. if(!insideBase(droid.x, droid.y))
822. {826. {
823. orderDroid(droid,DORDER_RTB); // return to base;827. orderDroid(droid,DORDER_RTB); // return to base;
824. }828. }
825. }829. }
826. }830. }
827. }831. }
828. else832. else
829. {833. {
830. structure = structureBuiltInRange(playerHQ, droid.x, droid.y, (5*128), me);834. structure = structureBuiltInRange(playerHQ, droid.x, droid.y, (5*128), me);
831. if(structure == NULLOBJECT)835. if(structure == NULLOBJECT)
832. {836. {
833. if(!insideBase(droid.x, droid.y))837. if(!insideBase(droid.x, droid.y))
834. {838. {
835. orderDroid(droid,DORDER_RTB); // return to base;839. orderDroid(droid,DORDER_RTB); // return to base;
836. }840. }
837. }841. }
838. }842. }
839. }843. }
840. droid = iterateGroup(buildGroup);844. droid = iterateGroup(buildGroup);
841. }845. }
842.}846.}
843.847.
844./////////////////////////////////////////////////////////////////////848./////////////////////////////////////////////////////////////////////
845.//mortar etc.. rules. build sensor towers and emplacements.849.//mortar etc.. rules. build sensor towers and emplacements.
846.event incendry(incendryTr)850.event incendry(incendryTr)
847.{851.{
848. if (not isStructureAvailable(sensorTower, me))852. if (not isStructureAvailable(sensorTower, me))
849. {853. {
850. exit;854. exit;
851. }855. }
852.856.
853. initEnumStruct(FALSE,sensorTower,me,me);857. initEnumStruct(FALSE,sensorTower,me,me);
854.858.
855. count = 0;859. count = 0;
856. structure = enumStruct();860. structure = enumStruct();
857. while(structure != NULLOBJECT)861. while(structure != NULLOBJECT)
858. {862. {
859. count = count + 1;863. count = count + 1;
860. structure = enumStruct();864. structure = enumStruct();
861. }865. }
862.866.
863. if (count < (gameTime/4200)) // every 7 mins867. if (count < (gameTime/600)) // every 7 mins
864. {868. {
865. // if not found build a sensor tower.869. // if not found build a sensor tower.
866. // find a place to build.870. // find a place to build.
867. buildX = 0;871. buildX = 0;
868. buildY = 0;872. buildY = 0;
869. initEnumStruct(FALSE,derrick,me,me);873. initEnumStruct(FALSE,derrick,me,me);
870. structure= enumStruct();874. structure= enumStruct();
871. while(structure != NULLOBJECT)875. while(structure != NULLOBJECT)
872. {876. {
873. count = 0;877. count = 0;
874. result = 0;878. result = 0;
875. while(count < numDefStructs)879. while(count < numDefStructs)
876. {880. {
877. structure2 = structureBuiltInRange(defStructs[count], structure.x, structure.y,(4*128), me);881. structure2 = structureBuiltInRange(defStructs[count], structure.x, structure.y,(4*128), me);
878. if(structure2 != NULLOBJECT)882. if(structure2 != NULLOBJECT)
879. {883. {
880. result = result + 1;884. result = result + 1;
881. }885. }
882. count = count + 1;886. count = count + 1;
883. }887. }
884.888.
885. // check for sensor nearby,889. // check for sensor nearby,
886. structure2 = structureBuiltInRange(sensorTower, structure.x, structure.y,(5*128), me);890. structure2 = structureBuiltInRange(sensorTower, structure.x, structure.y,(5*128), me);
887. if(structure2 != NULLOBJECT)891. if(structure2 != NULLOBJECT)
888. {892. {
889. result = 4;893. result = 4;
890. }894. }
891.895.
892. if(result < 3)896. if(result < 3)
893. {897. {
894. buildX = structure.x;898. buildX = structure.x;
895. buildY = structure.y;899. buildY = structure.y;
896. structure = NULLOBJECT;900. structure = NULLOBJECT;
897. }901. }
898. else902. else
899. {903. {
900. structure = enumStruct();904. structure = enumStruct();
901. }905. }
902. }906. }
903.907.
904. if(buildX != 0)908. if(buildX != 0)
905. {909. {
906. boolResult = pickStructLocation(sensorTower, ref buildX, ref buildY,me); // pick spot.910. boolResult = pickStructLocation(sensorTower, ref buildX, ref buildY,me); // pick spot.
907. if(boolResult == TRUE)911. if(boolResult == TRUE)
908. {912. {
909. // find unit913. // find unit
910. initIterateGroup(buildGroup);914. initIterateGroup(buildGroup);
911. droid = iterateGroup(buildGroup);915. droid = iterateGroup(buildGroup);
912. while(droid != NULLOBJECT)916. while(droid != NULLOBJECT)
913. {917. {
914. if ((droid.order == DORDER_NONE or droid.order == DORDER_RTB) and droidCanReach(droid, buildX, buildY))918. if ((droid.order == DORDER_NONE or droid.order == DORDER_RTB) and droidCanReach(droid, buildX, buildY))
915. {919. {
916. orderDroidStatsLoc(droid, DORDER_BUILD, sensorTower, buildX, buildY);920. orderDroidStatsLoc(droid, DORDER_BUILD, sensorTower, buildX, buildY);
917. droid = NULLOBJECT;921. droid = NULLOBJECT;
918. }922. }
919. else923. else
920. {924. {
921. droid = iterateGroup(buildGroup);925. droid = iterateGroup(buildGroup);
922. }926. }
923. }927. }
924. }928. }
925. }929. }
926. }930. }
927. else931. else
928. {932. {
929. // find a sensor tower with least incencdry structs around it..933. // find a sensor tower with least incencdry structs around it..
930. buildX = 0;934. buildX = 0;
931. buildY = 0;935. buildY = 0;
932.936.
933. initEnumStruct(FALSE,sensorTower,me,me);937. initEnumStruct(FALSE,sensorTower,me,me);
934. structure= enumStruct();938. structure= enumStruct();
935. count = 999;939. count = 999;
936. while(structure != NULLOBJECT)940. while(structure != NULLOBJECT)
937. {941. {
938. // count incendrys near this tower.942. // count incendrys near this tower.
939. result = 0;943. result = 0;
940. count2 = 0;944. count2 = 0;
941. while(count2 < numIncendrys)945. while(count2 < numIncendrys)
942. {946. {
943. structure2 = structureBuiltInRange(incendrys[count2], structure.x, structure.y,(4*128), me);947. structure2 = structureBuiltInRange(incendrys[count2], structure.x, structure.y,(4*128), me);
944. if(structure2 != NULLOBJECT)948. if(structure2 != NULLOBJECT)
945. {949. {
946. result = result + 1;950. result = result + 1;
947. }951. }
948. count2 = count2 + 1;952. count2 = count2 + 1;
949. }953. }
950.954.
951. if((result < 6) and (result < count)) // lowest found yet. only sites with <6 too.955. if((result < 6) and (result < count)) // lowest found yet. only sites with <6 too.
952. {956. {
953. buildX = structure.x;957. buildX = structure.x;
954. buildY = structure.y;958. buildY = structure.y;
955. count = result;959. count = result;
956. }960. }
957. structure = enumStruct();961. structure = enumStruct();
958. }962. }
959.963.
960. if(buildX != 0)964. if(buildX != 0)
961. {965. {
962.966.
963. // choose a device967. // choose a device
964. count = numIncendrys - 1;968. count = numIncendrys - 1;
965. result = 99;969. result = 99;
966. while(count >= 0 )970. while(count >= 0 )
967. {971. {
968. if(isStructureAvailable(incendrys[count],me))972. if(isStructureAvailable(incendrys[count],me))
969. {973. {
970. result = count;974. result = count;
971. count = -1;975. count = -1;
972. }976. }
973. else977. else
974. {978. {
975. count = count - 1;979. count = count - 1;
976. }980. }
977. }981. }
978.982.
979.983.
980. // find a unit and build an incendry device.984. // find a unit and build an incendry device.
981. if(result != 99)985. if(result != 99)
982. {986. {
983. boolResult = pickStructLocation(incendrys[result], ref buildX, ref buildY,me); // pick spot.987. boolResult = pickStructLocation(incendrys[result], ref buildX, ref buildY,me); // pick spot.
984. if(boolResult == TRUE)988. if(boolResult == TRUE)
985. {989. {
986. initIterateGroup(buildGroup);990. initIterateGroup(buildGroup);
987. droid = iterateGroup(buildGroup);991. droid = iterateGroup(buildGroup);
988.992.
989. boolResult = (numBuildSameBuilding(incendrys[result], buildX, buildY) > 0); //anyone building there already?993. boolResult = (numBuildSameBuilding(incendrys[result], buildX, buildY) > 0); //anyone building there already?
990.994.
991. while(droid != NULLOBJECT and (not boolResult))995. while(droid != NULLOBJECT and (not boolResult))
992. {996. {
993. if ((droid.order == DORDER_NONE or droid.order == DORDER_RTB) and droidCanReach(droid, buildX, buildY))997. if ((droid.order == DORDER_NONE or droid.order == DORDER_RTB) and droidCanReach(droid, buildX, buildY))
994. {998. {
995. orderDroidStatsLoc(droid, DORDER_BUILD,incendrys[result], buildX,buildY);999. orderDroidStatsLoc(droid, DORDER_BUILD,incendrys[result], buildX,buildY);
996. boolResult = TRUE; //only 1 truck1000. boolResult = TRUE; //only 1 truck
997. }1001. }
998. droid = iterateGroup(buildGroup);1002. droid = iterateGroup(buildGroup);
999. }1003. }
1000. }1004. }
1001. }1005. }
1002. }1006. }
1003. }1007. }
1004.}1008.}
1005.1009.
1006./////////////////////////////////////////////////////////////////////1010./////////////////////////////////////////////////////////////////////
1007.// build a power gen for every 4 derricks. VITAL!1011.// build a power gen for every 4 derricks. VITAL!
1008.event buildPowerGenerators(buildPowerGeneratorsTr)1012.event buildPowerGenerators(buildPowerGeneratorsTr)
1009.{1013.{
1010. if (!isStructureAvailable(powGen, me))1014. if (!isStructureAvailable(powGen, me))
1011. {1015. {
1012. exit;1016. exit;
1013. }1017. }
1014. initEnumStruct(FALSE,derrick,me,me); // count = numderricks1018. initEnumStruct(FALSE,derrick,me,me); // count = numderricks
1015. structure= enumStruct();1019. structure= enumStruct();
1016. count = 0;1020. count = 0;
1017. while(structure != NULLOBJECT)1021. while(structure != NULLOBJECT)
1018. {1022. {
1019. count = count + 1;1023. count = count + 1;
1020. structure= enumStruct();1024. structure= enumStruct();
1021. }1025. }
1022.1026.
1023. initEnumStruct(FALSE,powGen,me,me); // count2 = numpowgens1027. initEnumStruct(FALSE,powGen,me,me); // count2 = numpowgens
1024. structure= enumStruct();1028. structure= enumStruct();
1025. count2 = 0;1029. count2 = 0;
1026. while(structure != NULLOBJECT)1030. while(structure != NULLOBJECT)
1027. {1031. {
1028. count2 = count2 + 1;1032. count2 = count2 + 1;
1029. structure= enumStruct();1033. structure= enumStruct();
1030. }1034. }
1031.1035.
1032. if( (count2 * 4) < count ) // if we need powergen1036. if( (count2 * 4) < count ) // if we need powergen
1033. {1037. {
1034. initIterateGroup(buildGroup);1038. initIterateGroup(buildGroup);
1035. droid = iterateGroup(buildGroup);1039. droid = iterateGroup(buildGroup);
1036. while(droid != NULLOBJECT)1040. while(droid != NULLOBJECT)
1037. {1041. {
1038. if (droid.order != DORDER_HELPBUILD and droid.order != DORDER_BUILD and droid.order != DORDER_LINEBUILD)1042. if (droid.order != DORDER_HELPBUILD and droid.order != DORDER_BUILD and droid.order != DORDER_LINEBUILD)
1039. {1043. {
1040. buildX = baseX; // try build powergen.1044. buildX = baseX; // try build powergen.
1041. buildY = baseY;1045. buildY = baseY;
1042. if (pickDroidStructLocation(droid, powGen, ref buildX, ref buildY, me, 1))1046. if (pickDroidStructLocation(droid, powGen, ref buildX, ref buildY, me, 1))
1043. {1047. {
1044. orderDroidStatsLoc(droid, DORDER_BUILD, powGen, buildX,buildY);1048. orderDroidStatsLoc(droid, DORDER_BUILD, powGen, buildX,buildY);
1045. }1049. }
1046. }1050. }
1047. droid = iterateGroup(buildGroup);1051. droid = iterateGroup(buildGroup);
1048. }1052. }
1049. }1053. }
1050.}1054.}
1051.1055.
1052.1056.
1053./////////////////////////////////////////////////////////////////////1057./////////////////////////////////////////////////////////////////////
1054.// ensure we have everything in the vital structs list.1058.// ensure we have everything in the vital structs list.
1055.event buildBase(buildBaseTr)1059.event buildBase(buildBaseTr)
1056.{1060.{
1057. if (idleGroup(buildGroup) >= (buildGroup.members / 2))1061. if (idleGroup(buildGroup) >= (buildGroup.members / 2))
1058. {1062. {
1059. count = 0;1063. count = 0;
1060. while(count < numStructs)1064. while(count < numStructs)
1061. {1065. {
1062. // check that struct.1066. // check that struct.
1063. structure = getStructure(structs[count],me);1067. structure = getStructure(structs[count],me);
1064. if(structure == NULLOBJECT) // if missing build it.1068. if(structure == NULLOBJECT) // if missing build it.
1065. {1069. {
1066. if(isStructureAvailable(structs[count],me))1070. if(isStructureAvailable(structs[count],me))
1067. {1071. {
1068. if (grabTrucksAndBuild(10, structs[count], 0))1072. if (grabTrucksAndBuild(10, structs[count], 0))
1069. {1073. {
1070. exit; // done here1074. exit; // done here
1071. }1075. }
1072. }1076. }
1073. }1077. }
1074. count = count + 1;1078. count = count + 1;
1075. }1079. }
1076. }1080. }
1077.}1081.}
1078.1082.
1079./////////////////////////////////////////////////////////////////////1083./////////////////////////////////////////////////////////////////////
1080.// build other stuff, grow the base slowly...1084.// build other stuff, grow the base slowly...
1081.event buildExpand( buildExpandTr )1085.event buildExpand( buildExpandTr )
1082.{1086.{
1083. if (playerPower(me) < LOW_POWER)1087. if (playerPower(me) < LOW_POWER)
1084. {1088. {
1085. exit; // do not expand base with low power1089. exit; // do not expand base with low power
1086. }1090. }
1087.1091.
1088. if(extraStruct == numExtraStructs[curTech]) // loop round1092. if(extraStruct == numExtraStructs[curTech]) // loop round
1089. {1093. {
1090. extraStruct = 0;1094. extraStruct = 0;
1091. }1095. }
1092.1096.
1093. if(isStructureAvailable(extraStructs[curTech][extraStruct],me))1097. if(isStructureAvailable(extraStructs[curTech][extraStruct],me))
1094. {1098. {
1095. if (not grabTrucksAndBuild(10, extraStructs[curTech][extraStruct], 0))1099. if (not grabTrucksAndBuild(10, extraStructs[curTech][extraStruct], 0))
1096. {1100. {
1097. dbg("Failed to build expand", me);1101. dbg("Failed to build expand", me);
1098. }1102. }
1099. }1103. }
1100.1104.
1101. extraStruct = extraStruct + 1;1105. extraStruct = extraStruct + 1;
1102.}1106.}
1103.1107.
1104.1108.
1105./////////////////////////////////////////////////////////////////////1109./////////////////////////////////////////////////////////////////////
1106.// Structure (fac/res/pow) upgrades1110.// Structure (fac/res/pow) upgrades
1107.event upgradeStructures(upgradeStructuresTr )1111.event upgradeStructures(upgradeStructuresTr )
1108.{1112.{
1109. if (not havePowerSource()) 1113. if (not havePowerSource())
1110. {1114. {
1111. exit;1115. exit;
1112. }1116. }
1113. initIterateGroup(buildGroup); // find idle droids in build group.1117. initIterateGroup(buildGroup); // find idle droids in build group.
1114. droid = iterateGroup(buildGroup);1118. droid = iterateGroup(buildGroup);
1115. while(droid != NULLOBJECT)1119. while(droid != NULLOBJECT)
1116. {1120. {
1117. if ((droid.order != DORDER_BUILD) and (droid.order != DORDER_LINEBUILD))1121. if ((droid.order != DORDER_BUILD) and (droid.order != DORDER_LINEBUILD))
1118. {1122. {
1119. boolResult = FALSE;1123. boolResult = FALSE;
1120.1124.
1121. if(curTech == branchDefault)1125. if(curTech == branchDefault)
1122. {1126. {
1123. //powergen1127. //powergen
1124. boolResult = upgradePowGen(droid, 2);1128. boolResult = upgradePowGen(droid, 4);
1125.1129.
1126. //factory1130. //factory
1127. if(droid.order != DORDER_BUILD){1131. if(droid.order != DORDER_BUILD){
1128. boolResult = upgradeFactory(droid, 3);1132. boolResult = upgradeFactory(droid, 4);
1129. }1133. }
1130.1134.
1131. //research1135. //research
1132. if(droid.order != DORDER_BUILD){1136. if(droid.order != DORDER_BUILD){
1133. boolResult = upgradeResearch(droid, 1);1137. boolResult = upgradeResearch(droid, 4);
1134. }1138. }
1135.1139.
1136. //vtol Factory1140. //vtol Factory
1137. if(droid.order != DORDER_BUILD){1141. if(droid.order != DORDER_BUILD){
1138. boolResult = upgradeVtolFactory(droid, 1);1142. boolResult = upgradeVtolFactory(droid, 4);
1139. }1143. }
1140. }1144. }
1141. else if(curTech == branchVTOL)1145. else if(curTech == branchVTOL)
1142. {1146. {
1143. //powergen1147. //powergen
1144. boolResult = upgradePowGen(droid, 2);1148. boolResult = upgradePowGen(droid, 4);
1145.1149.
1146. //vtol Factory1150. //vtol Factory
1147. if(droid.order != DORDER_BUILD){1151. if(droid.order != DORDER_BUILD){
1148. boolResult = upgradeVtolFactory(droid, 3);1152. boolResult = upgradeVtolFactory(droid, 4);
1149. }1153. }
1150.1154.
1151. //factory1155. //factory
1152. if(droid.order != DORDER_BUILD){1156. if(droid.order != DORDER_BUILD){
1153. boolResult = upgradeFactory(droid, 2);1157. boolResult = upgradeFactory(droid, 4);
1154. }1158. }
1155.1159.
1156. //research1160. //research
1157. if(droid.order != DORDER_BUILD){1161. if(droid.order != DORDER_BUILD){
1158. boolResult = upgradeResearch(droid, 1);1162. boolResult = upgradeResearch(droid, 4);
1159. }1163. }
1160. }1164. }
1161. }1165. }
1162. droid = iterateGroup(buildGroup);1166. droid = iterateGroup(buildGroup);
1163. }1167. }
1164.}1168.}
1165.1169.
1166.function bool upgradeFactory(DROID _truck, int _maxBuilders)1170.function bool upgradeFactory(DROID _truck, int _maxBuilders)
1167.{1171.{
1168. local STRUCTURE _factory;1172. local STRUCTURE _factory;
1169.1173.
1170. initEnumStruct(FALSE,factory,me,me);1174. initEnumStruct(FALSE,factory,me,me);
1171. _factory = enumStruct();1175. _factory = enumStruct();
1172. while(_factory != NULLOBJECT)1176. while(_factory != NULLOBJECT)
1173. {1177. {
1174. // if upgrade is available && struct is not upgraded1178. // if upgrade is available && struct is not upgraded
1175. if( isStructureAvailable(facModule,me) and (skGetFactoryCapacity(_factory) < 2 ) and droidCanReach(_truck, _factory.x, _factory.y))1179. if( isStructureAvailable(facModule,me) and (skGetFactoryCapacity(_factory) < 2 ) and droidCanReach(_truck, _factory.x, _factory.y))
1176. {1180. {
1177. if((numBuildSameBuilding(facModule, _factory.x, _factory.y) +1181. if((numBuildSameBuilding(facModule, _factory.x, _factory.y) +
1178. numBuildSameBuilding(vtolFactory, _factory.x, _factory.y)) < _maxBuilders)1182. numBuildSameBuilding(vtolFactory, _factory.x, _factory.y)) < _maxBuilders)
1179. {1183. {
1180. orderDroidStatsLoc(_truck, DORDER_BUILD,facModule, _factory.x,_factory.y); // upgrade it.1184. orderDroidStatsLoc(_truck, DORDER_BUILD,facModule, _factory.x,_factory.y); // upgrade it.
1181. return TRUE;1185. return TRUE;
1182. }1186. }
1183. }1187. }
1184. _factory = enumStruct();1188. _factory = enumStruct();
1185. }1189. }
1186.1190.
1187. return FALSE;1191. return FALSE;
1188.}1192.}
1189.1193.
1190.function bool upgradeVtolFactory(DROID _truck, int _maxBuilders)1194.function bool upgradeVtolFactory(DROID _truck, int _maxBuilders)
1191.{1195.{
1192. local STRUCTURE _factory;1196. local STRUCTURE _factory;
1193.1197.
1194. initEnumStruct(FALSE,vtolFactory,me,me);1198. initEnumStruct(FALSE,vtolFactory,me,me);
1195. _factory = enumStruct();1199. _factory = enumStruct();
1196. while(_factory != NULLOBJECT)1200. while(_factory != NULLOBJECT)
1197. {1201. {
1198. // if upgrade is available && struct is not upgraded1202. // if upgrade is available && struct is not upgraded
1199. if( isStructureAvailable(facModule,me) and (skGetFactoryCapacity(_factory) < 2 ) and droidCanReach(_truck, _factory.x, _factory.y))1203. if( isStructureAvailable(facModule,me) and (skGetFactoryCapacity(_factory) < 2 ) and droidCanReach(_truck, _factory.x, _factory.y))
1200. {1204. {
1201. if((numBuildSameBuilding(facModule, _factory.x, _factory.y) +1205. if((numBuildSameBuilding(facModule, _factory.x, _factory.y) +
1202. numBuildSameBuilding(factory, _factory.x, _factory.y)) < _maxBuilders)1206. numBuildSameBuilding(factory, _factory.x, _factory.y)) < _maxBuilders)
1203. {1207. {
1204. orderDroidStatsLoc(_truck, DORDER_BUILD,facModule, _factory.x,_factory.y); // upgrade it.1208. orderDroidStatsLoc(_truck, DORDER_BUILD,facModule, _factory.x,_factory.y); // upgrade it.
1205. return TRUE;1209. return TRUE;
1206. }1210. }
1207. }1211. }
1208. _factory = enumStruct();1212. _factory = enumStruct();
1209. }1213. }
1210.1214.
1211. return FALSE;1215. return FALSE;
1212.}1216.}
1213.1217.
1214.function bool upgradeResearch(DROID _truck, int _maxBuilders)1218.function bool upgradeResearch(DROID _truck, int _maxBuilders)
1215.{1219.{
1216. local STRUCTURE _resFac;1220. local STRUCTURE _resFac;
1217.1221.
1218. initEnumStruct(FALSE,resLab,me,me);1222. initEnumStruct(FALSE,resLab,me,me);
1219. _resFac = enumStruct();1223. _resFac = enumStruct();
1220. while(_resFac != NULLOBJECT)1224. while(_resFac != NULLOBJECT)
1221. {1225. {
1222. // if upgrade is available && struct is not upgraded1226. // if upgrade is available && struct is not upgraded
1223. if( isStructureAvailable(resModule,me) and (not testStructureModule(me, _resFac, 0)) and droidCanReach(_truck, _resFac.x, _resFac.y))1227. if( isStructureAvailable(resModule,me) and (not testStructureModule(me, _resFac, 0)) and droidCanReach(_truck, _resFac.x, _resFac.y))
1224. {1228. {
1225. if((numBuildSameBuilding(resModule, _resFac.x, _resFac.y) +1229. if((numBuildSameBuilding(resModule, _resFac.x, _resFac.y) +
1226. numBuildSameBuilding(resLab, _resFac.x, _resFac.y)) < _maxBuilders)1230. numBuildSameBuilding(resLab, _resFac.x, _resFac.y)) < _maxBuilders)
1227. {1231. {
1228. orderDroidStatsLoc(_truck, DORDER_BUILD,resModule, _resFac.x,_resFac.y); // upgrade it.1232. orderDroidStatsLoc(_truck, DORDER_BUILD,resModule, _resFac.x,_resFac.y); // upgrade it.
1229. return TRUE;1233. return TRUE;
1230. }1234. }
1231. }1235. }
1232. _resFac = enumStruct();1236. _resFac = enumStruct();
1233. }1237. }
1234.1238.
1235. return FALSE;1239. return FALSE;
1236.}1240.}
1237.1241.
1238.function bool upgradePowGen(DROID _truck, int _maxBuilders)1242.function bool upgradePowGen(DROID _truck, int _maxBuilders)
1239.{1243.{
1240. local STRUCTURE _powGen;1244. local STRUCTURE _powGen;
1241.1245.
1242. initEnumStruct(FALSE,powGen,me,me);1246. initEnumStruct(FALSE,powGen,me,me);
1243. _powGen = enumStruct();1247. _powGen = enumStruct();
1244. while(_powGen != NULLOBJECT)1248. while(_powGen != NULLOBJECT)
1245. {1249. {
1246. // if upgrade is available && struct is not upgraded1250. // if upgrade is available && struct is not upgraded
1247. if( isStructureAvailable(powModule,me) and (not testStructureModule(me, _powGen, 0)) and droidCanReach(_truck, _powGen.x, _powGen.y))1251. if( isStructureAvailable(powModule,me) and (not testStructureModule(me, _powGen, 0)) and droidCanReach(_truck, _powGen.x, _powGen.y))
1248. {1252. {
1249. if((numBuildSameBuilding(powModule, _powGen.x,_powGen.y) +1253. if((numBuildSameBuilding(powModule, _powGen.x,_powGen.y) +
1250. numBuildSameBuilding(powGen, _powGen.x,_powGen.y)) < _maxBuilders)1254. numBuildSameBuilding(powGen, _powGen.x,_powGen.y)) < _maxBuilders)
1251. {1255. {
1252. orderDroidStatsLoc(_truck, DORDER_BUILD, powModule, _powGen.x,_powGen.y); // upgrade it.1256. orderDroidStatsLoc(_truck, DORDER_BUILD, powModule, _powGen.x,_powGen.y); // upgrade it.
1253. return TRUE;1257. return TRUE;
1254. }1258. }
1255. }1259. }
1256. _powGen = enumStruct();1260. _powGen = enumStruct();
1257. }1261. }
1258.1262.
1259. return FALSE;1263. return FALSE;
1260.}1264.}
1261.1265.
1262.1266.
1263./////////////////////////////////////////////////////////////////////1267./////////////////////////////////////////////////////////////////////
1264.// Finish Building Part Built Structures1268.// Finish Building Part Built Structures
1265.event finishStructs(finishStructsTr)1269.event finishStructs(finishStructsTr)
1266.{1270.{
1267. initEnumStruct(TRUE,factory,me,me);1271. initEnumStruct(TRUE,factory,me,me);
1268. structure= enumStruct();1272. structure= enumStruct();
1269. while(structure != NULLOBJECT)1273. while(structure != NULLOBJECT)
1270. {1274. {
1271. if(not structureComplete(structure))1275. if(not structureComplete(structure))
1272. {1276. {
1273. initIterateGroup(buildGroup); // find idle droids in build group.1277. initIterateGroup(buildGroup); // find idle droids in build group.
1274. droid = iterateGroup(buildGroup);1278. droid = iterateGroup(buildGroup);
1275. while(droid != NULLOBJECT)1279. while(droid != NULLOBJECT)
1276. {1280. {
1277. if (droid.order != DORDER_BUILD and droid.order != DORDER_LINEBUILD1281. if (droid.order != DORDER_BUILD and droid.order != DORDER_LINEBUILD
1278. and droidCanReach(droid, structure.x, structure.y)1282. and droidCanReach(droid, structure.x, structure.y)
1279. and distBetweenTwoPoints(droid.x, droid.y, structure.x, structure.y) < 20 * TILE)1283. and distBetweenTwoPoints(droid.x, droid.y, structure.x, structure.y) < 20 * TILE)
1280. {1284. {
1281. orderDroidObj(droid,DORDER_HELPBUILD,structure);1285. orderDroidObj(droid,DORDER_HELPBUILD,structure);
1282. }1286. }
1283. droid = iterateGroup(buildGroup);1287. droid = iterateGroup(buildGroup);
1284. }1288. }
1285. }1289. }
1286. structure= enumStruct();1290. structure= enumStruct();
1287. }1291. }
1288.}1292.}
1289.1293.
1290.1294.
1291./////////////////////////////////////////////////////////////////////1295./////////////////////////////////////////////////////////////////////
1292.// fortify base by builiding defensive structs on the edge of the base.1296.// fortify base by builiding defensive structs on the edge of the base.
1293.// rewrote fortify to use scrSkDefenseLocation(baseX,baseY,me);1297.// rewrote fortify to use scrSkDefenseLocation(baseX,baseY,me);
1294.1298.
1295.event newfortify(fortifyTr)1299.event newfortify(fortifyTr)
1296.{1300.{
1297. local int _numBuilders,_maxBuilders;1301. local int _numBuilders,_maxBuilders;
1298.1302.
1299. _maxBuilders = 1;1303. _maxBuilders = 1;
1300.1304.
1301. if(numGroupSameOrder(buildGroup, DORDER_LINEBUILD) >= _maxBuilders)1305. if(numGroupSameOrder(buildGroup, DORDER_LINEBUILD) >= _maxBuilders)
1302. {1306. {
1303. exit;1307. exit;
1304. }1308. }
1305.1309.
1306. boolResult = FALSE;1310. boolResult = FALSE;
1307. initIterateGroup(buildGroup); // find idle an idle veh.in build group.1311. initIterateGroup(buildGroup); // find idle an idle veh.in build group.
1308. droid = iterateGroup(buildGroup);1312. droid = iterateGroup(buildGroup);
1309. while((boolResult == FALSE) and (droid != NULLOBJECT))1313. while((boolResult == FALSE) and (droid != NULLOBJECT))
1310. {1314. {
1311. if (droid.order != DORDER_BUILD and droid.order != DORDER_LINEBUILD and droid.order != DORDER_HELPBUILD)1315. if (droid.order != DORDER_BUILD and droid.order != DORDER_LINEBUILD and droid.order != DORDER_HELPBUILD)
1312. {1316. {
1313. boolResult = TRUE; // dont do this again!1317. boolResult = TRUE; // dont do this again!
1314.1318.
1315. tempx = baseX;1319. tempx = baseX;
1316. tempy = baseY;1320. tempy = baseY;
1317.1321.
1318. // choose a suitable turret.1322. // choose a suitable turret.
1319. count = numWallWeaps - 1;1323. count = numWallWeaps - 1;
1320. count2 = 0;1324. count2 = 0;
1321. while( (count2 < 3) and (count >= 0) )1325. while( (count2 < 3) and (count >= 0) )
1322. {1326. {
1323. if( isStructureAvailable(wallWeaps[count],me))1327. if( isStructureAvailable(wallWeaps[count],me))
1324. {1328. {
1325. structChoice[count2] = wallWeaps[count];1329. structChoice[count2] = wallWeaps[count];
1326. count2 = count2 + 1;1330. count2 = count2 + 1;
1327. }1331. }
1328. count = count - 1;1332. count = count - 1;
1329. }1333. }
1330. count =0;1334. count =0;
1331. if((count2 > 0) and (_numBuilders < _maxBuilders))1335. if((count2 > 0) and (_numBuilders < _maxBuilders))
1332. {1336. {
1333. count = random(count2);1337. count = random(count2);
1334. skDefenseLocationB(ref tempx,ref tempy,wall,structChoice[count],droid,me);1338. skDefenseLocationB(ref tempx,ref tempy,wall,structChoice[count],droid,me);
1335. _numBuilders++;1339. _numBuilders++;
1336. }1340. }
1337.1341.
1338. }1342. }
1339. droid = iterateGroup(buildGroup);1343. droid = iterateGroup(buildGroup);
1340.1344.
1341. }1345. }
1342.}1346.}
1343.1347.
1344.1348.
1345./////////////////////////////////////////////////////////////////////1349./////////////////////////////////////////////////////////////////////
1346.// droid building rules1350.// droid building rules
1347./////////////////////////////////////////////////////////////////////1351./////////////////////////////////////////////////////////////////////
1348.// deal with a droid being built1352.// deal with a droid being built
1349.event droidBuiltAssign(droidBuiltTr)1353.event droidBuiltAssign(droidBuiltTr)
1350.{1354.{
1351. if(isVtol(droid))1355. if(isVtol(droid))
1352. {1356. {
1353. if(vtolDefendGr.members < numDefendVtols)1357. if(vtolDefendGr.members < numDefendVtols)
1354. {1358. {
1355. groupAddDroid(vtolDefendGr, droid);1359. groupAddDroid(vtolDefendGr, droid);
1356. }1360. }
1357. else1361. else
1358. {1362. {
1359. count = 0;1363. count = 0;
1360. while(count < numVtolAttackGroups)1364. while(count < numVtolAttackGroups)
1361. {1365. {
1362. if(vtolAttackGr[count].members < numAttackVtols)1366. if(vtolAttackGr[count].members < numAttackVtols)
1363. {1367. {
1364. dbg("added new vtol to group " & count, me);1368. dbg("added new vtol to group " & count, me);
1365. groupAddDroid(vtolAttackGr[count], droid);1369. groupAddDroid(vtolAttackGr[count], droid);
1366. count = numVtolAttackGroups;1370. count = numVtolAttackGroups;
1367. }1371. }
1368. count++;1372. count++;
1369. }1373. }
1370. }1374. }
1371. }1375. }
1372. else if((droid.droidType != DROID_TRANSPORTER) and (droid.droidType != DROID_COMMAND))1376. else if((droid.droidType != DROID_TRANSPORTER) and (droid.droidType != DROID_COMMAND))
1373. {1377. {
1374.1378.
1375. if((droid.droidType == DROID_REPAIR)1379. if((droid.droidType == DROID_REPAIR)
1376. or (droid.droidType == DROID_CYBORG_REPAIR))1380. or (droid.droidType == DROID_CYBORG_REPAIR))
1377. {1381. {
1378. numRepairUnits = numRepairUnits + 1;1382. numRepairUnits = numRepairUnits + 1;
1379. }1383. }
1380. 1384. if(droid.droidType == DROID_SENSOR)
1385. {
1386. numSensorUnits = numSensorUnits + 1;
1387. }
1381. if((droid.droidType == DROID_CONSTRUCT)1388. if((droid.droidType == DROID_CONSTRUCT)
1382. or (droid.droidType == DROID_CYBORG_CONSTRUCT)) // if constructor droid1389. or (droid.droidType == DROID_CYBORG_CONSTRUCT)) // if constructor droid
1383. {1390. {
1384. groupAddDroid(buildGroup, droid);1391. groupAddDroid(buildGroup, droid);
1385. }1392. }
1386. else1393. else
1387. {1394. {
1388. if(droid.droidType == DROID_CYBORG)1395. if(droid.droidType == DROID_CYBORG)
1389. {1396. {
1390. groupAddDroid(defendGroup, droid);1397. groupAddDroid(attackGroup, droid);
1391. }1398. }
1392. else1399. else
1393. {1400. {
1394. if(scoutGroup.members < numScouts[curTech])1401. if(scoutGroup.members < numScouts[curTech])
1395. {1402. {
1396. groupAddDroid(scoutGroup, droid);1403. groupAddDroid(scoutGroup, droid);
1397. }1404. }
1398. else if(attackGroup.members < numAttackers[curTech])1405. else if(attackGroup.members < numAttackers[curTech])
1399. {1406. {
1400. groupAddDroid(attackGroup, droid);1407. groupAddDroid(attackGroup, droid);
1401. }1408. }
1402. else if( defendGroup.members < numDefenders[curTech])1409. else if( defendGroup.members < numDefenders[curTech])
1403. {1410. {
1404. groupAddDroid(defendGroup, droid);1411. groupAddDroid(defendGroup, droid);
1405. }1412. }
1406. else1413. else
1407. {1414. {
1408. if(scoutGroup.members < maxScouts[curTech])1415. if(scoutGroup.members < maxScouts[curTech])
1409. {1416. {
1410. groupAddDroid(scoutGroup, droid);1417. groupAddDroid(scoutGroup, droid);
1411. }1418. }
1412. else if(attackGroup.members < maxAttackers[curTech])1419. else if(attackGroup.members < maxAttackers[curTech])
1413. {1420. {
1414. groupAddDroid(attackGroup, droid);1421. groupAddDroid(attackGroup, droid);
1415. }1422. }
1416. else if( defendGroup.members < maxDefenders[curTech])1423. else if( defendGroup.members < maxDefenders[curTech])
1417. {1424. {
1418. groupAddDroid(defendGroup, droid);1425. groupAddDroid(defendGroup, droid);
1419. }1426. }
1420. else //make them attack1427. else //make them attack
1421. {1428. {
1422. groupAddDroid(attackGroup, droid);1429. groupAddDroid(attackGroup, droid);
1423. }1430. }
1424. }1431. }
1425. }1432. }
1426. }1433. }
1427. }1434. }
1428.}1435.}
1429.1436.
1430.//When droid built: check emergency jobs, start building next droid1437.//When droid built: check emergency jobs, start building next droid
1431.event droidBuilt(droidBuiltTr)1438.event droidBuilt(droidBuiltTr)
1432.{1439.{
1433. local STRUCTURE _fundie;1440. local STRUCTURE _fundie;
1434.1441.
1435. /* Start building next droid */1442. /* Start building next droid */
1436. if(structure != NULLOBJECT)1443. if(structure != NULLOBJECT)
1437. {1444. {
1438. // derrick works as NULL here, as NULLSTAT does not seem to work1445. // derrick works as NULL here, as NULLSTAT does not seem to work
1439. if (droid.droidType == DROID_CONSTRUCT and fundamentalBeingBuilt != derrick)1446. if (droid.droidType == DROID_CONSTRUCT and fundamentalBeingBuilt != derrick)
1440. {1447. {
1441. _fundie = getStructure(fundamentalBeingBuilt, me);1448. _fundie = getStructure(fundamentalBeingBuilt, me);
1442. if (_fundie != NULLOBJECT)1449. if (_fundie != NULLOBJECT)
1443. {1450. {
1444. if (not structureComplete(_fundie))1451. if (not structureComplete(_fundie))
1445. {1452. {
1446. orderDroidObj(droid, DORDER_HELPBUILD, _fundie);1453. orderDroidObj(droid, DORDER_HELPBUILD, _fundie);
1447. }1454. }
1448. }1455. }
1449. }1456. }
1450.1457.
1451. if (droid.droidType == DROID_CONSTRUCT && structure.stattype == REF_FACTORY)1458. if (droid.droidType == DROID_CONSTRUCT && structure.stattype == REF_FACTORY)
1452. {1459. {
1453. setEventTrigger(conDroids, chainloadTr); // consider building more1460. setEventTrigger(conDroids, chainloadTr); // consider building more
1454. }1461. }
1455. // Continue building new droids right away1462. // Continue building new droids right away
1456. else if(structure.stattype == REF_FACTORY)1463. else if(structure.stattype == REF_FACTORY)
1457. {1464. {
1458. factoryBuildDroid(structure);1465. factoryBuildDroid(structure);
1459. }1466. }
1460. else if(structure.stattype == REF_CYBORG_FACTORY)1467. else if(structure.stattype == REF_CYBORG_FACTORY)
1461. {1468. {
1462. cybFactorBuildCyborg(structure);1469. cybFactorBuildCyborg(structure);
1463. }1470. }
1464. else if(structure.stattype == REF_VTOL_FACTORY)1471. else if(structure.stattype == REF_VTOL_FACTORY)
1465. {1472. {
1466. vtolFactoryBuildVtol(structure);1473. vtolFactoryBuildVtol(structure);
1467. }1474. }
1468. }1475. }
1469.}1476.}
1470.1477.
1471./* Gets triggered when structure was built */1478./* Gets triggered when structure was built */
1472.event structBuilt(structBuiltTr)1479.event structBuilt(structBuiltTr)
1473.{1480.{
1474. local FEATURE _oilResource;1481. local FEATURE _oilResource;
1475. local int _count,_count2;1482. local int _count,_count2;
1476.1483.
1477. if (structure == NULLOBJECT || droid == NULLOBJECT)1484. if (structure == NULLOBJECT || droid == NULLOBJECT)
1478. {1485. {
1479. exit;1486. exit;
1480. }1487. }
1481.1488.
1482. /* factory or factory module */1489. /* factory or factory module */
1483. if(structure.stattype == REF_FACTORY)1490. if(structure.stattype == REF_FACTORY)
1484. {1491. {
1485. if (isStructureAvailable(facModule, me) and (skGetFactoryCapacity(structure) < 2 ) and (getDroidCount(me) > 4))1492. if (isStructureAvailable(facModule, me) and (skGetFactoryCapacity(structure) < 2 ) and (getDroidCount(me) > 4))
1486. {1493. {
1487. orderDroidStatsLoc(droid, DORDER_BUILD,facModule, structure.x,structure.y); // upgrade it.1494. orderDroidStatsLoc(droid, DORDER_BUILD,facModule, structure.x,structure.y); // upgrade it.
1488. }1495. }
1489. else1496. else
1490. {1497. {
1491. setEventTrigger(conDroids, chainloadTr);1498. setEventTrigger(conDroids, chainloadTr);
1492. }1499. }
1493. }1500. }
1494. /* vtol factory or vtol factory module */1501. /* vtol factory or vtol factory module */
1495. else if(structure.stattype == REF_VTOL_FACTORY)1502. else if(structure.stattype == REF_VTOL_FACTORY)
1496. {1503. {
1497. if( isStructureAvailable(facModule,me) and (skGetFactoryCapacity(structure) < 2 ))1504. if( isStructureAvailable(facModule,me) and (skGetFactoryCapacity(structure) < 2 ))
1498. {1505. {
1499. orderDroidStatsLoc(droid, DORDER_BUILD,facModule, structure.x,structure.y); // upgrade it.1506. orderDroidStatsLoc(droid, DORDER_BUILD,facModule, structure.x,structure.y); // upgrade it.
1500. }1507. }
1501. }1508. }
1502. else if(structure.stattype == REF_RESOURCE_EXTRACTOR)1509. else if(structure.stattype == REF_RESOURCE_EXTRACTOR)
1503. {1510. {
1504. setEventTrigger(buildDerrick, chainloadTr);1511. setEventTrigger(buildDerrick, chainloadTr);
1505. exit;1512. exit;
1506. }1513. }
1507. else if (structure.stattype == REF_RESEARCH)1514. else if (structure.stattype == REF_RESEARCH)
1508. {1515. {
1509. if (isStructureAvailable(resModule, me))1516. if (isStructureAvailable(resModule, me))
1510. {1517. {
1511. orderDroidStatsLoc(droid, DORDER_BUILD, resModule, structure.x, structure.y); // upgrade it.1518. orderDroidStatsLoc(droid, DORDER_BUILD, resModule, structure.x, structure.y); // upgrade it.
1512. }1519. }
1513. else1520. else
1514. {1521. {
1515. setEventTrigger(doResearch, chainloadTr);1522. setEventTrigger(doResearch, chainloadTr);
1516. }1523. }
1517. }1524. }
1518. else if (structure.stattype == REF_POWER_GEN)1525. else if (structure.stattype == REF_POWER_GEN)
1519. {1526. {
1520. if (isStructureAvailable(powModule, me))1527. if (isStructureAvailable(powModule, me))
1521. {1528. {
1522. orderDroidStatsLoc(droid, DORDER_BUILD, powModule, structure.x, structure.y); // upgrade it.1529. orderDroidStatsLoc(droid, DORDER_BUILD, powModule, structure.x, structure.y); // upgrade it.
1523. }1530. }
1524. }1531. }
1525.1532.
1526. // Check if available trucks need to build more absolute necessities right away. We need a trigger here because1533. // Check if available trucks need to build more absolute necessities right away. We need a trigger here because
1527. // droids involved in building have not yet come out of their build orders.1534. // droids involved in building have not yet come out of their build orders.
1528. setEventTrigger(buildFundamentals, slowloadTr);1535. setEventTrigger(buildFundamentals, slowloadTr);
1529.1536.
1530. //see if we have just rebuilt a destroyed structure1537. //see if we have just rebuilt a destroyed structure
1531. _count = 0;1538. _count = 0;
1532. while(_count < countRebuildStruct)1539. while(_count < countRebuildStruct)
1533. {1540. {
1534. if(structure.x == rebuildStructX[_count] and1541. if(structure.x == rebuildStructX[_count] and
1535. structure.y == rebuildStructY[_count] and1542. structure.y == rebuildStructY[_count] and
1536. ( (structure.stat == rebuildStructStat[_count]) or //walls can end up as corner walls1543. ( (structure.stat == rebuildStructStat[_count]) or //walls can end up as corner walls
1537. ( (structure.stat == wall or structure.stat == cornerWall) and1544. ( (structure.stat == wall or structure.stat == cornerWall) and
1538. (rebuildStructStat[_count] == wall or rebuildStructStat[_count] == cornerWall))1545. (rebuildStructStat[_count] == wall or rebuildStructStat[_count] == cornerWall))
1539. ))1546. ))
1540. {1547. {
1541. dbg("finished rebuilding destroyed structure - " & _count, me);1548. dbg("finished rebuilding destroyed structure - " & _count, me);
1542.1549.
1543. //resort destroyed structures1550. //resort destroyed structures
1544. _count2 = _count;1551. _count2 = _count;
1545. while(_count2 < (countRebuildStruct - 1))1552. while(_count2 < (countRebuildStruct - 1))
1546. {1553. {
1547. rebuildStructX[_count2] = rebuildStructX[_count2 + 1];1554. rebuildStructX[_count2] = rebuildStructX[_count2 + 1];
1548. rebuildStructY[_count2] = rebuildStructY[_count2 + 1];1555. rebuildStructY[_count2] = rebuildStructY[_count2 + 1];
1549. rebuildStructStat[_count2] = rebuildStructStat[_count2 + 1];1556. rebuildStructStat[_count2] = rebuildStructStat[_count2 + 1];
1550.1557.
1551. _count2++;1558. _count2++;
1552. }1559. }
1553.1560.
1554. //clear last entry1561. //clear last entry
1555. rebuildStructX[countRebuildStruct - 1] = 0;1562. rebuildStructX[countRebuildStruct - 1] = 0;
1556. rebuildStructY[countRebuildStruct - 1] = 0;1563. rebuildStructY[countRebuildStruct - 1] = 0;
1557. rebuildStructStat[countRebuildStruct - 1] = NULLSTRUCTURESTAT;1564. rebuildStructStat[countRebuildStruct - 1] = NULLSTRUCTURESTAT;
1558.1565.
1559. countRebuildStruct--; //we just built one structure1566. countRebuildStruct--; //we just built one structure
1560.1567.
1561. //_count = countRebuildStruct; //exit outer loop1568. //_count = countRebuildStruct; //exit outer loop
1562. }1569. }
1563. _count++;1570. _count++;
1564. }1571. }
1565.}1572.}
1566.1573.
1567./////////////////////////////////////////////////////////////////////1574./////////////////////////////////////////////////////////////////////
1568.// deal with attacks.1575.// deal with attacks.
1569.event droidDestroyed(droidDestroyedTr)1576.event droidDestroyed(droidDestroyedTr)
1570.{1577.{
1571.1578.
1572. if(droid.droidType == DROID_REPAIR)1579. if(droid.droidType == DROID_REPAIR)
1573. {1580. {
1574. numRepairUnits = numRepairUnits - 1;1581. numRepairUnits = numRepairUnits - 1;
1575. }1582. }
1583.
1584. if(droid.droidType == DROID_SENSOR)
1585. {
1586. numSensorUnits = numSensorUnits - 1;
1587. }
1576.1588.
1577. if(droid.droidType == DROID_CONSTRUCT) // if constructor droid1589. if(droid.droidType == DROID_CONSTRUCT) // if constructor droid
1578. {1590. {
1579. initEnumStruct(FALSE,factory,me,me);1591. initEnumStruct(FALSE,factory,me,me);
1580. structure= enumStruct(); // find factory.1592. structure= enumStruct(); // find factory.
1581.1593.
1582. if( (structure != NULLOBJECT) and (getDroidCount(me) < MAX_DROIDS) )1594. if( (structure != NULLOBJECT) and (getDroidCount(me) < MAX_DROIDS) )
1583. {1595. {
1584. buildDroid(constructor, structure, me, 1); // build constructor1596. buildDroid(constructor, structure, me, 1); // build constructor
1585. }1597. }
1586.1598.
1587. }1599. }
1588.}1600.}
1589.1601.
1590.1602.
1591./////////////////////////////////////////////////////////////////////1603./////////////////////////////////////////////////////////////////////
1592.// build more con droids.1604.// build more con droids.
1593.event conDroids(conDroidsTr)1605.event conDroids(conDroidsTr)
1594.{1606.{
1595. local int _maxTrucks;1607. local int _maxTrucks;
1596. local STRUCTURE _factory;1608. local STRUCTURE _factory;
1597. local int _numBuilding,_haveTrucks,_maxTruckFactories,_totalTrucks;1609. local int _numBuilding,_haveTrucks,_maxTruckFactories,_totalTrucks;
1598. local bool _bStartedBuilding;1610. local bool _bStartedBuilding;
1599.1611.
1600. _maxTrucks = MAX_TRUCKS;1612. _maxTrucks = MAX_TRUCKS;
1601. if (playerPower(me) < LOW_POWER)1613. if (playerPower(me) < LOW_POWER)
1602. {1614. {
1603. _maxTrucks = MIN_TRUCKS;1615. _maxTrucks = MIN_TRUCKS;
1604. }1616. }
1605.1617.
1606. _maxTruckFactories = 3; //max factories to use for truck production1618. _maxTruckFactories = 3; //max factories to use for truck production
1607.1619.
1608. _haveTrucks = buildGroup.members;1620. _haveTrucks = buildGroup.members;
1609. 1621.
1610. //Find out how many trucks and combat engineers are already in production1622. //Find out how many trucks and combat engineers are already in production
1611. _numBuilding = numTemplatesInProduction(constructor,me); //trucks1623. _numBuilding = numTemplatesInProduction(constructor,me); //trucks
1612. _numBuilding = _numBuilding + numTemplatesInProduction(cybEngineer,me); //engineers1624. _numBuilding = _numBuilding + numTemplatesInProduction(cybEngineer,me); //engineers
1613.1625.
1614. _totalTrucks = _numBuilding + _haveTrucks;1626. _totalTrucks = _numBuilding + _haveTrucks;
1615. 1627.
1616. initEnumStruct(FALSE,factory,me,me);1628. initEnumStruct(FALSE,factory,me,me);
1617. _factory = enumStruct();1629. _factory = enumStruct();
1618. 1630.
1619. while ((_factory != NULLOBJECT) and (_numBuilding < _maxTruckFactories) and (_totalTrucks < _maxTrucks))1631. while ((_factory != NULLOBJECT) and (_numBuilding < _maxTruckFactories) and (_totalTrucks < _maxTrucks))
1620. {1632. {
1621. //Try to build a truck1633. //Try to build a truck
1622. if (skCanBuildTemplate(me, _factory, hovertruck))1634. if (skCanBuildTemplate(me, _factory, hovertruck))
1623. {1635. {
1624. _bStartedBuilding = buildUnit(hovertruck, _factory, factory, FALSE); //build truck even if not idle1636. _bStartedBuilding = buildUnit(hovertruck, _factory, factory, FALSE); //build truck even if not idle
1625. }1637. }
1626. else1638. else
1627. {1639. {
1628. _bStartedBuilding = buildUnit(constructor, _factory, factory, FALSE); //build truck even if not idle1640. _bStartedBuilding = buildUnit(constructor, _factory, factory, FALSE); //build truck even if not idle
1629. }1641. }
1630. 1642.
1631. //Update statistics if started building a truck1643. //Update statistics if started building a truck
1632. if(_bStartedBuilding)1644. if(_bStartedBuilding)
1633. {1645. {
1634. _numBuilding++;1646. _numBuilding++;
1635. _totalTrucks++;1647. _totalTrucks++;
1636. }1648. }
1637. 1649.
1638. _factory = enumStruct();1650. _factory = enumStruct();
1639. }1651. }
1640. 1652.
1641. //build cyborg engineers if needed, no building structure limit here1653. //build cyborg engineers if needed, no building structure limit here
1642. initEnumStruct(FALSE,cybFactory,me,me);1654. initEnumStruct(FALSE,cybFactory,me,me);
1643. _factory = enumStruct();1655. _factory = enumStruct();
1644. while((_factory != NULLOBJECT) and (_totalTrucks < _maxTrucks))1656. while((_factory != NULLOBJECT) and (_totalTrucks < _maxTrucks))
1645. {1657. {
1646. //Try to build a truck1658. //Try to build a truck
1647. if( skCanBuildTemplate(me,_factory, cybEngineer) ) //make sure we have researched cyb engineer1659. if( skCanBuildTemplate(me,_factory, cybEngineer) ) //make sure we have researched cyb engineer
1648. {1660. {
1649. _bStartedBuilding = buildUnit(cybEngineer, _factory, cybFactory, FALSE); //build a cyb eng even if not idle1661. _bStartedBuilding = buildUnit(cybEngineer, _factory, cybFactory, FALSE); //build a cyb eng even if not idle
1650. 1662.
1651. //Update statistics if started building a cyborg engineer1663. //Update statistics if started building a cyborg engineer
1652. if(_bStartedBuilding)1664. if(_bStartedBuilding)
1653. {1665. {
1654. _numBuilding++;1666. _numBuilding++;
1655. _totalTrucks++;1667. _totalTrucks++;
1656. }1668. }
1657. }1669. }
1658.1670.
1659. _factory = enumStruct();1671. _factory = enumStruct();
1660. }1672. }
1661. setEventTrigger(conDroids, conDroidsTr);1673. setEventTrigger(conDroids, conDroidsTr);
1662.}1674.}
1663.1675.
1664.//Build a droid1676.//Build a droid
1665.function bool buildUnit(TEMPLATE _tankTemplate, STRUCTURE _factory, STRUCTURESTAT _factoryType, bool _bIdleOnly)1677.function bool buildUnit(TEMPLATE _tankTemplate, STRUCTURE _factory, STRUCTURESTAT _factoryType, bool _bIdleOnly)
1666.{1678.{
1667. //Factory was not provided, find an factory1679. //Factory was not provided, find an factory
1668. if(_factory == NULLOBJECT)1680. if(_factory == NULLOBJECT)
1669. {1681. {
1670. _factory = findIdleStructure(_factoryType, _bIdleOnly);1682. _factory = findIdleStructure(_factoryType, _bIdleOnly);
1671. }1683. }
1672.1684.
1673. //Build if got a factory1685. //Build if got a factory
1674. if(_factory != NULLOBJECT)1686. if(_factory != NULLOBJECT)
1675. {1687. {
1676. if(structureComplete(_factory) and (getDroidCount(me) < MAX_DROIDS))1688. if(structureComplete(_factory) and (getDroidCount(me) < MAX_DROIDS))
1677. {1689. {
1678. if( !(_bIdleOnly and !structureIdle(_factory)) ) //don't build if only allowed to build whe idle and fac is not idle1690. if( !(_bIdleOnly and !structureIdle(_factory)) ) //don't build if only allowed to build whe idle and fac is not idle
1679. {1691. {
1680. buildDroid(_tankTemplate, _factory, me, 1); // build a tank1692. buildDroid(_tankTemplate, _factory, me, 1); // build a tank
1681. return TRUE; //success1693. return TRUE; //success
1682. }1694. }
1683. }1695. }
1684. }1696. }
1685.1697.
1686. return FALSE; //failed1698. return FALSE; //failed
1687.}1699.}
1688.1700.
1689.//Returns an idle structure of the provided type or NULLOBJECT if none found1701.//Returns an idle structure of the provided type or NULLOBJECT if none found
1690.function STRUCTURE findIdleStructure(STRUCTURESTAT _structType, bool _bIdleOnly)1702.function STRUCTURE findIdleStructure(STRUCTURESTAT _structType, bool _bIdleOnly)
1691.{1703.{
1692. local STRUCTURE _structure;1704. local STRUCTURE _structure;
1693.1705.
1694. initEnumStruct(FALSE,_structType,me,me);1706. initEnumStruct(FALSE,_structType,me,me);
1695. _structure = enumStruct();1707. _structure = enumStruct();
1696. while(_structure != NULLOBJECT)1708. while(_structure != NULLOBJECT)
1697. {1709. {
1698. if(structureComplete(_structure))1710. if(structureComplete(_structure))
1699. {1711. {
1700. if( !(_bIdleOnly and !structureIdle(_structure)) )1712. if( !(_bIdleOnly and !structureIdle(_structure)) )
1701. {1713. {
1702. return _structure;1714. return _structure;
1703. }1715. }
1704. }1716. }
1705.1717.
1706. _structure = enumStruct();1718. _structure = enumStruct();
1707. }1719. }
1708. 1720.
1709. return NULLOBJECT; //none found1721. return NULLOBJECT; //none found
1710.}1722.}
1711.1723.
1712./////////////////////////////////////////////////////////////////////1724./////////////////////////////////////////////////////////////////////
1713.// build repair droids.1725.// build repair droids.
1714.event repairDroids(repairDroidsTr)1726.event repairDroids(repairDroidsTr)
1715.{1727.{
1716. // if we're running low on repair droids, build some..1728. // if we're running low on repair droids, build some..
1717. if(numRepairUnits <3)1729. if(numRepairUnits <8 and (playerPower(me) > LOW_POWER))
1730. {
1731. if(random(10) <= 3)
1732. {
1733. initEnumStruct(FALSE,factory,me,me);
1734. structure= enumStruct(); // find factory.
1735. if (structure != NULLOBJECT)
1736. {
1737. count = 6;
1738. while( count >= 0 )
1739. {
1740. if ((getDroidCount(me) < MAX_DROIDS) and (skCanBuildTemplate(me, structure, repair[count])) )
1741. {
1742. buildDroid(repair[count], structure, me, 1); // build repairunit.
1743. count = -1;
1744. }
1745. count = count - 1;
1746. }
1747. }
1748. }
1749. else
1750. {
1751. initEnumStruct(FALSE,cybFactory,me,me);
1752. structure= enumStruct(); // find factory.
1753. if (structure != NULLOBJECT)
1754. {
1755. count = 6;
1756. while( count >= 0 )
1757. {
1758. if ((getDroidCount(me) < MAX_DROIDS) and (skCanBuildTemplate(me, structure, repair[count])) )
1759. {
1760. buildDroid(repair[count], structure, me, 1); // build repairunit.
1761. count = -1;
1762. }
1763. count = count - 1;
1764. }
1765. }
1766. }
1767. }
1768.}
1769.
1770./////////////////////////////////////////////////////////////////////
1771.// build sensor droids.
1772.event sensorDroids(sensorDroidsTr)
1773.{
1774. if(numSensorUnits <3 and (playerPower(me) > LOW_POWER))
1718. {1775. {
1719. initEnumStruct(FALSE,factory,me,me);1776. initEnumStruct(FALSE,factory,me,me);
1720. structure= enumStruct(); // find factory.1777. structure= enumStruct();
1721. if (structure != NULLOBJECT)1778. if(structure != NULLOBJECT)
1722. {1779. {
1723. if ((getDroidCount(me) < MAX_DROIDS) and (skCanBuildTemplate(me, structure, repairUnit)))1780. count = 7;
1781. while( count >= 0 )
1724. {1782. {
1725. buildDroid(repairUnit, structure, me, 1); // build repairunit.1783. if((getDroidCount(me) < MAX_DROIDS) and (skCanBuildTemplate(me, structure, sense[count])) )
1784. {
1785. count2 = 0;
1786. count2 = count - 1;
1787. if(random(10) <= 5 and count2 >= 0)
1788. {
1789. if(skCanBuildTemplate(me, structure, sense[count2]))
1790. {
1791. buildDroid(sense[count2], structure, me, 1);
1792. count = -1;
1793. }
1794. else
1795. {
1796. buildDroid(sense[count], structure, me, 1);
1797. count = -1;
1798. }
1799. }
1800. else
1801. {
1802. buildDroid(sense[count], structure, me, 1);
1803. count = -1;
1804. }
1805. }
1806. count = count - 1;
1726. }1807. }
1727. }1808. }
1728. }1809. }
1729.}1810.}
1730.
1731.1811.
1732./////////////////////////////////////////////////////////////////////1812./////////////////////////////////////////////////////////////////////
1733.event factoryEvent(factoryEventTr)1813.event factoryEvent(factoryEventTr)
1734.{1814.{
1735. // for each factory....1815. // for each factory....
1736. initEnumStruct(FALSE,factory,me,me);1816. initEnumStruct(FALSE,factory,me,me);
1737. structure = enumStruct(); // find factory.1817. structure = enumStruct(); // find factory.
1738. if(getDroidCount(me) < MAX_DROIDS)1818. if(getDroidCount(me) < MAX_DROIDS)
1739. {1819. {
1740. while(structure != NULLOBJECT)1820. while(structure != NULLOBJECT)
1741. {1821. {
1742. if( structureIdle(structure) )1822. if( structureIdle(structure) )
1743. {1823. {
1744. factoryBuildDroid(structure);1824. factoryBuildDroid(structure);
1745. }1825. }
1746.1826.
1747. structure = enumStruct();1827. structure = enumStruct();
1748. }1828. }
1749. }1829. }
1750.}1830.}
1751.1831.
1752.function bool needTank()1832.function bool needTank()
1753.{1833.{
1754. if(not havePowerSource())1834. if(not havePowerSource())
1755. {1835. {
1756. return FALSE;1836. return FALSE;
1757. }1837. }
1758. 1838.
1759. if((defendGroup.members < maxDefenders[curTech]) or (maxDefenders[curTech] == UNLIMITED))1839. if((defendGroup.members < maxDefenders[curTech]) or (maxDefenders[curTech] == UNLIMITED))
1760. {1840. {
1761. return TRUE;1841. return TRUE;
1762. }1842. }
1763.1843.
1764. if((scoutGroup.members < maxScouts[curTech]) or (maxScouts[curTech] == UNLIMITED))1844. if((scoutGroup.members < maxScouts[curTech]) or (maxScouts[curTech] == UNLIMITED))
1765. {1845. {
1766. return TRUE;1846. return TRUE;
1767. }1847. }
1768.1848.
1769. if((attackGroup.members < maxAttackers[curTech]) or (maxAttackers[curTech] == UNLIMITED))1849. if((attackGroup.members < maxAttackers[curTech]) or (maxAttackers[curTech] == UNLIMITED))
1770. {1850. {
1771. return TRUE;1851. return TRUE;
1772. }1852. }
1773.1853.
1774. return FALSE;1854. return FALSE;
1775.}1855.}
1776.1856.
1777.function void factoryBuildDroid(STRUCTURE _factory)1857.function void factoryBuildDroid(STRUCTURE _factory)
1778.{1858.{
1779. local int _count,_count2;1859. local int _count,_count2;
1780.1860.
1781. if(_factory == NULLOBJECT){1861. if(_factory == NULLOBJECT){
1782. dbg("factoryBuildDroid: factory is NULLOBJECT", me);1862. dbg("factoryBuildDroid: factory is NULLOBJECT", me);
1783. return;1863. return;
1784. }1864. }
1785.1865.
1786. if(not needTank())1866. if(not needTank())
1787. {1867. {
1788. //dbg("NEED NO TANKS!! " & maxDefenders[curTech], me);1868. //dbg("NEED NO TANKS!! " & maxDefenders[curTech], me);
1789. return;1869. return;
1790. }1870. }
1791.1871.
1792. if( structureIdle(_factory) )1872. if( structureIdle(_factory) and (playerPower(me) > LOW_POWER))
1793. {1873. {
1794. _count = numTemplates[curTech] - 1;1874. _count = numTemplates[curTech] - 1;
1795. _count2 = 0;1875. _count2 = 0;
1796. while( (_count2 < MAX_RANDOM_TEMPLATES) and (_count >= 0) )1876. while( (_count2 < MAX_RANDOM_TEMPLATES) and (_count >= 0) )
1797. {1877. {
1798. if( skCanBuildTemplate(me,_factory, tmpl[curTech][_count]) )1878. if( skCanBuildTemplate(me,_factory, tmpl[curTech][_count]) )
1799. {1879. {
1800. tmplChoice[_count2] = tmpl[curTech][_count];1880. tmplChoice[_count2] = tmpl[curTech][_count];
1801. _count2 = _count2 + 1;1881. _count2 = _count2 + 1;
1802. }1882. }
1803. _count = _count - 1;1883. _count = _count - 1;
1804. }1884. }
1805.1885.
1806. if(_count2 > 0)1886. if(_count2 > 0)
1807. {1887. {
1808. buildDroid(tmplChoice[random(_count2)],_factory,me,1);1888. buildDroid(tmplChoice[random(_count2)],_factory,me,1);
1809. }1889. }
1810. }1890. }
1811. else1891. else
1812. {1892. {
1813. dbg("factoryBuildDroid: factory is busy", me);1893. dbg("factoryBuildDroid: factory is busy", me);
1814. }1894. }
1815.}1895.}
1816.1896.
1817./////////////////////////////////////////////////////////////////////1897./////////////////////////////////////////////////////////////////////
1818.// put cyborg factories to work1898.// put cyborg factories to work
1819.event cyborgFactoryEvent(cyborgFactoryEventTr)1899.event cyborgFactoryEvent(cyborgFactoryEventTr)
1820.{1900.{
1821.1901.
1822. if(not ((defendGroup.members < maxCyborgs[curTech]) or (maxCyborgs[curTech] == UNLIMITED)))1902. if(not ((defendGroup.members < maxCyborgs[curTech]) or (maxCyborgs[curTech] == UNLIMITED)))
1823. {1903. {
1824. exit; //we need no cyborgs1904. exit; //we need no cyborgs
1825. }1905. }
1826.1906.
1827. initEnumStruct(FALSE,cybFactory,me,me);1907. initEnumStruct(FALSE,cybFactory,me,me);
1828. structure= enumStruct(); // find factory.1908. structure= enumStruct(); // find factory.
1829.1909.
1830. while(structure != NULLOBJECT)1910. while(structure != NULLOBJECT)
1831. {1911. {
1832. if( structureIdle(structure) == TRUE)1912. if( structureIdle(structure) == TRUE)
1833. {1913. {
1834. cybFactorBuildCyborg(structure);1914. cybFactorBuildCyborg(structure);
1835. }1915. }
1836. structure= enumStruct(); // find factory.1916. structure= enumStruct(); // find factory.
1837. }1917. }
1838.}1918.}
1839.1919.
1840.function void cybFactorBuildCyborg(STRUCTURE _factory)1920.function void cybFactorBuildCyborg(STRUCTURE _factory)
1841.{1921.{
1842. if(_factory == NULLOBJECT){1922. if(_factory == NULLOBJECT){
1843. dbg("cybFactorBuildCyborg: factory is NULLOBJECT", me);1923. dbg("cybFactorBuildCyborg: factory is NULLOBJECT", me);
1844. return;1924. return;
1845. }1925. }
1846.1926.
1847. if( structureIdle(_factory) )1927. if( structureIdle(_factory) and (playerPower(me) > LOW_POWER))
1848. {1928. {
1849. if( (defendGroup.members < maxCyborgs[curTech]) and (getDroidCount(me) < MAX_DROIDS) )1929. if( (defendGroup.members < maxCyborgs[curTech]) and (getDroidCount(me) < MAX_DROIDS) )
1850. {1930. {
1851. if(random(5) == 1)1931. count = 20;
1932. count2 = 0;
1933. while( count >= 0 )
1852. {1934. {
1853. buildDroid(cybMechanic,_factory,me,1);1935. if( skCanBuildTemplate(me,_factory, superCyb[count]) )
1936. {
1937. tmplChoice[count2] = superCyb[count];
1938. count2 = count2 + 1;
1939. }
1940. count = count - 1;
1854. }1941. }
1855. else1942. if(count2 > 0)
1856. {1943. {
1857. count = 3;1944. buildDroid(tmplChoice[random(count2)],_factory,me,1);
1945. }
1946. else //try light cyborgs
1947. {
1948. count = numLightCyborgs - 1;
1858. count2 = 0;1949. count2 = 0;
1859. while( count >= 0 )1950. while( (count >= 0) and (count2 < 2) )
1860. {1951. {
1861. if( skCanBuildTemplate(me,_factory, superCyb[count]) )1952. if( skCanBuildTemplate(me,_factory, cybTempl[count]) )
1862. {1953. {
1863. tmplChoice[count2] = superCyb[count];1954. tmplChoice[count2] = cybTempl[count];
1864. count2 = count2 + 1;1955. count2++;
1865. }1956. }
1866. count = count - 1;1957. count--;
1867. }1958. }
1868.
1869. if(count2 > 0)1959. if(count2 > 0)
1870. {1960. {
1871. buildDroid(tmplChoice[random(count2)],_factory,me,1);1961. buildDroid(tmplChoice[random(count2)], _factory, me, 1);
1872. }
1873. else //try light cyborgs
1874. {
1875. count = numLightCyborgs - 1;
1876. count2 = 0;
1877. while( (count >= 0) and (count2 < 2) )
1878. {
1879. if( skCanBuildTemplate(me,_factory, cybTempl[count]) )
1880. {
1881. tmplChoice[count2] = cybTempl[count];
1882. count2++;
1883. }
1884. count--;
1885. }
1886. if(count2 > 0)
1887. {
1888. buildDroid(tmplChoice[random(count2)], _factory, me, 1);
1889. }
1890. }1962. }
1891. }1963. }
1892.
1893. }1964. }
1894. }1965. }
1895.}1966.}
1896.1967.
1897./////////////////////////////////////////////////////////////////////1968./////////////////////////////////////////////////////////////////////
1898./////////////////////////////////////////////////////////////////////1969./////////////////////////////////////////////////////////////////////
1899.// scouting rules1970.// scouting rules
1900.1971.
1901.// scout an area1972.// scout an area
1902.event chooseScoutArea(chooseScoutAreaTr)1973.event chooseScoutArea(chooseScoutAreaTr)
1903.{1974.{
1904. scoutX = scoutTLX + random(scoutW);1975. scoutX = scoutTLX + random(scoutW);
1905. scoutY = scoutTLY + random(scoutH);1976. scoutY = scoutTLY + random(scoutH);
1906.}1977.}
1907.1978.
1908./////////////////////////////////////////////////////////////////////1979./////////////////////////////////////////////////////////////////////
1909.// visit new places1980.// visit new places
1910.1981.
1911.event expandScoutArea(expandScoutAreaTr)1982.event expandScoutArea(expandScoutAreaTr)
1912.{1983.{
1913.1984.
1914. //expand the scouting area slightly1985. //expand the scouting area slightly
1915. scoutTLX = scoutTLX - ((mapWidth*128)/ tileExpand);1986. scoutTLX = scoutTLX - ((mapWidth*128)/ tileExpand);
1916. scoutTLY = scoutTLY - ((mapHeight*128)/ tileExpand);1987. scoutTLY = scoutTLY - ((mapHeight*128)/ tileExpand);
1917. scoutW = scoutW + (2*((mapWidth*128)/ tileExpand));1988. scoutW = scoutW + (2*((mapWidth*128)/ tileExpand));
1918. scoutH = scoutH + (2*((mapHeight*128)/ tileExpand));1989. scoutH = scoutH + (2*((mapHeight*128)/ tileExpand));
1919.1990.
1920. // check & restrain.1991. // check & restrain.
1921. if(scoutTLX <1)1992. if(scoutTLX <1)
1922. {1993. {
1923. scoutTLX = 1;1994. scoutTLX = 1;
1924. }1995. }
1925. if(scoutTLY <1)1996. if(scoutTLY <1)
1926. {1997. {
1927. scoutTLY = 1;1998. scoutTLY = 1;
1928. }1999. }
1929.2000.
1930. if(scoutTLX >(mapWidth*128))2001. if(scoutTLX >(mapWidth*128))
1931. {2002. {
1932. scoutTLX = (mapWidth*128) - 128;2003. scoutTLX = (mapWidth*128) - 128;
1933. }2004. }
1934. if(scoutTLY >(mapHeight*128))2005. if(scoutTLY >(mapHeight*128))
1935. {2006. {
1936. scoutTLY = (128*mapHeight) - 128;2007. scoutTLY = (128*mapHeight) - 128;
1937. }2008. }
1938.2009.
1939. if( (scoutTLX + scoutW) > (128 * mapWidth) )2010. if( (scoutTLX + scoutW) > (128 * mapWidth) )
1940. {2011. {
1941. scoutW = ( (128 * mapWidth) - scoutTLX) - 128;2012. scoutW = ( (128 * mapWidth) - scoutTLX) - 128;
1942. }2013. }
1943. if( (scoutTLY + scoutH) > (128 *mapHeight) )2014. if( (scoutTLY + scoutH) > (128 *mapHeight) )
1944. {2015. {
1945. scoutH = ( (128*mapHeight) - scoutTLY) - 128;2016. scoutH = ( (128*mapHeight) - scoutTLY) - 128;
1946. }2017. }
1947.}2018.}
1948.2019.
1949./////////////////////////////////////////////////////////////////////2020./////////////////////////////////////////////////////////////////////
1950.// order scouts2021.// order scouts
1951.2022.
1952.event scoutMain(scoutMainTr)2023.event scoutMain(scoutMainTr)
1953.{2024.{
1954. // find any new scouts2025. // find any new scouts
1955. // if scouts aren't busy, send them to a new spot.2026. // if scouts aren't busy, send them to a new spot.
1956. if( idleGroup(scoutGroup) >= (scoutGroup.members /2) )2027. if( idleGroup(scoutGroup) >= (scoutGroup.members /2) )
1957. {2028. {
1958. orderGroupLoc(scoutGroup, DORDER_MOVE,scoutX,scoutY);2029. orderGroupLoc(scoutGroup, DORDER_MOVE,scoutX,scoutY);
1959. }2030. }
1960.}2031.}
1961.2032.
1962./////////////////////////////////////////////////////////////////////2033./////////////////////////////////////////////////////////////////////
1963.// process new visibility reports2034.// process new visibility reports
1964.event newObjectReport(newObjectReportTr)2035.event newObjectReport(newObjectReportTr)
1965.{2036.{
1966. if(!friendlyPlayer(baseobj.player))2037. if(!friendlyPlayer(baseobj.player))
1967. {2038. {
1968. if(targetTypeValue(baseobj) > targetTypeValue(attackObj))2039. if(targetTypeValue(baseobj) > targetTypeValue(attackObj))
1969. {2040. {
1970. attackObj = baseobj;// got a new unseen target from a scout.2041. attackObj = baseobj;// got a new unseen target from a scout.
1971.2042.
1972. if( attackObj.type == OBJ_STRUCTURE)2043. if( attackObj.type == OBJ_STRUCTURE)
1973. {2044. {
1974. if(not allianceExistsBetween(attackObj.player,me)) // an enemy2045. if(not allianceExistsBetween(attackObj.player,me)) // an enemy
1975. {2046. {
1976. structure = objToStructure(attackObj);2047. structure = objToStructure(attackObj);
1977. if(structure.stat == factory)2048. if(structure.stat == factory)
1978. {2049. {
1979. allOutAttack = attackObj;2050. allOutAttack = attackObj;
1980. }2051. }
1981. }2052. }
1982. }2053. }
1983. }2054. }
1984. }2055. }
1985.}2056.}
1986.2057.
1987.function int targetTypeValue(BASEOBJ _target)2058.function int targetTypeValue(BASEOBJ _target)
1988.{2059.{
1989. local STRUCTURE _strTarget;2060. local STRUCTURE _strTarget;
1990.2061.
1991. if(_target == NULLOBJECT){2062. if(_target == NULLOBJECT){
1992. return NO_