~ubuntu-branches/ubuntu/lucid/warzone2100/lucid

« back to all changes in this revision

Viewing changes to data/mods/multiplay/ntw/multiplay/skirmish/player5.slo

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Egger, Paul Wise, Christoph Egger
  • Date: 2009-06-29 17:12:52 UTC
  • mfrom: (1.1.11 upstream) (2.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090629171252-5ddnlfg3zfchrega
Tags: 2.2.1+dfsg1-1
[ Paul Wise ]
* New upstream release (Closes: #534962)
* Adjust the flex build-depends to take account of the conflict
  with all the versions of flex 2.5.34 (LP: #372872)
* Make the -music Recommends more strict, 2.1 music doesn't work
  with 2.2.
* Upstream moved the downloads to sourceforge, update the watch file
* Bump Standards-Version, no changes needed
* Drop use of dh_desktop since it no longer does anything
* Recommend the new warzone2100-video package, version 2.2 or similar
* Mention the warzone2100 crash reports in the -dbg package description

[ Christoph Egger ]
* Replace CC-2.0 graphic from cybersphinx, create a new tarball
* Add myself to uploaders

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//------------------------------------------------------
 
2
//      Public variables
 
3
//------------------------------------------------------
 
4
public  STRUCTURESTAT           legoSt[12],derrick,powGen,factory,resLab,powModule,facModule,resModule,vtolFactory,wall,
 
5
                                repairFacility,extraStructs[5],defenses[18],structChoice[5],baseStructs[13],vtolPad,vtolDefStruct[5],sens[3],arty[5],attackStructs[5],cybFactory;
 
6
public  FEATURESTAT             oilRes;
 
7
public  INT                     numLego,player,numTemplates,numExtraStructs,numDefenses,numBaseStructs,numSVtolTemplates,numTVtolTemplates,sPref[6],numVtolDefStr,numAttackStructs;
 
8
public  TEMPLATE                tmpl[2][12],constructor,sVtols[2][1],tVtols[2][3],tmplRep[2],cybMechanic,cybTmpl[11],Transport;
 
9
public  WEAPON                  sVtolWeapon[3],tVtolWeapon[3];
 
10
public  TEXTSTRING              ai_ally_msg[5],DebugMsg[15];
 
11
public  PROPULSION              cyborgProp,vtolProp;    
 
12
 
 
13
//------------------------------------------------------
 
14
//      Private variables
 
15
//------------------------------------------------------
 
16
private GROUP                   buildGroup,tempGroup,sendOutpostGr,sendAttackGr,collectSendGr,attackGroup,scoutGroup[3],oilGr,sVtolGr,tVtolGr,defendGr,repGr,repairedGroup,transportGr,dropGr;
 
17
private INT                     count,count2,result,result2,result3,result4,temp,buildX,buildY,baseX,baseY,tempX,tempY,maxy,maxx,miny,minx,outpostDist;
 
18
private INT                     minAttackH,maxAttackH,maxOilGr,scoutX[2],scoutY[2],stuckX,stuckY,stuckTimes,maxTVtols,maxSVtols,maxDefenders;
 
19
private INT                     oilX,oilY;
 
20
private DROID                   droid,tempDroid,outpostDroid,repDefendDroid[2],toRepDefendDroid[2],transportDroid,transportDroid2;
 
21
private INT                     numRetreats,NumOldDefenders,helpAllyPlayer,helpAllyPlayerX,helpAllyPlayerY;
 
22
private BOOL                    boolResult,boolResult2,haveOutpost,powerSaving,defendingBase;
 
23
private FEATURE                 feature,feature2;
 
24
private TEMPLATE                tmplChoice[5];
 
25
private STRUCTURE               structure,structure2;   //attackDerrick;
 
26
 
 
27
private BOOL                    actPlayer[8],allyPlayer[8],debugMode,dropEnabled,alreadyAttacked,bigMap;
 
28
private BASEOBJ                 baseobj,attackObject,defendObject,tVtolObject,sVtolObject;
 
29
 
 
30
private INT                     numEnemies,Enemies[8],EnemyX[8],EnemyY[8],LZ_X,LZ_Y,transportZ,cybTemplate;
 
31
private INT                     allianceTime[8];
 
32
 
 
33
//------------------------------------------------------
 
34
//      Static private variables
 
35
//------------------------------------------------------
 
36
private INT                     mainPhase,curLegoStr,TemplDepth,maxTrucks,curEnemy,curEnemyX,curEnemyY,dropPhase,
 
37
                                attackPhase,maxScouts,extraStruct,curEnEdgeX,curEnEdgeY,KeepDist,numRushers,maxRepairing,maxRetreats,muchoPower;
 
38
 
 
39
//===============================================================================================
 
40
//
 
41
//                                              Triggers
 
42
//
 
43
//===============================================================================================
 
44
 
 
45
//------------------------------------------------------
 
46
//      Lego
 
47
//------------------------------------------------------
 
48
trigger StartGameTr                     (wait, 10);
 
49
trigger LegoBuildTr                     (every, 10);
 
50
 
 
51
//------------------------------------------------------
 
52
//      Rush
 
53
//------------------------------------------------------
 
54
trigger RushTr                          (every, 30);
 
55
trigger RushControlTr                   (every, 80);    //Was 80
 
56
 
 
57
//------------------------------------------------------
 
58
//      Rush preparations
 
59
//------------------------------------------------------
 
60
trigger BuildAttackForceTr              (every, 80);
 
61
trigger buildCyborgsTr                  (every, 100);
 
62
trigger buildVtolsTr                    (every, 100);
 
63
trigger doResearchTr                    (every, 20);    
 
64
trigger buildDerricksTr                 (every, 80);    //was 60
 
65
trigger sendScoutsTr                    (every, 200);
 
66
trigger expandBaseTr                    (every, 150);   //was 150
 
67
trigger buildDefensesTr                 (every, 80);
 
68
trigger buildVtolPadsTr                 (every, 80);
 
69
trigger basedetailsTr                   (every, 50);
 
70
trigger oilDefensesTr                   (every, 100);
 
71
 
 
72
//------------------------------------------------------
 
73
//      Other
 
74
//------------------------------------------------------
 
75
trigger droidDestroyedTr                (CALL_DROID_DESTROYED,  player, ref droid);
 
76
trigger nowTr                           (wait, 1);
 
77
trigger keepTrackTr                     (every, 60);
 
78
trigger chooseEnemyTr                   (every, 70);
 
79
trigger LegoTrucksTr                    (every, 10);
 
80
trigger buildPowerGeneratorsTr          (every, 60);
 
81
trigger droidBuiltTr                    (CALL_NEWDROID,player, ref droid,ref structure);
 
82
trigger difficultyModTr                 (every, 600);
 
83
trigger upgradeStructuresTr             (every, 50);
 
84
trigger moveIfAttackedTr                (CALL_DROID_ATTACKED, player, ref droid, ref baseobj);
 
85
trigger BuildOutpostTr                  (every, 100);
 
86
trigger updateDetailsTr                 (every, 40);
 
87
trigger savePowerTr                     (every, 20);
 
88
trigger destroyOilTr                    (every, 60);
 
89
trigger stuckTr                         (every, 80);
 
90
trigger vtolAttackTr                    (every, 50);
 
91
trigger vtolDefendTr                    (CALL_STRUCT_ATTACKED, player, ref structure, ref baseobj);
 
92
trigger formAllianceEventTr             (every, 170);
 
93
trigger humanAllianceTr                 (CALL_ALLIANCEOFFER,ref count, ref count2);
 
94
trigger FinishStructuresTr              (every, 120);
 
95
trigger repairStuffTr                   (every, 130);
 
96
trigger cyborgDropTr                    (every, 999);
 
97
trigger manageDropAttacksTr             (every, 999);
 
98
trigger WatchDefendBaseTr               (every, 160);   //was 200
 
99
trigger WatchHelpAllyTr                 (every, 200);
 
100
trigger agressiveDefenceTr              (every, 80);
 
101
trigger additVTOLDefensesTr             (every, 180);
 
102
trigger PowerBoostTr            (every, 50);    //Same as research timer
 
103
 
 
104
//===============================================================================================
 
105
//
 
106
//                                      Events
 
107
//
 
108
//===============================================================================================
 
109
event endPhaseOne;
 
110
event initializeRushPrep;
 
111
event BuildAttackForce;
 
112
event doResearch;
 
113
event buildDerricks;
 
114
event chooseEnemy;
 
115
event RushControl;
 
116
event sendScouts;
 
117
event expandBase;
 
118
event buildDefenses;
 
119
event basedetails;
 
120
event oilDefenses;
 
121
event LegoTrucks;
 
122
event stopAttack;
 
123
event BuildOutpost;
 
124
event updateDetails;
 
125
event savePower;
 
126
event destroyOil;
 
127
event buildVtolPads;
 
128
event StartGame;
 
129
event FinishStructures;
 
130
event WatchDefendBase;
 
131
event WatchHelpAlly;
 
132
event agressiveDefence;
 
133
event additVTOLDefenses;
 
134
event PowerBoost;
 
135
 
 
136
 
 
137
/*%? Help1      =       "This will only have an effect untill the early-mid - mid game.\n
 
138
After gaining the most vital technology and being low on power, 
 
139
GK will manage research speed by itself. 
 
140
You can only additionaly limit the speed, but you can't make GK do more research at that time." */
 
141
 
 
142
/*%? Help2      =       "Hint: play as AI ..." */
 
143
 
 
144
 
 
145
//===============================================================================================
 
146
//
 
147
//                                      [LEGO PHASE]
 
148
//
 
149
//===============================================================================================
 
150
 
 
151
//------------------------------------------------------
 
152
//      Initialize
 
153
//------------------------------------------------------
 
154
event StartGame(StartGameTr)
 
155
{
 
156
 
 
157
        //Initialize variables
 
158
        //--------------------
 
159
        mainPhase = 0;
 
160
        curLegoStr = 0;
 
161
        maxTrucks = 5;
 
162
 
 
163
        temp = random(16);
 
164
        if(temp > 12)
 
165
        {
 
166
                numRushers = 8;         //Early rush
 
167
        }
 
168
        else if((temp >= 5) and (temp <= 12))
 
169
        {
 
170
                numRushers = 17;        //Mass attack
 
171
        }
 
172
        else
 
173
        {
 
174
                numRushers = 12;        //Normal attack
 
175
        }
 
176
 
 
177
        curEnemy = -1;
 
178
        curEnemyX = -1;
 
179
        curEnemyY = -1;
 
180
        attackPhase = 0;
 
181
        TemplDepth = 1;                         //From how many different templates to choose a template randomly, depends on res phase
 
182
        maxScouts = 1;                          //Enable atleast 1 scout at startup, otherwise might take too long (if 20 attackers)
 
183
        extraStruct = 0;
 
184
        curEnEdgeX = -1;
 
185
 
 
186
        //Distance to keep of the enemy base when sending attackGr for regrouping
 
187
        KeepDist = (19 * 128);                  /*%!    ID="OutpostDistance",
 
188
                                                MainDesc="Distance from GK outpost to enemy base",
 
189
                                                type="asn",             //Assign
 
190
                                                val="19",
 
191
                                                ArgDesc="19 Tiles (Default)",
 
192
                                                val="5",
 
193
                                                ArgDesc="5 Tiles",
 
194
                                                val="10",
 
195
                                                ArgDesc="10 Tiles",
 
196
                                                val="15",
 
197
                                                ArgDesc="15 Tiles",
 
198
                                                val="25",
 
199
                                                ArgDesc="25 Tiles",
 
200
                                                val="30",
 
201
                                                ArgDesc="30 Tiles"      */
 
202
 
 
203
 
 
204
 
 
205
        minAttackH = 47;                        //Min attack health. Retreat if < minAttackH
 
206
        maxAttackH = 90;                        //Attack only if health > maxAttackH, must be bigger than minAttackH
 
207
        //numRepairing = 0;                     //How many attackers are repairing at the moment
 
208
        haveOutpost = FALSE;                    //Outpost to retreat to and where to repair damadged units
 
209
        powerSaving = FALSE;                    //If we are in power saving mode
 
210
        defendingBase = FALSE;                  //Attackers are currently defending the base
 
211
        maxOilGr = 4;                           //Number of droids in the oilGr
 
212
        //attackOilX = -1;                      //Coordinates of enemy derrick
 
213
        //attackOilY = -1;                      //Coordinates of enemy derrick
 
214
        //attackDerrick = NULLOBJECT;           //No enemy derricks to attack yet
 
215
        maxTVtols = 8;                          //Max number of antitank VTOLs
 
216
        maxSVtols = 10;                         //Max number of antistructure  VTOLs
 
217
        maxDefenders = 5;                       //Max number of defenders
 
218
        outpostDist = 0;                        //Remember the distance between the enemy base and the outpost
 
219
        maxRetreats = 6;                        //Max time to retreat before alloutattack
 
220
        muchoPower = 3500;                      //If this amount of power is available, then start building expensive templates
 
221
        transportDroid = NULLOBJECT;            //Cyborg transport
 
222
        dropPhase = 0;                          //Phase of the vurrent cyborg drop
 
223
        transportZ = 0;                         //Height of the transport when landing
 
224
        cybTemplate = 0;                        //Cyborg template to use for drops
 
225
        dropEnabled = FALSE;                    //Wheather to drop or not to drop
 
226
        alreadyAttacked = FALSE;                //Wheather we have already attacked an enemy base atleast 1 time
 
227
        //toRepDefendDroid = NULLOBJECT;                //Defender, which is about to be repaired by the repair unit
 
228
        NumOldDefenders = 0;                    //How many defenders there were, before base defence was turned on (revert to this number)
 
229
        
 
230
        helpAllyPlayer = -1;                    //No ally in danger right now
 
231
        helpAllyPlayerX = -1;                   //Coords of where to send help for the ally
 
232
        helpAllyPlayerY = -1;                   //Coords of where to send help for the ally
 
233
 
 
234
        bigMap = FALSE;
 
235
        if((mapHeight > 150) and (mapWidth > 150))
 
236
        {
 
237
                bigMap = TRUE;
 
238
        }
 
239
 
 
240
        oilX = 0;
 
241
        oilY = 0;
 
242
 
 
243
 
 
244
        temp = (9 * 128);
 
245
 
 
246
        scoutX[0] = temp;                               //Bottom left
 
247
        scoutY[0] = (mapHeight * 128) - temp;
 
248
        scoutX[1] = (mapWidth * 128) - temp;    //Top right
 
249
        scoutY[1] = temp;
 
250
 
 
251
        //Prepair features for future use
 
252
        //-------------------------------
 
253
        initGetFeature(oilRes,player,player);
 
254
 
 
255
        //Temp base
 
256
        //---------
 
257
        baseX = (128*mapWidth)/2;
 
258
        baseY = (128*mapHeight)/2;
 
259
 
 
260
        //Add all droids to a group and sort out constructors
 
261
        //---------------------------------------------------
 
262
        groupAddArea(tempGroup, player, 0, 0, (mapWidth*128), (mapHeight*128));
 
263
        initIterateGroup(tempGroup);
 
264
        droid = iterateGroup(tempGroup);
 
265
        while(droid != NULLOBJECT)
 
266
        {
 
267
                if(droid.droidType == DROID_CONSTRUCT)  //If a constructor
 
268
                {
 
269
                        //forceDamageObject(droid, 50);
 
270
 
 
271
                        baseX = droid.x;        //Base coordinates
 
272
                        baseY = droid.y;
 
273
 
 
274
                        droidLeaveGroup(droid);
 
275
                        groupAddDroid(buildGroup,droid);
 
276
                }
 
277
                droid = iterateGroup(tempGroup);
 
278
        }
 
279
 
 
280
 
 
281
        //Send one truck to build factory
 
282
        //-------------------------------
 
283
        boolResult = FALSE;
 
284
        buildX = baseX;
 
285
        buildY = baseY;
 
286
        initIterateGroup(buildGroup);
 
287
        droid = iterateGroup(buildGroup);
 
288
        while((boolResult == FALSE) and (droid != NULLOBJECT))
 
289
        {
 
290
                if(droid.order == DORDER_NONE)
 
291
                {
 
292
                        boolResult2 = pickStructLocation(factory, ref buildX, ref buildY,player);
 
293
                        if(boolResult2 == TRUE)
 
294
                        {
 
295
                                orderDroidStatsLoc(droid, DORDER_BUILD, factory, buildX,buildY);
 
296
                                boolResult = TRUE;
 
297
                        }
 
298
                }
 
299
                droid = iterateGroup(buildGroup);
 
300
        }
 
301
 
 
302
        //transportDroid = addDroid(Transport, baseX, baseY, player);
 
303
}
 
304
 
 
305
 
 
306
//------------------------------------------------------
 
307
//      Build all necessary structures
 
308
//------------------------------------------------------
 
309
event LegoBuild(LegoBuildTr)
 
310
{
 
311
        //DERRICKS
 
312
        //--------
 
313
        initGetFeature(oilRes,player,player);
 
314
        feature = getFeature(player);
 
315
        if(feature != NULLOBJECT)
 
316
        {
 
317
                buildX = feature.x;
 
318
                buildY = feature.y;
 
319
 
 
320
                //If no no trucks already trying to build the same derrick
 
321
                initIterateGroup(buildGroup);
 
322
                droid = iterateGroup(buildGroup);
 
323
                count = 0;
 
324
                while((droid != NULLOBJECT) and (count == 0))
 
325
                {
 
326
                        if((droid.orderx == buildX) and (droid.ordery == buildY))
 
327
                        {
 
328
                                count = count + 1;      //Count trucks
 
329
                        }
 
330
                        droid = iterateGroup(buildGroup);
 
331
                }
 
332
 
 
333
                if(count == 0)          //Send only 1 truck to each derrick
 
334
                {
 
335
                        initIterateGroup(buildGroup);
 
336
                        droid = iterateGroup(buildGroup);
 
337
                        boolResult = FALSE;
 
338
                        while((boolResult == FALSE) and (droid != NULLOBJECT))
 
339
                        {
 
340
                                if(droid.order == DORDER_NONE)
 
341
                                {
 
342
                                        orderDroidStatsLoc(droid, DORDER_BUILD,derrick, buildX,buildY);
 
343
                                        boolResult = TRUE;
 
344
                                }
 
345
                                droid = iterateGroup(buildGroup);
 
346
                        }
 
347
                }
 
348
        }
 
349
 
 
350
        //Upgrade factories if it is T3
 
351
        //-----------------------------
 
352
        if(isStructureAvailable(facModule,player))              //If Factory module is already available
 
353
        {
 
354
                initEnumStruct(FALSE,factory,player,player);                    
 
355
                structure= enumStruct();
 
356
                while(structure != NULLOBJECT)
 
357
                {
 
358
                        //if((skGetFactoryCapacity(structure) < 2) and (skCanBuildTemplate(player,structure, tmpl[0][8])))              //No fac module and T3 (if we have Trck Python HC)              
 
359
                        if(skGetFactoryCapacity(structure) < 2)
 
360
                        {
 
361
                                initIterateGroup(buildGroup);
 
362
                                droid = iterateGroup(buildGroup);
 
363
                                //boolResult = TRUE;                    //Send only 1 truck
 
364
                                //while((droid != NULLOBJECT) and (boolResult))
 
365
                                while(droid != NULLOBJECT)
 
366
                                {
 
367
                                        if(droid.order == DORDER_NONE)
 
368
                                        {
 
369
                                                //boolResult = FALSE;
 
370
                                                orderDroidStatsLoc(droid, DORDER_BUILD, facModule, structure.x,structure.y);
 
371
                                        }
 
372
                                        droid = iterateGroup(buildGroup);
 
373
                                }
 
374
                        }
 
375
                        structure = enumStruct();
 
376
                }
 
377
        }
 
378
 
 
379
        //STRUCTURES
 
380
        //----------
 
381
        if(curLegoStr < numLego)
 
382
        {
 
383
                buildX = baseX;
 
384
                buildY = baseY;
 
385
                droid = NULLOBJECT;
 
386
                boolResult = FALSE;
 
387
 
 
388
                initIterateGroup(buildGroup);
 
389
                droid = iterateGroup(buildGroup);
 
390
                while((droid != NULLOBJECT) and (boolResult == FALSE))
 
391
                {
 
392
                        if(droid.order == DORDER_NONE)
 
393
                        {
 
394
                                boolResult2 = pickStructLocation(legoSt[curLegoStr], ref buildX, ref buildY,player);
 
395
                                if(boolResult2 == TRUE)
 
396
                                {
 
397
                                        tempDroid = droid;
 
398
                                        boolResult = TRUE;
 
399
                                }
 
400
                        }
 
401
                        droid = iterateGroup(buildGroup);       //Next droid
 
402
                }
 
403
 
 
404
                //Find out if a truck is already building on the spot where another truck might try to build and will fail
 
405
                if(boolResult)
 
406
                {
 
407
                        boolResult = TRUE;
 
408
                        initIterateGroup(buildGroup);
 
409
                        droid = iterateGroup(buildGroup);
 
410
                        while((droid != NULLOBJECT) and (boolResult == TRUE))
 
411
                        {
 
412
                                if(droid != tempDroid)
 
413
                                {
 
414
                                        if(droid.order == DORDER_BUILD)
 
415
                                        {
 
416
                                                if((buildX == droid.orderx) and (buildY == droid.ordery))
 
417
                                                {
 
418
                                                        boolResult = FALSE;
 
419
                                                }
 
420
                                        }
 
421
                                }
 
422
                                droid = iterateGroup(buildGroup);
 
423
                        }
 
424
                }
 
425
 
 
426
                //Build
 
427
                if(boolResult)
 
428
                {
 
429
                        orderDroidStatsLoc(tempDroid, DORDER_BUILD,legoSt[curLegoStr], buildX,buildY);
 
430
                        curLegoStr = curLegoStr + 1;
 
431
                }
 
432
        }
 
433
 
 
434
        //End Lego phase, start rush preparations
 
435
        //---------------------------------------
 
436
        if(mainPhase == 0)      //If not already activated
 
437
        {
 
438
                if(curLegoStr == (numLego - 1))         // (numLego - HQ)
 
439
                {
 
440
                        setEventTrigger(endPhaseOne,nowTr);
 
441
                }
 
442
        }
 
443
 
 
444
        //Now that HQ is built we can deactivate it
 
445
        //-----------------------------------------
 
446
        if(curLegoStr == numLego)
 
447
        {
 
448
                setEventTrigger(LegoBuild, inactive);
 
449
        }
 
450
}
 
451
 
 
452
 
 
453
//------------------------------------------------------
 
454
//      End Lego phase, start rush preparations
 
455
//------------------------------------------------------
 
456
event endPhaseOne(inactive)
 
457
{
 
458
        //Start rush preparation phase
 
459
        //----------------------------
 
460
        setEventTrigger(doResearch,doResearchTr);
 
461
        setEventTrigger(buildDerricks,buildDerricksTr);
 
462
        setEventTrigger(initializeRushPrep,nowTr);
 
463
        setEventTrigger(RushControl,RushControlTr);
 
464
        //setEventTrigger(sendScouts,sendScoutsTr);
 
465
        setEventTrigger(expandBase,expandBaseTr);
 
466
        setEventTrigger(buildDefenses,buildDefensesTr);
 
467
        setEventTrigger(oilDefenses,oilDefensesTr);
 
468
        //setEventTrigger(updateDetails,updateDetailsTr);
 
469
        setEventTrigger(savePower,savePowerTr);
 
470
        setEventTrigger(destroyOil,destroyOilTr);
 
471
        setEventTrigger(buildVtolPads,buildVtolPadsTr);
 
472
        setEventTrigger(FinishStructures,FinishStructuresTr);
 
473
 
 
474
        setEventTrigger(LegoTrucks,inactive);
 
475
        setEventTrigger(endPhaseOne, inactive);
 
476
        
 
477
}
 
478
 
 
479
//=============================================================================================
 
480
//                                      [RUSH]
 
481
//=============================================================================================
 
482
 
 
483
//------------------------------------------------------
 
484
//      Send units to the outpost, near the enemy base
 
485
//------------------------------------------------------
 
486
event Rush(RushTr)
 
487
{
 
488
        if((sendOutpostGr.members + attackGroup.members + collectSendGr.members) > numRushers)
 
489
        {
 
490
                //setFogColour(random(200) + 50, 1, 1);
 
491
                if(curEnemy != -1)      //We have an enemy and not already on our way
 
492
                {
 
493
                        //setFogColour(1, random(200) + 50, 1);
 
494
                        if((curEnEdgeX > 0) and (attackPhase == 0))
 
495
                        {
 
496
                                maxTrucks = 12;                                                 //Maximum number of the trucks to be built in this phase
 
497
 
 
498
                                if(bigMap)
 
499
                                {
 
500
                                        maxScouts = 3;
 
501
                                }
 
502
                                else
 
503
                                {
 
504
                                        maxScouts = 2;
 
505
                                }
 
506
                                groupAddGroup(sendOutpostGr, collectSendGr);            //From collectSendGr to sendOutpostGr
 
507
                                groupAddGroup(sendOutpostGr, attackGroup);              //From attackGroup to sendOutpostGr
 
508
                                setGroupSecondary(sendOutpostGr, DSO_HALTTYPE, DSS_HALT_GUARD); //Don't start attacking the base
 
509
                                orderGroupLoc(sendOutpostGr, DORDER_MOVE, curEnEdgeX, curEnEdgeY);
 
510
                                attackPhase = 1;                                                //On our way
 
511
 
 
512
                                alreadyAttacked = TRUE;
 
513
 
 
514
                                //If we were making an early rush then make sure we build more units before we attack again (otherwise will be slowly increased by 1)
 
515
                                //if(numRushers < 10)
 
516
                                //{
 
517
                                //      numRushers = 10;
 
518
                                //}
 
519
 
 
520
                                setEventTrigger(BuildOutpost,BuildOutpostTr);           //Start building outpost
 
521
                                setEventTrigger(Rush,inactive);
 
522
                        }
 
523
                }
 
524
        }
 
525
}
 
526
 
 
527
//------------------------------------------------------
 
528
//      Cancel current attack
 
529
//------------------------------------------------------
 
530
event stopAttack(inactive)
 
531
{
 
532
        showConsoleText(DebugMsg[4], player);           //Attack stopped
 
533
 
 
534
        attackPhase = 0;
 
535
        curEnemy = -1;
 
536
        curEnEdgeX = -1;
 
537
        curEnEdgeY = -1;
 
538
        curEnemyX = -1;
 
539
        curEnemyY = -1;
 
540
        numRetreats = 0;
 
541
 
 
542
        groupAddGroup(sendOutpostGr, attackGroup);      //Add attackGroup to sendOutpostGr
 
543
        groupAddGroup(sendOutpostGr, collectSendGr);    //Add collectSendGr to sendOutpostGr
 
544
        groupAddGroup(sendOutpostGr, repairedGroup);    //Add repairedGroup to sendOutpostGr
 
545
        groupAddGroup(repGr, repairedGroup);            //Add repGr to sendOutpostGr
 
546
 
 
547
        //setGroupSecondary(attackGroup, DSO_HALTTYPE, DSS_HALT_GUARD);
 
548
        //orderGroupLoc(attackGroup, DORDER_MOVE,attackGroup.x,attackGroup.y);  //Collect them a bit
 
549
        setGroupSecondary(sendOutpostGr, DSO_HALTTYPE, DSS_HALT_GUARD);
 
550
        orderGroupLoc(sendOutpostGr, DORDER_MOVE,attackGroup.x,attackGroup.y);  //Collect them a bit
 
551
        setEventTrigger(Rush,RushTr);
 
552
 
 
553
        setEventTrigger(stopAttack,inactive);
 
554
}
 
555
 
 
556
//------------------------------------------------------
 
557
//      Control the attack
 
558
//------------------------------------------------------
 
559
event RushControl(inactive)
 
560
{
 
561
        //=====================================================================
 
562
        //              attackPhase explaination:
 
563
        //      0:      idle
 
564
        //      1:      on our way to the enemy 'edge' (waiting for regrouping)
 
565
        //      2:      on our way to the base
 
566
        //      3:      attacking
 
567
        //=====================================================================
 
568
 
 
569
        if((not defendingBase) and (helpAllyPlayer < 0))        //Attackers not busy
 
570
        {
 
571
 
 
572
                temp = (KeepDist / 2);                  //Enemy base range
 
573
 
 
574
                //maxRepairing = numRushers * 3 / 7 + 1;                //Max number of units allowed to be repairing before retreating
 
575
 
 
576
                //Max number of units that may be going to repair at the same time before retreat
 
577
                //-------------------------------------------------------------------------------
 
578
                result = attackGroup.members + repGr.members;           //Total available units (+repGr units to make it more precise)
 
579
 
 
580
                //if(numRushers > attackGroup.members)
 
581
                //{
 
582
                //      result = numRushers;            //Use numRushers or number of attackers to calculate how many units may repair at a time (whatever number is bigger)
 
583
                //}
 
584
 
 
585
                maxRepairing = attackGroup.members * 3 / 7 + 2;         //Max number of units allowed to be repairing before retreating
 
586
 
 
587
 
 
588
 
 
589
                //------------------------
 
590
                //Stop attack if necessary
 
591
                //------------------------
 
592
                if((attackPhase > 0) and (curEnemy != -1))      //If dead
 
593
                {
 
594
                        if(not actPlayer[curEnemy])
 
595
                        {
 
596
                        //Retreat if enemy is dead
 
597
                                //------------------------
 
598
                                setEventTrigger(stopAttack,nowTr);      //Cancel attack, clear variables
 
599
                                attackPhase = 0;
 
600
                        }
 
601
                }
 
602
 
 
603
                //Add units from collectSendGr to sendOutpostGr if we have a small group which can protect itself (prevent ant-tail)
 
604
                if(collectSendGr.members > 6)
 
605
                {
 
606
                        groupAddGroup(sendOutpostGr, collectSendGr);    //Add collectSendGr to sendOutpostGr
 
607
                }
 
608
 
 
609
                //-------------------------------------------------------------
 
610
                //Add units to attack group after they have reached the outpost
 
611
                //-------------------------------------------------------------
 
612
                if(attackPhase > 0)     //If on our way to the outpost
 
613
                {
 
614
                        //If all attack units were killed or alloutattack, then make defend units attackers
 
615
                        //---------------------------------------------------------------------------------
 
616
                        if(((attackGroup.members + sendOutpostGr.members + repGr.members) < (numRushers / 2)) or (numRetreats > maxRetreats))
 
617
                        {
 
618
                                if(defendGr.members > (maxDefenders / 2))               //Enough defenders
 
619
                                {
 
620
                                        showConsoleText(DebugMsg[5], player);           //Adding some defenders to attackers
 
621
 
 
622
                                        initIterateGroup(defendGr);
 
623
                                        droid = iterateGroup(defendGr);
 
624
                                        count = defendGr.members;
 
625
                                        count2 = defendGr.members;
 
626
                                        while((count > (count2 / 2)) and (droid != NULLOBJECT)) //Leave atleast 50% of available number of defenders
 
627
                                        {
 
628
                                                if(droid.droidType != DROID_REPAIR)             //Leave them the repair unit, so this will not screw up everything
 
629
                                                {
 
630
                                                        groupAddDroid(sendOutpostGr, droid);    //Add to attackers
 
631
                                                        count = count - 1;
 
632
                                                }
 
633
                                                droid = iterateGroup(defendGr);         //Next droid
 
634
                                        }
 
635
 
 
636
                                        toRepDefendDroid[0] = NULLOBJECT;               //Make repairer stop following this unit if it became an attacker
 
637
                                        toRepDefendDroid[1] = NULLOBJECT;
 
638
                                }
 
639
                        }
 
640
 
 
641
                        //Do alloutattack if failed too many times already
 
642
                        //------------------------------------------------
 
643
                        if(numRetreats > maxRetreats)
 
644
                        {
 
645
                                //if(not defendingBase)         //(Done earlier now)
 
646
                                //{
 
647
                                        showConsoleText(DebugMsg[3], player);           //Alloutattack
 
648
                                        groupAddGroup(sendOutpostGr, collectSendGr);    //Add collectSendGr to sendOutpostGr
 
649
                                        groupAddGroup(sendOutpostGr, attackGroup);      //Add attackGroup to sendOutpostGr
 
650
                                        groupAddGroup(sendOutpostGr, scoutGroup[0]);    //Add scout group1 to sendOutpostGr
 
651
                                        groupAddGroup(sendOutpostGr, scoutGroup[1]);    //Add scout group2 to sendOutpostGr
 
652
                                        groupAddGroup(sendOutpostGr, oilGr);            //Add oil attacking group to sendOutpostGr
 
653
        
 
654
                                        numRetreats = 0;        //Reset (necessary?)
 
655
                                //}
 
656
                        }
 
657
 
 
658
                        //Send newly-built units to the edge
 
659
                        //----------------------------------
 
660
                        boolResult = FALSE;
 
661
                        if(((attackGroup.members + sendOutpostGr.members) > (numRushers / 2)) and (sendOutpostGr.members > 3))          //Check this condition only one time
 
662
                        {
 
663
                                //showConsoleText(DebugMsg[2], player); //reinforcements on the way
 
664
                                boolResult = TRUE;
 
665
                        }
 
666
 
 
667
                        //tempX = sendOutpostGr.x;                      //Find center of the group
 
668
                        //tempY = sendOutpostGr.y;
 
669
                        //result = tempGroup.members;           //By accessing another group we make WZ clear the cached sendOutpostGr member variables, to reinitialize them next time we run this event (otherwise values won't change)
 
670
 
 
671
                        initIterateGroup(sendOutpostGr);
 
672
                        droid = iterateGroup(sendOutpostGr);
 
673
                        while(droid != NULLOBJECT)
 
674
                        {
 
675
                                if(distBetweenTwoPoints(droid.x, droid.y, curEnEdgeX, curEnEdgeY) > temp)               //If not in the outpost
 
676
                                {
 
677
                                        //Prevent the ant-tail, send units to the center of the group if too far away ahead
 
678
                                        //if(distBetweenTwoPoints(droid.orderx, droid.ordery, curEnEdgeX, curEnEdgeY) < temp)           //If was already sent to the outpost
 
679
                                        //{
 
680
                                        //      if(distBetweenTwoPoints(droid.x, droid.y, tempX, tempY) > (9 * 128))            //If too far away from its buddies
 
681
                                        //      {
 
682
                                        //              orderDroidLoc(droid, DORDER_MOVE, tempX, tempY);                //Prevent ant-tail, send unit back to the group center
 
683
                                        //      }
 
684
                                        //}
 
685
                                        //else
 
686
 
 
687
                                        if(distBetweenTwoPoints(droid.orderx, droid.ordery, curEnEdgeX, curEnEdgeY) >= temp)            //If not going to the outpost
 
688
                                        {
 
689
                                                if(boolResult == TRUE)          //Condition checked before
 
690
                                                {
 
691
                                                        setDroidSecondary(droid, DSO_HALTTYPE, DSS_HALT_GUARD);
 
692
                                                        result = (7 * 128);
 
693
                                                        //orderDroidLoc(droid, DORDER_MOVE, curEnEdgeX + random(result) - (result/2), curEnEdgeY + random(result) - (result/2));                //Send to the outpost
 
694
                                                        orderDroidLoc(droid, DORDER_SCOUT, curEnEdgeX + random(result) - (result/2), curEnEdgeY + random(result) - (result/2));         //Send to the outpost
 
695
                                                }
 
696
                                        }
 
697
                                }
 
698
                                else    //Add to attackers if reached outpost
 
699
                                {
 
700
                                        //droidLeaveGroup(droid);
 
701
                                        groupAddDroid(attackGroup,droid);
 
702
                                }
 
703
                                droid = iterateGroup(sendOutpostGr);            //Next droid
 
704
                        }
 
705
 
 
706
                        //-------------------------------------------
 
707
                        //Add repaired units back to the attack group
 
708
                        //-------------------------------------------
 
709
                        initIterateGroup(repGr);
 
710
                        droid = iterateGroup(repGr);
 
711
                        while(droid != NULLOBJECT)
 
712
                        {
 
713
 
 
714
                                if((droid.health > 85) or (not haveOutpost))    //Don't have to or can't repair
 
715
                                {
 
716
                                        groupAddDroid(repairedGroup, droid);    //Collect them, add to a temporary group to prevent ant-tail
 
717
                                }
 
718
                                else    //Re-send to repair
 
719
                                {
 
720
                                        if((droid.health < 85)  and (haveOutpost) and  (droid.order != DORDER_RTR))     //Has to and can repair and not going to repair
 
721
                                        {
 
722
                                                orderDroid(droid, DORDER_RTR);          //Re-order to repair
 
723
                                        }
 
724
                                }
 
725
 
 
726
                        /*
 
727
                                if((droid.health < 85) and (haveOutpost) and (droid.order != DORDER_RTR))
 
728
                                {       
 
729
                                        //if(droid.order != DORDER_RTR)                 //If not going to repair
 
730
                                        //{
 
731
                                                orderDroid(droid, DORDER_RTR);          //Order to repair
 
732
                                        //}
 
733
                                }
 
734
                                else            //If already repaired or can't repair
 
735
                                {
 
736
                                        if(((droid.health > 85) or (not haveOutpost)) and (droid.order != DORDER_RTR))                  //If not going to repair
 
737
                                        {
 
738
                                                //droidLeaveGroup(droid);
 
739
                                                //groupAddDroid(attackGroup, droid);    //Add to attackers
 
740
                                                groupAddDroid(repairedGroup, droid);    //Collect them, add to a temporary group to prevent ant-tail
 
741
                                        }
 
742
                                }
 
743
                        */
 
744
 
 
745
                                droid = iterateGroup(repGr);                    //Next droid
 
746
                        }
 
747
 
 
748
                        //If units are far (already attacking enemy base) then wait for more peraired units
 
749
                        if(attackPhase > 2)
 
750
                        {
 
751
                                result = 3;
 
752
                                if(repGr.members > 7)
 
753
                                {
 
754
                                        result = 6;             //Wait for more repaired units, if many of them are going to repair, before sending back to enemy
 
755
                                }
 
756
                                
 
757
                                if(repairedGroup.members > result)      //Prevent ant-tail while attacking
 
758
                                {
 
759
                                        groupAddGroup(sendOutpostGr, repairedGroup);    //Add back to action
 
760
                                }
 
761
                        }
 
762
                        else
 
763
                        {
 
764
                                groupAddGroup(attackGroup, repairedGroup);      //Add back to attackers directly
 
765
                        }
 
766
 
 
767
                        //Remove unit from the attack group if it is goint to repair
 
768
                        //----------------------------------------------------------
 
769
                        initIterateGroup(attackGroup);
 
770
                        droid = iterateGroup(attackGroup);
 
771
                        while(droid != NULLOBJECT)
 
772
                        {
 
773
                                if(droid.order == DORDER_RTR)                   //If going to repair
 
774
                                {
 
775
                                        //droidLeaveGroup(droid);
 
776
                                        setDroidSecondary(droid, DSO_HALTTYPE, DSS_HALT_GUARD);         //Don't pursue, guard position
 
777
                                        groupAddDroid(repGr, droid);            //Add to repair group
 
778
                        
 
779
                                }
 
780
                                droid = iterateGroup(attackGroup);              //Next droid
 
781
                        }
 
782
                }
 
783
 
 
784
 
 
785
                //------------------------------------------------------------------
 
786
                //Start attacking enemy base if most of the units are in the outpost
 
787
                //------------------------------------------------------------------
 
788
                if(attackPhase == 1)            //If on our way to the outpost
 
789
                {
 
790
                        //Check if we can start our invasion
 
791
                        //----------------------------------
 
792
                        //if(attackGroup.members > numRushers)                  //If we have enough units
 
793
                        //{
 
794
                                boolResult = FALSE;
 
795
                                //if(numRepairing == 0)
 
796
                                //{
 
797
                                        if(haveOutpost == TRUE)
 
798
                                        {
 
799
                                                boolResult = TRUE;      //Repair units with light damage
 
800
                                        }
 
801
                                //}
 
802
 
 
803
                                //Find idle repair facility
 
804
                                //-------------------------
 
805
                                //structure2 = NULLOBJECT;
 
806
                                //initEnumStruct(FALSE,factory,player,player);
 
807
                                //structure = enumStruct();
 
808
                                //while(structure != NULLOBJECT)
 
809
                                //{
 
810
                                //      if(structureIdle(structure) == TRUE)
 
811
                                //      {
 
812
                                //              structure2 = structure;
 
813
                                //      }
 
814
                                //      structure = enumStruct();
 
815
                                //}
 
816
 
 
817
                                //Count idle units
 
818
                                //----------------
 
819
                                result2 = repGr.members;
 
820
                                result = 0;
 
821
                                initIterateGroup(attackGroup);
 
822
                                droid = iterateGroup(attackGroup);
 
823
                                while(droid != NULLOBJECT)
 
824
                                {
 
825
                                        if((droid.order == DORDER_NONE) or ((droid.orderx == curEnEdgeX) and (droid.ordery == curEnEdgeY)))     //Not moving or retreating      //Was != DORDER_MOVE
 
826
                                        {
 
827
                                                result = result + 1;            //Num of idle units
 
828
 
 
829
                                                //Repair units with light damage
 
830
                                                //------------------------------
 
831
                                                //if((droid.health < 60) and (boolResult) and ((result2 + 2) < maxRepairing))   //If it's damaged a bit and can repair, don't sent to rpare too many units, keep number under maxRepairing
 
832
                                                if((droid.health < 70) and (boolResult))        //If it's damaged a bit and can repair
 
833
                                                {
 
834
                                                        orderDroid(droid, DORDER_RTR);  //Repair unit
 
835
                                                        result2 = result2 + 1;
 
836
                                                }
 
837
                                        }
 
838
                                        droid = iterateGroup(attackGroup);
 
839
                                }
 
840
 
 
841
                                //Send to the enemy base if everything's ok
 
842
                                //-----------------------------------------
 
843
                                if((attackGroup.members) > numRushers)          //If have enough units ready to attack
 
844
                                {
 
845
                                        boolResult = FALSE;
 
846
                                        if(isHumanPlayer(curEnemy))             //Move instead of scout if attacking human
 
847
                                        {
 
848
                                                boolResult = TRUE;
 
849
                                        }
 
850
 
 
851
                                        //result2 = (result * 100 / attackGroup.members);
 
852
 
 
853
                                        //if((result2 > 60) or (result >= numRushers))                          // > 60% of the entire group is ready for attack, or have enough, even if many repairing
 
854
                                        //{
 
855
                                                if(((haveOutpost) and (attackGroup.health >= maxAttackH)) or (haveOutpost == FALSE))
 
856
                                                {
 
857
                                                        //if((numRepairing < (attackGroup.members / 2)) and (repGr.members < (numRushers / 4)))         //If not too many attackers repairing
 
858
                                                        if(repGr.members < (maxRepairing / 2))  //Not too many repairing otherwise wait until repaired
 
859
                                                        {
 
860
                                                                //Send to the enemy base
 
861
                                                                //----------------------
 
862
                                                                attackPhase = 2;
 
863
                                                                showConsoleText(DebugMsg[2], player);   //Starting attack
 
864
                                                                setGroupSecondary(attackGroup, DSO_HALTTYPE, DSS_HALT_GUARD);
 
865
 
 
866
                                                                //if(boolResult == TRUE)                //If human
 
867
                                                                //{
 
868
                                                                //      orderGroupLoc(attackGroup, DORDER_MOVE, curEnemyX, curEnemyY);
 
869
                                                                //}
 
870
                                                                //else                                  //AI
 
871
                                                                //{
 
872
                                                                        orderGroupLoc(attackGroup, DORDER_SCOUT, curEnemyX, curEnemyY);
 
873
                                                                //}
 
874
                                                        }
 
875
                                                }
 
876
                                        //}
 
877
                                }
 
878
                        //}
 
879
                }
 
880
 
 
881
 
 
882
                //-------------------------------
 
883
                //Sending to the enemy base rules
 
884
                //-------------------------------
 
885
                if(attackPhase > 1)     //If goint to the enemy base or already reached it
 
886
                {
 
887
                        //If attack failed
 
888
                        //----------------
 
889
                        //if((attackGroup.members < (numRushers * 2 / 3)) or ((haveOutpost) and (attackGroup.health < minAttackH)) or (numRepairing >= (attackGroup.members / 2)) or (repGr.members > maxRepairing))    //If not enough units available
 
890
 
 
891
                        boolResult = FALSE;
 
892
 
 
893
                        if(attackGroup.members < 6)     //Not enough units left 
 
894
                        {
 
895
                                showConsoleText(DebugMsg[6], player);           //Not enough units left 
 
896
                                boolResult = TRUE;
 
897
                        }
 
898
 
 
899
                        //else if((haveOutpost) and (attackGroup.health < minAttackH))  //Too many damaged units
 
900
                        //{
 
901
                        //      showConsoleText(DebugMsg[5], player);                   //Too many damaged units
 
902
                        //      boolResult = TRUE;
 
903
                        //}
 
904
                        //if(repGr.members >= maxRepairing)     //Too many repairing
 
905
                        //{
 
906
                        //      showConsoleText(DebugMsg[4], player);           //Too many repairing
 
907
                        //      boolResult = TRUE;
 
908
                        //}
 
909
                        //else if(attackGroup.members < (numRushers * 2 / 5))   //If not enough units available
 
910
                        //{
 
911
                        //      showConsoleText(DebugMsg[6], player);           //Not enough units left 
 
912
                        //      boolResult = TRUE;
 
913
                        //}
 
914
 
 
915
                        if(boolResult)          //Cancel attack, retreat
 
916
                        {
 
917
                                attackPhase = 1;
 
918
                                setGroupSecondary(attackGroup, DSO_HALTTYPE, DSS_HALT_GUARD);
 
919
                                orderGroupLoc(attackGroup, DORDER_MOVE, curEnEdgeX, curEnEdgeY);        //Retreat
 
920
                                numRushers = numRushers + 2;    //Increase number of attackers
 
921
                                if(numRushers > 40)
 
922
                                {
 
923
                                        numRushers = 40;
 
924
                                }
 
925
 
 
926
                                numRetreats = numRetreats + 1;          //Remember how many times our attacks failed
 
927
                        }
 
928
                        else            //If enough units available
 
929
                        {
 
930
                                boolResult = FALSE;
 
931
                                if(isHumanPlayer(curEnemy))             //Move instead of scout if attacking human
 
932
                                {
 
933
                                        boolResult = TRUE;
 
934
                                }
 
935
 
 
936
                                //--------------------------------------------------
 
937
                                //Send newly-arrived units (outpost units) to attack
 
938
                                //--------------------------------------------------
 
939
                                //tempX = attackGroup.x;                        //Find center of the group
 
940
                                //tempY = attackGroup.y;
 
941
                                //result = tempGroup.members;           //By accessing another group we make WZ clear the cached sendOutpostGr member variables, to reinitialize them next time we run this event (otherwise values won't change)
 
942
                                initIterateGroup(attackGroup);
 
943
                                droid = iterateGroup(attackGroup);
 
944
 
 
945
                                while(droid != NULLOBJECT)
 
946
                                {
 
947
                                        if(distBetweenTwoPoints(droid.x, droid.y, curEnemyX, curEnemyY) > temp)         //If not in the enemy base
 
948
                                        {
 
949
                                                if((droid.order == DORDER_NONE) or ((droid.orderx != curEnemyX) and (droid.ordery != curEnemyY)))               //Idle, or going somewhere else, but not to the enemy base
 
950
                                                {
 
951
                                                        setDroidSecondary(droid, DSO_HALTTYPE, DSS_HALT_GUARD);
 
952
                                                        //if(boolResult == TRUE)                //Human
 
953
                                                        //{
 
954
                                                        //      orderDroidLoc(droid, DORDER_MOVE, curEnemyX, curEnemyY);
 
955
                                                        //}
 
956
                                                        //else                  //AI
 
957
                                                        //{
 
958
                                                                orderDroidLoc(droid, DORDER_SCOUT, curEnemyX, curEnemyY);
 
959
                                                        //}
 
960
                                                }
 
961
                                                //else  //If already on the way to the enemy base
 
962
                                                //{
 
963
                                                //      //Prevent the ant-tail, send units to the center of the group if too far away ahead
 
964
                                                //      if(distBetweenTwoPoints(droid.x, droid.y, tempX, tempY) > (9 * 128))            //If too far away from its buddies
 
965
                                                //      {
 
966
                                                //              orderDroidLoc(droid, DORDER_MOVE, tempX, tempY);                //Prevent ant-tail, send unit back to the group center
 
967
                                                //      }
 
968
                                                //}
 
969
                                        }
 
970
                                        else                            //Already in the enemy base
 
971
                                        {
 
972
                                                if(attackPhase != 3)
 
973
                                                {
 
974
                                                        showConsoleText(DebugMsg[7], player);           //Reached enemy base
 
975
                                                }
 
976
 
 
977
                                                attackPhase = 3;
 
978
                                                setDroidSecondary(droid,DSO_HALTTYPE, DSS_HALT_PERSUE); //Persue. For more efficient structure targeting.
 
979
                                        }
 
980
                                        droid = iterateGroup(attackGroup);              //Next droid
 
981
                                }
 
982
                        }
 
983
                }
 
984
 
 
985
 
 
986
                //------------
 
987
                //Attack rules
 
988
                //------------
 
989
                if(attackPhase == 3)                    //If attacking
 
990
                {
 
991
                        //If we were making an early rush then make sure we build more units before we attack again (otherwise will be slowly increased by 1)
 
992
                        if(numRushers < 10)
 
993
                        {
 
994
                                numRushers = 10;
 
995
                        }
 
996
 
 
997
                        //They are repairing bunker we attack! Eliminate the truck
 
998
                        //--------------------------------------------------------
 
999
                        boolResult = FALSE;
 
1000
                        resetDroidTargets();
 
1001
                        setDroidTarPref(DT_CONSTRUCT);
 
1002
                        tempDroid = droidTargetInArea(curEnemy, player, curEnemyX - temp, curEnemyY - temp, curEnemyX + temp, curEnemyY + temp);
 
1003
                        if(tempDroid != NULLOBJECT)
 
1004
                        {
 
1005
                                if(tempDroid.droidType == DROID_CONSTRUCT)
 
1006
                                {
 
1007
                                        //Order droid close to the truck to attack it
 
1008
                                        //-------------------------------------------
 
1009
                                        boolResult = TRUE;
 
1010
                                        initIterateGroup(attackGroup);
 
1011
                                        droid = iterateGroup(attackGroup);
 
1012
                                        while(droid != NULLOBJECT)
 
1013
                                        {
 
1014
                                                if(distBetweenTwoPoints(droid.x, droid.y, tempDroid.x, tempDroid.y) < (10 * 128))
 
1015
                                                //if(losTwoObjects(droid, tempDroid, TRUE))     //If can see truck
 
1016
                                                {
 
1017
                                                        orderDroidObj(droid, DORDER_ATTACK,tempDroid);
 
1018
                                                        attackObject = tempDroid;
 
1019
                                                }
 
1020
                                                droid = iterateGroup(attackGroup);
 
1021
                                        }
 
1022
                                }
 
1023
                        }
 
1024
 
 
1025
                        //Hi-priority structures
 
1026
                        //----------------------
 
1027
                        count = numAttackStructs - 1;
 
1028
                        while(count >= 0)
 
1029
                        {
 
1030
                                result = (15 * 128);
 
1031
                                initEnumStruct(FALSE,attackStructs[count],curEnemy,player);                     
 
1032
                                structure = enumStruct();
 
1033
                                while(structure != NULLOBJECT)
 
1034
                                {
 
1035
                                        if(distBetweenTwoPoints(curEnemyX, curEnemyY, structure.x, structure.y) < result)               //If in the enemy base
 
1036
                                        {
 
1037
                                                boolResult = TRUE;
 
1038
                                                initIterateGroup(attackGroup);
 
1039
                                                droid = iterateGroup(attackGroup);
 
1040
                                                while(droid != NULLOBJECT)
 
1041
                                                {
 
1042
                                                        if(droid.order != DORDER_ATTACK)        //Not already attacking
 
1043
                                                        {
 
1044
                                                                //if(distBetweenTwoPoints(droid.x, droid.y, structure.x, structure.y) < (12 * 128))
 
1045
                                                                if(losTwoObjects(droid, structure, FALSE))      //If can see this structure
 
1046
                                                                {
 
1047
                                                                        orderDroidObj(droid, DORDER_ATTACK, structure);
 
1048
                                                                        sVtolObject = structure;
 
1049
                                                                }
 
1050
                                                        }
 
1051
                                                        droid = iterateGroup(attackGroup);
 
1052
                                                }
 
1053
                                        }
 
1054
                                        structure = enumStruct();
 
1055
                                }
 
1056
                                count = count - 1;
 
1057
                        }
 
1058
 
 
1059
                        if(boolResult == FALSE)         //Factories
 
1060
                        {
 
1061
                                resetStructTargets();
 
1062
                                setStructTarPref(ST_FACTORY);
 
1063
                                structure = structTargetInArea(curEnemy, player, curEnemyX - temp, curEnemyY - temp, curEnemyX + temp, curEnemyY + temp);
 
1064
                                if(structure != NULLOBJECT)
 
1065
                                {
 
1066
                                        //Order droid close to the factory to attack it
 
1067
                                        initIterateGroup(attackGroup);
 
1068
                                        droid = iterateGroup(attackGroup);
 
1069
                                        while(droid != NULLOBJECT)
 
1070
                                        {
 
1071
                                                if(distBetweenTwoPoints(droid.x, droid.y, structure.x, structure.y) < (10 * 128))
 
1072
                                                {
 
1073
                                                        orderDroidObj(droid, DORDER_ATTACK,structure);
 
1074
                                                        attackObject = structure;
 
1075
                                                }
 
1076
                                                droid = iterateGroup(attackGroup);
 
1077
                                        }
 
1078
                                }
 
1079
                        }
 
1080
                }
 
1081
 
 
1082
                //--------------------------------------------------------
 
1083
                //Allow repairing if we have repair facilities in outposts
 
1084
                //--------------------------------------------------------
 
1085
                if(haveOutpost)
 
1086
                {
 
1087
                        setGroupSecondary(attackGroup, DSO_REPAIR_LEVEL, DSS_REPLEV_HIGH);
 
1088
                }
 
1089
                else
 
1090
                {
 
1091
                        setGroupSecondary(attackGroup, DSO_REPAIR_LEVEL, DSS_REPLEV_NEVER);
 
1092
                }
 
1093
        }
 
1094
}
 
1095
 
 
1096
//------------------------------------------------------
 
1097
//Finish part-built structures
 
1098
//------------------------------------------------------
 
1099
event FinishStructures(inactive)
 
1100
{
 
1101
        //Find structure closest to the base
 
1102
        //----------------------------------
 
1103
        temp = tempGroup.members;               //Reset cached buildGroup values
 
1104
        result = 99999;
 
1105
        structure2 = NULLOBJECT;
 
1106
        initEnumStruct(TRUE,derrick,player,player);             //TRUE: iterate through all structures
 
1107
        structure= enumStruct();
 
1108
        while(structure != NULLOBJECT)
 
1109
        {
 
1110
                if(not structureComplete(structure))            //If structure not finished
 
1111
                {
 
1112
                        //Check if anybody is building it already
 
1113
                        //---------------------------------------
 
1114
                        boolResult = TRUE;
 
1115
                        initIterateGroup(buildGroup);                           // find idle droids in build group.
 
1116
                        droid = iterateGroup(buildGroup);
 
1117
                        while((droid != NULLOBJECT) and (boolResult))
 
1118
                        {
 
1119
                                if((droid.orderx == structure.x) and (droid.ordery == structure.y)) 
 
1120
                                {
 
1121
                                        boolResult = FALSE;                     //Somebody is building it, try next structure
 
1122
                                }
 
1123
                                droid = iterateGroup(buildGroup);
 
1124
                        }
 
1125
 
 
1126
                        //Make sure it is not an Outpost defense (since outpost builder is not in the buildGroup)
 
1127
                        //--------------------------------------
 
1128
                        if(boolResult)
 
1129
                        {
 
1130
                                if(outpostDroid != NULLOBJECT)
 
1131
                                {
 
1132
                                        if((outpostDroid.orderx == structure.x) and (outpostDroid.ordery == structure.y))
 
1133
                                        {
 
1134
                                                boolResult = FALSE;             //Don't finish building this structure
 
1135
                                        }
 
1136
                                }
 
1137
                        }
 
1138
 
 
1139
                        //Remember this structure if it is the closest one so far
 
1140
                        //-------------------------------------------------------
 
1141
                        if(boolResult)                                          //If nobody is building it already
 
1142
                        {
 
1143
                                result2 = distBetweenTwoPoints(baseX, baseY, structure.x, structure.y);         //How far away from the base
 
1144
                                if(result2 < result)                            //If this structure is closer than the last one, then store it instead of the last one
 
1145
                                {
 
1146
                                        result = result2;
 
1147
                                        structure2 = structure;                 //Remember this structure
 
1148
                                }
 
1149
                        }
 
1150
                }
 
1151
                structure = enumStruct();
 
1152
        }
 
1153
 
 
1154
        //Finish building structure, if there are any
 
1155
        //-------------------------------------------
 
1156
        if((structure2 != NULLOBJECT) and (boolResult))                 //If found an unbuilt structure and nobody is building it already
 
1157
        {
 
1158
                //Find closest truck
 
1159
                //------------------
 
1160
                result = 99999;
 
1161
                tempDroid = NULLOBJECT;
 
1162
                initIterateGroup(buildGroup);                           // find idle droids in build group.
 
1163
                droid = iterateGroup(buildGroup);
 
1164
                while(droid != NULLOBJECT)
 
1165
                {
 
1166
                        if(droid.order == DORDER_NONE)                  //If idle
 
1167
                        {
 
1168
                                result2 = distBetweenTwoPoints(droid.x, droid.y, structure2.x, structure2.y);           //How far away this truck is from the unfinished structure
 
1169
                                if(result2 < result)
 
1170
                                {
 
1171
                                        result = result2;
 
1172
                                        tempDroid = droid;              //Remember this truck, it is the closest so far
 
1173
                                }
 
1174
                        }
 
1175
                        droid = iterateGroup(buildGroup);
 
1176
                }
 
1177
 
 
1178
                //Send to build if found a truck
 
1179
                //------------------------------
 
1180
                if(tempDroid != NULLOBJECT)
 
1181
                {
 
1182
                        orderDroidObj(tempDroid,DORDER_HELPBUILD,structure2);
 
1183
                }
 
1184
        }
 
1185
}
 
1186
 
 
1187
//------------------------------------------------------
 
1188
//Destroy enemy derricks
 
1189
//------------------------------------------------------
 
1190
event destroyOil(inactive)
 
1191
{
 
1192
        if(idleGroup(oilGr) > (oilGr.members / 2))
 
1193
        {
 
1194
                if(oilGr.members >= maxOilGr)
 
1195
                {
 
1196
                        boolResult = FALSE;
 
1197
                        //if(attackDerrick != NULLOBJECT)               //If we have derrick to attack
 
1198
                        if(oilX > 0)
 
1199
                        {
 
1200
                                temp = (4 * 128);
 
1201
                                count = 0;
 
1202
                                while((count < numEnemies) and (boolResult == FALSE))
 
1203
                                {
 
1204
                                        boolResult = structInArea(Enemies[count], oilX - temp, oilY - temp, oilX + temp, oilY + temp);
 
1205
                                        count = count + 1;
 
1206
                                }
 
1207
                        }
 
1208
 
 
1209
                        //Find new derrick
 
1210
                        if(boolResult == FALSE)         //No structures found in the area or first search
 
1211
                        {
 
1212
                                //Find closest enemy derrick
 
1213
                                //--------------------------
 
1214
                                oilX = 0;
 
1215
                                result = 99999;
 
1216
                                structure2 = NULLOBJECT;
 
1217
                                count = 0;
 
1218
                                while(count < numEnemies)
 
1219
                                {
 
1220
                                        temp = 2432;    //19 * 128
 
1221
                                        initEnumStruct(FALSE,derrick,Enemies[count],Enemies[count]);
 
1222
                                        structure = enumStruct();
 
1223
                                        while(structure != NULLOBJECT)
 
1224
                                        {
 
1225
                                                if(EnemyX[count] > 0)
 
1226
                                                {
 
1227
                                                        if(distBetweenTwoPoints(structure.x, structure.y, EnemyX[count], EnemyY[count]) > temp)         //Not in the enemy base
 
1228
                                                        {
 
1229
                                                                result2 = distBetweenTwoPoints(baseX, baseY, structure.x,structure.y);
 
1230
                                                                if(result2 < result)
 
1231
                                                                {
 
1232
                                                                        result = result2;
 
1233
                                                                        structure2 = structure;
 
1234
                                                                }
 
1235
                                                        }
 
1236
                                                }
 
1237
                                                structure = enumStruct();
 
1238
                                        }
 
1239
                                        count = count + 1;
 
1240
                                }
 
1241
 
 
1242
                                //Assign to the found object
 
1243
                                //--------------------------
 
1244
                                if(structure2 != NULLOBJECT)
 
1245
                                {
 
1246
                                        //attackDerrick = structure2;
 
1247
                                        oilX = structure2.x;
 
1248
                                        oilY = structure2.y;
 
1249
                                        boolResult = TRUE;
 
1250
                                }
 
1251
                        }
 
1252
 
 
1253
                        if(boolResult == TRUE)
 
1254
                        {
 
1255
                                orderGroupLoc(oilGr, DORDER_MOVE, oilX, oilY);
 
1256
                        }
 
1257
                }
 
1258
        }
 
1259
 
 
1260
        //Manage oil attack when arrived, destroy derrick if we can get it
 
1261
        //----------------------------------------------------------------
 
1262
        //if(oilX > 0)          //If we have an enemy derrick to attack
 
1263
        //{
 
1264
        //      initIterateGroup(oilGr);
 
1265
        //      droid = iterateGroup(oilGr);
 
1266
        //      while(droid != NULLOBJECT)
 
1267
        //      {
 
1268
        //              //if(distBetweenTwoPoints(attackDerrick.x, attackDerrick.y, droid.x, droid.y) < (7 128))        //If close
 
1269
        //              if(losTwoObjects(droid, attackDerrick, TRUE))   //If we can shoot at the derrick
 
1270
        //              {
 
1271
        //                      orderDroidObj(droid, DORDER_ATTACK, attackDerrick);
 
1272
        //              }
 
1273
        //              droid = iterateGroup(oilGr);
 
1274
        //      }
 
1275
        //}
 
1276
}
 
1277
 
 
1278
//------------------------------------------------------
 
1279
//      Find most suitabe enemy
 
1280
//------------------------------------------------------
 
1281
event chooseEnemy(chooseEnemyTr)
 
1282
{
 
1283
 
 
1284
        //if((curEnemy == -1) and (numEnemies > 0))
 
1285
        if(numEnemies > 0)
 
1286
        {
 
1287
                if((sendOutpostGr.members + attackGroup.members + collectSendGr.members) > numRushers)
 
1288
                {
 
1289
                        temp = -1;      //Temp enemy
 
1290
                        count = 0;
 
1291
                        result = 99999;
 
1292
                        while(count < numEnemies)
 
1293
                        {
 
1294
                                if((isHumanPlayer(Enemies[count])) and (EnemyX[count] > 0))
 
1295
                                {
 
1296
                                        result2 = distBetweenTwoPoints(baseX, baseY, EnemyX[count], EnemyY[count]);
 
1297
                                        if(result2 < result)
 
1298
                                        {
 
1299
                                                result = result2;       //Remember closest distance so far
 
1300
                                                result3 = result2;      //Remember for later use
 
1301
                                                temp = Enemies[count];
 
1302
                                        }
 
1303
                                }
 
1304
                                count = count + 1;
 
1305
                        }
 
1306
 
 
1307
                        //If no human players, find the closest AI
 
1308
                        if(temp == -1)
 
1309
                        {
 
1310
                                result = 99999;
 
1311
                                count = 0;
 
1312
                                while(count < numEnemies)
 
1313
                                {
 
1314
                                        if(EnemyX[count] > 0)
 
1315
                                        {
 
1316
                                                result2 = distBetweenTwoPoints(baseX, baseY, EnemyX[count], EnemyY[count]);
 
1317
                                                if(result2 < result)
 
1318
                                                {
 
1319
                                                        result = result2;       //Remember closest distance so far
 
1320
                                                        result3 = result2;      //For later use
 
1321
                                                        temp = Enemies[count];
 
1322
                                                }
 
1323
                                        }
 
1324
                                        count = count + 1;
 
1325
                                }
 
1326
                        }
 
1327
                        
 
1328
 
 
1329
                        //Change enemy only if new enemy is *much* closer (20 tiles)
 
1330
                        //----------------------------------------------------------
 
1331
                        if(curEnemyX > 0)
 
1332
                        {
 
1333
                                result = distBetweenTwoPoints(baseX, baseY, curEnemyX, curEnemyY) + (20 * 128);
 
1334
                        }
 
1335
 
 
1336
                        if(((curEnemyX > 0) and (result3 > result)) or (curEnemyX < 1)) //If already have enemy and new enemy is much closer or no enemy set yet
 
1337
                        {
 
1338
                                curEnemy = temp;        //Remember 'best' enemy
 
1339
                                numRetreats = 0;        //Reset, need to do it in a better place to make generic
 
1340
                        }
 
1341
                }
 
1342
        }
 
1343
 
 
1344
        
 
1345
        //Find bases again even if (curEnemy != -1) so that attackers could find next factory if its far away
 
1346
        //---------------------------------------------------------------------------------------------------
 
1347
        count = 0;
 
1348
        while(count < numEnemies)
 
1349
        {
 
1350
 
 
1351
                //-----------------------
 
1352
                //      Find enemy's base
 
1353
                //-----------------------
 
1354
                tempX = baseX;
 
1355
                tempY = baseY;
 
1356
 
 
1357
                //Store enemy base coords, find closest structure
 
1358
                //-----------------------------------------------
 
1359
                EnemyX[count] = -1;
 
1360
                EnemyY[count] = -1;
 
1361
                result = 99999;
 
1362
                count2 = 0;
 
1363
                while(count2 < numBaseStructs)          //For all base structures
 
1364
                {
 
1365
                        initEnumStruct(FALSE,baseStructs[count2],Enemies[count],Enemies[count]);
 
1366
                        structure = enumStruct();
 
1367
                        while(structure != NULLOBJECT)
 
1368
                        {
 
1369
                                //if(structureComplete(structure))
 
1370
                                //{
 
1371
                                        result2 = distBetweenTwoPoints(tempX, tempY, structure.x, structure.y);
 
1372
                                        if(result2 < result)
 
1373
                                        {
 
1374
                                                result = result2;
 
1375
                                                EnemyX[count] = structure.x;
 
1376
                                                EnemyY[count] = structure.y;
 
1377
                                        }
 
1378
                                //}
 
1379
                                structure = enumStruct();
 
1380
                        }
 
1381
                        count2 = count2 + 1;
 
1382
                }
 
1383
 
 
1384
                //Remember coordinates of the enemy
 
1385
                //---------------------------------
 
1386
                if(Enemies[count] == curEnemy)
 
1387
                {
 
1388
                        
 
1389
                        if((EnemyX[count] != -1) and (EnemyY[count] != -1))
 
1390
                        {
 
1391
                                curEnemyX = EnemyX[count];
 
1392
                                curEnemyY = EnemyY[count];
 
1393
                        }
 
1394
 
 
1395
                        result = distBetweenTwoPoints(curEnEdgeX, curEnEdgeY, curEnemyX, curEnemyY);            //If base moved too much
 
1396
                        if((curEnEdgeX == -1) or ((result + (6 * 128)) < outpostDist) or ((result - (6 * 128)) > outpostDist) ) //If no outpost coord yet or enemy base moved too much
 
1397
                        {
 
1398
                                //Find 'edge' of the base
 
1399
                                //-----------------------
 
1400
                                curEnEdgeX = -1;
 
1401
                                curEnEdgeY = -1;
 
1402
                                result = 99999;
 
1403
                                count2 = 0;
 
1404
 
 
1405
                                tempX = baseX;
 
1406
                                tempY = baseY;
 
1407
 
 
1408
                                curEnEdgeX = curEnemyX;
 
1409
                                curEnEdgeY = curEnemyY;
 
1410
 
 
1411
                                //Calculate destination point of the attack group for regrouping
 
1412
                                //--------------------------------------------------------------
 
1413
                                if(curEnEdgeX != -1)
 
1414
                                {
 
1415
                                        result = 1;     //KeepDist;     //Assume enemy base to the left
 
1416
                                        result2 = 1;    //KeepDist;     //Assume enemy base above the base
 
1417
 
 
1418
                                        if(curEnEdgeX > maxx)           //Enemy base to the right
 
1419
                                        {
 
1420
                                                result = result * (-1); //Go to the left from the enemy base for oupost
 
1421
                                        }
 
1422
                                        else if(curEnEdgeX > minx)      //Almost on the same X level
 
1423
                                        {
 
1424
                                                result = 0;
 
1425
                                        }
 
1426
 
 
1427
                                        if(curEnEdgeY > maxy)           //Enemy base lower to the base
 
1428
                                        {
 
1429
                                                result2 = result2 * (-1);       //Go up for the outpot y coord
 
1430
                                        }
 
1431
                                        else if(curEnEdgeY > miny)      //Almost on the same Y level
 
1432
                                        {
 
1433
                                                result2 = 0;
 
1434
                                        }
 
1435
 
 
1436
                                        curEnEdgeX = curEnEdgeX + (result * KeepDist);
 
1437
                                        curEnEdgeY = curEnEdgeY + (result2 * KeepDist);
 
1438
 
 
1439
                                        //Check limits
 
1440
                                        if(curEnEdgeX < 0)
 
1441
                                        {
 
1442
                                                curEnEdgeX = (4 * 128);
 
1443
                                        }
 
1444
                                        if(curEnEdgeY < 0)
 
1445
                                        {
 
1446
                                                curEnEdgeY = (4 * 128);
 
1447
                                        }
 
1448
                                        if(curEnEdgeX > (128 * mapWidth))
 
1449
                                        {
 
1450
                                                curEnEdgeX = ((128 * mapWidth) - (4 * 128));
 
1451
                                        }
 
1452
                                        if(curEnEdgeY > (128 * mapHeight))
 
1453
                                        {
 
1454
                                                curEnEdgeY = ((128*mapHeight) - (4 * 128));
 
1455
                                        }
 
1456
 
 
1457
                                        outpostDist = distBetweenTwoPoints(curEnEdgeX, curEnEdgeY, curEnemyX, curEnemyY);
 
1458
                                        boolResult = pickStructLocation(factory, ref curEnEdgeX, ref curEnEdgeY,player);
 
1459
                                        if(boolResult == FALSE)
 
1460
                                        {
 
1461
                                                curEnEdgeX = -1;
 
1462
                                                curEnEdgeY = -1;
 
1463
                                        }
 
1464
                                        
 
1465
/*
 
1466
                                        //--------------------------
 
1467
                                        //Pathfinding
 
1468
                                        //--------------------------
 
1469
                                        //result and result2 are directions
 
1470
                                        temp = 0;
 
1471
                                        result3 = 0;                    //Final lenght between enemy base and outpost in tiles
 
1472
                                        result4 = 150;                  //Max number of iterations (in tiles)
 
1473
 
 
1474
                                        tempX = curEnemyX + (result * 512);     //Skip 4 tiles in outpost's direction
 
1475
                                        tempY = curEnemyY + (result2 * 512);    //Skip 4 tiles in outpost's direction
 
1476
 
 
1477
                                        //Round to 128 (+ 64)
 
1478
                                        tempX  = tempX / 128;
 
1479
                                        tempX  = tempX * 128 + 64;
 
1480
 
 
1481
                                        tempY = tempY / 128;
 
1482
                                        tempY = tempY * 128 + 64;
 
1483
 
 
1484
                                        boolResult = TRUE;              //Horizontal direction not blocked
 
1485
                                        boolResult2 = TRUE;             //Vertical direction not blocked
 
1486
                                        while((result4 > 0) and (result3 < 85))         //while still tries left and dist less than 50 tiles
 
1487
                                        {
 
1488
                                                //---------------------------------------------
 
1489
                                                //Choose new coordinates
 
1490
                                                //---------------------------------------------
 
1491
                                                if(temp == 0)   //Move Horizontally
 
1492
                                                {
 
1493
                                                        buildX = tempX + (result * 128);                //Move 1 tile in outpost's direction horizontaly (x)
 
1494
                                                        buildY = tempY;
 
1495
                                                }
 
1496
                                                else            //Move vertically
 
1497
                                                {
 
1498
                                                        buildX = tempX;
 
1499
                                                        buildY = tempY + (result2 * 128);       //Move 1 tile in outpost's direction vertically (y)
 
1500
                                                }
 
1501
 
 
1502
                                                //---------------------------------------------
 
1503
                                                //Check new location with a wall
 
1504
                                                //---------------------------------------------
 
1505
                                                count = buildX; //Remember to compare later
 
1506
                                                count2 = buildY;
 
1507
 
 
1508
                                                if(pickStructLocation(wall, ref buildX, ref buildY, player))    //Try this location
 
1509
                                                {
 
1510
                                                        
 
1511
                                                        if((count != (buildX + 128)) or (count2 != (buildY + 128)))     //If this location is not accessible (building coords were modified)
 
1512
                                                        {
 
1513
                                                                //turnPowerOff();
 
1514
                                                                //setPowerLevel(buildX, player);
 
1515
                                                                //addStructure( vtolPad, player, tempX - (3 * 128) , tempY );   //DEBUG
 
1516
                        showConsoleText(DebugMsg[2], player);
 
1517
 
 
1518
                                                                if(temp == 0)           //Moving horizontally
 
1519
                                                                {
 
1520
                                                                        boolResult = FALSE;     //Can't move horizontally
 
1521
                                                                }
 
1522
                                                                else                    //Moving vertically
 
1523
                                                                {
 
1524
                                                                        boolResult2 = FALSE;    //Can't move vertically
 
1525
                                                                }
 
1526
                                                        }
 
1527
                                                        else    //This tile is ok
 
1528
                                                        {
 
1529
                        showConsoleText(DebugMsg[3], player);
 
1530
                        addStructure( wall, player, count  , count2 );  //DEBUG
 
1531
 
 
1532
                                                                tempX = count;  //Remember new coords permanently
 
1533
                                                                tempY = count2; //Remember new coords permanently
 
1534
 
 
1535
                                                                if(temp == 0)           //Moving horizontally
 
1536
                                                                {
 
1537
                                                                        boolResult = TRUE;      //Cancel direction blockage flag, if was blocked
 
1538
                                                                }
 
1539
                                                                else                    //Moving vertically
 
1540
                                                                {
 
1541
                                                                        boolResult2 = TRUE;     //Cancel direction blockage flag, if was blocked
 
1542
                                                                }
 
1543
 
 
1544
                                                                result3 = result3 + 1;          //Moved 1 tile
 
1545
                                                        }
 
1546
                                                }
 
1547
 
 
1548
                                                //------------------------------------------------
 
1549
                                                //If can't move further in the outpost's direction
 
1550
                                                //------------------------------------------------
 
1551
                                                if((not boolResult) and (not boolResult2))      //If both directions blocked (hor and vert)
 
1552
                                                {
 
1553
                        showConsoleText(DebugMsg[1], player);
 
1554
                                                        if(temp==0)     //Was moving horizontally this time (X)
 
1555
                                                        {
 
1556
                                                                buildY = tempY - (result2 * 128);
 
1557
                                                                buildX = tempX;
 
1558
                                                                count = buildX;         //Remember to compare later
 
1559
                                                                count2 = buildY;
 
1560
                                                                pickStructLocation(wall, ref buildX, ref buildY,player);        //Try this location
 
1561
                                                                if((count == (buildX + 128)) and (count2 == (buildY + 128)))    //If this location is accessible (building coords were same)
 
1562
                                                                {
 
1563
                                                                        temp = 1;
 
1564
                                                                        tempY = count2;
 
1565
                                                                        tempX = count;
 
1566
                                                                        boolResult2 = TRUE;     //Reset Vertical blockage
 
1567
                                                                }
 
1568
                                                        }
 
1569
                                                        else    //Was moving vertically this time (Y)
 
1570
                                                        {
 
1571
                                                                buildX = tempX - (result * 128);        //Move 1 tile back (reversed) into a horizontal direction
 
1572
                                                                buildY = tempY;
 
1573
                                                                count = buildX;         //Remember to compare later
 
1574
                                                                count2 = buildY;
 
1575
                                                                pickStructLocation(wall, ref buildX, ref buildY,player);        //Try this location
 
1576
                                                                if((count == (buildX + 128)) and (count2 == (buildY + 128)))    //If this location is accessible (building coords were same)
 
1577
                                                                {
 
1578
                                                                        temp = 0;               //Move vertically again next time (temp will be set to 1 later)
 
1579
                                                                        tempX = count;          //Remember new X position
 
1580
                                                                        tempY = count2;
 
1581
                                                                        boolResult = TRUE;      //Reset Horizontal blockage
 
1582
                                                                }
 
1583
                                                        }
 
1584
 
 
1585
                                                        //boolResult = TRUE;    //Reset Horizontal blockage
 
1586
                                                        //boolResult2 = TRUE;   //Reset Vertical blockage
 
1587
                                                }
 
1588
 
 
1589
                                                //--------------------------------
 
1590
                                                //Cycle moving direction
 
1591
                                                //--------------------------------
 
1592
                                                if(temp == 0)
 
1593
                                                {
 
1594
                                                        temp = 1;               //Vertically next time
 
1595
                                                }
 
1596
                                                else
 
1597
                                                {
 
1598
                                                        temp = 0;               //Horizontally next time
 
1599
                                                }
 
1600
                                                
 
1601
 
 
1602
                                                result4 = result4 - 1;
 
1603
                                        }
 
1604
 
 
1605
                                        if(tempX < 0)
 
1606
                                        {
 
1607
                                                tempX = (4 * 128);
 
1608
                                        }
 
1609
                                        if(tempY < 0)
 
1610
                                        {
 
1611
                                                tempY = (4 * 128);
 
1612
                                        }
 
1613
                                        if(tempX > (128 * mapWidth))
 
1614
                                        {
 
1615
                                                tempX = ((128 * mapWidth) - (4 * 128));
 
1616
                                        }
 
1617
                                        if(tempY > (128 * mapHeight))
 
1618
                                        {
 
1619
                                                tempY = ((128*mapHeight) - (4 * 128));
 
1620
                                        }
 
1621
 
 
1622
                                        centreViewPos(tempX, tempY);
 
1623
*/
 
1624
 
 
1625
 
 
1626
                                }
 
1627
                        }
 
1628
                        
 
1629
                }
 
1630
                count = count + 1;
 
1631
        }
 
1632
}
 
1633
 
 
1634
//==============================================================================================
 
1635
//
 
1636
//                                      [RUSH PREPARATION]
 
1637
//
 
1638
//==============================================================================================
 
1639
 
 
1640
 
 
1641
//------------------------------------------------------
 
1642
//      Initialize rush preparation phase.
 
1643
//------------------------------------------------------
 
1644
event initializeRushPrep(inactive)
 
1645
{
 
1646
        mainPhase = 1;                  //Next phase became active
 
1647
}
 
1648
 
 
1649
//------------------------------------------------------
 
1650
//      Build attack units
 
1651
//------------------------------------------------------
 
1652
event BuildAttackForce(BuildAttackForceTr)
 
1653
{
 
1654
        //Enable more trucks after 15 mins, if got stuck in Lego phase somehow
 
1655
        if(gameTime > 9000)
 
1656
        {
 
1657
                maxTrucks = 12;
 
1658
        }
 
1659
 
 
1660
        //Manage truck production
 
1661
        //-----------------------
 
1662
        result2 = 0;    //Number of trucks we started building (don't build too many at one time since we can't count how many of them will get built)          
 
1663
        temp = 2;       //How many trucks to build at a time
 
1664
 
 
1665
        //if(buildGroup.members == 0)
 
1666
        //{
 
1667
        //      temp = 5;       //Build more trucks at a time
 
1668
        //}
 
1669
 
 
1670
        temp = maxTrucks - buildGroup.members;
 
1671
        if(temp > 4)
 
1672
        {
 
1673
                temp = 5;       //How many trucks to build at a time
 
1674
        }
 
1675
 
 
1676
        //Build units
 
1677
        //-----------
 
1678
        result = 0;     //Index of the current factory (count factories)
 
1679
        initEnumStruct(FALSE,factory,player,player);
 
1680
        structure = enumStruct();
 
1681
        while(structure != NULLOBJECT)
 
1682
        {
 
1683
                if((structureIdle(structure) == TRUE) and (structureComplete(structure)))
 
1684
                {
 
1685
                        boolResult = TRUE;      //Didn't start building anything yet
 
1686
 
 
1687
                        //We have not enough trucks
 
1688
                        //-------------------------
 
1689
                        if(boolResult)
 
1690
                        {
 
1691
                                if((buildGroup.members < maxTrucks) and (result2 < temp))       //Only <temp> trucks at a time
 
1692
                                {
 
1693
                                        buildDroid(constructor, structure, player, 1);  //Normal one
 
1694
                                        result2 = result2 + 1;          //Count trucks
 
1695
                                        boolResult = FALSE;
 
1696
                                }
 
1697
                        }
 
1698
 
 
1699
                        if(boolResult)          //Didn't start build anything yet
 
1700
                        {
 
1701
                                if((attackPhase > 0) and (result == 0) and (not defendingBase)) //If no repair unit and we already have enough attackers, use only 1 factory (result == 0)
 
1702
                                {
 
1703
                                        if(repDefendDroid[0] == NULLOBJECT)
 
1704
                                        {
 
1705
                                                boolResult = FALSE;
 
1706
                                        }
 
1707
                                        else if(repDefendDroid[1] == NULLOBJECT)
 
1708
                                        {
 
1709
                                                boolResult = FALSE;
 
1710
                                        }
 
1711
                                }
 
1712
 
 
1713
                                if(not boolResult)      //If decided to build a repair unit
 
1714
                                {
 
1715
                                        if(skCanBuildTemplate(player,structure, tmplRep[1]))
 
1716
                                        {
 
1717
                                                buildDroid(tmplRep[1], structure, player, 1);   //Heavy repair unit
 
1718
                                        }
 
1719
                                        else
 
1720
                                        {
 
1721
                                                buildDroid(tmplRep[0], structure, player, 1);   //Light repair unit
 
1722
                                        }
 
1723
                                }
 
1724
                                
 
1725
                        }
 
1726
 
 
1727
                        //Attack units
 
1728
                        //----------------------
 
1729
                        if(boolResult)          //Didn't start build anything yet
 
1730
                        {
 
1731
                                //Decide weather to use cheap or expensive templates
 
1732
                                //--------------------------------------------------
 
1733
                                result3 = 0;                    //Cheap templates
 
1734
                                if(playerPower(player) > muchoPower)
 
1735
                                {
 
1736
                                        result3 = 1;            //Use expensive templates if we have plenty of power
 
1737
                                }
 
1738
 
 
1739
                                //Fill array with best templates
 
1740
                                //------------------------------
 
1741
                                count2 = 0;
 
1742
                                count = numTemplates - 1;
 
1743
                                while((count2 < TemplDepth) and (count >= 0))
 
1744
                                {
 
1745
                                        if(skCanBuildTemplate(player,structure, tmpl[result3][count]))
 
1746
                                        {
 
1747
                                                //setFogColour(random(200) + 50, 1, 1);
 
1748
 
 
1749
                                                tmplChoice[count2] = tmpl[result3][count];
 
1750
                                                count2 = count2 + 1;            //We have chosen one more template
 
1751
                                        }
 
1752
                                        count = count - 1;                      //Check next template
 
1753
                                }
 
1754
 
 
1755
                                if(count2 > 0)          //Any templates found
 
1756
                                {
 
1757
                                        
 
1758
                                        if(getDroidCount(player) < 85)  //Let it build VTOLs and trucks
 
1759
                                        {
 
1760
                                                boolResult = FALSE;
 
1761
                                                buildDroid(tmplChoice[random(count2)],structure,player,1);
 
1762
                                        }
 
1763
                                }
 
1764
                        }
 
1765
                }
 
1766
                result = result + 1;            //Remember factory index
 
1767
                structure = enumStruct();
 
1768
        }
 
1769
}
 
1770
 
 
1771
//--------------------------------------------------------
 
1772
//Build cyborgs
 
1773
//--------------------------------------------------------
 
1774
event buildCyborgs(buildCyborgsTr)
 
1775
{
 
1776
        if((transportGr.members < 10) and (dropGr.members < 6) and (dropPhase == 0))
 
1777
        {
 
1778
                if(getStructure(vtolFactory,player) != NULLOBJECT)      //Already have VTOL tech to build transporter soon?
 
1779
                {
 
1780
                        if(dropEnabled and (not powerSaving))
 
1781
                        {
 
1782
                                initEnumStruct(FALSE,cybFactory,player,player);
 
1783
                                structure= enumStruct();                                        //Find factory
 
1784
                                while(structure != NULLOBJECT)
 
1785
                                {
 
1786
                                        if(structureIdle(structure))
 
1787
                                        {
 
1788
 
 
1789
                                //count = 1;            //numTemplates - 1
 
1790
                                //count2 = 0;
 
1791
                                //while(count >= 0)
 
1792
                                //{
 
1793
                                //      if(skCanBuildTemplate(player,structure, cybTmpl[count]) )
 
1794
                                //      {
 
1795
                                //              tmplChoice[count2] = cybTmpl[count];
 
1796
                                //              count2 = count2 + 1;
 
1797
                                //      }
 
1798
                                //      count = count - 1;
 
1799
                                //}
 
1800
 
 
1801
                                                if(cybTemplate > -1)
 
1802
                                                {
 
1803
                                                        buildDroid(cybTmpl[cybTemplate],structure,player,1);
 
1804
                                                }               
 
1805
                                        }
 
1806
                                        structure= enumStruct();
 
1807
                                }
 
1808
                        }
 
1809
                }
 
1810
        }
 
1811
 
 
1812
}
 
1813
 
 
1814
 
 
1815
//------------------------------------------------------
 
1816
//      Research Stuff
 
1817
//------------------------------------------------------
 
1818
event doResearch(doResearchTr)
 
1819
{
 
1820
        //Count how many are already researching
 
1821
        //--------------------------------------
 
1822
        initEnumStruct(FALSE,resLab,player,player);
 
1823
        structure = enumStruct();
 
1824
        result = 0;
 
1825
        while(structure != NULLOBJECT)
 
1826
        {
 
1827
                if(not structureIdle(structure))        //Max 2 res fac if low on power
 
1828
                {
 
1829
                        result = result + 1;
 
1830
                }
 
1831
                structure = enumStruct();
 
1832
        }
 
1833
 
 
1834
        temp = 2;               /*%!    ID="MaxResFacLowPower",
 
1835
                                        MainDesc="When low on power limit research to x facilities",
 
1836
                                        MoreInfo="<Help1>",
 
1837
                                        type="asn",             //Assign
 
1838
                                        val="2",
 
1839
                                        ArgDesc="2 (Default)",
 
1840
                                        val="0",
 
1841
                                        ArgDesc="Pause researching",
 
1842
                                        val="1",
 
1843
                                        ArgDesc="1",
 
1844
                                        val="3",
 
1845
                                        ArgDesc="3",
 
1846
                                        val="4",
 
1847
                                        ArgDesc="4",
 
1848
                                        val="5",
 
1849
                                        ArgDesc="5",
 
1850
                                        val="6",
 
1851
                                        ArgDesc="6",
 
1852
                                        val="7",
 
1853
                                        ArgDesc="7",
 
1854
                                        val="-1",
 
1855
                                        ArgDesc="Don't limit"   */
 
1856
 
 
1857
 
 
1858
        //Research
 
1859
        //--------
 
1860
        initEnumStruct(FALSE,resLab,player,player);
 
1861
        structure = enumStruct();
 
1862
        while(structure != NULLOBJECT)
 
1863
        {
 
1864
                if(structureIdle(structure))    //Not researching already
 
1865
                {
 
1866
                        if((not powerSaving) or (powerSaving and (result < temp)) or (temp == -1))              //Max 2 res fac if low on power (if enough power or low power, but still not enough res labs working)
 
1867
                        {
 
1868
                        
 
1869
                                if(not ((mainPhase >= 2) and (result >= 3) and (playerPower(player) < 600)))            //If we already have Trck Python HC template (and low on power) then don't use more then 3 res fac, since no new usefull tech
 
1870
                                {
 
1871
                                        skDoResearch(structure,player,0);
 
1872
                                        result = result + 1;
 
1873
                                }
 
1874
                        }
 
1875
                }
 
1876
                structure = enumStruct();
 
1877
        }
 
1878
}
 
1879
 
 
1880
 
 
1881
//------------------------------------------------------
 
1882
//      Build derricks with nearest truck
 
1883
//------------------------------------------------------
 
1884
event buildDerricks(inactive)
 
1885
{
 
1886
        //Find closest oil resource
 
1887
        //-------------------------
 
1888
        result = 99999;
 
1889
        feature2 = NULLOBJECT;
 
1890
        initGetFeature(oilRes,player,player);
 
1891
        feature = getFeature(player);
 
1892
        while(feature != NULLOBJECT)
 
1893
        {
 
1894
                //Make sure no other truck is  trying to build it
 
1895
                //-----------------------------------------------
 
1896
                boolResult = TRUE;
 
1897
                initIterateGroup(buildGroup);
 
1898
                droid = iterateGroup(buildGroup);
 
1899
                while((droid != NULLOBJECT) and (boolResult))
 
1900
                {
 
1901
                        if(droid.order == DORDER_BUILD)
 
1902
                        {
 
1903
                                if((droid.orderx == feature.x) and (droid.ordery == feature.y))
 
1904
                                {
 
1905
                                        boolResult = FALSE;
 
1906
                                }
 
1907
                        }
 
1908
                        droid = iterateGroup(buildGroup);
 
1909
                }
 
1910
 
 
1911
                //Make sure there are no enemy units and defenses nearby
 
1912
                if(boolResult)
 
1913
                {
 
1914
                        temp = (13 * 128);
 
1915
                        count = 0;
 
1916
                        while((count < numEnemies) and (boolResult))
 
1917
                        {
 
1918
                                resetStructTargets();
 
1919
                                setStructTarPref(ST_DEF_GROUND);
 
1920
 
 
1921
                                //if(numStructsByTypeInArea(Enemies[count], REF_DEFENSE, feature.x - temp, feature.y - temp, feature.x + temp, feature.y + temp) > 0)
 
1922
 
 
1923
                                structure = structTargetInArea(Enemies[count], Enemies[count], feature.x - temp, feature.y - temp, feature.x + temp, feature.y + temp);
 
1924
                                if(structure != NULLOBJECT)
 
1925
                                {
 
1926
                                        boolResult = FALSE;             //Too dangerous
 
1927
                                }
 
1928
                                else
 
1929
                                {
 
1930
                                        resetDroidTargets();
 
1931
                                        setDroidTarPref(DT_WEAP_GROUND);
 
1932
                                        droid = droidTargetInArea(Enemies[count], Enemies[count], feature.x - temp, feature.y - temp, feature.x + temp, feature.y + temp);
 
1933
                                        if(droid != NULLOBJECT)
 
1934
                                        {
 
1935
                                                boolResult = FALSE;             //Too dangerous
 
1936
                                        }
 
1937
                                }
 
1938
                                
 
1939
                                count = count + 1;
 
1940
                        }
 
1941
                }
 
1942
 
 
1943
                //Remember closest structure
 
1944
                //--------------------------
 
1945
                if(boolResult)          //If not trying to build already and no enemy defenses
 
1946
                {
 
1947
                        result2 = distBetweenTwoPoints(baseX, baseY, feature.x, feature.y);             //How close to the base
 
1948
                        if(result2 < result)                    //If closer
 
1949
                        {
 
1950
                                result = result2;
 
1951
                                feature2 = feature;                     //Remember this oil resource
 
1952
                        }
 
1953
                }
 
1954
 
 
1955
                feature = getFeature(player);
 
1956
        }
 
1957
 
 
1958
        //Build oil derrick
 
1959
        //-----------------
 
1960
        if(feature2 != NULLOBJECT)
 
1961
        {
 
1962
                //Find closest truck
 
1963
                //------------------
 
1964
                tempDroid = NULLOBJECT;
 
1965
                result = 99999;
 
1966
                initIterateGroup(buildGroup);
 
1967
                droid = iterateGroup(buildGroup);
 
1968
                while(droid != NULLOBJECT)
 
1969
                {
 
1970
                        if(droid.order == DORDER_NONE)
 
1971
                        {
 
1972
                                result2 = distBetweenTwoPoints(droid.x, droid.y, feature2.x, feature2.y);
 
1973
                                if(result2 < result)
 
1974
                                {
 
1975
                                        result = result2;
 
1976
                                        tempDroid = droid;
 
1977
                                }
 
1978
                        }
 
1979
                        droid = iterateGroup(buildGroup);
 
1980
                }
 
1981
 
 
1982
                //Build derrick
 
1983
                //-------------
 
1984
                if(tempDroid != NULLOBJECT)
 
1985
                {
 
1986
                        orderDroidStatsLoc(tempDroid, DORDER_BUILD,derrick, feature2.x, feature2.y);
 
1987
                }
 
1988
        }
 
1989
}
 
1990
 
 
1991
 
 
1992
//------------------------------------------------------
 
1993
//      Send scouts to look for oil resources
 
1994
//------------------------------------------------------
 
1995
event sendScouts(sendScoutsTr)
 
1996
{
 
1997
        count = 0;
 
1998
        temp = (43 * 128);              //Step
 
1999
 
 
2000
        while(count < maxScouts)
 
2001
        {
 
2002
                if(scoutGroup[count].members > 0)
 
2003
                {
 
2004
                        if(idleGroup(scoutGroup[count]) > (scoutGroup[count].members /2))
 
2005
                        {
 
2006
                                if(count > 1)   //3rd scout vitits random places (only on big maps)
 
2007
                                {
 
2008
                                        tempX = random(mapWidth) * 128;
 
2009
                                        tempY = random(mapHeight) * 128;
 
2010
                                        boolResult = pickStructLocation(vtolPad, ref tempX, ref tempY,player);
 
2011
                                        if(boolResult == TRUE)
 
2012
                                        {
 
2013
                                                orderGroupLoc(scoutGroup[count], DORDER_MOVE, tempX, tempY);
 
2014
                                        }
 
2015
                                }
 
2016
                                else            //Using a scouting algorithm for the first 2 scouts
 
2017
                                {
 
2018
                                        //Send to scout before choosing new coords, so that
 
2019
                                        //they would visit the initial (first) location
 
2020
                                        //-------------------------------------------------
 
2021
                                        tempX = scoutX[count];
 
2022
                                        tempY = scoutY[count];
 
2023
                                        boolResult = pickStructLocation(vtolPad, ref tempX, ref tempY,player);
 
2024
                                        if(boolResult == TRUE)
 
2025
                                        {
 
2026
                                                orderGroupLoc(scoutGroup[count], DORDER_MOVE, tempX, tempY);
 
2027
                                        }
 
2028
 
 
2029
 
 
2030
                                        //Try 3 times to find a safe scouting location
 
2031
                                        //--------------------------------------------
 
2032
                                        boolResult = FALSE;
 
2033
                                        result = 0;             //Number of times failed to find safe location
 
2034
                                        while((result < 3) and (not boolResult))        //May fail max 3 times
 
2035
                                        {
 
2036
                                                if(count == 0)  //SCOUT1: From bottom left to the top
 
2037
                                                {
 
2038
                                                        scoutY[count] = scoutY[count] - temp;   //Move up 1 step
 
2039
                                                        if(scoutY[count] < 512)                 //If reached top
 
2040
                                                        {
 
2041
                                                                scoutY[count] = (128 * mapHeight) - (9 * 128);  //Back to bottom
 
2042
                                                                scoutX[count] = scoutX[count] + temp;           //Move right 1 step
 
2043
                                                        }
 
2044
 
 
2045
                                                        if(scoutX[count] > (mapWidth * 128))    //If reached right border
 
2046
                                                        {
 
2047
                                                                scoutX[count] = (9 * 128);              //Start from the left
 
2048
                                                        }
 
2049
 
 
2050
                                                }
 
2051
                                                else    //SCOUT2: From top right to the left
 
2052
                                                {
 
2053
                                                        scoutX[count] = scoutX[count] - temp;   //Move left 1 step
 
2054
                                                        if(scoutX[count] < 512)                 //If reached left border
 
2055
                                                        {
 
2056
                                                                scoutX[count] = (mapWidth * 128) - (9 * 128);           //Start from right
 
2057
                                                                scoutY[count] = scoutY[count] + temp;   //Move line down
 
2058
                                                        }
 
2059
 
 
2060
                                                        if(scoutY[count] > (128 * mapHeight))           //If reached bottom
 
2061
                                                        {
 
2062
                                                                scoutY[count] = (9 * 128);              //Start from top
 
2063
                                                        }
 
2064
                                                }
 
2065
 
 
2066
 
 
2067
                                                //Check if new scouting location is safe
 
2068
                                                //--------------------------------------
 
2069
                                                count2 = 0;
 
2070
                                                boolResult = TRUE;              //All ok right now (for max tries)
 
2071
                                                while((count2 < numEnemies) and (boolResult))
 
2072
                                                {
 
2073
                                                        if(objectInRange(Enemies[count2], scoutX[count],scoutY[count], 1280))   //10*128
 
2074
                                                        {
 
2075
                                                                boolResult = FALSE;             //This location failed this time
 
2076
                                                                result = result + 1;            //# of times safety check failed
 
2077
                                                        }
 
2078
                                                        count2 = count2 + 1;    //Next enemy
 
2079
                                                }
 
2080
                                        }
 
2081
                                }
 
2082
                        }
 
2083
                }
 
2084
                count = count + 1;
 
2085
        }
 
2086
}
 
2087
 
 
2088
 
 
2089
//------------------------------------------------------
 
2090
//      Build base
 
2091
//------------------------------------------------------
 
2092
event expandBase(inactive)
 
2093
{
 
2094
        //if(not powerSaving)
 
2095
        //{
 
2096
                if(extraStruct == numExtraStructs)      // loop round
 
2097
                {
 
2098
                        extraStruct = 0;
 
2099
                }
 
2100
 
 
2101
                //We have all vital structures, expand the base
 
2102
                //---------------------------------------------
 
2103
                boolResult = FALSE;
 
2104
                if(isStructureAvailable(extraStructs[extraStruct],player))
 
2105
                {
 
2106
                        buildX = baseX;
 
2107
                        buildY = baseY;
 
2108
 
 
2109
                        //Don't try to build a second HQ
 
2110
                        //------------------------------
 
2111
                        boolResult2 = TRUE;
 
2112
                        if(extraStruct == 2)    //HQ
 
2113
                        {
 
2114
                                if(getStructure(extraStructs[2],player) != NULLOBJECT)
 
2115
                                {
 
2116
                                        boolResult2 = FALSE;
 
2117
                                }
 
2118
                        }
 
2119
 
 
2120
                        boolResult = FALSE;
 
2121
                        if(boolResult2)         //If not a second HQ
 
2122
                        {
 
2123
                                boolResult2 = pickStructLocation(extraStructs[extraStruct], ref buildX, ref buildY,player);
 
2124
                                if(boolResult2 == TRUE)
 
2125
                                {
 
2126
                                        boolResult = TRUE;
 
2127
                                }
 
2128
                        }
 
2129
                }
 
2130
 
 
2131
                if(boolResult)
 
2132
                {
 
2133
                        result = 99999;
 
2134
                        tempDroid = NULLOBJECT;
 
2135
 
 
2136
                        initIterateGroup(buildGroup);
 
2137
                        droid = iterateGroup(buildGroup);
 
2138
                        while(droid != NULLOBJECT)
 
2139
                        {
 
2140
                                if(droid.order == DORDER_NONE)
 
2141
                                {
 
2142
                                        result2 = distBetweenTwoPoints(buildX, buildY, droid.x, droid.y);
 
2143
                                        if(result2 < result)
 
2144
                                        {
 
2145
                                                result = result2;
 
2146
                                                tempDroid = droid;
 
2147
                                        }
 
2148
                                }
 
2149
                                droid = iterateGroup(buildGroup);
 
2150
                        }
 
2151
 
 
2152
                        if(tempDroid != NULLOBJECT)
 
2153
                        {
 
2154
                                orderDroidStatsLoc(tempDroid, DORDER_BUILD,extraStructs[extraStruct], buildX,buildY);
 
2155
                        }
 
2156
                }
 
2157
                extraStruct = extraStruct + 1;          //Next structure
 
2158
        //}
 
2159
}
 
2160
 
 
2161
 
 
2162
//------------------------------------------------------
 
2163
//      Build base defenses
 
2164
//------------------------------------------------------
 
2165
event buildDefenses(inactive)
 
2166
{
 
2167
        if(not powerSaving)
 
2168
        {
 
2169
                count = numDefenses - 1;
 
2170
                count2 = 0;
 
2171
                boolResult = TRUE;
 
2172
                while((boolResult == TRUE) and (count >= 0))
 
2173
                {
 
2174
                        if(isStructureAvailable(defenses[count],player))
 
2175
                        {
 
2176
                                structChoice[0] = defenses[count];
 
2177
                                boolResult = FALSE;
 
2178
                        }
 
2179
                        count = count - 1;
 
2180
                }
 
2181
 
 
2182
                if(boolResult == FALSE)
 
2183
                {
 
2184
                        buildX = baseX;
 
2185
                        buildY = baseY;
 
2186
                        boolResult2 = pickStructLocation(powGen, ref buildX, ref buildY,player);
 
2187
                        if(boolResult2 == TRUE)
 
2188
                        {
 
2189
                                result = 99999;
 
2190
                                tempDroid = NULLOBJECT;
 
2191
 
 
2192
                                initIterateGroup(buildGroup);
 
2193
                                droid = iterateGroup(buildGroup);
 
2194
                                while(droid != NULLOBJECT)              //Find truck who is near the oil resource
 
2195
                                {
 
2196
                                        if(droid.order == DORDER_NONE)
 
2197
                                        {
 
2198
                                                result2 = distBetweenTwoPoints(buildX, buildY, droid.x, droid.y);
 
2199
                                                if(result2 < result)
 
2200
                                                {
 
2201
                                                        result = result2;
 
2202
                                                        tempDroid = droid;
 
2203
                                                }
 
2204
                                        }
 
2205
                                        droid = iterateGroup(buildGroup);
 
2206
                                }
 
2207
 
 
2208
                                if(tempDroid != NULLOBJECT)
 
2209
                                {
 
2210
                                        orderDroidStatsLoc(tempDroid, DORDER_BUILD,structChoice[0], buildX,buildY);
 
2211
                                }
 
2212
                        }
 
2213
                }
 
2214
        }
 
2215
}
 
2216
 
 
2217
 
 
2218
//------------------------------------------------------
 
2219
//      Build oil defenses
 
2220
//------------------------------------------------------
 
2221
event oilDefenses(inactive)
 
2222
{
 
2223
        if(not powerSaving)
 
2224
        {
 
2225
                temp = (4 * 128);               //Defenses range
 
2226
                result = 99999;
 
2227
                boolResult = TRUE;
 
2228
                structure2 = NULLOBJECT;
 
2229
 
 
2230
                initEnumStruct(FALSE,derrick,player,player);
 
2231
                structure = enumStruct();
 
2232
                while(structure != NULLOBJECT)
 
2233
                {
 
2234
                        result2 = distBetweenTwoPoints(baseX, baseY, structure.x, structure.y);
 
2235
                        if(result2 < result)
 
2236
                        {
 
2237
                                boolResult = TRUE;
 
2238
 
 
2239
                                //If not within a base
 
2240
                                //--------------------
 
2241
                                if((structure.x > minx) and (structure.y > miny) and (structure.x < maxx) and (structure.y <maxy))
 
2242
                                {
 
2243
                                        boolResult = FALSE;
 
2244
                                }
 
2245
 
 
2246
                                //If not to many defenses already
 
2247
                                //-------------------------------
 
2248
                                if(boolResult == TRUE)
 
2249
                                {
 
2250
                                        if(numStructsInArea(player, structure.x - temp, structure.y - temp, structure.x + temp, structure.y + temp) > 3)
 
2251
                                        {
 
2252
                                                boolResult = FALSE;
 
2253
                                        }
 
2254
                                }
 
2255
 
 
2256
                                //Choose best defense
 
2257
                                //-------------------
 
2258
                                if(boolResult == TRUE)
 
2259
                                {
 
2260
                                        count = numDefenses - 1;
 
2261
                                        boolResult = FALSE;
 
2262
                                        while((count >= 0) and (boolResult == FALSE))
 
2263
                                        {
 
2264
                                                if(isStructureAvailable(defenses[count], player))
 
2265
                                                {
 
2266
                                                        structChoice[0] = defenses[count];
 
2267
                                                        boolResult = TRUE;                      //Stop
 
2268
                                                }
 
2269
                                                count = count - 1;
 
2270
                                        }
 
2271
                                }
 
2272
 
 
2273
                                if(boolResult == TRUE)
 
2274
                                {
 
2275
                                        //If we have a derrick to defend
 
2276
                                        //------------------------------
 
2277
                                        boolResult = FALSE;
 
2278
                                        result3 = 99999;
 
2279
                                        tempDroid = NULLOBJECT;
 
2280
 
 
2281
                                        initIterateGroup(buildGroup);
 
2282
                                        droid = iterateGroup(buildGroup);
 
2283
                                        while(droid != NULLOBJECT)
 
2284
                                        {
 
2285
                                                if(droid.order == DORDER_NONE)
 
2286
                                                {
 
2287
                                                        result4 = distBetweenTwoPoints(structure.x, structure.y, droid.x, droid.y);
 
2288
                                                        if(result4 < result3)
 
2289
                                                        {
 
2290
                                                                boolResult = TRUE;
 
2291
                                                                result3 = result4;
 
2292
                                                                tempDroid = droid;
 
2293
                                                        }
 
2294
                                                }
 
2295
                                                droid = iterateGroup(buildGroup);
 
2296
                                        }
 
2297
                                }
 
2298
 
 
2299
                                //If we have a droid
 
2300
                                //------------------
 
2301
                                if(boolResult == TRUE)
 
2302
                                {
 
2303
                                        buildX = structure.x;
 
2304
                                        buildY = structure.y;
 
2305
                                        boolResult = pickStructLocation(structChoice[0], ref buildX, ref buildY,player);
 
2306
                                        if(boolResult == TRUE)
 
2307
                                        {
 
2308
                                                boolResult = FALSE;
 
2309
                                                if((buildX > structure.x - temp) and (buildY > structure.y - temp) and (buildX < structure.x + temp) and (buildY < structure.y + temp))         //If in the range
 
2310
                                                {
 
2311
                                                        boolResult = TRUE;
 
2312
                                                }
 
2313
                                        }
 
2314
                                }
 
2315
 
 
2316
                                if(boolResult == TRUE)
 
2317
                                {
 
2318
                                        result = result2;
 
2319
                                        structure2 = structure;
 
2320
                                }
 
2321
                        }
 
2322
                        structure = enumStruct();
 
2323
                }
 
2324
 
 
2325
                //If we can build it now
 
2326
                //----------------------
 
2327
                if((structure2 != NULLOBJECT) and (tempDroid != NULLOBJECT))
 
2328
                {
 
2329
                        orderDroidStatsLoc(tempDroid, DORDER_BUILD, structChoice[0], buildX, buildY);
 
2330
                }
 
2331
        }
 
2332
}
 
2333
 
 
2334
//------------------------------------------------------
 
2335
//      Keep details about the size and postion of the
 
2336
//      ai players base
 
2337
//------------------------------------------------------
 
2338
event basedetails(basedetailsTr)
 
2339
{
 
2340
        // clear old extremities
 
2341
        //----------------------
 
2342
        maxy = 0;
 
2343
        maxx = 0;
 
2344
        miny = (mapHeight*128);
 
2345
        minx = (mapWidth*128);
 
2346
 
 
2347
        //Now find the extremities of our vital structures
 
2348
        //------------------------------------------------
 
2349
        count = 0;
 
2350
        while(count < numBaseStructs)
 
2351
        {
 
2352
                initEnumStruct(FALSE,baseStructs[count],player,player);                                 
 
2353
                structure = enumStruct();
 
2354
                while(structure != NULLOBJECT)  
 
2355
                {
 
2356
                        if(structure.x < minx)
 
2357
                        {
 
2358
                                minx = structure.x;     // - 896;
 
2359
                        }
 
2360
                        if(structure.x > maxx)
 
2361
                        {
 
2362
                                maxx = structure.x;     // + 896;       
 
2363
                        }
 
2364
                        if(structure.y < miny)
 
2365
                        {
 
2366
                                miny = structure.y;     // - 896;
 
2367
                        }
 
2368
                        if(structure.y > maxy)
 
2369
                        {
 
2370
                                maxy = structure.y;     // + 896;
 
2371
                        }
 
2372
                        structure = enumStruct();
 
2373
                }
 
2374
                count = count + 1;
 
2375
        }
 
2376
 
 
2377
        //Must be done here, after all structures are checked, otherwise
 
2378
        //even if structure2.x < structure.x, (structure.x - minx) might be less and minx won't be set to
 
2379
        //structure2.x, even if (structure2.x < structure.x), base won't expand enough
 
2380
        //--------------------------------
 
2381
 
 
2382
        temp = 7;
 
2383
        if(bigMap)
 
2384
        {
 
2385
                temp = 11 * 128;
 
2386
        }
 
2387
 
 
2388
        minx = minx - temp;
 
2389
        maxx = maxx + temp;
 
2390
        miny = miny - temp;
 
2391
        maxy = maxy + temp;
 
2392
 
 
2393
        //minx = minx - 896;
 
2394
        //maxx = maxx + 896;
 
2395
        //miny = miny - 896;
 
2396
        //maxy = maxy + 896;
 
2397
 
 
2398
        //Check everything's within limits
 
2399
        //--------------------------------
 
2400
        if(minx < 0)
 
2401
        {
 
2402
                minx = 128;
 
2403
        }
 
2404
        if(miny < 0)
 
2405
        {
 
2406
                miny = 128;
 
2407
        }
 
2408
        if(maxx > (mapWidth * 128))
 
2409
        {
 
2410
                maxx = (mapWidth * 128) - 128;
 
2411
        }
 
2412
        if(maxy > (mapHeight * 128))
 
2413
        {
 
2414
                maxy = (mapHeight * 128) - 128;
 
2415
        }
 
2416
}
 
2417
 
 
2418
 
 
2419
//==============================================================================================
 
2420
//
 
2421
//                              [Other stuff important for all phases]
 
2422
//
 
2423
//==============================================================================================
 
2424
 
 
2425
//------------------------------------------------------
 
2426
//      Keep track on the other players
 
2427
//------------------------------------------------------
 
2428
event keepTrack(keepTrackTr)
 
2429
{
 
2430
        numEnemies = 0;
 
2431
        count = 0;
 
2432
        while(count < 8)
 
2433
        {
 
2434
                allyPlayer[count] = FALSE;
 
2435
                actPlayer[count] = FALSE;
 
2436
 
 
2437
                if(count != player)     //Not me
 
2438
                {
 
2439
 
 
2440
                        //Check if player has any structures (still alive)
 
2441
                        //------------------------------------------------
 
2442
                        boolResult = FALSE;
 
2443
                        count2 = 0;
 
2444
                        while((count2 < numBaseStructs) and (not boolResult))           //For all base structures
 
2445
                        {
 
2446
                                if(getStructure(baseStructs[count2],count) != NULLOBJECT)
 
2447
                                {
 
2448
                                        boolResult = TRUE;
 
2449
                                }
 
2450
                                count2 = count2 + 1;
 
2451
                        }
 
2452
 
 
2453
                        if(boolResult)          //If alive
 
2454
                        {
 
2455
                                actPlayer[count] = TRUE;
 
2456
 
 
2457
                                //Not enemy
 
2458
                                if(allianceExistsBetween(player,count))
 
2459
                                {
 
2460
                                        allyPlayer[count] = TRUE;
 
2461
                                }
 
2462
                                else    //Enemy
 
2463
                                {
 
2464
                                        //Find enemy's base by finding its base structures
 
2465
                                        Enemies[numEnemies] = count;    //Remember all enemies
 
2466
                                        numEnemies = numEnemies + 1;
 
2467
                                }
 
2468
                        }
 
2469
 
 
2470
                }
 
2471
                count = count + 1;
 
2472
        }
 
2473
}
 
2474
 
 
2475
//------------------------------------------------------
 
2476
//      Deal with a droid being destroyed
 
2477
//------------------------------------------------------
 
2478
event droidDestroyed(droidDestroyedTr)
 
2479
{
 
2480
        count = 0;      //Do nothing
 
2481
 
 
2482
        //if(droid.droidType == DROID_CONSTRUCT)
 
2483
        //{
 
2484
        //      if(droid != outpostDroid)               //If wasn't outpost builder (will outpostDroid be NULLOBJECT already?)
 
2485
        //      {
 
2486
        //              numTrucks = numTrucks - 1;
 
2487
        //      }
 
2488
        //}
 
2489
}
 
2490
 
 
2491
 
 
2492
//------------------------------------------------------
 
2493
//      Build a power gen for every 4 derricks
 
2494
//------------------------------------------------------
 
2495
event buildPowerGenerators(buildPowerGeneratorsTr)
 
2496
{
 
2497
        count = 0;
 
2498
        initEnumStruct(FALSE,derrick,player,player);    // count = numderricks
 
2499
        structure = enumStruct();
 
2500
        while(structure != NULLOBJECT)  
 
2501
        {
 
2502
                count = count + 1;
 
2503
                structure = enumStruct();
 
2504
        }
 
2505
 
 
2506
        count2 = 0;     
 
2507
        initEnumStruct(FALSE,powGen,player,player);     // count2 = numpowgens
 
2508
        structure= enumStruct();
 
2509
        while(structure != NULLOBJECT)  
 
2510
        {
 
2511
                count2 = count2 + 1;
 
2512
                structure= enumStruct();
 
2513
        }
 
2514
                                                                
 
2515
        if((count2 * 4) < count)                        // if we need powergen
 
2516
        {
 
2517
                buildX = baseX;                         // try build powergen
 
2518
                buildY = baseY;
 
2519
                boolResult = pickStructLocation(powGen, ref buildX, ref buildY,player);
 
2520
                if(boolResult == TRUE)
 
2521
                {
 
2522
                        result = 999999;
 
2523
                        tempDroid = NULLOBJECT;
 
2524
 
 
2525
                        initIterateGroup(buildGroup);
 
2526
                        droid = iterateGroup(buildGroup);
 
2527
                        while(droid != NULLOBJECT)      //Find truck who is near the oil resource
 
2528
                        {
 
2529
                                if(droid.order == DORDER_NONE)
 
2530
                                {
 
2531
                                        result2 = distBetweenTwoPoints(buildX, buildY, droid.x, droid.y);
 
2532
                                        if(result2 < result)
 
2533
                                        {
 
2534
                                                result = result2;
 
2535
                                                tempDroid = droid;
 
2536
                                        }
 
2537
                                }
 
2538
                                droid = iterateGroup(buildGroup);
 
2539
                        }
 
2540
 
 
2541
                        if(tempDroid != NULLOBJECT)
 
2542
                        {
 
2543
                                orderDroidStatsLoc(tempDroid, DORDER_BUILD,powGen, buildX,buildY);
 
2544
                        }
 
2545
                }
 
2546
        }
 
2547
}
 
2548
 
 
2549
 
 
2550
//------------------------------------------------------
 
2551
//      Build trucks if necessary
 
2552
//------------------------------------------------------
 
2553
event LegoTrucks(LegoTrucksTr)
 
2554
{
 
2555
        initEnumStruct(FALSE,factory,player,player);
 
2556
        structure = enumStruct();
 
2557
        if((structure != NULLOBJECT) and (buildGroup.members < maxTrucks))
 
2558
        {
 
2559
                if(structureIdle(structure))
 
2560
                {
 
2561
                        buildDroid(constructor, structure, player, 1);
 
2562
                }
 
2563
        }
 
2564
}
 
2565
 
 
2566
 
 
2567
//------------------------------------------------------
 
2568
//      Deal with a droid being built
 
2569
//------------------------------------------------------
 
2570
event droidBuilt(droidBuiltTr)
 
2571
{
 
2572
 
 
2573
        if(droid.droidType == DROID_CONSTRUCT)          // if constructor droid 
 
2574
        {       
 
2575
                groupAddDroid(buildGroup, droid);
 
2576
        }
 
2577
        else if((droid.droidType == DROID_CYBORG) or (droid.propulsion == cyborgProp))  //Cyborg or heavy cyborg
 
2578
        {
 
2579
                groupAddDroid(transportGr, droid);
 
2580
        }
 
2581
        else if(droid.droidType == DROID_TRANSPORTER)
 
2582
        {
 
2583
                //if(transportDroid == NULLOBJECT)
 
2584
                //{
 
2585
                        transportDroid = droid;
 
2586
                        orderDroidLoc(transportDroid, DORDER_MOVE, baseX, baseY);
 
2587
                        //setDroidSecondary(transportDroid, DSO_ATTACK_LEVEL, DSS_ALEV_NEVER);
 
2588
                //}
 
2589
                
 
2590
        }
 
2591
        else
 
2592
        {
 
2593
                setDroidSecondary(droid, DSO_ATTACK_RANGE, DSS_ARANGE_LONG);
 
2594
 
 
2595
                if(isVtol(droid))
 
2596
                {
 
2597
                        orderDroid(droid, DORDER_RTB);  //Move away
 
2598
 
 
2599
                        //Check weapon
 
2600
                        count = 0;
 
2601
                        boolResult = FALSE;
 
2602
                        while((count < numSVtolTemplates) and (not boolResult))
 
2603
                        {
 
2604
                                if(droid.weapon == sVtolWeapon[count])
 
2605
                                {
 
2606
                                        //setFogColour(1, 1, random(200) + 50);
 
2607
                                        boolResult = TRUE;
 
2608
                                        groupAddDroid(sVtolGr, droid);  //Antistructure
 
2609
                                        //setFogColour(random(200) + 50, 1, 1);
 
2610
                                }
 
2611
                                count = count + 1;
 
2612
                        }
 
2613
 
 
2614
                        //Antitank
 
2615
                        if(not boolResult)
 
2616
                        {
 
2617
                                groupAddDroid(tVtolGr, droid);
 
2618
                        }
 
2619
                }
 
2620
                else
 
2621
                {
 
2622
                        boolResult = TRUE;
 
2623
                        setDroidSecondary(droid, DSO_ATTACK_RANGE, DSS_ARANGE_LONG);    //Was short
 
2624
 
 
2625
                        //Repair unit
 
2626
                        //---------------------------
 
2627
                        if(droid.droidType == DROID_REPAIR)
 
2628
                        {
 
2629
                                setDroidSecondary(droid, DSO_REPAIR_LEVEL, DSS_REPLEV_NEVER);   //Perair units never repair
 
2630
 
 
2631
                                if(repDefendDroid[0] == NULLOBJECT)
 
2632
                                {
 
2633
                                        repDefendDroid[0] = droid;
 
2634
                                        boolResult = FALSE;
 
2635
                                }
 
2636
                                else if(repDefendDroid[1] == NULLOBJECT)
 
2637
                                {
 
2638
                                        repDefendDroid[1] = droid;
 
2639
                                        boolResult = FALSE;
 
2640
                                }
 
2641
                        }
 
2642
 
 
2643
                        //Scouts
 
2644
                        //---------------------------
 
2645
                        count = 0;
 
2646
                        while((count < maxScouts) and (boolResult))
 
2647
                        {
 
2648
                                if(scoutGroup[count].members == 0)
 
2649
                                {
 
2650
                                        groupAddDroid(scoutGroup[count], droid);
 
2651
                                        boolResult = FALSE;
 
2652
                                }
 
2653
                                count = count + 1;
 
2654
                        }
 
2655
 
 
2656
                        //Random scout (#3)
 
2657
                        if(boolResult)
 
2658
                        {
 
2659
                                if(scoutGroup[2].members == 0)
 
2660
                                {
 
2661
                                        if(((attackGroup.members + sendOutpostGr.members) > numRushers) and (defendGr.members >= maxDefenders))
 
2662
                                        {
 
2663
                                                groupAddDroid(scoutGroup[2], droid);
 
2664
                                                boolResult = FALSE;
 
2665
                                        }
 
2666
                                }
 
2667
                        }
 
2668
 
 
2669
 
 
2670
                        //Defenders
 
2671
                        //---------------------------
 
2672
                        if(boolResult)
 
2673
                        {
 
2674
                                //if((attackPhase > 0) or (alreadyAttacked))    //Send to attack for the first time or not attacking right now, but attacked before (attackState=0, but alreadyAttacked)
 
2675
                                if(alreadyAttacked)             //Already sent units to the outpost
 
2676
                                {
 
2677
                                        if(((attackGroup.members > numRushers) and (defendGr.members < maxDefenders)) or (defendGr.members < 7) or (defendingBase))
 
2678
                                        {
 
2679
                                                if(defendGr.members < maxDefenders)
 
2680
                                                {
 
2681
                                                        groupAddDroid(defendGr, droid);
 
2682
                                                        boolResult = FALSE;
 
2683
                                                }
 
2684
                                        }
 
2685
                                }
 
2686
                        }
 
2687
 
 
2688
 
 
2689
                        //Defenders
 
2690
                        //---------------------------
 
2691
                        //if(boolResult and ((attackGroup.members >= numRushers) or ((attackPhase > 0) and (defendGr.members < 5))))    //If already many rushers or (have already rushed and not enough defenders)
 
2692
                        //{
 
2693
                        //      if(defendGr.members < maxDefenders)
 
2694
                        //      {
 
2695
                        //              if(mainPhase > 0)
 
2696
                        //              {
 
2697
                        //                      groupAddDroid(defendGr, droid);
 
2698
                        //                      boolResult = FALSE;
 
2699
                        //              }
 
2700
                        //      }
 
2701
                        //}
 
2702
 
 
2703
 
 
2704
                        //Oil
 
2705
                        //---------------------------
 
2706
                        if(boolResult and (attackGroup.members > numRushers))
 
2707
                        {
 
2708
                                if(oilGr.members < maxOilGr)
 
2709
                                {
 
2710
                                        groupAddDroid(oilGr, droid);
 
2711
                                        boolResult = FALSE;
 
2712
                                }
 
2713
                        }
 
2714
 
 
2715
                        //Attackers
 
2716
                        //---------------------------
 
2717
                        if(boolResult)
 
2718
                        {
 
2719
                                groupAddDroid(collectSendGr, droid);
 
2720
                                boolResult = FALSE;
 
2721
                                //groupAddDroid(sendOutpostGr, droid);
 
2722
                        }
 
2723
 
 
2724
                        //Increase number of defenders
 
2725
                        //----------------------------
 
2726
                        if(attackGroup.members > numRushers)
 
2727
                        {
 
2728
                                if((defendGr.members >= maxDefenders) and (maxDefenders < 14) and (alreadyAttacked))    //(attackPhase > 0): if we have already enough attackers and started attacking
 
2729
                                {
 
2730
                                        maxDefenders = maxDefenders + 1;
 
2731
                                }
 
2732
                        }
 
2733
                }
 
2734
        }
 
2735
}
 
2736
 
 
2737
 
 
2738
//------------------------------------------------------
 
2739
//      Cheat a bit, like Pumpkin AI, not more
 
2740
//------------------------------------------------------
 
2741
event difficultyMod(difficultyModTr)
 
2742
{
 
2743
        skDifficultyModifier(player);
 
2744
        randomiseSeed();                //Will not hurt if done once in a while
 
2745
}
 
2746
 
 
2747
 
 
2748
//------------------------------------------------------
 
2749
//      Upgrade structures
 
2750
//------------------------------------------------------
 
2751
event upgradeStructures(upgradeStructuresTr)
 
2752
{
 
2753
 
 
2754
        //Find closest truck
 
2755
        //-------------------
 
2756
        tempX = baseX;
 
2757
        tempY = baseY;
 
2758
        result = 999999;
 
2759
        tempDroid = NULLOBJECT;
 
2760
        boolResult = TRUE;
 
2761
 
 
2762
        initIterateGroup(buildGroup);
 
2763
        droid = iterateGroup(buildGroup);
 
2764
        while(droid != NULLOBJECT)
 
2765
        {
 
2766
                if(droid.order == DORDER_NONE)
 
2767
                {
 
2768
                        result2 = distBetweenTwoPoints(tempX, tempY, droid.x, droid.y);
 
2769
                        if(result2 < result)
 
2770
                        {
 
2771
                                result = result2;
 
2772
                                tempDroid = droid;
 
2773
                        }
 
2774
                }
 
2775
                droid = iterateGroup(buildGroup);
 
2776
        }
 
2777
 
 
2778
        //------------------
 
2779
        //      Factory
 
2780
        //-----------------
 
2781
        initEnumStruct(FALSE,factory,player,player);
 
2782
        structure= enumStruct();
 
2783
        while(structure != NULLOBJECT)  
 
2784
        {
 
2785
                if(structureComplete(structure))
 
2786
                {
 
2787
                        if(isStructureAvailable(facModule,player) and (skGetFactoryCapacity(structure) < 2 ))                   
 
2788
                        {
 
2789
                                if((attackPhase > 0) or (skCanBuildTemplate(player,structure, tmpl[0][8])))     //Don't upgrade while preparing the first rush or upgrade if it's necessary to be able to build units in T3
 
2790
                                {
 
2791
                                        if(tempDroid != NULLOBJECT)
 
2792
                                        {
 
2793
                                                boolResult = FALSE;
 
2794
                                                orderDroidStatsLoc(tempDroid, DORDER_BUILD,facModule, structure.x,structure.y);
 
2795
                                        }
 
2796
                                }
 
2797
                        }
 
2798
                }
 
2799
                structure= enumStruct();
 
2800
        }
 
2801
 
 
2802
        //------------------
 
2803
        //      Powergen
 
2804
        //------------------
 
2805
        initEnumStruct(FALSE,powGen,player,player);
 
2806
        structure= enumStruct();
 
2807
        while(structure != NULLOBJECT)
 
2808
        {
 
2809
                if(structureComplete(structure))
 
2810
                {
 
2811
                        if(isStructureAvailable(powModule,player) and (not testStructureModule(player, structure, 0)))                  
 
2812
                        {
 
2813
                                if((tempDroid != NULLOBJECT) and (boolResult == TRUE))
 
2814
                                {
 
2815
                                        boolResult = FALSE;
 
2816
                                        orderDroidStatsLoc(tempDroid,DORDER_BUILD,powModule, structure.x,structure.y);  //Upgrade it.
 
2817
                                }
 
2818
                        }
 
2819
                }
 
2820
                structure= enumStruct();
 
2821
        }
 
2822
 
 
2823
        //-----------------
 
2824
        //      Research
 
2825
        //-----------------
 
2826
        if(not powerSaving)
 
2827
        {
 
2828
                initEnumStruct(FALSE,resLab,player,player);
 
2829
                structure= enumStruct();
 
2830
                while(structure != NULLOBJECT)  
 
2831
                {
 
2832
                        if(structureComplete(structure))
 
2833
                        {
 
2834
                                if( isStructureAvailable(resModule,player) and (not testStructureModule(player, structure, 0)))                 
 
2835
                                {
 
2836
                                        if((tempDroid != NULLOBJECT) and (boolResult == TRUE))
 
2837
                                        {
 
2838
                                                boolResult = FALSE;
 
2839
                                                orderDroidStatsLoc(tempDroid, DORDER_BUILD,resModule, structure.x,structure.y);
 
2840
                                        }
 
2841
                                }
 
2842
                        }
 
2843
                        structure= enumStruct();
 
2844
                }
 
2845
 
 
2846
                //-------------------
 
2847
                //      VTOL Factory
 
2848
                //-------------------
 
2849
                if(not powerSaving)
 
2850
                {
 
2851
                        initEnumStruct(FALSE,vtolFactory,player,player);
 
2852
                        structure= enumStruct();
 
2853
                        while(structure != NULLOBJECT)  
 
2854
                        {
 
2855
                                if(structureComplete(structure))
 
2856
                                {
 
2857
                                        if(isStructureAvailable(facModule,player) and (skGetFactoryCapacity(structure) < 2 ))                   
 
2858
                                        {
 
2859
                                                if((tempDroid != NULLOBJECT) and (boolResult == TRUE))
 
2860
                                                {
 
2861
                                                        boolResult = FALSE;
 
2862
                                                orderDroidStatsLoc(tempDroid, DORDER_BUILD,facModule, structure.x,structure.y);
 
2863
                                                }       
 
2864
                                        }
 
2865
                                }
 
2866
                                structure = enumStruct();
 
2867
                        }
 
2868
                }
 
2869
        }
 
2870
}
 
2871
 
 
2872
 
 
2873
//------------------------------------------------------
 
2874
//      Run for a bit when attacked
 
2875
//------------------------------------------------------
 
2876
event moveIfAttacked(moveIfAttackedTr)
 
2877
{
 
2878
        //If unit is still alive and is still under attack
 
2879
        if((droid != NULLOBJECT) and (baseobj != NULLOBJECT))
 
2880
        {
 
2881
                //If during the attack
 
2882
                //if(attackPhase >= 2)
 
2883
                //{
 
2884
                //      if(groupMember(attackGroup, droid))
 
2885
                //      {
 
2886
                //              if(distBetweenTwoPoints(curEnemyX, curEnemyY, baseobj.x, baseobj.y) < (KeepDist / 2))
 
2887
                //              {
 
2888
                //                      if(losTwoObjects(droid, baseobj, TRUE))         //Only if we can see the enemy (get out of his range)
 
2889
                //                      {
 
2890
                //                              orderDroidLoc(droid, DORDER_MOVE, curEnEdgeX, curEnEdgeY);      //Retreat
 
2891
                //                      }
 
2892
                //              }
 
2893
                //      }
 
2894
                //}
 
2895
 
 
2896
                if(baseobj.player != player)    //Not attacking itself by an accident or with a mass-weapon
 
2897
                {
 
2898
 
 
2899
                        boolResult = TRUE;
 
2900
                        if(baseobj.type == OBJ_DROID)
 
2901
                        {
 
2902
                                if(isVtol(objToDroid(baseobj)))
 
2903
                                {
 
2904
                                        boolResult = FALSE;             //Attacked by a VTOL
 
2905
                                }
 
2906
                        }
 
2907
 
 
2908
                        if(droid.type == OBJ_DROID)
 
2909
                        {
 
2910
                                if(isVtol(objToDroid(droid)))
 
2911
                                {
 
2912
                                        boolResult = FALSE;             //VTOL was attacked
 
2913
                                }
 
2914
                        }
 
2915
 
 
2916
                        //If we have a weapon, then answer
 
2917
                        //--------------------------------
 
2918
                        if(boolResult)          //If a land unit or a defense
 
2919
                        {
 
2920
                                if(droid.droidType == DROID_WEAPON)             //Has a weapon
 
2921
                                {
 
2922
                                        if(droid.order == DORDER_NONE)  //Not already attacking
 
2923
                                        {
 
2924
                                                if(losTwoObjects(droid, baseobj, TRUE))         //If we can see attacker
 
2925
                                                {
 
2926
                                                        //orderDroidObj(droid, DORDER_ATTACK, baseobj);
 
2927
                                                        orderDroidLoc(droid, DORDER_SCOUT, baseobj.x, baseobj.y);
 
2928
                                                }
 
2929
                                        }
 
2930
                                }
 
2931
 
 
2932
                                //Help a friend if we are near
 
2933
                                //----------------------------
 
2934
                                if(groupMember(attackGroup, droid))
 
2935
                                {
 
2936
                                        temp = (7 * 128);
 
2937
                                        initIterateGroup(attackGroup);
 
2938
                                        tempDroid = iterateGroup(attackGroup);
 
2939
                                        while(tempDroid != NULLOBJECT)
 
2940
                                        {
 
2941
                                                if(tempDroid.order == DORDER_NONE)
 
2942
                                                {
 
2943
                                                        if(distBetweenTwoPoints(tempDroid.x, tempDroid.y, droid.x, droid.y) < temp)
 
2944
                                                        {
 
2945
                                                                //if(losTwoObjects(tempDroid, baseobj, TRUE))           //If we can see attacker
 
2946
                                                                //{
 
2947
                                                                        //orderDroidObj(tempDroid, DORDER_ATTACK, baseobj);
 
2948
                                                                        orderDroidLoc(tempDroid, DORDER_SCOUT, baseobj.x, baseobj.y);
 
2949
                                                                //}
 
2950
                                                        }
 
2951
                                                }
 
2952
                                                tempDroid = iterateGroup(attackGroup);
 
2953
                                        }
 
2954
                                }
 
2955
                        }
 
2956
 
 
2957
                        //Vtols and trucks run away
 
2958
                        //-------------------------
 
2959
                        if((droid.droidType == DROID_CONSTRUCT) or (isVtol(droid)))     //If a constructor or a VTOL
 
2960
                        {
 
2961
                                if(droid.order == DORDER_NONE)
 
2962
                                {
 
2963
                                        temp = (3 * 128);
 
2964
                                        temp = random(temp * 2) - temp;
 
2965
                                        orderDroidLoc(droid, DORDER_MOVE, droid.x + temp, droid.y + temp);
 
2966
                                }
 
2967
                        }
 
2968
                }
 
2969
        }
 
2970
}
 
2971
 
 
2972
//---------------------------------------------------------------
 
2973
//      Build an outpost to retreat to and to repair damaged units
 
2974
//---------------------------------------------------------------
 
2975
event BuildOutpost(inactive)
 
2976
{
 
2977
        //Find trucks to build the outpost
 
2978
        //--------------------------------
 
2979
        count2 = (KeepDist / 2);
 
2980
        
 
2981
        //Reduce number of defenses temporary if low on power
 
2982
        temp = 6;       /*%!    ID="NumOutpostDef",
 
2983
                                                MainDesc="Num outpost defences",
 
2984
                                                type="asn",             //Assign
 
2985
                                                val="6",
 
2986
                                                ArgDesc="6 (Default)",
 
2987
                                                val="0",
 
2988
                                                ArgDesc="0",
 
2989
                                                val="3",
 
2990
                                                ArgDesc="3",
 
2991
                                                val="9",
 
2992
                                                ArgDesc="9",
 
2993
                                                val="12",
 
2994
                                                ArgDesc="12",
 
2995
                                                val="15",
 
2996
                                                ArgDesc="15"    */
 
2997
 
 
2998
        if(powerSaving)
 
2999
        {
 
3000
                temp = 2;       /*%!    ID="NumOutpostDefLowPow",
 
3001
                                                MainDesc="Num outpost defences on low power",
 
3002
                                                type="asn",             //Assign
 
3003
                                                val="2",
 
3004
                                                ArgDesc="2 (Default)",
 
3005
                                                val="0",
 
3006
                                                ArgDesc="0",
 
3007
                                                val="4",
 
3008
                                                ArgDesc="4",
 
3009
                                                val="6",
 
3010
                                                ArgDesc="6",
 
3011
                                                val="10",
 
3012
                                                ArgDesc="10",
 
3013
                                                val="12",
 
3014
                                                ArgDesc="12",
 
3015
                                                val="temp",
 
3016
                                                ArgDesc="Same value as above"   */
 
3017
        }
 
3018
 
 
3019
        if(outpostDroid == NULLOBJECT)
 
3020
        {
 
3021
                if(not defendingBase)           //Need trucks for base rebuilding now
 
3022
                {
 
3023
                        initIterateGroup(buildGroup);
 
3024
                        droid = iterateGroup(buildGroup);
 
3025
                        while((droid != NULLOBJECT) and (outpostDroid == NULLOBJECT))
 
3026
                        {
 
3027
                                if(droid.order == DORDER_NONE)
 
3028
                                {
 
3029
                                        droidLeaveGroup(droid);
 
3030
                                        outpostDroid = droid;
 
3031
                                        orderDroidLoc(outpostDroid, DORDER_MOVE, curEnEdgeX, curEnEdgeY);
 
3032
                                }
 
3033
                                droid = iterateGroup(buildGroup);
 
3034
                        }
 
3035
                }
 
3036
        }
 
3037
 
 
3038
        //--------------------------------------------------------
 
3039
        //Check if we have all necessary structures in the outpost
 
3040
        //--------------------------------------------------------
 
3041
        if((outpostDroid != NULLOBJECT) and (curEnEdgeX > 0) and (not defendingBase))   //If we have trucks, have outpost coords and don't need money for the base
 
3042
        {
 
3043
                boolResult = TRUE;
 
3044
 
 
3045
                //-------------------------
 
3046
                //Remove old rep facilities
 
3047
                //-------------------------
 
3048
                initEnumStruct(FALSE,repairFacility,player,player);
 
3049
                structure = enumStruct();
 
3050
                while(structure != NULLOBJECT)
 
3051
                {
 
3052
                        //Demolish if outside of the new edge
 
3053
                        if(distBetweenTwoPoints(curEnEdgeX, curEnEdgeY, structure.x, structure.y) > count2)
 
3054
                        {
 
3055
                                if((outpostDroid.order == DORDER_NONE) or (outpostDroid.order == DORDER_MOVE))  //Not busy
 
3056
                                {
 
3057
                                        orderDroidObj(outpostDroid, DORDER_DEMOLISH, structure);
 
3058
                                }
 
3059
                        }
 
3060
                        structure = enumStruct();
 
3061
                }
 
3062
 
 
3063
                //-----------------------
 
3064
                //Check repair facilities
 
3065
                //-----------------------
 
3066
                result = numStructsByTypeInArea(player, REF_REPAIR_FACILITY, curEnEdgeX - count2, curEnEdgeY - count2, curEnEdgeX + count2, curEnEdgeY + count2);
 
3067
                if(result < 1)          //We need repair facilities
 
3068
                {
 
3069
                        boolResult = FALSE;             //Not done building outpost yet
 
3070
 
 
3071
                        buildX = curEnEdgeX;            //Outpost coords = build coords
 
3072
                        buildY = curEnEdgeY;
 
3073
                        boolResult2 = pickStructLocation(repairFacility, ref buildX, ref buildY, player);
 
3074
                        if(boolResult2 == TRUE)         //If we can build
 
3075
                        {
 
3076
                                //Not outside of the outpost
 
3077
                                //--------------------------
 
3078
                                if(distBetweenTwoPoints(curEnEdgeX, curEnEdgeY, buildX, buildY) < count2)
 
3079
                                {
 
3080
                                        if((outpostDroid.order == DORDER_NONE) or (outpostDroid.order == DORDER_MOVE))  //Not busy
 
3081
                                        {
 
3082
                                                orderDroidStatsLoc(outpostDroid, DORDER_BUILD, repairFacility, buildX,buildY);
 
3083
                                        }
 
3084
                                }
 
3085
                        }
 
3086
                }
 
3087
 
 
3088
                //---------------------------------------------------
 
3089
                //Build some defenses in the outpost if we are idling
 
3090
                //---------------------------------------------------
 
3091
                if(outpostDroid.order == DORDER_NONE)   //Not busy
 
3092
                {
 
3093
                        //Count defenses
 
3094
                        //--------------
 
3095
                        result = 0;
 
3096
                        count = 0;
 
3097
                        while(count < numDefenses)
 
3098
                        {
 
3099
                                initEnumStruct(FALSE,defenses[count],player,player);
 
3100
                                structure = enumStruct();
 
3101
                                while(structure != NULLOBJECT)
 
3102
                                {
 
3103
                                        if(distBetweenTwoPoints(structure.x, structure.y, curEnEdgeX, curEnEdgeY) < count2)             //In the outpost
 
3104
                                        {
 
3105
                                                result = result + 1;
 
3106
                                        }
 
3107
                                        structure = enumStruct();
 
3108
                                }
 
3109
                                count = count + 1;
 
3110
                        }
 
3111
 
 
3112
                        //if(numStructsInArea(player, curEnEdgeX - count2, curEnEdgeY - count2, curEnEdgeX + count2, curEnEdgeY + count2) < count)
 
3113
                        if(result < temp)
 
3114
                        {
 
3115
                                //Choose best defense
 
3116
                                //-------------------
 
3117
                                count = numDefenses - 1;
 
3118
                                boolResult = FALSE;
 
3119
                                while((count >= 0) and (boolResult == FALSE))
 
3120
                                {
 
3121
                                        if(isStructureAvailable(defenses[count], player))
 
3122
                                        {
 
3123
                                                structChoice[0] = defenses[count];
 
3124
                                                boolResult = TRUE;                      //Stop
 
3125
                                        }
 
3126
                                        count = count - 1;
 
3127
                                }
 
3128
 
 
3129
                                if(boolResult == TRUE)          //If we have a defense we can build
 
3130
                                {
 
3131
                                        buildX = curEnEdgeX;
 
3132
                                        buildY = curEnEdgeY;
 
3133
                                        boolResult = pickStructLocation(powGen, ref buildX, ref buildY, player);
 
3134
                                        if(boolResult == TRUE)
 
3135
                                        {
 
3136
                                                if(distBetweenTwoPoints(buildX, buildY, curEnEdgeX, curEnEdgeY) < count2)
 
3137
                                                {
 
3138
                                                        orderDroidStatsLoc(outpostDroid, DORDER_BUILD, structChoice[0], buildX, buildY);
 
3139
                                                }
 
3140
                                        }
 
3141
                                }
 
3142
                        }
 
3143
                }
 
3144
 
 
3145
                //---------------
 
3146
                //Build some arty
 
3147
                //---------------
 
3148
                result4 = 6;    /*%!    ID="NumOutpostArtyDef",
 
3149
                                                MainDesc="Num outpost arty defences",
 
3150
                                                type="asn",             //Assign
 
3151
                                                val="6",
 
3152
                                                ArgDesc="6 (Default)",
 
3153
                                                val="0",
 
3154
                                                ArgDesc="0",
 
3155
                                                val="3",
 
3156
                                                ArgDesc="3",
 
3157
                                                val="8",
 
3158
                                                ArgDesc="8",
 
3159
                                                val="10",
 
3160
                                                ArgDesc="10",
 
3161
                                                val="15",
 
3162
                                                ArgDesc="15"    */
 
3163
 
 
3164
                if(outpostDroid.order == DORDER_NONE)
 
3165
                {
 
3166
                        //Arty
 
3167
                        if(numStructsByTypeInArea(player, REF_DEFENSE, curEnEdgeX - count2, curEnEdgeY - count2, curEnEdgeX + count2, curEnEdgeY + count2) < (temp + result4))  //Max 6 arty def
 
3168
                        {
 
3169
                                //Check if we have arty tech available
 
3170
                                count = 1;
 
3171
                                boolResult = FALSE;
 
3172
                                while((count >= 0) and (boolResult == FALSE))
 
3173
                                {
 
3174
                                        if(isStructureAvailable(arty[count], player))
 
3175
                                        {
 
3176
                                                structChoice[0] = arty[count];
 
3177
                                                boolResult = TRUE;                      //Stop
 
3178
                                        }
 
3179
                                        count = count - 1;
 
3180
                                }
 
3181
 
 
3182
                                if(boolResult == TRUE)          //If we have arty tech
 
3183
                                {
 
3184
                                        buildX = curEnEdgeX;
 
3185
                                        buildY = curEnEdgeY;
 
3186
                                        boolResult = pickStructLocation(powGen, ref buildX, ref buildY, player);
 
3187
                                        if(boolResult == TRUE)
 
3188
                                        {
 
3189
                                                if(distBetweenTwoPoints(buildX, buildY, curEnEdgeX, curEnEdgeY) < count2)
 
3190
                                                {
 
3191
                                                        orderDroidStatsLoc(outpostDroid, DORDER_BUILD, structChoice[0], buildX, buildY);
 
3192
                                                }
 
3193
                                        }
 
3194
                                }
 
3195
                        }
 
3196
 
 
3197
                        //-------
 
3198
                        //Sensors
 
3199
                        //-------
 
3200
 
 
3201
                        //Count sensors
 
3202
                        //-------------
 
3203
                        result = 0;
 
3204
                        count = 0;
 
3205
                        while(count < 2)
 
3206
                        {
 
3207
                                initEnumStruct(FALSE,sens[count],player,player);
 
3208
                                structure = enumStruct();
 
3209
                                while(structure != NULLOBJECT)
 
3210
                                {
 
3211
                                        if(distBetweenTwoPoints(structure.x, structure.y, curEnEdgeX, curEnEdgeY) < count2)             //In the outpost
 
3212
                                        {
 
3213
                                                result = result + 1;
 
3214
                                        }
 
3215
                                        structure = enumStruct();
 
3216
                                }
 
3217
                                count = count + 1;
 
3218
                        }
 
3219
 
 
3220
                        if(result == 0)
 
3221
                        {
 
3222
                                //Check if we have sensor tech available
 
3223
                                count = 1;
 
3224
                                boolResult = FALSE;
 
3225
                                while((count >= 0) and (boolResult == FALSE))
 
3226
                                {
 
3227
                                        if(isStructureAvailable(sens[count], player))
 
3228
                                        {
 
3229
                                                structChoice[0] = sens[count];
 
3230
                                                boolResult = TRUE;                      //Stop
 
3231
                                        }
 
3232
                                        count = count - 1;
 
3233
                                }
 
3234
 
 
3235
                                if(boolResult == TRUE)          //If we have sensor tech available
 
3236
                                {
 
3237
                                        buildX = curEnEdgeX;
 
3238
                                        buildY = curEnEdgeY;
 
3239
                                        boolResult = pickStructLocation(powGen, ref buildX, ref buildY, player);
 
3240
                                        if(boolResult == TRUE)
 
3241
                                        {
 
3242
                                                if(distBetweenTwoPoints(buildX, buildY, curEnEdgeX, curEnEdgeY) < count2)
 
3243
                                                {
 
3244
                                                        orderDroidStatsLoc(outpostDroid, DORDER_BUILD, structChoice[0], buildX, buildY);
 
3245
                                                }
 
3246
                                        }
 
3247
                                }
 
3248
                        }
 
3249
                }
 
3250
        }
 
3251
}
 
3252
 
 
3253
//-------------------------------------------------------------
 
3254
//      Check for some important details we need for the script
 
3255
//-------------------------------------------------------------
 
3256
event updateDetails(updateDetailsTr)
 
3257
{
 
3258
        //Decide wheather to drop or not
 
3259
        //----------------------------------------------------
 
3260
        if(not dropEnabled)
 
3261
        {
 
3262
                if((alreadyAttacked and (playerPower(player) > 500)) or (playerPower(player) > muchoPower))             //Started attacking and enough power
 
3263
                {
 
3264
                        dropEnabled = TRUE;
 
3265
                }
 
3266
        }
 
3267
 
 
3268
        //----------------------------------------------------
 
3269
        //Count how many attackers are repairing at the moment
 
3270
        //----------------------------------------------------
 
3271
        //numRepairing = 0;
 
3272
        //initIterateGroup(attackGroup);
 
3273
        //droid = iterateGroup(attackGroup);
 
3274
        //while(droid != NULLOBJECT)
 
3275
        //{
 
3276
        //      if(droid.order == DORDER_RTR)
 
3277
        //      {
 
3278
        //              numRepairing = numRepairing + 1;
 
3279
        //      }
 
3280
        //      droid = iterateGroup(attackGroup);
 
3281
        //}
 
3282
 
 
3283
        //------------------------------------------
 
3284
        //Check if we have an outpost and can repair
 
3285
        //------------------------------------------
 
3286
        haveOutpost = FALSE;
 
3287
        if(curEnEdgeX > 0)
 
3288
        {
 
3289
                //Find rep facilities
 
3290
                //-------------------
 
3291
                count2 = (KeepDist / 2);
 
3292
                if(numStructsByTypeInArea(player, REF_REPAIR_FACILITY, curEnEdgeX - count2, curEnEdgeY - count2, curEnEdgeX + count2, curEnEdgeY + count2) > 0)
 
3293
                {
 
3294
                        haveOutpost = TRUE;
 
3295
                }
 
3296
        }
 
3297
 
 
3298
        //Decide how many templates tochoose from
 
3299
        //---------------------------------------
 
3300
        structure = getStructure(factory,player);
 
3301
        if(structure != NULLOBJECT)
 
3302
        {
 
3303
                temp = 0;
 
3304
                TemplDepth = 1;
 
3305
                if(playerPower(player) > muchoPower)
 
3306
                {
 
3307
                        temp = 1;
 
3308
                }
 
3309
 
 
3310
                if(skCanBuildTemplate(player,structure, tmpl[0][8]))    //If we have Trck Python HC
 
3311
                {
 
3312
                        if(mainPhase == 1)              //If set to 2 too early, then some stuff will not be activated at startup
 
3313
                        {
 
3314
                                mainPhase = 2;
 
3315
                        }
 
3316
                }
 
3317
 
 
3318
                if(skCanBuildTemplate(player,structure, tmpl[temp][10]))                //If we have A-Mantis-Trk-Lancer then start using 3 templates
 
3319
                {
 
3320
                        TemplDepth = 3;
 
3321
                }
 
3322
                else if(skCanBuildTemplate(player,structure, tmpl[temp][9]))    //If we have A-Python-Trk-Lancer then use A-Python-Trk-Lancer and A-Python-Trk-HC
 
3323
                {
 
3324
                        TemplDepth = 2;
 
3325
                }
 
3326
 
 
3327
        }
 
3328
 
 
3329
        //Remember the best cyborg template available
 
3330
        //-------------------------------------------
 
3331
        structure = getStructure(cybFactory, player);
 
3332
        if(structure != NULLOBJECT)
 
3333
        {
 
3334
                count = 1;              //numTemplates - 1
 
3335
                boolResult = TRUE;
 
3336
                while((count >= 0) and (boolResult))
 
3337
                {
 
3338
                        if(skCanBuildTemplate(player,structure, cybTmpl[count]) )
 
3339
                        {
 
3340
                                cybTemplate = count;
 
3341
                                boolResult = FALSE;
 
3342
                        }
 
3343
                        count = count - 1;
 
3344
                }
 
3345
        }
 
3346
}
 
3347
 
 
3348
//----------------------------------------
 
3349
//Power saving
 
3350
//----------------------------------------
 
3351
event savePower(inactive)
 
3352
{
 
3353
        //------------
 
3354
        //Power saving
 
3355
        //------------
 
3356
        powerSaving = FALSE;
 
3357
        if((playerPower(player) < 100) or (defendingBase))              //Low on power or need power for fast unit production
 
3358
        {
 
3359
                powerSaving = TRUE;
 
3360
        }
 
3361
}
 
3362
 
 
3363
//----------------------------------------
 
3364
//Repair damaged droids using repair units
 
3365
//----------------------------------------
 
3366
event repairStuff(repairStuffTr)
 
3367
{
 
3368
        //------------------------
 
3369
        //Defenders
 
3370
        //------------------------
 
3371
        result = 2;     //Total number of (repDefendDroid - 1)
 
3372
        count = 0;      //Current repair unit index
 
3373
        while(count < result)
 
3374
        {
 
3375
                if(repDefendDroid[count] != NULLOBJECT)         //If this repairer exists
 
3376
                {
 
3377
                        boolResult = FALSE;                             //Assume it's still busy right now
 
3378
                        if(toRepDefendDroid[count] == NULLOBJECT)               //Nothing to repair
 
3379
                        {
 
3380
                                boolResult = TRUE;                              //Not busy, find a unit to repair
 
3381
                        }
 
3382
                        else                                    //Damaged unit still exists
 
3383
                        {
 
3384
                                if(toRepDefendDroid[count].health > 95)         //Already repaired
 
3385
                                {
 
3386
                                        boolResult = TRUE;                      //Find another unit
 
3387
                                        toRepDefendDroid[count] = NULLOBJECT;   //'Forget' this unit
 
3388
                                }
 
3389
                        }
 
3390
 
 
3391
                        //-------------------
 
3392
                        //Find a damaged unit
 
3393
                        //-------------------
 
3394
                        if(boolResult)                                  //Have nothing to repair
 
3395
                        {
 
3396
                                initIterateGroup(defendGr);
 
3397
                                droid = iterateGroup(defendGr);
 
3398
                                boolResult = TRUE;
 
3399
                                while((droid != NULLOBJECT) and (boolResult))
 
3400
                                {
 
3401
                                        if(droid.health < 90)                   //Needs repair
 
3402
                                        {
 
3403
                                                boolResult = FALSE;             //Busy now, found a unit to repair
 
3404
 
 
3405
                                                //Make sure this unit is not already get repaired by the second repairer
 
3406
                                                //----------------------------------------------------------------------
 
3407
                                                if(count == 0)  //For the first repairer
 
3408
                                                {
 
3409
                                                        if(droid == toRepDefendDroid[1])        //If already get repaired
 
3410
                                                        {
 
3411
                                                                boolResult = TRUE;      //Don't take this unit
 
3412
                                                        }
 
3413
                                                }
 
3414
                                                else if(count == 1)
 
3415
                                                {
 
3416
                                                        if(droid == toRepDefendDroid[0])        //If already get repaired
 
3417
                                                        {
 
3418
                                                                boolResult = TRUE;      //Don't take this unit
 
3419
                                                        }
 
3420
                                                }
 
3421
 
 
3422
                                                if(not boolResult)      //If we did decide to choose this unit for repairing
 
3423
                                                {
 
3424
                                                        toRepDefendDroid[count] = droid;        //Choose it
 
3425
                                                }
 
3426
                                        }
 
3427
                                        droid = iterateGroup(defendGr);
 
3428
                                }
 
3429
 
 
3430
                                //---------------------------------------------------------
 
3431
                                //If nothing to repair so far, repair the other repair unit
 
3432
                                //---------------------------------------------------------
 
3433
                                if(boolResult)          //Nothing to repair
 
3434
                                {
 
3435
                                        if(count == 0)  //For the first rep unit
 
3436
                                        {
 
3437
                                                if(repDefendDroid[1] != NULLOBJECT)     //2nd repair unit exists
 
3438
                                                {
 
3439
                                                        if(repDefendDroid[1].health < 90)       //Needs repair
 
3440
                                                        {
 
3441
                                                                boolResult = FALSE;                     //Busy now
 
3442
                                                                toRepDefendDroid[count] = repDefendDroid[1];    //Repair it
 
3443
                                                        }
 
3444
                                                }
 
3445
                                        }
 
3446
                                        else if(count == 1)
 
3447
                                        {
 
3448
                                                if(repDefendDroid[0] != NULLOBJECT)     //1st repair unit exists
 
3449
                                                {
 
3450
                                                        if(repDefendDroid[0].health < 90)       //Needs repair
 
3451
                                                        {
 
3452
                                                                boolResult = FALSE;                     //Busy now
 
3453
                                                                toRepDefendDroid[count] = repDefendDroid[0];    //Repair it
 
3454
                                                        }
 
3455
                                                }
 
3456
                                        }
 
3457
                                        
 
3458
                                }
 
3459
 
 
3460
                                //---------------------------------------------------------
 
3461
                                //If found something to repair, then get closer to the unit
 
3462
                                //---------------------------------------------------------
 
3463
                                if(not boolResult)              //Busy
 
3464
                                {
 
3465
                                        if(distBetweenTwoPoints(toRepDefendDroid[count].x, toRepDefendDroid[count].y, repDefendDroid[count].x, repDefendDroid[count].y) > 256)  //If too far away from the damaged unit
 
3466
                                        {
 
3467
                                                tempX = 128;
 
3468
                                                tempY = 128;
 
3469
                                                if(repDefendDroid[count].x < toRepDefendDroid[count].x)         //Don't make the unit get out of the way, stop near it
 
3470
                                                {
 
3471
                                                        tempX = -128;
 
3472
                                                }
 
3473
 
 
3474
                                                if(repDefendDroid[count].y < toRepDefendDroid[count].y)
 
3475
                                                {
 
3476
                                                        tempY = -128;
 
3477
                                                }
 
3478
                                        
 
3479
                                                orderDroidLoc(repDefendDroid[count], DORDER_MOVE, toRepDefendDroid[count].x + tempX, toRepDefendDroid[count].y + tempY);
 
3480
                                        }
 
3481
                                }
 
3482
                                else    //If still idle, then move closer to the defend group
 
3483
                                {
 
3484
                                        tempX = defendGr.x;
 
3485
                                        tempY = defendGr.y;
 
3486
 
 
3487
                                        if(distBetweenTwoPoints(tempX, tempY, repDefendDroid[count].x, repDefendDroid[count].y) > 1024) //Too far away from defenders
 
3488
                                        {
 
3489
                                                orderDroidLoc(repDefendDroid[count], DORDER_MOVE, tempX, tempY);        //Move closer to the group
 
3490
                                                boolResult = FALSE;
 
3491
                                        }
 
3492
                                }
 
3493
                        }
 
3494
                        else if(toRepDefendDroid[count] != NULLOBJECT)          //Has something to repair and not going to repair it
 
3495
                        {
 
3496
                                if(repDefendDroid[count].order == DORDER_NONE)  //Idle
 
3497
                                {
 
3498
                                        if(distBetweenTwoPoints(repDefendDroid[count].x, repDefendDroid[count].y, toRepDefendDroid[count].x, toRepDefendDroid[count].y) > (3 * 128))
 
3499
                                        {
 
3500
                                                orderDroidLoc(repDefendDroid[count], DORDER_MOVE, toRepDefendDroid[count].x, toRepDefendDroid[count].y);
 
3501
                                        }
 
3502
                                }
 
3503
                        }
 
3504
                }
 
3505
                count = count + 1;
 
3506
        }
 
3507
 
 
3508
 
 
3509
/*
 
3510
        //------------------------
 
3511
        //Attackers
 
3512
        //------------------------
 
3513
        if(repAttackDroid != NULLOBJECT)
 
3514
        {
 
3515
                if(repAttackDroid.order == DORDER_NONE)                 //Not busy
 
3516
                {
 
3517
                        initIterateGroup(attackGroup);
 
3518
                        droid = iterateGroup(attackGroup);
 
3519
                        boolResult = TRUE;                              //Send only 1 truck
 
3520
                        while((droid != NULLOBJECT) and (boolResult))
 
3521
                        {
 
3522
                                if(droid.health < 90)                   //Needs repair
 
3523
                                {
 
3524
                                        if(distBetweenTwoPoints(droid.x, droid.y, repAttackDroid.x, repAttackDroid.y) > 256)
 
3525
                                        {
 
3526
                                                boolResult = FALSE;
 
3527
                                                tempX = 128;
 
3528
                                                tempY = 128;
 
3529
                                                if(repAttackDroid.x < droid.x)          //Don't make the unit get out of the way, stop near it
 
3530
                                                {
 
3531
                                                        tempX = -128;
 
3532
                                                }
 
3533
 
 
3534
                                                if(repAttackDroid.y < droid.y)
 
3535
                                                {
 
3536
                                                        tempY = -128;
 
3537
                                                }
 
3538
                                        
 
3539
                                                orderDroidLoc(repAttackDroid, DORDER_MOVE, droid.x + tempX, droid.y + tempY);
 
3540
                                        }
 
3541
                                }
 
3542
                                droid = iterateGroup(attackGroup);
 
3543
                        }
 
3544
 
 
3545
                        tempX = attackGroup.x;
 
3546
                        tempY = attackGroup.y;
 
3547
                        if(not boolResult)
 
3548
                        {
 
3549
                                if(distBetweenTwoPoints(tempX, tempY, repAttackDroid.x, repAttackDroid.y) > 512)        //(6 * 128)
 
3550
                                {
 
3551
                                        orderDroidLoc(repDefendDroid, DORDER_MOVE, tempX, tempY);       //Move closer to the group
 
3552
                                }
 
3553
                        }
 
3554
                }
 
3555
        }
 
3556
*/
 
3557
 
 
3558
        //-----------------------
 
3559
        //Base structures
 
3560
        //-----------------------
 
3561
        structure2 = NULLOBJECT;
 
3562
        initEnumStruct(TRUE,derrick,player,player);             //TRUE: iterate through all structures
 
3563
        structure = enumStruct();
 
3564
        while((structure != NULLOBJECT) and (structure2 == NULLOBJECT))
 
3565
        {
 
3566
                //if(not structureComplete(structure))          //If structure not finished
 
3567
                //{
 
3568
                        if(structure.health < 90)
 
3569
                        {
 
3570
                                if((structure.x < maxx) and (structure.x > minx))       //Only base structures
 
3571
                                {
 
3572
                                        if((structure.y < maxy) and (structure.y > miny))
 
3573
                                        {
 
3574
                                                structure2 = structure;
 
3575
                                        }
 
3576
                                }
 
3577
                        }
 
3578
                //}
 
3579
                structure = enumStruct();
 
3580
        }
 
3581
 
 
3582
        if(structure2 != NULLOBJECT)
 
3583
        {
 
3584
                boolResult = TRUE;
 
3585
                result = 0;
 
3586
                tempDroid = NULLOBJECT;
 
3587
 
 
3588
                temp = 45 * 128;
 
3589
                initIterateGroup(buildGroup);
 
3590
                droid = iterateGroup(buildGroup);
 
3591
                while((droid != NULLOBJECT) and (boolResult))
 
3592
                {
 
3593
                        if(droid.order == DORDER_NONE)  //Make sure there's only one droid repairing at a time
 
3594
                        {
 
3595
                                if(distBetweenTwoPoints(droid.x, droid.y, structure2.x, structure2.y) < temp)   //Not too far away
 
3596
                                {
 
3597
                                        tempDroid = droid;
 
3598
                                        boolResult = FALSE;             //We found our droid, make iteration stop here
 
3599
                                }
 
3600
                        }
 
3601
                        else            //Max 2 trucks repairing the same structure
 
3602
                        {
 
3603
                                if(droid.order == DORDER_REPAIR)        //If somebody is already repairing something
 
3604
                                {
 
3605
                                        if((droid.orderx == structure2.x) and (droid.ordery == structure2.y))
 
3606
                                        {
 
3607
                                                tempDroid = NULLOBJECT;
 
3608
                                                boolResult = FALSE;             //Stop iteration
 
3609
                                        }
 
3610
                                }
 
3611
                        }
 
3612
                        droid = iterateGroup(buildGroup);
 
3613
                }
 
3614
 
 
3615
                if(tempDroid != NULLOBJECT)             //Droid found and nobody already repairing
 
3616
                {
 
3617
                        orderDroidObj(tempDroid, DORDER_REPAIR, structure2);            //Repair
 
3618
                }
 
3619
        }
 
3620
 
 
3621
}
 
3622
 
 
3623
//------------------------------------
 
3624
//      Units stuck, do something!
 
3625
//------------------------------------
 
3626
event stuck(stuckTr)
 
3627
{
 
3628
        //Most of them have an order
 
3629
        if((attackGroup.members > 0) and (idleGroup(attackGroup) < (attackGroup.members / 2)))
 
3630
        {
 
3631
                //If we moved
 
3632
                temp = (7 * 128);
 
3633
 
 
3634
                if(repGr.members > 0)           //Have repGr
 
3635
                {
 
3636
                        tempX = (attackGroup.x + repGr.x) / 2;          //Attack and rep group stuck often,
 
3637
                        tempY = (attackGroup.y + repGr.y) / 2;          //so use the middle value of the 2 groups
 
3638
                }
 
3639
                else
 
3640
                {
 
3641
                        tempX = attackGroup.x;  
 
3642
                        tempY = attackGroup.y;
 
3643
                }
 
3644
 
 
3645
 
 
3646
                if(distBetweenTwoPoints(tempX, tempY, stuckX, stuckY) > temp)           //Moved
 
3647
                {
 
3648
                        stuckTimes = 0;
 
3649
                        stuckX = tempX;         //Store new coordinates
 
3650
                        stuckY = tempY; 
 
3651
                }                       //Reset
 
3652
                else
 
3653
                {
 
3654
                        stuckTimes = stuckTimes + 1;
 
3655
                }
 
3656
 
 
3657
                result = 35;
 
3658
                result2 = result + 15;
 
3659
 
 
3660
                //If they are really stuck
 
3661
                if((stuckTimes > result) and (stuckTimes < result2))
 
3662
                {
 
3663
                        showConsoleText(DebugMsg[9], player);           //STUCK: Running a bit
 
3664
 
 
3665
                        //count = 0;
 
3666
                        //while(count < 5)
 
3667
                        //{
 
3668
                                //Run a bit
 
3669
                                initIterateGroup(attackGroup);
 
3670
                                droid = iterateGroup(attackGroup);
 
3671
                                while(droid != NULLOBJECT)
 
3672
                                {
 
3673
                                        orderDroid(droid, DORDER_RUN);
 
3674
                                        droid = iterateGroup(attackGroup);
 
3675
                                }
 
3676
 
 
3677
                                //Run a bit
 
3678
                                initIterateGroup(sendOutpostGr);
 
3679
                                droid = iterateGroup(sendOutpostGr);
 
3680
                                while(droid != NULLOBJECT)
 
3681
                                {
 
3682
                                        orderDroid(droid, DORDER_RUN);
 
3683
                                        droid = iterateGroup(sendOutpostGr);
 
3684
                                }
 
3685
 
 
3686
                                //Run a bit
 
3687
                                initIterateGroup(repGr);
 
3688
                                droid = iterateGroup(repGr);
 
3689
                                while(droid != NULLOBJECT)
 
3690
                                {
 
3691
                                        orderDroid(droid, DORDER_RUN);
 
3692
                                        droid = iterateGroup(repGr);
 
3693
                                }
 
3694
                        //      count = count + 1;
 
3695
                        //}
 
3696
                }
 
3697
                else if(stuckTimes >= result2)
 
3698
                {
 
3699
                        showConsoleText(DebugMsg[10], player);          //STUCK: Removing obstacles
 
3700
 
 
3701
                        //Wipe out any structure near the group or some units if there are no structures
 
3702
                        resetStructTargets();
 
3703
                        result = (5 * 128);
 
3704
                        structure = structTargetInArea(player, player, tempX - result, tempY - result, tempX + result, tempY + result);
 
3705
                        if(structure == NULLOBJECT)
 
3706
                        {
 
3707
                                setStructTarPref(ST_WALL);
 
3708
                                structure = structTargetInArea(player, player, tempX - result, tempY - result, tempX + result, tempY + result);
 
3709
                        }
 
3710
 
 
3711
                        if(structure != NULLOBJECT)
 
3712
                        {
 
3713
                                orderGroupObj(attackGroup, DORDER_ATTACK, structure);
 
3714
                        }
 
3715
                        else
 
3716
                        {
 
3717
                                resetDroidTargets();
 
3718
                                tempDroid = droidTargetInArea(player, player, tempX - result, tempY - result, tempX + result, tempY + result);
 
3719
                                if(tempDroid != NULLOBJECT)
 
3720
                                {
 
3721
                                        orderGroupObj(attackGroup, DORDER_ATTACK, tempDroid);
 
3722
                                }
 
3723
                        }
 
3724
                }
 
3725
                else if(stuckTimes > (result2 + 20))    //Destroy 20 objects, then reset
 
3726
                {
 
3727
                        stuckTimes = 0;                 //Try to get out now
 
3728
                }
 
3729
        }
 
3730
}
 
3731
 
 
3732
//=============================================================================================
 
3733
//                                                      VTOLs
 
3734
//=============================================================================================
 
3735
//---------------------
 
3736
//      Build rearm pads
 
3737
//---------------------
 
3738
event buildVtolPads(inactive)
 
3739
{
 
3740
        if(getStructure(vtolFactory,player) != NULLOBJECT)      //If we have VTOL factory
 
3741
        {
 
3742
                if(alreadyAttacked and (not powerSaving))       //If we already have built an attack force
 
3743
                {
 
3744
                        //Count rearm pads
 
3745
                        //----------------
 
3746
                        initEnumStruct(FALSE,vtolPad,player,player);
 
3747
                        structure= enumStruct();
 
3748
                        count    = 0;
 
3749
                        while(structure != NULLOBJECT)
 
3750
                        {
 
3751
                                count = count + 1;
 
3752
                                structure= enumStruct();
 
3753
                        }
 
3754
 
 
3755
                        //Do we have enough rearm pads?
 
3756
                        //-----------------------------
 
3757
                        if(count < ((maxTVtols + maxSVtols) / 2))
 
3758
                        {
 
3759
                                //Find nearest truck
 
3760
                                //------------------
 
3761
                                buildX = baseX;
 
3762
                                buildY = baseY;
 
3763
                                result = 99999;
 
3764
                                tempDroid = NULLOBJECT;
 
3765
                                initIterateGroup(buildGroup);
 
3766
                                droid = iterateGroup(buildGroup);
 
3767
                                while(droid != NULLOBJECT)
 
3768
                                {
 
3769
                                        if(droid.order == DORDER_NONE)
 
3770
                                        {
 
3771
                                                result2 = distBetweenTwoPoints(buildX, buildY, droid.x, droid.y);
 
3772
                                                if(result2 < result)
 
3773
                                                {
 
3774
                                                        result = result2;
 
3775
                                                        tempDroid = droid;
 
3776
                                                }
 
3777
                                        }
 
3778
                                        droid = iterateGroup(buildGroup);
 
3779
                                }
 
3780
 
 
3781
                                //Build vtol rearm pads
 
3782
                                //---------------------
 
3783
                                boolResult = pickStructLocation(vtolPad, ref buildX, ref buildY,player);
 
3784
                                if((boolResult == TRUE) and (tempDroid != NULLOBJECT))
 
3785
                                {
 
3786
                                        orderDroidStatsLoc(tempDroid, DORDER_BUILD, vtolPad, buildX, buildY);
 
3787
                                }
 
3788
                        }
 
3789
                }
 
3790
        }
 
3791
        else if((not powerSaving) and (alreadyAttacked))        //Build VTOL Factory
 
3792
        {
 
3793
                if(isStructureAvailable(vtolFactory,player))
 
3794
                {
 
3795
                        //Find nearest truck
 
3796
                        //------------------
 
3797
                        buildX = baseX;
 
3798
                        buildY = baseY;
 
3799
                        result = 99999;
 
3800
                        tempDroid = NULLOBJECT;
 
3801
                        initIterateGroup(buildGroup);
 
3802
                        droid = iterateGroup(buildGroup);
 
3803
                        while(droid != NULLOBJECT)
 
3804
                        {
 
3805
                                if(droid.order == DORDER_NONE)
 
3806
                                {
 
3807
                                        result2 = distBetweenTwoPoints(buildX, buildY, droid.x, droid.y);
 
3808
                                        if(result2 < result)
 
3809
                                        {
 
3810
                                                result = result2;
 
3811
                                                tempDroid = droid;
 
3812
                                        }
 
3813
                                }
 
3814
                                droid = iterateGroup(buildGroup);
 
3815
                        }
 
3816
 
 
3817
                        //Build VTOL Facrory
 
3818
                        //------------------
 
3819
                        boolResult = pickStructLocation(vtolFactory, ref buildX, ref buildY,player);
 
3820
                        if((boolResult == TRUE) and (tempDroid != NULLOBJECT))
 
3821
                        {
 
3822
                                orderDroidStatsLoc(tempDroid, DORDER_BUILD, vtolFactory, buildX, buildY);
 
3823
                        }
 
3824
                }
 
3825
        }
 
3826
}
 
3827
 
 
3828
//----------------------
 
3829
//      Build VTOLs
 
3830
//----------------------
 
3831
event buildVtols(buildVtolsTr)
 
3832
{
 
3833
        structure = getStructure(vtolPad,player);                       //Got vtol pads?
 
3834
        if((structure != NULLOBJECT) and (alreadyAttacked) and (not powerSaving))       //Got pads and already have an attack force                                     
 
3835
        {
 
3836
                structure = getStructure(vtolFactory,player);
 
3837
                if(structure != NULLOBJECT)
 
3838
                {
 
3839
                        //Check if we can afford heavy templates
 
3840
                        //--------------------------------------
 
3841
                        temp = 0;                       //Light templates
 
3842
                        if(playerPower(player) > muchoPower)
 
3843
                        {
 
3844
                                temp = 1;               //Use heavy, expensive templates, if can afford it
 
3845
                        }
 
3846
 
 
3847
                        //Check if we have any antitank template
 
3848
                        //--------------------------------------
 
3849
                        boolResult = FALSE;
 
3850
                        count = numTVtolTemplates - 1;
 
3851
                        count2 = 0;
 
3852
                        while((count >= 0) and (boolResult == FALSE))
 
3853
                        {
 
3854
                                if(skCanBuildTemplate(player,structure, tVtols[temp][count]))
 
3855
                                {
 
3856
                                        boolResult = TRUE;
 
3857
                                }
 
3858
                                count = count - 1;
 
3859
                        }
 
3860
 
 
3861
                        //Check if we have any antistructure template
 
3862
                        //-------------------------------------------
 
3863
                        boolResult2 = FALSE;
 
3864
                        count = numSVtolTemplates - 1;
 
3865
                        count2 = 0;
 
3866
                        while((count >= 0) and (not boolResult2))
 
3867
                        {
 
3868
                                if(skCanBuildTemplate(player,structure, sVtols[temp][count]) )
 
3869
                                {
 
3870
                                        boolResult2 = TRUE;
 
3871
                                }
 
3872
                                count = count - 1;
 
3873
                        }
 
3874
 
 
3875
                        //Build Cyborg Transport
 
3876
                        //-------------------------------------
 
3877
                        result = 0;
 
3878
                        if((transportDroid == NULLOBJECT) and (dropEnabled) and (transportGr.members > 7))
 
3879
                        {
 
3880
                                result = 3;
 
3881
                        }
 
3882
                        else
 
3883
                        {
 
3884
                                //Decide for which group to build VTOLs
 
3885
                                //-------------------------------------
 
3886
                                if((tVtolGr.members < maxTVtols) and ((tVtolGr.members <= sVtolGr.members) or (not boolResult2)))
 
3887
                                {
 
3888
                                        result = 1;     //tVtolGr
 
3889
                                }
 
3890
                                //else if((sVtolGr.members < maxSVtols) and ((sVtolGr.members < tVtolGr.members) or (not boolResult)))
 
3891
                                else if(sVtolGr.members < maxSVtols)
 
3892
                                {
 
3893
                                        result = 2;     //sVtolGr
 
3894
                                }
 
3895
                        }
 
3896
 
 
3897
                        //Build Vtols
 
3898
                        //-------------------------------------
 
3899
                        if(result > 0)
 
3900
                        {
 
3901
                                if(structureIdle(structure))    // if factory idle
 
3902
                                {
 
3903
                                        count2 = 0;
 
3904
                                        if(result == 2)         //sVtolGr
 
3905
                                        {
 
3906
                                                count = numSVtolTemplates - 1;
 
3907
                                                while((count2 < numSVtolTemplates) and (count >= 0))
 
3908
                                                {
 
3909
                                                        if(skCanBuildTemplate(player,structure, sVtols[temp][count]) )
 
3910
                                                        {
 
3911
                                                                tmplChoice[count2] = sVtols[temp][count];
 
3912
                                                                count2 = count2 + 1;
 
3913
                                                        }
 
3914
                                                        count = count - 1;
 
3915
                                                }
 
3916
                                        }
 
3917
                                        else if(result == 1)                            //tVtolGr
 
3918
                                        {
 
3919
                                                count = numTVtolTemplates - 1;
 
3920
                                                while((count2 < numTVtolTemplates) and (count >= 0))
 
3921
                                                {
 
3922
                                                        if(skCanBuildTemplate(player,structure, tVtols[temp][count]) )
 
3923
                                                        {
 
3924
                                                                tmplChoice[count2] = tVtols[temp][count];
 
3925
                                                                count2 = count2 + 1;
 
3926
                                                        }
 
3927
                                                        count = count - 1;
 
3928
                                                }
 
3929
                                        }
 
3930
                                        else    //Transport
 
3931
                                        {
 
3932
                                                count2 = 1;
 
3933
                                                tmplChoice[0] = Transport;
 
3934
                                        }
 
3935
 
 
3936
                                        //Build it
 
3937
                                        //--------------------
 
3938
                                        if(count2 > 0)
 
3939
                                        {
 
3940
                                                buildDroid(tmplChoice[random(count2)],structure,player,1);
 
3941
                                        }
 
3942
                                }
 
3943
                                structure = enumStruct();
 
3944
                        }
 
3945
                }
 
3946
        }
 
3947
}
 
3948
 
 
3949
//----------------------------
 
3950
// Build VTOL defenses
 
3951
//----------------------------
 
3952
event vtolDefend(vtolDefendTr)
 
3953
{
 
3954
        if(baseobj != NULLOBJECT)
 
3955
        {
 
3956
                if(baseobj.player != player)    //Wasn't our own tank
 
3957
                {
 
3958
                        //Break alliance if our ally has attacked us
 
3959
                        //------------------------------------------
 
3960
                        if(allianceExistsBetween(player, baseobj.player))       //If we allied
 
3961
                        {
 
3962
                                breakAlliance(player, baseobj.player);          //No backstabbing
 
3963
                        }
 
3964
 
 
3965
                        if(baseobj.type == OBJ_DROID)
 
3966
                        {
 
3967
                                if(isVtol(objToDroid(baseobj)))
 
3968
                                {
 
3969
                                        if(structure != NULLOBJECT)             //Attacked structure still exists
 
3970
                                        {
 
3971
                                                buildX = structure.x;
 
3972
                                                buildY = structure.y;
 
3973
 
 
3974
                                                result = 99999;
 
3975
                                                tempDroid = NULLOBJECT;
 
3976
        
 
3977
                                                initIterateGroup(buildGroup);
 
3978
                                                droid = iterateGroup(buildGroup);
 
3979
                                                while(droid != NULLOBJECT)
 
3980
                                                {
 
3981
                                                        if(droid.order == DORDER_NONE)
 
3982
                                                        {
 
3983
                                                                result2 = distBetweenTwoPoints(buildX, buildY, droid.x, droid.y);
 
3984
                                                                if(result2 < result)
 
3985
                                                                {
 
3986
                                                                        result = result2;
 
3987
                                                                        tempDroid = droid;
 
3988
                                                                }
 
3989
                                                        }
 
3990
                                                        droid = iterateGroup(buildGroup);
 
3991
                                                }
 
3992
 
 
3993
                                                if(tempDroid != NULLOBJECT)             //If we have a truck
 
3994
                                                {
 
3995
                                                        //Find best defense we can build
 
3996
                                                        //------------------------------
 
3997
                                                        count = 0;
 
3998
                                                        count2 = -1;
 
3999
                                                        while(count < numVtolDefStr)
 
4000
                                                        {
 
4001
                                                                if(isStructureAvailable(vtolDefStruct[count],player))
 
4002
                                                                {
 
4003
                                                                        count2 = count;
 
4004
                                                                }
 
4005
                                                                count = count + 1;
 
4006
                                                        }
 
4007
 
 
4008
                                                        if(count2 != (-1) )     //If we have a structure to build
 
4009
                                                        {
 
4010
                                                                boolResult = pickStructLocation(vtolDefStruct[count2], ref buildX, ref buildY,player);
 
4011
                                                                if(boolResult == TRUE)
 
4012
                                                                {
 
4013
                                                                        orderDroidStatsLoc(tempDroid, DORDER_BUILD, vtolDefStruct[count2],buildX,buildY);
 
4014
                                                                }
 
4015
                                                        }
 
4016
                                                }
 
4017
                                        }
 
4018
                                }
 
4019
                                else            //Attacked by a tank
 
4020
                                {
 
4021
                                        tVtolObject = baseobj;
 
4022
                                }       
 
4023
                        }
 
4024
                        else                    //Attacked by a structure
 
4025
                        {
 
4026
                                sVtolObject = baseobj;
 
4027
                        }
 
4028
 
 
4029
                        //Remember this attacker
 
4030
                        //if(defendObject == NULLOBJECT)                //Killed last attacker already, remember new one
 
4031
                        //{
 
4032
                                //Defend group
 
4033
                                if(structure != NULLOBJECT)             //Attacked structure still exists
 
4034
                                {
 
4035
                                        //If structure is in the base
 
4036
                                        if((structure.x > minx) and (structure.x < maxx) and (structure.y > miny) and (structure.y < maxy))
 
4037
                                        {
 
4038
                                                if(baseobj.type == OBJ_STRUCTURE)
 
4039
                                                {
 
4040
                                                        defendObject = baseobj;
 
4041
                                                }
 
4042
                                                else if(baseobj.type == OBJ_DROID)
 
4043
                                                {
 
4044
                                                        tempDroid = objToDroid(baseobj);
 
4045
                                                        //if(not isVtol(tempDroid))
 
4046
                                                        if(tempDroid.propulsion != vtolProp)
 
4047
                                                        {
 
4048
                                                                defendObject = baseobj;
 
4049
                                                        }
 
4050
                                                }
 
4051
                                        }
 
4052
                                }
 
4053
                        //}
 
4054
 
 
4055
                        //Attack
 
4056
                        if(defendObject != NULLOBJECT)
 
4057
                        {
 
4058
                                if(defendGr.members > 0)
 
4059
                                {
 
4060
                                        if(idleGroup(defendGr) >= (defendGr.members / 2))
 
4061
                                        {
 
4062
                                                showConsoleText(DebugMsg[13], player);          //Base attacked. Defending.
 
4063
 
 
4064
                                                orderGroupLoc(defendGr, DORDER_SCOUT, defendObject.x, defendObject.y);
 
4065
                                        }
 
4066
                                }
 
4067
 
 
4068
                                //Use collectSendGr group too, since they are just idling anyway
 
4069
                                if(collectSendGr.members > 0)
 
4070
                                {
 
4071
                                        if(idleGroup(collectSendGr) >= (collectSendGr.members / 2))
 
4072
                                        {
 
4073
                                                orderGroupLoc(collectSendGr, DORDER_SCOUT, defendObject.x, defendObject.y);
 
4074
                                        }
 
4075
                                }
 
4076
                                defendObject = NULLOBJECT;      //Reset
 
4077
                        }
 
4078
                }
 
4079
 
 
4080
        }
 
4081
}
 
4082
 
 
4083
 
 
4084
//----------------------------------
 
4085
//Build min number of VTOL defenses
 
4086
//----------------------------------
 
4087
event additVTOLDefenses(additVTOLDefensesTr)
 
4088
{
 
4089
        if((not defendingBase) and (alreadyAttacked))
 
4090
        {
 
4091
                //Count VTOL defenses
 
4092
                //-------------------
 
4093
                result = 0;
 
4094
                count = 0;
 
4095
                while(count < numVtolDefStr)
 
4096
                {
 
4097
                        initEnumStruct(FALSE,vtolDefStruct[count],player,player);
 
4098
                        structure = enumStruct();
 
4099
                        while(structure != NULLOBJECT)
 
4100
                        {
 
4101
                                if((structure.x > minx) and (structure.y > miny) and (structure.x < maxx) and (structure.y < maxy))     //If in the base
 
4102
                                {
 
4103
                                        result = result + 1;
 
4104
                                }
 
4105
                                structure = enumStruct();
 
4106
                        }
 
4107
                        count = count + 1;
 
4108
                }
 
4109
 
 
4110
                //Min number of VTOL defenses
 
4111
                temp = 16;              /*%!    ID="MinVTOL_AdditDefences",
 
4112
                                                MainDesc="Min number of VTOL defences",
 
4113
                                                type="asn",             //Assign
 
4114
                                                val="16",
 
4115
                                                ArgDesc="16 (Default)",
 
4116
                                                val="0",
 
4117
                                                ArgDesc="No additional defences",
 
4118
                                                val="5",
 
4119
                                                ArgDesc="5",
 
4120
                                                val="10",
 
4121
                                                ArgDesc="10",
 
4122
                                                val="20",
 
4123
                                                ArgDesc="20",
 
4124
                                                val="25",
 
4125
                                                ArgDesc="25",
 
4126
                                                val="30",
 
4127
                                                ArgDesc="30"    */
 
4128
                if(powerSaving)
 
4129
                {
 
4130
                        //Don't buld too many if not enough power
 
4131
                        temp = 7;       /*%!    ID="MinVTOL_AdditDefencesLowPow",
 
4132
                                                MainDesc="Low power VTOL defences",
 
4133
                                                type="asn",             //Assign
 
4134
                                                val="7",
 
4135
                                                ArgDesc="7 (Default)",
 
4136
                                                val="0",
 
4137
                                                ArgDesc="No additional defences",
 
4138
                                                val="3",
 
4139
                                                ArgDesc="3",
 
4140
                                                val="5",
 
4141
                                                ArgDesc="5",
 
4142
                                                val="7",
 
4143
                                                ArgDesc="7",
 
4144
                                                val="10",
 
4145
                                                ArgDesc="10",
 
4146
                                                val="temp",
 
4147
                                                ArgDesc="Same value as above"   */
 
4148
                }
 
4149
 
 
4150
                if(result < temp)
 
4151
                {
 
4152
                        //Find the best VTOL defense available
 
4153
                        //------------------------------------
 
4154
                        count = 0;
 
4155
                        temp = -1;
 
4156
                        while(count < numVtolDefStr)
 
4157
                        {
 
4158
                                if(isStructureAvailable(vtolDefStruct[count],player))
 
4159
                                {
 
4160
                                        temp = count;
 
4161
                                }
 
4162
                                count = count + 1;
 
4163
                        }
 
4164
 
 
4165
                        if(temp != (-1) )       //If we have a structure to build
 
4166
                        {
 
4167
                                buildX = baseX;
 
4168
                                buildY = baseY;
 
4169
 
 
4170
                                boolResult = pickStructLocation(vtolDefStruct[temp], ref buildX, ref buildY,player);
 
4171
                                if(boolResult == TRUE)
 
4172
                                {
 
4173
                                        //Find closest droid
 
4174
                                        //------------------------------------
 
4175
                                        result = 99999;
 
4176
                                        tempDroid = NULLOBJECT;
 
4177
 
 
4178
                                        initIterateGroup(buildGroup);
 
4179
                                        droid = iterateGroup(buildGroup);
 
4180
                                        while(droid != NULLOBJECT)
 
4181
                                        {
 
4182
                                                if(droid.order == DORDER_NONE)
 
4183
                                                {
 
4184
                                                        result2 = distBetweenTwoPoints(buildX, buildY, droid.x, droid.y);
 
4185
                                                        if(result2 < result)
 
4186
                                                        {
 
4187
                                                                result = result2;
 
4188
                                                                tempDroid = droid;
 
4189
                                                        }
 
4190
                                                }
 
4191
                                                droid = iterateGroup(buildGroup);
 
4192
                                        }
 
4193
 
 
4194
                                        if(tempDroid != NULLOBJECT)             //If we have a truck
 
4195
                                        {
 
4196
                                                orderDroidStatsLoc(tempDroid, DORDER_BUILD, vtolDefStruct[temp],buildX,buildY);
 
4197
                                        }
 
4198
                                }
 
4199
                        }
 
4200
 
 
4201
                }
 
4202
        }
 
4203
}
 
4204
 
 
4205
//------------------------------------------
 
4206
//Attack enemy objects in the base
 
4207
//------------------------------------------
 
4208
event agressiveDefence(agressiveDefenceTr)
 
4209
{
 
4210
        //If defenders got carried away from the base, make them return
 
4211
        if((defendGr.x < minx) or (defendGr.y < miny) or (defendGr.x > maxx) or (defendGr.y > maxy))
 
4212
        {
 
4213
                buildX = baseX;
 
4214
                buildY = baseY;
 
4215
                if(pickStructLocation(factory, ref buildX, ref buildY, player))         //Find an open spot
 
4216
                {
 
4217
                        orderGroupLoc(defendGr, DORDER_SCOUT, buildX, buildY);          //Send back
 
4218
                        orderGroupLoc(collectSendGr, DORDER_SCOUT, buildX, buildY);     //Send back
 
4219
                }
 
4220
        }
 
4221
 
 
4222
        result = defendGr.members + collectSendGr.members;
 
4223
        if(result > 3)          //Have defenders
 
4224
        {
 
4225
                if((idleGroup(defendGr) + idleGroup(collectSendGr)) > (result / 2))     //Not busy
 
4226
                {
 
4227
                        //Find enemy droids in the base
 
4228
                        //-----------------------------
 
4229
                        resetDroidTargets();
 
4230
                        setDroidTarPref(DT_WEAP_GROUND);        //Ignore VTOLs, tanks only
 
4231
                        setDroidTarIgnore(DT_VTOL);
 
4232
 
 
4233
                        tempDroid = NULLOBJECT;
 
4234
                        count = 0;
 
4235
                        while((count < numEnemies) and (tempDroid == NULLOBJECT))
 
4236
                        {
 
4237
                                tempDroid = droidTargetInArea(Enemies[count], player, minx, miny, maxx, maxy);  //Droid
 
4238
                                count = count + 1;
 
4239
                        }
 
4240
 
 
4241
                        if(tempDroid != NULLOBJECT)
 
4242
                        {
 
4243
                                //Check if we are following our own tank
 
4244
                                //--------------------------------------
 
4245
                                if((tempDroid.player == player) or (isVtol(tempDroid)))
 
4246
                                {
 
4247
                                        tempDroid = NULLOBJECT;
 
4248
                                }
 
4249
 
 
4250
                        }
 
4251
 
 
4252
                        //Still have an attacker
 
4253
                        if(tempDroid != NULLOBJECT)
 
4254
                        {
 
4255
                                showConsoleText(DebugMsg[14], player);          //Agressive defence
 
4256
                                orderGroupLoc(defendGr, DORDER_SCOUT, tempDroid.x, tempDroid.y);
 
4257
                                orderGroupLoc(collectSendGr, DORDER_SCOUT, tempDroid.x, tempDroid.y);
 
4258
 
 
4259
                                if(idleGroup(sVtolGr) == sVtolGr.members)
 
4260
                                {
 
4261
                                        orderGroupObj(sVtolGr, DORDER_ATTACK, tempDroid);
 
4262
                                }
 
4263
 
 
4264
                                if(idleGroup(tVtolGr) == tVtolGr.members)
 
4265
                                {
 
4266
                                        orderGroupObj(tVtolGr, DORDER_ATTACK, tempDroid);
 
4267
                                }
 
4268
 
 
4269
                        }
 
4270
 
 
4271
                }
 
4272
        }
 
4273
}
 
4274
 
 
4275
//-------------------------
 
4276
//      Attack with VTOLs
 
4277
//-------------------------
 
4278
event vtolAttack(vtolAttackTr)
 
4279
{
 
4280
        temp = (KeepDist / 2);                  //Enemy base range
 
4281
        //if(attackPhase > 1)
 
4282
        if(curEnemy != -1)
 
4283
        {
 
4284
                //-------------------------
 
4285
                //Attack with anitank VTOLs
 
4286
                //-------------------------
 
4287
                boolResult = FALSE;
 
4288
                if(tVtolObject == NULLOBJECT)           //No target
 
4289
                {
 
4290
                        boolResult = TRUE;
 
4291
                }
 
4292
                //else if(tVtolObject.player != curEnemy)               //Attacking another player
 
4293
                //{
 
4294
                //      boolResult = TRUE;
 
4295
                //}
 
4296
 
 
4297
                //If we can attack
 
4298
                if(boolResult)
 
4299
                {
 
4300
                        resetDroidTargets();
 
4301
                        setDroidTarPref(DT_CONSTRUCT);                  //Find truck to attack
 
4302
                        //tempDroid = droidTargetInArea(curEnemy, -1, curEnemyX - temp, curEnemyY - temp, curEnemyX + temp, curEnemyY + temp);
 
4303
 
 
4304
                        //if(tempDroid == NULLOBJECT)
 
4305
                        //{
 
4306
                                tempDroid = droidTargetOnMap(curEnemy, -1);
 
4307
                        //}
 
4308
 
 
4309
                        if(tempDroid == NULLOBJECT)                             //No truck, find another unit
 
4310
                        {
 
4311
                                resetDroidTargets();
 
4312
                                setDroidTarPref(DT_WEAP_GROUND);                //Ground,air,idf units
 
4313
                                setDroidTarIgnore(DT_LEGS);                     //Ignore cyborgs
 
4314
                                setDroidTarIgnore(DT_LIGHT);                    //Ignore light units
 
4315
                                tempDroid = droidTargetOnMap(curEnemy, curEnemy);
 
4316
                                //tempDroid = droidTargetInArea(curEnemy, curEnemy, curEnemyX - temp, curEnemyY - temp, curEnemyX + temp, curEnemyY + temp);
 
4317
                        }
 
4318
 
 
4319
 
 
4320
                        if(tempDroid != NULLOBJECT)                             //Attack
 
4321
                        {
 
4322
                                tVtolObject = tempDroid;                        //Remember
 
4323
                        }
 
4324
                }
 
4325
 
 
4326
                //-------------------------------
 
4327
                //Attack with antistructure VTOLs
 
4328
                //-------------------------------
 
4329
                boolResult = FALSE;
 
4330
                if(sVtolObject == NULLOBJECT)           //No target
 
4331
                {
 
4332
                        boolResult = TRUE;
 
4333
                }
 
4334
                //else if(sVtolObject.player != curEnemy)               //Attacking another player
 
4335
                //{
 
4336
                //      boolResult = TRUE;
 
4337
                //}
 
4338
 
 
4339
                //If we can attack
 
4340
                if(boolResult)
 
4341
                {
 
4342
                        count = 0;
 
4343
                        structure = NULLOBJECT;
 
4344
                        while((count < 6) and (structure == NULLOBJECT))
 
4345
                        {
 
4346
                                resetStructTargets();
 
4347
                                setStructTarPref(sPref[count]);                 //Find structure to attack
 
4348
                                structure = structTargetInArea(curEnemy, -1, curEnemyX - temp, curEnemyY - temp, curEnemyX + temp, curEnemyY + temp);
 
4349
                                count = count + 1;
 
4350
                        }
 
4351
 
 
4352
                        if(structure == NULLOBJECT)                             //No structure, find another structure
 
4353
                        {
 
4354
                                resetStructTargets();
 
4355
                                setStructTarPref(ST_DEF_ALL);                   //Ground,air,idf
 
4356
                                structure = structTargetOnMap(curEnemy, -1);
 
4357
                        }
 
4358
 
 
4359
                        if(structure != NULLOBJECT)                             //Attack
 
4360
                        {
 
4361
                                sVtolObject = structure;                        //Remember
 
4362
                        }
 
4363
                }
 
4364
        }
 
4365
        else
 
4366
        {
 
4367
                //-------------------------
 
4368
                //Attack with anitank VTOLs
 
4369
                //-------------------------
 
4370
                if(tVtolObject == NULLOBJECT)
 
4371
                {
 
4372
                        //Find truck
 
4373
                        resetDroidTargets();
 
4374
                        setDroidTarPref(DT_CONSTRUCT);
 
4375
 
 
4376
                        count = 0;
 
4377
                        droid = NULLOBJECT;
 
4378
                        while((count < numEnemies) and (droid == NULLOBJECT))
 
4379
                        {
 
4380
                                droid = droidTargetOnMap(Enemies[count], Enemies[count]);
 
4381
                                count = count + 1;
 
4382
                        }
 
4383
 
 
4384
                        //No truck, find another unit
 
4385
                        if(droid == NULLOBJECT)
 
4386
                        {
 
4387
                                resetDroidTargets();
 
4388
                                setDroidTarPref(DT_WEAP_ALL);           //Any weapon unit
 
4389
 
 
4390
                                count = 0;
 
4391
                                droid = NULLOBJECT;
 
4392
                                while((count < numEnemies) and (droid == NULLOBJECT))
 
4393
                                {
 
4394
                                        droid = droidTargetOnMap(Enemies[count], Enemies[count]);
 
4395
                                        count = count + 1;
 
4396
                                }
 
4397
                        }
 
4398
 
 
4399
                        if(droid != NULLOBJECT)
 
4400
                        {
 
4401
                                tVtolObject = droid;
 
4402
                        }
 
4403
                }
 
4404
 
 
4405
                //-------------------------------
 
4406
                //Attack with antistructure VTOLs
 
4407
                //-------------------------------
 
4408
                if(sVtolObject == NULLOBJECT)
 
4409
                {
 
4410
                        //Find structure
 
4411
                        count = 0;
 
4412
                        structure = NULLOBJECT;
 
4413
                        while((count < numEnemies) and (structure == NULLOBJECT))
 
4414
                        {
 
4415
                                count2 = 0;
 
4416
                                while((count2 < 6) and (structure == NULLOBJECT))
 
4417
                                {
 
4418
                                        resetStructTargets();
 
4419
                                        setStructTarPref(sPref[count2]);                        //Find structure to attack
 
4420
                                        structure = structTargetOnMap(Enemies[count], Enemies[count]);
 
4421
                                        count2 = count2 + 1;
 
4422
                                }
 
4423
                                count = count + 1;
 
4424
                        }
 
4425
 
 
4426
                        if(structure != NULLOBJECT)
 
4427
                        {
 
4428
                                sVtolObject = structure;
 
4429
                        }
 
4430
                }
 
4431
        }
 
4432
 
 
4433
 
 
4434
        //------
 
4435
        //Attack
 
4436
        //------
 
4437
 
 
4438
        //Antitank
 
4439
        if(tVtolObject != NULLOBJECT)
 
4440
        {
 
4441
                if((idleGroup(tVtolGr) >= (tVtolGr.members - 1)) and (tVtolGr.members >= maxTVtols))            //Enough VTOLs?
 
4442
                {
 
4443
                        orderGroupObj(tVtolGr, DORDER_ATTACK, tVtolObject);             //Attack
 
4444
                }
 
4445
                else if((idleGroup(tVtolGr) <= (tVtolGr.members / 2)) and (tVtolGr.members <= (maxTVtols / 2)))
 
4446
                {
 
4447
                        orderGroup(tVtolGr, DORDER_RTB);
 
4448
                }
 
4449
        }
 
4450
 
 
4451
        //Antistructure
 
4452
        if(sVtolObject != NULLOBJECT)
 
4453
        {
 
4454
                if((idleGroup(sVtolGr) >= (sVtolGr.members - 1)) and (sVtolGr.members >= maxSVtols))            //Enough VTOLs?
 
4455
                {
 
4456
                        orderGroupObj(sVtolGr, DORDER_ATTACK, sVtolObject);             //Attack
 
4457
                }
 
4458
                else if((idleGroup(sVtolGr) <= (sVtolGr.members / 2)) and (sVtolGr.members <= (maxSVtols / 2)))         //Return home
 
4459
                {
 
4460
                        orderGroup(sVtolGr, DORDER_RTB);
 
4461
                }
 
4462
        }
 
4463
}
 
4464
 
 
4465
/////////////////////////////////////////////////////////////////////
 
4466
/////////////////////////////////////////////////////////////////////
 
4467
// Alliance Rules
 
4468
 
 
4469
// form alliances
 
4470
event formAllianceEvent(every, 170)
 
4471
{
 
4472
        if( (player == selectedPlayer) or (not myResponsibility(player)) )
 
4473
        {       
 
4474
                setEventTrigger(formAllianceEvent,      inactive);                      
 
4475
        }
 
4476
        else
 
4477
        {
 
4478
                count = 0;
 
4479
                while(count<8)
 
4480
                {
 
4481
                        if( count != player )                                                                                           // if not the only other player and rand2
 
4482
                        {
 
4483
                                if((getDroidCount(player) > 1) and (getDroidCount(count) > 1) ) // not dead
 
4484
                                {
 
4485
                                                if(not isHumanPlayer(count))                                                    // not human
 
4486
                                                {
 
4487
                                                        createAlliance(player,count);
 
4488
                                                        allianceTime[count] = gameTime;
 
4489
                                                }
 
4490
                                }
 
4491
                        }
 
4492
                        count = count + 1;      
 
4493
                }
 
4494
                setEventTrigger(formAllianceEvent,      inactive);
 
4495
        }
 
4496
}
 
4497
 
 
4498
//--------------------
 
4499
//Human alliances
 
4500
//--------------------
 
4501
event formHumanAlliances(humanAllianceTr)
 
4502
{
 
4503
        if(count2 == player) //If offered to me
 
4504
        {
 
4505
                randomiseSeed();
 
4506
                if(random(2) == 1)
 
4507
                {
 
4508
                        showConsoleText(ai_ally_msg[random(4)],count);
 
4509
                }
 
4510
        }
 
4511
}
 
4512
 
 
4513
//=====================================================================================================
 
4514
//                                      CYBORG TRANSPORT
 
4515
//=====================================================================================================
 
4516
event cyborgDrop(cyborgDropTr)
 
4517
{
 
4518
        /********************************
 
4519
                dropPhase:
 
4520
                0 - idle
 
4521
                1 - loading
 
4522
                2 - on the way to lz
 
4523
                3 - landing
 
4524
                4 - landed and released cyborgs, transport returning home
 
4525
        ********************************/
 
4526
 
 
4527
        //Wait until all droids are loaded
 
4528
        //--------------------------------
 
4529
        if(dropPhase == 1)              //Loading
 
4530
        {
 
4531
                boolResult = TRUE;
 
4532
                if(transportDroid == NULLOBJECT)                //Was destroyed
 
4533
                {
 
4534
                        boolResult = FALSE;
 
4535
                        dropPhase = 0;                  //Stop
 
4536
                }
 
4537
 
 
4538
                if(boolResult)          //If transport is still there
 
4539
                {
 
4540
                        
 
4541
 
 
4542
                        //Check if all droids are idle (loaded into transport)
 
4543
                        //----------------------------------------------------
 
4544
                        boolResult = TRUE;
 
4545
                        initIterateGroup(transportGr);
 
4546
                        droid = iterateGroup(transportGr);
 
4547
                        while(droid != NULLOBJECT)
 
4548
                        {
 
4549
                                if(distBetweenTwoPoints(droid.x, droid.y, transportDroid.x, transportDroid.y) > 256)
 
4550
                                {
 
4551
                                        boolResult = FALSE;
 
4552
                                        if((droid.orderx != transportDroid.x) or (droid.ordery != transportDroid.y))            //Not going to the transport
 
4553
                                        {
 
4554
                                                orderDroidLoc(droid, DORDER_MOVE, transportDroid.x, transportDroid.y);          //Go to the transport
 
4555
                                        }
 
4556
                                }
 
4557
                                else            //Load
 
4558
                                {
 
4559
                                        vanishUnit(droid);
 
4560
                                }
 
4561
 
 
4562
                                droid = iterateGroup(transportGr);
 
4563
                        }
 
4564
 
 
4565
                        //Order transport to fly to the enemy to unload the units
 
4566
                        //-------------------------------------------------------
 
4567
                        if((boolResult) and (curEnemy >= 0) and (curEnemyX > 0))                        //If all loaded
 
4568
                        {
 
4569
                                //Find an enemy base structure that is far away from the tank attack point
 
4570
                                //------------------------------------------------------------------------
 
4571
                                count = 0;
 
4572
                                boolResult = FALSE;
 
4573
                                temp = (30 * 128);              //Enemy base radius
 
4574
                                result = 0;
 
4575
                                while(count < numBaseStructs)
 
4576
                                {
 
4577
                                        initEnumStruct(FALSE,baseStructs[count],curEnemy,player);               //Find visible in-base structure that is far away from the attack point (more efficient)
 
4578
                                        structure = enumStruct();
 
4579
                                        while(structure != NULLOBJECT)
 
4580
                                        {
 
4581
                                                //if(losTwoObjects(transportDroid, structure, FALSE))   //If can see enemy base structure
 
4582
                                                //{
 
4583
                                                        
 
4584
                                                        result2 = distBetweenTwoPoints(curEnemyX,curEnemyY, structure.x, structure.y);
 
4585
                                                        if(result2 < temp)              //In the enemy base
 
4586
                                                        {
 
4587
                                                                //setFogColour(1, random(200) + 50, 1);
 
4588
                                                                if(result2 > result)    //Further away
 
4589
                                                                {
 
4590
                                                                        //setFogColour(1, 1, random(200) + 50);
 
4591
                                                                        result = result2;
 
4592
                                                                        LZ_X = structure.x;
 
4593
                                                                        LZ_Y = structure.y;
 
4594
                                                                }
 
4595
                                                        }
 
4596
                                                //}
 
4597
                                                structure = enumStruct();
 
4598
                                        }
 
4599
                                        count = count + 1;
 
4600
                                }
 
4601
 
 
4602
                                //setFogColour(random(200) + 50, 1, 1);
 
4603
 
 
4604
                                if(result == 0)
 
4605
                                {
 
4606
                                        temp = (7 * 128);       //temp / 2;
 
4607
                                        resetStructTargets();
 
4608
                                        structure = structTargetInArea(curEnemy, player, curEnemyX - temp, curEnemyY - temp, curEnemyX + temp, curEnemyY + temp);
 
4609
                                        if(structure != NULLOBJECT)
 
4610
                                        {
 
4611
                                                //setFogColour(1, random(200) + 50, random(200) + 50);
 
4612
                                                LZ_X = structure.x;
 
4613
                                                LZ_Y = structure.y;
 
4614
                                                result = 1;
 
4615
                                        }
 
4616
                                }
 
4617
 
 
4618
                                if(result > 0)  //Found a structure
 
4619
                                {
 
4620
                                        temp = (7 * 128);
 
4621
                                        //resetStructTargets();
 
4622
                                        //setStructTarPref(ST_DEF_AIR);         //Make sure no AA
 
4623
                                        //structure = structTargetInArea(curEnemy, curEnemy, LZ_X - temp, LZ_Y - temp, LZ_X + temp, LZ_Y + temp);
 
4624
                                        //if(structure == NULLOBJECT)   //No AA
 
4625
                                        //{
 
4626
                                                boolResult = pickStructLocation(wall, ref LZ_X, ref LZ_Y,player);
 
4627
                                                if(boolResult)
 
4628
                                                {
 
4629
                                                        //centreViewPos(LZ_X, LZ_Y);
 
4630
                                                        //setFogColour(random(200) + 50, 1, random(200) + 50);
 
4631
                                                        orderDroidLoc(transportDroid, DORDER_MOVE, LZ_X, LZ_Y);
 
4632
 
 
4633
                                                        if(transportDroid.order != DORDER_NONE)
 
4634
                                                        {
 
4635
                                                                dropPhase = 2;
 
4636
                                                        }
 
4637
                                                        else
 
4638
                                                        {
 
4639
                                                                resetPlayerVisibility(player);          //Reset structures which were discovered and *are not visible anymore*
 
4640
                                                        }
 
4641
                                                }
 
4642
                                        //}
 
4643
                                }
 
4644
 
 
4645
                                //orderDroidLoc(transportDroid, DORDER_SCOUT, LZ_X, LZ_Y);              //Take off
 
4646
                        }
 
4647
                }
 
4648
        }
 
4649
        else if(dropPhase == 2)         //On the way to LZ
 
4650
        {
 
4651
                
 
4652
 
 
4653
                if(transportDroid != NULLOBJECT)
 
4654
                {
 
4655
                        if(transportDroid.order == DORDER_NONE)         //If reached LZ and is landing
 
4656
                        {
 
4657
                                dropPhase = 3;
 
4658
                                transportZ = -1;                //Remember current height of the transport
 
4659
                        }
 
4660
                }
 
4661
                else            //Transport destroyed
 
4662
                {
 
4663
                        dropPhase = 0;
 
4664
                }
 
4665
        }
 
4666
        else if(dropPhase == 3)         //Landing on LZ
 
4667
        {
 
4668
                
 
4669
 
 
4670
                //Release cyborgs if stopped landiong
 
4671
                //-----------------------------------
 
4672
                if(transportDroid != NULLOBJECT)
 
4673
                {
 
4674
                        if(transportZ == transportDroid.z)      //If stopped landing
 
4675
                        {
 
4676
                                //setFogColour(random(200) + 50, 1, 1);
 
4677
 
 
4678
                                //'Unload' best cyborgs with best templates available
 
4679
                                //---------------------------------------------------
 
4680
                                structure = getStructure(cybFactory,player);
 
4681
                                if(structure != NULLOBJECT)
 
4682
                                {
 
4683
                                        if(cybTemplate > -1)
 
4684
                                        {
 
4685
                                                //setFogColour(random(200) + 50, random(200) + 50, 1);
 
4686
 
 
4687
                                                //Cyborgs with weapons
 
4688
                                                //--------------------
 
4689
                                                result = 0;
 
4690
                                                while(result < 8)               //Unload 8 weapon cyborgs
 
4691
                                                {
 
4692
                                                        
 
4693
                                                        droid = addDroid(cybTmpl[cybTemplate], transportDroid.x, transportDroid.y, player);
 
4694
                                                        if(droid != NULLOBJECT)
 
4695
                                                        {
 
4696
                                                                //orderDroid(droid, DORDER_RUN);                //Don't stay too compact
 
4697
                                                                //groupAddDroid(attackGroup, droid);
 
4698
                                                                groupAddDroid(dropGr, droid);
 
4699
                                                        }
 
4700
                                                        result = result + 1;
 
4701
                                                }
 
4702
 
 
4703
                                                //Mechanics
 
4704
                                                //--------------------
 
4705
                                                result = 0;
 
4706
                                                while(result < 2)               //Unload 2 mechanics
 
4707
                                                {
 
4708
                                                        droid = addDroid(cybMechanic, transportDroid.x, transportDroid.y, player);      //Add mechanic
 
4709
                                                        //groupAddDroid(attackGroup,droid);
 
4710
                                                        groupAddDroid(dropGr, droid);
 
4711
                                                        result = result + 1;
 
4712
                                                }
 
4713
                                                
 
4714
                                        }
 
4715
                                }
 
4716
 
 
4717
 
 
4718
                                orderDroid(transportDroid, DORDER_RTB);
 
4719
                                //orderDroidLoc(transportDroid, DORDER_MOVE, baseX, baseY);     //Send transport back to the base
 
4720
                                dropPhase = 4;
 
4721
                        }
 
4722
                }
 
4723
                else    //Transport destroyed
 
4724
                {
 
4725
                        dropPhase = 0;
 
4726
                }
 
4727
 
 
4728
                transportZ = transportDroid.z;
 
4729
        }
 
4730
        else if(dropPhase == 4)         //Transport returning to the base
 
4731
        {
 
4732
 
 
4733
                if(transportDroid != NULLOBJECT)
 
4734
                {
 
4735
                        if(transportDroid.order == DORDER_NONE)         //If reached LZ and is landing
 
4736
                        {
 
4737
                                dropPhase = 0;
 
4738
                        }
 
4739
                }
 
4740
                else
 
4741
                {
 
4742
                        dropPhase = 0;
 
4743
                }
 
4744
        }
 
4745
 
 
4746
        if((attackPhase > 2) and (dropPhase == 0))      //Attacking enemy base and not already transporting
 
4747
        //if(dropPhase == 0)    //Attacking enemy base and not already transporting
 
4748
        {
 
4749
                if((transportDroid != NULLOBJECT) and (curEnemyX > 0))
 
4750
                {
 
4751
                        if((transportGr.members >= 10) and (transportDroid.order == DORDER_NONE))
 
4752
                        {
 
4753
                                showConsoleText(DebugMsg[8], player);           //Initializing drop
 
4754
 
 
4755
                                //Load transport
 
4756
                                //----------------------------
 
4757
                                initIterateGroup(transportGr);
 
4758
                                droid = iterateGroup(transportGr);
 
4759
                                while(droid != NULLOBJECT)
 
4760
                                {
 
4761
                                        orderDroidLoc(droid, DORDER_MOVE, transportDroid.x, transportDroid.y);
 
4762
                                        //setDroidSecondary(droid, DSO_RETURN_TO_LOC, DSS_RTL_TRANSPORT);
 
4763
                                        //orderDroidObj(droid, DORDER_EMBARK, transportDroid);
 
4764
                                        droid = iterateGroup(transportGr);
 
4765
                                }
 
4766
 
 
4767
                                //LZ_X = curEnemyX;
 
4768
                                //LZ_Y = curEnemyY;
 
4769
 
 
4770
                                dropPhase = 1;          //Loading Transport
 
4771
                        }
 
4772
                }
 
4773
        }
 
4774
}
 
4775
 
 
4776
//---------------------------------------------
 
4777
//Attack with cyborgs
 
4778
//---------------------------------------------
 
4779
event manageDropAttacks(manageDropAttacksTr)
 
4780
{
 
4781
        if(dropGr.members > 0)
 
4782
        {
 
4783
                if(idleGroup(dropGr) >= (dropGr.members / 2))
 
4784
                {
 
4785
                        if((curEnemyX > 0) and (curEnemy > -1))
 
4786
                        {
 
4787
                                //Find a target
 
4788
                                //-------------
 
4789
                                tempX = dropGr.x;
 
4790
                                tempY = dropGr.y;
 
4791
                                temp = (15 * 128);
 
4792
                                count = 0;              //Attack base structures
 
4793
                                while(count < numBaseStructs)
 
4794
                                {
 
4795
                                        initEnumStruct(FALSE,baseStructs[count],curEnemy,player);                       
 
4796
                                        structure = enumStruct();
 
4797
                                        while(structure != NULLOBJECT)
 
4798
                                        {
 
4799
                                                if(distBetweenTwoPoints(tempX, tempY, structure.x, structure.y) < temp)         //If in the enemy base
 
4800
                                                {
 
4801
                                                        boolResult = TRUE;
 
4802
                                                        initIterateGroup(dropGr);
 
4803
                                                        droid = iterateGroup(dropGr);
 
4804
                                                        while(droid != NULLOBJECT)
 
4805
                                                        {
 
4806
                                                                //if(droid.droidType != DROID_REPAIR)           //Mechanics stay near the group
 
4807
                                                                //{
 
4808
                                                                        if(droid.order != DORDER_ATTACK)        //Not already attacking
 
4809
                                                                        {
 
4810
                                                                                if(losTwoObjects(droid, structure, FALSE))      //If can see this structure
 
4811
                                                                                {
 
4812
                                                                                        orderDroidObj(droid, DORDER_ATTACK, structure);
 
4813
                                                                                        //sVtolObject = structure;
 
4814
                                                                                }
 
4815
                                                                        }
 
4816
                                                                //}
 
4817
                                                                droid = iterateGroup(dropGr);
 
4818
                                                        }
 
4819
                                                }
 
4820
                                                structure = enumStruct();
 
4821
                                        }
 
4822
                                        count = count + 1;
 
4823
                                }
 
4824
 
 
4825
                                //Still no target, attack the base
 
4826
                                //--------------------------------
 
4827
                                if(idleGroup(dropGr) >= (dropGr.members / 2))
 
4828
                                {
 
4829
                                        orderGroupLoc(dropGr, DORDER_SCOUT, curEnemyX, curEnemyY);
 
4830
                                }
 
4831
                        }
 
4832
                }
 
4833
        }
 
4834
}
 
4835
 
 
4836
//------------------------------------------------------
 
4837
//Make attackers return to the base if base is in danger
 
4838
//------------------------------------------------------
 
4839
event WatchDefendBase(WatchDefendBaseTr)
 
4840
{
 
4841
        //temp = 20 * 128;      //Search radius
 
4842
 
 
4843
        //if(bigMap)
 
4844
        //{
 
4845
        //      temp = 12 * 128;
 
4846
        //}
 
4847
        //else
 
4848
        //{
 
4849
        //      temp = 0;
 
4850
        //}
 
4851
 
 
4852
        //tempX = minx - temp;
 
4853
        //tempY = miny - temp;
 
4854
        //buildX = maxx + temp;
 
4855
        //buildY = maxy + temp;
 
4856
 
 
4857
        tempX = minx;
 
4858
        tempY = miny;
 
4859
        buildX = maxx;
 
4860
        buildY = maxy;
 
4861
 
 
4862
        //Check everything's within limits
 
4863
        //--------------------------------
 
4864
        if(tempX < 0)                   {       tempX = 128;    }
 
4865
        if(tempY < 0)                   {       tempY = 128;    }
 
4866
        if(buildX > (mapWidth * 128))   {       buildX = (mapWidth * 128) - 128;        }
 
4867
        if(buildY > (mapHeight * 128))  {       buildY = (mapHeight * 128) - 128;       }
 
4868
 
 
4869
        //Count enemies
 
4870
        //--------------------------
 
4871
        resetDroidTargets();
 
4872
        setDroidTarPref(DT_WEAP_GROUND);        //Tanks only, ignore VTOLs
 
4873
        result = 0;
 
4874
        count = 0;
 
4875
        while(count < numEnemies)
 
4876
        {
 
4877
                result = numDroidsInArea(Enemies[count], tempX, tempY, buildX, buildY) + result;        //Count enemy units
 
4878
                count = count + 1;
 
4879
        }
 
4880
 
 
4881
 
 
4882
        //---------------------------
 
4883
        //If not defending right now
 
4884
        //---------------------------
 
4885
        if(not defendingBase)
 
4886
        {
 
4887
                //If too many enemies
 
4888
                //---------------------------------
 
4889
                if(result > (defendGr.members + collectSendGr.members + 5))     //collectSendGr is also in the base
 
4890
                {
 
4891
                        defendingBase = TRUE;
 
4892
                        powerSaving = TRUE;             //Save some power
 
4893
                        attackPhase = 1;                //Re-initialize attack later
 
4894
 
 
4895
                        showConsoleText(DebugMsg[0], player);   //Base defence active
 
4896
 
 
4897
                        NumOldDefenders = defendGr.members;     //Revert to this number after threat is gone
 
4898
 
 
4899
                        //Order back to the base (before addign to defeners, so that defenders wouldn't cancel defending, if they already are)
 
4900
                        orderGroupLoc(sendOutpostGr, DORDER_MOVE, baseX, baseY);
 
4901
                        orderGroupLoc(collectSendGr, DORDER_MOVE, baseX, baseY);
 
4902
                        orderGroupLoc(attackGroup, DORDER_MOVE, baseX, baseY);
 
4903
                        orderGroupLoc(oilGr, DORDER_MOVE, baseX, baseY);
 
4904
                        orderGroupLoc(repairedGroup, DORDER_MOVE, baseX, baseY);
 
4905
 
 
4906
                        //Add to defenders now
 
4907
                        groupAddGroup(defendGr, sendOutpostGr);
 
4908
                        groupAddGroup(defendGr, repairedGroup);
 
4909
                        groupAddGroup(defendGr, collectSendGr);
 
4910
                        groupAddGroup(defendGr, attackGroup);
 
4911
                        groupAddGroup(defendGr, oilGr);
 
4912
 
 
4913
                        setGroupSecondary(defendGr, DSO_REPAIR_LEVEL, DSS_REPLEV_NEVER);        //Don't return to the outpost for repair
 
4914
                }
 
4915
        }
 
4916
        else            //If defending and no threat, then cancel defend state
 
4917
        {
 
4918
                boolResult = FALSE;
 
4919
                if(result < 2)          //Almost all kiled
 
4920
                {
 
4921
                        boolResult = TRUE;
 
4922
                }
 
4923
                //else                  //Compare number of enemy and friendly units in the base
 
4924
                //{
 
4925
                //      result2 = numDroidsInArea(player, tempX, tempY, buildX, buildY);
 
4926
                //      if(result2 > (result + 8))
 
4927
                //      {
 
4928
                //              boolResult = TRUE;
 
4929
                //      }
 
4930
                //}
 
4931
 
 
4932
                if(boolResult)          //Can stop defending
 
4933
                {
 
4934
                        showConsoleText(DebugMsg[1], player);   //Base defence off
 
4935
                        defendingBase = FALSE;
 
4936
 
 
4937
                        if(NumOldDefenders < 8)         //Leave enough defenders
 
4938
                        {
 
4939
                                NumOldDefenders = 8;
 
4940
                        }
 
4941
 
 
4942
                        //Add defenders back to attackers
 
4943
                        //-------------------------------
 
4944
                        count = defendGr.members;
 
4945
                        initIterateGroup(defendGr);
 
4946
                        droid = iterateGroup(defendGr);
 
4947
                        while((droid != NULLOBJECT) and (count > NumOldDefenders))              //While there are now more defenders that there were
 
4948
                        {
 
4949
                                if(droid.droidType != DROID_REPAIR)             //Leave repair unit for the defenders
 
4950
                                {
 
4951
                                        orderDroid(droid, DORDER_STOP);         //Make idle
 
4952
                                        groupAddDroid(sendOutpostGr, droid);    //Add back to attackers
 
4953
                                        count = count - 1;      
 
4954
                                }
 
4955
                                droid = iterateGroup(defendGr);
 
4956
                        }
 
4957
 
 
4958
                        toRepDefendDroid[0] = NULLOBJECT;               //Make repairer stop following this unit if it became an attacker
 
4959
                        toRepDefendDroid[1] = NULLOBJECT;
 
4960
 
 
4961
                        NumOldDefenders = 0;
 
4962
 
 
4963
                }
 
4964
        }
 
4965
}
 
4966
 
 
4967
//-------------------------------------
 
4968
//Help an ally if he's in trouble
 
4969
//-------------------------------------
 
4970
event WatchHelpAlly(WatchHelpAllyTr)
 
4971
{
 
4972
        temp = (12 * 128);      //Base radius around the found structure
 
4973
 
 
4974
        if((not defendingBase) and (helpAllyPlayer < 0))        //Not busy
 
4975
        {
 
4976
                if(attackGroup.members > 5)
 
4977
                {
 
4978
                        count = 0;
 
4979
                        while((count < 8) and (helpAllyPlayer < 0))     //For all 8 players and while haven't started helping to defend yet
 
4980
                        {
 
4981
                                if(allyPlayer[count])
 
4982
                                {
 
4983
                                        //Find ally base
 
4984
                                        //--------------------------------------
 
4985
                                        boolResult2 = FALSE;
 
4986
                                        count2 = 0;
 
4987
                                        while((count2 < numBaseStructs) and (not boolResult2))  //For all base structures
 
4988
                                        {
 
4989
                                                structure = getStructure(baseStructs[count2], count);   //Find Ally's base structure
 
4990
                                                if(structure != NULLOBJECT)
 
4991
                                                {
 
4992
                                                        tempX = structure.x;
 
4993
                                                        tempY = structure.y;
 
4994
                                                        boolResult2 = TRUE;             //Found base
 
4995
                                                }
 
4996
                                                count2 = count2 + 1;
 
4997
                                        }
 
4998
 
 
4999
                                        if(boolResult2) //If base found
 
5000
                                        {
 
5001
                                                temp = 12 * 128;        //Search radius
 
5002
 
 
5003
                                                result = numDroidsInArea(count, tempX - temp, tempY - temp, tempX + temp, tempY + temp);        //Count Ally's units
 
5004
 
 
5005
                                                //Count number of enemies in ally's base
 
5006
                                                //--------------------------------------
 
5007
                                                result2 = 0;
 
5008
                                                count2 = 0;
 
5009
                                                while(count2 < numEnemies)
 
5010
                                                {
 
5011
                                                        result2 = numDroidsInArea(Enemies[count2], tempX - temp, tempY - temp, tempX + temp, tempY + temp) + result2;   //Count enemy units
 
5012
                                                        count2 = count2 + 1;
 
5013
                                                }
 
5014
 
 
5015
                                                if(result2 > (result + 7))      //If many more enemy than ally units in ally's base
 
5016
                                                {
 
5017
                                                        showConsoleText(DebugMsg[12], player);          //Helping ally's base
 
5018
 
 
5019
                                                        //Collect attackers
 
5020
                                                        groupAddGroup(attackGroup, sendOutpostGr);
 
5021
                                                        groupAddGroup(attackGroup, repairedGroup);
 
5022
                                                        groupAddGroup(attackGroup, oilGr);
 
5023
                                                        //groupAddGroup(attackGroup, collectSendGr);
 
5024
 
 
5025
                                                        setGroupSecondary(attackGroup, DSO_REPAIR_LEVEL, DSS_REPLEV_NEVER);     //Don't return to the outpost for repair
 
5026
                                                        attackPhase = 1;                //Re-initialize attack later
 
5027
                                                        helpAllyPlayer = count;
 
5028
                                                }
 
5029
                                        }
 
5030
                                }
 
5031
                                count = count + 1;
 
5032
                        }
 
5033
                }
 
5034
        }
 
5035
        else if(helpAllyPlayer > (-1))  //Helping an ally already
 
5036
        {
 
5037
                if((helpAllyPlayerX > (-1)) and (helpAllyPlayerY > (-1)))       //Help coords exist
 
5038
                {
 
5039
                        //Check if threat is gone now
 
5040
                        //---------------------------
 
5041
                        result = numDroidsInArea(helpAllyPlayer, helpAllyPlayerX - temp, helpAllyPlayerY - temp, helpAllyPlayerX + temp, helpAllyPlayerY + temp);       //Count Ally's units
 
5042
 
 
5043
                        //Count number of enemies in ally's base
 
5044
                        //--------------------------------------
 
5045
                        result2 = 0;
 
5046
                        count2 = 0;
 
5047
                        while(count2 < numEnemies)
 
5048
                        {
 
5049
                                result2 = numDroidsInArea(Enemies[count2], helpAllyPlayerX - temp, helpAllyPlayerY - temp, helpAllyPlayerX + temp, helpAllyPlayerY + temp) + result2;   //Count enemy units
 
5050
                                count2 = count2 + 1;
 
5051
                        }
 
5052
 
 
5053
                        if((result > (result2 + 6)) or (result2 == 0))  //If ally has more units than enemy or no enemy units at all
 
5054
                        {
 
5055
                                showConsoleText(DebugMsg[13], player);          //Ally's base is safe. Returning.
 
5056
 
 
5057
                                helpAllyPlayer = -1;            //Cancel 'help AI base' state
 
5058
                                helpAllyPlayerX = -1;
 
5059
                                helpAllyPlayerY = -1;
 
5060
                        }
 
5061
 
 
5062
                }
 
5063
        }
 
5064
}
 
5065
 
 
5066
event PowerBoost(PowerBoostTr)
 
5067
{
 
5068
        //Customizable power cheat
 
5069
        temp = 25;
 
5070
        addPower(temp, player);         /*%!    ID="GKPowerBoost",
 
5071
                                        MainDesc="Power boost amount",
 
5072
                                        type="asn",             //Assign
 
5073
                                        val="0",
 
5074
                                        ArgDesc="No power boost (Default)",
 
5075
                                        val="25",               //5*5
 
5076
                                        ArgDesc="Small power boost",
 
5077
                                        val="60",               //12*5
 
5078
                                        ArgDesc="Medium power boost",
 
5079
                                        val="200",              //40*5
 
5080
                                        ArgDesc="Big power boost",
 
5081
                                        val="450",              //90*5
 
5082
                                        ArgDesc="Huge power boost"      */
 
5083
}
 
5084
 
 
5085
event deactivate(CALL_GAMEINIT)
 
5086
{
 
5087
        debugMode = FALSE;      /*%!    ID="GK_Debug",
 
5088
                                                MainDesc="Enable GK debug (observe) mode",
 
5089
                                                MoreInfo="<Help2>",
 
5090
                                                type="asn",             //Assign
 
5091
                                                tmpl="YesNo"    */
 
5092
 
 
5093
        if( (not debugMode) and ((player == selectedPlayer) or (not myResponsibility(player))) )
 
5094
        {
 
5095
                setEventTrigger(StartGame,inactive);
 
5096
                setEventTrigger(LegoBuild,inactive);
 
5097
                setEventTrigger(Rush,inactive);
 
5098
                setEventTrigger(chooseEnemy,inactive);
 
5099
                setEventTrigger(BuildAttackForce,inactive);
 
5100
                setEventTrigger(doResearch,inactive);
 
5101
                setEventTrigger(basedetails,inactive);
 
5102
                setEventTrigger(keepTrack,inactive);
 
5103
                setEventTrigger(droidDestroyed,inactive);
 
5104
                setEventTrigger(buildPowerGenerators,inactive);
 
5105
                setEventTrigger(LegoTrucks,inactive);
 
5106
                setEventTrigger(droidBuilt,inactive);
 
5107
                setEventTrigger(difficultyMod,inactive);
 
5108
                setEventTrigger(upgradeStructures,inactive);
 
5109
                setEventTrigger(moveIfAttacked,inactive);
 
5110
                setEventTrigger(stuck,inactive);
 
5111
                setEventTrigger(buildVtols,inactive);
 
5112
                setEventTrigger(vtolDefend,inactive);
 
5113
                setEventTrigger(vtolAttack,inactive);
 
5114
                setEventTrigger(formAllianceEvent,inactive);
 
5115
                setEventTrigger(formHumanAlliances,inactive);
 
5116
                setEventTrigger(updateDetails,inactive);
 
5117
                setEventTrigger(repairStuff,inactive);
 
5118
                setEventTrigger(FinishStructures,inactive);
 
5119
                setEventTrigger(buildCyborgs,inactive);
 
5120
                setEventTrigger(cyborgDrop,inactive);
 
5121
                setEventTrigger(manageDropAttacks,inactive);
 
5122
                setEventTrigger(WatchDefendBase,inactive);
 
5123
                setEventTrigger(WatchHelpAlly,inactive);
 
5124
                setEventTrigger(sendScouts,inactive);
 
5125
                setEventTrigger(agressiveDefence,inactive);
 
5126
                setEventTrigger(additVTOLDefenses,inactive);
 
5127
                setEventTrigger(PowerBoost,inactive);
 
5128
        }
 
5129
}