Jump to content


Photo

[RESOLVED] Toggle AI Code to allow activation in Combat but..


  • Please log in to reply
26 replies to this topic

#1 thudo

thudo

    Wacko AI Guy!

  • Division Leaders
  • 12,164 posts
  • Location:Lemonville North, Canada
  • Projects:DoW AI Scripting Project
  • Division:DoW
  • Job:Division Leader

Posted 18 April 2006 - 04:26 PM

This is the opposite toggle to the current Fleet of Foot but:

a) On during and out of Combat
b) Off when engaged in Melee
c) Off when Health is less than 40%

Can the following below be adapted to work this way.. Currently, the following activates the ability in combat only and off when not in combat.

--toggle ability to be used during combat and off when not
DoAbilityToggleCombat = function( squad_ai, id, msg )

	   if squad_ai:CanDoAbility( id ) and not squad_ai:IsAttached() then

			   local using = squad_ai:IsUsingAbility( id )
			   local combat = squad_ai:IsInCombat()
			   local move = cpu_manager:IsMoving( squad_ai ) or cpu_manager:InSubState( squad_ai:GetID() )

			   if ( using == true and combat == false and move == true) or
				  ( using == false and ( combat == true or move == false) ) then

					   squad_ai:DoSpecialAbility( id )

			   end
	   end
end,
Any help would be appreciated. This will be a step towards more elaborate ability toggles.
Advanced Skirmish AI Team Lead for the coolest Warhammer40k PC RTS out there:

Dawn of War Advanced AI Headquarters

Latest DoW Advanced AI Download!

#2 Finaldeath

Finaldeath
  • Project Team
  • 188 posts
  • Location:UK

Posted 18 April 2006 - 05:29 PM

a) On during and out of Combat
b) Off when engaged in Melee
c) Off when Health is less than 40%

A and B are actually one and the same, considering it'll only be on out of combat, it'll never be on in melee (which is part of combat!)

C - Well, remember, squads and health might not match up too well.

However, here is the code altered to what should work (untested):

--toggle ability to be used during out of combat and at high (>40%) health
DoAbilityToggleNotInCombat = function( squad_ai, id, msg )

	   if squad_ai:CanDoAbility( id ) and not squad_ai:IsAttached() then

			   local using = squad_ai:IsUsingAbility( id )
			   local healthpercent = squad_ai:GetHealthPercentage()
			   local combat = squad_ai:IsInCombat()

			   if using == true and combat == false and healthpercent > 40 then
					   squad_ai:DoSpecialAbility( id )
			   end
	   end
end,

That make sense? :) (I removed the unnessissary movement check, combat is the main check here).

Edited by Finaldeath, 18 April 2006 - 05:30 PM.


#3 thudo

thudo

    Wacko AI Guy!

  • Division Leaders
  • 12,164 posts
  • Location:Lemonville North, Canada
  • Projects:DoW AI Scripting Project
  • Division:DoW
  • Job:Division Leader

Posted 18 April 2006 - 05:45 PM

Excellent.. thats getting REAL close.. now problem is: Combat does include Melee. I've seen the ability used even when engaged in CC so Combat still = Melee. THe challenge.. disable it when the squad or single unit is engaged in CC. This is meant for vehicles only btw so that should help! eheh
Advanced Skirmish AI Team Lead for the coolest Warhammer40k PC RTS out there:

Dawn of War Advanced AI Headquarters

Latest DoW Advanced AI Download!

#4 Finaldeath

Finaldeath
  • Project Team
  • 188 posts
  • Location:UK

Posted 18 April 2006 - 06:46 PM

Misread your post.

I didn't realise you meant "in AND out of combat", which...is a rather silly statement, thud ;)

--toggle ability to be used at high (>40%) health
DoAbilityToggleIfHighHealth = function( squad_ai, id, msg )

	   if squad_ai:CanDoAbility( id ) and not squad_ai:IsAttached() then

			   local using = squad_ai:IsUsingAbility( id )
			   local healthpercent = squad_ai:GetHealthPercentage()

			   if using == true and healthpercent > 40 then
					   squad_ai:DoSpecialAbility( id )
			   end
	   end
end,

Note: there is no inbuilt "is being attacked in CC" function...I am sure larkin or arkhan can get that sorted in a satifyable way however by using location based target checking of somesort.

#5 thudo

thudo

    Wacko AI Guy!

  • Division Leaders
  • 12,164 posts
  • Location:Lemonville North, Canada
  • Projects:DoW AI Scripting Project
  • Division:DoW
  • Job:Division Leader

