XGM Forum
Сайт - Статьи - Проекты - Ресурсы - Блоги

Форуме в режиме ТОЛЬКО ЧТЕНИЕ. Вы можете задать вопросы в Q/A на сайте, либо создать свой проект или ресурс.
Вернуться   XGM Forum > Warcraft> Академия: форум для вопросов> Jass
Ник
Пароль
Войти через VK в один клик
Сайт использует только имя.

Ответ
 
Vampirrr
O_o
offline
Опыт: 19,286
Активность:
Помощь в оптимизации
Наконец-таки я добился того, к чему стремился..работает безупречно и так как надо. Единственное, я думаю что код можно оптимизорвать, но сам не берусь, т.к. знаний маловато, да если 1 ошибку сделаю, потом хрен ее найду. Так что надеюсь на ваши знания)

» Код
Код:
function Conditions2 takes nothing returns boolean
    if ( ( GetUnitTypeId(GetTriggerUnit()) == 'hmtt' ) ) then
        return true
    endif
    if ( ( GetUnitTypeId(GetTriggerUnit()) == 'ocat' ) ) then
        return true
    endif
    if ( ( GetUnitTypeId(GetTriggerUnit()) == 'ebal' ) ) then
        return true
    endif
    if ( ( GetUnitTypeId(GetTriggerUnit()) == 'umtw' ) ) then
        return true
    endif
    return false
endfunction

function Conditions1 takes nothing returns boolean
    if ( not ( GetOwningPlayer(GetTriggerUnit()) == Player(0) ) ) then
        return false
    endif
    if ( not Conditions2() ) then
        return false
    endif
    return true
endfunction

function Actions takes nothing returns nothing
    local integer a
    local integer b
    set a = 0
    set b = 0
    
    loop
      set a = a+1
      exitwhen a == 64
      if ( IsUnitInGroup(GetTriggerUnit(), GetUnitsInRectAll(udg_Square[a])) == true ) then
        exitwhen true
      endif
      set a = a
    endloop  

    loop
      set b = b+1
      exitwhen b > 4
      exitwhen ( not (IsUnitGroupEmptyBJ(GetUnitsInRectOfPlayer(udg_Square[a+8*b], Player(0)))) )  
      if (IsUnitGroupEmptyBJ(GetUnitsInRectOfPlayer(udg_Square[a+8*b], Player(0)))) then
      if (IsUnitGroupEmptyBJ(GetUnitsInRectOfPlayer(udg_Square[a+8*b], Player(1)))) then
      call CreateNUnitsAtLoc( 1, 'e001', GetTriggerPlayer(), GetRectCenter(udg_Square[a+8*b]), bj_UNIT_FACING ) 
      else
      call CreateNUnitsAtLoc( 1, 'h000', GetTriggerPlayer(), GetRectCenter(udg_Square[a+8*b]), bj_UNIT_FACING ) 
      exitwhen ( not (IsUnitGroupEmptyBJ(GetUnitsInRectOfPlayer(udg_Square[a+8*b], Player(1)))) )
      call CreateNUnitsAtLoc( 1, 'e001', GetTriggerPlayer(), GetRectCenter(udg_Square[a+8*b]), bj_UNIT_FACING ) 
      endif
      endif
    
    endloop
 
    call DisplayTextToForce( GetPlayersAll(), I2S(a) )
    call DisplayTextToForce( GetPlayersAll(), I2S(b) )

endfunction


//===========================================================================
function InitTrig_Rook takes nothing returns nothing
    set gg_trg_Rook = CreateTrigger(  )
    call TriggerRegisterPlayerSelectionEventBJ( gg_trg_Rook, Player(0), true )
    call TriggerAddCondition( gg_trg_Rook, Condition( function Conditions1 ) )
    call TriggerAddAction( gg_trg_Rook, function Actions )
endfunction
Старый 31.12.2008, 03:43
J
expert
offline
Опыт: 48,447
Активность:
через чур говнокодисто, нужно все исать с нуля но правельно, но если просто наждачкой провести то будет так:
» code
Код:
function Conditions1 takes nothing returns boolean
    local integer i = GetUnitTypeId(GetTriggerUnit())
    return (GetOwningPlayer(GetTriggerUnit()) == Player(0)) and ((i == 'hmtt') or (i == 'ocat') or (i == 'ebal') or (i == 'umtw'))
endfunction

function Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local integer a = 0
    local integer b = 0    
    loop
        set a = a+1
        exitwhen a == 64
        if IsUnitInGroup(u, GetUnitsInRectAll(udg_Square[a])) then
            exitwhen true
        endif
    endloop
    loop                                  
        set b = b + 1
        exitwhen (b > 4)
        if (IsUnitGroupEmptyBJ(GetUnitsInRectOfPlayer(udg_Square[a+8*b], Player(0)))) then
            if (IsUnitGroupEmptyBJ(GetUnitsInRectOfPlayer(udg_Square[a+8*b], Player(1)))) then
                call CreateUnit(GetTriggerPlayer(), 'e001', GetRectCenterX(udg_Square[a+8*b]), GetRectCenterY(udg_Square[a+8*b]), bj_UNIT_FACING)
            else   
                call CreateUnit(GetTriggerPlayer(), 'h000', GetRectCenterX(udg_Square[a+8*b]), GetRectCenterY(udg_Square[a+8*b]), bj_UNIT_FACING)
                //Этот выход сработает в любом случае
                //exitwhen ( not (IsUnitGroupEmptyBJ(GetUnitsInRectOfPlayer(udg_Square[a+8*b], Player(1)))) )      
                //call CreateUnit(GetTriggerPlayer(), 'e001', GetRectCenterX(udg_Square[a+8*b]), GetRectCenterY(udg_Square[a+8*b]), bj_UNIT_FACING)
            endif
        else
            exitwhen true
        endif
    endloop
    call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, I2S(a))
    call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, I2S(b))
endfunction

function InitTrig_Rook takes nothing returns nothing
    set gg_trg_Rook = CreateTrigger()
    call TriggerRegisterPlayerSelectionEventBJ(gg_trg_Rook, Player(0), true)
    call TriggerAddCondition(gg_trg_Rook, Condition(function Conditions1))
    call TriggerAddAction(gg_trg_Rook, function Actions)
endfunction
Старый 31.12.2008, 05:39
ShadoW DaemoN

offline
Опыт: 37,078
Активность:
Конкретно по этому вопросу рекомендую почитать статью Оптимизация Jass кода.
А вообще советую побродить по ссылкам из Jass-библиотеки - найдешь немало полезного.
Старый 31.12.2008, 06:04
Ответ

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск

Ваши права в разделе
Вы не можете создавать темы
Вы не можете отвечать на сообщения
Вы не можете прикреплять файлы
Вы можете скачивать файлы

BB-коды Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход



Часовой пояс GMT +3, время: 18:03.