- Joined
- Nov 25, 2008
- Messages
- 1,309
JASS:
//***************************************************************************
// Code: Dot System
//***************************************************************************
function Dot_Delete takes unit Dot returns nothing
local integer Did=GetUnitUserData(Dot)
local player P=GetOwningPlayer(Dot)
local integer DID=udg_Dot_Death[Did]
set udg_Ids[Did]=udg_Ids[0]
set udg_Ids[0]=Did
if DID!=0then
call CreateUnit(P,DID,GetUnitX(Dot),GetUnitY(Dot),GetUnitFacing(Dot))
endif
endfunction
function Dot_Loop takes nothing returns nothing
// ***** Local variables *****
// Main variables
local boolean Ok
local boolean DUD
local real Dmg
local integer Did
local unit Dot // Iterated effect unit.
local unit Tar // Iterated effect's target.
set udg_Dot_Run=true
// ***** Iterate over all dots *****
loop
// ***** Set-up loop *****
set Dot=FirstOfGroup(udg_Groups[0])
exitwhen Dot==null
call GroupRemoveUnit(udg_Groups[0],Dot)
// ***** Handle dot *****
if IsUnitType(Dot,UNIT_TYPE_DEAD)or GetUnitTypeId(Dot)==0 then
call Dot_Delete(Dot)
else
set DUD=IsUnitType(Dot,UNIT_TYPE_UNDEAD)
set Did=GetUnitUserData(Dot)
set udg_Dot_Run=false
set Dmg=udg_Dot_Dmg[Did]
// ***** Damage targets *****
call GroupEnumUnitsInRange(udg_Groups[5],GetUnitX(Dot),GetUnitY(Dot),udg_Dot_AoE[Did],null)
loop
// ***** Damage loop set-up *****
set Tar=FirstOfGroup(udg_Groups[5])
exitwhen Tar==null
call GroupRemoveUnit(udg_Groups[5],Tar)
// ***** Handle dot's target *****
call DisplayTextToPlayer(Player(0),0,0,"Target: "+GetUnitName(Tar)+".")
if (IsUnitType(Tar,UNIT_TYPE_DEAD)or GetUnitTypeId(Tar)==0or GetUnitAbilityLevel(Tar,'A002')>0)==false then
if DUD then
set Ok=(IsUnitType(Tar,UNIT_TYPE_UNDEAD)or(IsUnitType(Tar,UNIT_TYPE_STRUCTURE)==true))==false
else
set Ok=true
endif
if Ok then
if GetUnitAbilityLevel(Tar,'A003')>0then // Target is flammable, kill them.
call DisplayTextToPlayer(Player(0),0,0,"Dot killed dot.")
call KillUnit(Tar)
else // Target is not flammable, damage them.
call UnitDamageTarget(Dot,Tar,Dmg,false,false,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
endif
endif
endif
// ***** Damage loop clean-up *****
set Tar=null
endloop
// ***** Clean-up *****
call SetWidgetLife(Dot,GetWidgetLife(Dot)-.25)
call GroupAddUnit(udg_Groups[3],Dot)
endif
// ***** Clean-up loop *****
set Dot=null
endloop
// ***** Restart timer as needed *****
if udg_Dot_Run then
call DestroyTimer(GetExpiredTimer()) // Clean-up timer.
else
call TimerStart(GetExpiredTimer(),.25,false,function Dot_Loop) // Restart timer.
endif
// ***** Clean-up *****
set udg_Groups[4]=udg_Groups[0]
set udg_Groups[0]=udg_Groups[3]
set udg_Groups[3]=udg_Groups[4]
set udg_Groups[4]=null
endfunction
function Dot_New takes unit U,real Dmg,real AoE,integer Did returns nothing
local integer New=udg_Ids[0]
set udg_Ids[0]=udg_Ids[New]
set udg_Dot_Dmg[New]=Dmg
set udg_Dot_AoE[New]=AoE
set udg_Dot_Death[New]=Did
call SetUnitUserData(U,New)
call GroupAddUnit(udg_Groups[0],U)
if udg_Dot_Run then
set udg_Dot_Run=false
call TimerStart(CreateTimer(),0.25,false,function Dot_Loop)
endif
endfunction
function Dot_Init takes nothing returns nothing
local integer i=0
set udg_Groups[1]=CreateGroup()
set udg_Groups[2]=CreateGroup()
set udg_Groups[0]=udg_Groups[1]
set udg_Groups[3]=udg_Groups[2]
set udg_Groups[5]=CreateGroup()
set udg_Ids[8191]=0
loop
set udg_Ids[i]=i+1
exitwhen i==8190
set i=i+1
endloop
endfunction
I have several units that I turn into 'dots'. A dot is a unit that constantly damages all nearby units around it. The ability 'A002' is my flag to disallow certain units from being damaged by dots, it's used to stop dots from damaging other dots. The ability 'A003' is a flag to tell instead of damaging the dot, kill it instead. Is a dot is undead, then it can't damage buildings, or other undead units. The problem is that my non-undead dots are not killing my flammable, undead dots. These flammable, undead dots do not have 'A002'.
Any suggestions?