Author Topic: Destroying Units As An Objective  (Read 774 times)

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3205
Destroying Units As An Objective
« on: February 04, 2010, 01:50:27 PM »
I want an objective to be "destroy all waves of incoming enemy units" but sadly OP2 has no "EnemyGroupDestroyed" trigger.

Any suggestions?

Edit 3: I'm going to try using a Set Trigger to combine a Time Trigger with a Vehicle Count Trigger.  I'll let you know if it works.

Edit: Unrelated to the above problem, but part of the same project.

Code: [Select]
    Unit Unit1;
    for (short s = 23; s < 39; s++)
    {
        TethysGame::CreateUnit(Unit1, mapScorpion, LOCATION(s+31, 1-1), 1, mapEnergyCannon, 2);
            Unit1.DoSetLights(1);
            SD.Wave4.TakeUnit(Unit1);
    }

    SD.Wave4.SetAttackType(mapCommandCenter);
    SD.Wave4.DoAttackEnemy();

Any idea why that only spawns 2 Scorpions (or sometimes none at all)?  I have nearly identical code that works, which makes it even more confusing...

Edit 2: Problem solved due to Arklon.  Apparently, OP2 deletes units if you try to put them in a full attack group...
« Last Edit: February 06, 2010, 03:23:40 PM by Sirbomber »
"As usual, colonist opinion is split between those who think the plague is a good idea, and those who are dying from it." - Outpost Evening Star

Outpost 2 Coding 101 Tutorials

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4763
Destroying Units As An Objective
« Reply #1 on: February 07, 2010, 05:33:53 PM »
I wonder if SetDeleteWhenEmpty would be of any use? Maybe you can check if a group gets destroyed, which should happen when all the units in it are killed. I believe in certain cases with the Unit variable, the internal ID is cleared to 0 if the unit is no longer valid. Perhaps there is similar behavior with groups. Maybe check the stubIndex periodically, and see if it changes when all units in the group are destroyed.