Jump to content


Photo

AI + Custom DLL =


  • Please log in to reply
13 replies to this topic

#1 Corsix

Corsix

    Code Monkey

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

Posted 30 June 2006 - 04:23 PM

I've managed a proof of concept DLL for AI modding which exports a variable to the AI scripts. I put this into cpu_manager.ai:
ailog("e:\\"..tostring( player_id).."aitrace.txt", CorsixHooks)
And then appears in the log file:
AI1001 0.1 DEV
The easiest thing to implement from here would be inter-AI communication. In single player, all of the AIs are run on the one computer. In multiplayer, the AIs may be spread out amongst the players, so we'll have to find this out as the communication can only be between AIs running on the same computer.
After we find this out, I want to know how you want this implemented. Current planning:
- Add global function called "GetHookedAICount()" which returns the number of AIs running on this computer
- Add a function to the cpu_manager class called "cpu_manager:receive_message(string)"
- Add a global function called "SendAiMessage(string)"
Whenever SendAiMessage is called, for every other AI running on this computer, cpu_manager:receive_message would be called.
Arhkan, would this be good, or would you like it slightly differently?
Posted Image

#2 ArkhanTheBlack

ArkhanTheBlack

    title available

  • Members
  • 814 posts

Posted 30 June 2006 - 10:12 PM

A broadcast message would be nice with SendMessage() and ReceiveMessage(), though I don't know why you need a special method to get the AI count. A message should also contain the ID from the sender.

The message feature could be usefull to transfer base positions and attack targets. Very interesting approach! :p

#3 Corsix

Corsix

    Code Monkey

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

Posted 04 July 2006 - 08:14 PM

Just so you know, by tomorrow I should have a version to test, and by the day after I should hopefully be able to post it here for you to test.

As for AIs in multiplayer, they are distributed evenly and randomly over all the players. As such, AI communication in multiplayer wil be slightly restricted.
Posted Image

#4 Corsix

Corsix

    Code Monkey

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

Posted 05 July 2006 - 07:06 PM

The DLL: download here (place in your DoW directory)
How to use it: Make sure it is in your DoW directory and then open the AI mod .module file, and change the DllName line to:
DllName = dowai_mod
What it does: Allows AI players running on the same computer to communicate with each other

Detailed documentation:
Global variable aimod_extensions_version
This variable will be set if the DLL is loaded correctly, and for this version of the DLL it is the string "1.0". If the DLL is not loaded then this varialbe will be nil.

Global table ai_communication
This is a global table which contains all of the communication methods (the three methods below)

ai_communication.can_talk_to
In: float PlayerID [, float PlayerID2 [, float PlayerID3 [, ...]]]
Out: float Number
Returns the number of players which can be contacted of the list of PlayerIDs passed
Useful to find out which AI players are running on this computer

ai_communication.send_broadcast
In: string FunctionName [, any Arg1 [, any Arg2 [, ...]]]
Out: none
Calls FunctionName(Arg1, Arg2, ...) on every other AI player
FunctionName must be a global function
Arg1 through ArgN can be: nil, boolean, number, string, or table (but table keys and values can only be nil, boolean, number, string and tables)
Returns nothing

ai_communication.send_message
In: number TargetPlayerId, string FunctionName [, any Arg1 [, any Arg2 [, ...]]]
Out: [any Return1 [, any Return2 [, ...]]]
Calls FunctionName(Arg1, Arg2, ...) on the AI with player ID TargetPlayerId
Cannot call itself (will return nil)
FunctionName must be a global function
Arg1 through ArgN can be: nil, boolean, number, string, or table (but table keys and values can only be nil, boolean, number, string and tables)
Returns the return value(s) of FunctionName(Arg1, Arg2, ...)
Return1 through ReturnN can be: nil, boolean, number, string, or table (but table keys and values can only be nil, boolean, number, string and tables)
If the AI with player ID TargetPlayerId cannot be found, then nothing is returned

Example code
function recv_message(from, arg1, arg2, arg3)
	aitimelog("C:\\ailog.txt", "Got message from " .. tostring(from) .. ": " .. arg1 .. " " .. tostring(arg2) .. " " .. tostring(arg3))
end

