Суть у мя бывает 1 волна что генерирует крипы рандомно и все заношу в массив каждого типа количество юнитов а потом при спавн генерирую рандом от 0 до макс доступных типов в цикле если есть создаю и снова по циклом.. пример кода низу. Вот и хочу как вы реализоывываете без цикла бывает что 3 раза попадет 0 счетчик которые уже заспавнили..
static method spawnEnemy takes nothing returns nothing
local integer c = 0
local unit u = null
local rect r = swapns[GetRandomInt(0, 1)]
if thistype.allEnemy + (5 * thistype.l) > thistype.deadEnemy then
loop
exitwhen u != null
set c = GetRandomInt(0, thistype.last.count - 1)
if thistype.allCount[c] != 0 then
set u = CreateUnit(Player(10), thistype.last.enemy[c], GetRectCenterX(r), GetRectCenterY(r), bj_UNIT_FACING)
set thistype.allCount[c] = thistype.allCount[c] - 1
set thistype.allEnemy = thistype.allEnemy - 1
endif
endloop
endif
if thistype.allEnemy == 0 then
call PauseTimer(t)
endif
set u = null
endmethod
Принятый ответ
8gabriel8, у меня без приказа а тупо чисто радиус приказа так как у меня чисто арена.
Hate, не я решил делать подобие как удаление с данные и уменшить счетчик помогает без повтора
примерно так лучше
Hate, не я решил делать подобие как удаление с данные и уменшить счетчик помогает без повтора
примерно так лучше
static method spawnUnit takes nothing returns unit
local integer r
local unit u = null
if .count > 0 then
set r = GetRandomInt(1, .count) - 1 // 0...1...2
set u = CreateUnit(Player(0), .typeUnits[r], 0, 0, bj_UNIT_FACING)
set .countUnits[r] = .countUnits[r] - 1
if .countUnits[r] == 0 then
set .typeUnits[r] = typeUnits[.count - 1]
set .countUnits[r] = .countUnits[.count - 1]
set .count = .count - 1
endif
endif
return u
endmethod
Вот структура если кому надо берите я не тестил его так как писал на планшете... после сна проверю..
struct xWave
static constant integer MAX_UNIT_ON_MAP = 5
private static integer countSpawn = 0
private static integer countDead = 0
private static integer countAll = 0
private static integer countMap = 0
private static integer array typeUnits
private static integer array countUnits
private static integer array countMaps
private static timer t = CreateTimer()
static method spawnUnit takes nothing returns unit
local integer r
local unit u = null
if .countSpawn > 0 and .countMap < MAX_UNIT_ON_MAP then
set r = GetRandomInt(1, .countSpawn) - 1 // 0...1...2
set u = CreateUnit(Player(0), .typeUnits[r], 0, 0, bj_UNIT_FACING)
set .countUnits[r] = .countUnits[r] - 1
set .countMap = .countMap + 1
if .countUnits[r] == 0 then
set .typeUnits[r] = typeUnits[.countSpawn - 1]
set .countUnits[r] = .countUnits[.countSpawn - 1]
set .countSpawn = .countSpawn - 1
endif
if .countSpawn == 0 then
call end()
endif
endif
return u
endmethod
static method createUnit takes integer t, integer c returns nothing
set .typeUnits[.countSpawn] = t
set .countUnits[.countSpawn] = c
set .countAll = .countAll + c
set .countSpawn = .countSpawn + 1
endmethod
static method update takes nothing returns nothing
local unit u = spawnUnit()
if not(u == null) then
call SetUnitPosition(u, 0, 0)
call SetUnitOwner(u, Player(PLAYER_NEUTRAL_AGGRESSIVE), true)
endif
set u = null
endmethod
static method start takes nothing returns nothing
if .countSpawn == 0 or .countAll == 0 then
debug call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "[ОШИБКА] Нельзя стартовать волны без войска")
return
endif
call update()
call TimerStart(t, 100/(.countAll*2), true, function thistype.update)
endmethod
static method end takes nothing returns nothing
set .countSpawn = 0
set .countDead = 0
set .countAll = 0
set .countMap = 0
call PauseTimer(t)
endmethod
endstruct
`
ОЖИДАНИЕ РЕКЛАМЫ...
Чтобы оставить комментарий, пожалуйста, войдите на сайт.
Ред. pro100master
Опишу суть каждый 0.8 сек создает 2 локации из рандома точек если в массиве имеет 3 тип и количество войск то берет рандом от 0 до 2 и отнимаем счетчик но когда у мя бывает 10 типов по каждый 10 войск то все вышли а некоторые нет пока цикл ишет и не может найди нужный имеюший войска... как исключить если счетчик войска было выпушено и сократить? хотя у мя идея напишу после нг.
Hate, не я решил делать подобие как удаление с данные и уменшить счетчик помогает без повтора
примерно так лучше