HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

System works one day, doesn't work the next...

03-01-2007, 02:38 AM#1
Pyrogasm
So I'm working on a custom movement system; however, this is irrelevant. What is relevant is that I saved the map in a working (albeit bugged) state, in which the aura circles and triggers all worked fine.

The next day (today), I came back to the map and decided I should test it first to recall what it was I should be working on. Map starts, and BAM! Nothing happens.

The code compiles fine, it worked before, and I did not change a single letter of the code. Luckily, I had uploaded a previous, working version of the map to the pastebin here, so I tried downloading that and working from there. Again, nothing is working! As far as I can tell, the trigger never even runs once.

Why might this be?

Here's the code:
Realistic Movement System Functions

Collapse JASS:
//----------------------------------------------------------
//Move System Functions
//
//
function Set_Appropriate_MS takes unit U, real D returns nothing
    local real S
    local real DS = GetUnitDefaultMoveSpeed(U)
    local integer UD = GetUnitUserData(U)
    local integer OUD = GetUnitUserData(U)
    local real P
    local real M
    local real S2
    local item Item
    local integer I = 0
    local integer array Buffs
    local integer array Abilities

    set Buffs[1] = 'B001'
    set Buffs[2] = 'B002'
    set Buffs[3] = 'B003'
    set Buffs[4] = 'B004'
    set Buffs[5] = 'B006'
    set Buffs[6] = 'B000'

    set Abilities[1] = 'A002'
    set Abilities[2] = 'A003'
    set Abilities[3] = 'A001'
    set Abilities[4] = 'A004'
    set Abilities[5] = 'A005'
    set Abilities[6] = 'A000'

    loop
        set I = I+1
        exitwhen I > 6
        set Item = UnitItemInSlot(U, I)
        call UnitAddItem(udg_Item_Dummy, Item)
    endloop

    if UD < 0 then
        set UD = UD*-1
        call SetUnitUserData(U, UD)
    endif
//    call BJDebugMsg(I2S(UD)+" and "+I2S(OUD))
    set P = UD*0.005
    set S = GetUnitMoveSpeed(U)
    set M = S/DS
    if D > 0.00 then
        if UD <= 100 then
            if M < 0.80 then
                set S2 = 35.00*(1.00-M)
            else
                set S2 = 7.00
            endif
            if M < 1.00 then
                    call SetUnitMoveSpeed(U, S+(S2*P))
            else
                if IsUnitType(U, UNIT_TYPE_MECHANICAL) == false then
                    set UD = UD+1
                    call SetUnitUserData(U, UD)
                endif
                call SetUnitMoveSpeed(U, DS)
            endif
        else
            if P < 1.00 then
                if OUD > 0 then
                    if M < 0.80 then
                        set S2 = 35.00*(1.00-M)
                    else
                        set S2 = 7.00
                    endif
                    if M < 1.00 then
                        call SetUnitMoveSpeed(U, S+(S2*P))
                    else
                        if IsUnitType(U, UNIT_TYPE_MECHANICAL) == false then
                            set UD = UD+1
                            call SetUnitUserData(U, UD)
                        endif
                    endif
                    call SetUnitMoveSpeed(U, DS)
                else
                    call SetUnitMoveSpeed(U, DS*(1.00-(P-0.50)))
                    set UD = (UD+1)*-1
                    call SetUnitUserData(U, UD)
                endif
            else
                call SetUnitMoveSpeed(U, 5.00)
                call IssueImmediateOrder(U, "stop")
            endif
        endif
    else
        call SetUnitMoveSpeed(U, 5.00)
        if UD > 0 then
            call SetUnitUserData(U, UD-1)
        endif
    endif
    set UD = GetUnitUserData(U)
    if UD < 0 then
        set UD = UD*-1
    endif

    set I = 0
    loop
        set I = I+1
        exitwhen I > 6
        set Item = UnitItemInSlot(udg_Item_Dummy, I)
        call UnitAddItem(U, Item)
    endloop

    set I = 0
    loop
        set I = I+1
        exitwhen I > 6
        if (UD > (I*40)-80 and UD <= (I*40)-40) and GetUnitAbilityLevel(U, Abilities[i]) == 0 then
            call UnitAddAbility(U, Abilities[i])
            call UnitRemoveAbility(U, Abilities[I-1])
            call UnitRemoveAbility(U, Abilities[I+1])
            call UnitRemoveAbility(U, Buffs[I-1])
            call UnitRemoveAbility(U, Buffs[I+1])            
        endif
    endloop
   
    set U = null
    set Item = null
endfunction

function Is_Unit_Moving takes nothing returns nothing
    local unit U = GetEnumUnit()
    local real X1 = GetUnitX(U)
    local real Y1 = GetUnitY(U)
    local real X2
    local real Y2
    local real D

    call TriggerSleepAction(0.00)
    set X2 = GetUnitX(U)
    set Y2 = GetUnitY(U)
    set D = SquareRoot((X2-X1)*(X2-X1)+(Y2-Y1)*(Y2-Y1))
    call Set_Appropriate_MS(U, D)

    set U = null
