Jump to content


Photo

MultiMod detection system


  • Please log in to reply
43 replies to this topic

#1 thudo

thudo

    Wacko AI Guy!

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

Posted 20 April 2006 - 05:34 PM

Creating its own thread on this subject..

Essentially.. Arkhan came up with this brillant script which when used with this:

if (cpu_manager:GetActiveModInfo("<mod name>") ~= nil) then
Where <mod name> is the name on the line in Local.ini (found in DoW's root folder) which tells what active mod is being loaded.

The scripts that drive it are found in utility.ai:
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+)=(.+)") 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
This work great and now when mod is active the AI can check if it exists then run any mod-specific code we wish..

Now.. the new challenge..

Whats going to happen is in order to incorporate multiple mods at once the above scripts DO NOT take into account many mods being used at once.. it only checks in Local.ini for an active mod but not then that mod's .module file for such things as..
RequiredMod.3 = steel_legion
RequiredMod.4 = harlequins
RequiredMod.5 = tyranids
RequiredMod.6 = Tau_Mod
From RequiredMod.3 to, say, 99 should be checked and then acknowledged as being active as well similar to the main mod detection. Is this possible?

A new script would look like this before running custom mod scripts:
if (cpu_manager:GetRequiredModInfo("<mod name>") ~= nil) then

Thanks all! Input is INCREDIBLY valuable!
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 Corsix

Corsix

    Code Monkey

  • Hosted
  • 290 posts
  • Location:Berkeley, UK
  • Projects:DoW AI, DoW Mod Studio
  •  Blue Text :)

Posted 26 April 2006 - 04:29 PM

This is untested as I don't have a copy of WA installed (my WA CD 2 is corrupt):
function Util_AllActiveMods(sActiveMod)

	local reqs = {}

	reqs[0] = sActiveMod

	local ini = nil

	ini = io.open(sActiveMod .. ".module", "r")

	if(ini ~= nil) then

		for line in ini:lines() do

			for k, v in string.gfind(line, "RequiredMod%.([1-9][0-9]*)%s*=%s*(.+)") do

				reqs[k] = v

			end

		end

	end

	return reqs

end
You pass it the name of the active mod (which you get from GetActiveDowMod() or GetActiveWxpMod() ) and it should return a table/list of all the active mods (so the mod you passed to it and all of it's required mods). Again, it is untested, so it may not work.
Posted Image

#3 thudo

thudo

    Wacko AI Guy!

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

Posted 26 April 2006 - 04:40 PM

Okie excellent.. this is a fantastic start Corsix! Very important as well..

Now my question is when I test it tonight:

1) If I have this:
RequiredMod.3 = steel_legion
RequiredMod.4 = harlequins
RequiredMod.5 = tyranids
RequiredMod.6 = Tau_Mod
But the main active mod is called, say, "master_mod" then I can still use, for example:

if (cpu_manager:GetActiveModInfo("tyranids") ~= nil) then
and it will pass over to the next scripts I choose to run IF it finds "tyranids" in one of the RequiredMod sections of the main active mod "master_mod"?

2) There was another thing I forgot to mention that Arkan coded. There is a folder called CUSTOM you'll see in our \AI folder. It identifies active main mods. Does this still need to contain any mention of, say, the tyranid mod as well?

File would look like:
----------------------------------------
-- File: 'tyranid.ai'
-- Created by Thudmeizer	@ 26.04.2006

class 'tyranid'

-- Constructor
function tyranid:__init()
	
end

-- Returns a specific information
function tyranid:GetInfo(sType)

	-- Check info type
	if (sType == "tyranid") then
		return true
	end
	return nil
end
If the master_mod was being used here obviously substitute all "tyanid" above with "master_mod".
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 Corsix

Corsix

    Code Monkey

  • Hosted
  • 290 posts
  • Location:Berkeley, UK
  • Projects:DoW AI, DoW Mod Studio
  •  Blue Text :)

Posted 26 April 2006 - 05:51 PM

I don't know. You havn't posted the code for GetActiveModInfo

Edited by Corsix, 26 April 2006 - 05:51 PM.

Posted Image

#5 thudo

thudo

    Wacko AI Guy!

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

Posted 27 April 2006 - 02:54 AM

Sorry Corsix..

function CpuManager:__init( cpu_player_id )

	-- Arkhan 03.2006: Active mod class
	self.m_oActiveMod = nil

function CpuManager:InitCustomAI()

	-- Get active mod name
	local sActiveModName = GetActiveWxpMod()
	if (sActiveModName == "wxp") then
		return
	end
	
	-- Check if a custom AI file is present
	pcall(import ,'Custom/'..sActiveModName..'.ai')
	if (_G[sActiveModName] ~= nil) then
		self.m_oActiveMod = _G[sActiveModName]()
		print("Custom AI activated for "..sActiveModName.."...")
	end
