Rem Project: AI Tank
Rem Created: 3/17/2005 3:15:05 PM
Rem Created by Patrick Lewis
Rem ***** Main Source File *****
 
Sync On:Sync Rate 60:Autocam Off
Global MaxCodes
MaxCodes=55
 
Type Coordinates
   x as FLoat
   y as Float
   z as Float
Endtype
 
Type Menu
   ObjectNum as DWord
   MenuText as String
   Rotate As Float
   Pos as Coordinates
Endtype
MI=MaxCodes+20
Dim Menu(MI) as Menu
 
Type Commands
   Menu_ID as Integer
   Com_ID as Integer
   Com_Text as String
   Value as Integer
EndType
Dim Command_Menu(20) as Commands
Dim Code_List(MaxCodes) as Commands
Global MouseRate
Global m_Select as Integer
Global Select_Menu as Integer
Global Last_Menu as Integer
Global Code
Global IfCount
 
Type Players
   Com_Delay as Integer
   N as Integer
   A as Integer
   B as Integer
   Hull as Integer
   Armor as Integer
   Treads as Integer
   Turret as Integer
   Weapon as Integer
   Scanner as Integer
   Scanner_Angle as Coordinates
   Turret_Angle as Coordinates
   Shield as Integer
   Position as Coordinates
EndType
Dim Player(2) as Players
Dim Player_Code(2,MaxCodes) as Commands
 
Make_Field()
Make_Tank(10)
Make_Tank(11)
Position Object 10,15,2,15
PositioN Object 11,185,2,185
Position Camera 100,20,10
Restore R_Main_Menu
i=0
Do
   Read ID
   If ID=999 Then Exit
   Command_Menu(i).Com_ID=ID
   Read Command_Menu(i).Com_Text
   Read Flag
   Make_Menu_Box(100+i,Command_Menu(i).Com_Text,Command_Menu(i).Com_ID,45,45-(i*5),80)
   i=i+1
Loop
 
Select_Menu=0
Last_Menu=0
Code=0
Do
   Turn Object Left 10,1
   Turn Object Right 11,1
   Select Select_Menu
      Case 0:Main_Menu():EndCase
      Case 1,2,3,4,5,6:Sub_Menu():EndCase
      Case 7:System_Menu():EndCase
   EndSelect
   If m_Select=Code+19 and Code>0
      Code=Code-1
      If Code_List(Code).Com_Text="End If" Then IfCount=IfCount+1
      If Left$(Code_List(Code).Com_Text,2)="If" Then IfCount=IfCount-1
      Code_List(Code).Menu_ID=0
      Code_List(Code).Com_ID=0
      Code_List(Code).Value=0
      Code_List(Code).Com_Text=""
      Delete_Menu_Box(m_Select)
   Endif
   Turn Camera Left LeftKey()-RightKey()
   Move Camera Upkey()-DownKey()
   Sync
Loop
 
Function Main_Menu()
   Select_Menu=0
   If Last_Menu<>Select_Menu
      For i = 0 to 19
         Delete_Menu_Box(i)
      Next i
      Restore R_Main_Menu
      i=0
      Do
         Read ID
         If ID=999 Then Exit
         Command_Menu(i).Com_ID=ID
         Read Command_Menu(i).Com_Text
         Read Flag
         Make_Menu_Box(100+i,Command_Menu(i).Com_Text,Command_Menu(i).Com_ID,45,45-(i*5),80)
         i=i+1
      Loop
      Last_Menu=Select_Menu
   Endif
   m_Select=Menu_Wrangler()
   If M_Select>-1 and M_select<20 and Code<30
      Select_Menu=M_select+1
   Endif
EndFunction
 