endfunction


function ForGroupUnitMoving takes nothing returns nothing
    call ExecuteFunc("Is_Unit_Moving")
endfunction

function Movement_System_Filter takes nothing returns boolean
    return (IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) and IsUnitType(GetFilterUnit(), UNIT_TYPE_POLYMORPHED)) == false
endfunction

function Main_Function_Moving takes nothing returns nothing
    local group G = GetUnitsInRectMatching(GetPlayableMapRect(), Condition(function Movement_System_Filter))
    call ForGroup(G, function ForGroupUnitMoving)
    call DestroyGroup(G)
    set G = null
endfunction



function RMS_Disable takes nothing returns nothing
    local player P = GetEnumPlayer()
    call SetPlayerAbilityAvailable(P, 'A002', false)
    call SetPlayerAbilityAvailable(P, 'A003', false)
    call SetPlayerAbilityAvailable(P, 'A001', false)
    set P = null
endfunction

function RMS_Init takes nothing returns nothing
    local real X = GetLocationX(GetRectCenter(GetPlayableMapRect()))
    local real Y = GetLocationY(GetRectCenter(GetPlayableMapRect()))
    local group G = GetUnitsInRectAll(GetPlayableMapRect())
    local unit U

    loop
        set U = FirstOfGroup(G)
        exitwhen U == null
        call UnitAddAbility(U, 'A002')
        call GroupRemoveUnit(G, U)
    endloop
    set udg_Item_Dummy = CreateUnit(Player(15), 'h000', X, Y, 0)

    call ForForce(GetPlayersAll(), function RMS_Disable)

    set U = null
endfunction

function RMS_Unit_Filter takes nothing returns boolean
    return GetUnitTypeId(GetFilterUnit()) != 'u000'
endfunction


function RMS_Ability_Add takes nothing returns nothing
    local unit U = GetTriggerUnit()
    call SetUnitMoveSpeed(U, 5.00)
    call SetUnitUserData(U, 0)
    call UnitAddAbility(U, 'A002')
    set U = null
endfunction

function RMS_Callback takes nothing returns nothing
    call Main_Function_Moving()
    call TriggerSleepAction( 0.00 )
    call SetTextTagTextBJ( udg_Knight_Value, ( "Fatigue: " + ( R2S(( I2R(GetUnitUserData(gg_unit_hkni_0002)) / 2.00 )) + "%" ) ), 10 )
    call SetTextTagTextBJ( udg_Knight_Speed, ( "Movement Speed: " + R2S(GetUnitMoveSpeed(gg_unit_hkni_0002)) ), 10 )
endfunction

//===========================================================================
function InitTrig_Realistic_Movement_System takes nothing returns nothing
    local trigger T = CreateTrigger(  )
    local region R = CreateRegion()

    call RegionAddRect(R, GetPlayableMapRect())
    call TriggerRegisterEnterRegion(T, R, Condition(function RMS_Unit_Filter))
    call TriggerAddAction(T, function RMS_Ability_Add)

    set T = CreateTrigger(  )
    call TriggerRegisterTimerEvent(T, 0.00, false)
    call TriggerAddAction(T, function RMS_Init)

    set gg_trg_Realistic_Movement_System = CreateTrigger(  )
    call TriggerRegisterTimerEvent(gg_trg_Realistic_Movement_System, 0.20, true)
    call TriggerAddAction(gg_trg_Realistic_Movement_System, function RMS_Callback)

    set T = null
endfunction


Old map download here

New map is attached.

EDIT: Forgot to explain what should be going on:
  • Units accellerate non-linearly until they reach their max speed; they accellerate by 25*(Current Speed/Default Speed) every 0.20 seconds
  • Units may run at max speed until they reach 50% fatigue, after which they loose speed proportional to their current fatigue level. Every 0.20 seconds, their Move Speed becomes equal to (Default Speed)*((Fatigue)*0.005).
  • After reaching 100% fatigue, the unit is ordered to stop. I was hoping to find away around this to get it to remember its current order, but no such luck.
  • Mechanical units accellerate like normal units, but do not loose speed over time. I was wondering if they should be forced to stop upon reaching 100% fatigue... maybe for gas?
  • While not moving for any reason, a unit's fatigue decreases by 0.5% every 0.20 seconds, and its move speed is set to 5.00.
  • If a unit accellerates while it has fatigue, it will accellerate at the rate of 25*((Current Speed/Default Speed)*((Fatigue)*0.005)) every 0.20 seconds
  • At all times, units have a "fatigue indicator" effect and buff on them to indicate their current fatigue level. The effect is a modified "generic aura target"
Attached Files
File type: w3xMovement System.w3x (31.0 KB)
03-01-2007, 03:02 AM#2
wantok
I opened the old map and the movement trigger was messed up. I went to copy and paste it in here to show you but it pasted fine, so I pasted it into JassCraft and then copied and pasted it back into the map and the trigger works fine for me.

See if the map below works for you.
Attached Images
File type: jpgtrig.jpg (59.4 KB)
Attached Files
File type: w3xMovement System1.w3x (29.3 KB)