Posted 18 April 2006 - 06:49 PM

I'll test that then.. so essentially that is disabling the ability when the unit's health falls below 40%. Thats about right: the "melee combat check" would only be useful for such units as Dreads.
Advanced Skirmish AI Team Lead for the coolest Warhammer40k PC RTS out there:

Dawn of War Advanced AI Headquarters

Latest DoW Advanced AI Download!

#6 Finaldeath

Finaldeath
  • Project Team
  • 188 posts
  • Location:UK

Posted 18 April 2006 - 07:47 PM

It'd probably also be easier to explain the ability itself remember. Saying those conditions is hard to visualise why the AI would do that for a unit ;)

#7 thudo

thudo

    Wacko AI Guy!

  • Division Leaders
  • 12,164 posts
  • Location:Lemonville North, Canada
  • Projects:DoW AI Scripting Project
  • Division:DoW
  • Job:Division Leader

Posted 18 April 2006 - 07:55 PM

;) Yeaa I should have been more precise. Too me its no biggie if the ability is still being used during CC. It would be nice to set that regardless but its no showstopper.
Advanced Skirmish AI Team Lead for the coolest Warhammer40k PC RTS out there:

Dawn of War Advanced AI Headquarters

Latest DoW Advanced AI Download!

#8 ArkhanTheBlack

ArkhanTheBlack

    title available

  • Members
  • 814 posts

Posted 19 April 2006 - 09:40 AM

You can use the same code part to detect CC combat like Larkins dancing code. I can post this code part if you want this evening since I'm at work at the moment.

#9 LarkinVB

LarkinVB

    title available

  • Members
  • 1,488 posts

Posted 19 April 2006 - 10:22 AM

I wrote up some crude untested function for melee check. Perhaps it can help you.

function Tactic:IsInMelee()

	local squad_pos = self.squad_ai:GetPosition()
	
	local infantry = Ability.Filters.CloseInfantryEnemy( squad_pos, 5, 1 )
	if infantry ~= nil then
	
		local stance = infantry:GetMeleeStance()
		if infantry:IsInStateAttackMove() and not infantry:IsBroken() and not
			infantry:IsCapturing() and stance == SquadAI.MSTANCE_Assault then
			return true
		end
	end
	
	local vehicle = Ability.Filters.CloseVehicleEnemy( squad_pos, 5, 1 )
	if vehicle ~= nil then
	
		local stance = vehicle:GetMeleeStance()
		if vehicle:IsInStateAttackMove() and stance == SquadAI.MSTANCE_Assault then
			return true
		end
	end
	
	local commander = Ability.Filters.CloseCommanderEnemy( squad_pos, 5, 1 )
	if commander ~= nil then
	
		local stance = commander:GetMeleeStance()
		if commander:IsInStateAttackMove() and not commander:IsBroken() and
			stance == SquadAI.MSTANCE_Assault then
			return true
		end
	end
	
	
	return false
end

Edited by LarkinVB, 19 April 2006 - 10:26 AM.


#10 thudo

thudo

    Wacko AI Guy!

  • Division Leaders
  • 12,164 posts
  • Location:Lemonville North, Canada
  • Projects:DoW AI Scripting Project
  • Division:DoW
  • Job:Division Leader

Posted 19 April 2006 - 04:45 PM

Fantastic everyone! I'll put it together and test it out!