Function Sub_Menu()
   If Last_Menu<>Select_Menu
      For i = 0 to 19
         Delete_Menu_Box(i)
      Next i
      Select Select_Menu
         Case 1:Restore R_Move_Menu:EndCase
         Case 2:Restore R_Scan_Menu:EndCase
         Case 3:Restore R_Weapon_Menu:EndCase
         Case 4:Restore R_Conditions_Menu:EndCase
         Case 5:Restore R_Var_Menu:EndCase
         Case 6:Restore R_Misc_Menu:EndCase
      EndSelect
      i=0
      Do
         Read ID
         If ID=999 Then Exit
         Command_Menu(i).Com_ID=ID
         Read Command_Menu(i).Com_Text
         Read Command_Menu(i).Value
         Make_Menu_Box(100+i,Command_Menu(i).Com_Text,Command_Menu(i).Com_ID,45,45-(i*5),80)
         i=i+1
      Loop
      Last_Menu=Select_Menu
   Endif
   m_Select=Menu_Wrangler()
   If m_Select<0 then ExitFunction
   If m_Select=0
      Select_Menu=0
      ExitFunction
   Else
      If Menu(M_Select).MenuText="End If" and IfCount=0 Then ExitFunction
      If M_select<20 and Code<=MaxCodes
         Code_List(Code).Menu_ID=Select_Menu
         Code_List(Code).Com_ID=M_Select
         offset=Int(Code/19)
         If Menu(M_Select).MenuText="End If" Then IfCount=IfCount-1
         horz=-50+(offset*30)+IfCount*3:vert=45+(Offset*19*5)-(code*5)
         If Command_Menu(M_Select).Value=1
            Make_Menu_Box(200+Code,"Enter Value:",20+Code,horz,vert,80)
            Do
               Set Cursor Object Screen X(200+Code)+45,Object Screen Y(200+Code)-10
               Input "",v$
               If Val(v$)<51 OR Select_Menu<>5 Or M_select<>5 Then Exit
            Loop
            Code_List(Code).Value=Val(v$)
            Code_List(Code).Com_Text=Menu(M_Select).MenuText+v$
         Else
            Code_List(Code).Value=0
            Code_List(Code).Com_Text=Menu(M_Select).MenuText
         Endif
         Make_Menu_Box(200+Code,Str$(Code+1)+": "+Code_List(Code).Com_Text,20+Code,horz,vert,80)
         Code=Code+1
         If Left$(Menu(M_Select).MenuText,2)="If" Then IfCount=IfCount+1
      Endif
   Endif
EndFunction
 
