home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / jpi / entities.bas < prev    next >
Encoding:
BASIC Source File  |  1998-01-29  |  75.6 KB  |  1,838 lines

  1. Attribute VB_Name = "Entities"
  2. Private Type PointList
  3.   PathPoints(200) As Point2D
  4.   PathPointsActive As Integer
  5. End Type
  6. Private Type PathNode
  7.   Points As PointList
  8.   Stuck As Boolean
  9. End Type
  10. Private Type PathObj
  11.   Points As PointList
  12. End Type
  13.  
  14.  
  15. Global Const DISTANCEBEFOREOUTOFWAY = 30
  16. Global Const DELAYWEAPON = -1
  17. Global Const NOOBJECT = 0
  18. Global Const OBJCONST_ObjectStopDistance = 6
  19. Global Const OBJCONST_MissileStopDistance = 8
  20. Global Const OBJCONST_TimeTillAdjustDirection = 3
  21.  
  22. Global Const NOMAPIMPRINT = 0
  23.  
  24. Global Const IMPRINTSIZE = 10
  25. Global Const HALFIMPRINTSIZE = IMPRINTSIZE / 2
  26. Private Type MapTemplate
  27.   ImprintName As String
  28.   ImprintArray(IMPRINTSIZE, IMPRINTSIZE) As Boolean
  29. End Type
  30. Global Const MAXIMPRINTS = 80
  31. Public MapImprints(MAXIMPRINTS) As MapTemplate
  32.  
  33. 'Ability List
  34. Global Const MAXABILITIES = 55
  35. Global Const ABILITY_MOVES = 1
  36. Global Const ABILITY_FLIES = 2
  37. Global Const ABILITY_CANLANDONGROUND = 3 'For helicopters and such.  Everything can land on a landing pad.
  38. Global Const ABILITY_SHOOTS = 4
  39. Global Const ABILITY_HARVESTS = 5
  40. Global Const ABILITY_CARRIESPEOPLE = 6
  41. Global Const ABILITY_PANICS = 7
  42. Global Const ABILITY_REPAIRABLE = 8
  43. Global Const ABILITY_SELFHEALING = 9
  44. Global Const ABILITY_CRAWLS = 10
  45. Global Const ABILITY_RETREATS = 11
  46. Global Const ABILITY_GETSPOWERUPS = 12
  47. Global Const ABILITY_RELIESONELECTRICITY = 13
  48. Global Const ABILITY_REACHESTARGETINSTANTLY = 14
  49. Global Const ABILITY_UNLIMITEDAMMO = 15
  50. Global Const ABILITY_FIRESDOUBLE = 16
  51. Global Const ABILITY_LEAVESSPARKLETRAIL = 17
  52. Global Const ABILITY_BLEEDSWHENHIT = 18
  53. Global Const ABILITY_THROWSMETALWHENHIT = 19
  54. Global Const ABILITY_THROWSBLOODATDEATH = 20
  55. Global Const ABILITY_THROWSMETALATDEATH = 21
  56. Global Const ABILITY_PROCESSESMATERIALS = 22
  57. Global Const ABILITY_REPAIRSVEHICLES = 23
  58. Global Const ABILITY_REPAIRSPEOPLE = 24
  59. Global Const ABILITY_AIRCRAFTPAD = 25 'for landing aircraft
  60. Global Const ABILITY_NAVALDOCK = 26 'for boats
  61. Global Const ABILITY_RESSURECTS = 27
  62. Global Const ABILITY_LEAVESWRECKAGE = 28
  63. Global Const ABILITY_SELECTABLE = 29
  64. Global Const ABILITY_FOLLOWSTARGET = 30
  65. Global Const ABILITY_RELIESONSTRENGTH = 31
  66. Global Const ABILITY_CANBECOMEINVISIBLE = 32
  67. Global Const ABILITY_ENTERSBUILDINGS = 33
  68. Global Const ABILITY_ISPHYSICAL = 34
  69. Global Const ABILITY_GETTABLE = 35
  70. Global Const ABILITY_HITTABLE = 36
  71. Global Const ABILITY_INFECTABLE = 37
  72. Global Const ABILITY_AFFECTEDBYDISEASE = 38
  73. Global Const ABILITY_COMBUSTUBLE = 39
  74. Global Const ABILITY_EXPLODESWITHFIRE = 40
  75. Global Const ABILITY_DEPLOYS = 41
  76. Global Const ABILITY_BUILDS = 42
  77. Global Const ABILITY_BUILDABLE = 43
  78. Global Const ABILITY_CANBEDAMAGED = 44
  79. Global Const ABILITY_BODYISBISECTED = 45
  80. Global Const ABILITY_THROWSSPARKLESATCOLLIDE = 46
  81. Global Const ABILITY_FRAMES_SHOOTING = 47
  82. Global Const ABILITY_SPLASHESWATER = 48
  83. Global Const ABILITY_HASDNA = 49
  84. Global Const ABILITY_EMOTIONS = 50
  85. Global Const ABILITY_LEADER = 51
  86. Global Const ABILITY_SHOOTSLIGHTNINGONBUILD = 52
  87. Global Const ABILITY_REQUIRESTRACTION = 53
  88. Global Const ABILITY_USESINERTIA = 54
  89. Global Const ABILITY_HASSHADOW = 55
  90.  
  91. 'Attribute List
  92. Global Const MAXMODELATTRIBUTES = 52
  93. Global Const ATTRIBUTE_SPRITE = 1
  94. Global Const ATTRIBUTE_SIZE = 2
  95. Global Const ATTRIBUTE_LENGTHX = 3
  96. Global Const ATTRIBUTE_LENGTHY = 4
  97. Global Const ATTRIBUTE_LENGTHZ = 5  'Higher up, more Z
  98. Global Const ATTRIBUTE_MAXSPEED = 6
  99. Global Const ATTRIBUTE_BULLETARMOR = 7
  100. Global Const ATTRIBUTE_SHELLARMOR = 8
  101. Global Const ATTRIBUTE_BOMBARMOR = 9
  102. Global Const ATTRIBUTE_FIREARMOR = 10
  103. Global Const ATTRIBUTE_ELECTROMAGNETICARMOR = 11
  104. Global Const ATTRIBUTE_RADIATIONARMOR = 12
  105. Global Const ATTRIBUTE_MAXAMMO = 13 'only effective if UnlimitedAmmo is False
  106. Global Const ATTRIBUTE_EXPLOSIONTYPE = 14
  107. Global Const ATTRIBUTE_EXPLOSIONINTENSITY = 15
  108. Global Const ATTRIBUTE_EXPLOSIONRADIUS = 16 'Determines also how many sparks will fly
  109. Global Const ATTRIBUTE_EXPLOSIONSPRITE = 17 'In the game, the Sprite Groups will be variations of the same Explosion type :)
  110. Global Const ATTRIBUTE_POWERREQUIRED = 18
  111. Global Const ATTRIBUTE_OBJECTBUILDTYPE = 19
  112. Global Const ATTRIBUTE_COST = 20
  113. Global Const ATTRIBUTE_HEALTH = 21
  114. Global Const ATTRIBUTE_WEIGHT = 22
  115. Global Const ATTRIBUTE_ACCURACY = 23
  116. Global Const ATTRIBUTE_STRENGTH = 24
  117. Global Const ATTRIBUTE_SHOOTRADIUS = 25
  118. Global Const ATTRIBUTE_MINIMUMSHOOTRADIUS = 26
  119. Global Const ATTRIBUTE_DIRECTIONAMOUNT = 27
  120. Global Const ATTRIBUTE_SIGHTRADIUS = 28
  121. Global Const ATTRIBUTE_SOUNDGROUP = 29
  122. Global Const ATTRIBUTE_SIDE = 30
  123. Global Const ATTRIBUTE_GETTABLEPOWERUPTYPE = 31
  124. Global Const ATTRIBUTE_MAPIMPRINT = 32
  125. Global Const ATTRIBUTE_SPRITEPOSITIONX = 33
  126. Global Const ATTRIBUTE_SPRITEPOSITIONY = 34
  127. Global Const ATTRIBUTE_COMBUSTIONTEMPERATURE = 35
  128. Global Const ATTRIBUTE_DEPLOYOBJECT = 36
  129. Global Const ATTRIBUTE_TECHLEVEL = 37
  130. Global Const ATTRIBUTE_BUILDPICTURE = 38
  131. Global Const ATTRIBUTE_TOPSPRITE = 39
  132. Global Const ATTRIBUTE_TOPDIRECTIONAMOUNT = 40
  133. Global Const ATTRIBUTE_TOPSPRITEPOSITIONX = 41
  134. Global Const ATTRIBUTE_TOPSPRITEPOSITIONY = 42
  135. Global Const ATTRIBUTE_BUILDATFRAME = 43
  136. Global Const ATTRIBUTE_REQUIREDBEFOREBUILD = 44
  137. Global Const ATTRIBUTE_IMPORTANCE = 45
  138. Global Const ATTRIBUTE_ENGINEPOWER = 46
  139. Global Const ATTRIBUTE_TURNSPEED = 47
  140. Global Const ATTRIBUTE_SHADOWPIC = 48
  141. Global Const ATTRIBUTE_WEAPONX = 49
  142. Global Const ATTRIBUTE_WEAPONY = 50
  143. Global Const ATTRIBUTE_DEFAULTWEAPONOBJECT = 51
  144. Global Const ATTRIBUTE_WEAPONCHARGETIME = 52
  145.  
  146. 'The Behavior types
  147. Global Const MAXBEHAVIORMODES = 7
  148. Global Const BEHAVIORMODE_NONE = -1
  149. Global Const BEHAVIORMODE_INANIMATE = 0
  150. Global Const BEHAVIORMODE_BUILDING = 1
  151. Global Const BEHAVIORMODE_SOLDIER = 2
  152. Global Const BEHAVIORMODE_SHIP = 3
  153. Global Const BEHAVIORMODE_TANK = 4
  154. Global Const BEHAVIORMODE_AIRCRAFT = 5
  155. Global Const BEHAVIORMODE_SPACECRAFT = 6
  156. Global Const BEHAVIORMODE_WEAPON = 7
  157.  
  158. 'Explosion Behavior
  159. Global Const EXPLODETYPE_BULLET = 1
  160. Global Const EXPLODETYPE_SHELL = 2
  161. Global Const EXPLODETYPE_BOMB = 3
  162. Global Const EXPLODETYPE_FIRE = 4
  163. Global Const EXPLODETYPE_ELECTROMAGNETIC = 5
  164. Global Const EXPLODETYPE_RADIATION = 6
  165.  
  166. Global Const MAXCONSTS = 4
  167. Global Const CONST_DIRECTIONDIV = 1
  168. Global Const CONST_DIRECTIONDIVDIV = 2
  169. Global Const CONST_TOPDIRECTIONDIV = 3
  170. Global Const CONST_TOPDIRECTIONDIVDIV = 4
  171.  
  172. Type Objzmods
  173.   Consts(MAXCONSTS) As Single
  174.   BehaviorType As Integer
  175.   ObjClassName As String
  176.   ObjName As String
  177.   Abilities(MAXABILITIES) As Boolean
  178.   Attributes(MAXMODELATTRIBUTES) As Integer
  179.   MapImprintNumber As Integer
  180.   SoundGroup As SoundObj
  181. End Type
  182.  
  183. Global Const MaxObjModels = 100 'for the following line
  184. Global ObjModels(MaxObjModels) As Objzmods
  185. Global MaxObjModTypes As Integer 'For the program
  186. Global Const NOTARGET = -1 'For the PROPERTY_TARGET
  187. Global Const TARGETGROUND = -2 'For the PROPERTY_TARGET
  188.  
  189. 'Object Attributes
  190. Global Const MAXOBJECTPROPERTIES = 17
  191. Global Const PROPERTY_PEOPLECONTAINED = 1
  192. Global Const PROPERTY_GEMSCONTAINED = 2
  193. Global Const PROPERTY_HEALTH = 3
  194. Global Const PROPERTY_TIMEUNTILADJUSTDIRECTION = 4
  195. Global Const PROPERTY_OBJECTTOPATROL = 5
  196. Global Const PROPERTY_HOMEOBJECT = 6
  197. Global Const PROPERTY_WEAPONCHARGE = 7
  198. Global Const PROPERTY_CRAWLING = 8 'true false
  199. Global Const PROPERTY_BUILDOBJECTTYPE = 9
  200. Global Const PROPERTY_BUILDPROGRESS = 10
  201. Global Const PROPERTY_FUEL = 11
  202. Global Const PROPERTY_LASTCOMMAND = 12
  203. Global Const PROPERTY_CLASSTOBUILD = 13
  204. Global Const PROPERTY_TIMEREMAININGONSITSTILL = 14
  205. Global Const PROPERTY_POSITIONTEMPX = 15
  206. Global Const PROPERTY_POSITIONTEMPY = 16
  207. Global Const PROPERTY_WEAPONOBJECTTYPE = 17
  208.  
  209. 'Goals
  210. Global Const GOAL_NOTHING = 1
  211. Global Const GOAL_MOVESOMEWHERE = 2
  212. Global Const GOAL_STANDGROUND = 3
  213. Global Const GOAL_ATTACK = 4
  214. Global Const GOAL_GUARD = 5
  215. Global Const GOAL_PATROL = 6
  216. Global Const GOAL_HARVESTGEMS = 7
  217. Global Const GOAL_INVADE = 8
  218. Global Const GOAL_RETURNTOHOME = 9
  219. Global Const GOAL_SCOUT = 10
  220. Global Const GOAL_CAMP = 11
  221. Global Const GOAL_BUILD = 12
  222. Global Const GOAL_GETOUTOFTHEWAY = 13
  223. Global Const GOAL_GETFARTHERAWAYFROMTARGET = 14
  224. Global Const GOAL_SITSTILL = 15
  225. Global Const GOAL_FOLLOWPATH = 16
  226.  
  227. Global Const MAXSTATES = 9
  228. 'States
  229. Global Const STATE_MOVING = 2
  230. Global Const STATE_FIRING = 3
  231. Global Const STATE_CAMPING = 4
  232. Global Const STATE_REPAIRING = 5
  233. Global Const STATE_BUILDING = 6
  234. Global Const STATE_TAKINGOFF = 7
  235. Global Const STATE_LANDING = 8
  236. Global Const STATE_MOVINGANDFIRING = 9
  237.  
  238. Global Const MAXGENETICS = 3
  239. Global Const GENETIC_SPEED = 1
  240. Global Const GENETIC_RESILIENCE = 2
  241. Global Const GENETIC_INTELLIGENCE = 3
  242.  
  243. Global Const GeneticRange = 10
  244. Global Const HalfGeneticRange = GeneticRange / 2
  245.  
  246. Public Type DNAType
  247.   Genetics(MAXGENETICS) As Integer
  248. End Type
  249.  
  250. Global Const MAXEMOTIONS = 4
  251. Global Const EMOTION_HAPPY = 1
  252. Global Const EMOTION_SAD = 2
  253. Global Const EMOTION_SCARED = 3
  254. Global Const EMOTION_HATE = 4
  255.  
  256. Private Type EmotionType
  257.   EmotionsOn As Boolean
  258.   Emotions(MAXEMOTIONS) As Integer
  259. End Type
  260.  
  261. Private Type BrainType
  262.   Emotions As EmotionType
  263. End Type
  264.  
  265. Type UnitObjective
  266.   Goal As Integer
  267.   Target As Integer
  268.   TargetPosition As Point3D
  269.   MainDestination As Point3D
  270.   CurrentDestination As Point3D
  271.   Path As PathObj
  272.   CurrentPathPoint As Integer
  273.   Speed As Integer
  274. End Type
  275.  
  276. Global Const MAXTAGS = 3
  277. Global Const TAG_BLOCKED = 1
  278.  
  279. Type ObjThing
  280.   Objective As UnitObjective
  281.   Active As Boolean
  282.   Brain As BrainType
  283.   DNA As DNAType
  284.   ModelIndex As Integer
  285.   Side As Integer
  286.   States(MAXSTATES) As Boolean
  287.   Position As Point3D
  288.   MapPosition As Point3D
  289.   Vector As Vect3D
  290.   CurrentSpeed As Integer
  291.   DisplayDirection As Integer
  292.   Properties(MAXOBJECTPROPERTIES) As Integer
  293.   Sprite As SpriteDefType
  294.   Frozen As Boolean
  295.   TopSprite As SpriteDefType
  296.   TopDirection As Integer
  297.   TopDisplayDirection As Integer
  298.   InertiaDirection As Vect3D
  299.   InertiaSpeed As Integer
  300.   InertiaSpeedUp As Single
  301.  
  302.   ObjectTags(MAXTAGS) As Boolean
  303. End Type
  304.  
  305. Global Const MAXOBJECTS = 999
  306. Global Objects(MAXOBJECTS) As ObjThing
  307. Global ObjectsActive As Integer
  308. Global Const OBJCHECK_ALIVE = 1
  309. Global Const OBJCHECK_CANBEDIRECTED = 2
  310. Global Const OBJCHECK_CANBESELECTED = 3
  311. Global Const OBJCHECK_CANATTACK = 4
  312. Global Const OBJCHECK_CANMOVE = 5
  313. Global Const OBJCHECK_OCCUPIESMAPSPACE = 6
  314. Global Const OBJCHECK_SELECTABLE = 7
  315. Global Const OBJCHECK_HITTABLE = 8
  316. Global Const OBJCHECK_VISIBLE = 9
  317.  
  318. Global Const INSTRUCTION_FORCEATTACK = 1
  319. Global Const INSTRUCTION_FORCEMOVE = 2
  320.  
  321. Global Const SPRITEGROUP_NORMAL = 1
  322. Global Const SPRITEGROUP_SHOOTING = 2
  323. Global Const SPRITEGROUP_BUILDING = 3
  324. Public Function FindPath(ObjIndex, X, Y, UnpassableTerrain) As PathObj
  325. 'Pathfinding algorithm
  326.  
  327. 'FindPath.Points = PathNodes(FoundIndex).Points
  328. End Function
  329. Public Sub Assign_DNA(ObjIndex)
  330. For I = 1 To MAXGENETICS
  331.   Objects(I).DNA.Genetics(I) = Int(GeneticRange * Rnd) - HalfGeneticRange
  332. Next I
  333. End Sub
  334. Public Function CheckObject(ObjIndex, CheckType) As Boolean
  335. With ObjModels(Objects(ObjIndex).ModelIndex)
  336.     Select Case CheckType
  337.     Case OBJCHECK_ALIVE
  338.       If Objects(ObjIndex).Active = True Then
  339.         CheckObject = True
  340.       End If
  341.     Case OBJCHECK_CANBEDIRECTED
  342.       If .Abilities(ABILITY_MOVES) = True Then
  343.         CheckObject = True
  344.       End If
  345.     Case OBJCHECK_CANBESELECTED
  346.       If .Abilities(ABILITY_SELECTABLE) = True Then
  347.         CheckObject = True
  348.       End If
  349.     Case OBJCHECK_CANATTACK
  350.       If .Abilities(ABILITY_SHOOTS) = True Then
  351.         CheckObject = True
  352.       End If
  353.     Case OBJCHECK_CANMOVE
  354.       If .Abilities(ABILITY_MOVES) = True Then
  355.         CheckObject = True
  356.       End If
  357.     Case OBJCHECK_OCCUPIESMAPSPACE
  358.       If .Abilities(ABILITY_ISPHYSICAL) = True Then
  359.         CheckObject = True
  360.       End If
  361.     Case OBJCHECK_SELECTABLE
  362.       If .Abilities(ABILITY_SELECTABLE) = True Then
  363.         If Objects(ObjIndex).Side = LocalPlayer.PlayerIndex Then
  364.           CheckObject = True
  365.         End If
  366.       End If
  367.     Case OBJCHECK_HITTABLE
  368.       If .Abilities(ABILITY_HITTABLE) = True Then
  369.         CheckObject = True
  370.       End If
  371.     Case OBJCHECK_VISIBLE
  372.       If .Attributes(ATTRIBUTE_SPRITE) <> NOSPRITE Then
  373.         CheckObject = True
  374.       End If
  375.     End Select
  376. End With
  377. End Function
  378. Public Sub DirectUnit(ObjIndex, XPoint, YPoint, ManualInstruction)
  379. Const DONOTEXECUTEGOAL = 999
  380. 'Figure out what the instruction is
  381. X = Map.ProjectToMapX(XPoint)
  382. Y = Map.ProjectToMapY(YPoint)
  383. If X < 0 Then X = 0
  384. If Y < 0 Then Y = 0
  385. Call Map.SetGroundUnOccupiedByObject(ObjIndex)
  386.  
  387. With GroundBlocks(X, Y)
  388.     Instruction = GOAL_NOTHING
  389.     If IsMapBlockEmptyXY(X, Y) = True Then
  390.       Instruction = GOAL_NOTHING
  391.     Else
  392.       If Objects(.OccupyingObject).Side <> LocalPlayer.PlayerIndex Then
  393.         If Objects(.OccupyingObject).Side <> SIDE_SCENERY Then
  394.           If CheckObject(.OccupyingObject, OBJCHECK_HITTABLE) = True Then
  395.             Instruction = GOAL_ATTACK
  396.           End If
  397.         End If
  398.       End If
  399.     End If
  400.     For I = 1 To ObjectsActive
  401.       If CheckObject(I, OBJCHECK_ALIVE) = True Then
  402.         If Objects(I).Side <> LocalPlayer.PlayerIndex = True Then
  403.           If Objects(I).Side <> SIDE_SCENERY = True Then
  404.             Dim Temppoint As Point3D
  405.             Temppoint.X = XPoint
  406.             Temppoint.Y = YPoint
  407.             If CheckObject(I, OBJCHECK_HITTABLE) = True Then
  408.               If CheckIfPointIsOnUnit(I, Temppoint) = True Then
  409.                 Instruction = DONOTEXECUTEGOAL
  410.                 Call ObjectCommand_AttackObject(ObjIndex, I, X, Y)
  411.               End If
  412.             End If
  413.           End If
  414.         End If
  415.       End If
  416.     Next I
  417.     If Instruction = GOAL_NOTHING Then
  418.       If ObjModels(Objects(ObjIndex).ModelIndex).Abilities(ABILITY_HARVESTS) Then
  419.         If .TerrainType = TERRAINTYPE_GEMS Then
  420.           Instruction = GOAL_HARVESTGEMS
  421.         End If
  422.       End If
  423.     End If
  424.     If Instruction = GOAL_NOTHING Then Instruction = GOAL_MOVESOMEWHERE
  425.     
  426.     If ManualInstruction = INSTRUCTION_FORCEATTACK Then
  427.       Instruction = GOAL_ATTACK
  428.     End If
  429.     
  430.     If ManualInstruction = INSTRUCTION_FORCEMOVE Then
  431.       Instruction = GOAL_MOVESOMEWHERE
  432.     End If
  433.     
  434.     'Carry out the instruction
  435.     Select Case Instruction
  436.     Case GOAL_MOVESOMEWHERE
  437.       If CheckObject(ObjIndex, OBJCHECK_CANBEDIRECTED) = True Then
  438.         Call ObjectCommand_MoveSomewhere(ObjIndex, X, Y)
  439.       End If
  440.     Case GOAL_ATTACK
  441.       If CheckObject(ObjIndex, OBJCHECK_CANBEDIRECTED) = True Then
  442.         If CheckObject(ObjIndex, OBJCHECK_CANATTACK) = True Then
  443.           OccupyObj = .OccupyingObject
  444.           If .Occupied = False Then OccupyObj = TARGETGROUND
  445.           Call ObjectCommand_AttackObject(ObjIndex, OccupyObj, X, Y)
  446.         End If
  447.       End If
  448.     End Select
  449.     Call Map.SetGroundOccupiedByObject(ObjIndex)
  450. End With
  451. End Sub
  452. Public Sub ObjectEmitSound(ObjIndex, SoundNumber)
  453. Dim SoundNum As Integer
  454. SoundNum = SoundNumber
  455. Call Sound.Play_Sound(SoundNum, 0, 0)
  456. End Sub
  457. Public Sub ObjectCommand_MoveSomewhere(ObjIndex, X, Y)
  458. Call ClearObjectStates(ObjIndex)
  459. With Objects(ObjIndex)
  460.   .Objective.Goal = GOAL_MOVESOMEWHERE
  461.   .Objective.Speed = 0
  462.   .States(STATE_MOVING) = False
  463. End With
  464. Call ChangeObjectDestination(ObjIndex, X, Y, 0)
  465. End Sub
  466. Public Sub ObjectCommand_AvoidCollision(ObjIndex, X, Y)
  467. Dim TempPos As Point3D, TempVector As Vect3D
  468. With Objects(ObjIndex)
  469.   TempVector.Yaw = .Vector.Yaw + 22
  470.   CheckVector TempVector
  471.   .Vector.Yaw = TempVector.Yaw
  472.   TempPos = Math.GetPropelCoordinates(.Position, .Vector.Yaw, 0, 70)
  473.   If .Objective.Goal <> GOAL_GETOUTOFTHEWAY Then .Properties(PROPERTY_LASTCOMMAND) = .Objective.Goal
  474.   .Objective.Goal = GOAL_GETOUTOFTHEWAY
  475.   If .Objective.CurrentDestination.X < 0 Then .Objective.CurrentDestination.X = 0
  476.   If .Objective.CurrentDestination.Y < 0 Then .Objective.CurrentDestination.Y = 0
  477.   .Objective.CurrentDestination = Map.ProjectToMap3DPoint(TempPos)
  478. End With
  479. Call Entities.SetObjectDirection(ObjIndex, TempPos)
  480. SetDisplayDirection ObjIndex
  481. End Sub
  482. Sub ClearObjectStates(ObjIndex)
  483. For I = 1 To MAXSTATES
  484.   Objects(ObjIndex).States(I) = False
  485. Next I
  486. End Sub
  487. Public Sub ObjectCommand_BuildThis(ObjIndex, ClassToBuild)
  488. Call ClearObjectStates(ObjIndex)
  489. Objects(ObjIndex).States(STATE_BUILDING) = True
  490. Objects(ObjIndex).Properties(PROPERTY_BUILDPROGRESS) = 0
  491. Objects(ObjIndex).Properties(PROPERTY_CLASSTOBUILD) = ClassToBuild
  492. Objects(ObjIndex).Sprite.SpriteGroupNumber = SPRITEGROUP_BUILDING
  493. Objects(ObjIndex).Sprite.SpriteFrameNumber = 1
  494. End Sub
  495. Public Sub ObjectCommand_SitStillForTime(ObjIndex, TimeLength)
  496. With Objects(ObjIndex)
  497.   .Properties(PROPERTY_LASTCOMMAND) = .Objective.Goal
  498.   .Properties(PROPERTY_TIMEREMAININGONSITSTILL) = TimeLength
  499.   .Objective.Goal = GOAL_SITSTILL
  500.   .States(STATE_MOVING) = False
  501.   .Objective.Speed = 0
  502. End With
  503. End Sub
  504. Public Sub ObjectCommand_AttackObject(ObjIndex, ObjectToAttack, X, Y)
  505. Dim Temppoint As Point3D, TempVector As Vect3D, TargetPosition As Point3D
  506. Call ClearObjectStates(ObjIndex)
  507. With Objects(ObjIndex)
  508.   .Objective.Goal = GOAL_ATTACK
  509.   .Objective.Target = ObjectToAttack
  510.   .Objective.TargetPosition.X = X
  511.   .Objective.TargetPosition.Y = Y
  512.   .Objective.Speed = 0
  513.   TargetPosition = Map.UnProjectToMap3DPoint(.Objective.TargetPosition)
  514.   TempVector.Yaw = Math.GetYawFromXY(TargetPosition.X, TargetPosition.Y, .Position.X, .Position.Y)
  515.   Call CheckVector(TempVector)
  516.   If .Objective.Target = TARGETGROUND Then
  517.     DistOffsetVal = 0
  518.   Else
  519.     DistOffsetVal = ObjModels(Objects(.Objective.Target).ModelIndex).Attributes(ATTRIBUTE_SIZE) * MapBlockSize
  520.   End If
  521.   DistanceFromTarget = Math.GetDistance(Objects(ObjIndex).Position, Objects(ObjIndex).Objective.TargetPosition) - DistOffsetVal
  522.   If DistanceFromTarget < ObjModels(.ModelIndex).Attributes(ATTRIBUTE_MINIMUMSHOOTRADIUS) Then
  523.     Call ObjectCommand_GetFartherAwayFromTarget(ObjIndex, Map.ProjectToMap3DPoint(TargetPosition))
  524.   Else
  525.     If DistanceFromTarget > ObjModels(Objects(ObjIndex).ModelIndex).Attributes(ATTRIBUTE_SHOOTRADIUS) Then
  526.       Temppoint = Map.ProjectToMap3DPoint(Math.GetPropelCoordinates(TargetPosition, TempVector.Yaw, 0, ((ObjModels(.ModelIndex).Attributes(ATTRIBUTE_SHOOTRADIUS) - ObjModels(.ModelIndex).Attributes(ATTRIBUTE_MINIMUMSHOOTRADIUS)) / 2) + ObjModels(.ModelIndex).Attributes(ATTRIBUTE_MINIMUMSHOOTRADIUS) + DistOffsetVal))
  527.       Call ChangeObjectDestination(ObjIndex, Temppoint.X, Temppoint.Y, 0)
  528.     End If
  529.   End If
  530. End With
  531. End Sub
  532. Public Sub ObjectCommand_ContinueAttack(ObjIndex, ObjectToAttack, X, Y)
  533. Dim Temppoint As Point3D, TempVector As Vect3D, TargetPosition As Point3D
  534. With Objects(ObjIndex)
  535.   .Objective.Goal = GOAL_ATTACK
  536.   .Objective.Target = ObjectToAttack
  537.   .Objective.TargetPosition.X = X
  538.   .Objective.TargetPosition.Y = Y
  539.   TargetPosition = Map.UnProjectToMap3DPoint(.Objective.TargetPosition)
  540.   TempVector.Yaw = Math.GetYawFromXY(TargetPosition.X, TargetPosition.Y, .Position.X, .Position.Y)
  541.   Call CheckVector(TempVector)
  542.   Temppoint = Map.ProjectToMap3DPoint(Math.GetPropelCoordinates(TargetPosition, TempVector.Yaw, 0, ((ObjModels(.ModelIndex).Attributes(ATTRIBUTE_SHOOTRADIUS) - ObjModels(.ModelIndex).Attributes(ATTRIBUTE_MINIMUMSHOOTRADIUS)) / 2) + ObjModels(.ModelIndex).Attributes(ATTRIBUTE_MINIMUMSHOOTRADIUS)))
  543. End With
  544. Call ChangeObjectDestination(ObjIndex, Temppoint.X, Temppoint.Y, 0)
  545. End Sub
  546. Public Sub ObjectCommand_CeaseAttack(ObjIndex)
  547. With Objects(ObjIndex)
  548.   .Objective.Goal = GOAL_NOTHING
  549.   Call ClearObjectStates(ObjIndex)
  550.   .Objective.Speed = 0
  551.   .Objective.Target = NOTARGET
  552.   .Objective.TargetPosition.X = .MapPosition.X
  553.   .Objective.TargetPosition.Y = .MapPosition.Y
  554. End With
  555. End Sub
  556.  
  557. Public Sub ObjectCommand_Deploy(ObjIndex)
  558. With Objects(ObjIndex)
  559.   OBJDEPLOY = ObjModels(.ModelIndex).Attributes(ATTRIBUTE_DEPLOYOBJECT)
  560.   Side = .Side
  561.   X = .MapPosition.X
  562.   Y = .MapPosition.Y
  563. End With
  564. Call DestroyObject(ObjIndex)
  565. newobj = SpawnObject(OBJDEPLOY, Side, X, Y, 0, 0, 0)
  566. End Sub
  567. Public Sub RunObjectAnimation(ObjIndex)
  568. With Objects(ObjIndex)
  569.   If ObjModels(.ModelIndex).Abilities(ABILITY_BODYISBISECTED) = True Then
  570.     .TopSprite.SpriteFrameTicks = .TopSprite.SpriteFrameTicks + 1
  571.     If .TopSprite.SpriteFrameTicks > Sprites(ObjModels(.ModelIndex).Attributes(ATTRIBUTE_TOPSPRITE)).SpriteGroups(.TopSprite.SpriteFrameNumber).Frames(.TopSprite.SpriteFrameNumber).FrameDuration Then
  572.       .TopSprite.SpriteFrameTicks = 1
  573.       .TopSprite.SpriteFrameNumber = .TopSprite.SpriteFrameNumber + 1
  574.       If .TopSprite.SpriteFrameNumber > Sprites(ObjModels(.ModelIndex).Attributes(ATTRIBUTE_TOPSPRITE)).SpriteGroups(.TopSprite.SpriteGroupNumber).FrameMax Then
  575.         If Sprites(ObjModels(.ModelIndex).Attributes(ATTRIBUTE_TOPSPRITE)).SpriteGroups(.TopSprite.SpriteFrameNumber).RepeatSequence = True Then
  576.           .TopSprite.SpriteFrameNumber = 1
  577.         Else
  578.           .TopSprite.SpriteFrameNumber = 1
  579.           .TopSprite.SpriteGroupNumber = SPRITEGROUP_NORMAL
  580.         End If
  581.       End If
  582.     End If
  583.   Else
  584.     .Sprite.SpriteFrameTicks = .Sprite.SpriteFrameTicks + 1
  585.     If .Sprite.SpriteFrameTicks > Sprites(.Sprite.SpriteNumber).SpriteGroups(.Sprite.SpriteGroupNumber).Frames(.Sprite.SpriteFrameNumber).FrameDuration Then
  586.       .Sprite.SpriteFrameTicks = 1
  587.       .Sprite.SpriteFrameNumber = .Sprite.SpriteFrameNumber + 1
  588.       If .Sprite.SpriteFrameNumber > Sprites(.Sprite.SpriteNumber).SpriteGroups(.Sprite.SpriteGroupNumber).FrameMax Then
  589.         If Sprites(.Sprite.SpriteGroupNumber).SpriteGroups(.Sprite.SpriteGroupNumber).RepeatSequence = True Then
  590.           .Sprite.SpriteFrameNumber = 1
  591.         Else
  592.           .Sprite.SpriteFrameNumber = 1
  593.           .Sprite.SpriteGroupNumber = SPRITEGROUP_NORMAL
  594.         End If
  595.       End If
  596.     End If
  597.   End If
  598. End With
  599. End Sub
  600. Public Sub ObjectCommand_Fire(ObjIndex, X, Y, Z, Target)
  601. Dim Temppoint As Point3D, TempPosition As Point3D
  602. Call Object_PlaySound(ObjIndex, SoundEvent_Fire)
  603. With Temppoint
  604.   .X = X
  605.   .Y = Y
  606.   .Z = Z
  607. End With
  608. With Objects(ObjIndex)
  609.   If ObjModels(.ModelIndex).Abilities(ABILITY_FRAMES_SHOOTING) = True Then
  610.     If ObjModels(.ModelIndex).Abilities(ABILITY_BODYISBISECTED) = True Then
  611.       .TopSprite.SpriteGroupNumber = SPRITEGROUP_SHOOTING
  612.       .TopSprite.SpriteFrameNumber = 1
  613.     Else
  614.       .Sprite.SpriteGroupNumber = SPRITEGROUP_SHOOTING
  615.       .Sprite.SpriteFrameNumber = 1
  616.     End If
  617.   End If
  618.   If ObjModels(.ModelIndex).Attributes(ATTRIBUTE_ACCURACY) <> 0 Then
  619.     Offset = (ObjModels(.ModelIndex).Attributes(ATTRIBUTE_ACCURACY) * Rnd) - (ObjModels(.ModelIndex).Attributes(ATTRIBUTE_ACCURACY) / 2)
  620.   End If
  621.   If ObjModels(.ModelIndex).Abilities(ABILITY_BODYISBISECTED) = True Then
  622.     FireYaw = .TopDirection
  623.     TempPosition.X = .Position.X - ObjModels(.ModelIndex).Attributes(ATTRIBUTE_WEAPONX)
  624.     TempPosition.Y = .Position.Y - ObjModels(.ModelIndex).Attributes(ATTRIBUTE_WEAPONY)
  625.     TempPosition = Math.RotatePointAroundPoint(TempPosition, .Position, .TopDirection + Offset)
  626.   Else
  627.     FireYaw = .Vector.Yaw
  628.     TempPosition.X = .Position.X - ObjModels(.ModelIndex).Attributes(ATTRIBUTE_WEAPONX)
  629.     TempPosition.Y = .Position.Y - ObjModels(.ModelIndex).Attributes(ATTRIBUTE_WEAPONY)
  630.     TempPosition = Math.RotatePointAroundPoint(TempPosition, .Position, .Vector.Yaw + Offset)
  631.   End If
  632.   
  633.   
  634.   FireX = TempPosition.X
  635.   FireY = TempPosition.Y
  636.   FireZIncline = 0
  637.   .Properties(PROPERTY_WEAPONCHARGE) = 0
  638.   newobj = SpawnObject(.Properties(PROPERTY_WEAPONOBJECTTYPE), .Side, Map.ProjectToMapX(FireX), Map.ProjectToMapY(FireY), FireZ, FireYaw, FireZIncline)
  639.   Call RelocateObject(newobj, FireX, FireY, .Position.Z)
  640. End With
  641. With Objects(newobj)
  642.   .Position.Z = (ObjModels(.ModelIndex).Attributes(ATTRIBUTE_LENGTHZ) / 2) + .Position.Z
  643.   Call ChangeObjectDestination(newobj, X, Y, Z)
  644.   .Objective.Target = Target
  645.   .Objective.TargetPosition = Temppoint
  646.   .Properties(PROPERTY_FUEL) = Math.GetDistance(Objects(ObjIndex).Position, Map.UnProjectToMap3DPoint(Temppoint)) / (ObjModels(Objects(ObjIndex).ModelIndex).Attributes(ATTRIBUTE_MAXSPEED))
  647. End With
  648. End Sub
  649. Public Sub RelocateObject(ObjIndex, NewX, NewY, NewZ)
  650. If CheckObject(ObjIndex, OBJCHECK_OCCUPIESMAPSPACE) = True Then Call Map.SetGroundUnOccupiedByObject(ObjIndex)
  651. With Objects(ObjIndex)
  652.   .Position.X = NewX
  653.   .Position.Y = NewY
  654.   .Position.Z = NewZ
  655.   Call Entities.SetObjectMapPosition(ObjIndex)
  656. End With
  657. If CheckObject(ObjIndex, OBJCHECK_OCCUPIESMAPSPACE) = True Then Call Map.SetGroundOccupiedByObject(ObjIndex)
  658. End Sub
  659. Public Sub ObjectCommand_GetOutOfTheWay(Obj1, Obj2, GetOutOfWayLength)
  660. Dim Temppoint As Point3D, TempVector As Vect3D
  661. With Objects(Obj1)
  662.   TempVector.Yaw = Math.GetYawFromXY(.Position.X, .Position.Y, Objects(Obj2).Position.X, Objects(Obj2).Position.Y) + 180
  663.   If TempVector.Yaw > Objects(Obj1).Vector.Yaw - 15 Then
  664.     If TempVector.Yaw < Objects(Obj1).Vector.Yaw + 15 Then
  665.       If Int(2 * Rnd) = 1 Then
  666.         TempVector.Yaw = TempVector.Yaw - 15
  667.       Else
  668.         TempVector.Yaw = TempVector.Yaw + 15
  669.       End If
  670.     End If
  671.   End If
  672.   Call CheckVector(TempVector)
  673.   If .Objective.Goal <> GOAL_GETOUTOFTHEWAY Then .Properties(PROPERTY_LASTCOMMAND) = .Objective.Goal
  674.   .Properties(PROPERTY_POSITIONTEMPX) = .MapPosition.X
  675.   .Properties(PROPERTY_POSITIONTEMPY) = .MapPosition.Y
  676.   .Objective.Goal = GOAL_GETOUTOFTHEWAY
  677.   Temppoint = Map.ProjectToMap3DPoint(Math.GetPropelCoordinates(.Position, TempVector.Yaw, 0, GetOutOfWayLength))
  678.   Call Entities.ChangeObjectDestination(Obj1, Temppoint.X, Temppoint.Y, Temppoint.Z)
  679. End With
  680. End Sub
  681. Public Sub ObjectCommand_CreatePath(ObjIndex, X, Y)
  682. With Objects(ObjIndex)
  683.   If .Objective.Goal <> GOAL_GETOUTOFTHEWAY Then .Properties(PROPERTY_LASTCOMMAND) = .Objective.Goal
  684.   .Objective.Goal = GOAL_FOLLOWPATH
  685.   .Objective.CurrentPathPoint = 1
  686.   .Objective.Path = FindPath(ObjIndex, X, Y, TERRAINTYPE_WATER)
  687. End With
  688. End Sub
  689. Public Sub ObjectCommand_GetFartherAwayFromTarget(Obj1, TargetPosition As Point3D)
  690. Dim Temppoint As Point3D, TempVector As Vect3D
  691. With Objects(Obj1)
  692.   
  693.   
  694.   TempVector.Yaw = Math.GetYawFromXY(Map.UnProjectToMapX(TargetPosition.X), Map.UnProjectToMapY(TargetPosition.Y), .Position.X, .Position.Y) '+ 180
  695.   
  696.   Call CheckVector(TempVector)
  697.   .Objective.Goal = GOAL_GETFARTHERAWAYFROMTARGET
  698.   If .Objective.Target <> TARGETGROUND Then
  699.     TargetSize = (ObjModels(Objects(.Objective.Target).ModelIndex).Attributes(ATTRIBUTE_SIZE) * MapBlockSize)
  700.   Else
  701.     TargetSize = 0
  702.   End If
  703.   Temppoint = Map.ProjectToMap3DPoint(Math.GetPropelCoordinates(Map.UnProjectToMap3DPoint(TargetPosition), TempVector.Yaw, 0, TargetSize + ObjModels(.ModelIndex).Attributes(ATTRIBUTE_MINIMUMSHOOTRADIUS) + 20))
  704.   Call Entities.ChangeObjectDestination(Obj1, Temppoint.X, Temppoint.Y, Temppoint.Z)
  705. End With
  706. End Sub
  707. Public Sub RunObject(ObjIndex)
  708. Dim TempPos As Point3D
  709. If CheckObject(ObjIndex, OBJCHECK_OCCUPIESMAPSPACE) = True Then Call SetGroundOccupiedByObject(ObjIndex)
  710. Call RunObjectAnimation(ObjIndex)
  711. With Objects(ObjIndex)
  712.     If ObjModels(.ModelIndex).Abilities(ABILITY_USESINERTIA) = True Then
  713.       'Friction
  714.       If .Position.Z = GroundBlocks(.MapPosition.X, .MapPosition.Y).Height Then
  715.         .CurrentSpeed = .CurrentSpeed - (GroundBlocks(.MapPosition.X, .MapPosition.Y).Friction * ObjModels(.ModelIndex).Attributes(ATTRIBUTE_WEIGHT))
  716.         If .CurrentSpeed < 0 Then .CurrentSpeed = 0
  717.       Else
  718.         .CurrentSpeed = .CurrentSpeed - LevelSettings.AirFriction
  719.       End If
  720.       If .Objective.Speed > .CurrentSpeed Then
  721.         .CurrentSpeed = .CurrentSpeed + (ObjModels(.ModelIndex).Attributes(ATTRIBUTE_ENGINEPOWER) / ObjModels(.ModelIndex).Attributes(ATTRIBUTE_WEIGHT))
  722.         If .CurrentSpeed > .Objective.Speed Then .CurrentSpeed = .Objective.Speed
  723.       End If
  724.       If .InertiaSpeed > 0 Then
  725.         If .Position.Z = GroundBlocks(.MapPosition.X, .MapPosition.Y).Height Then
  726.           .InertiaSpeed = .InertiaSpeed - (GroundBlocks(.MapPosition.X, .MapPosition.Y).Friction / ObjModels(.ModelIndex).Attributes(ATTRIBUTE_WEIGHT))
  727.         Else
  728.           .InertiaSpeed = .InertiaSpeed - LevelSettings.AirFriction
  729.         End If
  730.       End If
  731.       If .Position.Z > GroundBlocks(.MapPosition.X, .MapPosition.Y).Height Then
  732.         .InertiaSpeedUp = .InertiaSpeedUp - (LevelSettings.GravityAmount * (ObjModels(.ModelIndex).Attributes(ATTRIBUTE_WEIGHT) + 1))
  733.       End If
  734.       Entities.SteerInertialDirection ObjIndex, .Vector.Yaw, 7
  735.       .Position.Z = .Position.Z + .InertiaSpeedUp
  736.       If .Position.Z <= GroundBlocks(.MapPosition.X, .MapPosition.Y).Height Then
  737.         If .InertiaSpeedUp < 0 Then
  738.           .Position.Z = GroundBlocks(.MapPosition.X, .MapPosition.Y).Height
  739.           .InertiaSpeedUp = -(.InertiaSpeedUp / 4) - LevelSettings.GravityAmount
  740.           If .InertiaSpeedUp < 3 Then
  741.             .InertiaSpeedUp = 0
  742.           End If
  743.         End If
  744.       End If
  745.     Else
  746.       .CurrentSpeed = .Objective.Speed
  747.     End If
  748.     Call RunBehavior(ObjIndex, ObjModels(.ModelIndex).BehaviorType)
  749.     If .States(STATE_FIRING) = True Then
  750.       If .Properties(PROPERTY_WEAPONCHARGE) <> DELAYWEAPON Then
  751.         .Properties(PROPERTY_WEAPONCHARGE) = .Properties(PROPERTY_WEAPONCHARGE) + 1
  752.         If .Properties(PROPERTY_WEAPONCHARGE) > ObjModels(.ModelIndex).Attributes(ATTRIBUTE_WEAPONCHARGETIME) Then
  753.           .Properties(PROPERTY_WEAPONCHARGE) = DELAYWEAPON
  754.           Call Events.SpawnEvent(Events.Event_ObjectFire, ObjIndex, .Objective.TargetPosition.X, .Objective.TargetPosition.Y, .Objective.TargetPosition.Z)
  755.         End If
  756.       End If
  757.     End If
  758.     If .CurrentSpeed > 0 Or .InertiaSpeed > 0 Then
  759.       If ObjModels(.ModelIndex).Abilities(ABILITY_SPLASHESWATER) = True Then
  760.         If GroundBlocks(.MapPosition.X, .MapPosition.Y).TerrainOverlayAmount > 1 Then
  761.           If .Position.Z = GroundBlocks(.MapPosition.X, .MapPosition.Y).Height Then
  762.             SparkDirection = Int(360 * Rnd)
  763.             TempPos = Math.GetPropelCoordinates(.Position, SparkDirection, 0, 7 + (5 * Rnd))
  764.             Call SpawnSpark(TempPos.X, TempPos.Y, .Position.Z, PALLETE_BLUE, SparkDirection, 2, 10, 7, 1)
  765.           End If
  766.         End If
  767.       End If
  768.       If ObjModels(.ModelIndex).Abilities(ABILITY_LEAVESSPARKLETRAIL) = True Then
  769.         Call SpawnSpark(.Position.X, .Position.Y, .Position.Z, PALLETE_YELLOW, Int(360 * Rnd), 1, 25, 0, 1)
  770.       End If
  771.       Call MoveObject(ObjIndex, .Vector.Yaw, .CurrentSpeed)
  772.       Call MoveObject(ObjIndex, .InertiaDirection.Yaw, .InertiaSpeed)
  773.     End If
  774. End With
  775. End Sub
  776. Public Sub RunBehavior(ObjIndex, BehaveType)
  777. With Objects(ObjIndex)
  778.     Select Case BehaveType
  779.     Case BEHAVIORMODE_TANK
  780.         Dim TempPos As Point3D
  781.         If .ObjectTags(TAG_BLOCKED) = True Then
  782.           Call ObjectCommand_CreatePath(ObjIndex, .Objective.MainDestination.X, .Objective.MainDestination.Y)
  783.           .ObjectTags(TAG_BLOCKED) = False
  784.         End If
  785.         Select Case .Objective.Goal
  786.         Case GOAL_FOLLOWPATH
  787.           If Math.GetDistance(.Position, Map.UnProjectToMap3DPoint(.Objective.CurrentDestination)) < OBJCONST_ObjectStopDistance Then
  788.             If .Objective.CurrentPathPoint = .Objective.Path.Points.PathPointsActive Then
  789.               .Objective.Speed = 0
  790.               .States(STATE_MOVING) = False
  791.               Select Case .Properties(PROPERTY_LASTCOMMAND)
  792.               Case GOAL_NOTHING
  793.                 Call ObjectCommand_MoveSomewhere(ObjIndex, .Properties(PROPERTY_POSITIONTEMPX), .Properties(PROPERTY_POSITIONTEMPY))
  794.               Case GOAL_MOVESOMEWHERE
  795.                 Call ObjectCommand_MoveSomewhere(ObjIndex, .Objective.MainDestination.X, .Objective.MainDestination.Y)
  796.               Case GOAL_ATTACK
  797.                 Call ObjectCommand_AttackObject(ObjIndex, Objects(ObjIndex).Objective.Target, Objects(ObjIndex).Objective.TargetPosition.X, Objects(ObjIndex).Objective.TargetPosition.Y)
  798.               Case GOAL_GETFARTHERAWAYFROMTARGET
  799.                 Call ObjectCommand_AttackObject(ObjIndex, Objects(ObjIndex).Objective.Target, Objects(ObjIndex).Objective.TargetPosition.X, Objects(ObjIndex).Objective.TargetPosition.Y)
  800.               End Select
  801.             Else
  802.               .Objective.CurrentPathPoint = .Objective.CurrentPathPoint + 1
  803.               .Objective.CurrentDestination.X = .Objective.Path.Points.PathPoints(.Objective.CurrentPathPoint).X
  804.               .Objective.CurrentDestination.Y = .Objective.Path.Points.PathPoints(.Objective.CurrentPathPoint).Y
  805.               .States(STATE_MOVING) = True
  806.             End If
  807.           End If
  808.         Case GOAL_SITSTILL
  809.           .Properties(PROPERTY_TIMEREMAININGONSITSTILL) = .Properties(PROPERTY_TIMEREMAININGONSITSTILL) - 1
  810.           If .Properties(PROPERTY_TIMEREMAININGONSITSTILL) = 0 Then
  811.             .Objective.Goal = .Properties(PROPERTY_LASTCOMMAND)
  812.           End If
  813.         Case GOAL_GETOUTOFTHEWAY
  814.           If Math.GetDistance(.Position, Map.UnProjectToMap3DPoint(.Objective.CurrentDestination)) > OBJCONST_ObjectStopDistance Then
  815.             .States(STATE_MOVING) = True
  816.           Else
  817.             .Objective.Speed = 0
  818.             .States(STATE_MOVING) = False
  819.             Select Case .Properties(PROPERTY_LASTCOMMAND)
  820.             Case GOAL_NOTHING
  821.               Call ObjectCommand_MoveSomewhere(ObjIndex, .Properties(PROPERTY_POSITIONTEMPX), .Properties(PROPERTY_POSITIONTEMPY))
  822.             Case GOAL_MOVESOMEWHERE
  823.               Call ObjectCommand_MoveSomewhere(ObjIndex, .Objective.MainDestination.X, .Objective.MainDestination.Y)
  824.             Case GOAL_ATTACK
  825.               Call ObjectCommand_AttackObject(ObjIndex, Objects(ObjIndex).Objective.Target, Objects(ObjIndex).Objective.TargetPosition.X, Objects(ObjIndex).Objective.TargetPosition.Y)
  826.             Case GOAL_GETFARTHERAWAYFROMTARGET
  827.               Call ObjectCommand_AttackObject(ObjIndex, Objects(ObjIndex).Objective.Target, Objects(ObjIndex).Objective.TargetPosition.X, Objects(ObjIndex).Objective.TargetPosition.Y)
  828.             Case Else
  829.               .Objective.Goal = GOAL_NOTHING
  830.             End Select
  831.           End If
  832.         Case GOAL_GETFARTHERAWAYFROMTARGET
  833.           If Math.GetDistance(.Position, Map.UnProjectToMap3DPoint(.Objective.CurrentDestination)) > OBJCONST_ObjectStopDistance Then
  834.             .States(STATE_MOVING) = True
  835.           Else
  836.             If .Objective.Target <> NOTARGET Then
  837.               .States(STATE_MOVING) = False
  838.               Call ObjectCommand_AttackObject(ObjIndex, .Objective.Target, .Objective.TargetPosition.X, .Objective.TargetPosition.Y)
  839.             End If
  840.           End If
  841.         Case GOAL_MOVESOMEWHERE
  842.           If ObjModels(.ModelIndex).Abilities(ABILITY_BODYISBISECTED) = True Then
  843.             Call SteerTurretDirection(ObjIndex, Map.UnProjectToMap3DPoint(.Objective.CurrentDestination))
  844.           End If
  845.           If .Objective.Speed > 0 Then
  846.             If Math.GetDistance(.Position, Map.UnProjectToMap3DPoint(.Objective.CurrentDestination)) < OBJCONST_ObjectStopDistance Then
  847.               .Objective.Speed = 0
  848.               .States(STATE_MOVING) = False
  849.               .Objective.Goal = GOAL_NOTHING
  850.             Else
  851.               IsOnCourse = SteerObjectDirection(ObjIndex, Map.UnProjectToMap3DPoint(.Objective.CurrentDestination), ObjModels(.ModelIndex).Attributes(ATTRIBUTE_TURNSPEED))
  852.               .States(STATE_MOVING) = True
  853.             End If
  854.           Else
  855.             If SteerObjectDirection(ObjIndex, Map.UnProjectToMap3DPoint(.Objective.CurrentDestination), ObjModels(.ModelIndex).Attributes(ATTRIBUTE_TURNSPEED)) = True Then
  856.               .States(STATE_MOVING) = True
  857.             End If
  858.           End If
  859.         Case GOAL_ATTACK
  860.           '.States(STATE_MOVING) = False
  861.           If .Objective.Target <> TARGETGROUND Then
  862.             .Objective.TargetPosition = Objects(.Objective.Target).MapPosition
  863.           End If
  864.           If ObjModels(.ModelIndex).Abilities(ABILITY_BODYISBISECTED) = True Then Steered = SteerTurretDirection(ObjIndex, Map.UnProjectToMap3DPoint(.Objective.TargetPosition))
  865.           If .Objective.Target = TARGETGROUND Then
  866.             DistOffsetVal = 0
  867.           Else
  868.             DistOffsetVal = ObjModels(Objects(.Objective.Target).ModelIndex).Attributes(ATTRIBUTE_SIZE) * MapBlockSize
  869.           End If
  870.           If Math.GetDistance(.Position, Map.UnProjectToMap3DPoint(.Objective.CurrentDestination)) < OBJCONST_ObjectStopDistance Then
  871.             .Objective.CurrentDestination = .MapPosition
  872.             .States(STATE_MOVING) = False
  873.             .Objective.Speed = 0
  874.           Else
  875.             If .States(STATE_MOVING) = False Then
  876.               blah = 43
  877.             End If
  878.             .States(STATE_MOVING) = True
  879.           End If
  880.             DistanceFromTarget = Math.GetDistance(.Position, Map.UnProjectToMap3DPoint(.Objective.TargetPosition)) - DistOffsetVal
  881.             If DistanceFromTarget < ObjModels(.ModelIndex).Attributes(ATTRIBUTE_SHOOTRADIUS) Then
  882.               If DistanceFromTarget > ObjModels(.ModelIndex).Attributes(ATTRIBUTE_MINIMUMSHOOTRADIUS) Then
  883.                 If ObjModels(.ModelIndex).Abilities(ABILITY_BODYISBISECTED) = True Then
  884.                   If Steered = True Then
  885.                     .States(STATE_FIRING) = True
  886.                   End If
  887.                 Else
  888.                   If SteerObjectDirection(ObjIndex, Map.UnProjectToMap3DPoint(.Objective.TargetPosition), ObjModels(.ModelIndex).Attributes(ATTRIBUTE_TURNSPEED)) = True Then
  889.                     .States(STATE_FIRING) = True
  890.                   Else
  891.                     .States(STATE_MOVING) = False
  892.                   End If
  893.                 End If
  894.               Else
  895.                 Call ObjectCommand_GetFartherAwayFromTarget(ObjIndex, .Objective.TargetPosition)
  896.               End If
  897.             Else
  898.               If .Objective.Target <> TARGETGROUND Then
  899.                 Call ObjectCommand_ContinueAttack(ObjIndex, .Objective.Target, .Objective.TargetPosition.X, .Objective.TargetPosition.Y)
  900.               End If
  901.               .States(STATE_MOVING) = True
  902.             End If
  903.         End Select
  904.         If .States(STATE_MOVING) = True Then
  905.             If Math.GetDistance(.Position, Map.UnProjectToMap3DPoint(.Objective.CurrentDestination)) > OBJCONST_ObjectStopDistance Then
  906.               If .Objective.Speed > 0 Then
  907.                 .Properties(PROPERTY_TIMEUNTILADJUSTDIRECTION) = .Properties(PROPERTY_TIMEUNTILADJUSTDIRECTION) - 1
  908.                 If .Properties(PROPERTY_TIMEUNTILADJUSTDIRECTION) = 0 Then
  909.                   .Properties(PROPERTY_TIMEUNTILADJUSTDIRECTION) = OBJCONST_TimeTillAdjustDirection
  910.                   If SteerObjectDirection(ObjIndex, Map.UnProjectToMap3DPoint(.Objective.CurrentDestination), ObjModels(.ModelIndex).Attributes(ATTRIBUTE_TURNSPEED)) = False Then
  911.                     .Objective.Speed = 0
  912.                   End If
  913.                 End If
  914.               Else
  915.                 If SteerObjectDirection(ObjIndex, Map.UnProjectToMap3DPoint(.Objective.CurrentDestination), ObjModels(.ModelIndex).Attributes(ATTRIBUTE_TURNSPEED)) = True Then
  916.                   .Objective.Speed = ObjModels(.ModelIndex).Attributes(ATTRIBUTE_MAXSPEED)
  917.                 End If
  918.               End If
  919.             Else
  920.               .Objective.Speed = 0
  921.               .States(STATE_MOVING) = False
  922.             End If
  923.           Else
  924.             .Objective.Speed = 0
  925.           End If
  926.     Case BEHAVIORMODE_WEAPON
  927.         .Properties(PROPERTY_FUEL) = .Properties(PROPERTY_FUEL) - 1
  928.         If .Properties(PROPERTY_FUEL) < 0 Then Call ObjectEvent_MissileCollide(ObjIndex)
  929.         .Properties(PROPERTY_TIMEUNTILADJUSTDIRECTION) = .Properties(PROPERTY_TIMEUNTILADJUSTDIRECTION) - 1
  930.         If .Properties(PROPERTY_TIMEUNTILADJUSTDIRECTION) = 0 Then
  931.           .Properties(PROPERTY_TIMEUNTILADJUSTDIRECTION) = OBJCONST_TimeTillAdjustDirection
  932.           Call SetObjectDirection(ObjIndex, Map.UnProjectToMap3DPoint(.Objective.CurrentDestination))
  933.         End If
  934.         If ObjModels(.ModelIndex).Abilities(ABILITY_REACHESTARGETINSTANTLY) = True Then
  935.           If ObjModels(.ModelIndex).Abilities(ABILITY_LEAVESSPARKLETRAIL) = True Then
  936.             Call VisualEffects.Effect_RailgunTrail(.Position, Map.UnProjectToMap3DPoint(.Objective.TargetPosition))
  937.             .Position = Map.UnProjectToMap3DPoint(.Objective.TargetPosition)
  938.             Call ObjectEvent_MissileCollide(ObjIndex)
  939.           End If
  940.         Else
  941.           .States(STATE_MOVING) = True
  942.           If .Objective.Target <> TARGETGROUND Then
  943.             If .Objective.Target <> NOTARGET Then
  944.               If ObjModels(.ModelIndex).Abilities(ABILITY_FOLLOWSTARGET) = True Then
  945.                 Call ChangeObjectDestination(ObjIndex, Map.ProjectToMapX(Objects(.Objective.Target).Position.X), Map.ProjectToMapY(Objects(.Objective.Target).Position.Y), 0)
  946.               End If
  947.             End If
  948.           End If
  949.           If Math.GetDistance(.Position, Map.UnProjectToMap3DPoint(.Objective.TargetPosition)) < OBJCONST_MissileStopDistance Then
  950.             Call ObjectEvent_MissileCollide(ObjIndex)
  951.           End If
  952.           .Objective.Speed = ObjModels(.ModelIndex).Attributes(ATTRIBUTE_MAXSPEED)
  953.           If GroundBlocks(.MapPosition.X, .MapPosition.Y).Occupied = True Then
  954.             OnObj = GroundBlocks(.MapPosition.X, .MapPosition.Y).OccupyingObject
  955.             If Objects(OnObj).Position.Z = .Position.Z Then
  956.               If CheckObject(OnObj, OBJCHECK_ALIVE) = True Then
  957.                 If CheckObject(OnObj, OBJCHECK_HITTABLE) = True Then
  958.                   If Objects(OnObj).Side <> .Side Then
  959.                     Call ObjectEvent_MissileCollide(ObjIndex)
  960.                   End If
  961.                 End If
  962.               End If
  963.             End If
  964.           End If
  965.         End If
  966.     Case BEHAVIORMODE_BUILDING
  967.         If ObjModels(.ModelIndex).Attributes(ATTRIBUTE_MAPIMPRINT) <> NOMAPIMPRINT Then Call Map.PlaceMapImprint(ObjModels(.ModelIndex).Attributes(ATTRIBUTE_MAPIMPRINT), .MapPosition.X, .MapPosition.Y, ObjIndex)
  968.         If .States(STATE_BUILDING) = True Then
  969.           .Properties(PROPERTY_BUILDPROGRESS) = .Properties(PROPERTY_BUILDPROGRESS) + 1
  970.           If .Properties(PROPERTY_BUILDPROGRESS) = ObjModels(.ModelIndex).Attributes(ATTRIBUTE_BUILDATFRAME) Then
  971.             newobj = SpawnObject(.Properties(PROPERTY_CLASSTOBUILD), .Side, .MapPosition.X + 1, .MapPosition.Y + 1, 0, 90, 0)
  972.             Call ChangeObjectDestination(newobj, .MapPosition.X + 2, .MapPosition.Y + 2, 0)
  973.             Objects(newobj).States(STATE_MOVING) = True
  974.             Objects(newobj).Objective.Goal = GOAL_MOVESOMEWHERE
  975.             .States(STATE_MOVING) = False
  976.           End If
  977.         End If
  978.     Case BEHAVIORMODE_INANIMATE
  979.         If ObjModels(.ModelIndex).Attributes(ATTRIBUTE_MAPIMPRINT) <> NOMAPIMPRINT Then Call Map.PlaceMapImprint(ObjModels(.ModelIndex).Attributes(ATTRIBUTE_MAPIMPRINT), .MapPosition.X, .MapPosition.Y, ObjIndex)
  980.     End Select
  981. End With
  982. End Sub
  983. Public Sub ObjectEvent_MissileCollide(MissileObj)
  984. With Objects(MissileObj)
  985.   If ObjModels(.ModelIndex).Abilities(ABILITY_THROWSMETALATDEATH) = True Then
  986.     Call SpawnSparkExplosion(.Position.X, .Position.Y, .Position.Z, PALLETE_WHITE, 5, 8)
  987.   End If
  988.  
  989.   Intensity = ObjModels(.ModelIndex).Attributes(ATTRIBUTE_EXPLOSIONINTENSITY)
  990.   Size = ObjModels(.ModelIndex).Attributes(ATTRIBUTE_EXPLOSIONRADIUS)
  991.  
  992.   If ObjModels(.ModelIndex).Abilities(ABILITY_THROWSSPARKLESATCOLLIDE) = True Then
  993.     Call SpawnSparkleExplosion(.Position.X, .Position.Y, .Position.Z, PALLETE_YELLOW, 3)
  994.   End If
  995.   Call SpawnSparkDirectionalExplosion(.Position.X, .Position.Y, .Position.Z, PALLETE_YELLOW, Size, Intensity, .Vector.Yaw + 180)
  996.   Call EnviromentEvent_Explosion(.Position, ObjModels(.ModelIndex).Attributes(ATTRIBUTE_EXPLOSIONRADIUS), ObjModels(.ModelIndex).Attributes(ATTRIBUTE_EXPLOSIONINTENSITY), ObjModels(.ModelIndex).Attributes(ATTRIBUTE_EXPLOSIONTYPE))
  997. End With
  998. Call Entities.DestroyObject(MissileObj)
  999. End Sub
  1000. Public Sub EnviromentEvent_Explosion(ExplodePosition As Point3D, Radius, Intensity, ExplodeType)
  1001. If GroundBlocks(Map.ProjectToMapX(ExplodePosition.X), Map.ProjectToMapY(ExplodePosition.Y)).Occupied = True Then
  1002.   If ObjModels(Objects(GroundBlocks(Map.ProjectToMapX(ExplodePosition.X), Map.ProjectToMapY(ExplodePosition.Y)).OccupyingObject).ModelIndex).Abilities(ABILITY_CANBEDAMAGED) = True Then Call DamageObject(GroundBlocks(Map.ProjectToMapX(ExplodePosition.X), Map.ProjectToMapY(ExplodePosition.Y)).OccupyingObject, Intensity, DamageType)
  1003. End If
  1004. For I = 1 To ObjectsActive
  1005.   If CheckObject(I, OBJCHECK_ALIVE) = True Then
  1006.     If CheckObject(I, OBJCHECK_HITTABLE) = True Then
  1007.       With Objects(I)
  1008.         If Math.GetDistance(ExplodePosition, .Position) < Radius * 10 Then
  1009.           If ObjModels(.ModelIndex).Abilities(ABILITY_THROWSMETALWHENHIT) = True Then
  1010.             ExplodeYaw = Math.GetYawFromXY(.Position.X, .Position.Y, ExplodePosition.X, ExplodePosition.Y)
  1011.             ExplodeX = SinTable(ExplodeYaw) * (ObjModels(.ModelIndex).Attributes(ATTRIBUTE_SIZE) * HalfMapBlockSize)
  1012.             ExplodeY = CosTable(ExplodeYaw) * (ObjModels(.ModelIndex).Attributes(ATTRIBUTE_SIZE) * HalfMapBlockSize)
  1013.             Call SpawnSparkDirectionalExplosion(.Position.X + ExplodeX, .Position.Y + ExplodeY, .Position.Z, PALLETE_WHITE, 2, 8, ExplodeYaw)
  1014.           End If
  1015.           If ObjModels(.ModelIndex).Abilities(ABILITY_CANBEDAMAGED) = True Then Call DamageObject(I, Intensity, DamageType)
  1016.         End If
  1017.       End With
  1018.     End If
  1019.   End If
  1020. Next I
  1021. End Sub
  1022. Public Sub DamageObject(ObjIndex, DamageAmount, DamageType)
  1023. With Objects(ObjIndex)
  1024.   .Properties(PROPERTY_HEALTH) = .Properties(PROPERTY_HEALTH) - DamageAmount
  1025.   If .Properties(PROPERTY_HEALTH) <= 0 Then
  1026.     .Frozen = True
  1027.     Call Events.SpawnEvent(Events.Event_DestroyObject, ObjIndex)
  1028.   End If
  1029. End With
  1030. End Sub
  1031. Public Sub SetObjectMapPosition(ObjIndex)
  1032. With Objects(ObjIndex)
  1033.   .MapPosition.X = Map.ProjectToMapX(.Position.X)
  1034.   .MapPosition.Y = Map.ProjectToMapY(.Position.Y)
  1035. End With
  1036. End Sub
  1037. Public Sub MoveObject(ObjIndex, Yaw, Speed)
  1038. Dim TempPos As Point3D
  1039. TempPos = Math.GetPropelCoordinates(Objects(ObjIndex).Position, Yaw, 0, Speed)
  1040. With Objects(ObjIndex)
  1041.   If CheckIfIllegalObjectPosition3D(TempPos) = False Then
  1042.     SetPosition = True
  1043.     If CheckObject(ObjIndex, OBJCHECK_OCCUPIESMAPSPACE) = True Then
  1044.       Call SetGroundUnOccupiedByObject(ObjIndex)
  1045.       MapX = Map.ProjectToMapX(TempPos.X)
  1046.       MapY = Map.ProjectToMapY(TempPos.Y)
  1047.       Size = ObjModels(Objects(ObjIndex).ModelIndex).Attributes(ATTRIBUTE_SIZE)
  1048.       If Map.GetGroundOccupied(MapX, MapY, Size) = False Then
  1049.         If ObjModels(.ModelIndex).BehaviorType = BEHAVIORMODE_TANK Then
  1050.           If GroundBlocks(MapX, MapY).Height - .Position.Z > ObjModels(.ModelIndex).Attributes(ATTRIBUTE_LENGTHZ) Then
  1051.             .ObjectTags(TAG_BLOCKED) = True
  1052.             'Call ObjectCommand_AvoidCollision(ObjIndex, TempPos.X, TempPos.Y)
  1053.             SetPosition = False
  1054.           End If
  1055.           If GroundBlocks(MapX, MapY).TerrainType = TERRAINTYPE_WATER Then
  1056.             .ObjectTags(TAG_BLOCKED) = True
  1057.             'Call ObjectCommand_AvoidCollision(ObjIndex, TempPos.X, TempPos.Y)
  1058.             SetPosition = False
  1059.           End If
  1060.         End If
  1061.       Else
  1062.         Call DetermineMoveFromCollide(ObjIndex, GroundBlocks(MapX, MapY).OccupyingObject)
  1063.         SetPosition = False
  1064.       End If
  1065.     End If
  1066.     If SetPosition = True Then
  1067.       TempPos.Z = .Position.Z
  1068.       If .Position.Z < GroundBlocks(MapX, MapY).Height Then
  1069.         'Goes up
  1070.         If ObjModels(.ModelIndex).Abilities(ABILITY_ISPHYSICAL) = True Then
  1071.           If ((GroundBlocks(MapX, MapY).Height - .Position.Z) / ObjModels(.ModelIndex).Attributes(ATTRIBUTE_WEIGHT)) > 2 Then
  1072.             .InertiaSpeedUp = .InertiaSpeedUp + (((GroundBlocks(MapX, MapY).Height - .Position.Z) * (.CurrentSpeed / 2)) / ObjModels(.ModelIndex).Attributes(ATTRIBUTE_WEIGHT))
  1073.           End If
  1074.         End If
  1075.         TempPos.Z = GroundBlocks(MapX, MapY).Height
  1076.       End If
  1077.       .Position = TempPos
  1078.       Call SetObjectMapPosition(ObjIndex)
  1079.     End If
  1080.     If CheckObject(ObjIndex, OBJCHECK_OCCUPIESMAPSPACE) = True Then Call SetGroundOccupiedByObject(ObjIndex)
  1081.   End If
  1082. End With
  1083. End Sub
  1084. Public Sub DetermineMoveFromCollide(ObjIndex, CollidedWithObject)
  1085. With Objects(ObjIndex)
  1086.   If ObjModels(Objects(CollidedWithObject).ModelIndex).Abilities(ABILITY_MOVES) = True Then
  1087.     If ObjModels(.ModelIndex).Attributes(ATTRIBUTE_IMPORTANCE) >= ObjModels(Objects(CollidedWithObject).ModelIndex).Attributes(ATTRIBUTE_IMPORTANCE) Then
  1088.       If Objects(CollidedWithObject).States(STATE_MOVING) = False Then
  1089.         If GroundBlocks(.MapPosition.X - 1, .MapPosition.Y - 1).Occupied = True Then
  1090.           IsBoxedInAmount = IsBoxedInAmount + 1
  1091.         End If
  1092.         If GroundBlocks(.MapPosition.X, .MapPosition.Y - 1).Occupied = True Then
  1093.           IsBoxedInAmount = IsBoxedInAmount + 1
  1094.         End If
  1095.         If GroundBlocks(.MapPosition.X + 1, .MapPosition.Y - 1).Occupied = True Then
  1096.           IsBoxedInAmount = IsBoxedInAmount + 1
  1097.         End If
  1098.         If GroundBlocks(.MapPosition.X + 1, .MapPosition.Y).Occupied = True Then
  1099.           IsBoxedInAmount = IsBoxedInAmount + 1
  1100.         End If
  1101.         If GroundBlocks(.MapPosition.X + 1, .MapPosition.Y + 1).Occupied = True Then
  1102.           IsBoxedInAmount = IsBoxedInAmount + 1
  1103.         End If
  1104.         If GroundBlocks(.MapPosition.X, .MapPosition.Y + 1).Occupied = True Then
  1105.           IsBoxedInAmount = IsBoxedInAmount + 1
  1106.         End If
  1107.         If GroundBlocks(.MapPosition.X - 1, .MapPosition.Y + 1).Occupied = True Then
  1108.           IsBoxedInAmount = IsBoxedInAmount + 1
  1109.         End If
  1110.         If GroundBlocks(.MapPosition.X - 1, .MapPosition.Y).Occupied = True Then
  1111.           IsBoxedInAmount = IsBoxedInAmount + 1
  1112.         End If
  1113.         If IsBoxedInAmount > 4 Then
  1114.           Call Entities.ObjectCommand_GetOutOfTheWay(CollidedWithObject, ObjIndex, 50)
  1115.           Call Entities.ObjectCommand_SitStillForTime(ObjIndex, 20)
  1116.         Else
  1117.           Call ObjectCommand_AvoidCollision(ObjIndex, Objects(CollidedWithObject).Position.X, Objects(CollidedWithObject).Position.Y)
  1118.         End If
  1119.       Else
  1120.         Call ObjectCommand_AvoidCollision(ObjIndex, Objects(CollidedWithObject).Position.X, Objects(CollidedWithObject).Position.Y)
  1121.       End If
  1122.     Else
  1123.       Call ObjectCommand_AvoidCollision(ObjIndex, Objects(CollidedWithObject).Position.X, Objects(CollidedWithObject).Position.Y)
  1124.     End If
  1125.   Else
  1126.     Call ObjectCommand_AvoidCollision(ObjIndex, Objects(CollidedWithObject).Position.X, Objects(CollidedWithObject).Position.Y)
  1127.   End If
  1128. End With
  1129. End Sub
  1130. Public Function CheckIfIllegalObjectPosition3D(Position As Point3D) As Boolean
  1131. If Position.X < 0 Then CheckIfIllegalObjectPosition3D = True: Exit Function
  1132. If Position.Y < 0 Then CheckIfIllegalObjectPosition3D = True: Exit Function
  1133. If Position.X > Map.BattleMap.RealWidth Then CheckIfIllegalObjectPosition3D = True: Exit Function
  1134. If Position.Y > Map.BattleMap.RealHeight Then CheckIfIllegalObjectPosition3D = True: Exit Function
  1135. End Function
  1136. Public Function GetMapImprintNum(Imprint$)
  1137. For I = 1 To MAXIMPRINTS
  1138.   If MapImprints(I).ImprintName = Imprint$ Then
  1139.     GetMapImprintNum = I
  1140.     Exit For
  1141.   End If
  1142. Next I
  1143. End Function
  1144. Public Sub ChangeObjectDestination(ObjIndex, NewX, NewY, NewZ)
  1145. Dim EmptyBlock As Point3D
  1146. If NewX < 0 Then NewX = 0
  1147. If NewY < 0 Then NewY = 0
  1148. If CheckObject(ObjIndex, OBJCHECK_OCCUPIESMAPSPACE) = True Then
  1149.   EmptyBlock = Map.GetNearestEmptyBlock(NewX, NewY, TERRAINTYPE_WATER, True)
  1150. Else
  1151.   EmptyBlock.X = NewX
  1152.   EmptyBlock.Y = NewY
  1153. End If
  1154. With Objects(ObjIndex)
  1155.   .Objective.MainDestination.X = EmptyBlock.X
  1156.   .Objective.MainDestination.Y = EmptyBlock.Y
  1157.   .Objective.MainDestination.Z = NewZ
  1158.   .Objective.CurrentDestination = .Objective.MainDestination
  1159. End With
  1160. End Sub
  1161. Public Sub ChangeObjectCurrentDestination(ObjIndex, NewX, NewY, NewZ)
  1162. Dim EmptyBlock As Point3D
  1163. If NewX < 0 Then NewX = 0
  1164. If NewY < 0 Then NewY = 0
  1165. If CheckObject(ObjIndex, OBJCHECK_OCCUPIESMAPSPACE) = True Then
  1166.   EmptyBlock = Map.GetNearestEmptyBlock(NewX, NewY, TERRAINTYPE_WATER, True)
  1167. Else
  1168.   EmptyBlock.X = NewX
  1169.   EmptyBlock.Y = NewY
  1170. End If
  1171. With Objects(ObjIndex).Objective.CurrentDestination
  1172.   .X = EmptyBlock.X
  1173.   .Y = EmptyBlock.Y
  1174.   .Z = NewZ
  1175. End With
  1176. Call SetObjectDirection(ObjIndex, Map.UnProjectToMap3DPoint(Objects(ObjIndex).Objective.CurrentDestination))
  1177. End Sub
  1178.  
  1179. Sub SetObjectDirection(ObjIndex, ObjDest As Point3D)
  1180. With Objects(ObjIndex)
  1181.   .Vector.Yaw = Math.GetYawFromXY(.Position.X, .Position.Y, ObjDest.X, ObjDest.Y)
  1182.   Call Math.CheckVector(.Vector)
  1183.   .Vector.ZIncline = 0
  1184.   Call SetDisplayDirection(ObjIndex)
  1185. End With
  1186. End Sub
  1187. Sub SteerInertialDirection(ObjIndex, DestYaw, TurnSpeed)
  1188. If TurnSpeed < 22 Then
  1189.   Speed = TurnSpeed
  1190. Else
  1191.   Speed = 11
  1192. End If
  1193. With Objects(ObjIndex)
  1194.     If .InertiaDirection.Yaw - 3 < DestYaw Then
  1195.       If .InertiaDirection.Yaw + 3 > DestYaw Then
  1196.         .InertiaDirection.Yaw = DestYaw
  1197.         Exit Sub
  1198.       End If
  1199.     End If
  1200.     If DestYaw > .Vector.Yaw Then
  1201.       If DestYaw - .Vector.Yaw < 180 Then
  1202.         .InertiaDirection.Yaw = .InertiaDirection.Yaw + Speed
  1203.       Else
  1204.         .InertiaDirection.Yaw = .InertiaDirection.Yaw - Speed
  1205.       End If
  1206.     Else
  1207.       If .InertiaDirection.Yaw - DestYaw < 180 Then
  1208.         .InertiaDirection.Yaw = .InertiaDirection.Yaw - Speed
  1209.       Else
  1210.         .InertiaDirection.Yaw = .InertiaDirection.Yaw + Speed
  1211.       End If
  1212.     End If
  1213.     If .InertiaDirection.Yaw + (Speed + 4) > DestYaw Then
  1214.       If .InertiaDirection.Yaw - (Speed + 4) < DestYaw Then
  1215.         .InertiaDirection.Yaw = DestYaw
  1216.       End If
  1217.     End If
  1218.     Call Math.CheckVector(.InertiaDirection)
  1219. End With
  1220. End Sub
  1221. Function SteerObjectDirection(ObjIndex, ObjDest As Point3D, ObjTurnSpeed) As Boolean
  1222. With Objects(ObjIndex)
  1223.     TurnSpeed = ObjTurnSpeed
  1224.     If .Position.Z > GroundBlocks(.MapPosition.X, .MapPosition.Y).Height Then
  1225.       If ObjModels(.ModelIndex).Abilities(ABILITY_REQUIRESTRACTION) = True Then
  1226.         TurnSpeed = ObjTurnSpeed / 4
  1227.       End If
  1228.     End If
  1229.     DestYaw = Math.GetYawFromXY(.Position.X, .Position.Y, ObjDest.X, ObjDest.Y)
  1230.     If .Vector.Yaw - 3 < DestYaw Then
  1231.       If .Vector.Yaw + 3 > DestYaw Then
  1232.         .Vector.Yaw = DestYaw
  1233.         SteerObjectDirection = True
  1234.         Exit Function
  1235.       End If
  1236.     End If
  1237.     If DestYaw > .Vector.Yaw Then
  1238.       If DestYaw - .Vector.Yaw < 180 Then
  1239.         .Vector.Yaw = .Vector.Yaw + TurnSpeed
  1240.       Else
  1241.         .Vector.Yaw = .Vector.Yaw - TurnSpeed
  1242.       End If
  1243.     Else
  1244.       If .Vector.Yaw - DestYaw < 180 Then
  1245.         .Vector.Yaw = .Vector.Yaw - TurnSpeed
  1246.       Else
  1247.         .Vector.Yaw = .Vector.Yaw + TurnSpeed
  1248.       End If
  1249.     End If
  1250.     If .Vector.Yaw + (TurnSpeed + 2) > DestYaw Then
  1251.       If .Vector.Yaw - (TurnSpeed + 2) < DestYaw Then
  1252.         .Vector.Yaw = DestYaw
  1253.         SteerObjectDirection = True
  1254.       End If
  1255.     End If
  1256.     Call Math.CheckVector(.Vector)
  1257.     .Vector.ZIncline = 0
  1258.     Call SetDisplayDirection(ObjIndex)
  1259. End With
  1260. End Function
  1261. Function SteerTurretDirection(ObjIndex, ObjDest As Point3D) As Boolean
  1262. Dim TempVector As Vect3D
  1263. With Objects(ObjIndex)
  1264.     DestYaw = Math.GetYawFromXY(.Position.X, .Position.Y, ObjDest.X, ObjDest.Y)
  1265.     If .TopDirection - 6 < DestYaw Then
  1266.       If .TopDirection + 6 > DestYaw Then
  1267.         .TopDirection = DestYaw
  1268.         SteerTurretDirection = True
  1269.         Exit Function
  1270.       End If
  1271.     End If
  1272.     If DestYaw > .TopDirection Then
  1273.       If DestYaw - .TopDirection < 180 Then
  1274.         .TopDirection = .TopDirection + 6
  1275.       Else
  1276.         .TopDirection = .TopDirection - 6
  1277.       End If
  1278.     Else
  1279.       If .TopDirection - DestYaw < 180 Then
  1280.         .TopDirection = .TopDirection - 6
  1281.       Else
  1282.         .TopDirection = .TopDirection + 6
  1283.       End If
  1284.     End If
  1285.     If .TopDirection + 8 > DestYaw Then
  1286.       If .TopDirection - 8 < DestYaw Then
  1287.         .TopDirection = DestYaw
  1288.         SteerTurretDirection = True
  1289.       End If
  1290.     End If
  1291.     TempVector.Yaw = .TopDirection
  1292.     Call Math.CheckVector(TempVector)
  1293.     .TopDirection = TempVector.Yaw
  1294.     Call SetDisplayDirection(ObjIndex)
  1295. End With
  1296. End Function
  1297. Sub SetDisplayDirection(ObjIndex)
  1298. With Objects(ObjIndex)
  1299.   If ObjModels(.ModelIndex).Attributes(ATTRIBUTE_DIRECTIONAMOUNT) <> 1 Then
  1300.     .DisplayDirection = Int((.Vector.Yaw + ObjModels(.ModelIndex).Consts(CONST_DIRECTIONDIVDIV)) / ObjModels(.ModelIndex).Consts(CONST_DIRECTIONDIV))
  1301.     If .DisplayDirection = ObjModels(.ModelIndex).Attributes(ATTRIBUTE_DIRECTIONAMOUNT) Then .DisplayDirection = 0
  1302.   Else
  1303.     .DisplayDirection = 0
  1304.   End If
  1305.   If ObjModels(.ModelIndex).Attributes(ATTRIBUTE_TOPDIRECTIONAMOUNT) <> 1 Then
  1306.     If ObjModels(.ModelIndex).Abilities(ABILITY_BODYISBISECTED) = True Then
  1307.       .TopDisplayDirection = Int((.TopDirection + ObjModels(.ModelIndex).Consts(CONST_TOPDIRECTIONDIVDIV)) / ObjModels(.ModelIndex).Consts(CONST_TOPDIRECTIONDIV))
  1308.       If .TopDisplayDirection = ObjModels(.ModelIndex).Attributes(ATTRIBUTE_TOPDIRECTIONAMOUNT) Then .TopDisplayDirection = 0
  1309.     End If
  1310.   Else
  1311.     .TopDisplayDirection = 0
  1312.   End If
  1313. End With
  1314. End Sub
  1315. Public Function SpawnObject(ClassNum, Side, X, Y, Z, Yaw, ZIncline) As Integer
  1316. If ObjModels(ClassNum).Abilities(ABILITY_ISPHYSICAL) = True Then
  1317.   If GroundBlocks(X, Y).Occupied = True Then
  1318.     GoTo DontSpawn
  1319.   End If
  1320. End If
  1321. If ObjModels(ClassNum).Attributes(ATTRIBUTE_MAPIMPRINT) <> NOMAPIMPRINT Then
  1322.   If Map.IsImprintSpaceNonGrass(X, Y, ObjModels(ClassNum).Attributes(ATTRIBUTE_MAPIMPRINT)) = True Then
  1323.     GoTo DontSpawn
  1324.   End If
  1325.   If Map.IsImprintSpaceOccupied(X, Y, ObjModels(ClassNum).Attributes(ATTRIBUTE_MAPIMPRINT)) = True Then
  1326.     GoTo DontSpawn
  1327.   End If
  1328. End If
  1329. For I = 1 To MAXOBJECTS
  1330.   If Objects(I).Active = False Then
  1331.     NewObject = I
  1332.     Exit For
  1333.   End If
  1334. Next I
  1335. If ObjectsActive < NewObject Then ObjectsActive = NewObject
  1336.  
  1337. With Objects(NewObject)
  1338.     'Clears all it's properties so it doesn't do something wacky!
  1339.     For I = 1 To MAXOBJECTPROPERTIES
  1340.       .Properties(I) = 0
  1341.     Next I
  1342.     
  1343.     'Initializes the object
  1344.     .Frozen = False
  1345.     .Active = True
  1346.     .Side = Side
  1347.     .ModelIndex = ClassNum
  1348.     .CurrentSpeed = 0
  1349.     .Position.X = Map.UnProjectToMapX(X)
  1350.     .Position.Y = Map.UnProjectToMapY(Y)
  1351.     .Position.Z = Z
  1352.     .Objective.MainDestination = Map.ProjectToMap3DPoint(.Position)
  1353.     .Objective.MainDestination.Z = Z
  1354.     .Objective.CurrentDestination = .Objective.MainDestination
  1355.     .DisplayDirection = 0
  1356.     .Vector.Yaw = Yaw
  1357.     .Vector.ZIncline = ZIncline
  1358.     .Objective.Goal = GOAL_NOTHING
  1359.     .States(STATE_MOVING) = False
  1360.     .Sprite.SpriteNumber = ObjModels(ClassNum).Attributes(ATTRIBUTE_SPRITE)
  1361.     .Sprite.SpriteFrameNumber = 1
  1362.     .Sprite.SpriteGroupNumber = 1
  1363.     
  1364.     .TopSprite.SpriteNumber = ObjModels(ClassNum).Attributes(ATTRIBUTE_TOPSPRITE)
  1365.     .TopSprite.SpriteFrameNumber = 1
  1366.     .TopSprite.SpriteGroupNumber = 1
  1367.     .TopDirection = .Vector.Yaw
  1368.     .DisplayDirection = .DisplayDirection
  1369.     
  1370.     .Properties(PROPERTY_TIMEUNTILADJUSTDIRECTION) = OBJCONST_TimeTillAdjustDirection
  1371.     .Properties(PROPERTY_WEAPONOBJECTTYPE) = ObjModels(ClassNum).Attributes(ATTRIBUTE_DEFAULTWEAPONOBJECT)
  1372.     .Properties(PROPERTY_HEALTH) = ObjModels(ClassNum).Attributes(ATTRIBUTE_HEALTH)
  1373.     
  1374.     If ObjModels(ClassNum).Abilities(ABILITY_HASDNA) = True Then Call Assign_DNA(NewObject)
  1375.     
  1376.     Call SetObjectMapPosition(NewObject)
  1377.     If ObjModels(.ModelIndex).BehaviorType = BEHAVIORMODE_TANK Then
  1378.       Dim TempPos As Point3D
  1379.       For I = 1 To 10
  1380.         SparkDirection = Int(360 * Rnd)
  1381.         TempPos = Math.GetPropelCoordinates(.Position, SparkDirection, 0, 7 + (5 * Rnd))
  1382.         Call SpawnSpark(TempPos.X, TempPos.Y, .Position.Z, PALLETE_BLUE, SparkDirection, 2, 10, 7, 1)
  1383.       Next I
  1384.       Call ObjectCommand_MoveSomewhere(NewObject, .MapPosition.X, .MapPosition.Y)
  1385.     End If
  1386.     If CheckObject(NewObject, OBJCHECK_OCCUPIESMAPSPACE) = True Then Call SetGroundOccupiedByObject(NewObject)
  1387.     'returns the handle of the object
  1388.     If ObjModels(ClassNum).Abilities(ABILITY_BUILDS) = True Then
  1389.       Call BuildObjectsChanged(Side)
  1390.     End If
  1391. End With
  1392. If ObjModels(ClassNum).Attributes(ATTRIBUTE_MAPIMPRINT) <> NOMAPIMPRINT Then
  1393.   Call Map.PlaceMapImprint(ObjModels(ClassNum).Attributes(ATTRIBUTE_MAPIMPRINT), X, Y, NewObject)
  1394. End If
  1395. Call Object_PlaySound(NewObject, SoundEvent_Spawn)
  1396. SpawnObject = NewObject
  1397. Exit Function
  1398. DontSpawn:
  1399.   SpawnObject = NOOBJECT
  1400. End Function
  1401. Public Sub LoadObjectData()
  1402. Dim MaxMods As Integer, a$, propvalue$, I As Integer, DeployObjectList(MaxObjModels) As String, WepObjs(MaxObjModels) As String
  1403. On Error Resume Next
  1404. MaxMods = 0
  1405. Call FileFunctions.OpenGameFile(File_UnitDefinitions, 1)
  1406. Do
  1407.   Line Input #1, a$
  1408.   Select Case MiscFunctions.GetPropertyName(a$)
  1409.   Case FILETAG_ENDFILE
  1410.     Exit Do
  1411.   Case "[OBJECTDEFSTART]"
  1412.     MaxMods = MaxMods + 1
  1413.     Line Input #1, a$
  1414.     ObjModels(MaxMods).ObjClassName = MiscFunctions.GetPropertyValue(a$)
  1415.  
  1416.     Line Input #1, a$
  1417.     ObjModels(MaxMods).ObjName = MiscFunctions.GetPropertyValue(a$)
  1418.     Line Input #1, a$
  1419.     Select Case MiscFunctions.GetPropertyValue(a$)
  1420.     Case "-NONE-"
  1421.       BehavType = BEHAVIORMODE_NONE
  1422.     Case "BEHAVIORMODE_INANIMATE"
  1423.       BehavType = BEHAVIORMODE_INANIMATE
  1424.     Case "BEHAVIORMODE_BUILDING"
  1425.       BehavType = BEHAVIORMODE_BUILDING
  1426.     Case "BEHAVIORMODE_SOLDIER"
  1427.       BehavType = BEHAVIORMODE_SOLDIER
  1428.     Case "BEHAVIORMODE_SHIP"
  1429.       BehavType = BEHAVIORMODE_SHIP
  1430.     Case "BEHAVIORMODE_TANK"
  1431.       BehavType = BEHAVIORMODE_TANK
  1432.     Case "BEHAVIORMODE_AIRCRAFT"
  1433.       BehavType = BEHAVIORMODE_AIRCRAFT
  1434.     Case "BEHAVIORMODE_SPACECRAFT"
  1435.       BehavType = BEHAVIORMODE_SPACECRAFT
  1436.     Case "BEHAVIORMODE_WEAPON"
  1437.       BehavType = BEHAVIORMODE_WEAPON
  1438.     End Select
  1439.     ObjModels(MaxMods).BehaviorType = BehavType
  1440.     
  1441.     For I = 1 To MAXABILITIES
  1442.       Line Input #1, a$
  1443.       a$ = MiscFunctions.GetPropertyValue(a$)
  1444.       ObjModels(MaxMods).Abilities(I) = MiscFunctions.ConvertTrueFalse(a$)
  1445.     Next I
  1446.     
  1447.     
  1448.     Line Input #1, a$
  1449.     a$ = MiscFunctions.GetPropertyValue(a$)
  1450.     ObjModels(MaxMods).Attributes(ATTRIBUTE_SPRITE) = SpriteStuff.GetSpriteIndex(a$)
  1451.     
  1452.     Line Input #1, a$
  1453.     a$ = MiscFunctions.GetPropertyValue(a$)
  1454.     ObjModels(MaxMods).Attributes(ATTRIBUTE_SIZE) = Val(a$)
  1455.     
  1456.     Line Input #1, a$
  1457.     a$ = MiscFunctions.GetPropertyValue(a$)
  1458.     ObjModels(MaxMods).Attributes(ATTRIBUTE_LENGTHX) = Val(a$)
  1459.  
  1460.     Line Input #1, a$
  1461.     a$ = MiscFunctions.GetPropertyValue(a$)
  1462.     ObjModels(MaxMods).Attributes(ATTRIBUTE_LENGTHY) = Val(a$)
  1463.     
  1464.     Line Input #1, a$
  1465.     a$ = MiscFunctions.GetPropertyValue(a$)
  1466.     ObjModels(MaxMods).Attributes(ATTRIBUTE_LENGTHZ) = Val(a$)
  1467.  
  1468.     Line Input #1, a$
  1469.     a$ = MiscFunctions.GetPropertyValue(a$)
  1470.     ObjModels(MaxMods).Attributes(ATTRIBUTE_MAXSPEED) = Val(a$)
  1471.     
  1472.     Line Input #1, a$
  1473.     a$ = MiscFunctions.GetPropertyValue(a$)
  1474.     ObjModels(MaxMods).Attributes(ATTRIBUTE_BULLETARMOR) = Val(a$)
  1475.     
  1476.     Line Input #1, a$
  1477.     a$ = MiscFunctions.GetPropertyValue(a$)
  1478.     ObjModels(MaxMods).Attributes(ATTRIBUTE_SHELLARMOR) = Val(a$)
  1479.     
  1480.     Line Input #1, a$
  1481.     a$ = MiscFunctions.GetPropertyValue(a$)
  1482.     ObjModels(MaxMods).Attributes(ATTRIBUTE_BOMBARMOR) = Val(a$)
  1483.  
  1484.     Line Input #1, a$
  1485.     a$ = MiscFunctions.GetPropertyValue(a$)
  1486.     ObjModels(MaxMods).Attributes(ATTRIBUTE_FIREARMOR) = Val(a$)
  1487.  
  1488.     Line Input #1, a$
  1489.     a$ = MiscFunctions.GetPropertyValue(a$)
  1490.     ObjModels(MaxMods).Attributes(ATTRIBUTE_ELECTROMAGNETICARMOR) = Val(a$)
  1491.  
  1492.     Line Input #1, a$
  1493.     a$ = MiscFunctions.GetPropertyValue(a$)
  1494.     ObjModels(MaxMods).Attributes(ATTRIBUTE_RADIATIONARMOR) = Val(a$)
  1495.  
  1496.     Line Input #1, a$
  1497.     a$ = MiscFunctions.GetPropertyValue(a$)
  1498.     ObjModels(MaxMods).Attributes(ATTRIBUTE_MAXAMMO) = Val(a$)
  1499.  
  1500.     Line Input #1, a$
  1501.    
  1502.     Select Case MiscFunctions.GetPropertyValue(a$)
  1503.     Case "EXPLODETYPE_BULLET"
  1504.       ExplodeType = EXPLODETYPE_BULLET
  1505.     Case "EXPLODETYPE_SHELL"
  1506.       ExplodeType = EXPLODETYPE_SHELL
  1507.     Case "EXPLODETYPE_BOMB"
  1508.       ExplodeType = EXPLODETYPE_BOMB
  1509.     Case "EXPLODETYPE_FIRE"
  1510.       ExplodeType = EXPLODETYPE_FIRE
  1511.     Case "EXPLODETYPE_ELECTROMAGNETIC"
  1512.       ExplodeType = EXPLODETYPE_ELECTROMAGNETIC
  1513.     Case "EXPLODETYPE_RADIATION"
  1514.       ExplodeType = EXPLODETYPE_RADIATION
  1515.     End Select
  1516.     ObjModels(MaxMods).Attributes(ATTRIBUTE_EXPLOSIONTYPE) = ExplodeType
  1517.     
  1518.     Line Input #1, a$
  1519.     a$ = MiscFunctions.GetPropertyValue(a$)
  1520.     ObjModels(MaxMods).Attributes(ATTRIBUTE_EXPLOSIONINTENSITY) = Val(a$)
  1521.  
  1522.     Line Input #1, a$
  1523.     a$ = MiscFunctions.GetPropertyValue(a$)
  1524.     ObjModels(MaxMods).Attributes(ATTRIBUTE_EXPLOSIONRADIUS) = Val(a$)
  1525.     
  1526.     Line Input #1, a$
  1527.     a$ = MiscFunctions.GetPropertyValue(a$)
  1528.     If a$ = "-Nothing-" Then
  1529.       ObjModels(MaxMods).Attributes(ATTRIBUTE_EXPLOSIONSPRITE) = NOSPRITE
  1530.     Else
  1531.       ObjModels(MaxMods).Attributes(ATTRIBUTE_EXPLOSIONSPRITE) = SpriteStuff.GetSpriteIndex(a$)
  1532.     End If
  1533.     
  1534.     Line Input #1, a$
  1535.     a$ = MiscFunctions.GetPropertyValue(a$)
  1536.     ObjModels(MaxMods).Attributes(ATTRIBUTE_POWERREQUIRED) = Val(a$)
  1537.  
  1538.     Line Input #1, a$
  1539.     Select Case MiscFunctions.GetPropertyValue(a$)
  1540.     Case "-NONE-"
  1541.       BehavType = BEHAVIORMODE_NONE
  1542.     Case "BEHAVIORMODE_INANIMATE"
  1543.       BehavType = BEHAVIORMODE_INANIMATE
  1544.     Case "BEHAVIORMODE_BUILDING"
  1545.       BehavType = BEHAVIORMODE_BUILDING
  1546.     Case "BEHAVIORMODE_SOLDIER"
  1547.       BehavType = BEHAVIORMODE_SOLDIER
  1548.     Case "BEHAVIORMODE_SHIP"
  1549.       BehavType = BEHAVIORMODE_SHIP
  1550.     Case "BEHAVIORMODE_TANK"
  1551.       BehavType = BEHAVIORMODE_TANK
  1552.     Case "BEHAVIORMODE_AIRCRAFT"
  1553.       BehavType = BEHAVIORMODE_AIRCRAFT
  1554.     Case "BEHAVIORMODE_SPACECRAFT"
  1555.       BehavType = BEHAVIORMODE_SPACECRAFT
  1556.     Case "BEHAVIORMODE_WEAPON"
  1557.       BehavType = BEHAVIORMODE_WEAPON
  1558.     End Select
  1559.     
  1560.     ObjModels(MaxMods).Attributes(ATTRIBUTE_OBJECTBUILDTYPE) = BehavType
  1561.     
  1562.     Line Input #1, a$
  1563.     a$ = MiscFunctions.GetPropertyValue(a$)
  1564.     ObjModels(MaxMods).Attributes(ATTRIBUTE_COST) = Val(a$)
  1565.  
  1566.     Line Input #1, a$
  1567.     a$ = MiscFunctions.GetPropertyValue(a$)
  1568.     ObjModels(MaxMods).Attributes(ATTRIBUTE_HEALTH) = Val(a$)
  1569.  
  1570.     Line Input #1, a$
  1571.     a$ = MiscFunctions.GetPropertyValue(a$)
  1572.     ObjModels(MaxMods).Attributes(ATTRIBUTE_WEIGHT) = Val(a$)
  1573.  
  1574.     Line Input #1, a$
  1575.     a$ = MiscFunctions.GetPropertyValue(a$)
  1576.     ObjModels(MaxMods).Attributes(ATTRIBUTE_ACCURACY) = Val(a$)
  1577.  
  1578.     Line Input #1, a$
  1579.     a$ = MiscFunctions.GetPropertyValue(a$)
  1580.     ObjModels(MaxMods).Attributes(ATTRIBUTE_STRENGTH) = Val(a$)
  1581.  
  1582.     Line Input #1, a$
  1583.     a$ = MiscFunctions.GetPropertyValue(a$)
  1584.     ObjModels(MaxMods).Attributes(ATTRIBUTE_SHOOTRADIUS) = Val(a$)
  1585.  
  1586.     Line Input #1, a$
  1587.     a$ = MiscFunctions.GetPropertyValue(a$)
  1588.     ObjModels(MaxMods).Attributes(ATTRIBUTE_MINIMUMSHOOTRADIUS) = Val(a$)
  1589.  
  1590.     Line Input #1, a$
  1591.     a$ = MiscFunctions.GetPropertyValue(a$)
  1592.     ObjModels(MaxMods).Attributes(ATTRIBUTE_DIRECTIONAMOUNT) = Val(a$)
  1593.     ObjModels(MaxMods).Consts(CONST_DIRECTIONDIV) = (360 / ObjModels(MaxMods).Attributes(ATTRIBUTE_DIRECTIONAMOUNT))
  1594.     ObjModels(MaxMods).Consts(CONST_DIRECTIONDIVDIV) = ObjModels(MaxMods).Consts(CONST_DIRECTIONDIV) / 2
  1595.     Line Input #1, a$
  1596.     a$ = MiscFunctions.GetPropertyValue(a$)
  1597.     ObjModels(MaxMods).Attributes(ATTRIBUTE_SIGHTRADIUS) = Val(a$)
  1598.  
  1599.     Line Input #1, a$
  1600.     a$ = MiscFunctions.GetPropertyValue(a$)
  1601.     If a$ <> "" Then
  1602.       ObjModels(MaxMods).Attributes(ATTRIBUTE_SOUNDGROUP) = True
  1603.       Call LoadSoundsToUnitModel(MaxMods, a$)
  1604.     Else
  1605.       ObjModels(MaxMods).Attributes(ATTRIBUTE_SOUNDGROUP) = False
  1606.     End If
  1607.  
  1608.     Line Input #1, a$
  1609.     Select Case MiscFunctions.GetPropertyValue(a$)
  1610.     Case "EDF"
  1611.       SideNum = FACTION_EDF
  1612.     End Select
  1613.     ObjModels(MaxMods).Attributes(ATTRIBUTE_SIDE) = SideNum
  1614.     
  1615.  
  1616.     Line Input #1, a$
  1617.     a$ = MiscFunctions.GetPropertyValue(a$)
  1618.     ObjModels(MaxMods).Attributes(ATTRIBUTE_GETTABLEPOWERUPTYPE) = Val(a$)
  1619.  
  1620.     Line Input #1, a$
  1621.     a$ = MiscFunctions.GetPropertyValue(a$)
  1622.     ObjModels(MaxMods).Attributes(ATTRIBUTE_MAPIMPRINT) = Entities.GetMapImprintNum(a$)
  1623.   
  1624.     Line Input #1, a$
  1625.     a$ = MiscFunctions.GetPropertyValue(a$)
  1626.     ObjModels(MaxMods).Attributes(ATTRIBUTE_SPRITEPOSITIONX) = Val(a$)
  1627.  
  1628.     Line Input #1, a$
  1629.     a$ = MiscFunctions.GetPropertyValue(a$)
  1630.     ObjModels(MaxMods).Attributes(ATTRIBUTE_SPRITEPOSITIONY) = Val(a$)
  1631.   
  1632.     Line Input #1, a$
  1633.     a$ = MiscFunctions.GetPropertyValue(a$)
  1634.     ObjModels(MaxMods).Attributes(ATTRIBUTE_COMBUSTIONTEMPERATURE) = Val(a$)
  1635.     
  1636.     Line Input #1, a$
  1637.     a$ = MiscFunctions.GetPropertyValue(a$)
  1638.     DeployObjectList(MaxMods) = a$
  1639.     
  1640.     Line Input #1, a$
  1641.     a$ = MiscFunctions.GetPropertyValue(a$)
  1642.     ObjModels(MaxMods).Attributes(ATTRIBUTE_TECHLEVEL) = Val(a$)
  1643.     
  1644.     Line Input #1, a$
  1645.     a$ = MiscFunctions.GetPropertyValue(a$)
  1646.     ObjModels(MaxMods).Attributes(ATTRIBUTE_BUILDPICTURE) = SpriteStuff.GetPicIndex(a$)
  1647.  
  1648.     Line Input #1, a$
  1649.     a$ = MiscFunctions.GetPropertyValue(a$)
  1650.     ObjModels(MaxMods).Attributes(ATTRIBUTE_TOPSPRITE) = SpriteStuff.GetSpriteIndex(a$)
  1651.     
  1652.     Line Input #1, a$
  1653.     a$ = MiscFunctions.GetPropertyValue(a$)
  1654.     If a$ = "ATTRIBUTE_TOPDIRECTIONAMOUNT" Then a$ = "0"
  1655.     ObjModels(MaxMods).Attributes(ATTRIBUTE_TOPDIRECTIONAMOUNT) = Val(a$)
  1656.     If ObjModels(MaxMods).Abilities(ABILITY_BODYISBISECTED) = True Then
  1657.       ObjModels(MaxMods).Consts(CONST_TOPDIRECTIONDIV) = (360 / ObjModels(MaxMods).Attributes(ATTRIBUTE_TOPDIRECTIONAMOUNT))
  1658.       ObjModels(MaxMods).Consts(CONST_TOPDIRECTIONDIVDIV) = ObjModels(MaxMods).Consts(CONST_TOPDIRECTIONDIV) / 2
  1659.     End If
  1660.     
  1661.     Line Input #1, a$
  1662.     a$ = MiscFunctions.GetPropertyValue(a$)
  1663.     ObjModels(MaxMods).Attributes(ATTRIBUTE_TOPSPRITEPOSITIONX) = Val(a$)
  1664.     
  1665.     Line Input #1, a$
  1666.     a$ = MiscFunctions.GetPropertyValue(a$)
  1667.     ObjModels(MaxMods).Attributes(ATTRIBUTE_TOPSPRITEPOSITIONY) = Val(a$)
  1668.   
  1669.     Line Input #1, a$
  1670.     a$ = MiscFunctions.GetPropertyValue(a$)
  1671.     ObjModels(MaxMods).Attributes(ATTRIBUTE_BUILDATFRAME) = Val(a$)
  1672.     
  1673.     Line Input #1, a$
  1674.     a$ = MiscFunctions.GetPropertyValue(a$)
  1675.     ObjModels(MaxMods).Attributes(ATTRIBUTE_REQUIREDBEFOREBUILD) = Val(a$)
  1676.     If Val(a$) = 0 Then ObjModels(MaxMods).Attributes(ATTRIBUTE_REQUIREDBEFOREBUILD) = NOOBJECT
  1677.     
  1678.     Line Input #1, a$
  1679.     a$ = MiscFunctions.GetPropertyValue(a$)
  1680.     ObjModels(MaxMods).Attributes(ATTRIBUTE_IMPORTANCE) = Val(a$)
  1681.   
  1682.     Line Input #1, a$
  1683.     a$ = MiscFunctions.GetPropertyValue(a$)
  1684.     ObjModels(MaxMods).Attributes(ATTRIBUTE_ENGINEPOWER) = Val(a$)
  1685.     
  1686.     Line Input #1, a$
  1687.     a$ = MiscFunctions.GetPropertyValue(a$)
  1688.     ObjModels(MaxMods).Attributes(ATTRIBUTE_TURNSPEED) = Val(a$)
  1689.     
  1690.     Line Input #1, a$
  1691.     a$ = MiscFunctions.GetPropertyValue(a$)
  1692.     ObjModels(MaxMods).Attributes(ATTRIBUTE_SHADOWPIC) = SpriteStuff.GetPicIndex(a$)
  1693.   
  1694.     Line Input #1, a$
  1695.     a$ = MiscFunctions.GetPropertyValue(a$)
  1696.     ObjModels(MaxMods).Attributes(ATTRIBUTE_WEAPONX) = Val(a$)
  1697.     
  1698.     Line Input #1, a$
  1699.     a$ = MiscFunctions.GetPropertyValue(a$)
  1700.     ObjModels(MaxMods).Attributes(ATTRIBUTE_WEAPONY) = Val(a$)
  1701.     
  1702.     Line Input #1, a$
  1703.     a$ = MiscFunctions.GetPropertyValue(a$)
  1704.     WepObjs(MaxMods) = a$
  1705.   
  1706.     Line Input #1, a$
  1707.     a$ = MiscFunctions.GetPropertyValue(a$)
  1708.     ObjModels(MaxMods).Attributes(ATTRIBUTE_WEAPONCHARGETIME) = Val(a$)
  1709.   End Select
  1710. Loop
  1711. Close #1
  1712. MaxObjModTypes = MaxMods
  1713. For I = 1 To MaxObjModTypes
  1714.   ObjModels(I).Attributes(ATTRIBUTE_DEPLOYOBJECT) = Entities.GetClassNum(DeployObjectList(I))
  1715.   ObjModels(I).Attributes(ATTRIBUTE_DEFAULTWEAPONOBJECT) = Entities.GetClassNum(WepObjs(I))
  1716. Next I
  1717. End Sub
  1718. Public Sub LoadSoundsToUnitModel(ModelIndex, SoundBaseName)
  1719. SoundEventName = SoundEvent_Fire
  1720. SoundEventText = "Fire"
  1721. ObjModels(ModelIndex).SoundGroup.EventSounds(SoundEventName) = Sound.GetSoundIndex(SoundBaseName & "." & SoundEventText)
  1722. If ObjModels(ModelIndex).SoundGroup.EventSounds(SoundEventName) = 0 Then ObjModels(ModelIndex).SoundGroup.EventSounds(SoundEventName) = NOSOUND
  1723. SoundEventName = SoundEvent_Explode
  1724. SoundEventText = "Explode"
  1725. ObjModels(ModelIndex).SoundGroup.EventSounds(SoundEventName) = Sound.GetSoundIndex(SoundBaseName & "." & SoundEventText)
  1726. If ObjModels(ModelIndex).SoundGroup.EventSounds(SoundEventName) = 0 Then ObjModels(ModelIndex).SoundGroup.EventSounds(SoundEventName) = NOSOUND
  1727. SoundEventName = SoundEvent_Spawn
  1728. SoundEventText = "Spawn"
  1729. ObjModels(ModelIndex).SoundGroup.EventSounds(SoundEventName) = Sound.GetSoundIndex(SoundBaseName & "." & SoundEventText)
  1730. If ObjModels(ModelIndex).SoundGroup.EventSounds(SoundEventName) = 0 Then ObjModels(ModelIndex).SoundGroup.EventSounds(SoundEventName) = NOSOUND
  1731.  
  1732. SoundEventName = SoundEvent_BuildObject
  1733. SoundEventText = "BuildObject"
  1734. ObjModels(ModelIndex).SoundGroup.EventSounds(SoundEventName) = Sound.GetSoundIndex(SoundBaseName & "." & SoundEventText)
  1735. If ObjModels(ModelIndex).SoundGroup.EventSounds(SoundEventName) = 0 Then ObjModels(ModelIndex).SoundGroup.EventSounds(SoundEventName) = NOSOUND
  1736.  
  1737. End Sub
  1738. Public Function GetClassNum(ClassName$)
  1739. GetClassNum = -999
  1740. For I = 1 To MaxObjModTypes
  1741.   If ClassName$ = Entities.ObjModels(I).ObjClassName Then
  1742.     GetClassNum = I
  1743.     Exit For
  1744.   End If
  1745. Next I
  1746. End Function
  1747. Public Sub LoadMapImprints()
  1748. Call FileFunctions.OpenGameFile(File_ObjectImprints, 1)
  1749. imprintnum = 0
  1750. Do
  1751.   Line Input #1, a$
  1752.   Select Case a$
  1753.   Case FILETAG_ENDFILE
  1754.     Exit Do
  1755.   Case "[OBJIMPRINT]"
  1756.     
  1757.     imprintnum = imprintnum + 1
  1758.     Line Input #1, a$
  1759.     MapImprints(imprintnum).ImprintName = a$
  1760.     For X = 1 To IMPRINTSIZE
  1761.       For Y = 1 To IMPRINTSIZE
  1762.         Line Input #1, a$
  1763.         MapImprints(imprintnum).ImprintArray(X, Y) = Val(a$)
  1764.       Next Y
  1765.     Next X
  1766.   End Select
  1767. Loop
  1768. Close #1
  1769. End Sub
  1770. Public Sub Object_PlaySound(ObjIndex, SoundEvent)
  1771. With Objects(ObjIndex)
  1772.   If ObjModels(.ModelIndex).Attributes(ATTRIBUTE_SOUNDGROUP) = True Then
  1773.     If ObjModels(.ModelIndex).SoundGroup.EventSounds(SoundEvent) <> NOSOUND Then
  1774.       Call Entities.ObjectEmitSound(ObjIndex, ObjModels(.ModelIndex).SoundGroup.EventSounds(SoundEvent))
  1775.     End If
  1776.   End If
  1777. End With
  1778. End Sub
  1779. Public Sub ResetObject(ObjIndex)
  1780. Dim BlankObject As ObjThing
  1781. Objects(ObjIndex) = BlankObject
  1782. End Sub
  1783. Public Sub DestroyObject(ObjIndex)
  1784. With Objects(ObjIndex)
  1785.     Call Object_PlaySound(ObjIndex, SoundEvent_Explode)
  1786.     If ObjModels(.ModelIndex).Abilities(ABILITY_EXPLODESWITHFIRE) = True Then
  1787.       Call VisualEffects.SpawnFire(.Position.X, .Position.Y, 0, ObjModels(.ModelIndex).Attributes(ATTRIBUTE_EXPLOSIONRADIUS), 15)
  1788.     End If
  1789.     .Frozen = False
  1790.     If ObjModels(.ModelIndex).Attributes(ATTRIBUTE_EXPLOSIONSPRITE) <> NOSPRITE Then
  1791.       Call VisualEffects.SpawnAnimation(.Position.X + (Int(20 * Rnd) - 10), .Position.Y + (Int(20 * Rnd) - 10) - (.Position.Z / 3), ObjModels(.ModelIndex).Attributes(ATTRIBUTE_EXPLOSIONSPRITE))
  1792.     End If
  1793.     For I = 1 To ObjectSelectedList.IndexesActive
  1794.       If ObjectSelectedList.Indexes(I) = ObjIndex Then
  1795.         Call ClearSelectedListEntry(I)
  1796.         Exit For
  1797.       End If
  1798.     Next I
  1799.     For I = 1 To ObjectsActive
  1800.       If Objects(I).Objective.Target = ObjIndex Then
  1801.         Objects(I).Objective.Target = NOTARGET
  1802.         Objects(I).States(STATE_FIRING) = False
  1803.         If Objects(I).Properties(PROPERTY_LASTCOMMAND) = GOAL_ATTACK Then
  1804.           Objects(I).Properties(PROPERTY_LASTCOMMAND) = GOAL_NOTHING
  1805.         End If
  1806.         If Objects(I).Objective.Goal = GOAL_GETFARTHERAWAYFROMTARGET Then
  1807.           Objects(I).Objective.Goal = GOAL_NOTHING
  1808.         End If
  1809.         If Objects(I).Objective.Goal = GOAL_ATTACK Then
  1810.           Call ObjectCommand_CeaseAttack(I)
  1811.         End If
  1812.       End If
  1813.     Next I
  1814.     .Active = False
  1815.     If CheckObject(ObjIndex, OBJCHECK_OCCUPIESMAPSPACE) = True Then Call Map.SetGroundUnOccupiedByObject(ObjIndex)
  1816.     If ObjectsActive = ObjIndex Then
  1817.       For I = 1 To ObjectsActive
  1818.         If Objects(I).Active = True Then
  1819.           ObjectsAlive = I
  1820.         End If
  1821.       Next I
  1822.       ObjectsActive = ObjectsAlive
  1823.     End If
  1824.     If ObjModels(.ModelIndex).Abilities(ABILITY_BUILDS) = True Then
  1825.       Call Players.BuildObjectsChanged(.Side)
  1826.     End If
  1827. End With
  1828. End Sub
  1829. Public Sub RunWorld()
  1830. For I = 1 To ObjectsActive
  1831.   If Objects(I).Active = True Then
  1832.     If Objects(I).Frozen = False Then
  1833.       Call Entities.RunObject(I)
  1834.     End If
  1835.   End If
  1836. Next I
  1837. End Sub
  1838.