Name | Type | is_array | initial_value |
AstartInt | integer | No | 0 |
Bonus | group | No | |
DotLoc | location | Yes | |
DotSet | group | No | |
DotUnit | unit | No | |
DummyCaster | unit | No | |
FreeLife | real | No | |
FX | effect | Yes | |
GameOver | dialog | No | |
HighLevel | integer | No | |
HighScore | multiboard | No | |
HighScoreInt | integer | No | |
InvBool | boolean | No | |
Invulnarable | boolean | Yes | |
Item | itemcode | Yes | |
Level | integer | No | |
MinInt | integer | No | 0 |
Pac_Group | group | No | |
PacMan | unit | Yes | |
Player_Colors | string | Yes | |
Point_Int | integer | No | |
PowBool | boolean | No | |
Power | boolean | Yes | |
PowerLoc | location | Yes | |
PowerSet | group | No | |
PowerUnit | unit | No | |
Spawn | location | No | |
StartLoc | location | No | |
TempLoc | location | No | |
TempTxt | texttag | Yes | |
UDex | integer | No | |
UDexGen | integer | No | |
UDexNext | integer | Yes | |
UDexPrev | integer | Yes | |
UDexRecycle | integer | No | |
UDexUnits | unit | Yes | |
UDexWasted | integer | No | |
UnitIndexerEnabled | boolean | No | |
UnitIndexEvent | real | No | |
UnitSpeedX | real | Yes | |
UnitType | unitcode | Yes | |
UnitValue | integer | Yes |
//TESH.scrollpos=0
//TESH.alwaysfold=0
library ArrowKeyMovement initializer moveinit
/*
***************** Pacman - ArrowKeyMovement by IcemanBo*******************
** **
** AddSpeed(playernumber, bonusspeed, duration) **
** If duration = 0 --> permanent change **
** **
**************************************************************************
*/
globals
/******************************** EDITABLE *************************************/
private constant real MOVEMENTSPEED = 20 // x32, to get normal movement speed
/******************************** FINISHED *************************************/
private constant integer CLIFF_TOLERANCE = 12
private constant integer CLIFF_LEVEL = 2
integer array runAnimationIndex
integer array moveIndex
private real array x_offset
private real array y_offset
real array offsetBonus
unit array pacman
boolean array moveBool
private timer timerMove = CreateTimer()
private constant real MOVE_TIMEOUT = .03125
private integer array timerCount
private timer array playerTimer
private constant integer MAXTIMER = 20
private hashtable hash = InitHashtable()
endglobals
function ResetSpeed takes integer i returns nothing
local integer j = MAXTIMER*i + 1
local integer k = MAXTIMER*i + timerCount[i]
set offsetBonus[i] = 0
loop
exitwhen j > k
call DestroyTimer(playerTimer[j])
set playerTimer[i] = null
set j = j + 1
endloop
endfunction
private function RemoveSpeed takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
local integer i = LoadInteger(hash, id, 0)
set timerCount[i] = timerCount[i] - 1
set offsetBonus[i] = offsetBonus[i] - LoadReal(hash, id, 0)
call DestroyTimer(t)
set t = null
endfunction
function AddSpeed takes integer i, real bonus, real timeout returns nothing
local timer t = CreateTimer()
local integer id = GetHandleId(t)
set timerCount[i] = timerCount[i] + 1
set playerTimer[MAXTIMER*i + timerCount[i]] = t
set offsetBonus[i] = offsetBonus[i] + bonus
if timeout != 0 then
call TimerStart(t, timeout, false, function RemoveSpeed)
call SaveInteger(hash, id, 0, i)
call SaveReal(hash, id, 0, bonus)
endif
set t = null
endfunction
private function PathCheck takes integer j, real x, real y returns boolean
return GetTerrainCliffLevel(x+CLIFF_TOLERANCE*x_offset[j],y+CLIFF_TOLERANCE*y_offset[j]) == CLIFF_LEVEL and GetTerrainCliffLevel(x+CLIFF_TOLERANCE*x_offset[j]*.25,y+CLIFF_TOLERANCE*y_offset[j]*.25) == CLIFF_LEVEL and not RectContainsCoords( gg_rct_Unpassable_Region, x, y)
endfunction
private function IsMovingAllowed takes integer i returns boolean
local integer j = moveIndex[i]
local unit u = pacman[i]
local real a = GetUnitFacing(u)*bj_DEGTORAD
local real x0 = GetUnitX(u)
local real y0 = GetUnitY(u)
local real x
local real y
set u = null
if x_offset[j] == 0 then
set y = y0 + y_offset[j] + offsetBonus[i] * MOVEMENTSPEED / y_offset[j]
set x = x0
else
set x = x0 + x_offset[j] + offsetBonus[i] * MOVEMENTSPEED / x_offset[j]
set y = y0
endif
return PathCheck(j, x, y)
endfunction
private function Movement takes nothing returns nothing
local integer i = 0
local integer j
local unit u
local real x
local real y
loop
exitwhen i > 3
set u = pacman[i]
if moveIndex[i] != 0 and not IsUnitType(u, UNIT_TYPE_DEAD) and GetUnitTypeId(u) != 0 and moveBool[i] then
set j = moveIndex[i]
if x_offset[j] == 0 then
set y = GetUnitY(u) + y_offset[j] + offsetBonus[i] * MOVEMENTSPEED / y_offset[j]
set x = GetUnitX(u)
else
set x = GetUnitX(u) + x_offset[j] + offsetBonus[i] * MOVEMENTSPEED / x_offset[j]
set y = GetUnitY(u)
endif
if PathCheck(j, x, y) then
call SetUnitX(u, x)
call SetUnitY(u, y)
//call SetUnitPosition(u, x, y)
else
set moveIndex[i] = 0
call SetUnitAnimation(u, "stand")
endif
endif
set i = i + 1
endloop
set u = null
endfunction
private function IsUnitDead takes nothing returns boolean
local integer i = GetPlayerId(GetTriggerPlayer())
local unit u = pacman[i]
local boolean b = not IsUnitType(u, UNIT_TYPE_DEAD) and GetUnitTypeId(u) != 0 and moveBool[i]
set u = null
return b
endfunction
private function UpPress takes nothing returns nothing
local integer i = GetPlayerId(GetTriggerPlayer())
local unit u = pacman[i]
local integer j = moveIndex[i]
set moveIndex[i] = 1
if IsMovingAllowed(i) then
call SetUnitAnimationByIndex(u, runAnimationIndex[i])
call SetUnitFacing(u, 90)
else
set moveIndex[i] = j
endif
set u = null
endfunction
private function DownPress takes nothing returns nothing
local integer i = GetPlayerId(GetTriggerPlayer())
local unit u = pacman[i]
local integer j = moveIndex[i]
set moveIndex[i] = 2
if IsMovingAllowed(i) then
call SetUnitAnimationByIndex(u, runAnimationIndex[i])
call SetUnitFacing(u, 270)
else
set moveIndex[i] = j
endif
set u = null
endfunction
private function RightPress takes nothing returns nothing
local integer i = GetPlayerId(GetTriggerPlayer())
local unit u = pacman[i]
local integer j = moveIndex[i]
set moveIndex[i] = 3
if IsMovingAllowed(i) then
call SetUnitAnimationByIndex(u, runAnimationIndex[i])
call SetUnitFacing(u, 0)
else
set moveIndex[i] = j
endif
set u = null
endfunction
private function LeftPress takes nothing returns nothing
local integer i = GetPlayerId(GetTriggerPlayer())
local unit u = pacman[i]
local integer j = moveIndex[i]
set moveIndex[i] = 4
if IsMovingAllowed(i) then
call SetUnitAnimationByIndex(u, runAnimationIndex[i])
call SetUnitFacing(u, 180)
else
set moveIndex[i] = j
endif
set u = null
endfunction
private function moveinit takes nothing returns nothing
local trigger move = CreateTrigger()
local trigger uppress = CreateTrigger()
local trigger downpress = CreateTrigger()
local trigger rightpress = CreateTrigger()
local trigger leftpress = CreateTrigger()
local integer i = 0
local player p
set x_offset[3] = MOVEMENTSPEED
set x_offset[4] = -MOVEMENTSPEED
set y_offset[1] = MOVEMENTSPEED
set y_offset[2] = -MOVEMENTSPEED
call TimerStart(timerMove, MOVE_TIMEOUT, TRUE, function Movement)
call TriggerAddAction(uppress, function UpPress)
call TriggerAddAction(downpress, function DownPress)
call TriggerAddAction(rightpress, function RightPress)
call TriggerAddAction(leftpress, function LeftPress)
call TriggerAddCondition( uppress, Condition( function IsUnitDead ) )
call TriggerAddCondition( downpress, Condition( function IsUnitDead ) )
call TriggerAddCondition( rightpress, Condition( function IsUnitDead ) )
call TriggerAddCondition( leftpress, Condition( function IsUnitDead ) )
loop
exitwhen i > 3
set p = Player(i)
call TriggerRegisterPlayerEvent(uppress, p, EVENT_PLAYER_ARROW_UP_DOWN)
call TriggerRegisterPlayerEvent(downpress, p, EVENT_PLAYER_ARROW_DOWN_DOWN)
call TriggerRegisterPlayerEvent(rightpress, p, EVENT_PLAYER_ARROW_RIGHT_DOWN)
call TriggerRegisterPlayerEvent(leftpress, p, EVENT_PLAYER_ARROW_LEFT_DOWN)
set moveBool[i] = TRUE
set i = i + 1
endloop
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library MoveSpeedXGUI /* v1.1.0.0
*************************************************************************************
*
* This library allows you to set unit movement speeds beyond 522 without bugs.
* This is an extension of the library MoveSpeedX, but is formatted for GUI use.
* Credits to Jesus4Lyf for the original system.
*
************************************************************************************
*
* SETTINGS
*/
globals
private constant real PERIOD = 0.03125
// This is the period on which all units will be run.
// If you lower this value, movement bonuses will be smoother,
// but will require more processing power (lag more).
// Also, the lower this is, the higher the move speed can be
// before it starts bugging on waypoints. The lowest valid
// period is 0.00125. A period of 0.00625 is very robust.
private constant real MARGIN = 0.01
// This is the margin of approximation when comparing reals.
// You will most likely not need to change this.
endglobals
/*
************************************************************************************
*
* Functions
*
* function GetUnitMoveSpeedX takes unit whichUnit returns real
* - Returns a unit movement speed. The GUI function will
* - not return the correct value. This function will always
* - return the correct value regardless of whether the unit
* - has a movement speed beyond 522.
*
************************************************************************************
*
* REQUIREMENTS
*
* 1. JassNewGen Pack v5d
* 2. JassHelper 0.A.2.B
* 3. Any unit indexer
*
* HOW TO IMPLEMENT
*
* 1. Copy the 'folder' MoveSpeedX.
* 2. Paste it into your map.
* 3. Open "Advanced -> Gameplay Constants".
* 4. Checkmark "Use Custom Gameplay Constants".
* 5. Find the field, "Movement - Unit Speed - Maximum", change
* that to 522.
* 6. Find the field, "Movement - Unit Speed - Minimum", hold
* shift and click, and change it to 0.
* 7. Read HOW TO USE.
*
************************************************************************************
*
* HOW TO USE
*
* This system will automatically work by itself. You can use the
* normal GUI function for modifying unit movement speeds. Simply
* use "Unit - Set Movement Speed", input whatever value you want,
* and you are good to go! It will handle values beyond 522 by itself.
*
* HOWEVER, the GUI function will not return correct values if a unit
* has a movement speed greater than 522. To fix this, use the function
* GetUnitMoveSpeedX to return the correct value. A sample is given in
* the trigger "Speed Change" in the test map.
*
************************************************************************************
*
* NOTES
*
* Units that were issued orders as groups might not *always* end up in the proper
* "order". (they might not end up in an organized formation) They do sometimes though.
* This is only for units with speeds above 522.
*
* This also will not factor in bonuses and probably not slows either.
*
* Units may waddle around the point for a little bit. Reduce PERIOD to fix
* it a little bit. I recommend about 0.02 if you have really high speeds.
*
************************************************************************************/
private function ApproxEqual takes real A, real B returns boolean
return (A >= (B - MARGIN)) and (A <= (B + MARGIN))
endfunction
private module M
private static trigger issued = CreateTrigger()
thistype next
thistype prev
boolean enabled
unit curr
real speed
real x
real y
real ox
real oy
method destroy takes nothing returns nothing
set this.next.prev = this.prev
set this.prev.next = this.next
set this.enabled = false
endmethod
private static method periodic takes nothing returns nothing
local thistype this = thistype(0).next // first instance in list
local real nx // the x-coordinate after tick
local real ny // the y-coordinate after tick
local real dx // distance between new-x and old-x
local real dy // distance between new-y and old-y
local real d // distance between new point and old point
local integer order // the unit's current order
local unit u // unit being affected
loop
exitwhen this == 0
set u = .curr
set nx = GetUnitX(u)
set ny = GetUnitY(u)
if IsUnitType(u, UNIT_TYPE_DEAD) then
call this.destroy()
elseif not ApproxEqual(nx, .x) or not ApproxEqual(ny, .y) then
if (not IsUnitPaused(u)) and GetUnitAbilityLevel(u, 'BSTN') == 0 and GetUnitAbilityLevel(u, 'BPSE') == 0 then
set order = GetUnitCurrentOrder(u)
set dx = nx - .x
set dy = ny - .y
set d = SquareRoot(dx * dx + dy * dy)
set dx = dx / d * .speed // move the unit offset-x by this
set dy = dy / d * .speed // move the unit offset-y by this
if (order == 851986 or order == 851971) and /*
*/ (this.ox - nx)*(this.ox - nx) < (dx*dx) and /*
*/ (this.oy - ny)*(this.oy - ny) < (dy*dy) then
// if the unit is issued a move or smart order and they are near their destination
// then move them there instantly (removes a bit of glitchyness towards the end)
call SetUnitX(u, .ox)
call SetUnitY(u, .oy)
set .x = .ox
set .y = .oy
call IssueImmediateOrderById(u, 851972) // order them to stop
else
set .x = nx + dx
set .y = ny + dy
call SetUnitX(u, .x)
call SetUnitY(u, .y)
endif
endif
endif
set this = this.next
endloop
set u = null
endmethod
static method create takes unit whichUnit, real newSpeed returns thistype
local thistype this = GetUnitUserData(whichUnit)
set this.next = thistype(0).next
set thistype(0).next.prev = this
set thistype(0).next = this
set this.prev = 0
set this.curr = whichUnit
set this.speed = (newSpeed - 522) * PERIOD
set this.x = GetUnitX(whichUnit)
set this.y = GetUnitY(whichUnit)
set this.enabled = true
return this
endmethod
static method update takes unit whichUnit, real newSpeed returns nothing
local thistype this = GetUnitUserData(whichUnit)
if this.enabled then
if newSpeed > 522 then
set this.speed = (newSpeed - 522) * PERIOD
else
call this.destroy()
endif
elseif newSpeed > 522 then
call thistype.create(whichUnit, newSpeed)
endif
endmethod
private static method storeOrderPoint takes nothing returns boolean
local thistype this = GetUnitUserData(GetTriggerUnit())
set this.ox = GetOrderPointX()
set this.oy = GetOrderPointY()
return false
endmethod
private static method onInit takes nothing returns nothing
call TimerStart(CreateTimer(), PERIOD, true, function thistype.periodic)
call TriggerRegisterAnyUnitEventBJ(issued, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER)
call TriggerAddCondition(issued, Condition(function thistype.storeOrderPoint))
endmethod
endmodule
private struct MoveSpeedStruct extends array
implement M
endstruct
function GetUnitMoveSpeedX takes unit whichUnit returns real
if MoveSpeedStruct(GetUnitUserData(whichUnit)).enabled then
return udg_UnitSpeedX[GetUnitUserData(whichUnit)]
endif
return GetUnitMoveSpeed(whichUnit)
endfunction
function SetUnitMoveSpeedX takes unit whichUnit, real newSpeed returns nothing
call MoveSpeedStruct.update(whichUnit, newSpeed)
set udg_UnitSpeedX[GetUnitUserData(whichUnit)] = newSpeed
endfunction
hook SetUnitMoveSpeed SetUnitMoveSpeedX
endlibrary