Skip to content

Commit

Permalink
Backport fix for derrick building from master so that trucks will not…
Browse files Browse the repository at this point in the history
… be paralyzed

if the closest oil is inaccessible. This should fix ticket:2876
  • Loading branch information
perim committed Sep 4, 2011
1 parent 2e13cb5 commit 0754218
Show file tree
Hide file tree
Showing 9 changed files with 564 additions and 536 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
@@ -1,3 +1,7 @@
2011-00-00: Version 2.3.9
* Multiplayer:
* Change: Make AI nastier (commit:2e13cb5420fa65554535f9c9dea7026fa992b21c)

2011-05-17: Version 2.3.8
* General:
* New: Two new 2 player maps - Vision and Roughness (commit:697afb16d5244f9715952f8762b1011c6d75101e, commit:ebfc46b679a1f74df0e63313e4d3e05db55a23ad)
Expand Down
137 changes: 70 additions & 67 deletions data/base/multiplay/skirmish/player0.slo
Expand Up @@ -224,6 +224,7 @@ trigger everySec (every, 10);
trigger manageDefendLocationTr (every, 70);
trigger startLevelTr (CALL_START_NEXT_LEVEL);
trigger chainloadTr (wait, 1);
trigger slowloadTr (wait, 13);

/* Events */
event conDroids;
Expand All @@ -236,6 +237,7 @@ event manageDefendLocationEv;
event structureDestroyed;
event rebuildStructureEv;
event doResearch;
event buildDerrick;

/* Function prototypes */
function bool haveBeacon(int _player);
Expand Down Expand Up @@ -265,7 +267,6 @@ function void factoryBuildDroid(STRUCTURE _factory);
function void cybFactorBuildCyborg(STRUCTURE _factory);
function void vtolFactoryBuildVtol(STRUCTURE _factory);
function bool insideBase(int _x, int _y);
function FEATURE closestOil(int _x, int _y, bool _bAvoidThreat);
function int numAlliesInBase(bool _bVtols);
function int numEnemiesInBase(bool _bVtols);
function bool defendingOwnBase();
Expand Down Expand Up @@ -436,6 +437,7 @@ event startLevel(startLevelTr)
setEventTrigger(buildFundamentals, chainloadTr);
setEventTrigger(conDroids, chainloadTr);
setEventTrigger(doResearch, chainloadTr);
setEventTrigger(buildDerrick, slowloadTr);
setEventTrigger(startLevel, inactive);
}

