Create individual profiles for AI

Blitz3D Forums/Blitz3D Programming/Create individual profiles for AI

Chad(Posted 2006) [#1]
I consider this more of an "advanced" type question, thus why it's not in B3D beginners area..

How can you create individual profiles for the AI of your game as follows.

In seperate text documents, you lay out everything you want and describe it..

This is just an idea I have for my game, but it would be really nice if possible, here's an example:
;--Fletcher Class Destroyer
fletcherdd=LoadMesh("fletcherdd.b3d")
topspeed=30        ;number of units passed a second
rotatespeed=48   ;seconds for a complete 360 circle
maxdistance=500000     ;set as units passed
ROE=Evade,Attack,DepthCharge,Patrol,Escort
;before march 1942
if < 03011942 then
Passivesonar=True
ActiveSonar=True
SonarRange=300    ;units
depthcharges=26
if > 03021942 then
PassiveSonar=True
ActiveSonar=True
SonarRange=400
depthcharges=38

And then in a seperate text I create a profile for each one of those telling what they do..
;PassiveSonar
passivesonar=AIlistener
sweep=270   ;arc of listening
If < 03011942 then
range=300

on and on and on..

If you get what I'm saying, please help me understand how to actually do this stuff.

Thanks,
Chad


jfk EO-11110(Posted 2006) [#2]
there are several ways to implement something like this, but in the end of the day it all depends on the conventions and standards you set.

One way is to use an identifier name and then a seperator followed by a value:
sweep=270

your properties loader will then parse each line. first it has to search for the seperator, that is the "=". Something like

lin$=upper$(readline(re))
where=instr(lin$,"=")
if where>0
 prop_name$=left$(lin$,where-1)
 prop_value=right$(lin$,len(lin$)-where)
endif


Now you need to search for a property that is named "SWEEP"

you can do that with miles of SELECT CASE comparing, or, if you have all your possible property names stored in a string array then you can check it with a for loop quickly:

if where>0
 num_names=123 ; or whatever
 what=-1
 for i=0 to num_names
  if prop_name$=prop_names_arr$(i)
   what=i
   exit
  endif
 next
endif


Now a thing like
If < 03011942 then
range=300

is not tored in the properties file, but must be determined
A) in the App that saves the properties, or
B) in the App or Game that loads the properties.

In case A the App will store 300 or an other number, depending on the date. In case of B the date was stored and the loader will set a variable RANGE to 300 when it's older than 03011942. BTW I strongly suggest to swap the date to year,month,day, this way you can compare this as a simple INT number and calculate what's older easily.
So the line in the props file would be (example given):

date=19421102

and the Loader will den compare this with 19421103:

if prop_value<19421103
 PassiveSonar=false
 ActiveSonar=false
 range= 300
else
 PassiveSonar=True
 ActiveSonar=True
 range = 5000
endif



Chad(Posted 2006) [#3]
Wow, I'll need to read that a couple times before I'll understand it..

Thanks for the examples, if there's anything else that I could look at to get the hang of it could you throw it at me too?

Thanks again jfk


Chad(Posted 2006) [#4]
lin$=upper$(readline(propfile$))
where=instr(lin$,"=")
if where>0
 prop_name$=left$(lin$,where-1)
 prop_value=right$(lin$,len(lin$)-where)
endif


with this how can I actually make this for a sonar? this is just a bunch of jumbled stuff for me, and I want to understand it but I think I just need a little more directions in this.


jfk EO-11110(Posted 2006) [#5]
(first: sorry there was a little typo, it should be:
lin$=upper$(readline(re))
)
yeah, well you need some application to save the properties to files. I take it you want 1 file for for each ship, submarine, or whatever it is.

If you gonna use a tool that lets you enter the properties in a form, or if you simply write it with notepad, that's up to you. But basicly you will need a file that contains several lines, eg:

build_date=19470512
maxspeed=50
maxfright=5000

etc...

Some people would use types to manage the following, I don't, so my description may differ from other peoples suggestions:

In your game you will have an array, like this:
num=2
dim prop_name_arr$(num)
prop_name_arr$(0)="BUILD_DATE"
prop_name_arr$(1)="MAXSPEED"
prop_name_arr$(2)="MAXFRIGHT"

In this array you put whatever needs to be stored, the variable "num" is the number of names in the array and needs to be set correctly, of course.

Now you can use a floating point array to store the values from the props files, eg:

max_ships=100: max of 100 ships
dim ship_props#(max_ships,num)



then you read every line of each one of your properties files. Let us assume your files are named prop_0.shp to prop_9.shp for ten ships.

for ship=0 to 9
 re=readfile("prop_"+ship+".shp")
 while eof(re)=0
  lin$=upper$(readline(re))
  where=instr(lin$,"=")
  if where>0
   prop_name$=left$(lin$,where-1)
   prop_value#=right$(lin$,len(lin$)-where)
   what=-1
   for i=0 to num
    if prop_name$=prop_name_arr$(i)
     what=i
     exit
    endif
   next
   if what>-1 ; found name
    ship_props#(ship,what)=prop_value#
   endif
  endif
 wend
 closefile re
next


Of course, using staticly dimmed arrays will waste some bytes, the sooner or later you should start to dynamicly dim arrays, or use types or banks instead (I mean, reserve only the amount of memory you really need: instead of using "max_ships=100" you could first count the number of prop files in a given folder and then dim the arrays with that number)


WolRon(Posted 2006) [#6]
http://www.blitzbasic.com/Community/posts.php?topic=27896


Chad(Posted 2006) [#7]
Thanks for your help guys, I'll try it out and see what I can come up with.