Update.. so the code will be (with Larkin's new function placed in the core Tactic.ai file):

--toggle ability to be used at high (>40%) health
DoAbilityToggleIfHighHealth = function( squad_ai, id, msg )

	   if squad_ai:CanDoAbility( id ) and not squad_ai:IsAttached() then

			   local using = squad_ai:IsUsingAbility( id )
			   local healthpercent = squad_ai:GetHealthPercentage()
			   local melee = squad_ai:IsInMelee()
 
			   if using == true and melee == false and healthpercent > 40 then
					   squad_ai:DoSpecialAbility( id )
			   end
	   end
end,
This should do the trick.. I'd love to have a bunch of scripts like this for toggles but then again we'll take it one step at a time.
Advanced Skirmish AI Team Lead for the coolest Warhammer40k PC RTS out there:

Dawn of War Advanced AI Headquarters

Latest DoW Advanced AI Download!

#11 LarkinVB

LarkinVB

    title available

  • Members
  • 1,488 posts

Posted 19 April 2006 - 08:29 PM

Not quite, I fear.

1. It is self:IsInMelee(), not squad_ai:IsInMelee(), while called from tactic
2. It doesn't look like this function is toggeling on/off. It is just toggeling off while the ability is active.

#12 thudo

thudo

    Wacko AI Guy!

  • Division Leaders
  • 12,164 posts
  • Location:Lemonville North, Canada
  • Projects:DoW AI Scripting Project
  • Division:DoW
  • Job:Division Leader

Posted 19 April 2006 - 08:37 PM

Thanks! The ONLY time this ability needs to be turned off is when in Melee and when health falls below 40%. Every other time it should remain ON. Hmm.. no idea why the toggle should not work.
Advanced Skirmish AI Team Lead for the coolest Warhammer40k PC RTS out there:

Dawn of War Advanced AI Headquarters

Latest DoW Advanced AI Download!

#13 LarkinVB

LarkinVB

    title available

  • Members
  • 1,488 posts

Posted 19 April 2006 - 09:13 PM

???

Your code will never turn it on at all. 'using' will be false if the ability is not active. I fear you do not really know what you are doing :p

#14 thudo

thudo

    Wacko AI Guy!

  • Division Leaders
  • 12,164 posts
  • Location:Lemonville North, Canada
  • Projects:DoW AI Scripting Project
  • Division:DoW
  • Job:Division Leader

Posted 20 April 2006 - 12:23 AM

Not too worry: I have a backup plan. ;)

Okay update:

1) If I use self:IsInMelee() as Larkin recommended and the function Tactic:IsInMelee() in tactic.ai (which Larkin provided) when the unit with the ability is created I get the error: self (a nil value). Is this related to the experimental function Tactic:IsInMelee() ?

2) In my ability code in ability.ai I am at least trying to have the AI toggle the ability off when health goes below 40% with the following:

local using = squad_ai:IsUsingAbility( id )
local combat = squad_ai:IsInCombat()
local move = cpu_manager:IsMoving( squad_ai ) or cpu_manager:InSubState( squad_ai:GetID() )
local healthpercent = squad_ai:GetHealthPercentage()

if ( using == true and combat == false and move == true and healthpercent < 40 ) or
( using == false and ( combat == true or move == false or healthpercent > 40 ) ) then
However.. it doesn't shut the ability off when health drops below 40%? :p Thanks guys for helping me on this one!
Advanced Skirmish AI Team Lead for the coolest Warhammer40k PC RTS out there:

Dawn of War Advanced AI Headquarters

Latest DoW Advanced AI Download!

#15 LarkinVB

LarkinVB

    title available

  • Members
  • 1,488 posts

Posted 20 April 2006 - 08:15 AM

Oh boy. Ok, here we go.

1. Change IsInMelee() like this and put it into cpu_manager.ai

function CpuManager:IsInMelee( squad_ai )

	local squad_pos = squad_ai:GetPosition()
	
	local infantry = Ability.Filters.CloseInfantryEnemy( squad_pos, 5, 1 )
	if infantry ~= nil then
	
		local stance = infantry:GetMeleeStance()
		if infantry:IsInStateAttackMove() and not infantry:IsBroken() and not
			infantry:IsCapturing() and stance == SquadAI.MSTANCE_Assault then
			return true
		end
	end
	
	local vehicle = Ability.Filters.CloseVehicleEnemy( squad_pos, 5, 1 )
	if vehicle ~= nil then
	
		local stance = vehicle:GetMeleeStance()
		if vehicle:IsInStateAttackMove() and stance == SquadAI.MSTANCE_Assault then
			return true
		end
	end
	
	local commander = Ability.Filters.CloseCommanderEnemy( squad_pos, 5, 1 )
	if commander ~= nil then
	
		local stance = commander:GetMeleeStance()
		if commander:IsInStateAttackMove() and not commander:IsBroken() and
			stance == SquadAI.MSTANCE_Assault then
			return true
		end
	end
	
	
	return false
end

2. Your function in ability.ai has to look like this :

--toggle ability to be used at high (>40%) health
DoAbilityToggleIfHighHealth = function( squad_ai, id )

	if squad_ai:CanDoAbility( id ) then

		local using = squad_ai:IsUsingAbility( id )
		local healthpercent = squad_ai:GetHealthPercentage()
		local melee = cpu_manager:IsInMelee( squad_ai )

		if (using == false and (melee == false or healthpercent >= 0.4)) or
		   (using == true and melee == true and healthpercent < 0.4) then
			squad_ai:DoSpecialAbility( id )
		end 	
	end
end,

Edited by LarkinVB, 20 April 2006 - 08:21 AM.


