Skip to content

Commit

Permalink
Prevent scavenger AI from producing trikes over limits.
Browse files Browse the repository at this point in the history
Make it use firetruck body.
Make it use DORDER_SCOUT for attack, instead of DORDER_MOVE.
Remove useless conversion to world coordinates (3.1 only)
  • Loading branch information
haoNoQ committed Feb 11, 2013
1 parent 0633524 commit 6736d68
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions data/mp/multiplay/script/scavfact.js
Expand Up @@ -7,13 +7,20 @@ const maxDroids = 25; // max guys to handle.
var attackGroup;
var lastAttack = 0;

function activateProduction(fac)
{
// Remind factory to produce
if (structureIdle(fac))
function produceDroid(fac1) {
if (fac1 && structureIdle(fac1) && groupSize(attackGroup) < maxDroids)
{
buildDroid(fac, "Trike", "B4body-sml-trike01", "BaBaProp", "", DROID_WEAPON, "bTrikeMG");
}
// We now have switch statements! And we can use the built-in Math library
switch (Math.floor(Math.random() * 10))
{
case 0: buildDroid(fac1, "Trike", "B4body-sml-trike01", "BaBaProp", "", DROID_WEAPON, "bTrikeMG"); break;
case 1: buildDroid(fac1, "Buggy", "B3body-sml-buggy01", "BaBaProp", "", DROID_WEAPON, "BuggyMG"); break;
case 2: buildDroid(fac1, "Jeep", "B2JeepBody", "BaBaProp", "", DROID_WEAPON, "BJeepMG"); break;
case 3: buildDroid(fac1, "Cannonbus", "BusBody", "BaBaProp", "", DROID_WEAPON, "BusCannon"); break;
case 4: buildDroid(fac1, "Firebus", "FireBody", "BaBaProp", "", DROID_WEAPON, "BabaFlame"); break;
default: buildDroid(fac1, "Bloke", "B1BaBaPerson01", "BaBaLegs", "", DROID_PERSON, "BaBaMG"); break;
}
}
}

// Regularly check back on our scavs
Expand All @@ -25,7 +32,7 @@ function scavtick()
// one way of dealing with lists is running a function on each member of the list
if (factorylist)
{
factorylist.forEach(activateProduction);
factorylist.forEach(produceDroid);
}

if ((gameTime - lastAttack) > 9000)
Expand Down Expand Up @@ -75,6 +82,7 @@ function eventGameInit()
makeComponentAvailable("B3body-sml-buggy01", me);
makeComponentAvailable("B2JeepBody", me);
makeComponentAvailable("BusBody", me);
makeComponentAvailable("FireBody", me);
makeComponentAvailable("B1BaBaPerson01", me);
makeComponentAvailable("BaBaProp", me);
makeComponentAvailable("BaBaLegs", me);
Expand All @@ -85,7 +93,7 @@ function eventGameInit()
makeComponentAvailable("BabaFlame", me);
makeComponentAvailable("BaBaMG", me);
attackGroup = newGroup(); // allocate a new group
groupAddArea(attackGroup, 0, 0, (mapWidth * 128), (mapHeight * 128));

This comment has been minimized.

Copy link
@originalfoo

originalfoo Feb 11, 2013

I assume the world coords issue is fixed in 3.1.1? Did it occur anywhere else? (for updating docs wiki)

This comment has been minimized.

Copy link
@haoNoQ

haoNoQ Feb 12, 2013

Author Member

I'm not seeing any differences in the usage of world_coord or map_coord anywhere near these functions in 3.1 and master.

groupAddArea(attackGroup, 0, 0, mapWidth, mapHeight);
}

function eventStartLevel()
Expand All @@ -100,19 +108,7 @@ function eventDroidBuilt(droid, fac1)
groupAddDroid(attackGroup, droid);

// Build another
if (fac1 && structureIdle(fac1) && groupSize(attackGroup) < maxDroids)
{
// We now have switch statements! And we can use the built-in Math library
switch (Math.floor(Math.random() * 10))
{
case 0: buildDroid(fac1, "Trike", "B4body-sml-trike01", "BaBaProp", "", DROID_WEAPON, "bTrikeMG"); break;
case 1: buildDroid(fac1, "Buggy", "B3body-sml-buggy01", "BaBaProp", "", DROID_WEAPON, "BuggyMG"); break;
case 2: buildDroid(fac1, "Jeep", "B2JeepBody", "BaBaProp", "", DROID_WEAPON, "BJeepMG"); break;
case 3: buildDroid(fac1, "Cannonbus", "BusBody", "BaBaProp", "", DROID_WEAPON, "BusCannon"); break;
case 4: buildDroid(fac1, "Firebus", "BusBody", "BaBaProp", "", DROID_WEAPON, "BabaFlame"); break;
default: buildDroid(fac1, "Bloke", "B1BaBaPerson01", "BaBaLegs", "", DROID_PERSON, "BaBaMG"); break;
}
}
produceDroid(fac1);
}

// watch for structures being attacked. Send the cavalry as required.
Expand All @@ -125,9 +121,9 @@ function eventAttacked(victim, attacker)
for (var i = 0; i < droidlist.length; i++)
{
var droid = droidlist[i];
if (distBetweenTwoPoints(victim.x, victim.y, attacker.x, attacker.y) < (24 * 128))
if (distBetweenTwoPoints(victim.x, victim.y, attacker.x, attacker.y) < 24)
{
orderDroidLoc(droid, DORDER_MOVE, attacker.x, attacker.y);
orderDroidLoc(droid, DORDER_SCOUT, attacker.x, attacker.y);
}
}
}
Expand Down

0 comments on commit 6736d68

Please sign in to comment.