semperfi: Make sure we build a factory first, even if we need power generators. Always help build the closest structure.

Grab trucks from wider distance to accomodate maps that place starting trucks far away from base.
master
Per Inge Mathisen 2010-12-05 15:56:26 +01:00
parent d9861ff326
commit 6d12963fc5
1 changed files with 43 additions and 24 deletions

View File

@ -746,13 +746,14 @@ event buildFundamentals(inactive)
{ {
local FEATURE _oil; local FEATURE _oil;
local bool needPwGen; local bool needPwGen;
local STRUCTURE iterstruct, closeststruct;
local int closest, proximity;
needPwGen = false; needPwGen = false;
count = 0;
setEventTrigger(buildFundamentals, inactive); setEventTrigger(buildFundamentals, inactive);
// Do we need power generators? // Do we need power generators?
if (numUnusedDerricks() > 0) if ((playerPower(me) < HIGH_POWER * 2 or numFactories() > 1) and numUnusedDerricks() > 0)
{ {
needPwGen = true; needPwGen = true;
dbgPlr("More power generators needed"); dbgPlr("More power generators needed");
@ -773,25 +774,42 @@ event buildFundamentals(inactive)
} }
// Help build unfinished buildings // Help build unfinished buildings
// TODO: Aid closest building initIterateGroup(buildGroup); // find idle droids in build group.
initEnumUnbuilt(me); droid = iterateGroup(buildGroup);
structure = enumUnbuilt(); while (droid != NULLOBJECT)
while (structure != NULLOBJECT) {
{ initEnumUnbuilt(me);
initIterateGroup(buildGroup); // find idle droids in build group. iterstruct = enumUnbuilt();
droid = iterateGroup(buildGroup); closeststruct = NULLOBJECT;
while (droid != NULLOBJECT) closest = 99999;
while (iterstruct != NULLOBJECT)
{ {
if (conCanHelp(droid, structure.x, structure.y) proximity = distBetweenTwoPoints(droid.x, droid.y, iterstruct.x, iterstruct.y);
and distBetweenTwoPoints(droid.x, droid.y, structure.x, structure.y) < 20 * TILE if (conCanHelp(droid, iterstruct.x, iterstruct.y)
and (!needPwGen or structure.stattype == REF_POWER_GEN or structure.stattype == REF_POWER_MODULE)) and (!needPwGen or iterstruct.stattype == REF_POWER_GEN or iterstruct.stattype == REF_POWER_MODULE)
and (proximity < 50 * TILE)
and (proximity < closest))
{ {
orderDroidObj(droid, DORDER_HELPBUILD, structure); closeststruct = iterstruct;
dbgObj(droid, "Aid construction at (" & structure.x & ", " & structure.y & ")"); closest = proximity;
} }
droid = iterateGroup(buildGroup); iterstruct = enumUnbuilt();
} }
structure = enumUnbuilt(); if (closeststruct != NULLOBJECT)
{
orderDroidObj(droid, DORDER_HELPBUILD, closeststruct);
dbgObj(droid, "Aid construction at (" & closeststruct.x & ", " & closeststruct.y & ")");
if (closeststruct.stattype == REF_POWER_GEN || closeststruct.stattype == REF_POWER_MODULE)
{
needPwGen = false; // in progress
}
}
droid = iterateGroup(buildGroup);
}
if (idleGroup(buildGroup) == 0)
{
exit;
} }
if (needPwGen) if (needPwGen)
@ -801,8 +819,9 @@ event buildFundamentals(inactive)
} }
// If we have power, build up base basics // If we have power, build up base basics
if (playerPower(me) >= LOW_POWER and idleGroup(buildGroup) > 0) if (playerPower(me) >= LOW_POWER)
{ {
count = 0;
while (count < numFundamental) while (count < numFundamental)
{ {
// check that struct. // check that struct.
@ -811,7 +830,7 @@ event buildFundamentals(inactive)
{ {
if (isStructureAvailable(structs[count], me)) if (isStructureAvailable(structs[count], me))
{ {
if (grabTrucksAndBuild(15, structs[count], 0)) if (grabTrucksAndBuild(100, structs[count], 0))
{ {
exit; exit;
} }
@ -1476,7 +1495,7 @@ event buildPowerGenerators(inactive)
{ {
if (isStructureAvailable(powGen, me)) if (isStructureAvailable(powGen, me))
{ {
if (not grabTrucksAndBuild(8, powGen, 1)) if (not grabTrucksAndBuild(20, powGen, 1))
{ {
dbgPlr("Needed power generator but could not build one"); dbgPlr("Needed power generator but could not build one");
} }
@ -1511,7 +1530,7 @@ event buildExpand(inactive)
buildY = baseY; buildY = baseY;
if (isStructureAvailable(cybFactory, me) and (cybfacs < factories)) if (isStructureAvailable(cybFactory, me) and (cybfacs < factories))
{ {
if (grabTrucksAndBuild(8, cybFactory, 0)) if (grabTrucksAndBuild(10, cybFactory, 0))
{ {
dbgPlr("Building more cyborg factories"); dbgPlr("Building more cyborg factories");
} }
@ -1519,7 +1538,7 @@ event buildExpand(inactive)
} }
if (isStructureAvailable(resLab, me) and (reslabs < factories)) if (isStructureAvailable(resLab, me) and (reslabs < factories))
{ {
if (grabTrucksAndBuild(8, resLab, 0)) if (grabTrucksAndBuild(10, resLab, 0))
{ {
dbgPlr("Building more research labs"); dbgPlr("Building more research labs");
} }
@ -1527,7 +1546,7 @@ event buildExpand(inactive)
} }
if (isStructureAvailable(vtolFactory, me) and (vtolfacs < factories)) if (isStructureAvailable(vtolFactory, me) and (vtolfacs < factories))
{ {
if (grabTrucksAndBuild(8, vtolFactory, 0)) if (grabTrucksAndBuild(10, vtolFactory, 0))
{ {
dbgPlr("Building more VTOL factories"); dbgPlr("Building more VTOL factories");
} }
@ -1535,7 +1554,7 @@ event buildExpand(inactive)
} }
if (isStructureAvailable(factory, me) and (factories < vtolfacs + cybfacs + reslabs + 1)) if (isStructureAvailable(factory, me) and (factories < vtolfacs + cybfacs + reslabs + 1))
{ {
if (grabTrucksAndBuild(12, factory, 0)) if (grabTrucksAndBuild(25, factory, 0))
{ {
dbgPlr("Building more factories"); dbgPlr("Building more factories");
} }