Jump to content


Photo

[CLOSED] For NightShift Project - Smart SearchLight Switching


  • This topic is locked This topic is locked
29 replies to this topic

#21 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 27 March 2006 - 06:59 PM

I require time to digest! ;)
Advanced Skirmish AI Team Lead for the coolest Warhammer40k PC RTS out there:

Dawn of War Advanced AI Headquarters

Latest DoW Advanced AI Download!

#22 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 27 March 2006 - 07:37 PM

Corsix.. where does this go?

function Util_GetIniSetting(sFile, sVal, sDef)
	local ini = nil
	ini = io.open(sFile, "r")
	if(ini ~= nil) then
		for line in ini:lines() do
			for k, v in string.gfind(line, "(%w+)=(%w+)") do
				if(k == sVal) then
					return v
				end
			end
		end
	end
	return sDef
end

function GetActiveDowMod()
	return Util_GetIniSetting("Local.ini", "currentmod", "w40k")
end

function GetActiveWxpMod()
	return Util_GetIniSetting("Local.ini", "currentmodwa", "wxp")
end

function ModIsActive(module_file, iswa)
	if(iswa == true) then
		if(string.lower(GetActiveWxpMod()) == string.lower(module_file)) then
			return true
		else
			return false
		end
	else
		if(string.lower(GetActiveDowMod()) == string.lower(module_file)) then
			return true
		else
			return false
		end
	end
end

function ModIsPresent(module_file, iswa)
	local file_id = nil
	file_id = pcall(io.open, module_file .. ".module", "r"))
	if (file_id ~= nil) then
		file_id:close()
		return true
	else
		return false
	end
end

Above goes in RaceLoader.ai ? I take it no editing to it is necessary as it will auto-detect the .module files dynamically?
Advanced Skirmish AI Team Lead for the coolest Warhammer40k PC RTS out there:

Dawn of War Advanced AI Headquarters

Latest DoW Advanced AI Download!

#23 ArkhanTheBlack

ArkhanTheBlack

    title available

  • Members
  • 814 posts

Posted 27 March 2006 - 08:15 PM

So in conclusion, as long as the bug does not bring up the error reporting thingy then pcall will help.


Thanks Corsix. It might be worth a try... ;)

Above goes in RaceLoader.ai ? I take it no editing to it is necessary as it will auto-detect the .module files dynamically?


I would have guessed that it belongs in utility.ai :)

#24 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 28 March 2006 - 01:58 AM

Okie.. code looks like:

local file_id = nil
file_id = pcall(io.open, "Night_Shift\\data\\attrib\\abilities\\night_dummy_space_marine.rgd", "r")
if (file_id ~= nil) then
if self.squad_ai:GetTactic():HasAbility( "marines_searchlight_dreadnought" ) then
local light1_id = cpu_manager.stats:GetAbilityID( "marines_searchlight_dreadnought" )
Ability.DoAbilitySearchLight( self.squad_ai, light1_id, " vehicle" )

I think the problem is in the tactic.ai for GetTactic():HasAbility:
function Tactic:HasAbility( ability_id )

	-- Get Ability ID
	local iAbilityID = cpu_manager.stats:GetAbilityID( ability_id )

		if (iAbilityID == ability_id ) then
			return true
		end

	return false
end
Does that look correct? Its just not passing it thru.

Btw.. thanks Corsix for the utility.ai code! Its in and works fine with pcall.
Advanced Skirmish AI Team Lead for the coolest Warhammer40k PC RTS out there:

Dawn of War Advanced AI Headquarters

Latest DoW Advanced AI Download!

#25 ArkhanTheBlack

ArkhanTheBlack

    title available

  • Members
  • 814 posts

Posted 28 March 2006 - 08:43 PM

Hmm shouldn't it be either...

