Author Topic: Ai Examples  (Read 4777 times)

Offline xamlit

  • Full Member
  • ***
  • Posts: 160
Ai Examples
« on: June 19, 2005, 10:10:57 PM »
Any AI examples that I can look at, kinda like hoovile?

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4952
Ai Examples
« Reply #1 on: June 19, 2005, 10:24:18 PM »
For the last time, it's "Hooville". With 2 l's. Not some evil, vile, despicable thing.  :P

And I think Eddy has posted a fair bit on AI.

Hmm, is it perhaps time to work on a new SDK update/version?
 

Offline Leviathan

  • Hero Member
  • *****
  • Posts: 4055
Ai Examples
« Reply #2 on: June 20, 2005, 10:08:35 AM »
With some basic AI stuff in!

Offline xamlit

  • Full Member
  • ***
  • Posts: 160
Ai Examples
« Reply #3 on: June 20, 2005, 11:40:08 PM »
Yup! That'd be pretty sweet. Thanx for anything!

Offline BlackBox

  • Administrator
  • Hero Member
  • *****
  • Posts: 3093
Ai Examples
« Reply #4 on: June 21, 2005, 07:44:03 AM »
Quote
For the last time, it's "Hooville". With 2 l's. Not some evil, vile, despicable thing.  :P
Maybe you should have named it "HooLand" or something :P

Quote
Hmm, is it perhaps time to work on a new SDK update/version?

That would be a good idea, since I don't think the Hooville kit is quite adequate enough in its current state (no offense given Hooman :P ) for some maps people are doing, so they're having to modify it (Joe did a lot of changes to it, and some source files with those changes merged in and made "official" would be really nice).

Some "hacks" I have seen being made to Hooville are:
  • Cargo of Structure Factories, you have to do a nasty hack to create the SF manually and make sure it ends up in the right base.
  • GP's, those have to be put in the vehicle arrays to give them a weapon.
  • Beacons and structures that aren't relative to a player position (have to create an extra array that contains absolute coordinates).
  • Lava animation controls. Not really a hack but functionality that would be nice to have.
  • Disaster controls. Disasters are one of the most untouched, yet vital areas of OP2 mission design. A system that can automatically spawn various disasters in the mission and control them would make it easy on the person writing the mission.
Drop-in code would be nice. Also, a system to make trigger creation easier would be great for newbies to C++. (We have to explain that a lot). Or maybe just more "template" triggers, like functions that autocreate things like RR, SR, or Midas triggers.

Also, perhaps we make different kits for different mission types (we have Hooville for a basic LoS mission, but having ones for colony games would be nice). For example colony game missions could have extra AI functions, etc in them.

Also: We need to figure out why maps that are using Hooville are crashing (and not all of them are crashing, but a lot are)

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Ai Examples
« Reply #5 on: June 21, 2005, 12:37:32 PM »
Quote
And I think Eddy has posted a fair bit on AI.
yes, i did.. Check this thread in the "Outpost 2 coding" forum.

I've mentioned before, any specific thing you want to learn or know, just ask. I'll try to work out some example code on how to do stuff. For the meantime i suggest you read the section on Triggers carefully, and play around with it, since they are the key thing with AI.
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4952
Ai Examples
« Reply #6 on: June 21, 2005, 04:57:33 PM »
Quote
Maybe you should have named it "HooLand" or something
Umm, no. Haven't you ever watched "The Grinch"? The town in called "Hooville", not "HooLand".


And I realize Hooville isn't adequate. Which is why I've been thinking about updating things. The increased use it's been getting has made a few flaws apparent. The hacks for SFs I've seen largely are sick. And the hacks for Convecs are even sicker. Anyways, there was some code I posted for using enums to find SFs build in the usual array data structure way, and then fill them with kits. It wasn't a lot of code and wasn't too bad. Although, it still doesn't address a few more general issues I'd like to. Anyways, I have some plans for how to handle this.

Also, the beacons attached to a base seems kinda flawed. Currently, if the base isn't created, neither are the beacons. Leaving empty startnig locations that you can't move into later. Anyways, the old way of creating beacons using a global map list still has it's code around. It just isn't being used in the current project so lots of people seem to be asking about it.

Oh, and I forgot to fix that day/night thing to be more standard. It was something I origianlly wanted in my level, but I don't think it's a good idea to have that in a sample project. It isn't what most people want and it's been misinterpreted as a bug.

Any bright ideas for handling disasters? I don't see an easier way of making area specific disasters. And one set of disaster settings doesn't exactly fit all. Maybe just a tutorial on how to set them up?
 

Offline xamlit

  • Full Member
  • ***
  • Posts: 160
Ai Examples
« Reply #7 on: June 21, 2005, 06:13:48 PM »
Hmm... I found disasters to be one of the easiest things to do. Joe even wrote a simple but effective Random disaster code that works well. I would concentrate more on the AI side of things. Like Beginning AI stuff and how to use the triggers and where exactly they should go. Because I am confused greatly as to the placement of AI stuff if not in AIProc itself. Hope I am making my self clear enough.

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Ai Examples
« Reply #8 on: June 22, 2005, 10:03:15 AM »
Quote
Because I am confused greatly as to the placement of AI stuff if not in AIProc itself.
For starters, the best advise i can give you, is DON'T use AIProc for anything.