Function System_Menu()
   If Last_Menu<>Select_Menu
      For i = 0 to 19
         Delete_Menu_Box(i)
      Next i
      Restore R_Syst_Menu
      i=0
      Do
         Read ID
         If ID=999 Then Exit
         Command_Menu(i).Com_ID=ID
         Read Command_Menu(i).Com_Text
         Read Command_Menu(i).Value
         Make_Menu_Box(100+i,Command_Menu(i).Com_Text,Command_Menu(i).Com_ID,45,45-(i*5),80)
         i=i+1
      Loop
      Last_Menu=Select_Menu
   Endif
   m_Select=Menu_Wrangler()
   if m_Select<0 Then ExitFunction
   Select m_Select
      Case 0
         Select_Menu=0
         ExitFunction
      EndCase
      Case 1
         Set Cursor Screen Width()/2-20,100
         Input "Enter Save File Name:",fs$
         Save Array fs$,Code_List()
      EndCase
      Case 2
         Set Cursor Screen Width()/2-20,100
         Input "Enter Load File Name:",fs$
         If File Exist(fs$)
            For i = 20 to 21+MaxCodes
               Delete_Menu_Box(i)
            Next i
            Load Array fs$,Code_List()
            IfCount=0
            For i = 0 to MaxCodes
               If Code_List(i).Com_ID>0
                  If Code_List(i).Com_Text="End If" Then IfCount=IfCount-1
                  offset=Int(i/19)
                  horz=-50+(offset*30)+IfCount*3:vert=45+(Offset*19*5)-(i*5)
                  Make_Menu_Box(200+i,Str$(i+1)+": "+Code_List(i).Com_Text,20+i,horz,vert,80)
                  If Left$(Code_List(i).Com_Text,2)="If" Then IfCount=IfCount+1
                  Code=i
               Endif
            Next i
         Else
            Set Cursor Screen Width()/2-20,100
            Print "File Name does not exist."
            Wait Key
         Endif
      EndCase
      Case 3
         `Test()
      EndCase
      Case 4
      Rem Load 2nd player code
      Endcase
   Endselect
EndFunction
 
 
Function Make_Field()
   If Matrix Exist(1) Then Delete Matrix 1
   Make Matrix 1,200,200,20,20
   If Bitmap Exist(1) Then Delete Bitmap 1
   Create Bitmap 1,128,128
   Set Current Bitmap 1
   Ink RGB(0,128,0),0
   Box 0,0,127,127
   For i=1 to 200
      Dot rnd(127),rnd(127),Rgb(10,Rnd(255),10)
   Next i
   Get Image 999,0,0,127,127
   Prepare Matrix Texture 1,999,1,1
   Update Matrix 1
   Make Object Box 901,200,10,2
   Offset Limb 901,0,100,0,0
   Clone Object 902,901
   Clone Object 903,901
   Clone Object 904,901
   Turn Object Left 902,90
   Move Object 903,200
   Move Object Right 904,200
   Turn Object Left 904,90
   Make Object Sphere 601,7,8,8
   Make Object Cylinder 602,5
   Scale Object 602,30,100,30
   Make Mesh From Object 602,602
   Add Limb 601,1,602
   Delete Object 602
   Delete Mesh 602
   Offset Limb 601,1,0,2.5,0
   Offset Limb 601,0,0,7,0
   Texture Limb 601,0,999
   Color Limb 601,1,RGB(128,64,64)
   Make Object Sphere 602,8,8,8
   Color Object 602,RGB(109,103,78)
   For i = 1 to rnd(50)+rnd(50)+rnd(50)+rnd(50)
      cln=rnd(1)+1
      Clone Object 602+i,600+cln
      Position Object 602+i,rnd(180)+10,0,rnd(180)+10
   Next i
   Position Object 601,rnd(180)+10,0,rnd(180)+10
   Position Object 602,rnd(180)+10,0,rnd(180)+10
EndFunction
 
 
 
Function Make_Tank(ObjectID)
If Object Exist (ObjectID) Then Delete Object ObjectID
`Body
Make Object Box ObjectID,7,2.5,5
`Turret
If Object Exist(2) Then Delete Object 2
If Mesh Exist(2) Then Delete Mesh 2
Make Object Cylinder 2,5
Scale Object 2,100,40,100
Make Mesh From Object 2,2
Add Limb ObjectID,1,2
Offset Limb ObjectID,1,0,2,0
Delete Mesh 2
Delete Object 2
`Cannon
Make Object Cylinder 2,4
Scale Object 2,25,120,25
Offset Limb 2,0,0,2,0
Roll Object Right 2,90
Fix Object Pivot 2
Make Mesh From Object 2,2
Add Limb ObjectID,2,2
Offset Limb ObjectID,2,0,2,0
Color Limb ObjectID,2,RGB(128,128,128)
`Treads
Delete Mesh 2
Delete Object 2
Make Object Cylinder 2,10
Scale Object 2,100,20,20
Pitch Object Down 2,90
Fix Object Pivot 2
Make Mesh From Object 2,2
Add Limb ObjectID,3,2
Add Limb ObjectID,4,2
Offset Limb ObjectID,3,0,-1.5,-3
Offset Limb ObjectID,4,0,-1.5,3
`Tread Panels
Delete Object 2
Delete Mesh 2
Make Object Sphere 2,10
Scale Object 2,100,20,1
Make Mesh from Object 2,2
Add Limb ObjectID,5,2
Add Limb ObjectID,6,2
Offset Limb ObjectID,5,0,-1.5,-3.9
Offset Limb ObjectID,6,0,-1.5,3.9
Delete Object 2
Delete Mesh 2
`Scanner
Make Object Box 2,2,.4,1
Offset Limb 2,0,1,0,0
Make Mesh From Object 2,2
Add Limb ObjectID,7,2
Offset Limb ObjectID,7,0,3.2,0
Delete Object 2
Delete Mesh 2
 
`Lid
Make Object Sphere 2,5
Scale Object 2,100,.1,100
Make Mesh From Object 2,2
Add Limb ObjectID,8,2
Offset Limb ObjectID,8,0,2.9,0
Delete Object 2
Delete Mesh 2
 