Expand Down Expand Up @@ -553,41 +555,72 @@ event basedetails(basedetailsTr)
// build derricks on oil.
event buildDerrick(buildDerrickTr)
{
feature = closestOil(baseX, baseY, true); // find unoccupied oil resource.
if(feature != NULLOBJECT)
{
buildX = feature.x;
buildY = feature.y;
local bool foundOne, _same;
local FEATURE _oil, _closestOil;
local int _bestDist, _newDist;
local DROID _search;

// if no more than 2 units already trying to build
initIterateGroup(buildGroup); // find all units in build group.
droid = iterateGroup(buildGroup);
count = 0;
while(droid != NULLOBJECT)
_bestDist = 99999;
_closestOil = NULLOBJECT;
foundOne = false;
initIterateGroup(buildGroup); // find all units in build group
droid = iterateGroup(buildGroup);
while (droid != NULLOBJECT && !foundOne)
{
if (droid.order != DORDER_BUILD and droid.order != DORDER_LINEBUILD and droid.order != DORDER_HELPBUILD)
{
if((droid.orderx == buildX) and (droid.ordery == buildY))
{
count = count + 1;
}
droid = iterateGroup(buildGroup);
foundOne = true;
}

if(count < 3)
else
{
initIterateGroup(buildGroup); // find all units in build group.
droid = iterateGroup(buildGroup);
boolResult = FALSE; // only send 1 droid to each derrick
while( (boolResult == FALSE) and (droid != NULLOBJECT) )
}
}
if (droid != NULLOBJECT)
{
initGetFeature(oilRes, -1, me);
_oil = getFeatureB(me);
while (_oil != NULLOBJECT)
{
_newDist = distBetweenTwoPoints(droid.x, droid.y, _oil.x, _oil.y);
_same = false;

if (_newDist < _bestDist and droidCanReach(droid, _oil.x, _oil.y)) // this one is closer
{
if ((droid.order == DORDER_NONE or droid.order == DORDER_RTB) and droidCanReach(droid, buildX, buildY))
if (!threatInRange(me, _oil.x, _oil.y, OIL_THREAT_RANGE, FALSE))
{
orderDroidStatsLoc(droid, DORDER_BUILD,derrick, buildX,buildY); //build a derick
boolResult = TRUE;
initIterateGroup(buildGroup); // find all units in build group.
_search = iterateGroup(buildGroup);
foundOne = false;
while (_search != NULLOBJECT && !foundOne)
{
if (_search.orderx == _oil.x and _search.ordery == _oil.y and _search != droid)
{
_same = true;
foundOne = true;
}
_search = iterateGroup(buildGroup);
}
if (!_same) // do not go to same spot as another droid
{
_bestDist = _newDist;
_closestOil = _oil;
}
}
droid = iterateGroup(buildGroup);
}
_oil = getFeatureB(me);
}
if (_closestOil != NULLOBJECT)
{
orderDroidStatsLoc(droid, DORDER_BUILD, derrick, _closestOil.x, _closestOil.y); // build a derick
if (idleGroup(buildGroup) > 0)
{
setEventTrigger(buildDerrick, slowloadTr); // do it again for next droid
exit;
}
}
}
setEventTrigger(buildDerrick, buildDerrickTr);
}

/////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1365,28 +1398,26 @@ event structBuilt(structBuiltTr)
/* vtol factory or vtol factory module */
else if(structure.stattype == REF_VTOL_FACTORY)
{
if( isStructureAvailable(facModule,me) and (skGetFactoryCapacity(structure) < 2 ))
if (isStructureAvailable(facModule,me) and (skGetFactoryCapacity(structure) < 2 ))
{
orderDroidStatsLoc(droid, DORDER_BUILD,facModule, structure.x,structure.y); // upgrade it.
}
}
else if(structure.stattype == REF_RESOURCE_EXTRACTOR)
else if (structure.stattype == REF_RESOURCE_EXTRACTOR)
{
/* get next oil resource nearby */
_oilResource = closestOil(structure.x, structure.y, TRUE);

if(_oilResource != NULLOBJECT)
{
if(distBetweenTwoPoints(_oilResource.x, _oilResource.y, structure.x, structure.y) < MORE_OIL_RANGE) //not too far away
{
dbg("structBuilt: more oil", me);
orderDroidStatsLoc(droid, DORDER_BUILD, derrick, _oilResource.x, _oilResource.y); //build a derick
}
}
setEventTrigger(buildDerrick, chainloadTr);
exit;
}
else if (structure.stattype == REF_RESEARCH)
{
setEventTrigger(doResearch, chainloadTr);
if (isStructureAvailable(resModule, me))
{
orderDroidStatsLoc(droid, DORDER_BUILD, resModule, structure.x, structure.y); // upgrade it.
}
else
{
setEventTrigger(doResearch, chainloadTr);
}
}

// Check if available trucks need to build more absolute necessities right away. We need a trigger here because
Expand Down Expand Up @@ -3817,34 +3848,6 @@ function bool insideBase(int _x, int _y)
return TRUE;
}

function FEATURE closestOil(int _x, int _y, bool _bAvoidThreat)
{
local FEATURE _oil,_closestOil;
local int _bestDist,_newDist;

_bestDist = 99999;
_closestOil = NULLOBJECT;

initGetFeature(oilRes, -1, me);
_oil = getFeatureB(me);
while(_oil != NULLOBJECT)
{
_newDist = distBetweenTwoPoints(_x, _y, _oil.x, _oil.y);

if(_newDist < _bestDist) //this one is closer
{
if( !(_bAvoidThreat && threatInRange(me, _oil.x, _oil.y, OIL_THREAT_RANGE, FALSE)) )
{
_bestDist = _newDist;
_closestOil = _oil;
}
}
_oil = getFeatureB(me);
}

return _closestOil;
}

event keyPressed(CALL_KEY_PRESSED, ref count, ref count2)
{
if(count == KEY_P and (count2 == KEY_RCTRL or count2 == KEY_LCTRL))
Expand Down

0 comments on commit 0754218

Please sign in to comment.