• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Why do my nurse ants never spawn (look at code please)?

Status
Not open for further replies.
JASS:
fixed[2] SimAnt_workerSpawnChance;
fixed[2] SimAnt_soldierSpawnChance;
fixed[2] SimAnt_nurseSpawnChance;
// Check for ants around the ant mounds to teleport.
bool SimAnt_HatchAntEggs_Func (bool testConds, bool runActions) {
    int     i = 1;
    unit    u = UnitGroupUnit(SimAnt_antEggs, i);
    int     p;
    int     i2;
    fixed   life;
    fixed   percent;
    string  antType;
    int     player;
    
    while (u != null) {
        life = UnitGetPropertyFixed(u, c_unitPropLifePercent, true);
        if (life >= 100.0) {
            p = UnitGetOwner(u);
            UnitKill(u);
            if (p <= maxPlayers/2) {
                i2 = 0;
            } else {
                i2 = 1;
            }
            percent = RandomFixed(0.0, SimAnt_workerSpawnChance[i2] + SimAnt_soldierSpawnChance[i2] + SimAnt_nurseSpawnChance[i2]);
            percent += -SimAnt_workerSpawnChance[i2];
            if (percent <= 0.0) {
                antType = AntWorker;
                player  = i2*maxPlayers/2 + RandomInt(2, 3);
            } else {
                percent += -SimAnt_soldierSpawnChance[i2];
                if (percent <= 0.0) {
                    antType = AntSoldier;
                    player  = i2*maxPlayers/2 + RandomInt(4, 5);
                } else {
                    percent += -SimAnt_nurseSpawnChance[i2];
                    if (percent <= 0.0) {
                        antType = AntNurse;
                        player  = i2*maxPlayers/2 + 1;
                    }
                }
            }
            UnitCreate(1, antType, c_unitCreateIgnorePlacement, player, UnitGetPosition(u), RandomFixed(0.0, 360.0));
        }
        i += 1;
        u = UnitGroupUnit(SimAnt_antEggs, i);
    }
    
    return true;
}
//--------------------------------------------------------------------------------------------------
void SimAnt_HatchAntEggs_Init () {
    TimerStart(SimAnt_antEggsTimer, 1.0, true, c_timeReal);
    TriggerAddEventTimer(gt_HatchAntEggs, SimAnt_teleportTimer);
    SimAnt_workerSpawnChance[0]     = 60;
    SimAnt_workerSpawnChance[1]     = 60;
    SimAnt_soldierSpawnChance[0]    = 30;
    SimAnt_soldierSpawnChance[1]    = 30;
    SimAnt_nurseSpawnChance[0]      = 10;
    SimAnt_nurseSpawnChance[1]      = 10;
}
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
TimerStart(SimAnt_antEggsTimer, 1.0, true, c_timeReal);
TriggerAddEventTimer(gt_HatchAntEggs, SimAnt_teleportTimer);
Nowhere do I see where you initialize either SimAnt_antEggsTimer or gt_HatchAntEggs. Remember that you need to create a Timer object and the Trigger object as passing null will not do much.

Does SimAnt_antEggs even contain a group with units in it? Maybe the first unit of the group is 0 and not 1 so you are always trying for the second unit. You also seem to never remove the egg from the group before killing it.
 
Depends on how they did the garbage collector. Does it null all references when destroyed or does it just make it evaluate to null. I do not think it would remove a removed unit from groups.

I was just under the impression that if something is no longer capable of being used (I.E a unit group or unit no longer connected to any future triggers and is gone) that it would remove all traces of said unit from the game, preventing leaks.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
It cannot do so without using a dynamic data structure to point at all references so it can null them on destruction. It is much more likely that a handle like system similar to WC3 is used where only if all references are lost does it allow the handle to get recycled.
 
Status
Not open for further replies.
Top