#16 thudo

thudo

    Wacko AI Guy!

  • Division Leaders
  • 12,164 posts
  • Location:Lemonville North, Canada
  • Projects:DoW AI Scripting Project
  • Division:DoW
  • Job:Division Leader

Posted 20 April 2006 - 03:25 PM

Thanks Larkin for hanging in on this. Script development like this is VERY important especially when its called for use "outside the box". I'll give it a test tonight. Once more.. Thanks A TON!
Advanced Skirmish AI Team Lead for the coolest Warhammer40k PC RTS out there:

Dawn of War Advanced AI Headquarters

Latest DoW Advanced AI Download!

#17 thudo

thudo

    Wacko AI Guy!

  • Division Leaders
  • 12,164 posts
  • Location:Lemonville North, Canada
  • Projects:DoW AI Scripting Project
  • Division:DoW
  • Job:Division Leader

Posted 21 April 2006 - 03:11 AM

Update.. okay nearly there. Its REAL CLOSE! Using Larkin's code and then improving it, the following allows the AI to shutoff the ability when the unit's health reaches 40%. It DOES NOT disable the ability when unit is engaged in Melee..

DoAbilityToggleIfHighHealth = function( squad_ai, id )

	if squad_ai:CanDoAbility( id ) then

		local using = squad_ai:IsUsingAbility( id )
		local healthpercent = squad_ai:GetHealthPercentage() < 0.4
		local melee = cpu_manager:IsInMelee( squad_ai )

		if (using == false and (melee == true or healthpercent == false)) or
		   (using == true and melee == false and healthpercent == true) then

			squad_ai:DoSpecialAbility( id )
		end	 
	end
end,
I think you can see the differences over Larkin's code. Now.. is there a way to get the Melee part to work? Its in cpu_manager.ai as requested but obviously isn't functioning. If this is the case, no biggie, Larkin. This is a massive step forward and tested it on all faction which will use it. VERY happy.. the Melee part is a nice bonus! Thanks Larkin for this code! :huh:
Advanced Skirmish AI Team Lead for the coolest Warhammer40k PC RTS out there:

Dawn of War Advanced AI Headquarters

Latest DoW Advanced AI Download!

#18 LarkinVB

LarkinVB

    title available

  • Members
  • 1,488 posts

Posted 21 April 2006 - 06:59 AM

I do not have the slightest idea why you did change my code. You said it should switch OFF when IN melee AND health is BELOW 40%.
That was exactly what I was showing.

Now you changed it to

(using == true and melee == false and healthpercent == true)

which will switch OFF while NOT IN melee AND health BELOW 40%.
Your changes improved nothing !

#19 thudo

thudo

    Wacko AI Guy!

  • Division Leaders
  • 12,164 posts
  • Location:Lemonville North, Canada
  • Projects:DoW AI Scripting Project
  • Division:DoW
  • Job:Division Leader

Posted 21 April 2006 - 12:09 PM

Thanks Larkin. I had to change it because yours did not work. I had to play with it. With yours the ability was kept ON all the time even when health dropped below 40%. Any ideas why mine works with the 40% health but still does not with Melee? We're getting close buddy.

Of course for you this is quite hard to test as you don't have the mod in question: Night_Shift. This is the ONLY custom ability and essentially custom script needed. Btw.. Melee is ONLY needed for both Dreads and Defilers but since those two vehicles get severely damaged anyway when they start into CC (due to enemy shotty units) then the 40% health checker works anyway since it turns the ability for the vulnerable CC unit off anyway.

Anyway, if you want to see the mod let me know.. I have a secret download link and you can quick test it. Its an AI script opposite to the brilliant one you did with FoF but reversed and then a little flair thrown in. ;)
Advanced Skirmish AI Team Lead for the coolest Warhammer40k PC RTS out there:

Dawn of War Advanced AI Headquarters

Latest DoW Advanced AI Download!

#20 LarkinVB

LarkinVB

    title available

  • Members
  • 1,488 posts

Posted 21 April 2006 - 02:09 PM

Ok. Give me the link and I will check.
Define melee please. What is it for you. The dread/defiler attacking ranged units in CC is melee ? Currently melee is definded as enemy commander/infantry/vehicle in attack move + assault stance withing 5 of the vehicle using the ability.

Should the ability also be disabled if the vehicle is just shot at and below 40% health.
What is this ability at all ? PLease give a detailled description of what you want to happen.

Edited by LarkinVB, 21 April 2006 - 02:10 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users