function Trig_Start_Harvest_Actions takes nothing returns nothing
local integer ilv
local item itm = GetOrderTargetItem()
local unit u = GetOrderedUnit()
local unit ut = GetOrderTargetUnit()
local integer cv = GetUnitUserData(u)
local integer i
local integer n
local integer pl
local real r
if GetPlayerController(GetTriggerPlayer()) == MAP_CONTROL_USER then
set pl = GetPlayerId(GetOwningPlayer(u)) + 1
if itm != null then
set ilv = GetItemLevel(itm)
if (itm == udg_Item_Last[pl] and udg_Item_Last[pl] != null) or (ilv > 1200 and ilv < 1203) or GetItemTypeId(itm) == 'gold' then
if ilv > 1200 and ilv < 1203 and GetItemUserData(itm) == 0 then
call IssueImmediateOrder( u, "stop" )
if GetIssuedOrderId() == OrderId("smart") then
set i = LoadInteger(udg_Stat_Table, 8989, GetHandleId(itm))
if LoadItemHandle(udg_Stat_Table, 8983, cv) != null then
if cv == i then
call SaveInteger(udg_Stat_Table, 8989, GetHandleId(LoadItemHandle(udg_Stat_Table, 8983, cv)), 0)
set i = 0
endif
call DestroyTextTag(LoadTextTagHandle(udg_Stat_Table, 9984, cv))
call SaveTextTagHandle(udg_Stat_Table, 8984, cv, null)
call SaveItemHandle(udg_Stat_Table, 8983, cv, null)
endif
if LoadInteger(udg_Stat_Table, 8987, cv) != 0 or LoadInteger(udg_Stat_Table, 8980, cv) == 1 then
call SaveInteger(udg_Stat_Table, 8980, cv, 0)
call SaveInteger(udg_Stat_Table, 8981, cv, - 1)
call SaveInteger(udg_Stat_Table, 8982, cv, 0)
call SaveReal(udg_Stat_Table, 8985, cv, 0)
call SaveReal(udg_Stat_Table, 8986, cv, 0)
if LoadInteger(udg_Stat_Table, 8987, cv) != 0 then
set udg_H_U[LoadInteger(udg_Stat_Table, 8987, cv)] = udg_H_U[udg_H_I]
call SaveInteger(udg_Stat_Table, 8987, cv, 0)
set udg_H_I = udg_H_I - 1
endif
endif
if i == 0 then
set udg_H_I = udg_H_I + 1
set udg_H_U[udg_H_I] = u
if ilv == 1201 then
set n = 80 - R2I((GetCraftLv(LoadInteger(udg_Stat_Table, 27000 + cv, 1), true) + GetCraftLv(LoadInteger(udg_Stat_Table, 27000 + cv, 2), true) + GetCraftLv(LoadInteger(udg_Stat_Table, 27000 + cv, 3), true)) / 3.00 * 4)
else
set n = 60 - (GetCraftLv(LoadInteger(udg_Stat_Table, 27000 + cv, 4), true) * 4)
endif
call SaveInteger(udg_Stat_Table, 8980, cv, 1)
call SaveInteger(udg_Stat_Table, 8981, cv, - 1)
call SaveInteger(udg_Stat_Table, 8982, cv, n)
call SaveItemHandle(udg_Stat_Table, 8983, cv, itm)
call SaveTextTagHandle(udg_Stat_Table, 8984, cv, null)
call SaveReal(udg_Stat_Table, 8985, cv, GetItemX(itm))
call SaveReal(udg_Stat_Table, 8986, cv, GetItemY(itm))
call SaveInteger(udg_Stat_Table, 8987, cv, udg_H_I)
call SaveInteger(udg_Stat_Table, 8989, GetHandleId(itm), cv)
call IssuePointOrder (u, "unloadall", GetItemX(itm), GetItemY(itm))
if udg_H_I == 1 then
call EnableTrigger( gg_trg_Harvester_Timer )
endif
else
call IssuePointOrder (u, "move", GetItemX(itm), GetItemY(itm))
endif
endif
endif
else
call Mb_Item_ToolTip (itm, cv, 0, 0)
set udg_Item_Last[pl] = itm
set r = GetUnitFacing(u)
call IssuePointOrder (u, "move", GetUnitX(u), GetUnitY(u))
call SetUnitFacing(u, r)
endif
else
set udg_Item_Last[pl] = null
if ut != null then
if GetUnitTypeId(ut) == 'h004' and IsUnitType(u, UNIT_TYPE_HERO) then
//call IssueImmediateOrder( u, "stop" )
//call IssueTargetOrder( u, "repair", ut )
elseif GetOwningPlayer(u) != GetOwningPlayer(ut) then
if udg_Unit_Last[pl] != ut then
if udg_Mb_Type[pl] == 0 then
call scaning (u, ut, GetTriggerPlayer())
set udg_Scan_Index = udg_Scan_Index + 1
set udg_Scan_Unit[udg_Scan_Index] = u
set udg_Scan_Target[udg_Scan_Index] = ut
else
call DestroyMultiboard(udg_Mb_Table[pl])
set udg_Mb_Type[pl] = 0
call scaning (u, ut, GetTriggerPlayer())
set udg_Scan_Index = udg_Scan_Index + 1
set udg_Scan_Unit[udg_Scan_Index] = u
set udg_Scan_Target[udg_Scan_Index] = ut
endif
set udg_Unit_Last[pl] = ut
set r = GetUnitFacing(u)
call IssuePointOrder (u, "move", GetUnitX(u), GetUnitY(u))
call SetUnitFacing(u, r)
endif
endif
else
set udg_Unit_Last[pl] = null
endif
endif
endif
set itm = null
set u = null
set ut = null
endfunction