end

-- Arkhan 03.2006: Requests information from the active mod
function CpuManager:GetActiveModInfo(sType)

	-- Check if we have a custom AI for the active mod
	if (self.m_oActiveMod == nil) then
		return nil
	end
	
	-- Return info
	return self.m_oActiveMod:GetInfo(sType)
end
Hope that helps you determine a solution!
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 ArkhanTheBlack

ArkhanTheBlack

    title available

  • Members
  • 814 posts

Posted 27 April 2006 - 02:35 PM

At the current state, only the custom AI of the master mod is loaded. If other custom AI's should be loaded too, then the master mod should include some kind of loading script for them.

The detection of child mods can be solved much easier by (ab)using the GetActiveModInfo() method. Instead of using cpu_manager:GetActiveModInfo("<mod name>"), you could use cpu_manager:GetActiveModInfo("NightShift") to find out if the Nightshift mod is loaded. The only thing you have to do is adjusting the custom AI to return true if asked for "NightShift". The advantage is that you can now set multiple mods as active. In your case, you'd return true for "steel_legion", "harlequins", "tyranids" and "Tau_Mod" in the custom AI. This is much easier and more flexible.

#7 thudo

thudo

    Wacko AI Guy!

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

Posted 27 April 2006 - 02:49 PM

As simple as:
if (cpu_manager:GetActiveModInfo("tyranids") == true) then
Just like that?
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 27 April 2006 - 04:48 PM

Exactly!

#9 thudo

thudo

    Wacko AI Guy!

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

Posted 27 April 2006 - 05:07 PM

Sounds too easy... So no new scripts even need to be coded in for this to work? Will let ya know ASAP tonight as this has ALOT of potentially good ramifications for AI and multimod setups! :lol:
Advanced Skirmish AI Team Lead for the coolest Warhammer40k PC RTS out there:

Dawn of War Advanced AI Headquarters

Latest DoW Advanced AI Download!

#10 thudo

thudo

    Wacko AI Guy!

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

Posted 28 April 2006 - 01:19 AM

Okay so I had my master_mod running with NightShift as so:

In Local.ini..
currentmodwa=master_mod

In master_mod.module
RequiredMod.1 = WXP
RequiredMod.2 = W40k
RequiredMod.3 = Night_Shift

master_mod was detected as being loaded (master_mod.ai in \custom) and indeed Night_Shift was running.. The script I used to check as I do normally but now added an "or" for the next requirement as per Arkhan:

if (cpu_manager:GetActiveModInfo("night_shift") ~= nil) or (cpu_manager:GetActiveModInfo("night_shift") == true) then

But did not work. I also used Corsix's new script there in utility.ai but to no avail.
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 ArkhanTheBlack

ArkhanTheBlack

    title available

  • Members
  • 814 posts

Posted 28 April 2006 - 12:03 PM

You probably forgot to adjust the custom AI. It has to look like that:

-- Returns a specific information
function master_mod:GetInfo(sType)
	if (sType == "night_shift") then
		return true
	elseif (sType == "tyranids") then
		return true
	elseif (sType == "steel_legion") then
		return true
	elseif (sType == "Tau_Mod") then
		return true
	elseif (sType == "harlequins") then
		return true
	end
	return nil
end


#12 thudo

thudo

    Wacko AI Guy!

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

Posted 28 April 2006 - 01:49 PM

And yes right.. just wonder though if there is a way to NOT have to edit that master_mod.module to add static modnames? Again.. this whole endeavour is to see how we can best detect mods with as little effort and user editing as possible.
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 Corsix

Corsix

    Code Monkey

  • Hosted
  • 290 posts
  • Location:Berkeley, UK
  • Projects:DoW AI, DoW Mod Studio
  •  Blue Text :)

Posted 28 April 2006 - 02:33 PM

There is, and thats using the code I posted. Just putting it into utility.ai won't make it suddeny work though. Like I said, I cannot integrate it as I don't have WA installed, but Arkhan should be able to plug it into the current system.
Posted Image

#14 thudo

thudo

    Wacko AI Guy!

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

Posted 29 April 2006 - 06:28 PM

Okie... found 2 problems to MultiMod Detection

1) Since we are using Local.ini to check what current mod is activated the problem arises when the user, while still in the gane, changes the active mod in the main menu. Doing this DOES NOT update the Local.ini so the ini still thinks its using the older mod. The only way to recify this is the close DoW down and then restart. How do we rectify this now with this new realization?

