So you want to be a programmer, eh? You want to write artificial intelligence just like the big boys, right? No problem! You too can code AI like the game companies do. Step right this way!
First off, let's take a short look at the AI of the two hottest 3D games, Quake 2 and Unreal. Both titles promised advanced monster smarts like evasion, higher awareness, and random roaming. But, um, well, um, let's just say most of it is, well, hard to spot.
However, we will learn all three of those features today! And tomorrow we will be working at highly successful software firms, right? Then we will be paid embarassingly high sums of money, right?
// look for other coop players
enemy_infront = infront(self.enemy);
if (coop && self.search_time < time)
{
if (FindTarget ())
return;
}
enemy_range = range(self.enemy);
enemy_yaw = vectoyaw(self.enemy.origin - self.origin);
if (time < self.enemy.attack_finished)
{
ai_run_slide();
return;
}
Ironically, the subroutine ai_run_slide() is already in QuakeC but is not used much. Go figure. It makes a monster slide from one side to another.
I could talk a whole lot more, but it's as simple as that. That's how to add attack evasion.
if (self.health < 25)
{
ai_back();
return;
}
Well, we can make it more complicated. We can make him angry when he's wounded. Replace the above code with this stuff:
if (self.health < 25)
{
ai_back();
self.th_missile();
return;
}
So now he should back up and attack as well. Whoa, neat. I hope the game companies are ready this.
/* ============= ai_walk The monster is walking it's beat ============= */ void(float dist) ai_walk = { local vector mtemp; movedist = dist;As you can see, there's not much too it. In fact, the only lines here that do anything are FindTarget() and movetogoal(). The rest is just excess fat.if (self.classname == "monster_dragon") { movetogoal (dist); return; } // check for noticing a player if (FindTarget ()) return; movetogoal (dist); };
Well, now you've learned how to create monster intelligence smarter than 90 percent of the 3D games out there. Of course there is alot more to it. But now you know enough to get one of those cushy game programmer jobs and make a million dollars.
For the next lesson, we'll learn things that will make us a billion dollars.