Author Topic: AI - revisited  (Read 16212 times)

0 Members and 1 Guest are viewing this topic.

Offline ares

  • 23
Hi everyone!

This is my first post here, so bear with me a little. I am slasher from the game-warden forums.

I am a quite experienced c/c++ coder and I'm currently studying for a PhD in Robotics/AI in Germany. I got here via the Battlestar Galactica mod hosted on game-warden and I am very interested in doing things with the AI. Now, I have heard there are weird things going on when you edit parts of the AI code... there were some forum messages to that effect.

Anyway, I've been reading up on game-oriented AI (which is quite different from academic AI research) and FS2_open in general, which makes me have some questions to you guys.

1) Would it be useful to add Lua scripting hooks to the AI code to add new behaviors that way? I'm not so sure of the details here, but after a brief look at the wiki, that should be possible and maybe a bit more appropriate than another .tbl file?

2) To avoid the whole backwards compatibility discussion, could there be one big setting saying "use AI implementation X" with a default pointing to the current one? I've already gone through the code to identify the "interface", i.e. the ai_* functions called from outside the AI module, which has to stay the same. So, with this global setting, it should be fairly easy (famous last words) to reimplement the AI in some other way. Once I find my way around completely, modularization of the AI code would be my first priority.

3) Any questions/comments/requests/hints from your side are very much appreciated. I've only been reading into this for a couple of days, so I might be completely wrong with my assessment of the situation.

For now, I am still working on getting my development build from the HEAD to run, so it will be a little while until my contributions come in. However, game development (especially AI) has always fascinated me, so I am very motivated. Let me know what you think.

Bye!

 

Offline Tempest

  • 28
  • The Star Wars Conversion
    • The Fate of the Galaxy - SWC
I'd like a more dynamic AI system personally. The current AI is a bit plain and quite frankly doesn't fight like a human would. I'd like the game to automatically randomize AI flight characteristics at the beginning of the mission, which could be done in the modular fasion you described. I don't know what the SCP coders say, but I say go for it.

Also, I think the game already allows you to select a different AI version but I've only been able to select the retail version. Correct me if I'm wrong but a modified AI version was used but people didn't like it?

I'd like the AI to dogfight better instead of leading you in circles and also it needs to learn how to fly capships and bombers properly. I was actually thinking that it'd be nice to see an AI take control of a capship and figure out where it should position itself to to maximum damage. It would make capship fights MUCH better.

Again, I haven't touched the SCP code so I'm not sure what those guys will say.
"... and the klingons also were the soviet's space program. i mean can you really believe that a bunch of communist farmers can make rockets like that?"
-Axem

My photobucket: with all my shiny new stuff on it! http://s118.photobucket.com/albums/o116/Tempest_77/

 

Offline Bob-san

  • Wishes he was cool
  • 210
  • It's 5 minutes to midnight.
My turn!  :D

:welcome:

Welcome to Hard Light Productions! Here are the minor offenses, and their corresponding punishments! Never comined "F", "S", or "3" in a thread! This minor offense is usually combated by the use of our standardized Flame-throwers! But, due to budget problems and a few legal concerns (lawyers don't like clients charred to their bones), there is no longer napal in the flame thrower, but rather holy water! Another major offense is disturbing our little buddy (hey! That was my lunch!) called Carl, the resident Shivan who has taken a fancy to living in our walls! Throw him your lunch, and you should be fine... But if you happen to be caught in the wall with Carl, simply take the emergancy saw, and cut off a few limbs! Carl should stop persuit, but if he doesnt... you're on your own! If you wish to leave HLP, simply walk to the back of the ship, and operate the airlocks! The only problem with that choices is the airlocks no longer work! You may check-out any time you wish, but you many not leave HLP! If you should have any concerns, simply walk to the bridge and open up the weapons locker. Inside is your standard AK-47 and Plasma Rifle! However, most of us have a bit of a hard time getting in, as only moderators, the hyper-intelligent shade of blue, and :v: have keys in! If you are a bit weary of staying on HLP, simply blow through the airlock and try to make your way over to the Game-Warden sister-station. Be careful, though! We are out of space suits, and I hear space doesn't have much oxygen... or much of anything! Good luck and enjoy your stay!


I guess too many of us are afraid to use new tactics... most people's style in this game is very practiced; most of us have played the main campaign many times as well as many mods.

I'd be happy to get some new higher AI-class levels... perhaps a learning-style for higher AI classes? Make engaging them gain at a certain rate, and nonengaging a quarter as fast learning? So if a enemy watches you dogfight for two minutes, it the equivelant of thirty-seconds in combat with you?
NGTM-1R: Currently considering spending the rest of the day in bed cuddling.
GTSVA: With who...?
Nuke: chewbacca?
Bob-san: The Rancor.

 
Stronger AI has always been something I've been looking forward to. I have no clue what you are talking about in your first post, but whatever you can do to make the enemy fighters fight smarter would be a boon to FS2, IMHO.

    |[===---(-         
    ||
 =(||==)_
    ||_____|
 =(||==)
    ||                   
    |[===---(-                             

"Take my love. Take my land. Take me where I cannot stand. I don't care, I'm still free. You can't take the sky from me. Take me out to the black, tell them I ain't comin' back. Burn the land boil the sea, you can't take the sky from me. There's no place I can be since I've found Serenity. But you can't take the sky from me." - Ballad of Serenity

 

Offline Goober5000

  • HLP Loremaster
  • 214
    • Goober5000 Productions
:welcome:

Sounds great. :) Do you have any code samples you could show us?

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Ah. Welcome aboard slasher. I was wondering where you'd gotten to :)
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline Kaine

  • 27
some kind of scripting hook (i don't know lua, but i'm sure it would be useful to learn) into the AI would be fantastic, with a launcher option of enabling or disabling them. would also make debugging much easier with good code module management. I have a strong interest in game AI myself, and giving a scripting interface would make it a lot more accessable to people like me who don't have the skills to deal with the source code but want to contribute something.

GL and welcome to HLP!

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
The AI should NEVER be affected by a launcher flag.

Launcher flags should only really affect visuals, loading speed or be there for troubleshooting. They shouldn't ever be required for a mod or mission to work as designed. That's just ****ing stuipid cause it's so easy for someone to come along and just accidentally turn them off.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline Bob-san

  • Wishes he was cool
  • 210
  • It's 5 minutes to midnight.
Can you rename some of the difficulty classes? Perhaps instead of the basic Very Easy, Easy, Medium, Hard, and Insane, add a class above Insane like Lunatic... make it so the enemy will learn your tactics to kill you faster; only way to win is to change your tactics every few minutes?
NGTM-1R: Currently considering spending the rest of the day in bed cuddling.
GTSVA: With who...?
Nuke: chewbacca?
Bob-san: The Rancor.

 

Offline ares

  • 23
Thanks everyone for the interest!

What kind of code samples do you want?  ;7

I'm not sure to what extend learning is really possible in real-time with the whole game going on simultaneously. However, we often let AI play against itself to train it offline, so that might be an option. Also, we might just "limit" AI to planning (without learning), like they did in FEAR. There are some nice articles about that on http://www.jorkin.com/.

Actually, things might be a bit challenging because its a space sim.. almost 6 degrees of freedom (maybe 5, not quite sure how those things like strafing and stuff change this). I've read stuff about path planning with dynamic constraints, as in flight dynamics:  http://msl.cs.uiuc.edu/rrt/, mostly http://msl.cs.uiuc.edu/~lavalle/papers/LavKuf01b.pdf. So it should be possible, however, some optimizations might be necessary to make it perform in the game.

So, my idea for now is to kind of copy what they did for FEAR. We already have goals that get defined in FRED (correct me if I'm wrong) and might be added dynamically by the player when he/she commands allies. Then, it is "just" a matter of defining actions, with pre- and postconditions, maybe in Lua, which get chained by the planner for each AI controlled entity to achieve its goals. There might be wing (squad) actions as well to coordinate teams, I have to think about this a little longer. Learning could later be used to identify new actions or meta-actions (i.e. sequences of actions or maneuvers, like mentioned in previous threads).

Actually, is there a tutorial or something which I can follow to run the development build from MS visual studio? Or do I just have to build and run from the IDE?

BTW: great talk about managing software development: http://video.google.com/videoplay?docid=-5105910452864283694

Bye!

 

Offline IPAndrews

  • Disgruntled Customer
  • 212
  • This site stole my work
Some suggestions of things you might want to take into account:

If you're thinking of using lua for making AI decisions there's probably an overhead in doing that which might multiply up into quite a big overhead with hundreds of ships making hundreds of decisions very frequently.

Proper weapon firing accuracy? Volition's interpretation of accuracy is how fast the AI fires it's weapons. Presumably their thinking was "if you're a good shot you can shoot more often". Of course it's quite possible to think you're on target and not be, and fire.  :rolleyes:

Collision avoidance. You. Huge capital ships. It doesn't matter what it is or how fast it's moving. The AI will crash into it. This should also take into account the size of both ships (bounding boxes?). For instance we have a big ship called the Whitestar which flies like a fighter but doesn't realise it's actually 125m long. It makes for some rubbish flying.

You also have the AI table to take into account and how that affects decisions made by the AI. Thought it was worth mentioning even though it's obvious. Since it sounds like you're considering something akin to a complete rewrite. Which incidentally I don't think is a bad idea.

I help teach AI at a uni. So if you get bored feel free to ICQ me :).
Be warned: This site's admins stole 100s of hours of my work. They will do it to you.

 
My vote for least realistic part of FreeSpace that should be fixed first:
Quote
The AI will crash into it.

I swear it's like outer space bumper cars, COMPLETELY unrealistic. Who would take a chance of sucking vacuum by running into something in outer space?

PS. Does anyone know Dr. Jan Plath from Germany?

 

Offline Bob-san

  • Wishes he was cool
  • 210
  • It's 5 minutes to midnight.
Good luck. I'd like to see some of the code...
NGTM-1R: Currently considering spending the rest of the day in bed cuddling.
GTSVA: With who...?
Nuke: chewbacca?
Bob-san: The Rancor.

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Lua stuff is pretty easy, once you get the hang of it.

For implementing Lua hooks, see: SetHookVar, SetHookObject, RemHookVar, RunCondition(?) and IsConditionOverride. These handle setting hook variables (SetHookVar), or object handles (SetHookObject), and removing them after the hook has executed (RemHookVar).

RunCondition is a bit more complex. It takes one argument, an object pointer. This is used to evaluate the preceding 'conditional' fields in scripting. The "condition" variable is used for a CHA_ define from scripting.h, which determines which action this is. You will need to define an action; do a global search for one of the CHA_ defines and it should be pretty clear, you will probably want to familiarize yourself with the conditional scripting .tbl syntax. I made a general overview of it in my pre-commit build thread, in the Recent Builds forum.

IsConditionOverride is for determining whether the original code functionality will be preserved. There is an order note here - things should always be defined in the order
1) if(!IsConditionOverride)
2) do_regular_stuff();
3) else RunCondition();
This allows for the override condition to do any setup for the RunCondition function, as well as evaluate things in their pre- state to toggle the regular stuff. Having RunCondition() (or any other scripting hook) after the default behavior allows the modder to selectively override the parts of the behavior that they want, if they don't want to rewrite that entire chunk of code. They can also use the override hook to gather any data required for that.

For implementing new Lua functions and libraries, see: ade_lib, ade_obj, ADE_FUNC, ADE_VIRTVAR, and ADE_INDEXER. ade_lib defines a new library, or, if the parent field is specified, a sub-library. An example of this is the Ships array in the Mission library. ade_obj defines a new object type, it is a template that takes the data storage type for the object in question (For example, an image handle would be <int>). You may want to use your own helper structs to allow you to check if the passed handle or object is valid; I've tried to keep Lua as safe as possible, so that only critical errors will cause it to completely crash.

ADE_FUNC defines a basic function, and uses the ade_get_args and ade_set_args to parse and return arguments, respectively. I recommend you take a look at existing functions to get the hang of using these. You can also use it to define operators, there is an array at the top of lua.cpp that lists all the operators. Please do not specify __index or __newindex unless you know exactly what you are doing; teh ADE_INDEXER define will probably do what you want.

ADE_INDEXER is essentially identical to ADE_FUNC, and is generally used for array usage ([]). See existing examples. ADE_SETTING_VAR is true when the form is Object[key] = something, ie the array index is being set rather than read.

ADE_VIRTVAR defines a function that will appear as a variable from within Lua. It's much like ADE_INDEXER, in that it uses ADE_SETTING_VAR and the basic function _get and _set functions. Note that both ADE_VIRTVAR and ADE_INDEXER should always return the appropriate value, even when the variable is set to.

Conventions: All Lua libraries and objects are l_<NAME> in lua.cpp. All Lua functions use Java-style naming, so getThis() or setThat() or doThis(). All functions that return handles, should always return handles. If there's a chance of failure, it should return an invalid handle, so that the Lua interpreter doesn't explode when a boolean or nil value is indexed. In addition, handles should define an isValid() function that checks whether the handle is both valid, and if the object is still alive (if applicable). Basically, this is so that a modder has a fast easy way of checking whether they can safely do something with a handle. All Lua variables (and libraries) use the general C++-style naming conventions, Variable, OtherVariable, MyArray, and so on. And all shorthand library names are two lower-case letters, preferably close together on a QWERTY keyboard and that are relatively easy to remember. (Basically: use common sense. :p)

References: Nothing official and up-to-date, unfortunately. -output_scripting will output all declared Lua functions, libraries, objects, and so on. This is generated from the description fields of the macros/functions.

Disclaimer: All this is generally based on What Made The Most Sense To Me The Last Time I Worked On It. Some of it may be inconsistent, owing to the gradual year-plus development of everything. There's also quite a bit of stuff I haven't mentioned because I hope that it's pretty self-explanatory from the way it's used in the code, if you have questions, go ahead and ask, I'd just rather not spend a couple hours writing everything up for a forum post that will more than likely be forgotten & ignored once this thread drops off the first page. :-/ And I've tried to comment things decently, but there are some sections that can just be pretty damn confusing, even if you know exactly what's going on. I've tried to keep their sections in their own little world, that nobody needs to mess with, except to make serious lowlevel changes to the system. You shouldn't _ever_ need to change a function with more than 3 "lua_" functions grouped together, unless you're fixing a bug with the scripting system itself.
-C

 

Offline ares

  • 23
Great! Thank you all for your help and advice!

It would be nice to keep this thread alive for a while, cause as much as I have played space sims, I could use some out-of-the-box advice on maneuvers and so on. So, if you have any more ideas as to what the AI could do, let me know.

I'll be working on it hopefully this week. I have a little plan, which goes like this:

0. Get my own fs2_open build to run and play a simple test mission (is there one? otherwise I make one, cant be that hard to place me and one fighter in space)
1. further hide/modularize the AI code, so it can be easily replaced
2. implement better collision avoidance in a separate version of the current code (possible because of modularization)
3. fix accuracy issue, this is maybe possible with some sort of "distance" threshold when the AI thinks its on target, in degrees or so
4. add a way to script new AI behaviors (right now, depending on the goal an AI is pursuing, it executes behavior to reach it, like "dock" or "chase", if we keep the scripts lightweight, overhead should be small)
5. implement FEAR-like action planner to have more dynamic behavior (needs reactive component to avoid collisions, etc)

Choosing one AI implementation will be done as a configuration in one of the table files. 5. will be most work of course, but I hope that by that time, I'll have gotten to know the code enough so it would be easier than starting now. Also, smaller steps of improvements would maybe benefit you guys more as well and let me make baby-steps into the code.

I'll let you know when I'm done with 1.

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Sounds like a good plan. You'll have no trouble making the mission for step 0. Just follow the basic walkthrough in the FS2 help and it teaches you how to build a 1 on 1 between the player and a Mara. :)
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline ares

  • 23
Is it possible to be an observer, like in Unreal Tournament? I.e. just look at whats happening but not be a player in the game?

 

Offline Kaine

  • 27
you've made me want to install FEAR again damn you.

*goes to find his DVD*

 
Is it possible to be an observer, like in Unreal Tournament? I.e. just look at whats happening but not be a player in the game?

In FS2, yes, the default controls are / (on the numpad) to view from selected ship, and . (also on the numpad) to 3rd person view selected ship. When in third person, you use the joystick to move the camera, so you can't move your ship. Also, each of those commands can be used separately. If you use the third person view with nothing selected, you will view your fighter.

Unfortunately, no, you can't actually go "ethereal" as an observer, you can only witness stuff from the third person view of a ship. However, if you're viewing third person from a capship, your perspective is a little larger, so it's easier to see what's going on...

    |[===---(-         
    ||
 =(||==)_
    ||_____|
 =(||==)
    ||                   
    |[===---(-                             

"Take my love. Take my land. Take me where I cannot stand. I don't care, I'm still free. You can't take the sky from me. Take me out to the black, tell them I ain't comin' back. Burn the land boil the sea, you can't take the sky from me. There's no place I can be since I've found Serenity. But you can't take the sky from me." - Ballad of Serenity

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Is it possible to be an observer, like in Unreal Tournament? I.e. just look at whats happening but not be a player in the game?

Make two ships (on friendly, one hostile) and then make an event in the Events Editor that does a (protect-ship Alpha 1). The two AI ships will battle it out while ignoring you completely. You can then fly about where ever you like to see the combat or use Spartan's suggestion to view everything externally.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]