Triggers for disasters can be put in InitProc:
Code: [Select]
EXPORT void Quake()
{
   TethysGame::SetEarthquake(TethysGame::GetRand(128)+32,TethysGame::GetRand(128)-1,1);
}

EXPORT int InitProc()
{
// some init stuff here..
   CreateTimeTrigger(1,0,3000,7000,"Quake");

   return 1;
}
The above will create quakes every 30~70 time-marks.

The same can be done for other AI functions:
Code: [Select]
FightGroup grp1;

EXPORT void CreateTanks()
{
   Unit u;

   grp1=CreateFightGroup(Player[1]);
   grp1.SetRect(MAP_RECT(130,8,134,12));
   TethysGame::CreateUnit(u,mapLynx,LOCATION(158,2),1,mapLaser,SouthWest);
   grp1.TakeUnit(u);
   TethysGame::CreateUnit(u,mapLynx,LOCATION(158,4),1,mapLaser,SouthWest);
   grp1.TakeUnit(u);
}

EXPORT void Attack()
{
   grp1.AttackEnemy();
}

EXPORT int InitProc()
{
// some init stuff here..
   CreateTimeTrigger(1,1,2000,"CreateTanks");
   CreateTimeTrigger(1,1,4000,"Attack");

   return 1;
}
That code will create 2 lynx at time-mark 20 and send them on the MAP_RECT(130,8,134,12). Then at time-mark 40, they will start attacking enemies.
« Last Edit: July 03, 2005, 01:50:36 PM by Eddy-B »
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline BlackBox

  • Administrator
  • Hero Member
  • *****
  • Posts: 3093
Ai Examples
« Reply #9 on: June 22, 2005, 10:51:26 AM »
Yeah, very rarely if ever should you have to put stuff in AIProc. AIProc is called every game cycle so putting complex or slow code in it would slow down the game engine a lot.

About the only place where it might be useful is to check game variables that you couldn't check any other way (the code in AIProc is executed several times a second so it would be useful to constantly monitor something).

But yeah, there's nothing that "magical" or "special" about AI, it's just triggers that control what computer opponents do. To make a simple AI is one thing, to make an AI that can adapt and react to players is totally another, for the most part it's just logic and thinking how to break situations down.
« Last Edit: June 22, 2005, 10:53:02 AM by op2hacker »

Offline xamlit

  • Full Member
  • ***
  • Posts: 160
Ai Examples
« Reply #10 on: June 23, 2005, 05:55:51 PM »
So am I to assume that player [1] is the AI by default? And when you tell your lynx to attack enemies does it automatically attack the closest? How does that work?

xam

Offline Leviathan

  • Hero Member
  • *****
  • Posts: 4055
Ai Examples
« Reply #11 on: June 23, 2005, 06:10:21 PM »
Player[0] is the human player in a colony game..

Take a look here btw:
wiki.outpostuniverse.net/AI_Coding_Examples

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Ai Examples
« Reply #12 on: June 25, 2005, 02:42:28 AM »
DoAttackEnemy finds the closest target and goes for it. It only attacks "military" targets, so things like agri's and residence won't be destroyed
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline HaXtOr

  • Sr. Member
  • ****
  • Posts: 423
    • http://www.wtfmoogle.com
Ai Examples
« Reply #13 on: June 26, 2005, 01:16:09 PM »
I have posted tones of ai code

ai wall building

Bombed out building code
« Last Edit: June 26, 2005, 02:01:36 PM by HaXtOr »

Offline xamlit

  • Full Member
  • ***
  • Posts: 160
Ai Examples
« Reply #14 on: June 30, 2005, 11:12:00 AM »
Hmmm.. Two more questions..Can you create a MP AI?

And..


What in the world does this mean: grp1.SetRect(MAP_RECT(130,8,134,12));

Offline Leviathan

  • Hero Member
  • *****
  • Posts: 4055
Ai Examples
« Reply #15 on: June 30, 2005, 11:28:29 AM »
Yea you can make AI for a MP map.

Thos cords in the MAP_RECT are the corners of a area that you want your trucks to move. This includes when the bay is full, full storage etc. The smelter and mine needs to be in this area.

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Ai Examples
« Reply #16 on: June 30, 2005, 02:21:22 PM »
Quote
What in the world does this mean: grp1.SetRect(MAP_RECT(130,8,134,12));
It moves any vehicles (from grp1 group) to this area, if they have nothing to do.
In the above example i used it to set an initial point (RECT) where the AI-lynx would go to when they are first created. Since i just created them only, and given them NO commands yet, they will move there. Then when a command is given they will move out -and in the example above attack enemies-
When the command has been completed, like no more enemies left, they will again move back to this area.

The above is JUST an example. This RECT should be a safe-area where your AI will "store" its tanks if they are not in use. You absolutely HAVE TO set this area using SetRect, cause if you don't use it, your vehicles will move to the default area, which is the topleft of the map near tile (1,1)
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline xamlit

  • Full Member
  • ***
  • Posts: 160
Ai Examples
« Reply #17 on: July 11, 2005, 10:38:51 PM »
I don't suppose someone could provide some sample code of building groups?

http://wiki.outpostuniverse.net/AI_Coding

Like the first couple of paragraphs, it would be nice if some code was provided and the assumption was made that every1 is a newb.