Добавлен noyl
Эта
library Kill initializer Init{
globals
private timer TMR = CreateTimer()
endglobals
struct resp{
unit ru
player p
integer time
real x
real y
boolean b
private static integer array next
private static integer array prev
method destroy takes nothing returns nothing
//Remove from the List
set next[prev[this]] = next[this]
set prev[next[this]] = prev[this]
//Timer
if next[0] == 0 {
call PauseTimer(TMR)
}
//Clean Handles
//Clean References
set .ru = null
set .p = null
call deallocate()
endmethod
private static nothing update(){
local thistype this = next[0]
loop{
exitwhen this == 0
if .time < 1 {
call ReviveHero(.ru, .x, .y, .b)
if GetLocalPlayer() == p {
call PanCameraTo(.x, .y)
call ClearSelection()
call SelectUnit(.ru, true)
}
call destroy()
} else {
set .time -= 1
}
set this = next[this]
}
}
static thistype create(unit u, integer t, boolean b){
local thistype this = allocate()
//Setting
set .ru = u
set .time = t
set .b = b
set .p = GetOwningPlayer(u)
if IsUnitAlly(u, Player(0)){
set .x = GetRectCenterX(gg_rct_BaseRed)
set .y = GetRectCenterY(gg_rct_BaseRed)
} else {
set .x = GetRectCenterX(gg_rct_BaseBlue)
set .y = GetRectCenterY(gg_rct_BaseBlue)
}
//Insert in the list
set next[this] = 0
set prev[this] = prev[0]
set next[prev[this]] = this
set prev[0] = this
if prev[this] == 0 {
call TimerStart(TMR, 1.0, true, function thistype.update)
}
return this
}
}
boolean Revive(){
local integer time
debug call BJDebugMsg(GetUnitName(GetTriggerUnit()))
if IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) {
set time = GetHeroLevel(GetTriggerUnit())
call resp.create(GetTriggerUnit(), time, true)
}
return false
}
private nothing Init(){
local trigger trg = CreateTrigger()
local integer index = 0
loop{
call TriggerRegisterPlayerUnitEvent(trg, Player(index), EVENT_PLAYER_UNIT_DEATH, null)
set index += 1
exitwhen index == bj_MAX_PLAYER_SLOTS
}
call TriggerAddCondition(trg, Condition(function Revive))
set trg = null
}
}
В общем. Захотел посмотреть как работают структуры.
Почитал статьи, написал код. Всё работает, но есть моменты которые я не понимаю.
Что за тип thistype?
Как работает эта часть кода?
Почитал статьи, написал код. Всё работает, но есть моменты которые я не понимаю.
Что за тип thistype?
Как работает эта часть кода?
раскрыть
loop{
exitwhen this == 0
set this = next[this]
}
И эта
set next[this] = 0
set prev[this] = prev[0]
set next[prev[this]] = this
set prev[0] = this
//
set next[prev[this]] = next[this]
set prev[next[this]] = prev[this]
Как всё работает через один таймер.
Да и в целом, что за манипуляции с thistype и this.
Если есть статья и я её пропустил, сори c:
Да и в целом, что за манипуляции с thistype и this.
Если есть статья и я её пропустил, сори c:
Принятый ответ
noyl:
А можно их вообще убрать?
Можно. Но понадобится массив для хранения всех экземпляров структуры. Дело в том, что таймер обходит все экземпляры чтобы убавить оставшееся время воскрешения на 1 каждую секунду, это происходит внутри функции
static nothing update()
Ну и разумеется внутри функциий create и destroy вносить и убирать отработанные экземпляры в/из этого массива.
`
ОЖИДАНИЕ РЕКЛАМЫ...
Чтобы оставить комментарий, пожалуйста, войдите на сайт.
GetLocalPlayer:
Да вроде всё вполне понятно.
С thistype и this разобрался.
Отредактирован MpW
сравни
Да и воскрешение я просто так сделал. Мне в основном интересно как работает конструкция с next и prev.
Steal nerves: Т.е по сути каждый я вызываю метод create, а конкретно allocator, то уже работает как next и prev в моем примере, ну и deallocate?