offline
Опыт:
86
Активность:
|
На этот раз структуры
Уже где-то с десятого раза не удается разобраться со структурами. Не могу найти ни одной ошибки в коде, однако карта становится нерабочей. Скажите, пожалуйста, в чем дело? Заранее спасибо.
» код
Код:
globals
meteo_spell meteo
gamecache spell_db = InitGameCache("circle")
endglobals
library RBs
function Ti2S takes timer T returns string
return T
return ""
endfunction
function T2S takes trigger T returns string
return T
return ""
endfunction
function S2T takes string S returns trigger
local trigger T
return S
return T
endfunction
function U2S takes unit U returns string
return U
return ""
endfunction
function S2U takes string S returns unit
local unit U
return S
return U
endfunction
function PolarZ takes real left, real dist returns real
local real r = dist / 2
local real Z = 4 * left * r * (1 - left / dist) / dist
return Z
endfunction
function PolarX takes real x, real dist, real ang returns real
return x + dist * Cos(ang * bj_DEGTORAD)
endfunction
function PolarY takes real y, real dist, real ang returns real
return y + dist * Sin(ang * bj_DEGTORAD)
endfunction
function DistanceBetweenCoords takes real aX, real aY, real bX, real bY returns real
local real dx = bX - aX
local real dy = bY - aY
return SquareRoot(dx * dx + dy * dy)
endfunction
function AngleBetweenCoords takes real aX, real aY, real bX, real bY returns real
return bj_RADTODEG * Atan2(bY - aY, bX - aX)
endfunction
endlibrary
library Actions uses RBs
function trig_rotate_action takes nothing returns nothing
call meteo.rotation()
endfunction
function trig_collision_action takes nothing returns nothing
call meteo.boom()
endfunction
function timer_destroy_trigger takes nothing returns nothing
call DestroyTrigger(S2T(GetStoredString(spell_db, "StoredTrigged", Ti2S(GetExpiredTimer()))))
call FlushStoredString(spell_db, "StoredTrigger", Ti2S(GetExpiredTimer()))
call DestroyTimer(GetExpiredTimer())
endfunction
function timer_destroy_index takes nothing returns nothing
local integer i = S2I(GetStoredString(spell_db, "StoredIndex", Ti2S(GetExpiredTimer())))
call FlushStoredString(spell_db, "StoredIndex", Ti2S(GetExpiredTimer()))
call DestroyTimer(GetExpiredTimer())
call meteo.remove_index(i)
endfunction
endlibrary
library Spells initializer InitTrig_Library uses RBs, Actions
struct meteo_spell
unit caster
unit array meteo[4]
real distance
real step
real array angle[4]
trigger rotate
trigger remove
trigger array collision[4]
static method starts takes unit whichCaster returns nothing
local meteo_spell i = meteo_spell.allocate()
local real x = GetUnitX(whichCaster)
local real y = GetUnitY(whichCaster)
local player owner = GetOwningPlayer(whichCaster)
// =============================
set i.caster = whichCaster
set i.distance = 150
set i.step = 0.0
// =============================
set i.meteo[0] = CreateUnit(owner, 'ewsp', PolarX(x, i.distance, 0.00), PolarY(y, i.distance, 0.00), 0)
call UnitAddAbility(i.meteo[0], 'Amrf')
call UnitRemoveAbility(i.meteo[0], 'Amrf')
call UnitApplyTimedLife(i.meteo[0], 'BTLF', 20)
set i.angle[0] = 0.00
set i.meteo[1] = CreateUnit(owner, 'ewsp', PolarX(x, i.distance, 90.00), PolarY(y, i.distance, 90.00), 0)
call UnitAddAbility(i.meteo[1], 'Amrf')
call UnitRemoveAbility(i.meteo[1], 'Amrf')
call UnitApplyTimedLife(i.meteo[1], 'BTLF', 20)
set i.angle[1] = 90.00
set i.meteo[2] = CreateUnit(owner, 'ewsp', PolarX(x, i.distance, 180.00), PolarY(y, i.distance, 180.00), 0)
call UnitAddAbility(i.meteo[2], 'Amrf')
call UnitRemoveAbility(i.meteo[2], 'Amrf')
call UnitApplyTimedLife(i.meteo[2], 'BTLF', 20)
set i.angle[2] = 180.00
set i.meteo[3] = CreateUnit(owner, 'ewsp', PolarX(x, i.distance, 270.00), PolarY(y, i.distance, 270.00), 0)
call UnitAddAbility(i.meteo[3], 'Amrf')
call UnitRemoveAbility(i.meteo[3], 'Amrf')
call UnitApplyTimedLife(i.meteo[3], 'BTLF', 20)
set i.angle[3] = 270.00
// ==============================
set i.rotate = CreateTrigger()
call StoreString(spell_db, "StoredIndex", T2S(i.rotate), I2S(i))
call TriggerRegisterTimerEvent(i.rotate, 0.02, true)
call TriggerAddAction(i.rotate, function trig_rotate_action)
// ==============================
set i.remove = CreateTrigger()
call StoreString(spell_db, "StoredIndex", T2S(i.remove), I2S(i))
call TriggerRegisterUnitEvent(i.remove, i.meteo[0], EVENT_UNIT_DEATH)
call TriggerRegisterUnitEvent(i.remove, i.meteo[1], EVENT_UNIT_DEATH)
call TriggerRegisterUnitEvent(i.remove, i.meteo[2], EVENT_UNIT_DEATH)
call TriggerRegisterUnitEvent(i.remove, i.meteo[3], EVENT_UNIT_DEATH)
// ==============================
set i.collision[0] = CreateTrigger()
call StoreString(spell_db, "StoredIndex", T2S(i.collision[0]), I2S(i))
call StoreString(spell_db, "StoredMeteo", T2S(i.collision[0]), "0")
call TriggerRegisterUnitInRange(i.collision[0], i.meteo[0], 40, null)
call TriggerAddAction(i.collision[0], function trig_collision_action)
// ==============================
set i.collision[1] = CreateTrigger()
call StoreString(spell_db, "StoredIndex", T2S(i.collision[1]), I2S(i))
call StoreString(spell_db, "StoredMeteo", T2S(i.collision[1]), "1")
call TriggerRegisterUnitInRange(i.collision[1], i.meteo[1], 40, null)
call TriggerAddAction(i.collision[1], function trig_collision_action)
// ==============================
set i.collision[2] = CreateTrigger()
call StoreString(spell_db, "StoredIndex", T2S(i.collision[2]), I2S(i))
call StoreString(spell_db, "StoredMeteo", T2S(i.collision[2]), "2")
call TriggerRegisterUnitInRange(i.collision[2], i.meteo[2], 40, null)
call TriggerAddAction(i.collision[2], function trig_collision_action)
// ==============================
set i.collision[3] = CreateTrigger()
call StoreString(spell_db, "StoredIndex", T2S(i.collision[3]), I2S(i))
call StoreString(spell_db, "StoredMeteo", T2S(i.collision[3]), "3")
call TriggerRegisterUnitInRange(i.collision[3], i.meteo[3], 40, null)
call TriggerAddAction(i.collision[3], function trig_collision_action)
endmethod
public method rotation takes nothing returns nothing
local thistype i = S2I(GetStoredString(spell_db, "StoredIndex", T2S(GetTriggeringTrigger())))
local real z = GetUnitFlyHeight(i.caster)
local real x = GetUnitX(i.caster)
local real y = GetUnitY(i.caster)
set i.distance = i.distance + i.step
// ==============================
set i.angle[0] = i.angle[0] + 1
call SetUnitFlyHeight(i.meteo[0], z + 50, 0)
call SetUnitX(i.meteo[0], PolarX(x, i.distance, i.angle[0]))
call SetUnitY(i.meteo[0], PolarY(y, i.distance, i.angle[0]))
// ==============================
set i.angle[1] = i.angle[1] + 1
call SetUnitFlyHeight(i.meteo[1], z + 50, 1)
call SetUnitX(i.meteo[1], PolarX(x, i.distance, i.angle[0]))
call SetUnitY(i.meteo[1], PolarY(y, i.distance, i.angle[1]))
// ==============================
set i.angle[2] = i.angle[2] + 1
call SetUnitFlyHeight(i.meteo[2], z + 50, 0)
call SetUnitX(i.meteo[2], PolarX(x, i.distance, i.angle[2]))
call SetUnitY(i.meteo[2], PolarY(y, i.distance, i.angle[2]))
// ==============================
set i.angle[3] = i.angle[3] + 1
call SetUnitFlyHeight(i.meteo[3], z + 50, 0)
call SetUnitX(i.meteo[3], PolarX(x, i.distance, i.angle[3]))
call SetUnitY(i.meteo[3], PolarY(y, i.distance, i.angle[3]))
endmethod
public method boom takes nothing returns nothing
local thistype i = S2I(GetStoredString(spell_db, "StoredIndex", T2S(GetTriggeringTrigger())))
local timer ti
local unit t = GetTriggerUnit()
local integer j = S2I(GetStoredString(spell_db, "StoredMeteo", T2S(GetTriggeringTrigger())))
if GetUnitFlyHeight(i.meteo[j]) > GetUnitFlyHeight(t) - 30 and GetUnitFlyHeight(i.meteo[j]) < GetUnitFlyHeight(t) + 60 then
call UnitDamagePoint(i.meteo[j], 0, 50, GetUnitX(i.meteo[j]), GetUnitY(i.meteo[j]), 1, false, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_FIRE, WEAPON_TYPE_WHOKNOWS)
if GetUnitTypeId(t) == 'ewsp' then
call KillUnit(t)
else
call UnitDamageTarget(i.meteo[j], t, 100, false, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_FIRE, WEAPON_TYPE_WHOKNOWS)
endif
call KillUnit(i.meteo[j])
set t = null
set i.meteo[j] = null
set ti = CreateTimer()
call DisableTrigger(GetTriggeringTrigger())
call TriggerClearActions(GetTriggeringTrigger())
call FlushStoredString(spell_db, "StoredIndex", T2S(GetTriggeringTrigger()))
call FlushStoredString(spell_db, "StoredMeteo", T2S(GetTriggeringTrigger()))
call TimerStart(CreateTimer(), 1.00, false, function timer_destroy_trigger)
call StoreString(spell_db, "StoredTrigger", Ti2S(ti), T2S(i.collision[j]))
set i.collision[j] = null
set ti = null
endif
endmethod
public method remove_meteo takes nothing returns nothing
local thistype i = S2I(GetStoredString(spell_db, "StoredIndex", T2S(GetTriggeringTrigger())))
local timer array t
if GetUnitState(i.meteo[0], UNIT_STATE_LIFE) <= 0 and GetUnitState(i.meteo[1], UNIT_STATE_LIFE) <= 0 and GetUnitState(i.meteo[2], UNIT_STATE_LIFE) <= 0 and GetUnitState(i.meteo[3], UNIT_STATE_LIFE) <= 0 then
set i.caster = null
set i.meteo[0] = null
set i.meteo[1] = null
set i.meteo[2] = null
set i.meteo[3] = null
set t[1] = CreateTimer()
set t[2] = CreateTimer()
set t[3] = CreateTimer()
call DisableTrigger(i.rotate)
call DisableTrigger(i.remove)
call TriggerClearActions(i.rotate)
call TriggerClearActions(i.remove)
call FlushStoredString(spell_db, "StoredIndex", T2S(GetTriggeringTrigger()))
call TimerStart(t[1], 1.00, false, function timer_destroy_trigger)
call StoreString(spell_db, "StoredTrigger", Ti2S(t[1]), T2S(i.rotate))
call TimerStart(t[2], 1.00, false, function timer_destroy_trigger)
call StoreString(spell_db, "StoredTrigger", Ti2S(t[2]), T2S(i.remove))
call TimerStart(t[3], 2.00, false, function timer_destroy_index)
call StoreString(spell_db, "StoredIndex", Ti2S(t[3]), I2S(i))
set t[1] = null
set t[2] = null
set t[3] = null
endif
endmethod
public method remove_index takes thistype i returns nothing
call meteo_spell.destroy(i)
endmethod
endstruct
function InitTrig_Library takes nothing returns nothing
set meteo = meteo_spell.create()
endfunction
endlibrary
|