local file_id = nil
file_id = pcall(io.open, "Night_Shift\\data\\attrib\\abilities\\night_dummy_space_marine.rgd", "r")
if (file_id ~= nil) then
	local iAbilityID = cpu_manager.stats:GetAbilityID("marines_searchlight_dreadnought")
	if (iAbilityID ~= nil) then
		Ability.DoAbilitySearchLight( self.squad_ai, iAbilityID, " vehicle" )
	end
end

or if GetAbilityID() crashes...

local file_id = nil
file_id = pcall(io.open, "Night_Shift\\data\\attrib\\abilities\\night_dummy_space_marine.rgd", "r")
if (file_id ~= nil) then
	local iAbilityID = pcall(cpu_manager.stats:GetAbilityID, "marines_searchlight_dreadnought")
	if (iAbilityID ~= nil) then
		Ability.DoAbilitySearchLight( self.squad_ai, iAbilityID, " vehicle" )
	end
end

In this case you wouldn't need Tactic:HasAbility()!

#26 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 28 March 2006 - 09:08 PM

It has to be the second one as if I have anything with cpu_manager.stats:GetAbilityID("marines_searchlight_dreadnought") and that ability does not exist and its called "naked" like it is, the game will CTD once the first Dread is created.

I'll test it and see what pcall does if it can prevent the crash AND pass the command over.
Advanced Skirmish AI Team Lead for the coolest Warhammer40k PC RTS out there:

Dawn of War Advanced AI Headquarters

Latest DoW Advanced AI Download!

#27 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 29 March 2006 - 02:07 AM

Update.. do you mean:

local iAbilityID = pcall(cpu_manager.stats:GetAbilityID( "marines_searchlight_dreadnought" ))
if (iAbilityID ~= nil) then
Ability.DoAbilitySearchLight( self.squad_ai, iAbilityID, " vehicle" )
I tried it on its own as above here and its a no go. Its the pcall that is blocking something here and not passing it over to the Ability.DoAbilitySearchLight line below. Any thoughts?

Btw, thanks you guys for the help in figuring this out. This is MASSIVELY HELPFUL and I seriously believe will be important to know in time. Yes its more a "research project" but its practical application is more than mere logic.
Advanced Skirmish AI Team Lead for the coolest Warhammer40k PC RTS out there:

Dawn of War Advanced AI Headquarters

Latest DoW Advanced AI Download!

#28 ArkhanTheBlack

ArkhanTheBlack

    title available

  • Members
  • 814 posts

Posted 29 March 2006 - 11:15 AM

Since Corsix has posted such nice code, I think I'll add one very last thing to 1.7 this evening.

I'll add a custom folder to the AI folder where every mod can place a custom ai file. The name has to be modname.ai, where 'modname' is the same string used for the module file of the mod. If such a file exists, I'll run an Init method of the class in this file which has to exist and which name must also be the module name.

You can then, for example, create a nightshift.ai file (Provided that the module file is called nightshift.module) which has just a parameter NightShiftIsActive = true and a nightshift class with just a lonly init.

You can then use the nightshift abilities everywhere like that:

if (NightShiftIsActive ~= nil) then
	local iAbilityID = cpu_manager.stats:GetAbilityID("marines_searchlight_dreadnought")
	Ability.DoAbilitySearchLight( self.squad_ai, iAbilityID, " vehicle" )
end

I'll send you a mail this evening/night when I'm finished...

#29 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 29 March 2006 - 12:42 PM

:ohmy: Fantastic! The key is to be able to just check for GetAbilityID ( "<ability name>" ) rather than a real-time live detect (which if its not there CTDs the game). Thanks a ton, Arkhan!
Advanced Skirmish AI Team Lead for the coolest Warhammer40k PC RTS out there:

Dawn of War Advanced AI Headquarters

Latest DoW Advanced AI Download!

#30 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 26 April 2006 - 03:14 AM

Closing this thread as it is now moved to other one for MultiModing..
Advanced Skirmish AI Team Lead for the coolest Warhammer40k PC RTS out there:

Dawn of War Advanced AI Headquarters

Latest DoW Advanced AI Download!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users