- Joined
- Jun 15, 2016
- Messages
- 472
By "Assault group" I'm referring to units already built and are acting under the attack captain.
Is it possible to do that?
Is it possible to do that?
AddAssault
and AddDefenders
.native ClearCaptainTargets takes nothing returns nothing
InitAssault
thinking it would work like InitAssaultGroup
but that doesn't work, or I'm using the function incorrectly...SuicideUnitEx(2, FOOTMAN, 0)
does not affect "captain" natives, but you have no control over these units (they die or destroy all Player(0) units)ResetCaptainLocs() ClearCaptainTargets() CaptainGoHome()
with Sleep() allows to order assault group to come back to base.SuicideUnitEx
offers to create more then one waves attacking diffrent players.I think it's not possible to remove units from assault group. They are removed upon death.
//=================================================================================================
// EMPTY ATTACK GROUP TEST
//=================================================================================================
globals
player user = Player(0)
//DEFENSE HOME
constant real DEFX = -3200.0
constant real DEFY = -4900.0
constant real DEFX2 = -4000.0
constant real DEFY2 = -6750.0
//ATTACK HOME
constant real ATTX = -2250.0
constant real ATTY = -5900.0
//ATTACK TARGET
constant real TARX = -2500.0
constant real TARY = -4500.0
endglobals
//-------------------------------------------------------------------------------------------------
// BUILD ORDER
//-------------------------------------------------------------------------------------------------
function BuildOrder takes nothing returns nothing
call SetBuildUnitEx( 1, 1, 1, TOWN_HALL )
call SetBuildUnitEx( 5,5,5, PEASANT )
call SetBuildUnitEx( 4, 4, 6, HOUSE )
call SetBuildUnitEx( 8,8,8, PEASANT )
call SetBuildUnitEx( 1, 1, 1, BARRACKS )
endfunction
//-------------------------------------------------------------------------------------------------
// ATTACK TEST
//-------------------------------------------------------------------------------------------------
function PerformCommand takes nothing returns nothing
local integer cmd = GetLastCommand()
if cmd == 1 then
call DisplayTextToPlayer(user,0,0,"Adding units to attack captain")
call AddAssault(4, FOOTMAN)
elseif cmd == 2 then
call DisplayTextToPlayer(user,0,0,"Attacking")
call CaptainAttack(TARX,TARY)
elseif cmd == 3 then
call DisplayTextToPlayer(user,0,0,"Truncating attack captain")
call InitAssault()
elseif cmd == 4 then
call DisplayTextToPlayer(user,0,0,"Adding units to defense captain")
call AddDefenders(4, FOOTMAN)
elseif cmd == 5 then
if CaptainGroupSize() == 4 then
call DisplayTextToPlayer(user,0,0,"Attack captain full")
elseif CaptainGroupSize() == 0 then
call DisplayTextToPlayer(user,0,0,"Attack captain empty")
else
call DisplayTextToPlayer(user,0,0,"Something strange is afoot")
endif
elseif cmd == 6 then
call DisplayTextToPlayer(user,0,0,"Relocating the defense captain for 5 seconds")
call SetCaptainHome(DEFENSE_CAPTAIN, DEFX2, DEFY2)
call Sleep(5)
call SetCaptainHome(DEFENSE_CAPTAIN, DEFX, DEFY)
elseif cmd == 7 then // FINAL SOLUTION
call DisplayTextToPlayer(user,0,0,"recreating the captains")
call CreateCaptains()
endif
call PopLastCommand()
endfunction
function TestLoop takes nothing returns nothing
if CommandsWaiting()>0 then
call PerformCommand()
endif
call StaggerSleep(3,3)
loop
if CommandsWaiting()>0 then
call PerformCommand()
endif
call Sleep(0.5)
endloop
endfunction
//-------------------------------------------------------------------------------------------------
// MAIN FUNCTION
//-------------------------------------------------------------------------------------------------
function main takes nothing returns nothing
call CampaignAI(HOUSE, null)
call DoCampaignFarms(false)
call DisplayTextToPlayer(user,0,0,"Script received")
call SetCaptainChanges(true)
call SetCaptainHome(DEFENSE_CAPTAIN, DEFX, DEFY)
call SetCaptainHome(ATTACK_CAPTAIN, ATTX, ATTY)
call BuildOrder()
call CampaignDefenderEx(4,4,4, FOOTMAN)
call TestLoop()
endfunction
InitAssault()
.CaptainGroupSize() == 4
),empty (CaptainGroupSize() == 0
) or something else.CreateCaptains()
.However depending on what you excatly want to do you may use.
AddAssault
for normal attack waves. But switch between base and attack point using "defend units" by changing SetCaptainHome(DEFENSE_CAPTAIN, x, y)
. But I noticed that SetCaptainHome works after new unit has been produced.. or maybe you know a way to update SetCaptainHome w/o creating unit?It may be a litle crooked idea but maybe use
AddAssault
for normal attack waves. But switch between base and attack point using "defend units" by changing
SetCaptainHome(DEFENSE_CAPTAIN, x, y)
. But I noticed that SetCaptainHome works after new unit has been produced.. or maybe you know a way to update SetCaptainHome w/o creating unit?
CaptainGoHome
does it, but I think this works only for attack captains. Anyway this won't really work here. Once the ai receives a prompt to start hunting, it starts an attack based on CaptainVsUnits
, so getting the unit's location is more trouble than its worth (and I don't think it's possible anyway). Technically SetCaptainChanges
should do something along these lines as well, no?Since CreateCaptains() indeed resets "captain" natives (like CaptainIsEmpty(), CaptainIsFull(), CaptainGroupSize()) but units added to assault group are somehow "marked", I didnt found a way to reuse them.
CreateCaptains
does not actually create the captains and that's it. It creates two widgets of type captain, and assigns each one to a variable, and both of them together to another variable (see common ai lines 666-668). Calling CreateCaptains
again does not remove the existing captains, but rather overwrites their variables with the newly created captains, as evidence some "residue" of a former attack captain remains in the form of units which cannot be reassigned to a different captain.CreateCaptains
every couple of minutes and see if/when the game crashes. Hopefully my computer won't burst in flames.//=================================================================================================
// EMPTY ATTACK GROUP TEST
//=================================================================================================
globals
player user = Player(0)
//DEFENSE HOME
constant real DEFX = -3200.0
constant real DEFY = -4900.0
constant real DEFX2 = -4000.0
constant real DEFY2 = -6750.0
//ATTACK HOME
constant real ATTX = -2250.0
constant real ATTY = -5900.0
//ATTACK TARGET
constant real TARX = -2500.0
constant real TARY = -4500.0
endglobals
//-------------------------------------------------------------------------------------------------
// BUILD ORDER
//-------------------------------------------------------------------------------------------------
function BuildOrder takes nothing returns nothing
call SetBuildUnitEx( 1, 1, 1, TOWN_HALL )
call SetBuildUnitEx( 5,5,5, PEASANT )
call SetBuildUnitEx( 4, 4, 6, HOUSE )
call SetBuildUnitEx( 8,8,8, PEASANT )
call SetBuildUnitEx( 1, 1, 1, BARRACKS )
call SetBuildUnitEx( 1, 1, 1, BLACKSMITH )
endfunction
//-------------------------------------------------------------------------------------------------
// ATTACK TEST
//-------------------------------------------------------------------------------------------------
function PerformCommand takes nothing returns nothing
local integer cmd = GetLastCommand()
if cmd == 1 then
call DisplayTextToPlayer(user,0,0,"Adding units to attack captain")
call AddAssault(4, FOOTMAN)
elseif cmd == 2 then
call DisplayTextToPlayer(user,0,0,"Attacking")
call CaptainAttack(TARX,TARY)
elseif cmd == 3 then
call DisplayTextToPlayer(user,0,0,"Truncating attack captain")
call InitAssault()
elseif cmd == 4 then
call DisplayTextToPlayer(user,0,0,"Adding units to defense captain")
call AddDefenders(4, FOOTMAN)
elseif cmd == 5 then
if CaptainGroupSize() == 4 then
call DisplayTextToPlayer(user,0,0,"Attack captain full")
elseif CaptainGroupSize() == 0 then
call DisplayTextToPlayer(user,0,0,"Attack captain empty")
else
call DisplayTextToPlayer(user,0,0,"Something strange is afoot")
endif
elseif cmd == 6 then
call DisplayTextToPlayer(user,0,0,"Relocating the defense captain for 5 seconds")
call SetCaptainHome(DEFENSE_CAPTAIN, DEFX2, DEFY2)
call Sleep(5)
call SetCaptainHome(DEFENSE_CAPTAIN, DEFX, DEFY)
elseif cmd == 7 then // FINAL SOLUTION
call DisplayTextToPlayer(user,0,0,"recreating the captains")
call CreateCaptains()
call CampaignDefenderEx(5,5,5, FOOTMAN)
call CampaignAttackerEx(2,2,2, RIFLEMAN)
call BuildAttackers()
call Sleep(10)
call DisplayTextToPlayer(user,0,0,"Sleep is over, try using a captain")
call AddAssault(2,RIFLEMAN)
endif
call PopLastCommand()
endfunction
function TestLoop takes nothing returns nothing
if CommandsWaiting()>0 then
call PerformCommand()
endif
call StaggerSleep(3,3)
loop
if CommandsWaiting()>0 then
call PerformCommand()
endif
call Sleep(0.5)
endloop
endfunction
//-------------------------------------------------------------------------------------------------
// MAIN FUNCTION
//-------------------------------------------------------------------------------------------------
function main takes nothing returns nothing
call CampaignAI(HOUSE, null)
call DoCampaignFarms(false)
call DisplayTextToPlayer(user,0,0,"Script received")
call SetCaptainHome(DEFENSE_CAPTAIN, DEFX, DEFY)
call SetCaptainHome(ATTACK_CAPTAIN, ATTX, ATTY)
call BuildOrder()
call CampaignDefenderEx(4,4,4, FOOTMAN)
call TestLoop()
endfunction
call SuicideUnitEx(3, FOOTMAN, 2)
3 footmans will attack Player(2)CampaignDefenderEx( 2, 2, 2, KNIGHT )
normal basic actionfunction ResetCaptainLocs_Ex takes nothing returns nothing
call Trace_Ex("reseting captain locs..")
call ResetCaptainLocs()
call Sleep(5.00)
call SetCaptainHome(ATTACK_CAPTAIN, ATT_TARGET_X, ATT_TARGET_Y)
call SetCaptainHome(DEFENSE_CAPTAIN, DEF_TARGET_X, DEF_TARGET_Y)
call Sleep(5.00)
endfunction
function AttackCaptain_ForceGoBack takes nothing returns nothing
loop // force go back
call Trace_Ex("attack captain CaptainGoHome() ...")
call CaptainGoHome() // attack captain goes to his "CaptainHome" location
call Sleep(1.00)
exitwhen CaptainIsHome() and (not CaptainInCombat(true))
endloop
endfunction
//------------------------------------------
function main takes nothing returns nothing
local integer cmd
local real x=0.00
local real y=0.00
call CampaignAI(AI_FARM, null ) //farm
call SetTargetHeroes(true)
call SetUnitsFlee(false)
call SetGroupsFlee(false)
call SetSlowChopping(false)
call SetPeonsRepair(true)
call SetHarvestLumber(true)
call SetCaptainChanges(true)
call SetCaptainHome(DEFENSE_CAPTAIN, DEF_TARGET_X, DEF_TARGET_Y)
call SetCaptainHome(ATTACK_CAPTAIN, ATT_TARGET_X, ATT_TARGET_Y)
call SetBuildUnitEx( 6, 6, 6, PEASANT )
call SetBuildUnitEx( 2, 2, 2, AI_FARM )
call SetBuildUnitEx( 2, 2, 2, BARRACKS )
call CampaignDefenderEx( 2, 2, 2, FOOTMAN )
call CampaignDefenderEx( 2, 2, 2, KNIGHT )
call CampaignDefenderEx( 2, 2, 2, RIFLEMAN )
loop
exitwhen GetUnitCount(RIFLEMAN)>=2
call Sleep(2.00)
endloop
call SuicideUnitEx(2, FOOTMAN, 2)// 2 footmans attack Player(2); does not affect captain natives
//call StartThread(function AI_Info)
call Trace_Ex("init assault + attack 2 KNIGHTS ----------------------------")
call InitAssault()
call AddAssault(2,KNIGHT)
//call AttackMoveXY(ATT_TARGET_X, ATT_TARGET_Y)
call CaptainVsUnits(HumanPlayer)
call Sleep(20.00)
call ResetCaptainLocs_Ex()
call AttackCaptain_ForceGoBack()
call Sleep(15.00)
//attack new target
call Trace_Ex("ATTACK NEW TARGET ---------------------------")
call InitAssault()
call AddAssault(1,RIFLEMAN)
//call CaptainAttack(PLAYER_RED_X, PLAYER_RED_Y)
call CaptainVsUnits(HumanPlayer)
call Sleep(30.00)
call ResetCaptainLocs_Ex()
call AttackCaptain_ForceGoBack()
call Sleep(35.00)
call Trace_Ex("2 ATTACKS FINISHED")