- Joined
- Apr 1, 2010
- Messages
- 289
here is the code
the leaks it has involve trigger leaks(which i don't know how to remove)
i am pretty sure all other leaks are handled there are three unit groups used, one of which is destroyed the other 2 are permanent.
all special effect are destroyed and the vars are nulled.
and no locations are used.
JASS:
//==================================================================================================================\\
// ____ ______ _____ _ \\
// / __ \ | ___ \ | __ \ _ | | \\
// /__/ \ \ | | \ \ | | \ | | | | | \\
// | | | | \ || |__/ | _ _ ___ _ ___ _____ __| |__ _ | | ___ \\
// / / | | | || ____/ | |/ __\ / _ \ |_| / __ \ / __/ |__ __| |_| | | / __ \ \\
// / / | | | || | | / | / \ | _ | / _| | | / | | _ | | | / _| | \\
// / / | | / || | | | | | | | | | | |/_ / | | | | | | | | | |/_ / \\
// / /_____ | |___/ / | | | | | \_/ | | | | \___ | \____ | | | | | | | \___ \\
// |_________| |______/ |_| |_| \ ___ / | | \ ____| \ ___ / |_| |_| |_| \ ____| \\
// ____ _ / | \\
// / __ \ \ _ / _ \\
// | / \__| | | \\
// \ \ __ __ __ __| |__ ___ __ __ \\
// \ \ \ \ / / / _ \ |__ __| / __ \ | \/ | \\
// \ \ \ / | / \ | | | / _| | | |\ /| | \\
// __ \ \ | | \ \ | | | |/_ / | | \/ | | \\
// | \_/ | | | _/ | | | | \___ | | | | \\
// \ ___ / |_| \ __ / |_| \ ____| |_| |_| \\
// \\
// ______ \\
// | __ \ \\
// | | | | __ __ \\
// | | / / \ \ / / \\
// | | \ \ \ / \\
// | | | | | | \\
// | |__| | | | \\
// |_____ / |_| \\
// _ _ \\
// | \ | | \\
// | \ | | \\
// | |\ \ | | ____ _ _ ___ ____ ___ ____ \\
// | | \ \ | | |___ \ | |/ __\ / _ \ / ___ | / _ \ / ___ | \\
// | | \ \ | | ___| | | / | / \ | | | | | | / \ || | | | \\
// | | \ \| | / _ | | | | | | | | | | | | | | || | | | \\
// | | \ | | (_) | | | | \ _ / | | |___| | | \ _ / || |___| | \\
// |_| \__| \ ___/ |_| \ ___ / \ ___ | \ ___ / \ ___ | \\
// | | | | \\
// ___ / / __ / / \\
// |____/ |___/ \\
// \\
//====================================================================================================================
//2d projectile system By Narogog,
//=======================================================
//
//version 0.1b
//
//importing
// copy and paste the trigger entiled "Variables" after doing so you can delete it.
// copy and paste this to the maps header
// copy and paste MS to your map
// Give Credits
// if you want to modify this go ahead. but Give credits.
//
//
//
//User variables
//
//=============================================================================
// udg_Proj_CollisionEvent (real) *
//is used to trigger collision events *
// when its =0.00 a projectile has collided with a unit collision has occured *
// when its = 1.00 a projectile collision occured *
// when its = 2.00 a unit has collided with a unit *
// when its = 3.00 a projectile has ran out of fuel, *
// when its = 3.50 its target has died *
// when its = 4.00 a unit has left the playable map *
//=============================================================================
//
//====================================================================
// udg_Proj_CollisionUnit (unit) *
// is the unit that is being hit *
// used in all collisions *
//====================================================================
//
//====================================================================
// udg_Proj_CollidingU (unit) *
// is the projectile that is colliding *
// used in 1,2 *
//====================================================================
//
//====================================================================
// udg_Proj_CollisionIndex (int) *
// the index of the projectile, used with 1,3,3.5,4 *
// used with call Proj_deallocate(udg_Proj_CollisionIndex) to "kill" *
// the projectile *
//====================================================================
//
//====================================================================
// udg_Proj_CollisionIndex2 (int) *
// used only in projectile collisions ie 2 *
//====================================================================
//
//====================================================================
// Proj_deallocate (function) *
// how to use just call Proj_deallocate(projindex) *
// where projindx is LoadInteger(udg_Proj,GetHandleId(someProj),1) *
// what does this do? well it "destroys" the projectile *
// make sure you nullify all data connected to the projectile *
//====================================================================
//
//====================================================================
// CreateProjectile (function) *
// to use *
// set udg_I CreateProjectile(owner,x,y,facing,speed,life,attach, *
// modelpath, 0,null) *
// then you can use udg_I as the index of an array, import get rid of*
// all data connected to the projectile. before deallocating it *
//====================================================================
//
//====================================================================
// udg_Proj_Target[array] (unit) *
// use this when setting a new target for a projectile *
// CAUTION only use udg_CollisionIndex for changing this *
// to prevent interfering with another projectile *
//====================================================================
// end of user vars begining of system variables *
//
//
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//udg_Proj_Group (group) *
// this is the lazy projectile group *
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//udg_Proj_Leave_Map (group) *
// this is a group that contains all units who have left the map *
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//udg_Proj_NotCollidable (group) *
// this contains units that cannot be collided with *
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//end of system vars(for now)
//
//do NOT modify the following values
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// udg_Proj_Group_Count (integer) *
// this is just the number of lazy projectiles *
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//udg_ProjMax (integer) *
//number of active projectiles *
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//
//
//Currently there is only one global collision size.
//
//
//currently does NOT support Terrain wall collisions.
//currently does Not support Destructible collisions.
//
// Allocate
function Proj_allocate takes nothing returns integer
// allocate it
local integer this
if udg_Proj_instanceRecycle == 0 then
set udg_Proj_instanceCount = udg_Proj_instanceCount + 1
set this = udg_Proj_instanceCount
else
set this = udg_Proj_instanceRecycle
set udg_Proj_instanceRecycle = udg_Proj_recycleNext[this]
endif
// add it to the list
set udg_Proj_next[this] = 0
set udg_Proj_prev[this] = udg_Proj_prev[0]
set udg_Proj_next[udg_Proj_prev[0]] = this
set udg_Proj_prev[0] = this
// return the new instance
return this
endfunction
// deallocate:
function Proj_deallocate takes integer this returns nothing
// deallocate it
if this == 0 then
else
set udg_Proj_recycleNext[this] = udg_Proj_instanceRecycle
set udg_Proj_instanceRecycle = this
// remove it from the list
set udg_Proj_next[udg_Proj_prev[this]] = udg_Proj_next[this]
set udg_Proj_prev[udg_Proj_next[this]] = udg_Proj_prev[this]
set udg_Proj_Max = udg_Proj_Max - 1
call ShowUnit(udg_Proj_U[this],false)// making it visible
set udg_Proj_Group_Count= udg_Proj_Group_Count +1
call GroupAddUnit(udg_Proj_Group,udg_Proj_U[this])
call GroupAddUnit(udg_Proj_NotCollidable,udg_Proj_U[this])
call SaveInteger(udg_Proj,GetHandleId(udg_Proj_U[this]),1,0)
call DestroyEffect(udg_Proj_E[this])
call DisableTrigger(LoadTriggerHandle(udg_Proj,GetHandleId(udg_Proj_U[this]),0))
set udg_Proj_Target[this] = null
set udg_Proj_E[this]=null
endif
endfunction
function Proj_Collision takes nothing returns boolean//this triggers the collision event
local unit u = GetTriggerUnit()
set udg_Proj_CollisionUnit = LoadUnitHandle(udg_Proj,GetHandleId(GetTriggeringTrigger()),0)
if not IsUnitInGroup(u,udg_Proj_NotCollidable) and not IsUnitType(u, UNIT_TYPE_DEAD) and not IsUnitType(udg_Proj_CollisionUnit, UNIT_TYPE_DEAD) then
//this checks to see if it is a projectile collision, ie only projectiles are involved.
if GetUnitTypeId(udg_Proj_CollisionUnit) == udg_Proj_UnitId then
if GetUnitTypeId(u) == udg_Proj_UnitId then
set udg_Proj_CollisionIndex=LoadInteger(udg_Proj,GetHandleId(udg_Proj_CollisionUnit),1)
set udg_Proj_CollisionIndex2=LoadInteger(udg_Proj,GetHandleId(u),1)
set udg_Proj_CollidingU = u
set udg_Proj_CollisionEvent = 1
else
set udg_Proj_CollidingU = udg_Proj_CollisionUnit
set udg_Proj_CollisionUnit=u
set udg_Proj_CollisionIndex=LoadInteger(udg_Proj,GetHandleId(udg_Proj_CollidingU),1)
set udg_Proj_CollisionEvent = 0
endif
else
set udg_Proj_CollidingU=u
if GetUnitTypeId(udg_Proj_CollidingU) != udg_Proj_UnitId then
set udg_Proj_CollisionEvent = 2
else
set udg_Proj_CollisionIndex=LoadInteger(udg_Proj,GetHandleId(udg_Proj_CollidingU),1)
set udg_Proj_CollisionEvent = 0
endif
endif
set udg_Proj_CollisionEvent = -1
endif
set u = null
return false
endfunction
// CreateProjectile takes player owner of projectile, real x coord, real y coord, real facing, real speed, real how long the projectile lasts, string attachement string ie "origin", string model
function CreateProjectile takes player p, real x, real y, real f, real s, real l, string a, string e,unit target, real rate returns integer
local integer i = Proj_allocate()
if udg_Proj_Max == 0 then
call EnableTrigger(gg_trg_MS)
endif
set udg_Proj_Max = udg_Proj_Max +1
if udg_Proj_Group_Count==0 then// if there are no enough projectiles that are idle it creates one
set udg_Proj_U[i] = CreateUnit(p,udg_Proj_UnitId,x,y,f)
call PauseUnit(udg_Proj_U[i],true)// pausing unit so user can't issue it orders, Unit in range does not detect units with 'aloc' so i am not giving the units 'aloc'
set udg_Proj_T = CreateTrigger()
call TriggerRegisterUnitInRange( udg_Proj_T, udg_Proj_U[i],60, null)// you can modify collision size here
call TriggerAddCondition(udg_Proj_T, LoadBooleanExprHandle(udg_Proj,1,1))
call SaveTriggerHandle(udg_Proj,GetHandleId(udg_Proj_U[i]),0,udg_Proj_T) // saving trigger etc...
call SaveUnitHandle(udg_Proj,GetHandleId(udg_Proj_T),0,udg_Proj_U[i])
else
loop
set udg_Proj_U[i] = FirstOfGroup(udg_Proj_Group) // other wise it just gets one from Missle group
call GroupRemoveUnit(udg_Proj_Group, udg_Proj_U[i])
exitwhen udg_Proj_U[i] != null
endloop
set udg_Proj_Group_Count = udg_Proj_Group_Count - 1
call SetUnitX(udg_Proj_U[i],x)// seting projectiles position
call SetUnitY(udg_Proj_U[i],y)
call SetUnitFacing(udg_Proj_U[i],f)//setting its facing
call SetUnitOwner(udg_Proj_U[i],p,true)//setting owner
call ShowUnit(udg_Proj_U[i],true)// making it visible
call EnableTrigger(LoadTriggerHandle(udg_Proj,GetHandleId(udg_Proj_U[i]),0))
call GroupRemoveUnit(udg_Proj_NotCollidable,udg_Proj_U[i])
endif
call SaveInteger(udg_Proj,GetHandleId(udg_Proj_U[i]),1,i)
set udg_Proj_Y[i] =((Sin(f*bj_DEGTORAD))*s)// setting Y coordinate speed
set udg_Proj_X[i] =((Cos(f*bj_DEGTORAD))*s)// setting X coordinate speed
set udg_Proj_Life[i] = l//setting "timed" life if you want it to travel a certain distance then the furmula would be distance/speed per second or distance/(speed/.03)
set udg_Proj_E[i] = AddSpecialEffectTarget(e,udg_Proj_U[i],a)
set udg_Proj_Target[i] = target
set udg_Proj_TurnSpeed[i] = rate
set udg_Proj_Speed[i] = s
if udg_Proj_Target[i] != null then
set udg_Proj_Turn_D[i] = ((360/rate) * (s/3.14) )*2
endif
return i
endfunction
//=======================================================
//End of Narogog's 2d Projectile System v 0.4.0.0
//======================================================
JASS:
function Angles_MoveAngleTowardsAngle takes real a1, real a2, real i returns real // copied from jasscraft
local real x
set a1=ModuloReal(a1,360)
set a2=ModuloReal(a2,360)
if a1>a2 then
set x=a1-360
if a1-a2 > a2-x then
set a1=x
endif
else
set x=a2-360
if a2-a1 > a1-x then
set a2=x
endif
endif
if a1>a2 then
set x=a1-i
if x<=a2 then
return a2
endif
return x
endif
set x=a1+i
if x>=a2 then
return a2
endif
return x
endfunction
function Trig_MS_Actions takes nothing returns boolean
local integer this = udg_Proj_next[0]
local real x
local real y
local real xt
local real yt
local real a
local real a2
local real r
local real r1
local real r2
if udg_Proj_Max == 0 then
call DisableTrigger(gg_trg_MS)
endif
loop
exitwhen 0 == this
set udg_Proj_Life[this] = udg_Proj_Life[this]-.03
if 0 > udg_Proj_Life[this] then
set udg_Proj_CollisionUnit = udg_Proj_U[this]
set udg_Proj_CollisionIndex = this
set udg_Proj_CollisionEvent = 3.00
set udg_Proj_CollisionEvent = -1.00
call Proj_deallocate(this)
else
set x = GetUnitX(udg_Proj_U[this])
set y = GetUnitY(udg_Proj_U[this])
if null != udg_Proj_Target[this] then // this for Projectile tracking, if you don't want it delete this condition segment and all local vars other then this.
if GetUnitState(udg_Proj_U[this], UNIT_STATE_LIFE) > 1 then
set xt = GetUnitX(udg_Proj_Target[this])
set yt = GetUnitY(udg_Proj_Target[this])
set r1 = xt-x
set r2 = yt-y
set a = (Atan2(r2,r1)*bj_RADTODEG)
set a2 = GetUnitFacing(udg_Proj_U[this])
call DisplayTextToPlayer(Player(0),0,0,R2S(Acos(Cos(a-a2))*bj_RADTODEG))
if Acos(Cos(a-a2))*bj_RADTODEG > 10*udg_Proj_TurnSpeed[this] and IsUnitInRange(udg_Proj_U[this],udg_Proj_Target[this], udg_Proj_Turn_D[this]) then
else
set a2 = Angles_MoveAngleTowardsAngle(a2,a,udg_Proj_TurnSpeed[this])
set udg_Proj_Y[this] =((Sin(a2*bj_DEGTORAD))*udg_Proj_Speed[this])// setting Y coordinate speed
set udg_Proj_X[this] =((Cos(a2*bj_DEGTORAD))*udg_Proj_Speed[this])// setting X coordinate speed
call SetUnitFacing(udg_Proj_U[this],a2)
endif
else
set udg_Proj_CollisionUnit = udg_Proj_U[this]
set udg_Proj_CollisionIndex = this
set udg_Proj_CollidingU = udg_Proj_Target[this]
set udg_Proj_CollisionEvent = 3.50
set udg_Proj_CollisionEvent =-1.00
endif
endif
call SetUnitX(udg_Proj_U[this],x+udg_Proj_X[this])
call SetUnitY(udg_Proj_U[this],y+udg_Proj_Y[this])
endif
set this = udg_Proj_next[this]
endloop
return false
endfunction
// registers collision events for units entering the map
//made some comments here
function Proj_CreateCollision takes nothing returns boolean
local unit u = GetTriggerUnit()
if(IsUnitInGroup(u, udg_Proj_LeaveMap)) then // checking to see if the unit left the map.
call GroupRemoveUnit(udg_Proj_LeaveMap, u)
else
if GetUnitTypeId(u) != udg_Proj_UnitId and GetUnitAbilityLevel(u,'aloc') == 0 then
set udg_Proj_T = CreateTrigger()
//
call TriggerRegisterUnitInRange( udg_Proj_T, u,60, null)// you can modify collision size here
call TriggerAddCondition(udg_Proj_T, LoadBooleanExprHandle(udg_Proj,1,1))
call SaveTriggerHandle(udg_Proj,GetHandleId(u),0,udg_Proj_T)
call SaveUnitHandle(udg_Proj,GetHandleId(udg_Proj_T),0,u)
//
endif
endif
set u = null
return false
endfunction
function Proj_UnitDies takes nothing returns boolean
local unit u = GetTriggerUnit()
local trigger t =LoadTriggerHandle(udg_Proj,GetHandleId(u),0)
call FlushChildHashtable(udg_Proj,GetHandleId(t))
call DestroyTrigger(t)
call FlushChildHashtable(udg_Proj,GetHandleId(u))
set u = null
return false
endfunction
function Proj_LeaveMap takes nothing returns boolean
set udg_Proj_CollisionUnit = GetTriggerUnit()
call GroupAddUnit(udg_Proj_LeaveMap,udg_Proj_CollisionUnit)
set udg_Proj_CollisionIndex = LoadInteger(udg_Proj,GetHandleId(udg_Proj_CollisionUnit),1)
set udg_Proj_CollisionEvent = 4.00
return false
endfunction
//function Proj_DestructableCollision takes nothing returns nothing
//
//endfunction
//========================================================================
function InitTrig_MS takes nothing returns nothing
local region r = CreateRegion()
local group g
local unit u
local boolexpr b = Condition(function Proj_Collision)
set udg_Proj = InitHashtable()
call SaveBooleanExprHandle(udg_Proj,1,1,b)
set udg_Proj_UnitId = 'h000'
call RegionAddRect(r, GetWorldBounds())
set gg_trg_MS = CreateTrigger( )
call TriggerRegisterTimerEvent(gg_trg_MS, 0.0312500, true)
call TriggerAddCondition( gg_trg_MS, Condition(function Trig_MS_Actions) )
call TriggerRegisterEnterRegion(CreateTrigger(), r, Condition(function Proj_CreateCollision))
call TriggerRegisterLeaveRegion(CreateTrigger(), r, Condition(function Proj_LeaveMap))
set udg_Proj_T = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ (udg_Proj_T, EVENT_PLAYER_UNIT_DEATH)
call TriggerAddCondition(udg_Proj_T,Condition(function Proj_UnitDies))
set g = GetUnitsInRectAll(GetPlayableMapRect())
loop
set u = FirstOfGroup(g)
exitwhen u == null
set udg_Proj_T = CreateTrigger()
call TriggerRegisterUnitInRange( udg_Proj_T, u,60, null)// you can modify collision size here, what would be best to do is set an array or hash table with all the units collision size saved.
call TriggerAddCondition(udg_Proj_T, b)
call SaveTriggerHandle(udg_Proj,0,GetHandleId(u),udg_Proj_T)
call SaveUnitHandle(udg_Proj,0,GetHandleId(udg_Proj_T),u)
call GroupRemoveUnit(g,u)
endloop
call DestroyGroup(g)
endfunction
i am pretty sure all other leaks are handled there are three unit groups used, one of which is destroyed the other 2 are permanent.
all special effect are destroyed and the vars are nulled.
and no locations are used.
Attachments
Last edited: