Name | Type | is_array | initial_value |
//TESH.scrollpos=0
//TESH.alwaysfold=0
library Table2
globals
private constant integer MAX_INSTANCES=8100 //400000
private hashtable ht
private gamecache gc
endglobals
private keyword hack
private function SaveString takes hashtable table,integer parentKey,integer childKey,string value returns boolean
return SaveStr(table,parentKey,childKey,value)
endfunction // REMAKING TO FIT THE MACRO!
private function LoadString takes hashtable table,integer parentKey,integer childKey returns string
return LoadStr(table,parentKey,childKey)
endfunction // REMAKING TO FIT THE MACRO!
private struct CachedTable[MAX_INSTANCES]
readonly string sthis
static method create takes nothing returns CachedTable
local CachedTable this = CachedTable.allocate()
set this.sthis = SCOPE_PRIVATE + I2S(this)
return this
endmethod
method reset takes nothing returns nothing
call FlushStoredMission(gc, this.sthis )
endmethod
private method onDestroy takes nothing returns nothing
call FlushStoredMission(gc, this.sthis )
endmethod
static method hack takes string s returns nothing
set CachedTable(0).sthis = s
endmethod
private static method onInit takes nothing returns nothing
call FlushGameCache(InitGameCache("libtable.gc"))
set gc=InitGameCache("libtable.gc")
endmethod
endstruct
private struct GTable[MAX_INSTANCES]
method reset takes nothing returns nothing
call FlushChildHashtable(ht, integer(this) )
endmethod
private method onDestroy takes nothing returns nothing
call this.reset()
endmethod
private static method onInit takes nothing returns nothing
set ht = InitHashtable()
endmethod
endstruct
//! textmacro Table takes type, key, typetwo, keytwo
struct $type$_$typetwo$_Table extends GTable
method operator [] takes $type$ key returns $typetwo$
return Load$keytwo$(ht, integer(this), $key$)
endmethod
method operator []= takes $type$ key, $typetwo$ value returns nothing
call Save$keytwo$(ht, integer(this) ,$key$, value)
endmethod
method flush takes $type$ key returns nothing
call RemoveSaved$keytwo$(ht, integer(this), $key$)
endmethod
method exists takes $type$ key returns boolean
return HaveSaved$keytwo$( ht, integer(this) ,$key$)
endmethod
static method flush2D takes string firstkey returns nothing
call $type$_$typetwo$_Table(- StringHash(firstkey)).reset()
endmethod
static method operator [] takes string firstkey returns $type$_$typetwo$_Table
return $type$_$typetwo$_Table(- StringHash(firstkey) )
endmethod
endstruct
//! endtextmacro
//! textmacro CachedTable takes type, key, typetwo, keytwo
struct $type$_$typetwo$_CachedTable extends CachedTable
method operator [] takes $type$ key returns $typetwo$
return GetStored$keytwo$(gc, this.sthis ,$key$)
endmethod
method operator []= takes $type$ key, $typetwo$ value returns nothing
call Store$keytwo$(gc, this.sthis ,$key$, value)
endmethod
method flush takes $type$ key returns nothing
call FlushStored$keytwo$(gc, this.sthis ,$key$)
endmethod
method exists takes $type$ key returns boolean
return HaveStored$keytwo$(gc, this.sthis ,$key$)
endmethod
static method flush2D takes string firstkey returns nothing
call CachedTable.hack(firstkey)
call $type$_$typetwo$_CachedTable(0).reset()
endmethod
static method operator [] takes string firstkey returns $type$_$typetwo$_CachedTable
call CachedTable.hack(firstkey)
return $type$_$typetwo$_CachedTable(0)
endmethod
endstruct
//! endtextmacro
//! runtextmacro CachedTable("integer", "I2S(key)" , "integer", "Integer" )
//! runtextmacro CachedTable("real" , "R2S(key)" , "integer", "Integer" )
//! runtextmacro CachedTable("string" , "key" , "integer", "Integer" )
//! runtextmacro CachedTable("handle" , "I2S(GetHandleId(key))", "integer", "Integer" )
//! runtextmacro CachedTable("integer", "I2S(key)" , "real", "Real" )
//! runtextmacro CachedTable("real" , "R2S(key)" , "real", "Real" )
//! runtextmacro CachedTable("string" , "key" , "real", "Real" )
//! runtextmacro CachedTable("handle" , "I2S(GetHandleId(key))", "real", "Real" )
//! runtextmacro CachedTable("integer", "I2S(key)" , "string", "String" )
//! runtextmacro CachedTable("real" , "R2S(key)" , "string", "String" )
//! runtextmacro CachedTable("string" , "key" , "string", "String" )
//! runtextmacro CachedTable("handle" , "I2S(GetHandleId(key))", "string", "String" )
//! runtextmacro CachedTable("integer", "I2S(key)" , "boolean", "Boolean" )
//! runtextmacro CachedTable("real" , "R2S(key)" , "boolean", "Boolean" )
//! runtextmacro CachedTable("string" , "key" , "boolean", "Boolean" )
//! runtextmacro CachedTable("handle" , "I2S(GetHandleId(key))", "boolean", "Boolean" )
//! runtextmacro Table("integer", "key" , "integer", "Integer" )
//! runtextmacro Table("string" , "StringHash(key)" , "integer", "Integer" )
//! runtextmacro Table("handle" , "GetHandleId(key)", "integer", "Integer" )
//! runtextmacro Table("integer", "key" , "real", "Real" )
//! runtextmacro Table("string" , "StringHash(key)" , "real", "Real" )
//! runtextmacro Table("handle" , "GetHandleId(key)", "real", "Real" )
//! runtextmacro Table("integer", "key" , "string", "String" )
//! runtextmacro Table("string" , "StringHash(key)" , "string", "String" )
//! runtextmacro Table("handle" , "GetHandleId(key)", "string", "String" )
//! runtextmacro Table("integer", "key" , "boolean", "Boolean" )
//! runtextmacro Table("string" , "StringHash(key)" , "boolean", "Boolean" )
//! runtextmacro Table("handle" , "GetHandleId(key)", "boolean", "Boolean" )
endlibrary
// I don't like vegetables. o_o"
//TESH.scrollpos=0
//TESH.alwaysfold=0
library TerrainPathability initializer Init
//******************************************************************************
//* BY: Rising_Dusk
//*
//* This script can be used to detect the type of pathing at a specific point.
//* It is valuable to do it this way because the IsTerrainPathable is very
//* counterintuitive and returns in odd ways and aren't always as you would
//* expect. This library, however, facilitates detecting those things reliably
//* and easily.
//*
//******************************************************************************
//*
//* > function IsTerrainDeepWater takes real x, real y returns boolean
//* > function IsTerrainShallowWater takes real x, real y returns boolean
//* > function IsTerrainLand takes real x, real y returns boolean
//* > function IsTerrainPlatform takes real x, real y returns boolean
//* > function IsTerrainWalkable takes real x, real y returns boolean
//*
//* These functions return true if the given point is of the type specified
//* in the function's name and false if it is not. For the IsTerrainWalkable
//* function, the MAX_RANGE constant below is the maximum deviation range from
//* the supplied coordinates that will still return true.
//*
//* The IsTerrainPlatform works for any preplaced walkable destructable. It will
//* return true over bridges, destructable ramps, elevators, and invisible
//* platforms. Walkable destructables created at runtime do not create the same
//* pathing hole as preplaced ones do, so this will return false for them. All
//* other functions except IsTerrainWalkable return false for platforms, because
//* the platform itself erases their pathing when the map is saved.
//*
//* After calling IsTerrainWalkable(x, y), the following two global variables
//* gain meaning. They return the X and Y coordinates of the nearest walkable
//* point to the specified coordinates. These will only deviate from the
//* IsTerrainWalkable function arguments if the function returned false.
//*
//* Variables that can be used from the library:
//* [real] TerrainPathability_X
//* [real] TerrainPathability_Y
//*
globals
private constant real MAX_RANGE = 10.
private constant integer DUMMY_ITEM_ID = 'wolg'
endglobals
globals
private item Item = null
private rect Find = null
private item array Hid
private integer HidMax = 0
public real X = 0.
public real Y = 0.
endglobals
function IsTerrainDeepWater takes real x, real y returns boolean
return not IsTerrainPathable(x, y, PATHING_TYPE_FLOATABILITY) and IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY)
endfunction
function IsTerrainShallowWater takes real x, real y returns boolean
return not IsTerrainPathable(x, y, PATHING_TYPE_FLOATABILITY) and not IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY) and IsTerrainPathable(x, y, PATHING_TYPE_BUILDABILITY)
endfunction
function IsTerrainLand takes real x, real y returns boolean
return IsTerrainPathable(x, y, PATHING_TYPE_FLOATABILITY)
endfunction
function IsTerrainPlatform takes real x, real y returns boolean
return not IsTerrainPathable(x, y, PATHING_TYPE_FLOATABILITY) and not IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY) and not IsTerrainPathable(x, y, PATHING_TYPE_BUILDABILITY)
endfunction
private function HideItem takes nothing returns nothing
if IsItemVisible(GetEnumItem()) then
set Hid[HidMax] = GetEnumItem()
call SetItemVisible(Hid[HidMax], false)
set HidMax = HidMax + 1
endif
endfunction
function IsTerrainWalkable takes real x, real y returns boolean
//Hide any items in the area to avoid conflicts with our item
call MoveRectTo(Find, x, y)
call EnumItemsInRect(Find ,null, function HideItem)
//Try to move the test item and get its coords
call SetItemPosition(Item, x, y) //Unhides the item
set X = GetItemX(Item)
set Y = GetItemY(Item)
static if LIBRARY_IsTerrainWalkable then
//This is for compatibility with the IsTerrainWalkable library
set IsTerrainWalkable_X = X
set IsTerrainWalkable_Y = Y
endif
call SetItemVisible(Item, false)//Hide it again
//Unhide any items hidden at the start
loop
exitwhen HidMax <= 0
set HidMax = HidMax - 1
call SetItemVisible(Hid[HidMax], true)
set Hid[HidMax] = null
endloop
//Return walkability
return (X-x)*(X-x)+(Y-y)*(Y-y) <= MAX_RANGE*MAX_RANGE and not IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY)
endfunction
private function Init takes nothing returns nothing
set Find = Rect(0., 0., 128., 128.)
set Item = CreateItem(DUMMY_ITEM_ID, 0, 0)
call SetItemVisible(Item, false)
endfunction
endlibrary
//TESH.scrollpos=108
//TESH.alwaysfold=0
/*-----------------------------------------------------------------------------------*\
| Simple Velocity System |
| by Vercas |
| requires: - TerrainPathability |
| by Rising_Dusk |
| - Table2 |
| by Vercas (me) |
| |
| This is meant to be a simple velocity system for other people to use in their |
| systems or just to knock the hell out of units! |
| |
| |
| Application Programming Interface (API): |
| |
| Vel.add( unit, x, y, z ) -> nothing |
| This sets a unit's velocity to your given values DIVIDED BY 20!! |
| For safety reasons! |
| Vel.addAng( unit, ground angle, air angle, distance ) -> nothing |
| This calculates and sets the unit's velocity to the given values. |
| This is a 3D polar projection formula, and I hope you understand it! |
\*-----------------------------------------------------------------------------------*/
/**/library Velocity initializer Init requires TerrainPathability, Table2/***********/
struct Vel
static constant real INTERVAL = 0.01 //100 times per second.
static constant real REDUCTION = 0.03 //3%
static constant boolean ADD_CROW_FORM = true //To enable Z-axis velocity!
static handle_real_Table x
static handle_real_Table y
static handle_real_Table z
static trigger engine = CreateTrigger ( )
static group flyers = CreateGroup ( )
static location L = Location ( 0, 0 )
static method set takes unit u, real a, real b, real c returns nothing
set Vel.x[u] = a / 20
set Vel.y[u] = b / 20
set Vel.z[u] = c / 20
endmethod
static method add takes unit u, real a, real b, real c returns nothing
set Vel.x[u] = Vel.x[u] + a / 20
set Vel.y[u] = Vel.y[u] + b / 20
set Vel.z[u] = Vel.z[u] + c / 20
endmethod
static method setAng takes unit u, real yaw, real pitch, real distance returns nothing
local real ld = distance * Cos ( pitch * bj_DEGTORAD )
local real lz = distance * Sin ( pitch * bj_DEGTORAD )
local real lx = ld * Cos ( yaw * bj_DEGTORAD )
local real ly = ld * Sin ( yaw * bj_DEGTORAD )
set Vel.x[u] = lx
set Vel.y[u] = ly
set Vel.z[u] = lz
endmethod
static method addAng takes unit u, real yaw, real pitch, real distance returns nothing
local real ld = distance * Cos ( pitch * bj_DEGTORAD )
local real lz = distance * Sin ( pitch * bj_DEGTORAD )
local real lx = ld * Cos ( yaw * bj_DEGTORAD )
local real ly = ld * Sin ( yaw * bj_DEGTORAD )
set Vel.x[u] = Vel.x[u] + lx
set Vel.y[u] = Vel.y[u] + ly
set Vel.z[u] = Vel.z[u] + lz
endmethod
private static method Throw takes nothing returns nothing
local unit u = GetEnumUnit ( )
local real ux = GetUnitX ( u )
local real uy = GetUnitY ( u )
local real uz = GetUnitFlyHeight ( u )
local real vx = Vel.x[u]
local real vy = Vel.y[u]
local real vz = Vel.z[u]
local real tx = ux + vx
local real ty = uy + vy
local real tz
local real red = 1. - Vel.REDUCTION
if IsTerrainWalkable ( tx, uy ) then
call SetUnitX ( u, tx )
endif
if IsTerrainWalkable ( ux, ty ) then
call SetUnitY ( u, ty )
endif
if vz > 1. then
call MoveLocation ( Vel.L, GetUnitX( u ), GetUnitY( u ) )
set tz = uz+vz-GetLocationZ ( Vel.L )
call MoveLocation ( Vel.L, ux, uy )
set tz = tz +GetLocationZ ( Vel.L )
call SetUnitFlyHeight ( u , tz, 0. )
set Vel.z[u] = vz * red
elseif vz > 0.01 then
set Vel.z[u] = -0.1
elseif vz < 0. and uz > 0. then
set vz = vz * ( 1.0 + Vel.REDUCTION )
if uz > vz then
call SetUnitFlyHeight ( u, uz + vz, 0. )
else
call SetUnitFlyHeight ( u, 0. , 0. )
set vz = 0.
endif
set Vel.z[u] = vz
endif
if -0.5 < vx and vx < 0.5 then
set Vel.x[u] = 0.
else
set Vel.x[u] = vx * red
endif
if -0.5 < vy and vy < 0.5 then
set Vel.y[u] = 0.
else
set Vel.y[u] = vy * red
endif
set u = null
endmethod
private static method Check takes nothing returns boolean
local unit u = GetFilterUnit ( )
local boolean b = ( Vel.x[u] != 0. or Vel.y[u] != 0. or Vel.z[u] != 0. )
set u = null
return b
endmethod
private static method Prepare takes nothing returns nothing
call GroupClear ( Vel.flyers )
call GroupEnumUnitsInRect ( Vel.flyers, bj_mapInitialPlayableArea, Condition( function Vel.Check ) )
call ForGroup ( Vel.flyers, function Vel.Throw )
endmethod
static method setup takes nothing returns nothing
set .x = handle_real_Table.create ( )
set .y = handle_real_Table.create ( )
set .z = handle_real_Table.create ( )
call TriggerRegisterTimerEvent ( Vel.engine, Vel.INTERVAL, true )
call TriggerAddAction ( Vel.engine, function Vel.Prepare )
endmethod
endstruct
private function AddCrow takes nothing returns nothing
local unit u = GetTriggerUnit ( )
call UnitAddAbility ( u, 'Amrf' )
call UnitRemoveAbility ( u, 'Amrf' )
set u = null
endfunction
private function Cond takes nothing returns boolean
return GetUnitAbilityLevel ( GetFilterUnit( ), 'Amrf' ) == 0
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger ( )
local region r = CreateRegion ( )
if Vel.ADD_CROW_FORM then
call RegionAddRect ( r, GetWorldBounds( ) )
call TriggerRegisterEnterRegion ( t, r, Condition( function Cond ) )
call TriggerAddAction ( t, function AddCrow )
endif
call Vel.setup ( )
set t = null
set r = null
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_Jump_Conditions takes nothing returns boolean
if ( not ( GetSpellAbilityId() == 'A000' ) ) then
return false
endif
return true
endfunction
function Trig_Jump_Actions takes nothing returns nothing
call Vel.setAng( GetTriggerUnit( ), GetUnitFacing( GetTriggerUnit( ) ), 40., 10. ) // DO NOT USE HIGHER VALUES!
endfunction
//===========================================================================
function InitTrig_Jump takes nothing returns nothing
set gg_trg_Jump = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Jump, EVENT_PLAYER_UNIT_SPELL_CAST )
call TriggerAddCondition( gg_trg_Jump, Condition( function Trig_Jump_Conditions ) )
call TriggerAddAction( gg_trg_Jump, function Trig_Jump_Actions )
call CreateUnit( Player(0), 'hfoo', 0., 0., 0. )
endfunction