Yup
Below is a very quick edit of the "Teams Demo" that comes with Dark AI. You'll notice that the green team attacks you, the white team, and the red team. The red team attacks you,the white team, and the green team and etc.
remstart
*
* Teams
*
* -Creates 3 teams (friendly(green), enemy(red) and neutral(white))
* -Neutrals will run away from combat, friendlies will defend you, enemies will attack you
* -Sounds are enabled in this demo when an entity fires and will trigger nearby entities
*
* -Compiled with Version 6.1
*
remend
sync on : sync rate 0 : autocam off
set text font "Verdana" : set text size 14
rem creates the AI system and sets everything to default.
AI Start
rem sets the global radius, all entities will assumed to be this size
AI Set Radius 2.5
MakeBackground()
MakeLevel()
dim shootTimer(30) as float
Type AIType
id as integer
x as float
y as float
z as float
team as integer
isai as integer
Endtype
dim ai(100) as AIType
rem make a patrol path
AI Make Path 1
AI Path Add Point 1,40,40
AI Path Add Point 1,-40,40
rem entity template
make object cone 1,5
xrotate object 1,90
fix object pivot 1
make mesh from object 1,1
delete object 1
rem attack template
make object plain 1,0.3,1,1
xrotate object 1,90
fix object pivot 1
make mesh from object 2,1
delete object 1
rem single color images
MakeColorImage(11,1,rgb(255,0,0))
MakeColorImage(12,1,rgb(0,255,0))
rem make 3 enemies
inc aislot
for i = 2 to 4
make object i,1,0
position object i,i*5 - 30,2.5,40
texture object i,11
make object i+1000,2,11
set object light i+1000,0
hide object i+1000
ai(aislot).id=i
ai(aislot).x=i*5 - 30
ai(aislot).z=40
ai(aislot).team=3
ai(aislot).isai=1
rem add them to the enemy team and set their speed (in units per second)
AI Add Enemy i
AI Set Entity Speed i,10.0
AI Set Entity Aggressive i
AI Set Entity View Arc i,90,180
AI Set Entity View Range i,60
AI Set Entity Hearing Range i,100
inc aislot
next i
rem make 3 cilivians
for i = 11 to 13
make object i,1,0
position object i,rnd(50)-25,2.5,rnd(50)-25
ai(aislot).id=i
ai(aislot).x=object position x(i)
ai(aislot).z=object position z(i)
ai(aislot).team=2
ai(aislot).isai=1
rem add them to the enemy team and set their speed (in units per second)
AI Add Enemy i
AI Set Entity Speed i,10.0
AI Set Entity View Arc i,90,180
AI Set Entity View Range i,600
AI Set Entity Hearing Range i,100
inc aislot
next i
rem make 2 friendlies
for i = 21 to 22
make object i,1,0
position object i,i*5 - 120,2.5,-40
texture object i,12
make object i+1000,2,12
set object light i+1000,0
hide object i+1000
ai(aislot).id=i
ai(aislot).x=object position x(i)
ai(aislot).z=object position z(i)
ai(aislot).team=1
ai(aislot).isai=1
rem add them to the enemy team and set their speed (in units per second)
AI Add Enemy i
AI Set Entity Speed i,10.0
AI Set Entity View Arc i,90,180
AI Set Entity View Range i,600
AI Set Entity Hearing Range i,80
inc aislot
next i
rem make player
make object sphere 1,5
position object 1,20,2.5,-40
AI Add Player 1
position camera 0,100,-30 : point camera 0,0,-5
currtime# = timer()
lasttime# = currtime#
do
currtime# = timer()
speed# = 0.06*(currtime# - lasttime#)
lasttime# = currtime#
if upkey()=1 then move object 1,speed#
if downkey()=1 then move object 1,-speed#
if leftkey()=1 then move object left 1,speed#
if rightkey()=1 then move object right 1,speed#
rem handle debugging output
if keystate(2)=1 and ptimer<timer()
ptimer = timer()+300
pMode = 1-pMode
if ( pMode=0 ) then AI Debug Hide Paths else AI Debug Show Paths 2.5
endif
if keystate(3)=1 and btimer<timer()
btimer = timer()+300
bMode = 1-bMode
if ( bMode=0 ) then AI Debug Hide Obstacle Bounds 0 else AI Debug Show Obstacle Bounds 0,2.5
endif
if keystate(33)=1 and ftimer<timer()
ftimer = timer()+300
AI Team Follow Player 20
endif
if keystate(31)=1 and stimer<timer()
stimer = timer()+300
AI Team Separate
endif
rem handle F1 key
if ( keystate(59)=1 and f1Timer<timer() )
f1Timer = timer()+300
F1Pressed=1-F1Pressed
endif
if ( F1Pressed )
rem display info
set cursor 0,0
print "Enemies Are Red, Friendlies Are Green, Neutral Is White"
print
print "Controls: "
print "[ArrowKeys] Move Player"
print "[F] Make Friendlies Follow Player"
print "[S] Stop Friendlies Following Player"
print
print "Debug Controls: "
print "[1] Toggle Entity Path"
print "[2] Toggle Obstacle Bounds"
print
print "FPS: ";screen fps()
else
center text screen width()/2, 30, "-- Press F1 For Help --"
endif
rem hide attack lines
for i=1001 to 1025
if object exist(i) and shootTimer(i-1000)<70 then hide object i
next i
rem Call this command every sync to update entity AI state
AI Update
for i = 1 to aislot
if AI Entity Exist(ai(i).id)=1 and ai(i).isai=1
for e=1 to aislot
if ai(e).id<>ai(i).id and ai(i).team<>ai(e).team and ai(e).id>0 and ai(i).isai=1
x# = object position x(ai(e).id)
z# = object position z(ai(e).id)
if ai get entity can see(ai(e).id,x#,z#,1) then ai entity add target ai(i).id,ai(e).id
endif
next e
if AI Get Entity Can Fire(ai(i).id) and shootTimer(ai(i).id)<=0 and ai(i).team<>2
tx# = AI Get Entity Target X(ai(i).id)
tz# = AI Get Entity Target Z(ai(i).id)
x# = object position x(ai(i).id)
z# = object position z(ai(i).id)
dx# = ( x# + tx# ) / 2.0
dz# = ( z# + tz# ) / 2.0
dist# = sqrt ( (tx#-x#)*(tx#-x#) + (tz#-z#)*(tz#-z#) )
ang# = acos ( (tz#-z#) / dist# )
if ( (tx#-x#) < 0 ) then ang# = 360 - ang#
position object ai(i).id+1000,dx#,2.5,dz#
yrotate object ai(i).id+1000,ang#+0.1
scale object ai(i).id+1000,100,100,100*dist#
show object ai(i).id+1000
shootTimer(i)=100
AI Create Sound x#,z#,11,100
endif
endif
if shootTimer(i)>0 then shootTimer(i) = shootTimer(i)-(speed#*3)
next i
sync
loop
function MakeBackground()
load image "stripe5.png",1
load image "stripe6.png",2
rem create the background object
make object sphere 99,400,48,48
texture object 99,1
scale object texture 99,6,6
set object cull 99,0
set object light 99,0
rotate object 99,0,0,90
rem add the logo across the bottom
load image "logo.png", 100000
sprite 1, 0, screen height() - 60, 100000
endfunction
function MakeLevel()
rem make floor
make object box 100,100,1,100
position object 100,0,-0.5,0
texture object 100,2
i = 111
for x = -1 to 1
for z = -1 to 1
if ( x<>0 or z<>0 )
y# = rnd(5)+5
make object box i,12,y#,12
position object i,x*30,y#/2,z*30
color object i,rgb(rnd(180),rnd(180),rnd(180))
AI Add Static Obstacle i
inc i
endif
next y
next x
rem make boundary obstacle, encloses the space to keep the entity in
AI Start New Obstacle
rem add points in a anti-clockwise direction to create a boundary (use clockwise to create an obstacle)
AI Add Obstacle Vertex -50,-50
AI Add Obstacle Vertex 50,-50
AI Add Obstacle Vertex 50,50
AI Add Obstacle Vertex -50,50
rem finish creating our boundary
AI End New Obstacle 0,1
AI Complete Obstacles
endfunction
function MakeColorImage(image,mem,color)
make memblock mem,16
write memblock dword mem,0,1
write memblock dword mem,4,1
write memblock dword mem,8,32
write memblock dword mem,12,color
make image from memblock image,mem
delete memblock mem
endfunction