function recv_chat_message(from, arg1, arg2, arg3)
	aitimelog("C:\\ailog.txt", "Got chat from " .. tostring(from) .. ": " .. arg1 .. " " .. tostring(arg2) .. " " .. tostring(arg3))
	return "cheese pie", "ret2", arg2 + 2
end

-- ...

		msg_to_print = "Can talk to: "
		for i = 1000 , 1010 do
			if(ai_communication.can_talk_to(i) == 1) then
				msg_to_print = msg_to_print .. tostring(i) .. " "
				if i ~= self.player_id then
					ret1, ret2, ret3 = ai_communication.send_message(i, "recv_chat_message", self.player_id, "cheese", 15, true)
					aitimelog("C:\\ailog.txt", "Got reply from " .. tostring(i) .. ": " .. tostring(ret1) .. " " .. tostring(ret2) .. " " .. tostring(ret3))
				end
			end
		end
		aitimelog("C:\\ailog.txt", msg_to_print)
		ai_communication.send_broadcast("recv_message", self.player_id, "some_string1", 42, true)

Comments / questions ?
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 05 July 2006 - 07:23 PM

Outstanding work, Corsix! Marvellous indeed. Also easy to implement for mods as well since its one line. I will have to test in a multimod setting where one master .module file controls what mods are loaded. Should be a simple test and would simplify things if it needed only the one .module to associate to all the mods rather than the individual mod's .module.

Congrads on this development and strike out one against Relic.
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 06 July 2006 - 04:05 PM

Impressive work! :p I'll have a closer look on it when 1.8 is out. Do you use global variables as message transfer medium, or files?

Is it possible to expand this functionality somehow to include player commands?

#7 Corsix

Corsix

    Code Monkey

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

Posted 06 July 2006 - 04:24 PM

Do you use global variables as message transfer medium, or files?

Niether. Global varialbes wouldn't work, and files are too slow. The DLL copies the values directly from one AI's LUA to the other AI's LUA.

Is it possible to expand this functionality somehow to include player commands?

I don't know yet...
Posted Image

#8 LarkinVB

LarkinVB

    title available

  • Members
  • 1,488 posts

Posted 29 July 2006 - 11:03 AM

As for AIs in multiplayer, they are distributed evenly and randomly over all the players. As such, AI communication in multiplayer wil be slightly restricted.


Sure ? So all have to have identical AI + AIControlPanel settings for an even game ?
I thought the AI was only running on the host computer.

Edited by LarkinVB, 29 July 2006 - 11:04 AM.


#9 Finaldeath

Finaldeath
  • Project Team
  • 188 posts
  • Location:UK

Posted 29 July 2006 - 05:29 PM

RTS games don't have a "host" except perhaps for loading the game level.

All thing is distributed, and sync packets of info are sent over the connection to make sure everything on everyones end is doing the same stuff.

Yes, it basically runs a skirmish on your PC but you get packets saying where the other players units move, and damage is obviously the same on all machines due to how randomness is seeded, etc.

#10 LarkinVB

LarkinVB

    title available

  • Members
  • 1,488 posts

Posted 30 July 2006 - 07:00 AM

Summary : Players have to use similar AIControPanelSettings or the AI wil act differently during one game, right ?

#11 Finaldeath

Finaldeath
  • Project Team
  • 188 posts
  • Location:UK

Posted 01 August 2006 - 08:52 AM

I assume so. I've not tried it out yet however, might be worth testing. I guess it will sync error quite early on.

#12 LarkinVB

LarkinVB

    title available

  • Members
  • 1,488 posts

Posted 10 August 2006 - 09:53 PM

Perhaps Arkhan can add a 'default' button so players can sync their panel settings before starting a network compstomp.

#13 Corsix

Corsix

    Code Monkey

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

Posted 11 August 2006 - 10:36 AM

Replays from the AI mod work without the AI mod installed, so I assume that two different players with different AI settings do not conflict.
Posted Image

#14 Finaldeath

Finaldeath
  • Project Team
  • 188 posts
  • Location:UK

Posted 12 August 2006 - 02:09 PM

Replays from the AI mod work without the AI mod installed, so I assume that two different players with different AI settings do not conflict.


Replays?!

Replays don't have anything to do with the AI, or players as a matter of fact. They mearly record the in-game actions.

AI's that do different things must be problematic.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users