Game Development Community

Multiple Bots with Different Logic

by joint heir · in Technical Issues · 08/26/2005 (5:03 pm) · 10 replies

HI I need some help on this one. I've developed several types of "AI Logic," for my game. I Have 1) Archers 2) Guards and 3) Pursuit Bots. I can make each category work independently by adding an "AI Manager" to the game.cs file for each logic type.

The problem occurs when I try to run them all together, they all follow only one logic. for example all will act as guards or all will act as pursuit bots... I'm trying to put all the different logic driven bots in the game at the same time so they can interact. What Can I do?

#1
08/27/2005 (4:10 pm)
I think a good way to do it may be assigning the bot's datablocks different category names, and then use a different behaviour depending on what category every bot belongs to.
In this case, you could find useful the "faction system resource" (not sure about the real name right now).
Otherwise you could have 3 differently named aimanagers (as far as I know AImanager gets created inside aiplayer.cs as an object, with name, bells and whistles) and use each one with the right bot.
Hope it was useful.

Bye, Thc.
(soon: thc -> berserk)
#2
08/27/2005 (4:35 pm)
Joint you could implement a state machine functionality for your ai. maybe you could use random numbers to decide the current state and scheduled time to the next state. you could possibly set this as a randomly generated numerical property when the object is created.
#3
01/13/2008 (9:13 am)
Hi, i tried to create another AI by creating another .cs file ; for example aiplayer2.cs

Then i just changed the datablock name in the new file and in player.cs, i added a second AIManager script.

I also changed the shapefile to another dts.

But when i compile, the second AI is not spawning, it went missing. Am i doing the right steps in creating another AI with different logic?
#4
01/13/2008 (9:37 am)
@Rushh, please do not post on old threadss, this thread was made over 2 years ago...
#5
01/13/2008 (10:07 am)
I don't understand that really... what is wrong with bringing a thread back from the dead? Especially if you're discussing similar topics that are already covered there.... ?
#6
01/13/2008 (10:57 am)
@rushh, it sounds like you've got the right idea. Did you make sure that your second AIManager script is looking for your new datablock? Check for misspellings? The process you outlined is how I've done multiple AI types so it does work.

On a side note I see nothing wrong with reusing an old post, your problem is similar to the original posters and I think its better to consolidate forum discussions by similarity rather than having dozens of similar threads spread out over the years. There are threads over two years old that are still up and running today.
#7
01/13/2008 (6:52 pm)
Thanks, I agree, better than having to create a new thread which talks about similar thing. Okay thats not important...

Ok, i got two AI Player spawning side by side. But I changed the shapefile for the second AI. But it still take the shapefile from the first AI. I mean even if i changed to other shapefile, it still doesn't want to change. Any idea?
#8
01/13/2008 (6:56 pm)
Quote:
@Rushh, please do not post on old threadss, this thread was made over 2 years ago...

Ignore this please--there is nothing wrong whatsoever with replying to an old thread, as long as you are both on point with the original thread, and realize that both the information, as well as the people involved in the original discussion, may be outdated.
#9
01/19/2008 (11:04 pm)
I tried to add a second AI but not successful.

Here's what did..

Add second AIManager script in game.cs (AIManager2)
Create a second bot2.cs. (the content are as below)

datablock PlayerData( Bot2 : PlayerBody)
{
renderFirstPerson = false;
shapeFile = "~/data/shapes/player/player_org.dts"; 
//I changed the shapefile here to differentiate the  second AI       

};

//-----------------------------------------------------------------------------
// AIPlayer static functions
//-----------------------------------------------------------------------------

function AIPlayer::spawn( %name, %spawnPoint )
{
	// Create the A.I. driven bot object...
	%player = new AIPlayer()
	{
		dataBlock = Bot2; //changed the datablock to the second AI datablock
		path = "";
	};

	MissionCleanup.add( %player );
	%player.setShapeName( %name );
	%player.setTransform( %spawnPoint );
   	return %player;
}

function AIPlayer::spawnOnPath( %name, %path )
{
	// Spawn a bot and place him on the first node of the path
	if( !isObject( %path ) )
	{
		echo( "AIPlayer::spawnOnPath failed - Bad Path!" );
		%this.path = "";
		return;
	}

	%node = %path.getObject(0);
	%player = AIPlayer::spawn( %name, %node.getTransform() );

	return %player;
}


//-----------------------------------------------------------------------------
// AIManager static functions
//-----------------------------------------------------------------------------

function AIManager2::think( %this )
{
   if( !isObject( %this.player ) )
      %this.player = %this.spawn();

   %this.schedule( 500, think );
}

function AIManager2::spawn( %this )
{
	%bot2 = AIPlayer::spawn( "Bot 2", "37.8851 -419.900 0.0297761 0 0 -1 1.34971" );



   return %bot2;
}


Questions...
Wll the order of exec the .cs file in game.cs affect anything?
Will adding a second AI overwrite the AIPlayer classname of the first AI?
#10
01/20/2008 (6:53 am)
Its ok....figured it out...