`Object settings
Set Object Cull ObjectID,0
Turn Object Left ObjectID,90
Fix Object Pivot ObjectID
Color Object ObjectID,RGB(192,192,192)
`Treads image
If Bitmap Exist(1) Then Delete Bitmap 1
Create Bitmap 1,100,20
Set Current Bitmap 1
Ink RGB(210,210,210),0
Box 0,0,99,19
Ink Rgb(40,40,40),0
For i = 0 to 90 step 10
   Box i,0,i+1,19
Next i
Get Image 1,0,0,99,19
Delete Bitmap 1
Texture Limb ObjectID,3,1
Texture Limb ObjectID,4,1
Set Object Collision Off ObjectID
Set Object Collision to Boxes ObjectID
EndFunction
 
Function Make_Menu_Box(ObjectID,txt$,MenuID,x#,y#,z#)
If MenuID>Array Count(Menu()) Or MenuID<0 Then ExitFunction
If Object Exist(ObjectID) Then Delete Object ObjectID
If Image Exist(ObjectID) Then Delete Image ObjectID
If Menu(MenuID).ObjectNum>0
   If Object Exist(Menu(MenuID).ObjectNum) then Delete Object Menu(MenuID).ObjectNum
Endif
Make Object Box ObjectID,25,4,4
If Bitmap Exist(1) Then Delete Bitmap 1
w=Text Width(txt$)*1.2:h=Text Height(txt$)*2
Create Bitmap 1,w+1,h+1
Set Current Bitmap 1
Ink RGB(0,0,128),0
Box 0,0,w,h
Ink RGB(255,255,255),0
Center Text w/2,h*.33,txt$
Get Image ObjectID,0,0,w,h,1
Texture Object ObjectID,ObjectID
Set Current Bitmap 0
Delete Bitmap 1
Menu(MenuID).ObjectNum=ObjectID
Menu(MenuID).MenuText=txt$
Menu(MenuID).Pos.x=x#
Menu(MenuID).Pos.y=y#
Menu(MenuID).Pos.z=z#
Position Object ObjectID,Camera Position X(),Camera Position Y(),Camera Position Z()
Set Object To Camera Orientation ObjectID
Move Object ObjectID,z#
Move Object Right ObjectID,x#
Move Object Up ObjectID,y#
`Lock Object On ObjectID
Set Object Collision Off ObjectID
Set Object Collision To Boxes ObjectID
Endfunction
 
Function Menu_Wrangler()
Menu_Item=-1
For i = 0 to Array Count(Menu())
   ObjectID=Menu(i).ObjectNum
   If ObjectID>0
      Position Object ObjectID,Camera Position X(),Camera Position Y(),Camera Position Z()
      Set Object To Camera Orientation ObjectID
      Move Object ObjectID,Menu(i).Pos.z
      Move Object Right ObjectID,Menu(i).Pos.x
      Move Object Up ObjectID,Menu(i).Pos.y
      If Pick Object(MouseX(),MouseY(),ObjectID,ObjectID)=ObjectID
         Menu(i).Rotate=Menu(i).Rotate+1
         Menu_Item=i
      Else
         Menu(i).Rotate=0
      Endif
      If Menu(i).Rotate>89 Then Menu(i).Rotate=0
      Pitch Object Down ObjectID,Menu(i).Rotate
   Endif
Next i
If MouseClick()=1 And MouseRate=0
   MouseRate=1
Else
   If MouseClick()=0 Then MouseRate=0
   Menu_Item=-1
Endif
EndFunction Menu_Item
 
Function Delete_Menu_Box(MenuID)
ObjectID=Menu(MenuID).ObjectNum
If ObjectID>0
   If Object Exist(ObjectID)
      Delete Object ObjectID
      Delete Image ObjectID
   Endif
Endif
Menu(MenuID).ObjectNum=0
Menu(MenuID).MenuText=""
Menu(MenuID).Rotate=0
EndFunction
 
R_Main_Menu:
Data 0,"Movement Menu",0
Data 1,"Scanner Menu",0
Data 2,"Weapon Menu",0
Data 3,"Conditions Menu",0
Data 4,"Variables Menu",0
Data 5,"Misc. Menu",0
Data 6,"System Menu",0
Data 999,"999",999
 
R_Move_Menu:
Data 0,"Main Menu",0
Data 1,"Move Forward 1",0
Data 2,"Move Back 1",0
Data 3,"Set N=Tank_X",0
Data 4,"Set N=Tank_Y",0
Data 5,"Turn Tank Right 45",0
Data 6,"Turn Tank Left 45",0
Data 7,"Set N=Tank_Angle",0
Data 8,"Check Treads",0
Data 9,"Repair Treads",0
Data 999,"999",999
 
R_Scan_Menu:
Data 0,"Main Menu",0
Data 1,"Scan For Obstical",0
Data 2,"Set N=Object_Range",0
Data 3,"Set N=Object_X",0
Data 4,"Set N=Object_Y",0
Data 5,"Scan For Enemy",0
Data 6,"Set N=Enemy_Range",0
Data 7,"Set N=Enemy_X",0
Data 8,"Set N=Enemy_Y",0
Data 9,"Set N=Enemy_Angle",0
Data 10,"Turn Scanner Right 45",0
Data 11,"Turn Scanner Left 45",0
Data 12,"Set N=Scanner_Angle",0
Data 13,"Check Scanner",0
Data 14,"Repair Scanner",0
Data 999,"999",999
 
R_Weapon_Menu:
Data 0,"Main Menu",0
Data 1,"Fire Weapon",0
Data 2,"Turn Turret Right 45",0
Data 3,"Turn Turret Left 45",0
Data 4,"Set N=Turret_Angle",0
Data 6,"Check Weapon",0
Data 7,"Repair Weapon",0
Data 8,"Check Turret",0
Data 9,"Repair Turret",0
Data 999,"999",999
 
R_Conditions_Menu:
Data 0,"Main Menu",0
Data 1,"If N < ",1
Data 2,"If N > ",1
Data 3,"If N = ",1
Data 4,"If N <> ",1
Data 5,"If N < A",0
Data 6,"If N > A",0
Data 7,"If N = A",0
Data 8,"If N <> A",0
Data 9,"If N < B",0
Data 10,"If N > B",0
Data 11,"If N = B",0
Data 12,"If N <> B",0
Data 13,"End If",0
Data 999,"999",999
 
R_Var_Menu:
Data 0,"Main Menu",0
Data 1,"Set A = N",0
Data 2,"Set A = B",0
Data 3,"Set B = A",0
Data 4,"Set B = N",0
Data 5,"Set N = A",0
Data 6,"Set N = B",0
Data 7,"Set N=Random(A)",0
Data 8,"Set A = ",1
Data 9,"Set B = ",1
Data 10,"Set N = ",1
Data 11,"Set N = N + ",1
Data 12,"Set N = N - ",1
Data 13,"Set N = N + A",0
Data 14,"Set N = N - A",0
Data 15,"Set N = Damage",0
Data 999,"999",999
 
 
R_Misc_Menu:
Data 0,"Main Menu",0
Data 1,"Goto ",1
Data 2,"Wait ",1
Data 3,"Repeat ",1
Data 4,"Loop   ",0
Data 5,"Check Hit",0
Data 6,"Set N = Tank_Hit",0
Data 7,"Check Armor",0
Data 8,"Repair Armor",0
Data 9,"Check Hull",0
Data 10,"Repair Hull",0
Data 11,"Raise Shield",0
Data 12,"Lower Shield",0
Data 13,"Set N = Shield Energy",0
Data 999,"999",999
 
R_Syst_Menu:
Data 0,"Main Menu",0
Data 1,"Save Code",1
Data 2,"Load Code",1
Data 3,"Test Code",0
Data 4,"Play Code",0
Data 999,"999",999