Create individual profiles for AI

Blitz3D Forums/Blitz3D Programming/Create individual profiles for AI

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

(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)