//TESH.scrollpos=0
//TESH.alwaysfold=0
Name | Type | is_array | initial_value |
//TESH.scrollpos=0
//TESH.alwaysfold=0
Description
/*
08/12/2015
3D Object Collision and Jump System 0.7.0.0 Beta
Created completely from scratch by DeathChef @ hiveworkshop.com
This system is created to allow you to create physics like a
3rd person shooter with a 3rd dimension to their physics system.
For example if you want want to make a bridge, without this system
you would only be able to go either under or over and not both.
With this you are able to do both at the same time while also falling
onto and off and also jump to and from them smoothly.
Check out the disabled trigger named "Manual" to find out what
you can do with this system.
Check out the upload page for
full change log, updates, comment and other things:
www.hiveworkshop.com/forums/spells-569/3d-object-collision-jump-system-v0-4-0-0-a-263598
Basic test map controls:
1. Use the arrow keys to move
2. Use the "Q" hotkey to jump
3. Select other unit to change interface over to it
Change log: 0.6.0.1 beta -> 0.7.0.0 beta(08/12/2015)
1. Documentation:
- Listed out in the manual all the usable functions and variables
in this system
- Documented all triggers that are a part of this system
- Updated the importing documentation a little
2. Merged, optimized and organized a lot of code
3. Removed some requirments:
- ForAllDest
- GetLocZ
- CheckAngle
- IsPlaying
- InitArrowKey
- AllowFlight
Added some new ones:
- PlayerManager
- AutoFlight
- GetTerrainZ
- ArrowEvent
- ArriwEvent_PlayerRegister
4. Setting custimizability:
- Created settings trigger that contains constant value customizability
- Created functions and variables the can customize for unit unit types
(Only works on newly/to be created units)
- Can customize specific system unit settings at any time
- Due to custimizability of unit settings, the static method no longer
use the width and height variables
6. Collision objects:
- Added 2D Circle creation
- Can recreate 3D Rectangles dimensions with other 3D Rectangle Id
- Can now check if a unit is inside a 3D Rectangle
- Created some technical functions for indexing collision objects
Known bugs:
1. Edge of object clipping occurs
2. Setting a destructables health % to 0 will not remove the
collision object attached to it
3. Walking to collide with 3D objects in particular situations will cause the
unit to stop insdead of moving along side of it
(Not tested)
1. If you try and collide with a thin enough object, have a high enough move
rate you or/and have a thin enough unit you might walk through the object
2. Removing a 3D collision objects that is attached to
an destructable before killing the detstructable first will cause bugs
3. Some functions are not compleyely safe to run
(A possibility)
1. Some objects may not register or get destroyed properly
in certain situation
(Not debugable afaik)
1. Walking off the edge of the map will make your units
model disappear. ((Not tested.) Although it is possible
to create collision objects outside the edge of the map)
2. Creating collision objects with any patch of blizzard water
will create glitching (must have no indication of blizzard water
around objects with this system for this system to function)
Credits:
. Nestharus for the Unit Indexer and other requirments
. Bribe for the base ArrowKeyEvent System
Ideas:
1. Unit Movement with mouse clicks (allow disabling of the Camera
Arrow structs to be replaced by the normal camera and movement to
be made by clicks)
2. Use plains for collision (will help with unnesesary object clipping)
3. Allow sliding along edges of objects to not stop movment with a
thickness limit
4. Make sliding on steep cliffs
5. Allow usage of triangle like 3D object with z variance
6. Allow a function call that can call once or multiple times when a unit
enters a 3D objects area and can get the unit that entered
7. Have a hack for WE that allows placment of 3D collision objects or
atleast detect the Z value(or fly height like units) of destructables
8. When destructables are moved that have objects attached to them move
them with the destructable and viseversa
*/
//TESH.scrollpos=0
//TESH.alwaysfold=0
Importing the system into your map:
/*
08/12/2015
3D Object Collision and Jump System 0.7.0.0 Beta
Author: DeathChef @ hiveworkshop.com
(Note: Recommended to follow these instructions to avoid issues)
1. Copy all folders and paste all folders except the "Test Map Only"
into your map
2. Copy and paste the following object editor data into your map
'Abilities'
- 'A000' Unit Indexing (Unit Indexing)
- 'A001' Jump
Interface and Ingame units into your map
Units: The unit that you see ingame must have at least one(1) movement
speed and be able to move with the interface unit not having any movement
speed(0)
3. Recommended to import the units in this map
'Units'
- 'n001' Jumper
- 'n000' Jumper Interface
Read the description and follow the functions to your wants from the Manual
___
Remember to use Jass New Generation Pack or any other software
available for using vJass
*/
//TESH.scrollpos=0
//TESH.alwaysfold=0
Manual!
/*
08/12/2015
3D Object Collision and Jump System 0.7.0.0 Beta
Author: DeathChef @ hiveworkshop.com
Future updates may provide more detail on extra content
control and limitations
Content in this system may be changed in future updates
Content;
Using static method
Unit
- Movement
- SystemUnit
- Camera
- Arrow
- Interface
Object
Using static method
For any static method to be executed in your code, a prefix of the struct name
it came from has to be declared before the static method name
Eg;
for units
local real x = SystemUnit.GetX(UnitA)
call SystemUnit.Attach(UnitB, x, 60)
for 3D Rectangle objects
call Rectangle3D.Create(231, 313, 43, 143, 53, 152)
call Rectangle3D.RemoveInRectangleArea(321, 367, 456, 765)
For further information on how to use struct, check out the vJass manual
http://www.wc3c.net/vexorian/jasshelpermanual.html
Unit
The attached units will be able to collide and walk on the objects created for this system
Attached units will be given the potential ability to
. be given the ability to jump
. have the owning players vision locked to it
. be able to be ordered to walk by the arrow keys
. be able to be ordered to walk by right mouse click order (currently under construction)
Units that die automatically get detached
Once this unit is detached everything in this system for the unit will be removed with it
struct Movement extends array
Description
Core periodic event for getting units attached to system,
checking if any object is blocking their path and settings
that units coordinates to appropriate position.
Methods
static method Start takes nothing returns nothing
static method Stop takes nothing returns nothing
struct SystemUnit extends array
Description
Core of units attached to the system containing the variables
of those units, the initializers for attaching them and attaching
methods to them. Detaches any unit on death.
Fields
static integer Count
unit Unit
integer UserData
integer Index
boolean Attached
player User
integer UserId
real X
real Y
real Z
real Facing
real Height
real Width
real Distance
real Angle
real AirTime
boolean CanJump
real DropRate
real InitialJumpRate
real StopSpeed
real WalkSpeed
real WalkStraightSpeed
real TurnSpeed
integer AnimationIndexWalk
integer AnimationIndexStand
real AnimationSpeedWalkForward
real AnimationSpeedWalkBackward
real AnimationSpeedTurnOnSpot
/
static integer TypeIdCount
hashtable TypeIdIndex
real TypeIdDropRate
real TypeIdInitialJumpRate
real TypeIdStopSpeed
real TypeIdWalkSpeed
real TypeIdWalkStraightSpeed
real TypeIdTurnSpeed
integer TypeIdAnimationIndexWalk
integer TypeIdAnimationIndexStand
real TypeIdAnimationSpeedWalkForward
real TypeIdAnimationSpeedWalkBackward
real TypeIdAnimationSpeedTurnOnSpot
Methods
static method init takes unit u returns thistype
static method deinit takes thistype this returns nothing
/
static method AttachAll takes unit u returns nothing
static method AttachAllInterface takes unit u, integer UnitInterfaceId returns nothing
static method AttachUnit takes unit u returns nothing
static method AttachCamera takes unit u returns nothing
static method AttachInterface takes unit u, integer UnitInterfaceId returns nothing
static method AttachArrow takes unit u returns nothing
static method DetachUnit takes unit u returns nothing
static method DetachCamera takes unit u returns nothing
static method DetachInterface takes unit u returns nothing
static method DetachArrow takes unit u returns nothing
/
static method GetTypeIdHeight takes integer UnitTypeId returns real
static method GetTypeIdWidth takes integer UnitTypeId returns real
static method GetTypeIdDropRate takes integer UnitTypeId returns real
static method GetTypeIdInitialJumpRate takes integer UnitTypeId returns real
static method GetTypeIdStopSpeed takes integer UnitTypeId returns real
static method GetTypeIdWalkSpeed takes integer UnitTypeId returns real
static method GetTypeIdWalkStraightSpeed takes integer UnitTypeId returns real
static method GetTypeIdTurnSpeed takes integer UnitTypeId returns real
static method GetTypeIdAnimationIndexWalk takes integer UnitTypeId returns integer
static method GetTypeIdAnimationIndexStand takes integer UnitTypeId returns integer
static method GetTypeIdAnimationSpeedWalkForward takes integer UnitTypeId returns real
static method GetTypeIdAnimationSpeedWalkBackward takes integer UnitTypeId returns real
static method GetTypeIdAnimationSpeedTurnOnSpot takes integer UnitTypeId returns real
static method SetTypeIdHeight takes integer UnitTypeId, real h returns nothing
static method SetTypeIdWidth takes integer UnitTypeId, real w returns nothing
static method SetTypeIdDropRate takes integer UnitTypeId, real dr returns nothing
static method SetTypeIdInitialJumpRate takes integer UnitTypeId, real ijr returns nothing
static method SetTypeIdStopSpeed takes integer UnitTypeId, real ss returns nothing
static method SetTypeIdWalkSpeed takes integer UnitTypeId, real ws returns nothing
static method SetTypeIdWalkStraightSpeed takes integer UnitTypeId, real wsp returns nothing
static method SetTypeIdTurnSpeed takes integer UnitTypeId, real h returns nothing
static method SetTypeIdAnimationIndexWalk takes integer UnitTypeId, real aiw returns nothing
static method SetTypeIdAnimationIndexStand takes integer UnitTypeId, real ais returns nothing
static method SetTypeIdAnimationSpeedWalkForward takes integer UnitTypeId, real aswf returns nothing
static method SetTypeIdAnimationSpeedWalkBackward takes integer UnitTypeId, real aswb returns nothing
static method SetTypeIdAnimationSpeedTurnOnSpot takes integer UnitTypeId, real aston returns nothing
/
static method GetX takes unit u returns real
static method GetY takes unit u returns real
static method GetZ takes unit u returns real
static method GetFlyHeight takes unit u returns real
static method GetFacing takes unit u returns real
static method GetHeight takes unit u returns real
static method GetWidth takes unit u returns real
static method GetDropRate takes unit u returns real
static method GetInitialJumpRate takes unit u returns real
static method GetStopSpeed takes unit u returns real
static method GetWalkSpeed takes unit u returns real
static method GetWalkStraightSpeed takes unit u returns real
static method GetTurnSpeed takes unit u returns real
static method GetAnimationIndexWalk takes unit u returns integer
static method GetAnimationIndexStand takes unit u returns integer
static method GetAnimationSpeedWalkForward takes unit u returns real
static method GetAnimationSpeedWalkBackward takes unit u returns real
static method GetAnimationSpeedTurnOnSpot takes unit u returns real
static method SetXYZFacing takes unit u, real x, real y, real z, real f returns nothing
static method SetXYFlyHeightFacing takes unit u, real x, real y, real z, real f returns nothing
static method SetXYZ takes unit u, real x, real y, real z returns nothing
static method SetXYFlyHeight takes unit u, real x, real y, real z returns nothing
static method SetXYFacing takes unit u, real x, real y, real f returns nothing
static method SetXY takes unit u, real x, real y returns nothing
static method SetX takes unit u, real x returns nothing
static method SetY takes unit u, real y returns nothing
static method SetZ takes unit u, real z returns nothing
static method SetFlyHeight takes unit u, real z returns nothing
static method SetFacing takes unit u, real f returns nothing
static method SetHeight takes unit u, real h returns nothing
static method SetWidth takes unit u, real w returns nothing
static method SetDropRate takes unit u, real dr returns nothing
static method SetInitialJumpRate takes unit u, real ijr returns nothing
static method SetStopSpeed takes unit u, real ss returns nothing
static method SetWalkSpeed takes unit u, real ws returns nothing
static method SetWalkStraightSpeed takes unit u, real wsp returns nothing
static method SetTurnSpeed takes unit u, real h returns nothing
static method SetAnimationIndexWalk takes unit u, integer aiw returns nothing
static method SetAnimationIndexStand takes unit u, integer ais returns nothing
static method SetAnimationSpeedWalkForward takes unit u, real aswf returns nothing
static method SetAnimationSpeedWalkBackward takes unit u, real aswb returns nothing
static method SetAnimationSpeedTurnOnSpot takes unit u, real aston returns nothing
struct Camera extends array
Description
Attaches the owner of a unit's camera to the unit.
Is a requirment for Arrow commands and Unit interface.
Fields
static boolean LocalPlayerAttached = false
static integer LocalAttachedIndex
unit Unit
Methods
static method init takes SystemUnit this returns nothing
static method deinit takes SystemUnit this returns nothing
struct Arrow extends array
Description
Allows for Arrow key movement to the attached unit.
Requires Camera unit attachment.
Fields
boolean IsUp
boolean IsDown
boolean IsLeft
boolean IsRight
unit Unit
integer Id
Methods
static method init takes SystemUnit Index returns nothing
static method deinit takes SystemUnit Index returns nothing
struct Interface extends array
Description
Disables right click mobility and removes the command abilities.
Requires Camera unit attachment.
Fields
unit Unit
integer UserData
integer Index
boolean Attached
Methods
static method init takes thistype this, integer Id returns nothing
static method deinit takes thistype this returns nothing
static method deinit2 takes thistype this, thistype Count returns nothing
Object
For any unit attached to this system it will be able to collide and walk
on top of the objects created and initialized from the map script.
Note: The objects created in this system represent no art form, other
than collision (the actual objects themselves are invicible).
When any destructable gets destroyed the object that is attached to
it will be removed with it
struct Rectangle3D extends array
Description
Collision check for reassigning units position outside of
object if ever intercept with the objects coordinate limits
Fields
real MinX
real MaxX
real MinY
real MaxY
real MinZ
real MaxZ
static hashtable Sector
static hashtable SectorIndex
static hashtable SectorUserData
integer SectorCount
integer SectorIndexCount
integer Recycler
static thistype RecyclerCount
boolean Attached
destructable Dest
static hashtable DestIndex
integer DestHandle
boolean DestAttached
static InterfaceGetObjectId forObject
Methods
static method Create takes real MinX, real MaxX, real MinY, real MaxY, real MinZ, real MaxZ returns integer
static method Recreate takes real x, real y, thistype Object returns integer
static method RecreateZ takes real x, real y, real z, thistype Object returns integer
static method DoesExist takes thistype ObjectId returns boolean
static method CreateIndex takes real MinX, real MaxX, real MinY, real MaxY returns integer
static method Remove takes thistype ObjectIndex returns nothing
static method AttachToDest takes destructable d, thistype ObjectIndex returns nothing
static method CreateAttachedToDest takes destructable d, real MinX, real MaxX, real MinY, real MaxY, real MinZ, real MaxZ returns nothing
static method CreateAttachedToDests takes integer DestId, real MinX, real MaxX, real MinY, real MaxY, real MinZ, real MaxZ returns nothing
static method DetachDest takes thistype ObjectIndex returns nothing
static method DetachFromDest takes destructable d returns nothing
static method RegisterDestDeathEvent takes destructable d returns nothing
static method DestroyDestDeathEvent takes destructable d returns nothing
static method GetDestIndex takes destructable d returns integer
static method GetAttachedDest takes thistype ObjectId returns destructable
static method HasDestAttached takes thistype ObjectId returns boolean
static method IsDestAttached takes destructable Dest returns boolean
static method ForSectorsInCoordinates takes real MinX, real MaxX, real MinY, real MaxY, InterfaceGetObjectId temp_forObject returns nothing
static method ForSectorsInCoordinatesExclusive takes real MinX, real MaxX, real MinY, real MaxY, InterfaceGetObjectIdWithUnit forObject, SystemUnit Unit returns nothing
static method ForAllObjectsInRectangleObject takes RectangleObject ObjectId, InterfaceGetObjectId forObjectId returns nothing
static method ForAllObjectsInRectangleArea takes real MinX, real MaxX, real MinY, real MaxY, InterfaceGetObjectId forObjectId returns nothing
static method ForAllObjectsInRectangleAreaZ takes real MinX, real MaxX, real MinY, real MaxY, real MinZ, real MaxZ, InterfaceGetObjectId ObjectId returns nothing
static method IsUnitInsideId takes RectangleObject Object, SystemUnit this returns boolean
static method IsUnitInside takes RectangleObject Object, unit u returns boolean
static method IsUnitInsideAnyId takes SystemUnit this returns boolean
static method IsUnitInsideAny takes unit u returns boolean
static method GetMinX takes thistype ObjectId returns real
static method GetMaxX takes thistype ObjectId returns real
static method GetMinY takes thistype ObjectId returns real
static method GetMaxY takes thistype ObjectId returns real
static method GetMinZ takes thistype ObjectId returns real
static method GetMaxZ takes thistype ObjectId returns real
static method GetX takes thistype ObjectId returns real
static method GetY takes thistype ObjectId returns real
static method GetZ takes thistype ObjectId returns real
static method SetMinX takes thistype ObjectId, real minX returns nothing
static method SetMaxX takes thistype ObjectId, real maxX returns nothing
static method SetMinY takes thistype ObjectId, real minY returns nothing
static method SetMaxY takes thistype ObjectId, real maxY returns nothing
static method SetMinZ takes thistype ObjectId, real minZ returns nothing
static method SetMaxZ takes thistype ObjectId, real maxZ returns nothing
static method SetXYZ takes thistype ObjectId, real x, real y, real z returns nothing
static method SetXY takes thistype ObjectId, real x, real y, real z returns nothing
static method SetX takes thistype ObjectId, real x returns nothing
static method SetY takes thistype ObjectId, real y returns nothing
static method SetZ takes thistype ObjectId, real z returns nothing
struct Circle2D extends array
Description
Collision check for reassigning units position outside of
object if ever intercept with the objects coordinate limits
Modules
Circle2D_CreateAll
ObjectAddons
Fields
real x
real y
real z
real Radius
boolean HasTop
boolean HasBottom
static hashtable Sector
static hashtable SectorIndex
static hashtable SectorUserData
integer SectorCount
integer SectorIndexCount
integer Recycler
static thistype RecyclerCount
boolean Attached
destructable Dest
static hashtable DestIndex
integer DestHandle
boolean DestAttached
static InterfaceGetObjectId forObject
Methods
static method Create takes real x, real y, real z, real Radius, boolean HasTop, boolean HasBottom returns integer
static method DoesExist takes thistype ObjectId returns boolean
static method CreateIndex takes real MinX, real MaxX, real MinY, real MaxY returns integer
static method Remove takes thistype ObjectIndex returns nothing
static method AttachToDest takes destructable d, thistype ObjectIndex returns nothing
static method CreateAttachedToDest takes destructable d, real x, real y, real z, real Radius, boolean HasTop, boolean HasBottom returns nothing
static method CreateAttachedToDests takes integer DestId, real z, real Radius, boolean HasTop, boolean HasBottom returns nothing
static method DetachDest takes thistype ObjectIndex returns nothing
static method DetachFromDest takes destructable d returns nothing
static method RegisterDestDeathEvent takes destructable d returns nothing
static method DestroyDestDeathEvent takes destructable d returns nothing
static method GetDestIndex takes destructable d returns integer
static method GetAttachedDest takes thistype ObjectId returns destructable
static method HasDestAttached takes thistype ObjectId returns boolean
static method IsDestAttached takes destructable Dest returns boolean
static method ForSectorsInCoordinates takes real MinX, real MaxX, real MinY, real MaxY, InterfaceGetObjectId temp_forObject returns nothing
static method ForSectorsInCoordinatesExclusive takes real MinX, real MaxX, real MinY, real MaxY, InterfaceGetObjectIdWithUnit forObject, SystemUnit Unit returns nothing
*/
//TESH.scrollpos=0
//TESH.alwaysfold=0
//Settings
/*
Custom settings
This trigger contains all customizable
constant variables within this system
that arn't inside the Requirments folder
Any of these constants that are unit or
camera customizable can be changed with
custom function found in the manual
for each unit and player
*/
module Movement_Settings
static constant real PERIODIC_CHECK = 0.03125
endmodule
module SystemUnit_Settings
static constant real WIDTH = 14
static constant real HEIGHT = 65
static constant real DROP_RATE = 1.6
endmodule
module Jump_Settings
static constant integer JUMP = 'A001'
static constant real INITIAL_JUMP_RATE = 17.5
endmodule
module Camera_Settings
//Camera values
static real ZOffsetHeightMultiply = 0.8
static real ZOffsetAddition = 180
static real AngleOfAttack = 310
static real TargetDistance = 600
static real CameraSmoothFactor = 0.125
static real DefaultCameraSmoothFactor = 0
//Refresh rate
static real RotationRefreshRate = 0.15625
static real ZOffsetRefreshRate = 0.09375
static real AngleOfAttackRefreshRate = 0.03125
static real TargetDistangeRefreshRate = 0.03125
static constant real CAMERA_REFRESH_RATE = 0.03125
endmodule
module Arrow_Settings
//Movement speed values
static constant real STOP_SPEED = 0
static constant real WALK_SPEED = 3.8
static constant real WALK_STRAIGHT_SPEED = 4.2
static constant real TURN_SPEED = 3.2
//Animation values
static constant integer ANIMATION_INDEX_WALK = 0
static constant integer ANIMATION_INDEX_STAND = 1
static constant real ANIMATION_SPEED_WALK_FORWARD = 1.25
static constant real ANIMATION_SPEED_WALK_BACKWARD = -1.25
static constant real ANIMATION_SPEED_TURN_ON_SPOT = 0.75
endmodule
//TESH.scrollpos=0
//TESH.alwaysfold=0
library PinSector /* v2.0.0.0, created by DeathChef
*/ uses /*
*/ WorldBounds /*
struct PinSector extends array
Description
Splits parts of the map into individual square sections where
each square area has an individual index
How large each sector is must be a value of 2^n
Settings
*/
//! textmacro PIN_SECTOR_SETTINGS
private static constant real SECTOR_SCALE = 512
//! endtextmacro
/*
Fields
readonly static integer MapXSpread
readonly static integer MapMinX
readonly static integer MapMinY
readonly static integer MapMaxX
readonly static integer MapMaxY
Methods
static method Get takes real X, real Y returns integer
static method RunFunc takes real MinX, real MaxX, real MinY, real MaxY, GetSector forSector returns nothing
static method RunFuncExclusive takes real MinX, real MaxX, real MinY, real MaxY, GetSectorExclusive forSector, SystemUnit Unit returns nothing
function interfaces
function interface InterfaceGetObjectId takes integer ObjectId returns nothing
function interface InterfaceGetObjectIdWithUnit takes integer ObjectId, integer Unit returns nothing
*/
struct PinSector extends array
//! runtextmacro PIN_SECTOR_SETTINGS()
readonly static integer MapXSpread
readonly static integer MapMinX
readonly static integer MapMinY
readonly static integer MapMaxX
readonly static integer MapMaxY
private static method SafeR2I takes real r returns integer
if r < 0 then
return R2I(r - 1)
endif
return R2I(r)
endmethod
static method Get takes real X, real Y returns integer
return MapXSpread * (SafeR2I(Y / SECTOR_SCALE) - MapMinY) + SafeR2I(X / SECTOR_SCALE) - MapMinX
endmethod
implement PinSector_ForSectors
private static method onInit takes nothing returns nothing
set MapMinX = R2I(WorldBounds.minX/SECTOR_SCALE)
set MapMinY = R2I(WorldBounds.minY/SECTOR_SCALE)
set MapMaxX = R2I(WorldBounds.maxX/SECTOR_SCALE) - 1
set MapMaxY = R2I(WorldBounds.maxY/SECTOR_SCALE) - 1
set MapXSpread = MapMaxX - MapMinX + 1
endmethod
endstruct
endlibrary
function interface InterfaceGetObjectId takes integer ObjectId returns nothing
function interface InterfaceGetObjectIdWithUnit takes integer ObjectId, integer Unit returns nothing
module PinSector_ForSectors
static method RunFunc takes real MinX, real MaxX, real MinY, real MaxY, InterfaceGetObjectId forSector returns nothing
local integer BLSector = PinSector.Get(MinX, MinY)
local integer TRSector = PinSector.Get(MaxX, MaxY)
local integer SectorStart = BLSector
local integer SectorEnd = PinSector.Get(MaxX, MinY)
loop
loop
call forSector.execute(BLSector)
exitwhen BLSector == SectorEnd
set BLSector = BLSector + 1
endloop
exitwhen BLSector == TRSector
set SectorStart = SectorStart + PinSector.MapXSpread
set SectorEnd = SectorEnd + PinSector.MapXSpread
set BLSector = SectorStart
endloop
endmethod
static method RunFuncExclusive takes real MinX, real MaxX, real MinY, real MaxY, InterfaceGetObjectIdWithUnit forSector, SystemUnit Unit returns nothing
local integer BLSector = PinSector.Get(MinX, MinY)
local integer TRSector = PinSector.Get(MaxX, MaxY)
local integer SectorStart = BLSector
local integer SectorEnd = PinSector.Get(MaxX, MinY)
loop
loop
call forSector.execute(BLSector, Unit)
exitwhen BLSector == SectorEnd
set BLSector = BLSector + 1
endloop
exitwhen BLSector == TRSector
set SectorStart = SectorStart + PinSector.MapXSpread
set SectorEnd = SectorEnd + PinSector.MapXSpread
set BLSector = SectorStart
endloop
endmethod
endmodule
//TESH.scrollpos=0
//TESH.alwaysfold=0
library Event /* v2.0.0.1
************************************************************************************
*
* Functions
*
* function CreateEvent takes nothing returns integer
* function TriggerRegisterEvent takes trigger t, integer ev returns nothing
*
************************************************************************************
*
* struct Event extends array
*
* static method create takes nothing returns thistype
* method registerTrigger takes trigger t returns nothing
* method register takes boolexpr c returns nothing
* method fire takes nothing returns nothing
*
************************************************************************************/
globals
private real q=0
endglobals
struct Event extends array
private static integer w=0
private static trigger array e
static method create takes nothing returns thistype
set w=w+1
set e[w]=CreateTrigger()
return w
endmethod
method registerTrigger takes trigger t returns nothing
call TriggerRegisterVariableEvent(t,SCOPE_PRIVATE+"q",EQUAL,this)
endmethod
method register takes boolexpr c returns nothing
call TriggerAddCondition(e[this],c)
endmethod
method fire takes nothing returns nothing
set q=0
set q=this
call TriggerEvaluate(e[this])
endmethod
endstruct
function CreateEvent takes nothing returns Event
return Event.create()
endfunction
function TriggerRegisterEvent takes trigger t,Event ev returns nothing
call ev.registerTrigger(t)
endfunction
function RegisterEvent takes boolexpr c,Event ev returns nothing
call ev.register(c)
endfunction
function FireEvent takes Event ev returns nothing
call ev.fire()
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library UnitIndexer /* v4.0.2.7
*************************************************************************************
*
* Assigns unique indexes to units via unit user data.
*
*************************************************************************************
*
* */uses/*
*
* */ WorldBounds /* hiveworkshop.com/forums/jass-functions-413/snippet-worldbounds-180494/
* */ Event /* hiveworkshop.com/forums/submissions-414/snippet-event-186555/
*
************************************************************************************
*
* SETTINGS
*/
globals
constant integer ABILITIES_UNIT_INDEXER = 'A000'
endglobals
/*
************************************************************************************
*
* Functions
*
* function RegisterUnitIndexEvent takes boolexpr codeToRegister, Event unitIndexEvent returns nothing
* function TriggerRegisterUnitIndexEvent takes trigger triggerToRegister, Event unitIndexEvent returns nothing
*
* function GetUnitById takes integer index returns unit
* - Returns unit given a unit index
* function GetUnitId takes unit u returns integer
* - Returns unit index given a unit
*
* function IsUnitIndexed takes unit u returns boolean
* function IsUnitDeindexing takes unit u returns boolean
*
* function GetIndexedUnitId takes nothing returns integer
* function GetIndexedUnit takes nothing returns unit
*
************************************************************************************
*
* module UnitIndexStructMethods
* static method operator [] takes unit u returns thistype
* - Return GetUnitUserData(u)
*
* readonly unit unit
* - The indexed unit of the struct
*
************************************************************************************
*
* module UnitIndexStruct extends UnitIndexStructMethods
*
* - A pseudo module interface that runs a set of methods if they exist and provides
* - a few fields and operators. Runs on static ifs to minimize code.
*
* readonly boolean allocated
* - Is unit allocated for the struct
*
* Interface:
*
* - These methods don't have to exist. If they don't exist, the code
* - that calls them won't even be in the module.
*
* private method index takes nothing returns nothing
* - called when a unit is indexed and passes the filter.
* -
* - thistype this: Unit's index
* private method deindex takes nothing returns nothing
* - called when a unit is deindexed and is allocated for struct
* -
* - thistype this: Unit's index
* private static method filter takes unit unitToIndex returns boolean
* - Determines whether or not to allocate struct for unit
* -
* - unit unitToIndex: Unit being filtered
*
************************************************************************************
*
* struct UnitIndexer extends array
*
* - Controls the unit indexer system.
*
* static constant Event UnitIndexer.INDEX
* static constant Event UnitIndexer.DEINDEX
* - Don't register functions and triggers directly to the events. Register them via
* - RegisterUnitIndexEvent and TriggerRegisterUnitIndexEvent.
*
* static boolean enabled
* - Enables and disables unit indexing. Useful for filtering out dummy units.
*
************************************************************************************
*
* struct UnitIndex extends UnitIndexStructMethods
*
* - Constrols specific unit indexes.
*
* method lock takes nothing returns nothing
* - Locks an index. When an index is locked, it will not be recycled
* - when the unit is deindexed until all locks are removed. Deindex
* - events still fire at the appropriate times, the index just doesn't
* - get thrown into the recycler.
* method unlock takes nothing returns nothing
* - Unlocks an index.
*
************************************************************************************/
globals
private trigger q=CreateTrigger()
private trigger l=CreateTrigger()
private unit array e
private integer r=0
private integer y=0
private integer o=0
private boolean a=false
private integer array n
private integer array p
private integer array lc
endglobals
function GetIndexedUnitId takes nothing returns integer
return o
endfunction
function GetIndexedUnit takes nothing returns unit
return e[o]
endfunction
//! runtextmacro optional UNIT_LIST_LIB()
private struct PreLoader extends array
public static method run takes nothing returns nothing
call DestroyTimer(GetExpiredTimer())
set a=true
endmethod
public static method eval takes trigger t returns nothing
local integer f=n[0]
local integer d=o
loop
exitwhen 0==f
if (IsTriggerEnabled(t)) then
set o=f
if (TriggerEvaluate(t)) then
call TriggerExecute(t)
endif
else
exitwhen true
endif
set f=n[f]
endloop
set o=d
endmethod
public static method evalb takes boolexpr c returns nothing
local trigger t=CreateTrigger()
local thistype f=n[0]
local integer d=o
call TriggerAddCondition(t,c)
loop
exitwhen 0==f
set o=f
call TriggerEvaluate(t)
set f=n[f]
endloop
call DestroyTrigger(t)
set t=null
set o=d
endmethod
endstruct
//! runtextmacro optional UNIT_EVENT_MACRO()
private module UnitIndexerInit
private static method onInit takes nothing returns nothing
local integer i=15
local boolexpr bc=Condition(function thistype.onLeave)
local boolexpr bc2=Condition(function thistype.onEnter)
local group g=CreateGroup()
local player p
set INDEX=CreateEvent()
set DEINDEX=CreateEvent()
call TriggerRegisterEnterRegion(q,WorldBounds.worldRegion,bc2)
loop
set p=Player(i)
call TriggerRegisterPlayerUnitEvent(l,p,EVENT_PLAYER_UNIT_ISSUED_ORDER,bc)
call SetPlayerAbilityAvailable(p,ABILITIES_UNIT_INDEXER,false)
call GroupEnumUnitsOfPlayer(g,p,bc2)
exitwhen 0==i
set i=i-1
endloop
call DestroyGroup(g)
set bc=null
set g=null
set bc2=null
set p=null
call TimerStart(CreateTimer(),0,false,function PreLoader.run)
endmethod
endmodule
struct UnitIndex extends array
method lock takes nothing returns nothing
debug if (null!=e[this]) then
set lc[this]=lc[this]+1
debug else
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"UNIT INDEXER ERROR: ATTEMPT TO LOCK NULL INDEX")
debug endif
endmethod
method unlock takes nothing returns nothing
debug if (0<lc[this]) then
set lc[this]=lc[this]-1
if (0==lc[this] and null==e[this]) then
set n[this]=y
set y=this
endif
debug else
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"UNIT INDEXER ERROR: ATTEMPT TO UNLOCK UNLOCKED INDEX")
debug endif
endmethod
method operator unit takes nothing returns unit
return e[this]
endmethod
static method operator [] takes unit whichUnit returns thistype
return GetUnitUserData(whichUnit)
endmethod
endstruct
struct UnitIndexer extends array
readonly static Event INDEX
readonly static Event DEINDEX
static boolean enabled=true
private static method onEnter takes nothing returns boolean
local unit Q=GetFilterUnit()
local integer i
local integer d=o
if (enabled and Q!=e[GetUnitUserData(Q)] and 0==GetUnitUserData(Q)) then
if (0==y) then
set r=r+1
set i=r
else
set i=y
set y=n[y]
endif
call UnitAddAbility(Q,ABILITIES_UNIT_INDEXER)
call UnitMakeAbilityPermanent(Q,true,ABILITIES_UNIT_INDEXER)
call SetUnitUserData(Q,i)
set e[i]=Q
static if not LIBRARY_UnitList then
if (not a)then
set p[i]=p[0]
set n[p[0]]=i
set n[i]=0
set p[0]=i
endif
else
set p[i]=p[0]
set n[p[0]]=i
set n[i]=0
set p[0]=i
call GroupAddUnit(g,e[i])
endif
set o=i
call FireEvent(INDEX)
set o=d
endif
set Q=null
return false
endmethod
private static method onLeave takes nothing returns boolean
static if LIBRARY_UnitEvent then
implement optional UnitEventModule
else
local unit u=GetFilterUnit()
local integer i=GetUnitUserData(u)
local integer d=o
if (0==GetUnitAbilityLevel(u,ABILITIES_UNIT_INDEXER) and u==e[i]) then
static if not LIBRARY_UnitList then
if (not a)then
set n[p[i]]=n[i]
set p[n[i]]=p[i]
endif
else
set n[p[i]]=n[i]
set p[n[i]]=p[i]
call GroupRemoveUnit(g,e[i])
endif
set o=i
call FireEvent(DEINDEX)
set o=d
if (0==lc[i]) then
set n[i]=y
set y=i
endif
set e[i]=null
endif
set u=null
endif
return false
endmethod
implement UnitIndexerInit
endstruct
//! runtextmacro optional UNIT_EVENT_MACRO_2()
function RegisterUnitIndexEvent takes boolexpr c,integer ev returns nothing
call RegisterEvent(c, ev)
if (not a and ev==UnitIndexer.INDEX and 0!=n[0]) then
call PreLoader.evalb(c)
endif
endfunction
function TriggerRegisterUnitIndexEvent takes trigger t,integer ev returns nothing
call TriggerRegisterEvent(t,ev)
if (not a and ev == UnitIndexer.INDEX and 0!=n[0]) then
call PreLoader.eval(t)
endif
endfunction
function GetUnitById takes integer W returns unit
return e[W]
endfunction
function GetUnitId takes unit u returns integer
return GetUnitUserData(u)
endfunction
function IsUnitIndexed takes unit u returns boolean
return u==e[GetUnitUserData(u)]
endfunction
function IsUnitDeindexing takes unit u returns boolean
return IsUnitIndexed(u) and 0==GetUnitAbilityLevel(u,ABILITIES_UNIT_INDEXER)
endfunction
module UnitIndexStructMethods
static method operator [] takes unit u returns thistype
return GetUnitUserData(u)
endmethod
method operator unit takes nothing returns unit
return e[this]
endmethod
endmodule
module UnitIndexStruct
implement UnitIndexStructMethods
static if thistype.filter.exists then
static if thistype.index.exists then
static if thistype.deindex.exists then
readonly boolean allocated
else
method operator allocated takes nothing returns boolean
return filter(e[this])
endmethod
endif
else
method operator allocated takes nothing returns boolean
return filter(e[this])
endmethod
endif
elseif (thistype.index.exists) then
static if thistype.deindex.exists then
readonly boolean allocated
else
method operator allocated takes nothing returns boolean
return this==GetUnitUserData(e[this])
endmethod
endif
else
method operator allocated takes nothing returns boolean
return this==GetUnitUserData(e[this])
endmethod
endif
static if thistype.index.exists then
private static method onIndexEvent takes nothing returns boolean
static if thistype.filter.exists then
if (filter(e[o])) then
static if thistype.deindex.exists then
set thistype(o).allocated=true
endif
call thistype(o).index()
endif
else
static if thistype.deindex.exists then
set thistype(o).allocated=true
endif
call thistype(o).index()
endif
return false
endmethod
endif
static if thistype.deindex.exists then
private static method onDeindexEvent takes nothing returns boolean
static if thistype.filter.exists then
static if thistype.index.exists then
if (thistype(o).allocated) then
set thistype(o).allocated=false
call thistype(o).deindex()
endif
else
if (filter(e[o])) then
call thistype(o).deindex()
endif
endif
else
static if thistype.index.exists then
set thistype(o).allocated=false
endif
call thistype(o).deindex()
endif
return false
endmethod
endif
static if thistype.index.exists then
static if thistype.deindex.exists then
private static method onInit takes nothing returns nothing
call RegisterUnitIndexEvent(Condition(function thistype.onIndexEvent),UnitIndexer.INDEX)
call RegisterUnitIndexEvent(Condition(function thistype.onDeindexEvent),UnitIndexer.DEINDEX)
endmethod
else
private static method onInit takes nothing returns nothing
call RegisterUnitIndexEvent(Condition(function thistype.onIndexEvent),UnitIndexer.INDEX)
endmethod
endif
elseif thistype.deindex.exists then
private static method onInit takes nothing returns nothing
call RegisterUnitIndexEvent(Condition(function thistype.onDeindexEvent),UnitIndexer.DEINDEX)
endmethod
endif
endmodule
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library PlayerManager uses /*
*/Event //hiveworkshop.com/forums/submissions-414/snippet-event-186555/
/*===================================================================
Name: Player Manager
Version: v9.0.0.0
Author: Nestharus
struct Human, Computer, ActivePlayer, InactivePlayer
static readonly thistype first
static readonly thistype last
readonly thistype next
readonly thistype previous
readonly boolean end
readonly player get
readonly integer count
//end is true when the player is null
//loop
// set myPlayer = myPlayer.next
// exitwhen myPlayer.end
//endloop
struct Players
readonly static Event LEAVE
readonly static integer eventPlayer
readonly thistype next
readonly boolean end
readonly player get
readonly static player localPlayer
readonly static integer localPlayerId
===================================================================*/
private keyword next_p
private keyword previous_p
private keyword get_p
private keyword end_p
private keyword count_p
private keyword last_p
private keyword first_p
//! textmacro REMOVE_FROM_PLAYER_STRUCT takes PLAYER_TYPE, PLAYER_ID
set $PLAYER_TYPE$.count_p = $PLAYER_TYPE$.count_p - 1
set $PLAYER_TYPE$[$PLAYER_ID$].previous_p.next_p = $PLAYER_TYPE$[$PLAYER_ID$].next_p
set $PLAYER_TYPE$[$PLAYER_ID$].next_p.previous_p = $PLAYER_TYPE$[$PLAYER_ID$].previous_p
set $PLAYER_TYPE$[$PLAYER_ID$].get_p = null
//! endtextmacro
//! textmacro ADD_TO_PLAYER_STRUCT takes PLAYER_TYPE, PLAYER_ID
set $PLAYER_TYPE$.count_p = $PLAYER_TYPE$.count_p + 1
set $PLAYER_TYPE$[16].previous_p.next_p = $PLAYER_ID$
set $PLAYER_TYPE$[$PLAYER_ID$].previous_p = $PLAYER_TYPE$[16].previous_p
set $PLAYER_TYPE$[16].previous_p = $PLAYER_ID$
set $PLAYER_TYPE$[$PLAYER_ID$].next_p = 16
set $PLAYER_TYPE$[$PLAYER_ID$].get_p = Players[$PLAYER_ID$].get
//! endtextmacro
private module Initializer
private static method onPlayerLeave takes nothing returns boolean
local integer i = GetPlayerId(GetTriggerPlayer())
local integer prev = eventPlayer
set eventPlayer = i
call FireEvent(LEAVE)
set eventPlayer = prev
//! runtextmacro REMOVE_FROM_PLAYER_STRUCT("Human", "i")
//! runtextmacro REMOVE_FROM_PLAYER_STRUCT("ActivePlayer", "i")
//! runtextmacro ADD_TO_PLAYER_STRUCT("InactivePlayer", "i")
return false
endmethod
private static method onInit takes nothing returns nothing
local integer i = 0
local trigger humanLeave = CreateTrigger()
set LEAVE = CreateEvent()
set thistype[16].end = true
set Human[16].end_p = true
set Computer[16].end_p = true
set ActivePlayer[16].end_p = true
set InactivePlayer[16].end_p = true
set Human[16].next_p = 16
set Computer[16].next_p = 16
set ActivePlayer[16].next_p = 16
set InactivePlayer[16].next_p = 16
set Human[16].previous_p = 16
set Computer[16].previous_p = 16
set ActivePlayer[16].previous_p = 16
set InactivePlayer[16].previous_p = 16
loop
set thistype[i].get = Player(i)
if (GetPlayerSlotState(thistype[i].get) == PLAYER_SLOT_STATE_PLAYING) then
//! runtextmacro ADD_TO_PLAYER_STRUCT("ActivePlayer", "i")
if (GetPlayerController(thistype[i].get) == MAP_CONTROL_USER) then
//! runtextmacro ADD_TO_PLAYER_STRUCT("Human", "i")
else
//! runtextmacro ADD_TO_PLAYER_STRUCT("Computer", "i")
endif
call TriggerRegisterPlayerEvent(humanLeave, thistype[i].get, EVENT_PLAYER_LEAVE)
else
//! runtextmacro ADD_TO_PLAYER_STRUCT("InactivePlayer", "i")
endif
set i = i + 1
set thistype[i-1].next = i
exitwhen i == 12
endloop
loop
set thistype[i].get = Player(i)
set i = i + 1
set thistype[i-1].next = i
exitwhen i == 16
endloop
if (Human.count_p > 1) then
call TriggerAddCondition(humanLeave, Condition(function thistype.onPlayerLeave))
else
call DestroyTrigger(humanLeave)
endif
set humanLeave = null
set localPlayer = GetLocalPlayer()
set localPlayerId = GetPlayerId(localPlayer)
endmethod
endmodule
struct Players extends array
readonly thistype next
readonly boolean end
readonly player get
readonly static player localPlayer
readonly static integer localPlayerId
readonly static Event LEAVE = 0
readonly static integer eventPlayer = 0
implement Initializer
endstruct
private module PlayerVars
thistype next_p
thistype previous_p
player get_p
boolean end_p
static integer count_p = 0
public method operator next takes nothing returns thistype
return next_p
endmethod
public method operator previous takes nothing returns thistype
return previous_p
endmethod
public method operator get takes nothing returns player
return get_p
endmethod
public method operator end takes nothing returns boolean
return end_p
endmethod
public static method operator count takes nothing returns integer
return count_p
endmethod
public static method operator last takes nothing returns integer
return thistype[16].previous
endmethod
public static method operator first takes nothing returns integer
return thistype[16].next
endmethod
endmodule
struct Human extends array
implement PlayerVars
endstruct
struct Computer extends array
implement PlayerVars
endstruct
struct ActivePlayer extends array
implement PlayerVars
endstruct
struct InactivePlayer extends array
implement PlayerVars
endstruct
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library WorldBounds /* v2.0.0.0
************************************************************************************
*
* struct WorldBounds extends array
*
* Fields
* -------------------------
*
* readonly static integer maxX
* readonly static integer maxY
* readonly static integer minX
* readonly static integer minY
*
* readonly static integer centerX
* readonly static integer centerY
*
* readonly static rect world
* readonly static region worldRegion
*
************************************************************************************/
private module WorldBoundInit
private static method onInit takes nothing returns nothing
set world=GetWorldBounds()
set maxX = R2I(GetRectMaxX(world))
set maxY = R2I(GetRectMaxY(world))
set minX = R2I(GetRectMinX(world))
set minY = R2I(GetRectMinY(world))
set centerX = R2I((maxX + minX)/2)
set centerY = R2I((minY + maxY)/2)
set worldRegion = CreateRegion()
call RegionAddRect(worldRegion, world)
endmethod
endmodule
struct WorldBounds extends array
readonly static integer maxX
readonly static integer maxY
readonly static integer minX
readonly static integer minY
readonly static integer centerX
readonly static integer centerY
readonly static rect world
readonly static region worldRegion
implement WorldBoundInit
endstruct
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library AutoFly /* v1.0.0.1
-Credits to Magtheridon96 and Bribe for code update
-Credits to Azlier for original
-thehelper.net/forums/showthread.php/139729-AutoFly
*************************************************************************************
*
* Makes SetUnitFlyHeight possible
*
*************************************************************************************
*
* */uses/*
*
* */ UnitIndexer /* hiveworkshop.com/forums/jass-functions-413/unit-indexer-172090/
*
************************************************************************************/
private function i takes nothing returns boolean
return UnitAddAbility(GetIndexedUnit(), 'Amrf') and UnitRemoveAbility(GetIndexedUnit(), 'Amrf')
endfunction
private module Init
private static method onInit takes nothing returns nothing
call RegisterUnitIndexEvent(Condition(function i), UnitIndexer.INDEX)
endmethod
endmodule
private struct Inits extends array
implement Init
endstruct
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library GetTerrainZ /* v1.0.0.0 */
globals
private constant location L = Location(0, 0)
endglobals
function GetTerrainZ takes real x, real y returns real
call MoveLocation(L, x, y)
return GetLocationZ(L)
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library ArrowKeyEvent /*
=========================================================================
ArrowKeyEvent version 1.0.0.1
=========================================================================
Credits:
-------------------------------------------------------------------------
- Written by Bribe.
- Earth-Fury for providing a lot of inspiration for the development of
this system (especially documentation) via his KeyAction resource.
- tooltiperror & Sgqvur for providing very helpful, constructive advice.
=========================================================================
Introduction:
-------------------------------------------------------------------------
Easy to use, efficient system for handling all arrow key events. It uses
arrays and GetHandleId lookups to avoid the trap of many cloned functions
that so many arrow key systems suffer from.
=========================================================================
API Guide:
-------------------------------------------------------------------------
To help centralize and make everything understandable, I originally used
the constants appointed by Blizzard (bj_KEYEVENTKEY_LEFT/RIGHT/etc). But
there was a lot of criticism over their ugliness so I made the following
constants to correspond accordingly. They have the same values as the BJ
constants, so you can use whichever is more appealing for you.
Their purpose is to be passed as arguments so you are able to query such
things as "is this key pressed" or simply to help make sense of what key
was pressed from an event response and interpret it as an integer.
constant integer ARROW_KEY_LEFT = 0
constant integer ARROW_KEY_RIGHT = 1
constant integer ARROW_KEY_DOWN = 2
constant integer ARROW_KEY_UP = 3
-------------------------------------------------------------------------
As I was developing this resource, is was mostly written in vanilla JASS.
I had since converted it to OOP syntax but it has been requested to bring
it back. I have made it available once again.
function IsArrowKeyPressed
takes player whichPlayer, integer arrowKey
returns boolean
To find out if the arrow key was pressed, you need to first ask which
player is holding down the key, and then pass an ARROW_KEY constant
to represent the key you are querying for.
function RegisterArrowKeyEvent
takes code onEvent
returns nothing
Instead of making up to 8 different functions for 8 different events,
you can use this instead. Just specify a function that you want to be
called whenever any key is pressed. For event responses, reference 1
of the following 3 functions:
function GetEventArrowKeyPlayerId
takes nothing
returns integer
This is more of an optimization benefit than not. GetTriggerPlayer()
will get you the player who pressed the key, but most of the time you
just need to know the player ID of that person.
function GetEventArrowKey
takes nothing
returns integer
Call this function to find out which key was pressed. It will return
one of the four ARROW_KEY constants, of course.
function IsEventArrowKeyPressed
takes nothing
returns boolean
This is also here more for optimization's benefit. You can certainly
use "IsArrowKeyPressed(GetEventArrowKey(GetEventArrowKeyPlayerId()))"
but this is much more convenient I must say.
-------------------------------------------------------------------------
"implement ArrowKey"
ArrowKey API is accessible as if it were part of the implementing struct
itself. As a bonus, you can create a method "onArrowKeyEvent" that gets
called automatically when any key is pressed. The method musn't be static,
because the member "this" is a player ID (to mirror the ArrowKey struct's
own API). It must take an integer as its first argument to represent the
pressed or released key. As a final argument, it must take a boolean to
determine if the key was pressed (true) or released (false).
The member "this" taken by the method is a player ID.
*/
//=======================================================================
//
// System Code
//
//=======================================================================
globals
//-------------------------------------------------------------------
// Yo dawg, I herd you like constant variables so I gave you some new
// constant variables so you can have some constant variables to go
// with Blizzard's constant variables.
//
constant integer ARROW_KEY_LEFT = bj_KEYEVENTKEY_LEFT
constant integer ARROW_KEY_RIGHT = bj_KEYEVENTKEY_RIGHT
constant integer ARROW_KEY_DOWN = bj_KEYEVENTKEY_DOWN
constant integer ARROW_KEY_UP = bj_KEYEVENTKEY_UP
endglobals
//=======================================================================
// Ugly modules are needed to prevent initialization bugs.
//
private module Init
private static method onInit takes nothing returns nothing
local player p
local integer i = 12
local trigger t = .trig
loop
set i = i - 1
set p = Player(i)
if GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(p) == MAP_CONTROL_USER then
//Register arrow key events for playing players
call TriggerRegisterPlayerEvent(t, p, EVENT_PLAYER_ARROW_LEFT_DOWN)
call TriggerRegisterPlayerEvent(t, p, EVENT_PLAYER_ARROW_LEFT_UP)
call TriggerRegisterPlayerEvent(t, p, EVENT_PLAYER_ARROW_RIGHT_DOWN)
call TriggerRegisterPlayerEvent(t, p, EVENT_PLAYER_ARROW_RIGHT_UP)
call TriggerRegisterPlayerEvent(t, p, EVENT_PLAYER_ARROW_DOWN_DOWN)
call TriggerRegisterPlayerEvent(t, p, EVENT_PLAYER_ARROW_DOWN_UP)
call TriggerRegisterPlayerEvent(t, p, EVENT_PLAYER_ARROW_UP_DOWN)
call TriggerRegisterPlayerEvent(t, p, EVENT_PLAYER_ARROW_UP_UP)
//Run if library ArrowKey is found in the map.
//! runtextmacro optional INIT_ARROW_KEY_AA()
endif
exitwhen i == 0
endloop
//Run if library ArrowKey is found in the map.
//! runtextmacro optional INIT_ARROW_KEY_CALL_LINK()
call .registerEvent(function ArrowKey.actions)
set p = null
set t = null
endmethod
endmodule
//=======================================================================
// A central struct to handle all ArrowKey mechanics. This has its uses,
// giving you slightly more control over the inner system functionality.
//
struct ArrowKey extends array
//-------------------------------------------------------------------
// Event responses
//
readonly static integer eventKey = 0 //Arrow key that triggered the event.
readonly static boolean eventKeyPressed = false //Was the arrow key pressed?
readonly static ArrowKey eventPlayerId = 0 //The id of the player who pressed the key.
//Run if library ArrowKey is found in the map.
//! runtextmacro optional ARROW_KEY_DECLARE_ARRAYS()
//-------------------------------------------------------------------
// System variables
//
private static trigger trig = CreateTrigger() //Handles all events.
private static boolean array press //Is key pressed?
//===================================================================
// User-friendly typecasting.
//
static method operator [] takes player who returns ArrowKey
return GetPlayerId(who)
endmethod
//===================================================================
// Great for simplifying arrow key events - this function runs when
// any player presses or releases an arrow key. The code passed is
// expected to "return false".
//
static method registerEvent takes code onEvent returns nothing
call TriggerAddCondition(.trig, Filter(onEvent))
return
endmethod
//===================================================================
// Returns true if the key is pressed, false if it is released.
//
method isPressed takes integer arrow returns boolean
return press[this + arrow * 12]
endmethod
//Run if library ArrowKey is found in the map.
//! runtextmacro optional ARROW_KEY_AXIS_METHODS()
//===================================================================
// If you are running debug tests, this might come in handy.
//
static if DEBUG_MODE then
static method getKeyName takes integer arrow returns string
if arrow == ARROW_KEY_LEFT then
return "LEFT"
elseif arrow == ARROW_KEY_RIGHT then
return "RIGHT"
elseif arrow == ARROW_KEY_DOWN then
return "DOWN"
elseif arrow == ARROW_KEY_UP then
return "UP"
endif
return "--"
endmethod
endif
//===================================================================
//
// Private Components
//
//===================================================================
//===================================================================
// Key event handler.
//
private static method actions takes nothing returns nothing
local integer id = GetHandleId(GetTriggerEventId()) - 261
set .eventPlayerId = GetPlayerId(GetTriggerPlayer())
//If id is an even number, the key was pressed.
set .eventKey = id / 2
set .eventKeyPressed = .eventKey * 2 == id
set .press[.eventPlayerId + .eventKey * 12] = .eventKeyPressed
//Run if library ArrowKey is found in the map.
//! runtextmacro optional ARROW_KEY_SETUP()
endmethod
//Run if library ArrowKey is found in the map.
//! runtextmacro optional INIT_ARROW_KEY_LINK()
//Initialize the system via module
implement Init
endstruct
//=======================================================================
//
// Event Responses
//
//=======================================================================
//=======================================================================
function IsArrowKeyPressed takes player whichPlayer, integer arrowKey returns boolean
return ArrowKey[whichPlayer].isPressed(arrowKey)
endfunction
//=======================================================================
function RegisterArrowKeyEvent takes code onEvent returns nothing
call ArrowKey.registerEvent(onEvent)
endfunction
//=======================================================================
function GetEventArrowKeyPlayerId takes nothing returns integer
return ArrowKey.eventPlayerId
endfunction
//=======================================================================
function GetEventArrowKey takes nothing returns integer
return ArrowKey.eventKey
endfunction
//=======================================================================
function IsEventArrowKeyPressed takes nothing returns boolean
return ArrowKey.eventKeyPressed
endfunction
//=======================================================================
// Implementation of this module allows you to make your struct "extend"
// the ArrowKey struct. As a bonus feature, you can create a method named
// "onArrowKeyEvent" that is called whenever a key is pressed or released.
// The method needs "takes integer arrow, boolean pressed", and must be
// positioned *above* the "implement ArrowKey" statement (this way it is
// detected by the static if and doesn't compile to a function interface).
//
module ArrowKey
//Delegates are fun, you should try them out.
private delegate ArrowKey AK
//===================================================================
// Please call this method from *below the module implement statement
// if you know what's good for you.
//
static method operator [] takes player who returns thistype
return GetPlayerId(who)
endmethod
static if thistype.onArrowKeyEvent.exists then
private static method eventProxy takes nothing returns nothing
call thistype(.eventPlayerId).onArrowKeyEvent(.eventKey, .eventKeyPressed)
endmethod
endif
private static method onInit takes nothing returns nothing
local thistype i = 12
loop
set i = i - 1
set i.AK = i //Delegates require some delegation of course.
exitwhen i == 0
endloop
static if thistype.onArrowKeyEvent.exists then
call ArrowKey.registerEvent(function thistype.eventProxy)
endif
endmethod
endmodule
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
/* Created by DeathChef
module ArrowKeyEvent_PlayerRegister v1.0.0.0
Description
Extension of Bribes [System] ArrowKeyEvent
Allows players to be removed and added to any arrow
key event system with the use of implementing this
module and Bribes [System] ArrowKeyEvent
Use with
[System] ArrowKeyEvent http://www.hiveworkshop.com/forums/jass-resources-412/system-arrowkeyevent-205650/
Methods
static method AddArrowKeysPlayerId takes thistype PlayerId returns nothing
static method RemoveArrowKeysPlayerId takes thistype PlayerId returns nothing
static method AddArrowKeysAllPlayers takes nothing returns nothing
static method RemoveArrowKeysAllPlayers takes nothing returns nothing
Fields
boolean IsPlayerRegistered
How to use
Check out the demo for a code example
1. Implement ArrowKeyEvent_PlayerRegister along side with the ArrowKey module
2. Within your onArrowKeyEvent method create as the first ITE line as
if thistype(.eventPlayerId).IsPlayerRegistered then
//code body
endif
3. Use the custom methods that come with the module
*/
module ArrowKeyEvent_PlayerRegister
boolean IsPlayerRegistered
static method AddArrowKeysPlayerId takes thistype PlayerId returns nothing
set PlayerId.IsPlayerRegistered = GetPlayerSlotState(Player(PlayerId)) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(Player(PlayerId)) == MAP_CONTROL_USER
endmethod
static method RemoveArrowKeysPlayerId takes thistype PlayerId returns nothing
set PlayerId.IsPlayerRegistered = false
endmethod
static method AddArrowKeysAllPlayers takes nothing returns nothing
local thistype this = 11
loop
set IsPlayerRegistered = GetPlayerSlotState(Player(this)) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(Player(this)) == MAP_CONTROL_USER
exitwhen this == 0
set this = this - 1
endloop
endmethod
static method RemoveArrowKeysAllPlayers takes nothing returns nothing
local thistype this = 11
loop
set IsPlayerRegistered = false
exitwhen this == 0
set this = this - 1
endloop
endmethod
endmodule
//TESH.scrollpos=0
//TESH.alwaysfold=0
library Movement /*
*/ uses /*
*/ SystemUnit /*
*/ PinSector /*
struct Movement extends array
Description
Core periodic event for getting units attached to system,
checking if any object is blocking their path and settings
that units coordinates to appropriate position.
Modules
ObjectFuncs
Objects
Options
*/
//! textmacro MOVEMENT_SETTINGS
//See Settings under Manual
implement Movement_Settings
//! endtextmacro
/*
Methods
static method Start takes nothing returns nothing
static method Stop takes nothing returns nothing
*/
struct Movement extends array
//! runtextmacro MOVEMENT_SETTINGS()
private static real NewX
private static real NewY
private static real NewZ
private static real NewAir
private static real RedeclairX
private static real RedeclairY
private static real RedeclairZ
private static real RedeclairAir
//! runtextmacro Movement_Rectangle3DCollision()
//! runtextmacro Movement_Circle2DCollision()
private static method Execute takes nothing returns nothing
local SystemUnit this = SystemUnit.Count
local integer Sector
local integer Object
loop
exitwhen this == 0
set NewAir = this.AirTime - SystemUnit[this].DropRate
set NewX = this.X + this.Distance * Cos(Deg2Rad(this.Facing))
set NewY = this.Y + this.Distance * Sin(Deg2Rad(this.Facing))
if this.Z + NewAir <= GetTerrainZ(this.X, this.Y) then
set NewZ = GetTerrainZ(NewX, NewY)
set RedeclairAir = 0
set this.CanJump = true
else
set NewZ = this.Z + NewAir
set RedeclairAir = NewAir
set this.CanJump = false
endif
set RedeclairX = NewX
set RedeclairY = NewY
set RedeclairZ = NewZ
call thistype.Rectangle3D(this)
call thistype.Circle2D(this)
set this.X = RedeclairX
set this.Y = RedeclairY
set this.Z = RedeclairZ
set this.AirTime = RedeclairAir
set this.Facing = ModuloReal(this.Facing + this.Angle, 360)
call SetUnitX(this.Unit, RedeclairX)
call SetUnitY(this.Unit, RedeclairY)
call SetUnitFlyHeight(this.Unit, RedeclairZ - GetTerrainZ(RedeclairX, RedeclairY), 0)
call SetUnitFacing(this.Unit, this.Facing)
set this = this - 1
endloop
endmethod
implement Movement_Initializers
endstruct
module Movement_Initializers
private static timer PeriodicTimer = null
static method Start takes nothing returns nothing
if PeriodicTimer == null then
set PeriodicTimer = CreateTimer()
call TimerStart(PeriodicTimer, PERIODIC_CHECK, true, function thistype.Execute)
endif
endmethod
static method Stop takes nothing returns nothing
if PeriodicTimer != null then
call DestroyTimer(PeriodicTimer)
set PeriodicTimer = null
endif
endmethod
private static method onInit takes nothing returns nothing
call Start()
endmethod
endmodule
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library SystemUnit /*
*/ uses /*
*/ GetTerrainZ /*
/ Jump /
/ Camera /
/ Arrow /
struct SystemUnit extends array
Description
Core of units attached to the system containing the variables
of those units, the initializers for attaching them and attaching
methods to them. Detaches any unit on death.
Settings
*/
//! textmacro SYSTEMUNIT_SETTINGS
//See Settings under Manual
implement SystemUnit_Settings
//! endtextmacro
/*
Fields
static integer Count
unit Unit
integer UserData
integer Index
boolean Attached
player User
integer UserId
real X
real Y
real Z
real Facing
real Height
real Width
real Distance
real Angle
real AirTime
boolean CanJump
real DropRate
real InitialJumpRate
real StopSpeed
real WalkSpeed
real WalkStraightSpeed
real TurnSpeed
integer AnimationIndexWalk
integer AnimationIndexStand
real AnimationSpeedWalkForward
real AnimationSpeedWalkBackward
real AnimationSpeedTurnOnSpot
//-
static integer TypeIdCount
hashtable TypeIdIndex
real TypeIdDropRate
real TypeIdInitialJumpRate
real TypeIdStopSpeed
real TypeIdWalkSpeed
real TypeIdWalkStraightSpeed
real TypeIdTurnSpeed
integer TypeIdAnimationIndexWalk
integer TypeIdAnimationIndexStand
real TypeIdAnimationSpeedWalkForward
real TypeIdAnimationSpeedWalkBackward
real TypeIdAnimationSpeedTurnOnSpot
Methods
static method init takes unit u, real uWidth, real uHeight returns thistype
static method deinit takes thistype this returns nothing
/
static method AttachAll takes unit u returns nothing
static method AttachAllInterface takes unit u, integer UnitInterfaceId returns nothing
static method AttachUnit takes unit u returns nothing
static method AttachCamera takes unit u returns nothing
static method AttachInterface takes unit u, integer UnitInterfaceId returns nothing
static method AttachArrow takes unit u returns nothing
static method DetachUnit takes unit u returns nothing
static method DetachCamera takes unit u returns nothing
static method DetachInterface takes unit u returns nothing
static method DetachArrow takes unit u returns nothing
/
static method GetTypeIdHeight takes integer UnitTypeId returns real
static method GetTypeIdWidth takes integer UnitTypeId returns real
static method GetTypeIdDropRate takes integer UnitTypeId returns real
static method GetTypeIdInitialJumpRate takes integer UnitTypeId returns real
static method GetTypeIdStopSpeed takes integer UnitTypeId returns real
static method GetTypeIdWalkSpeed takes integer UnitTypeId returns real
static method GetTypeIdWalkStraightSpeed takes integer UnitTypeId returns real
static method GetTypeIdTurnSpeed takes integer UnitTypeId returns real
static method GetTypeIdAnimationIndexWalk takes integer UnitTypeId returns integer
static method GetTypeIdAnimationIndexStand takes integer UnitTypeId returns integer
static method GetTypeIdAnimationSpeedWalkForward takes integer UnitTypeId returns real
static method GetTypeIdAnimationSpeedWalkBackward takes integer UnitTypeId returns real
static method GetTypeIdAnimationSpeedTurnOnSpot takes integer UnitTypeId returns real
static method SetTypeIdHeight takes integer UnitTypeId, real h returns nothing
static method SetTypeIdWidth takes integer UnitTypeId, real w returns nothing
static method SetTypeIdDropRate takes integer UnitTypeId, real dr returns nothing
static method SetTypeIdInitialJumpRate takes integer UnitTypeId, real ijr returns nothing
static method SetTypeIdStopSpeed takes integer UnitTypeId, real ss returns nothing
static method SetTypeIdWalkSpeed takes integer UnitTypeId, real ws returns nothing
static method SetTypeIdWalkStraightSpeed takes integer UnitTypeId, real wsp returns nothing
static method SetTypeIdTurnSpeed takes integer UnitTypeId, real h returns nothing
static method SetTypeIdAnimationIndexWalk takes integer UnitTypeId, real aiw returns nothing
static method SetTypeIdAnimationIndexStand takes integer UnitTypeId, real ais returns nothing
static method SetTypeIdAnimationSpeedWalkForward takes integer UnitTypeId, real aswf returns nothing
static method SetTypeIdAnimationSpeedWalkBackward takes integer UnitTypeId, real aswb returns nothing
static method SetTypeIdAnimationSpeedTurnOnSpot takes integer UnitTypeId, real aston returns nothing
/
static method GetX takes unit u returns real
static method GetY takes unit u returns real
static method GetZ takes unit u returns real
static method GetFlyHeight takes unit u returns real
static method GetFacing takes unit u returns real
static method GetHeight takes unit u returns real
static method GetWidth takes unit u returns real
static method GetDropRate takes unit u returns real
static method GetInitialJumpRate takes unit u returns real
static method GetStopSpeed takes unit u returns real
static method GetWalkSpeed takes unit u returns real
static method GetWalkStraightSpeed takes unit u returns real
static method GetTurnSpeed takes unit u returns real
static method GetAnimationIndexWalk takes unit u returns integer
static method GetAnimationIndexStand takes unit u returns integer
static method GetAnimationSpeedWalkForward takes unit u returns real
static method GetAnimationSpeedWalkBackward takes unit u returns real
static method GetAnimationSpeedTurnOnSpot takes unit u returns real
static method SetXYZFacing takes unit u, real x, real y, real z, real f returns nothing
static method SetXYFlyHeightFacing takes unit u, real x, real y, real z, real f returns nothing
static method SetXYZ takes unit u, real x, real y, real z returns nothing
static method SetXYFlyHeight takes unit u, real x, real y, real z returns nothing
static method SetXYFacing takes unit u, real x, real y, real f returns nothing
static method SetXY takes unit u, real x, real y returns nothing
static method SetX takes unit u, real x returns nothing
static method SetY takes unit u, real y returns nothing
static method SetZ takes unit u, real z returns nothing
static method SetFlyHeight takes unit u, real z returns nothing
static method SetFacing takes unit u, real f returns nothing
static method SetHeight takes unit u, real h returns nothing
static method SetWidth takes unit u, real w returns nothing
static method SetDropRate takes unit u, real dr returns nothing
static method SetInitialJumpRate takes unit u, real ijr returns nothing
static method SetStopSpeed takes unit u, real ss returns nothing
static method SetWalkSpeed takes unit u, real ws returns nothing
static method SetWalkStraightSpeed takes unit u, real wsp returns nothing
static method SetTurnSpeed takes unit u, real h returns nothing
static method SetAnimationIndexWalk takes unit u, integer aiw returns nothing
static method SetAnimationIndexStand takes unit u, integer ais returns nothing
static method SetAnimationSpeedWalkForward takes unit u, real aswf returns nothing
static method SetAnimationSpeedWalkBackward takes unit u, real aswb returns nothing
static method SetAnimationSpeedTurnOnSpot takes unit u, real aston returns nothing
*/
struct SystemUnit extends array
static integer Count = 0
unit Unit
integer UserData
integer Index
boolean Attached
player User
integer UserId
real X
real Y
real Z
real Facing
real Distance
real Angle
real AirTime
//! runtextmacro SYSTEMUNIT_SETTINGS()
boolean CanJump
//--
real Height
real Width
real DropRate
real InitialJumpRate
real StopSpeed
real WalkSpeed
real WalkStraightSpeed
real TurnSpeed
integer AnimationIndexWalk
integer AnimationIndexStand
real AnimationSpeedWalkForward
real AnimationSpeedWalkBackward
real AnimationSpeedTurnOnSpot
//-
static integer TypeIdCount = 0
static hashtable TypeIdIndex = InitHashtable()
real TypeIdHeight
real TypeIdWidth
real TypeIdDropRate
real TypeIdInitialJumpRate
real TypeIdStopSpeed
real TypeIdWalkSpeed
real TypeIdWalkStraightSpeed
real TypeIdTurnSpeed
integer TypeIdAnimationIndexWalk
integer TypeIdAnimationIndexStand
real TypeIdAnimationSpeedWalkForward
real TypeIdAnimationSpeedWalkBackward
real TypeIdAnimationSpeedTurnOnSpot
//--
implement SystemUnit_Initializers
implement SystemUnit_AttachmentMethods
implement SystemUnit_DetachmentMethods
implement optional SystemUnit_SetUnitData
endstruct
module SystemUnit_AttachmentMethods
static method AttachAll takes unit u returns nothing
local thistype this = init(u)
call Camera.init(this)
call Arrow.init(this)
endmethod
static method AttachAllInterface takes unit u, integer Id returns nothing
local thistype this = init(u)
call Camera.init(this)
call Interface.init(this, Id)
call Arrow.init(this)
endmethod
static method AttachUnit takes unit u returns nothing
call init(u)
endmethod
static method AttachInterface takes unit u, integer Id returns nothing
call Interface.init(thistype[GetUnitUserData(u)].Index, Id)
endmethod
static method AttachCamera takes unit u returns nothing
call Camera.init(thistype[GetUnitUserData(u)].Index)
endmethod
static method AttachArrow takes unit u returns nothing
call Arrow.init(thistype[GetUnitUserData(u)].Index)
endmethod
endmodule
module SystemUnit_DetachmentMethods
static method DetachUnit takes unit u returns nothing
call deinit(thistype[GetUnitUserData(u)].UserData)
endmethod
static method DetachInterface takes unit u returns nothing
call Interface.deinit(thistype[GetUnitUserData(u)].UserData)
endmethod
static method DetachArrow takes unit u returns nothing
call Arrow.deinit(thistype[GetUnitUserData(u)].UserData)
endmethod
static method DetachCamera takes unit u returns nothing
call Camera.deinit(thistype[GetUnitUserData(u)].UserData)
endmethod
private static method DeathDetach takes nothing returns nothing
call deinit(thistype[GetUnitUserData(GetTriggerUnit())].UserData)
endmethod
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerAddAction(t, function thistype.DeathDetach)
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH)
set t = null
endmethod
endmodule
module SystemUnit_GetSetUnitTypeIdData
//! textmacro GetUnitTypeIdData takes TYPE, VARIABLE
static method GetTypeId$VARIABLE$ takes integer UnitTypeId returns $TYPE$
return thistype[LoadInteger(TypeIdIndex, 0, UnitTypeId)].TypeId$VARIABLE$
endmethod
//! endtextmacro
//! runtextmacro GetUnitTypeIdData("real", "Height")
//! runtextmacro GetUnitTypeIdData("real", "Width")
//! runtextmacro GetUnitTypeIdData("real", "DropRate")
//! runtextmacro GetUnitTypeIdData("real", "InitialJumpRate")
//! runtextmacro GetUnitTypeIdData("real", "StopSpeed")
//! runtextmacro GetUnitTypeIdData("real", "WalkSpeed")
//! runtextmacro GetUnitTypeIdData("real", "WalkStraightSpeed")
//! runtextmacro GetUnitTypeIdData("real", "TurnSpeed")
//! runtextmacro GetUnitTypeIdData("integer", "AnimationIndexWalk")
//! runtextmacro GetUnitTypeIdData("integer", "AnimationIndexStand")
//! runtextmacro GetUnitTypeIdData("real", "AnimationSpeedWalkForward")
//! runtextmacro GetUnitTypeIdData("real", "AnimationSpeedWalkBackward")
//! runtextmacro GetUnitTypeIdData("real", "AnimationSpeedTurnOnSpot")
//--
//! textmacro SetUnitTypeIdData takes TYPE, VARIABLE, NMBR
static method SetTypeId$VARIABLE$ takes integer UnitTypeId, $TYPE$ $NMBR$ returns nothing
local thistype i = LoadInteger(TypeIdIndex, 0, UnitTypeId)
if i == 0 then
set i = TypeIdCount + 1
set TypeIdCount = i
call SaveInteger(TypeIdIndex, 0, UnitTypeId, i)
endif
set i.TypeId$VARIABLE$ = $NMBR$
endmethod
//! endtextmacro
//! runtextmacro SetUnitTypeIdData("real", "Height", "h")
//! runtextmacro SetUnitTypeIdData("real", "Width", "w")
//! runtextmacro SetUnitTypeIdData("real", "DropRate", "dr")
//! runtextmacro SetUnitTypeIdData("real", "InitialJumpRate", "ijr")
//! runtextmacro SetUnitTypeIdData("real", "StopSpeed", "ss")
//! runtextmacro SetUnitTypeIdData("real", "WalkSpeed", "ws")
//! runtextmacro SetUnitTypeIdData("real", "WalkStraightSpeed", "wss")
//! runtextmacro SetUnitTypeIdData("real", "TurnSpeed", "ts")
//! runtextmacro SetUnitTypeIdData("integer", "AnimationIndexWalk", "aiw")
//! runtextmacro SetUnitTypeIdData("integer", "AnimationIndexStand", "ais")
//! runtextmacro SetUnitTypeIdData("real", "AnimationSpeedWalkForward", "aswf")
//! runtextmacro SetUnitTypeIdData("real", "AnimationSpeedWalkBackward", "aswb")
//! runtextmacro SetUnitTypeIdData("real", "AnimationSpeedTurnOnSpot", "astos")
endmodule
module SystemUnit_GetSetUnitData
//! textmacro GetUnitData takes TYPE, VARIABLE
static method Get$VARIABLE$ takes unit u returns $TYPE$
return thistype[thistype[GetUnitUserData(u)].UserData].$VARIABLE$
endmethod
//! endtextmacro
//! runtextmacro GetUnitData("real", "X")
//! runtextmacro GetUnitData("real", "Y")
//! runtextmacro GetUnitData("real", "Z")
static method GetFlyHeight takes unit u returns real
local thistype this = thistype[GetUnitUserData(u)].UserData
return Z - GetTerrainZ(X, Y)
endmethod
//! runtextmacro GetUnitData("real", "Facing")
//! runtextmacro GetUnitData("real", "Height")
//! runtextmacro GetUnitData("real", "Width")
//! runtextmacro GetUnitData("real", "DropRate")
//! runtextmacro GetUnitData("real", "InitialJumpRate")
//! runtextmacro GetUnitData("real", "StopSpeed")
//! runtextmacro GetUnitData("real", "WalkSpeed")
//! runtextmacro GetUnitData("real", "WalkStraightSpeed")
//! runtextmacro GetUnitData("real", "TurnSpeed")
//! runtextmacro GetUnitData("integer", "AnimationIndexWalk")
//! runtextmacro GetUnitData("integer", "AnimationIndexStand")
//! runtextmacro GetUnitData("real", "AnimationSpeedWalkForward")
//! runtextmacro GetUnitData("real", "AnimationSpeedWalkBackward")
//! runtextmacro GetUnitData("real", "AnimationSpeedTurnOnSpot")
//--
static method SetXYZFacing takes unit u, real x, real y, real z, real f returns nothing
local thistype this = thistype[GetUnitUserData(u)].UserData
set this.X = x
set this.Y = y
set this.Z = z
set this.Facing = ModuloReal(f, 360)
call SetUnitX(this.Unit, x)
call SetUnitY(this.Unit, y)
call SetUnitFlyHeight(this.Unit, z - GetTerrainZ(x, y), 0)
call SetUnitFacing(this.Unit, this.Facing)
endmethod
static method SetXYFlyHeightFacing takes unit u, real x, real y, real z, real f returns nothing
local thistype this = thistype[GetUnitUserData(u)].UserData
set this.X = x
set this.Y = y
set this.Z = z + GetTerrainZ(x, y)
set this.Facing = ModuloReal(f, 360)
call SetUnitX(this.Unit, x)
call SetUnitY(this.Unit, y)
call SetUnitFlyHeight(this.Unit, z, 0)
call SetUnitFacing(this.Unit, this.Facing)
endmethod
static method SetXYZ takes unit u, real x, real y, real z returns nothing
local thistype this = thistype[GetUnitUserData(u)].UserData
set this.X = x
set this.Y = y
set this.Z = z
call SetUnitX(this.Unit, x)
call SetUnitY(this.Unit, y)
call SetUnitFlyHeight(this.Unit, z - GetTerrainZ(x, y), 0)
endmethod
static method SetXYFlyHeight takes unit u, real x, real y, real z returns nothing
local thistype this = thistype[GetUnitUserData(u)].UserData
set this.X = x
set this.Y = y
set this.Z = z + GetTerrainZ(x, y)
call SetUnitX(this.Unit, x)
call SetUnitY(this.Unit, y)
call SetUnitFlyHeight(this.Unit, z, 0)
endmethod
static method SetXYFacing takes unit u, real x, real y, real facing returns nothing
local thistype this = thistype[GetUnitUserData(u)].UserData
set this.X = x
set this.Y = y
set this.Facing = ModuloReal(facing, 360)
call SetUnitX(this.Unit, x)
call SetUnitY(this.Unit, y)
call SetUnitFacing(this.Unit, this.Facing)
endmethod
static method SetXY takes unit u, real x, real y returns nothing
local thistype this = thistype[GetUnitUserData(u)].UserData
set this.X = x
set this.Y = y
call SetUnitX(this.Unit, x)
call SetUnitY(this.Unit, y)
endmethod
static method SetFacing takes unit u, real f returns nothing
local thistype this = thistype[GetUnitUserData(u)].UserData
set this.Facing = ModuloReal(f, 360)
call SetUnitFacing(this.Unit, this.Facing)
endmethod
static method SetX takes unit u, real x returns nothing
local thistype this = thistype[GetUnitUserData(u)].UserData
set this.X = x
call SetUnitX(this.Unit, x)
endmethod
static method SetY takes unit u, real y returns nothing
local thistype this = thistype[GetUnitUserData(u)].UserData
set this.Y = y
call SetUnitY(this.Unit, y)
endmethod
static method SetZ takes unit u, real z returns nothing
local thistype this = thistype[GetUnitUserData(u)].UserData
set this.Z = z
call SetUnitFlyHeight(this.Unit, z - GetTerrainZ(X, Y), 0)
endmethod
static method SetFlyHeight takes unit u, real z returns nothing
local thistype this = thistype[GetUnitUserData(u)].UserData
set this.Z = z + GetTerrainZ(Z, Y)
call SetUnitFlyHeight(this.Unit, z, 0)
endmethod
//! textmacro SetUnitData takes TYPE, VARIABLE, NMBR
static method Set$VARIABLE$ takes unit u, $TYPE$ $NMBR$ returns nothing
set thistype[thistype[GetUnitUserData(u)].UserData].$VARIABLE$ = $NMBR$
endmethod
//! endtextmacro
//! runtextmacro SetUnitData("real", "Height", "h")
//! runtextmacro SetUnitData("real", "Width", "w")
//! runtextmacro SetUnitData("real", "DropRate", "dr")
//! runtextmacro SetUnitData("real", "InitialJumpRate", "ijr")
//! runtextmacro SetUnitData("real", "StopSpeed", "ss")
//! runtextmacro SetUnitData("real", "WalkSpeed", "ws")
//! runtextmacro SetUnitData("real", "WalkStraightSpeed", "wss")
//! runtextmacro SetUnitData("real", "TurnSpeed", "ts")
//! runtextmacro SetUnitData("integer", "AnimationIndexWalk", "aiw")
//! runtextmacro SetUnitData("integer", "AnimationIndexStand", "ais")
//! runtextmacro SetUnitData("real", "AnimationSpeedWalkForward", "aswf")
//! runtextmacro SetUnitData("real", "AnimationSpeedWalkBackward", "aswb")
//! runtextmacro SetUnitData("real", "AnimationSpeedTurnOnSpot", "astos")
endmodule
module SystemUnit_Initializers
static method init takes unit u returns thistype
local thistype this = Count + 1
local thistype thisData = GetUnitUserData(u)
if thistype[thisData].Attached then
return thisData.Index
else
set Count = this
set Unit = u
set UserData = thisData
set thisData.Index = this
set thisData.Attached = true
//--
set User = GetOwningPlayer(u)
set UserId = GetPlayerId(User)
set X = GetUnitX(u)
set Y = GetUnitY(u)
set Z = GetUnitFlyHeight(u) + GetTerrainZ(X, Y)
set Facing = GetUnitFacing(u)
//--
set thisData = LoadInteger(TypeIdIndex, 0, GetUnitTypeId(u))
set Width = thisData.TypeIdWidth
set Height = thisData.TypeIdHeight
set DropRate = thisData.TypeIdDropRate
set InitialJumpRate = thisData.TypeIdInitialJumpRate
set StopSpeed = thisData.TypeIdStopSpeed
set WalkSpeed = thisData.TypeIdWalkSpeed
set WalkStraightSpeed = thisData.TypeIdWalkStraightSpeed
set TurnSpeed = thisData.TypeIdTurnSpeed
set AnimationIndexWalk = thisData.TypeIdAnimationIndexWalk
set AnimationIndexStand = thisData.TypeIdAnimationIndexStand
set AnimationSpeedWalkForward = thisData.TypeIdAnimationSpeedWalkForward
set AnimationSpeedWalkBackward = thisData.TypeIdAnimationSpeedWalkBackward
set AnimationSpeedTurnOnSpot = thisData.TypeIdAnimationSpeedTurnOnSpot
//--
return this
endif
endmethod
static method deinit takes thistype this returns nothing
local thistype Count = thistype.Count
local thistype thisData = UserData
if thisData.Index > 0 then
call SetUnitFlyHeight(Unit, GetUnitDefaultFlyHeight(Unit), 0)
//--
call Camera.deinit(this)
set UserData = 0
set thisData.Index = 0
set thisData.Attached = false
if this == Count then
set Unit = null
set User = null
else
call Interface.deinit2(this, Count)
set Unit = Count.Unit
set Count.Unit = null
set UserData = Count.UserData
set Count.UserData = 0
set thisData.Index = thistype[Count.UserData].Index
set thistype[Count.UserData].Index = 0
set User = Count.User
set Count.User = null
set X = Count.X
set Y = Count.Y
set Z = Count.Z
set Facing = Count.Facing
//--
set Width = Count.Width
set Height = Count.Height
set DropRate = Count.DropRate
set InitialJumpRate = Count.InitialJumpRate
set StopSpeed = Count.StopSpeed
set WalkSpeed = Count.WalkSpeed
set WalkStraightSpeed = Count.WalkStraightSpeed
set TurnSpeed = Count.TurnSpeed
set AnimationIndexWalk = Count.AnimationIndexWalk
set AnimationIndexStand = Count.AnimationIndexStand
set AnimationSpeedWalkForward = Count.AnimationSpeedWalkForward
set AnimationSpeedWalkBackward = Count.AnimationSpeedWalkBackward
set AnimationSpeedTurnOnSpot = Count.AnimationSpeedTurnOnSpot
//--
endif
set thistype.Count = Count - 1
endif
endmethod
private static method onInit takes nothing returns nothing
set thistype[0].TypeIdWidth = WIDTH
set thistype[0].TypeIdHeight = HEIGHT
set thistype[0].TypeIdDropRate = DROP_RATE
set thistype[0].TypeIdInitialJumpRate = Jump.INITIAL_JUMP_RATE
set thistype[0].TypeIdStopSpeed = Arrow.STOP_SPEED
set thistype[0].TypeIdWalkSpeed = Arrow.WALK_SPEED
set thistype[0].TypeIdWalkStraightSpeed = Arrow.WALK_STRAIGHT_SPEED
set thistype[0].TypeIdTurnSpeed = Arrow.TURN_SPEED
set thistype[0].TypeIdAnimationIndexWalk = Arrow.ANIMATION_INDEX_WALK
set thistype[0].TypeIdAnimationIndexStand = Arrow.ANIMATION_INDEX_STAND
set thistype[0].TypeIdAnimationSpeedWalkForward = Arrow.ANIMATION_SPEED_WALK_FORWARD
set thistype[0].TypeIdAnimationSpeedWalkBackward = Arrow.ANIMATION_SPEED_WALK_BACKWARD
set thistype[0].TypeIdAnimationSpeedTurnOnSpot = Arrow.ANIMATION_SPEED_TURN_ON_SPOT
endmethod
endmodule
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library Jump /*
*/ uses /*
*/ SystemUnit /*
struct Jump extends array
Description
For any unit that is attached to this system and uses the
Jump ability will execute to change that units velocity.
Settings
*/
//! textmacro JUMP_SETTINGS
//See Settings under Manual
implement Jump_Settings
//! endtextmacro
/*
*/
struct Jump extends array
//! runtextmacro JUMP_SETTINGS()
private static method IsJump takes nothing returns boolean
return GetSpellAbilityId() == JUMP
endmethod
private static method Execute takes nothing returns nothing
local SystemUnit this = GetUnitUserData(GetTriggerUnit())
if this.Attached then
set this = this.Index
elseif Interface[this].Attached then
set this = Interface[this].Index
else
return
endif
if this.CanJump then
set this.AirTime = SystemUnit[this].InitialJumpRate
endif
endmethod
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerAddAction(t, function thistype.Execute)
call TriggerAddCondition(t, Condition(function thistype.IsJump))
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_CAST)
set t = null
endmethod
endstruct
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library Camera /*
*/ uses /*
*/ SystemUnit /*
*/ PlayerManager /*
struct Camera extends array
Description
Attaches the owner of a unit's camera to the unit.
Is a requirment for Arrow commands and Unit interface.
Settings
*/
//! textmacro CAMERA_SETTINGS
//See Settings under Manual
implement Camera_Settings
//! endtextmacro
/*
Fields
//Local player attachment values
static boolean LocalPlayerAttached = false
static integer LocalAttachedIndex
unit Unit
Methods
static method init takes SystemUnit this returns nothing
static method deinit takes SystemUnit this returns nothing
*/
struct Camera extends array
//! runtextmacro CAMERA_SETTINGS()
static boolean LocalPlayerAttached = false
static integer LocalPlayerId
static integer LocalAttachedIndex
unit Unit
private static method Run takes nothing returns nothing
local SystemUnit this = LocalAttachedIndex
if LocalPlayerAttached then
call SetCameraField(CAMERA_FIELD_ROTATION, this.Facing, RotationRefreshRate)
call SetCameraField(CAMERA_FIELD_ZOFFSET, ((this.Z - GetTerrainZ(this.X, this.Y)) * ZOffsetHeightMultiply) + ZOffsetAddition, ZOffsetRefreshRate)
call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK, AngleOfAttack, AngleOfAttackRefreshRate)
call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, TargetDistance, TargetDistangeRefreshRate)
endif
endmethod
implement Camera_Initializers
endstruct
module Camera_Initializers
static method init takes SystemUnit this returns nothing
local unit u = this.Unit
if Human[this.UserId].get != null and u != null and u != thistype[this.UserId].Unit and SystemUnit[this.UserData].Attached then
set thistype[this.UserId].Unit = u
if this.UserId == Players.localPlayerId then
set LocalPlayerAttached = true
call CameraSetSmoothingFactor(CameraSmoothFactor)
set LocalAttachedIndex = this
call SetCameraTargetController(u, 0, 0, false)
call ClearSelection()
call SelectUnit(u, true)
//--
call SetCameraField(CAMERA_FIELD_ROTATION, this.Facing, 0)
call SetCameraField(CAMERA_FIELD_ZOFFSET, ((this.Z - GetTerrainZ(this.X, this.Y)) * ZOffsetHeightMultiply) + ZOffsetAddition, 0)
call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK, AngleOfAttack, 0)
call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, TargetDistance, 0)
endif
endif
set u = null
endmethod
static method deinit takes SystemUnit this returns nothing
if this.Unit != null then
//Deinit attached structs
call Arrow.deinit(this)
call Interface.deinit(this)
//Reset camera to default
if this.UserId == Players.localPlayerId then
set LocalPlayerAttached = false
call CameraSetSmoothingFactor(DefaultCameraSmoothFactor)
set LocalAttachedIndex = 0
call SetCameraTargetController(null, 0, 0, false)
//--
call ResetToGameCamera(.03)
endif
endif
endmethod
private static timer PeriodicCamera
private static method onInit takes nothing returns nothing
set PeriodicCamera = CreateTimer()
call TimerStart(PeriodicCamera, CAMERA_REFRESH_RATE, true, function thistype.Run)
endmethod
endmodule
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library Arrow /*
*/ uses /*
*/ SystemUnit /*
*/ PlayerManager /*
*/ Camera /*
struct Arrow extends array
Description
Allows for Arrow key movement to the attached unit.
Requires Camera unit attachment.
Settings
*/
//! textmacro ARROW_SETTINGS
//See Settings under Manual
implement Arrow_Settings
//! endtextmacro
/*
Fields
boolean IsUp
boolean IsDown
boolean IsLeft
boolean IsRight
unit Unit
integer Id
Methods
static method init takes SystemUnit Index returns nothing
static method deinit takes SystemUnit Index returns nothing
*/
struct Arrow extends array
//! runtextmacro ARROW_SETTINGS()
boolean IsUp
boolean IsDown
boolean IsLeft
boolean IsRight
unit Unit
integer Id
private static method onArrowKeyEvent takes integer arrow, boolean pressed returns nothing
local thistype this = thistype[GetTriggerPlayer()].Id
if thistype(.eventPlayerId).IsPlayerRegistered then
if pressed then
//Press Arrow Key
if ArrowKey.eventKey == ARROW_KEY_UP then
if IsRight then
set SystemUnit[this].Angle = -SystemUnit[this].TurnSpeed
set SystemUnit[this].Distance = SystemUnit[this].WalkSpeed
elseif IsLeft then
set SystemUnit[this].Angle = SystemUnit[this].TurnSpeed
set SystemUnit[this].Distance = SystemUnit[this].WalkSpeed
else
set SystemUnit[this].Distance = SystemUnit[this].WalkStraightSpeed
call SetUnitAnimationByIndex(SystemUnit[this].Unit, SystemUnit[this].AnimationIndexWalk)
endif
set IsUp = true
set IsDown = false
elseif ArrowKey.eventKey == ARROW_KEY_DOWN then
if IsRight then
set SystemUnit[this].Angle = SystemUnit[this].TurnSpeed
set SystemUnit[this].Distance = -SystemUnit[this].WalkSpeed
elseif IsLeft then
set SystemUnit[this].Angle = -SystemUnit[this].TurnSpeed
set SystemUnit[this].Distance = -SystemUnit[this].WalkSpeed
else
set SystemUnit[this].Distance = -SystemUnit[this].WalkStraightSpeed
call SetUnitAnimationByIndex(SystemUnit[this].Unit, SystemUnit[this].AnimationIndexWalk)
endif
set IsUp = false
set IsDown = true
elseif ArrowKey.eventKey == ARROW_KEY_LEFT then
if IsUp then
set SystemUnit[this].Angle = SystemUnit[this].TurnSpeed
set SystemUnit[this].Distance = SystemUnit[this].WalkSpeed
elseif IsDown then
set SystemUnit[this].Angle = -SystemUnit[this].TurnSpeed
set SystemUnit[this].Distance = -SystemUnit[this].WalkSpeed
else
set SystemUnit[this].Angle = SystemUnit[this].TurnSpeed
call SetUnitAnimationByIndex(SystemUnit[this].Unit, SystemUnit[this].AnimationIndexWalk)
endif
set IsLeft = true
set IsRight = false
elseif ArrowKey.eventKey == ARROW_KEY_RIGHT then
if IsUp then
set SystemUnit[this].Angle = -SystemUnit[this].TurnSpeed
set SystemUnit[this].Distance = SystemUnit[this].WalkSpeed
elseif IsDown then
set SystemUnit[this].Angle = SystemUnit[this].TurnSpeed
set SystemUnit[this].Distance = -SystemUnit[this].WalkSpeed
else
set SystemUnit[this].Angle = -SystemUnit[this].TurnSpeed
call SetUnitAnimationByIndex(SystemUnit[this].Unit, SystemUnit[this].AnimationIndexWalk)
endif
set IsLeft = false
set IsRight = true
endif
else
//Release Arrow Key
if ArrowKey.eventKey == ARROW_KEY_LEFT or ArrowKey.eventKey == ARROW_KEY_RIGHT then
if ArrowKey.eventKey == ARROW_KEY_LEFT then
if IsLeft then
set IsLeft = false
else
return
endif
elseif ArrowKey.eventKey == ARROW_KEY_RIGHT then
if IsRight then
set IsRight = false
else
return
endif
endif
set SystemUnit[this].Angle = SystemUnit[this].StopSpeed
if IsUp then
set SystemUnit[this].Distance = SystemUnit[this].WalkSpeed
elseif IsDown then
set SystemUnit[this].Distance = -SystemUnit[this].WalkSpeed
else
set SystemUnit[this].Distance = SystemUnit[this].StopSpeed
call SetUnitAnimationByIndex(SystemUnit[this].Unit, SystemUnit[this].AnimationIndexStand)
endif
elseif ArrowKey.eventKey == ARROW_KEY_UP or ArrowKey.eventKey == ARROW_KEY_DOWN then
if ArrowKey.eventKey == ARROW_KEY_UP then
if IsUp then
set IsUp = false
else
return
endif
elseif ArrowKey.eventKey == ARROW_KEY_DOWN then
if IsDown then
set IsDown = false
else
return
endif
endif
set SystemUnit[this].Distance = SystemUnit[this].StopSpeed
if IsRight then
set SystemUnit[this].Angle = -SystemUnit[this].TurnSpeed
elseif IsLeft then
set SystemUnit[this].Angle = SystemUnit[this].TurnSpeed
else
set SystemUnit[this].Angle = SystemUnit[this].StopSpeed
call SetUnitAnimationByIndex(SystemUnit[this].Unit, SystemUnit[this].AnimationIndexStand)
endif
endif
endif
//Animation Check
if IsUp then
call SetUnitTimeScale(SystemUnit[this].Unit, SystemUnit[this].AnimationSpeedWalkForward)
elseif IsDown then
call SetUnitTimeScale(SystemUnit[this].Unit, SystemUnit[this].AnimationSpeedWalkBackward)
else
call SetUnitTimeScale(SystemUnit[this].Unit, SystemUnit[this].AnimationSpeedTurnOnSpot)
endif
endif
endmethod
implement ArrowKeyEvent_PlayerRegister
implement ArrowKey
implement Arrow_Initializers
endstruct
module Arrow_Initializers
static method init takes SystemUnit Index returns nothing
local player p = GetOwningPlayer(Index.Unit)
local thistype this = GetPlayerId(p)
if SystemUnit[Index.UserData].Attached and Camera[this].Unit == Index.Unit then
if Unit != null then
call SetUnitTimeScale(Unit, 1)
call SetUnitAnimationByIndex(Unit, Index.AnimationIndexStand)
else
set IsPlayerRegistered = Human[this].get != null
endif
set Index.Distance = 0
set Index.Angle = 0
call SetUnitTimeScale(Index.Unit, Index.AnimationSpeedTurnOnSpot)
set Unit = Index.Unit
set Id = Index
endif
set p = null
endmethod
static method deinit takes SystemUnit Index returns nothing
local thistype this = GetPlayerId(GetOwningPlayer(Index.Unit))
if Unit == Index.Unit then
set Index.Distance = 0
set Index.Angle = 0
call SetUnitTimeScale(Unit, 1)
set Unit = null
set IsPlayerRegistered = false
endif
endmethod
endmodule
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library Interface /*
*/ uses /*
*/ SystemUnit /*
*/ Camera /*
struct Interface extends array
Description
Disables right click mobility and removes the command abilities.
Requires Camera unit attachment.
Fields
unit Unit
integer UserData
integer Index
boolean Attached
Methods
static method init takes thistype this, integer Id returns nothing
static method deinit takes thistype this returns nothing
static method deinit2 takes thistype this, thistype Count returns nothing
*/
struct Interface extends array
unit Unit
integer UserData
integer Index
boolean Attached
implement Interface_Initializers
endstruct
module Interface_Initializers
private static constant integer LOCUST = 'Aloc'
static method init takes thistype this, integer Id returns nothing
local thistype thisData
if SystemUnit[SystemUnit[this].UserData].Attached then
//Ovewrite
if Unit != null then
set thisData = GetUnitUserData(Unit)
set thisData.Index = 0
set thisData.Attached = false
call ShowUnit(Unit, false)
call ExplodeUnitBJ(Unit)
endif
//Create Data
set Unit = CreateUnit(SystemUnit[this].User, Id, 0, 0, 0)
set thisData = GetUnitUserData(Unit)
set UserData = thisData
set thisData.Index = this
set thisData.Attached = true
//Lock to owning player
if SystemUnit[this].UserId == Camera.LocalPlayerId then
call EnableSelect(false, false)
call EnableDragSelect(false, false)
call EnablePreSelect(false, true)
call SelectUnit(Unit, true)
endif
//Make undetectable on map
call UnitAddAbility(Unit, LOCUST)
call SetUnitX(Unit, (PinSector.MapMaxX * 512) + 514 + SystemUnit[this].UserId)
endif
endmethod
static method deinit takes thistype this returns nothing
local thistype thisData = GetUnitUserData(Unit)
if Unit != null then
set UserData = 0
set thisData.Index = 0
set thisData.Attached = false
call ShowUnit(Unit, false)
call ExplodeUnitBJ(Unit)
set Unit = null
if SystemUnit[this].UserId == Camera.LocalPlayerId then
call EnableSelect(true, true)
call EnableDragSelect(true, true)
call EnablePreSelect(true, true)
call SelectUnit(SystemUnit[this].Unit, true)
endif
endif
endmethod
static method deinit2 takes thistype this, thistype Count returns nothing
local thistype thisData = GetUnitUserData(Count.Unit)
call deinit(this)
if this != Count then
set UserData = thisData
set thisData.Index = this
set Unit = Count.Unit
set Count.Unit = null
endif
endmethod
endmodule
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library OrderMove /*
*/ uses /*
*/ SystemUnit /*
struct Arrow extends array
Description
When unit that is attached to the system is ordered
to move, it will be ordered to that coordinate. For
now though it is under construction and only stops
that unit on command.
*/
struct OrderMove extends array
private static integer uCount = 0
private static unit array u
private static method TimedStop takes nothing returns nothing
call DestroyTimer(GetExpiredTimer())
call IssueImmediateOrder(u[0], "stop")
set uCount = uCount - 1
if uCount > 0 then
set u[0] = u[uCount]
set u[uCount] = null
else
set u[0] = null
endif
endmethod
private static method Stop takes nothing returns nothing
set u[uCount] = GetTriggerUnit()
set uCount = uCount + 1
call TimerStart(CreateTimer(), 0, false, function thistype.TimedStop)
endmethod
private static method Move takes nothing returns nothing
local unit u = GetTriggerUnit()
//call Real2(GetOrderPointX(), GetOrderPointY())
endmethod
private static method passCondition takes nothing returns boolean
local SystemUnit this = SystemUnit[GetUnitUserData(GetTriggerUnit())].Index
return GetTriggerUnit() == this.Unit
endmethod
private static trigger OrderMove = CreateTrigger()
private static method onInit takes nothing returns nothing
call TriggerAddAction(OrderMove, function thistype.Stop)
call TriggerAddAction(OrderMove, function thistype.Move)
call TriggerAddCondition(OrderMove, Condition(function thistype.passCondition))
call TriggerRegisterAnyUnitEventBJ(OrderMove, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER)
endmethod
endstruct
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
/*
module ObjectAddons
Description
For all Object add ons below this trigger in
this folder. Implement all in object types structs
for proper functionality.
The Destructable Add-on requires the Object Indexing
Add-on to function 100%
Used in structs
RectangleObject
CircleObject
*/
module ObjectAddons
implement ObjectIndexing
implement DestructableAddOn
implement ForSectors
endmodule
//TESH.scrollpos=0
//TESH.alwaysfold=0
/*
module ObjectIndexing
Description
All your base indexing needs for sector indexing
to keep this system usable with lots of objects
Used in module
ObjectAddons
Used in structs
RectangleObject
CircleObject
Fields
static hashtable Sector
static hashtable SectorIndex
static hashtable SectorUserData
integer SectorCount
integer SectorIndexCount
integer Recycler
static thistype RecyclerCount
boolean Attached
Methods
static method DoesExist takes thistype ObjectId returns boolean
static method CreateIndex takes real MinX, real MaxX, real MinY, real MaxY returns integer
static method Remove takes thistype ObjectIndex returns nothing
*/
module ObjectIndexing
//Sector Indexer
static hashtable Sector = InitHashtable()
static hashtable SectorIndex = InitHashtable()
static hashtable SectorUserData = InitHashtable()
integer SectorCount
integer SectorIndexCount
//Basic Indexer
integer Recycler
static thistype RecyclerCount = 0
boolean Attached
static method DoesExist takes thistype ObjectId returns boolean
return ObjectId.Attached
endmethod
static method CreateIndex takes real MinX, real MaxX, real MinY, real MaxY returns integer
local thistype BLSector = PinSector.Get(MinX, MinY)
local thistype TRSector = PinSector.Get(MaxX, MaxY)
local thistype SectorStart = BLSector
local thistype SectorEnd = PinSector.Get(MaxX, MinY)
local thistype this
local thistype ObjectIndex
//Index the object
if RecyclerCount == 0 then
set ObjectIndex = thistype[0].Recycler
set thistype[0].Recycler = thistype[0].Recycler + 1
else
set ObjectIndex = RecyclerCount.Recycler
set RecyclerCount = RecyclerCount - 1
endif
set ObjectIndex.Attached = true
//Store the sectors it interacts with
loop
loop
set this = BLSector.SectorCount + 1
call SaveInteger(SectorIndex, BLSector, this, ObjectIndex)
call SaveInteger(SectorUserData, BLSector, ObjectIndex, this)
set ObjectIndex.SectorIndexCount = ObjectIndex.SectorIndexCount + 1
call SaveInteger(Sector, ObjectIndex, ObjectIndex.SectorIndexCount, BLSector)
set BLSector.SectorCount = this
exitwhen BLSector == SectorEnd
set BLSector = BLSector + 1
endloop
exitwhen BLSector == TRSector
set SectorStart = SectorStart + PinSector.MapXSpread
set SectorEnd = SectorEnd + PinSector.MapXSpread
set BLSector = SectorStart
endloop
//Retun
return ObjectIndex
endmethod
static method Remove takes thistype ObjectIndex returns nothing
//Deinit Sector Indexes
local thistype thisObjectSectorsCount = ObjectIndex.SectorIndexCount
local thistype thisSector
local thistype thisSectorUserData
local thistype thisSectorCount
local thistype newObjectIndex
loop
exitwhen thisObjectSectorsCount == 0
set thisSector = LoadInteger(Sector, ObjectIndex, thisObjectSectorsCount)
set thisSectorUserData = LoadInteger(SectorUserData, thisSector, ObjectIndex)
set thisSectorCount = thisSector.SectorCount
if thisSectorCount != thisSectorUserData then
set newObjectIndex = LoadInteger(SectorIndex, thisSector, thisSectorCount)
call SaveInteger(SectorIndex, thisSector, thisSectorUserData, newObjectIndex)
call SaveInteger(SectorUserData, thisSector, newObjectIndex, thisSectorUserData)
endif
set thisSector.SectorCount = thisSectorCount - 1
set thisObjectSectorsCount = thisObjectSectorsCount - 1
endloop
set ObjectIndex.Attached = false
//Deinit Dest
call DetachDest(ObjectIndex)
//Add ObjectIndex to recycler
set RecyclerCount = RecyclerCount + 1
set RecyclerCount.Recycler = ObjectIndex
endmethod
endmodule
//TESH.scrollpos=0
//TESH.alwaysfold=0
/*
module DestructableAddOn
Description
All your needed and possible attachment and
detachment indexing for attaching and detaching
destructables to object indexes
Destroys object on attached dests death unless
event is destroyed or dest detached from object
Used in module
ObjectAddons
Used in structs
RectangleObject
CircleObject
Fields
destructable Dest
static hashtable DestIndex
integer DestHandle
boolean DestAttached
Methods
static method AttachToDest takes destructable d, thistype ObjectIndex returns nothing
static method DetachDest takes thistype ObjectIndex returns nothing
static method DetachFromDest takes destructable d returns nothing
static method RegisterDestDeathEvent takes destructable d returns nothing
static method DestroyDestDeathEvent takes destructable d returns nothing
static method GetDestIndex takes destructable d returns integer
static method GetAttachedDest takes thistype ObjectId returns destructable
static method HasDestAttached takes thistype ObjectId returns boolean
static method IsDestAttached takes destructable Dest returns boolean
*/
module DestructableAddOn
destructable Dest
static hashtable DestIndex = InitHashtable()
integer DestHandle
boolean DestAttached
static method AttachToDest takes destructable d, thistype ObjectIndex returns nothing
local integer Handle = GetHandleId(d)
set ObjectIndex.Dest = d
call SaveInteger(DestIndex, 0, Handle, ObjectIndex)
set ObjectIndex.DestHandle = Handle
call RegisterDestDeathEvent(d)
set ObjectIndex.DestAttached = true
endmethod
//--
static method DetachDest takes thistype ObjectIndex returns nothing
if ObjectIndex.DestAttached then
call DestroyDestDeathEvent(ObjectIndex.Dest)
call RemoveSavedHandle(DestIndex, 0, GetHandleId(ObjectIndex.Dest))
set ObjectIndex.Dest = null
set ObjectIndex.DestHandle = 0
set ObjectIndex.DestAttached = false
endif
endmethod
static method DetachFromDest takes destructable d returns nothing
local integer Handle = GetHandleId(d)
local thistype ObjectIndex = LoadInteger(DestIndex, 0, Handle)
if ObjectIndex.DestAttached then
call DestroyDestDeathEvent(d)
call RemoveSavedHandle(DestIndex, 0, Handle)
set ObjectIndex.Dest = null
set ObjectIndex.DestHandle = 0
set ObjectIndex.DestAttached = false
endif
endmethod
private static method onDeath takes nothing returns nothing
call thistype.Remove(LoadInteger(DestIndex, 0, GetHandleId(GetTriggerDestructable())))
endmethod
private trigger ObjectDestructableDeath_Attach
static method RegisterDestDeathEvent takes destructable d returns nothing
local thistype this = LoadInteger(DestIndex, 0, GetHandleId(d))
set ObjectDestructableDeath_Attach = CreateTrigger()
call TriggerAddAction(ObjectDestructableDeath_Attach, function thistype.onDeath)
call TriggerRegisterDeathEvent(ObjectDestructableDeath_Attach, d)
endmethod
static method DestroyDestDeathEvent takes destructable d returns nothing
local thistype this = LoadInteger(DestIndex, 0, GetHandleId(d))
call DestroyTrigger(ObjectDestructableDeath_Attach)
endmethod
//--
static method GetDestIndex takes destructable d returns integer
return LoadInteger(DestIndex, 0, GetHandleId(d))
endmethod
static method GetAttachedDest takes thistype ObjectId returns destructable
return ObjectId.Dest
endmethod
static method HasDestAttached takes thistype ObjectId returns boolean
return ObjectId.DestAttached
endmethod
static method IsDestAttached takes destructable Dest returns boolean
return thistype[LoadInteger(DestIndex, 0, GetHandleId(Dest))].DestAttached
endmethod
endmodule
//TESH.scrollpos=0
//TESH.alwaysfold=0
/*
module ForSectors
Description
Getting all objects within a rectangle area
Used in module
ObjectAddons
Used in structs
RectangleObject
CircleObject
Uses
PinSector
Fields
static InterfaceGetObjectId forObject
Methods
static method ForSectorsInCoordinates takes real MinX, real MaxX, real MinY, real MaxY, InterfaceGetObjectId temp_forObject returns nothing
static method ForSectorsInCoordinatesExclusive takes real MinX, real MaxX, real MinY, real MaxY, InterfaceGetObjectIdWithUnit forObject, SystemUnit Unit returns nothing
*/
module ForSectors
static InterfaceGetObjectId forObject
private static method ForSectorsInCoordinates_Func takes thistype Sector returns nothing
local integer SectorCountIndex = Sector.SectorCount
loop
exitwhen SectorCountIndex == 0
call forObject.execute(LoadInteger(thistype.SectorIndex, Sector, SectorCountIndex))
set SectorCountIndex = SectorCountIndex - 1
endloop
endmethod
static method ForSectorsInCoordinates takes real MinX, real MaxX, real MinY, real MaxY, InterfaceGetObjectId temp_forObject returns nothing
set thistype.forObject = temp_forObject
call PinSector.RunFunc(MinX, MaxX, MinY, MaxY, ForSectorsInCoordinates_Func)
endmethod
private static InterfaceGetObjectIdWithUnit forObjectExclusive
private static method ForSectorsInCoordinatesExclusive_Func takes thistype Sector, SystemUnit Unit returns nothing
local integer SectorCountIndex = Sector.SectorCount
loop
exitwhen SectorCountIndex == 0
call forObjectExclusive.execute(LoadInteger(thistype.SectorIndex, Sector, SectorCountIndex), Unit)
set SectorCountIndex = SectorCountIndex - 1
endloop
endmethod
static method ForSectorsInCoordinatesExclusive takes real MinX, real MaxX, real MinY, real MaxY, InterfaceGetObjectIdWithUnit forObject, SystemUnit Unit returns nothing
set thistype.forObjectExclusive = forObject
call PinSector.RunFuncExclusive(MinX, MaxX, MinY, MaxY, ForSectorsInCoordinatesExclusive_Func, Unit)
endmethod
endmodule
//TESH.scrollpos=0
//TESH.alwaysfold=0
/*
textmacro Movement_Rectangle3DCollision
Description
Checks collision in appropriate sectors for reassigning
units position outside of object if ever intercept with
the objects coordinate limits
Used in module
ObjectAddons
Used in struct
Movement
*/
//! textmacro Movement_Rectangle3DCollision
private static method Rectangle3DCheck takes Rectangle3D Object, SystemUnit this returns nothing
local real MinX = Object.MinX - this.Width
local real MaxX = Object.MaxX + this.Width
local real MinY = Object.MinY - this.Width
local real MaxY = Object.MaxY + this.Width
local real MinZ = Object.MinZ - this.Height
local real MaxZ = Object.MaxZ
if RedeclairX > MinX and RedeclairX < MaxX and RedeclairY > MinY and RedeclairY < MaxY and RedeclairZ > MinZ and RedeclairZ < MaxZ then
if this.Z >= MaxZ then
set RedeclairZ = MaxZ
set RedeclairAir = 0
set this.CanJump = true
elseif this.Z <= MinZ then
if GetTerrainZ(NewX, NewY) >= MinZ then
set RedeclairX = this.X
set RedeclairY = this.Y
set RedeclairZ = this.Z
else
set RedeclairZ = MinZ
set RedeclairAir = NewAir
endif
elseif this.X <= MinX then
set RedeclairX = MinX
elseif this.X >= MaxX then
set RedeclairX = MaxX
elseif this.Y <= MinY then
set RedeclairY = MinY
elseif this.Y >= MaxY then
set RedeclairY = MaxY
endif
endif
endmethod
private static method Rectangle3D takes SystemUnit this returns nothing
if this.X < RedeclairX then
if this.Y < RedeclairY then
call Rectangle3D.ForSectorsInCoordinatesExclusive(this.X - this.Width, RedeclairX + this.Width, this.Y - this.Width, RedeclairY + this.Width, Rectangle3DCheck, this)
else
call Rectangle3D.ForSectorsInCoordinatesExclusive(this.X - this.Width, RedeclairX + this.Width, RedeclairY - this.Width, this.Y + this.Width, Rectangle3DCheck, this)
endif
else
if this.Y < RedeclairY then
call Rectangle3D.ForSectorsInCoordinatesExclusive(RedeclairX - this.Width, this.X + this.Width, this.Y - this.Width, RedeclairY + this.Width, Rectangle3DCheck, this)
else
call Rectangle3D.ForSectorsInCoordinatesExclusive(RedeclairX - this.Width, this.X + this.Width, RedeclairY - this.Width, this.Y + this.Width, Rectangle3DCheck, this)
endif
endif
endmethod
//! endtextmacro
//TESH.scrollpos=0
//TESH.alwaysfold=0
library Rectangle3D /*
*/ uses /*
*/ PinSector /*
*/ WorldBounds /*
struct Rectangle3D extends array
Description
Collision check for reassigning units position outside of
object if ever intercept with the objects coordinate limits
Modules
Rectangle3D_AllCreate
Rectangle3D_InAreaAll
Rectangle3D_Coordinates
ObjectAddons
Fields
real MinX
real MaxX
real MinY
real MaxY
real MinZ
real MaxZ
*/
struct Rectangle3D extends array
//Stored Data
real MinX
real MaxX
real MinY
real MaxY
real MinZ
real MaxZ
implement Rectangle3D_AllCreate
implement Rectangle3D_InAreaAll
implement Rectangle3D_Coordinates
//--
implement ObjectAddons
endstruct
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
/*
module Rectangle3D_AllCreate
Description
Containing all create methods from create modules
Used in struct
RectangleObject
Modules
Rectangle3D_Create
Rectangle3D_CreateAttachedToDest
module Rectangle3D_Create
Description
Containing basic create at coordinates that returns object ID
Also containing recreate that uses an already created objects
ID to use that objects size at a coordinate
Methods
static method Create takes real MinX, real MaxX, real MinY, real MaxY, real MinZ, real MaxZ returns integer
static method Recreate takes real x, real y, thistype Object returns integer
static method RecreateZ takes real x, real y, real z, thistype Object returns integer
module Rectangle3D_CreateAttachedToDest
Description
Either create an object and attach it to a destructable in one
call or create attached to all dests of the same ID at a set z
coordinate
Methods
static method CreateAttachedToDest takes destructable d, real MinX, real MaxX, real MinY, real MaxY, real MinZ, real MaxZ returns nothing
static method CreateAttachedToDests takes integer DestId, real MinX, real MaxX, real MinY, real MaxY, real MinZ, real MaxZ returns nothing
*/
module Rectangle3D_AllCreate
implement Rectangle3D_Create
implement Rectangle3D_CreateAttachedToDest
endmodule
module Rectangle3D_Create
static method Create takes real MinX, real MaxX, real MinY, real MaxY, real MinZ, real MaxZ returns integer
local thistype ObjectIndex = CreateIndex(MinX, MaxX, MinY, MaxY)
set ObjectIndex.MinX = MinX
set ObjectIndex.MaxX = MaxX
set ObjectIndex.MinY = MinY
set ObjectIndex.MaxY = MaxY
set ObjectIndex.MinZ = MinZ
set ObjectIndex.MaxZ = MaxZ
return ObjectIndex
endmethod
static method Recreate takes real x, real y, thistype Object returns integer
local real XWidth = (Object.MaxX - Object.MinX)/2
local real YWidth = (Object.MaxY - Object.MinY)/2
local real MinX = x - XWidth
local real MaxX = x + XWidth
local real MinY = y - YWidth
local real MaxY = y + YWidth
local thistype ObjectIndex = CreateIndex(MinX, MaxX, MinY, MaxY)
set ObjectIndex.MinX = MinX
set ObjectIndex.MaxX = MaxX
set ObjectIndex.MinY = MinY
set ObjectIndex.MaxY = MaxY
set ObjectIndex.MinZ = Object.MinZ
set ObjectIndex.MaxZ = Object.MaxZ
return ObjectIndex
endmethod
static method RecreateZ takes real x, real y, real z, thistype Object returns integer
local real XWidth = (Object.MaxX - Object.MinX)/2
local real YWidth = (Object.MaxY - Object.MinY)/2
local real ZHeight = (Object.MaxZ - Object.MinZ)/2
local real MinX = x - XWidth
local real MaxX = x + XWidth
local real MinY = y - YWidth
local real MaxY = y + YWidth
local thistype ObjectIndex = CreateIndex(MinX, MaxX, MinY, MaxY)
set ObjectIndex.MinX = MinX
set ObjectIndex.MaxX = MaxX
set ObjectIndex.MinY = MinY
set ObjectIndex.MaxY = MaxY
set ObjectIndex.MinZ = Object.MinZ - ZHeight
set ObjectIndex.MaxZ = Object.MaxZ + ZHeight
return ObjectIndex
endmethod
endmodule
module Rectangle3D_CreateAttachedToDest
static method CreateAttachedToDest takes destructable d, real MinX, real MaxX, real MinY, real MaxY, real MinZ, real MaxZ returns nothing
call AttachToDest(d, thistype.Create(MinX, MaxX, MinY, MaxY, MinZ, MaxZ))
endmethod
private static real temp_MinX
private static real temp_MaxX
private static real temp_MinY
private static real temp_MaxY
private static real temp_MinZ
private static real temp_MaxZ
private static method InitDestructable takes nothing returns nothing
local destructable d = GetEnumDestructable()
local real x = GetDestructableX(d)
local real y = GetDestructableY(d)
call CreateAttachedToDest(d, x-temp_MinX, x+temp_MaxX, y-temp_MinY, y+temp_MaxY, temp_MinZ, temp_MaxZ)
set d = null
endmethod
private static integer temp_Id
private static method IsDestructable takes nothing returns boolean
return GetDestructableTypeId(GetFilterDestructable()) == temp_Id
endmethod
static method CreateAttachedToDests takes integer DestId, real MinX, real MaxX, real MinY, real MaxY, real MinZ, real MaxZ returns nothing
set temp_Id = DestId
set temp_MinX = MinX
set temp_MaxX = MaxX
set temp_MinY = MinY
set temp_MaxY = MaxY
set temp_MinZ = MinZ
set temp_MaxZ = MaxZ
call EnumDestructablesInRect(WorldBounds.world, Condition(function thistype.IsDestructable), function thistype.InitDestructable)
endmethod
endmodule
//TESH.scrollpos=0
//TESH.alwaysfold=0
/*
module Rectangle3D_InAreaAll
Description
Containing all create methods from create modules
Used in struct
Rectangle3D
Modules
Rectangle3D_ForAllInRectangleObject
Rectangle3D_ForAllInRectangleArea
module Rectangle3D_ForAllInRectangleObject
Description
Containing basic create at coordinates that returns object ID
Also containing recreate that uses an already created objects
ID to use that objects size at a coordinate
Methods
static method ForAllObjectsInRectangleObject takes RectangleObject ObjectId, InterfaceGetObjectId forObjectId returns nothing
module Rectangle3D_ForAllInRectangleArea
Description
Either create an object and attach it to a destructable in one
call or create attached to all dests of the same ID at a set z
coordinate
Methods
static method ForAllObjectsInRectangleArea takes real MinX, real MaxX, real MinY, real MaxY, InterfaceGetObjectId forObjectId returns nothing
static method ForAllObjectsInRectangleAreaZ takes real MinX, real MaxX, real MinY, real MaxY, real MinZ, real MaxZ, InterfaceGetObjectId ObjectId returns nothing
*/
module Rectangle3D_InAreaAll
implement Rectangle3D_ForAllInRectangleObject
implement Rectangle3D_ForAllInRectangleArea
endmodule
module Rectangle3D_ForAllInRectangleObject
private static thistype temp_Object
private static InterfaceGetObjectId temp_forObjectId
static method ForAllObjectsInRectangleObject_Get takes thistype ObjectId returns nothing
if ObjectId.MaxX >= temp_Object.MinX and ObjectId.MinX <= temp_Object.MaxX and ObjectId.MaxY >= temp_Object.MinY and ObjectId.MinY <= temp_Object.MaxY and ObjectId.MaxZ >= temp_Object.MinZ and ObjectId.MinZ <= temp_Object.MaxZ then
call temp_forObjectId.execute(ObjectId)
endif
endmethod
static method ForAllObjectsInRectangleObject takes Rectangle3D ObjectId, InterfaceGetObjectId forObjectId returns nothing
set temp_Object = ObjectId
set temp_forObjectId = forObjectId
call thistype.ForSectorsInCoordinates(ObjectId.MinX, ObjectId.MinY, ObjectId.MaxX, ObjectId.MaxY, ForAllObjectsInRectangleObject_Get)
endmethod
endmodule
module Rectangle3D_ForAllInRectangleArea
private static real temp_MinX
private static real temp_MaxX
private static real temp_MinY
private static real temp_MaxY
private static real temp_MinZ
private static real temp_MaxZ
private static InterfaceGetObjectId temp_forObjectId
static method ForAllObjectsInRectangleArea_Check takes Rectangle3D ObjectId returns nothing
if temp_MaxX >= ObjectId.MinX and temp_MinX <= ObjectId.MaxX and temp_MaxY >= ObjectId.MinY and temp_MinY <= ObjectId.MaxY then
call temp_forObjectId.execute(ObjectId)
endif
endmethod
static method ForAllObjectsInRectangleArea takes real MinX, real MaxX, real MinY, real MaxY, InterfaceGetObjectId forObjectId returns nothing
set temp_MinX = MinX
set temp_MaxX = MaxX
set temp_MinY = MinY
set temp_MaxY = MaxY
set temp_forObjectId = forObjectId
call thistype.ForSectorsInCoordinates(MinX, MinY, MaxX, MaxY, ForAllObjectsInRectangleArea_Check)
endmethod
static method ForAllObjectsInRectangleAreaZ_Check takes Rectangle3D ObjectId returns nothing
if temp_MaxX >= ObjectId.MinX and temp_MinX <= ObjectId.MaxX and temp_MaxY >= ObjectId.MinY and temp_MinY <= ObjectId.MaxY and temp_MaxZ >= ObjectId.MinZ and temp_MinZ <= ObjectId.MaxZ then
call temp_forObjectId.execute(ObjectId)
endif
endmethod
static method ForAllObjectsInRectangleAreaZ takes real MinX, real MaxX, real MinY, real MaxY, real MinZ, real MaxZ, InterfaceGetObjectId ObjectId returns nothing
set temp_MinX = MinX
set temp_MaxX = MaxX
set temp_MinY = MinY
set temp_MaxY = MaxY
set temp_MinZ = MinZ
set temp_MaxZ = MaxZ
set temp_forObjectId = ObjectId
call thistype.ForSectorsInCoordinates(MinX, MinY, MaxX, MaxY, ForAllObjectsInRectangleAreaZ_Check)
endmethod
endmodule
//TESH.scrollpos=0
//TESH.alwaysfold=0
/*
module Rectangle3D_InAreaAll
Description
Boolean checks if inside a or any object
Used in struct
Rectangle3D
Methods
static method IsUnitInsideId takes RectangleObject Object, SystemUnit this returns boolean
static method IsUnitInside takes RectangleObject Object, unit u returns boolean
static method IsUnitInsideAnyId takes SystemUnit this returns boolean
static method IsUnitInsideAny takes unit u returns boolean
*/
module IsUnitInsideRectangle3D
static method IsUnitInsideId takes RectangleObject Object, SystemUnit this returns boolean
local real w = this.Width
local real MinX = Object.MinX-w
local real MaxX = Object.MaxX+w
local real MinY = Object.MinY-w
local real MaxY = Object.MaxY+w
local real MinZ = Object.MinZ-w
local real MaxZ = Object.MaxZ
local real uX = SystemUnit.GetX(u)
local real uY = SystemUnit.GetY(u)
local real uZ = SystemUnit.GetZ(u)
set u = null
return uX > MinX and uX < MaxX and uY > MinY and uY < MaxY and uZ > MinZ and uZ < MaxZ
endmethod
static method IsUnitInside takes RectangleObject Object, unit u returns boolean
local SystemUnit this = SystemUnit[GetUnitUserData(u)].Index
local real w = this.Width
local real MinX = Object.MinX-w
local real MaxX = Object.MaxX+w
local real MinY = Object.MinY-w
local real MaxY = Object.MaxY+w
local real MinZ = Object.MinZ-w
local real MaxZ = Object.MaxZ
local real uX = SystemUnit.GetX(u)
local real uY = SystemUnit.GetY(u)
local real uZ = SystemUnit.GetZ(u)
set u = null
return uX > MinX and uX < MaxX and uY > MinY and uY < MaxY and uZ > MinZ and uZ < MaxZ
endmethod
private static boolean Temp_IsTrue
private static method IsUnitInsideAnyCheck takes RectangleObject Object, SystemUnit this returns nothing
if IsUnitInsideId(Object, this) then
set temp_IsTrue = true
endif
endmethod
static method IsUnitInsideAnyId takes SystemUnit this returns boolean
local real x = this.X
local real y = this.Y
local real w = this.Width
set temp_IsTrue = false
call thistype.ForSectorsInCoordinatesExclusive(x-w, x+w, y-w, y+w, thistype.IsUnitInsideAnyCheck, this)
return temp_IsTrue
endmethod
static method IsUnitInsideAny takes unit u returns boolean
local SystemUnit this = SystemUnit[GetUnitUserData(u)].Index
local real x = this.X
local real y = this.Y
local real w = this.Width
set temp_IsTrue = false
call thistype.ForSectorsInCoordinatesExclusive(x-w, x+w, y-w, y+w, thistype.IsUnitInsideAnyCheck, this)
return temp_IsTrue
endmethod
endmodule
//TESH.scrollpos=0
//TESH.alwaysfold=0
/*
module Rectangle3D_Coordinates
Description
Getting object coordinates or modifying them
Used in struct
Rectangle3D
Methods
static method GetMinX takes thistype ObjectId returns real
static method GetMaxX takes thistype ObjectId returns real
static method GetMinY takes thistype ObjectId returns real
static method GetMaxY takes thistype ObjectId returns real
static method GetMinZ takes thistype ObjectId returns real
static method GetMaxZ takes thistype ObjectId returns real
static method GetX takes thistype ObjectId returns real
static method GetY takes thistype ObjectId returns real
static method GetZ takes thistype ObjectId returns real
static method SetMinX takes thistype ObjectId, real minX returns nothing
static method SetMaxX takes thistype ObjectId, real maxX returns nothing
static method SetMinY takes thistype ObjectId, real minY returns nothing
static method SetMaxY takes thistype ObjectId, real maxY returns nothing
static method SetMinZ takes thistype ObjectId, real minZ returns nothing
static method SetMaxZ takes thistype ObjectId, real maxZ returns nothing
static method SetXYZ takes thistype ObjectId, real x, real y, real z returns nothing
static method SetXY takes thistype ObjectId, real x, real y, real z returns nothing
static method SetX takes thistype ObjectId, real x returns nothing
static method SetY takes thistype ObjectId, real y returns nothing
static method SetZ takes thistype ObjectId, real z returns nothing
*/
module Rectangle3D_Coordinates
static method GetMinX takes thistype ObjectId returns real
return ObjectId.MinX
endmethod
static method GetMaxX takes thistype ObjectId returns real
return ObjectId.MaxX
endmethod
static method GetMinY takes thistype ObjectId returns real
return ObjectId.MinY
endmethod
static method GetMaxY takes thistype ObjectId returns real
return ObjectId.MaxY
endmethod
static method GetMinZ takes thistype ObjectId returns real
return ObjectId.MinZ
endmethod
static method GetMaxZ takes thistype ObjectId returns real
return ObjectId.MaxZ
endmethod
//----
static method GetX takes thistype ObjectId returns real
return (ObjectId.MinX + ObjectId.MaxX) / 2
endmethod
static method GetY takes thistype ObjectId returns real
return (ObjectId.MinY + ObjectId.MaxY) / 2
endmethod
static method GetZ takes thistype ObjectId returns real
return (ObjectId.MinZ + ObjectId.MaxZ) / 2
endmethod
//----
static method SetMinX takes thistype ObjectId, real minX returns nothing
set ObjectId.MinX = minX
endmethod
static method SetMaxX takes thistype ObjectId, real maxX returns nothing
set ObjectId.MaxX = maxX
endmethod
static method SetMinY takes thistype ObjectId, real minY returns nothing
set ObjectId.MinY = minY
endmethod
static method SetMaxY takes thistype ObjectId, real maxY returns nothing
set ObjectId.MaxY = maxY
endmethod
static method SetMinZ takes thistype ObjectId, real minZ returns nothing
set ObjectId.MinZ = minZ
endmethod
static method SetMaxZ takes thistype ObjectId, real maxZ returns nothing
set ObjectId.MaxZ = maxZ
endmethod
//----
static method SetXYZ takes thistype ObjectId, real x, real y, real z returns nothing
local real Difference = (ObjectId.MaxX - ObjectId.MinX) / 2
set ObjectId.MinX = x - Difference
set ObjectId.MaxX = x + Difference
set Difference = (ObjectId.MaxX - ObjectId.MinX) / 2
set ObjectId.MinX = y - Difference
set ObjectId.MaxX = y + Difference
set Difference = (ObjectId.MaxZ - ObjectId.MinZ) / 2
set ObjectId.MinZ = z - Difference
set ObjectId.MaxZ = z + Difference
endmethod
static method SetXY takes thistype ObjectId, real x, real y, real z returns nothing
local real Difference = (ObjectId.MaxX - ObjectId.MinX) / 2
set ObjectId.MinX = x - Difference
set ObjectId.MaxX = x + Difference
set Difference = (ObjectId.MaxX - ObjectId.MinX) / 2
set ObjectId.MinX = y - Difference
set ObjectId.MaxX = y + Difference
set Difference = (ObjectId.MaxZ - ObjectId.MinZ) / 2
set ObjectId.MinZ = z - Difference
set ObjectId.MaxZ = z + Difference
endmethod
static method SetX takes thistype ObjectId, real x returns nothing
local real Difference = (ObjectId.MaxX - ObjectId.MinX) / 2
set ObjectId.MinX = x - Difference
set ObjectId.MaxX = x + Difference
endmethod
static method SetY takes thistype ObjectId, real y returns nothing
local real Difference = (ObjectId.MaxY - ObjectId.MinY) / 2
set ObjectId.MinY = y - Difference
set ObjectId.MaxY = y + Difference
endmethod
static method SetZ takes thistype ObjectId, real z returns nothing
local real Difference = (ObjectId.MaxZ - ObjectId.MinZ) / 2
set ObjectId.MinZ = z - Difference
set ObjectId.MaxZ = z + Difference
endmethod
endmodule
//TESH.scrollpos=0
//TESH.alwaysfold=0
/*
textmacro Movement_Circle2DCollision
Description
Collision check for reassigning units position outside of
object if ever intercept with the objects coordinate limits
Used in module
ObjectAddons
Used in struct
Movement
*/
//! textmacro Movement_Circle2DCollision
private static method Circle2DCheck takes Circle2D Object, SystemUnit this returns nothing
local real dx = RedeclairX - Object.x
local real dy = RedeclairY - Object.y
if SquareRoot(dx * dx + dy * dy) <= Object.Radius + this.Width then
if Object.HasTop and this.Z >= Object.z and RedeclairZ < Object.z then
set RedeclairZ = Object.z
set RedeclairAir = 0
set this.CanJump = true
elseif Object.HasBottom and this.Z <= Object.z - this.Height and RedeclairZ > Object.z - this.Height then
if GetTerrainZ(NewX, NewY) >= Object.z - this.Height then
set RedeclairX = this.X
set RedeclairY = this.Y
set RedeclairZ = this.Z
else
set RedeclairZ = Object.z - this.Height
set RedeclairAir = NewAir
endif
endif
endif
endmethod
private static method Circle2D takes SystemUnit this returns nothing
if this.X < RedeclairX then
if this.Y < RedeclairY then
call Circle2D.ForSectorsInCoordinatesExclusive(this.X - this.Width, RedeclairX + this.Width, this.Y - this.Width, RedeclairY + this.Width, Circle2DCheck, this)
else
call Circle2D.ForSectorsInCoordinatesExclusive(this.X - this.Width, RedeclairX + this.Width, RedeclairY - this.Width, this.Y + this.Width, Circle2DCheck, this)
endif
else
if this.Y < RedeclairY then
call Circle2D.ForSectorsInCoordinatesExclusive(RedeclairX - this.Width, this.X + this.Width, this.Y - this.Width, RedeclairY + this.Width, Circle2DCheck, this)
else
call Circle2D.ForSectorsInCoordinatesExclusive(RedeclairX - this.Width, this.X + this.Width, RedeclairY - this.Width, this.Y + this.Width, Circle2DCheck, this)
endif
endif
endmethod
//! endtextmacro
//TESH.scrollpos=0
//TESH.alwaysfold=0
library CircleObject /*
*/ uses /*
*/ PinSector /*
*/ WorldBounds /*
struct Circle2D extends array
Description
Collision check for reassigning units position outside of
object if ever intercept with the objects coordinate limits
Modules
Circle2D_CreateAll
ObjectAddons
Fields
real x
real y
real z
real Radius
boolean HasTop
boolean HasBottom
*/
struct Circle2D extends array
real x
real y
real z
real Radius
boolean HasTop
boolean HasBottom
implement Circle2D_CreateAll
//--
implement ObjectAddons
endstruct
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
/*
module Rectangle2D_AllCreate
Description
Containing all create methods from create modules
Used in struct
Circle2D
Modules
Circle2D_Create
Circle2D_CreateAttachedToDest
module Circle2D_Create
Description
Containing basic create at coordinates that returns object ID
Methods
static method Create takes real x, real y, real z, real Radius, boolean HasTop, boolean HasBottom returns integer
module Circle2D_CreateAttachedToDest
Description
Either create an object and attach it to a destructable in one
call or create attached to all dests of the same ID at a set z
coordinate
Methods
static method CreateAttachedToDest takes destructable d, real x, real y, real z, real Radius, boolean HasTop, boolean HasBottom returns nothing
static method CreateAttachedToDests takes integer DestId, real z, real Radius, boolean HasTop, boolean HasBottom returns nothing
*/
module Circle2D_CreateAll
implement Circle2D_Create
implement Circle2D_CreateAttachedToDest
endmodule
module Circle2D_Create
static method Create takes real x, real y, real z, real Radius, boolean HasTop, boolean HasBottom returns integer
local thistype Object = CreateIndex(x-Radius, x+Radius, y-Radius, y+Radius)
set Object.x = x
set Object.y = y
set Object.z = z
set Object.Radius = Radius
set Object.HasTop = HasTop
set Object.HasBottom = HasBottom
return Object
endmethod
endmodule
module Circle2D_CreateAttachedToDest
static method CreateAttachedToDest takes destructable d, real x, real y, real z, real Radius, boolean HasTop, boolean HasBottom returns nothing
call AttachToDest(d, thistype.Create(x, y, z, Radius, HasTop, HasBottom))
endmethod
private static real temp_z
private static real temp_Radius
private static boolean temp_HasTop
private static boolean temp_HasBottom
private static method InitDestructable takes nothing returns nothing
local destructable d = GetEnumDestructable()
call AttachToDest(d, thistype.Create(GetDestructableX(d), GetDestructableY(d), temp_z, temp_Radius, temp_HasTop, temp_HasBottom))
set d = null
endmethod
private static integer Id
private static method IsDestructable takes nothing returns boolean
return GetDestructableTypeId(GetFilterDestructable()) == Id
endmethod
static method CreateAttachedToDests takes integer DestId, real z, real Radius, boolean HasTop, boolean HasBottom returns nothing
set Id = DestId
set temp_z = z
set temp_Radius = Radius
set temp_HasTop = HasTop
set temp_HasBottom = HasBottom
call EnumDestructablesInRect(GetWorldBounds(), Condition(function thistype.IsDestructable), function thistype.InitDestructable)
endmethod
endmodule
//TESH.scrollpos=0
//TESH.alwaysfold=0
library AAAA
//! textmacro TextSet takes name, variable, text
function $name$ takes $variable$ returns nothing
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, $text$)
endfunction
//! endtextmacro
//! runtextmacro TextSet("Test", "string s", "s")
//! runtextmacro TextSet("text", "string s", "s")
//! runtextmacro TextSet("Real2", "real a, real b", "R2S(a) + \", \" + R2S(b)")
//! runtextmacro TextSet("Real2a", "string s, real a, real b", "s + R2S(a) + \", \" + R2S(b)")
//! runtextmacro TextSet("Real3a", "string s, real a, real b, real c", "s + R2S(a) + \", \" + R2S(b) + \", \" + R2S(c)")
//! runtextmacro TextSet("Integer2", "integer a, integer b", "I2S(a) + \", \" + I2S(b)")
//! runtextmacro TextSet("Integer2a", "string s, integer a, integer b", "s + I2S(a) + \", \" + I2S(b)")
//! runtextmacro TextSet("Integer3a", "string s, integer a, integer b, integer c", "s + I2S(a) + \", \" + I2S(b) + \", \" + I2S(c)")
//! runtextmacro TextSet("Text", "string s", "s")
//! runtextmacro TextSet("Integer", "integer i", "I2S(i)")
//! runtextmacro TextSet("Real", "real r", "R2S(r)")
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library ExampleCreateAndKill initializer init uses SystemUnit, Rectangle3D
globals
Rectangle3D Tree
endglobals
private function GetObjectId takes integer ObjectId returns nothing
call Text("Index " + I2S(ObjectId))
call Rectangle3D.Remove(ObjectId)
endfunction
private function Test takes nothing returns nothing
call Rectangle3D.ForAllObjectsInRectangleArea(-1216, -1088, -576, -448, GetObjectId)
endfunction
private function init takes nothing returns nothing
globals
constant integer INTERFACE = 'n000'
constant integer INGAME = 'n001'
unit Test_Unit
endglobals
local unit u = CreateUnit(Player(0), INGAME, -350, -430, 20)
set Test_Unit = u
call SystemUnit.AttachAll(u)
//call SystemUnit.AttachAllInterface(u, INTERFACE)
set u = null
//__
globals
private constant integer LVL1_BARRELS = 'B01A'
private constant integer LVL2_BARRELS = 'B01B'
private constant integer LVL3_BARRELS = 'B01C'
private constant integer TEST_BARRELS = 'B01D'
endglobals
//Attach Objects to Destructable
call Rectangle3D.CreateAttachedToDests(LVL1_BARRELS, 32, 32, 32, 32, 390, 460)
call Rectangle3D.CreateAttachedToDests(LVL2_BARRELS, 32, 32, 32, 32, 460, 530)
call Rectangle3D.CreateAttachedToDests(LVL3_BARRELS, 32, 32, 32, 32, 530, 600)
call Rectangle3D.CreateAttachedToDests(TEST_BARRELS, 32, 32, 32, 32, 390, 460)
//Tree
set Tree = Rectangle3D.Create(-690, -600, -490, -400, 390, 530)
//Bridge
call Rectangle3D.Create(-626, -240, -1000, -516, 300, 424)
//Dead Bridge
call Rectangle3D.Create(-512, -416, -330, 110, 410, 434)
//Barrels
call Rectangle3D.Create(-160, -96, 160, 224, 345, 420)
call Rectangle3D.Create(-352, -288, -256, -128, 320, 385)
call Rectangle3D.Create(-352, -224, -256, -192, 385, 450)
call Rectangle3D.Create(-288, - 96, -352, -288, 436, 516)
call Rectangle3D.Create(-224, - 32, -608, -352, 436, 516)
call Rectangle3D.Create(140, 116, -224, -160, 336, 416)
call Rectangle3D.Create(126.4, 129.6, -352, -288, 336, 416)
call Rectangle3D.Create(128, 128, -480, -416, 336, 416)
call Circle2D.Create(-156, -732, 452, 70, true, true)
//call RectangleObject.Remove(Tree)
//call Test()
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library SelectLock
struct SelectLock
private static method Lock takes nothing returns nothing
local unit u = GetTriggerUnit()
call DisableTrigger(Select)
if GetOwningPlayer(u) == GetTriggerPlayer() then
call SystemUnit.AttachAll(u)
endif
call EnableTrigger(Select)
set u = null
endmethod
static trigger Select
private static method onInit takes nothing returns nothing
set Select = CreateTrigger()
call TriggerAddAction(Select, function thistype.Lock)
call TriggerRegisterPlayerUnitEvent(Select, Player(0), EVENT_PLAYER_UNIT_SELECTED, null)
endmethod
endstruct
endlibrary