[Solved] Map Optimizer breaks map

Level 14
Joined
Jan 24, 2017
Messages
280
I am using Map Optimizer 5.0 to optimize my map.
I recently added a new Zinc Ability to my map and after optimizing the map does not let me host it anymore (closes in the lobby).
There are other Zinc ability in my map that work.

I do not know why that happens, any ideas or help is appreciated.
Thanks

The Ability is slightly changes as in the test map, but the same issues occurs on both.


JASS:
//! zinc

library Vacuum requires Missile, TimerUtils {


// The effect to be used by the missile
// ------------------------------------
constant string FX_PATH = "Abilities\\Weapons\\BansheeMissile\\BansheeMissile.mdl";

// How frequently to tick the timer for pulling
// --------------------------------------------
constant real INTERVAL = 0.03125;

// The radius for the vacuum pull
// ------------------------------
constant real VACUUM_RADIUS = 450;

// How far to pull each unit per tick
// ----------------------------------
constant real VACUUM_DISTANCE_PER_TICK = 25;

// How long the vacuum pull lasts
// ------------------------------
constant real VACUUM_DURATION = 0.3;

group enumGroup;


// The ability-code that triggers the spell
// ----------------------------------------
function Conditions() -> boolean {
    return GetSpellAbilityId() == 'A0LD';
}

struct FMData {
    unit caster;
    player casterPlayer;
    real targetX;
    real targetY;
    real vacuumDuration;

    method onDestroy() {
        caster = null;
    }
}

function IsPathable(real x, real y) -> boolean {
    return IsTerrainPathable(x, y, PATHING_TYPE_FLOATABILITY);
}

function MoveUnitIfPossible(unit u, real x, real y) {
    real prevX = GetUnitX(u);
    real prevY = GetUnitY(u);
    real newX;
    real newY;
    real dx;
    real dy;
    real distanceSq;

    if (!IsPathable(x, y)) {
        SetUnitX(u, x);
        SetUnitY(u, y);
    }
    newX = GetUnitX(u);
    newY = GetUnitY(u);
    dx = newX - x;
    dy = newY - y;
    distanceSq = dx*dx + dy*dy;

    if (distanceSq > (10*10)) {
        SetUnitX(u, prevX);
        SetUnitY(u, prevY);
    }
}

function IsUnitAlive(unit u) -> boolean {
    return GetUnitTypeId(u) != 0 && !IsUnitType(u, UNIT_TYPE_DEAD);
}

function VacuumFilter(unit enumUnit, player casterPlayer) -> boolean {
    return IsUnitEnemy(enumUnit, casterPlayer) &&
           IsUnitAlive(enumUnit) &&
           !IsUnitType(enumUnit, UNIT_TYPE_STRUCTURE) &&
           !IsUnitType(enumUnit, UNIT_TYPE_MAGIC_IMMUNE);
}

function VacuumUnit(unit enumUnit, real targetX, real targetY) {
    real ux = GetUnitX(enumUnit);
    real uy = GetUnitY(enumUnit);
    real dx = targetX - ux;
    real dy = targetY - uy;
    real angle = Atan2(dy, dx);
    real distance = SquareRoot(dx*dx + dy*dy);

    real newX;
    real newY;

    // Do not move the unit if they are already close enough to the target point
    if (distance < VACUUM_DISTANCE_PER_TICK) {
        return;
    }

    newX = ux + VACUUM_DISTANCE_PER_TICK * Cos(angle);
    newY = uy + VACUUM_DISTANCE_PER_TICK * Sin(angle);

    MoveUnitIfPossible(enumUnit, newX, newY);
}

function VacuumLoop() {
    unit enumUnit = null;
    timer t = GetExpiredTimer();
    FMData data = GetTimerData(t);

    data.vacuumDuration -= INTERVAL;

    // Enumerate units in range 
    GroupEnumUnitsInRange(enumGroup, data.targetX, data.targetY, VACUUM_RADIUS, null);
    enumUnit = FirstOfGroup(enumGroup);

    // Loop through the units, removing them as we go, until our group is empty
    while (enumUnit != null) {
        if (VacuumFilter(enumUnit, data.casterPlayer)) {
            VacuumUnit(enumUnit, data.targetX, data.targetY);
        }

        GroupRemoveUnit(enumGroup, enumUnit);
        enumUnit = FirstOfGroup(enumGroup);
    }

    // End the spell once the pull is over
    if (data.vacuumDuration <= 0) {
        data.destroy();
        ReleaseTimer(t);
    }
    
    t = null;
}

function Vacuum(FMData data) {
    timer t = NewTimer();
    SetTimerData(t, data);
    TimerStart(t, INTERVAL, true, function VacuumLoop); 
    t = null;
    
    CreateNUnitsAtLoc( 1, 'h00O', GetOwningPlayer(data.caster), Location(data.targetX, data.targetY), bj_UNIT_FACING );
    UnitAddAbilityBJ( 'A0LK', GetLastCreatedUnit() );
    IssueImmediateOrderBJ( GetLastCreatedUnit(), "thunderclap" );
    UnitApplyTimedLifeBJ( 1.00, 'BTLF', GetLastCreatedUnit() );
}

function Actions() {
    FMData data = FMData.create();
    Dummy dummy;

    data.caster = GetTriggerUnit();
    data.casterPlayer = GetTriggerPlayer();
    data.targetX = GetSpellTargetX();
    data.targetY = GetSpellTargetY();
    data.vacuumDuration = VACUUM_DURATION;

    dummy = DummyBuilder
        .create(GetUnitX(GetTriggerUnit()), GetUnitY(GetTriggerUnit()), FX_PATH)
        .scale(4)
        .height(10.0)
        .createDummy();

    Missile.create(dummy)
        .constantSpeed(1300.0)
        .targetPoint(GetSpellTargetX(), GetSpellTargetY())
        .requirePathability(PATHING_TYPE_FLYABILITY)
        .setData(data)
        .onFinish(Vacuum)
        .go();
}

function onInit() {
    trigger trg = CreateTrigger();
    TriggerRegisterAnyUnitEventBJ( trg, EVENT_PLAYER_UNIT_SPELL_EFFECT );
    TriggerAddCondition( trg, Condition( function Conditions ) );
    TriggerAddAction( trg, function Actions );

    enumGroup = CreateGroup();
}

}

//! endzinc
 

Attachments

  • Vacuum v2.w3m
    45.6 KB · Views: 5
Top