First off, Sorry if the Title Prefix is wrong.
Ok so I have been working on a trigger and eventually arhowk decided he would write me a library that would do the same thing my GUI trigger did but better. So he wrote that and I decided to edit it to make it do more stuff.
Here is his version:
This is what I added/changed.
Specific Questions:
Here it is
Ok so I have been working on a trigger and eventually arhowk decided he would write me a library that would do the same thing my GUI trigger did but better. So he wrote that and I decided to edit it to make it do more stuff.
Here is his version:
JASS:
library BaseDefenders initializer onBDInit
globals
private real radius = 175
private real checkRadius = 375
private real period = 0.7
private unit host
private filterfunc checkFilter
endglobals
private function enumFilter takes nothing returns boolean
return GetFilterUnit() != host and GetOwningPlayer(host) == GetOwningPlayer(GetFilterUnit())
endfunction
private function looper takes nothing returns nothing
local unit u
local item i
local group g = CreateGroup()
local group g2 = CreateGroup()
set bj_groupAddGroupDest = g
call ForGroup(udg_BD_Bases, function GroupAddGroupEnum)
loop
set host = FirstOfGroup(g)
exitwhen host == null
call GroupClear(g2)
call GroupEnumUnitsInRange(g2, GetUnitX(host), GetUnitY(host), radius, checkFilter)
if FirstOfGroup(g2) == null then
call GroupClear(g2)
call GroupEnumUnitsInRange(g2, GetUnitX(host), GetUnitY(host), checkRadius, checkFilter)
set u = FirstOfGroup(g2)
if u != null then
set i = CreateItem('hval', GetUnitX(host), GetUnitY(host))
call IssueImmediateOrder(u, "stop" )
call SetUnitX(u, GetItemX(i))
call SetUnitY(u, GetItemY(i))
call RemoveItem(i)
endif
endif
call GroupRemoveUnit(g,host)
endloop
set u = null
set i = null
call DestroyGroup(g)
call DestroyGroup(g2)
set g = null
set g2 = null
endfunction
private function onBDInit takes nothing returns nothing
set checkFilter = Filter(function enumFilter)
call TimerStart(CreateTimer(), period, true, function looper)
endfunction
endlibrary
This is what I added/changed.
- Land Bases can not have ships as defenders, They will be captureable.
- Ships can take ownership of land bases and can be the defender of ports
- If a players base has no available defender(captureable), It can be captured by another player if they move a unit within 600 of the base.
- It checks more frequently (.05), and for larger second radius (600)
- To Bases will now change owner to whatever player owns the current defender, you can do that if the current owner has no defender in a 600 radius.
Specific Questions:
- If there are 2 bases in the large range of each other owned by the same player, and one base is has all the units killed, will it take the other bases defender? If so, how can i prevent this. (I havent been able to test this)
- It seems that if a ship is in range of a land base, the defender can leave. it only works with land bases and ships. other wise it works correctly. (it should not let the land defender leave if its a land base.) How can I fix this?
- How can I turn this on at a certain point in game, etc. after voting and set up has finished. (turn off initially, and turn on with another trigger like gui?)
Here it is
JASS:
library BaseControlPoint initializer onBDInit
globals
private real radius = 150
private real checkRadius = 600
private real period = 0.5
private unit tower
private unit base
private filterfunc checkFilter
private filterfunc checkFilterTwo
endglobals
private function enumFilter takes nothing returns boolean
return IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) !=true and IsUnitAliveBJ(GetFilterUnit()) ==true and GetOwningPlayer(tower) == GetOwningPlayer(GetFilterUnit())
endfunction
private function enumFilterTwo takes nothing returns boolean
return IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) !=true and IsUnitAliveBJ(GetFilterUnit()) ==true and GetOwningPlayer(tower) != GetOwningPlayer(GetFilterUnit())
endfunction
private function looper takes nothing returns nothing
local unit u
local item i
local group g = CreateGroup()
local group g2 = CreateGroup()
local group g3 = CreateGroup()
set bj_groupAddGroupDest = g
call ForGroup(udg_BD_Towers, function GroupAddGroupEnum)
set bj_groupAddGroupDest = g3
call ForGroup(udg_BD_Bases, function GroupAddGroupEnum)
loop
set tower = FirstOfGroup(g)
exitwhen tower == null
set base = FirstOfGroup(g3)
call GroupClear(g2)
call GroupEnumUnitsInRange(g2, GetUnitX(tower), GetUnitY(tower), radius, checkFilter)
if FirstOfGroup(g2) == null then
call GroupClear(g2)
call GroupEnumUnitsInRange(g2, GetUnitX(tower), GetUnitY(tower), checkRadius, checkFilter)
set u = FirstOfGroup(g2)
if u != null then
if IsUnitType(u, UNIT_TYPE_ANCIENT) !=true then
call SetUnitX(u, GetUnitX(tower))
call SetUnitY(u, GetUnitY(tower))
call IssueImmediateOrder (u, "stop")
else
if ( GetUnitTypeId(base) == 'h000' ) then
call SetUnitX(u, GetUnitX(tower))
call SetUnitY(u, GetUnitY(tower))
call IssueImmediateOrder (u, "stop")
else
endif
endif
else
call GroupClear(g2)
call GroupEnumUnitsInRange(g2, GetUnitX(tower), GetUnitY(tower), checkRadius, checkFilterTwo)
set u = FirstOfGroup(g2)
call SetUnitOwner (tower, GetOwningPlayer(u),true)
call SetUnitOwner (base, GetOwningPlayer(u),true)
if IsUnitType (u, UNIT_TYPE_ANCIENT) !=true then
call SetUnitX(u, GetUnitX(tower))
call SetUnitY(u, GetUnitY(tower))
call IssueImmediateOrder (u, "stop")
else
if ( GetUnitTypeId(base) == 'h000' ) then
call SetUnitX(u, GetUnitX(tower))
call SetUnitY(u, GetUnitY(tower))
call IssueImmediateOrder (u, "stop")
else
endif
endif
endif
else
endif
call GroupRemoveUnit(g,tower)
call GroupRemoveUnit(g3,base)
endloop
set u = null
set i = null
call DestroyGroup(g)
call DestroyGroup(g2)
call DestroyGroup(g3)
set g = null
set g2 = null
set g3 = null
endfunction
private function onBDInit takes nothing returns nothing
set checkFilter = Filter(function enumFilter)
set checkFilterTwo = Filter(function enumFilterTwo)
call TimerStart(CreateTimer(), period, true, function looper)
endfunction
endlibrary