HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Movement System Function(s)

02-04-2007, 08:46 AM#1
Pyrogasm
I'm working on a Movent system in which units start at slow movespeed and increase gradually to their max movement speed. After reaching their top speed, units gain fatigue constantly until their fatigue reaches 100%. While stopped for any reason, units' fatigue wears off.

If a unit stops moving and then resumes moving while below 50% fatigue, it will move without gaining fatigue until it reachs max speed. If a unit stops and then resumes moving while above 50% fatigue, it will continue to gain fatigue. If a unit's fatigue reaches 100%, the unit will be paused until it's fatigue reaches 0%.

The functions are written by me (mostly) with some help from zeroXD, Moyack (the last two functions were entirely Moyack's design), and Rising_Dusk; however, I am hoping to get some feedback as to what doesn't seem right/what could be improved. The system is not complete, but it is fully functional as is. I've attached a map to test it out.
Collapse JASS:
function Is_Unit_Moving takes nothing returns nothing
    local unit Moving_Unit = GetEnumUnit()
    local real Moving_Point_X = GetUnitX( Moving_Unit )
    local real Moving_Point_Y = GetUnitY( Moving_Unit )
    local real Moving_Point_X2
    local real Moving_Point_Y2
    local real Moving_Distance
//    local real array Moving_Facing          I was thinking of using Unit facing to get around the random stop bug
//    set Moving_Facing[1] = GetUnitFacing( Moving_Unit )
    call TriggerSleepAction( 0.00 )
    set Moving_Point_X2 = GetUnitX( Moving_Unit )
    set Moving_Point_Y2 = GetUnitY( Moving_Unit )
//    set Moving_Facing[2] = GetUnitFacing( Moving_Unit )
    set Moving_Distance = SquareRoot( (Moving_Point_X2-Moving_Point_X)*(Moving_Point_X2-Moving_Point_X)+(Moving_Point_Y2-Moving_Point_Y)*(Moving_Point_Y2-Moving_Point_Y) )
//    if Moving_Distance > 0 or Moving_Facing[1]-Moving_Facing[2] != 0 then
    if Moving_Distance > 0 then
        call SetUnitMoveSpeed( Moving_Unit, (GetUnitMoveSpeed(Moving_Unit)+5.00) )
        if GetUnitMoveSpeed( Moving_Unit ) >= GetUnitDefaultMoveSpeed( Moving_Unit ) then
            call GroupAddUnit( udg_Fatigue_Group, Moving_Unit )
            call SetUnitMoveSpeed( Moving_Unit, GetUnitDefaultMoveSpeed(Moving_Unit) ) //In case it goes over it's default movespeed
        else
        endif
        if IsUnitInGroup( Moving_Unit, udg_Fatigue_Group ) == true then
            call SetUnitUserData( Moving_Unit, (GetUnitUserData(Moving_Unit)+1) )
        else
        endif
        if GetUnitUserData(Moving_Unit) >= 200 then
            call PauseUnit( Moving_Unit, true )
            call DisplayTextToPlayer( GetOwningPlayer(Moving_Unit), 0.00, 0.00, "Your unit is too fatigued to run any more. Wait a bit while he or she rests." )
            call GroupAddUnit( udg_Pause_Group, Moving_Unit )
            //Add some more slowing functions here
        else
        endif
//        call GroupAddUnit( udg_Move_Group, Moving_Unit )
//        call GroupRemoveUnit( udg_Stop_Group, Moving_Unit )
    else
        call SetUnitMoveSpeed( Moving_Unit, 5 )
        if GetUnitUserData(Moving_Unit) > 0 then
            call SetUnitUserData( Moving_Unit, (GetUnitUserData(Moving_Unit)-1) )
        else
        endif
        if GetUnitUserData(Moving_Unit) <= 100 and IsUnitInGroup(Moving_Unit, udg_Fatigue_Group) == true then
            call GroupRemoveUnit( udg_Fatigue_Group, Moving_Unit )
        else
        endif
        if IsUnitInGroup( Moving_Unit, udg_Pause_Group ) == true and GetUnitUserData( Moving_Unit ) == 0 then
            call PauseUnit( Moving_Unit, false )
        else
        endif
//        call GroupRemoveUnit( udg_Move_Group, Moving_Unit )
//        call GroupAddUnit( udg_Stop_Group, Moving_Unit )
    endif
    set Moving_Unit = null
endfunction
Collapse Moyack's Functions:
function ForGroupUnitMoving takes nothing returns nothing
    call ExecuteFunc("Is_Unit_Moving")
endfunction

function Main_Function_Moving takes nothing returns nothing
    local group Moving_Units = GetUnitsInRectAll( GetWorldBounds() )
    call ForGroup( Moving_Units, function ForGroupUnitMoving )
    call DestroyGroup( Moving_Units )
    set Moving_Units = null
endfunction
Trigger:
Main Trigger
Collapse Events
Time - Every 0.20 seconds of game time
Conditions
Collapse Actions
Custom script: call GroupClear( udg_Move_Group )
Custom script: call GroupClear( udg_Stop_Group )
Custom script: call Main_Function_Moving()
Wait 0.00 seconds
Floating Text - Change text of Knight_Value to (Fatigue: + ((String(((Real((Custom value of Knight 0002 <gen>))) / 2.00))) + %)) using font size 10.00
Floating Text - Change text of Knight_Speed to (Movement Speed: + (String((Current movement speed of Knight 0002 <gen>)))) using font size 10.00
Trigger:
Initilization MS Set
Collapse Events
Map initialization
Conditions
Collapse Actions
Set All_Units = (Units in (Entire map))
Unit Group - Pick every unit in All_Units and do (Unit - Set (Picked unit) movement speed to 5.00)
Custom script: call DestroyGroup( udg_All_Units )
Floating Text - Create floating text that reads (Fatigue: + ((String((Custom value of Knight 0002 <gen>))) + %)) above Knight 0002 <gen> with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
Set Knight_Value = (Last created floating text)
Floating Text - Create floating text that reads (Movement Speed: + (String((Current movement speed of Knight 0002 <gen>)))) above Knight 0002 <gen> with Z offset 50.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
Set Knight_Speed = (Last created floating text)
Trigger:
Entering MS Set
Collapse Events
Unit - A unit enters (Entire map)
Conditions
Collapse Actions
Unit - Set (Triggering unit) movement speed to 5.00
Attached Files
File type: w3xMovement System.w3x (22.7 KB)
02-04-2007, 09:37 PM#2
Pyrogasm
Bump.

So... no ideas? No criticism or suggestions?