Jump to content


Photo

Checking Cpu_DoString


7 replies to this topic

#1 Finaldeath

Finaldeath
  • Project Team
  • 188 posts
  • Location:UK

Posted 27 January 2006 - 01:39 PM

Hey AI team,

I want to know if anyone knows anything more about the SCAR function Cpu_DoString.

Official description:

Runs a string on an AI player
Void Cpu_DoString(
PlayerID player,
String s,
)

I added a little about what I thought it implied to the wiki:

http://www.relic.com...ons/CpuDoString

However I do not know the specifics on how this works.

It could be useful for singleplayer AI - since the SCAR script ditacts the difficulty, and activation (or lack of) the CPU AI files, and can interject some commands and stop the AI from using some units.

This, in combination with the other things, could allow a specific map to have, for a race, a specific build pattern or something - if the string is activated when the AI is enabled, it could load new files or something.

But I'm not entirely sure how it works. My example is:

-- Possible example. Run this on an AI player to do the same thing as Cpu_CounterVictoryObj
Cpu_DoString(World_GetPlayerAt(1), "CpuManager:CounterVictoryObj()")

Which may not actually be a correct use of it.

can anyone either be able to test is or perhaps say what it could be? Or provide a better example of a function to execute which'll provide feedback (or how to add a simple one to the default.ai file perhaps) when executed via. this so I can test this?

Thanks for any info guys!

#2 ArkhanTheBlack

ArkhanTheBlack

    title available

  • Members
  • 814 posts

Posted 27 January 2006 - 10:15 PM

No idea! Never used this function. If it works like you say, it could be used to give the AI some custom parameters. For example the map name, which could offer lots of interesting options...

#3 Finaldeath

Finaldeath
  • Project Team
  • 188 posts
  • Location:UK

Posted 01 February 2006 - 10:38 PM

No other ideas eh?

Anyone else?

And do you have a sample function that could be made up to, say, print a string to the log file? So I can add it to the default AI file and test this? I don't want to get stopped by the first issue of now knowing if a funciton I test actually does something :p

#4 Corsix

Corsix

    Code Monkey

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

Posted 01 February 2006 - 10:45 PM

There is this function I write for utility.ai :

--AI log dump to text file (activate in cpu_manager.ai when self.debug = true)

function ailog( logfile, msg ) 

   

   local log log = io.open( logfile , "a+" ) 

   if player_id == nil then 

	  log:write("AI"," ", tostring(msg) , "\n") 

   else 

	  log:write("AI"..player_id," ", tostring(msg) , "\n") 

   end 

   

   log:close() 

   

end
Other people have written more advanced logging code, but thats the basic function
stack_trace_num = 0

tracing = {}



g_bAITrace = false



function aitrace( msg )



	if (g_bAITrace) then

	

		for i = 0, stack_trace_num-1 do

			msg = ("   "..msg)

		end

	

		table.insert(tracing, msg)

		

		-- Arkhan 09.2005: Remove comment characters to get AI-Trace log file at root

		-- Debug start

		local txt = cpu_manager.cpu_player:GetGameTime().." "..msg

		ailog("c:\\"..tostring( player_id).."aitrace.txt", txt)

		-- Debug end

	end

end

Posted Image

#5 Finaldeath

Finaldeath
  • Project Team
  • 188 posts
  • Location:UK

Posted 02 February 2006 - 12:50 AM

Will use the first, thanks corsix, as long as it works its fine, I just need to test printing a message :p

Will also allow me to test parameters :)

#6 Finaldeath

Finaldeath
  • Project Team
  • 188 posts
  • Location:UK

Posted 04 February 2006 - 04:04 AM

Finally sorted out my installation so I could test this, it works, woo!

Basically it will do whatever is put into the input. There is something special needing to be used to make it work properly however.

For example:

	for i = 0, count-1 do
		-- Test this using logs.
		Cpu_DoString(World_GetPlayerAt(i), "print('hello world')")
	end

Will print, into the AI log, for each player the string "hello world". that example basically shows the extent of the complexity - that strings within strings have to be ' ' and not " ".

You can do anything else, eg:

Cpu_DoString(World_GetPlayerAt(i), "blah = 1")

Will set "blah" to equal the value 1, on player i.

If we then call this:

Cpu_DoString(World_GetPlayerAt(i), "print(blah)")

It will print "1" if i is the same player.

I am thinking, although i've not gone this far, the function calls things on a global scale - not inside another function.

So, we can call any function, or do value setting, in the AI files themselves. :)

Fun stuff eh? I'll be looking into using this for setting specific build strageties and patterns, overriding what the AI has already set, once the AI has an easier way of adding new build patterns.

It'd be a good idea if a new include file could be created specifically for singleplayer modders. Something like "import( 'custom.ai' )" at the top of the default.ai file, which contains any functions the modder wants to add specifically for his mod installation - for singleplayer.

So, I can add in there, say, a function to change Orks so they will now build a second base straight away, defend their ally, do special build patterns, or something. :blink:

#7 LarkinVB

LarkinVB

    title available

  • Members
  • 1,488 posts

Posted 26 March 2006 - 08:55 PM

Can we use this so the AI ally will send its troops to a destination at the minimap the player does ping ?

This would be cool :D

#8 Finaldeath

Finaldeath
  • Project Team
  • 188 posts
  • Location:UK

Posted 26 March 2006 - 10:15 PM

SCAR is map dependant, I'm afraid. That, and the player's pings can't be detected using SCAR.

However, if you made a map where specifically you had a new button "attack and guard area" or somesuch, you could use Cpu_DoString to set the location, for instance, if the AI knew how to use this new change.

SCAR is, remember, map dependant. Not many user inputs apart from those used in the tutorial (moving your cursor, clicking, closing the objectives box, looking around, zooming) can be detected, even less so for multiplayer.



Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users