2) This is Night_Shift related (I've asked Palii from the mod to join us on this in this thread) but the problem is now is: the AI uses the searchlights even on regular Non-Night_Shift Maps even though human players cannot. Anyone have a recommendation or check idea for this?
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 Palii

Palii
  • Members
  • 6 posts

Posted 29 April 2006 - 06:34 PM

Greetings to everyone. The night shift mod is having a bug in the AI department. Thudmeizer suggested that I post here, where the elite coders reside.

The Issue:
Some maps are night maps, others are day maps. The goal is to make the skirmish AI aware of the map type. On night maps it will use searchlights, but not on day maps. Here are some clues about night maps, that could help with this issue.

Possible Clues:
#1. Map name: Can the Ai determine this?
#2. Map file name: And this?
#3. Player_Night_Dummy_1: This is a dummy building, that is placed only on night maps. One is placed for each player, belonging to the players. This dummy building is invisible and unselectable, but it is coded so that it can be used as a building requirement for lua abilities. It works and acts like a building. Despite that it is placed in Mission Editor, each will become part of player's race. Can the AI determine if the AI controlled player owns such a building or not?
#4. Active Mod: Thud used this one, and it worked, until we realised that this only works perfectly under dev mode. So relic screwed something up related to this one.
#5. Declared Variable: Each map can have its own scar file. What if we declare a variable in that scar? Only on night maps, something like "this_is_night_map = 1" Can the Skirmish AI have access to such a variable?

I'm not a scar coder, I'm unaware of the possibilities. Any other solutions are welcome. Thanks for your time.

Edited by Palii, 29 April 2006 - 06:35 PM.


#16 thudo

thudo

    Wacko AI Guy!

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

Posted 29 April 2006 - 06:48 PM

#4. Active Mod: Thud used this one, and it worked, until we realised that this only works perfectly under dev mode. So relic screwed something up related to this one.

Actually it does work whether -dev or not.. the problem is in Local.ini - it DOES NOT get updated in realtime when a user changes the mod in Game Manager while in the game. Bah! Silly Relic. :p
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 LarkinVB

LarkinVB

    title available

  • Members
  • 1,488 posts

Posted 29 April 2006 - 10:32 PM

Hi Palii,

Here 2cents from a non elite coder :

I guess #1,#2 and #4 are no options.

#3 should be possible but I prefer #5.

Check this thread.

Cpu_DoString() with map SCAR might be the solution.



Actually it does work whether -dev or not.. the problem is in Local.ini - it DOES NOT get updated in realtime when a user changes the mod in Game Manager while in the game.


I started the nightshift mod from desktop shortcut and it didn't work. I did not use the ingame manager at all. Seems related to local.ini too, it tried the load the custom mod file from the last mod played, not the one just started. Just want hint that it can malfunction even while not touching the ingame manager at all.

Edited by LarkinVB, 29 April 2006 - 10:35 PM.


#18 thudo

thudo

    Wacko AI Guy!

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

Posted 29 April 2006 - 11:35 PM

I started the nightshift mod from desktop shortcut and it didn't work. I did not use the ingame manager at all. Seems related to local.ini too, it tried the load the custom mod file from the last mod played, not the one just started. Just want hint that it can malfunction even while not touching the ingame manager at all

Hmmm.. I don't understand.. If you run the game first with another mod then exit. Then start the game using the Night_Shift's own shortcut "W40kWA.exe -modname night_shift" it won't switch in the local.ini file? Huh? That makes no sense. I'll have to try that. However.. if your in the game using ONE mod, then switch to Night_Shift with the game manager then exit then it should update local.ini.
Advanced Skirmish AI Team Lead for the coolest Warhammer40k PC RTS out there:

Dawn of War Advanced AI Headquarters

Latest DoW Advanced AI Download!

#19 Palii

Palii
  • Members
  • 6 posts

Posted 30 April 2006 - 01:25 AM

If you run the game first with another mod then exit. Then start the game using the Night_Shift's own shortcut "W40kWA.exe -modname night_shift" it won't switch in the local.ini file?

Yes! That is right. I experienced this same damn bug :(
If you run in dev mode, then it works every time.

Cpu_DoString() with map SCAR might be the solution.

I hope it will work out, seems good to me. I glanced at the thread, but this is out of my league.

Tell me Thud if I can do anything to help.

#20 thudo

thudo

    Wacko AI Guy!

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

Posted 30 April 2006 - 01:43 AM

Hmm.. yer gonna have to set that value then for the map OR find some way to ensure the searchlight abilities are firmly SHUT OFF on non Night_Shift maps. I have no clue why the AI would use the searchlights on maps it cannot have em - thats a mod bug me thinks. That tells me the AI is working fine but the mod still allows the searchlights except the UI doesn't show it for the human player. Possible?
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