📄 entities.bas
字号:
Else
.Sprite.SpriteGroupNumber = SPRITEGROUP_SHOOTING
.Sprite.SpriteFrameNumber = 1
End If
End If
If ObjModels(.ModelIndex).Attributes(ATTRIBUTE_ACCURACY) <> 0 Then
Offset = (ObjModels(.ModelIndex).Attributes(ATTRIBUTE_ACCURACY) * Rnd) - (ObjModels(.ModelIndex).Attributes(ATTRIBUTE_ACCURACY) / 2)
End If
If ObjModels(.ModelIndex).Abilities(ABILITY_BODYISBISECTED) = True Then
FireYaw = .TopDirection
TempPosition.X = .Position.X - ObjModels(.ModelIndex).Attributes(ATTRIBUTE_WEAPONX)
TempPosition.Y = .Position.Y - ObjModels(.ModelIndex).Attributes(ATTRIBUTE_WEAPONY)
TempPosition = Math.RotatePointAroundPoint(TempPosition, .Position, .TopDirection + Offset)
Else
FireYaw = .Vector.Yaw
TempPosition.X = .Position.X - ObjModels(.ModelIndex).Attributes(ATTRIBUTE_WEAPONX)
TempPosition.Y = .Position.Y - ObjModels(.ModelIndex).Attributes(ATTRIBUTE_WEAPONY)
TempPosition = Math.RotatePointAroundPoint(TempPosition, .Position, .Vector.Yaw + Offset)
End If
FireX = TempPosition.X
FireY = TempPosition.Y
FireZIncline = 0
.Properties(PROPERTY_WEAPONCHARGE) = 0
newobj = SpawnObject(.Properties(PROPERTY_WEAPONOBJECTTYPE), .Side, Map.ProjectToMapX(FireX), Map.ProjectToMapY(FireY), FireZ, FireYaw, FireZIncline)
Call RelocateObject(newobj, FireX, FireY, .Position.Z)
End With
With Objects(newobj)
.Position.Z = (ObjModels(.ModelIndex).Attributes(ATTRIBUTE_LENGTHZ) / 2) + .Position.Z
Call ChangeObjectDestination(newobj, X, Y, Z)
.Objective.Target = Target
.Objective.TargetPosition = Temppoint
.Properties(PROPERTY_FUEL) = Math.GetDistance(Objects(ObjIndex).Position, Map.UnProjectToMap3DPoint(Temppoint)) / (ObjModels(Objects(ObjIndex).ModelIndex).Attributes(ATTRIBUTE_MAXSPEED))
End With
End Sub
Public Sub RelocateObject(ObjIndex, NewX, NewY, NewZ)
If CheckObject(ObjIndex, OBJCHECK_OCCUPIESMAPSPACE) = True Then Call Map.SetGroundUnOccupiedByObject(ObjIndex)
With Objects(ObjIndex)
.Position.X = NewX
.Position.Y = NewY
.Position.Z = NewZ
Call Entities.SetObjectMapPosition(ObjIndex)
End With
If CheckObject(ObjIndex, OBJCHECK_OCCUPIESMAPSPACE) = True Then Call Map.SetGroundOccupiedByObject(ObjIndex)
End Sub
Public Sub ObjectCommand_GetOutOfTheWay(Obj1, Obj2, GetOutOfWayLength)
Dim Temppoint As Point3D, TempVector As Vect3D
With Objects(Obj1)
TempVector.Yaw = Math.GetYawFromXY(.Position.X, .Position.Y, Objects(Obj2).Position.X, Objects(Obj2).Position.Y) + 180
If TempVector.Yaw > Objects(Obj1).Vector.Yaw - 15 Then
If TempVector.Yaw < Objects(Obj1).Vector.Yaw + 15 Then
If Int(2 * Rnd) = 1 Then
TempVector.Yaw = TempVector.Yaw - 15
Else
TempVector.Yaw = TempVector.Yaw + 15
End If
End If
End If
Call CheckVector(TempVector)
If .Objective.Goal <> GOAL_GETOUTOFTHEWAY Then .Properties(PROPERTY_LASTCOMMAND) = .Objective.Goal
.Properties(PROPERTY_POSITIONTEMPX) = .MapPosition.X
.Properties(PROPERTY_POSITIONTEMPY) = .MapPosition.Y
.Objective.Goal = GOAL_GETOUTOFTHEWAY
Temppoint = Map.ProjectToMap3DPoint(Math.GetPropelCoordinates(.Position, TempVector.Yaw, 0, GetOutOfWayLength))
Call Entities.ChangeObjectDestination(Obj1, Temppoint.X, Temppoint.Y, Temppoint.Z)
End With
End Sub
Public Sub ObjectCommand_CreatePath(ObjIndex, X, Y)
With Objects(ObjIndex)
If .Objective.Goal <> GOAL_GETOUTOFTHEWAY Then .Properties(PROPERTY_LASTCOMMAND) = .Objective.Goal
.Objective.Goal = GOAL_FOLLOWPATH
.Objective.CurrentPathPoint = 1
.Objective.Path = FindPath(ObjIndex, X, Y, TERRAINTYPE_WATER)
End With
End Sub
Public Sub ObjectCommand_GetFartherAwayFromTarget(Obj1, TargetPosition As Point3D)
Dim Temppoint As Point3D, TempVector As Vect3D
With Objects(Obj1)
TempVector.Yaw = Math.GetYawFromXY(Map.UnProjectToMapX(TargetPosition.X), Map.UnProjectToMapY(TargetPosition.Y), .Position.X, .Position.Y) '+ 180
Call CheckVector(TempVector)
.Objective.Goal = GOAL_GETFARTHERAWAYFROMTARGET
If .Objective.Target <> TARGETGROUND Then
TargetSize = (ObjModels(Objects(.Objective.Target).ModelIndex).Attributes(ATTRIBUTE_SIZE) * MapBlockSize)
Else
TargetSize = 0
End If
Temppoint = Map.ProjectToMap3DPoint(Math.GetPropelCoordinates(Map.UnProjectToMap3DPoint(TargetPosition), TempVector.Yaw, 0, TargetSize + ObjModels(.ModelIndex).Attributes(ATTRIBUTE_MINIMUMSHOOTRADIUS) + 20))
Call Entities.ChangeObjectDestination(Obj1, Temppoint.X, Temppoint.Y, Temppoint.Z)
End With
End Sub
Public Sub RunObject(ObjIndex)
Dim TempPos As Point3D
If CheckObject(ObjIndex, OBJCHECK_OCCUPIESMAPSPACE) = True Then Call SetGroundOccupiedByObject(ObjIndex)
Call RunObjectAnimation(ObjIndex)
With Objects(ObjIndex)
If ObjModels(.ModelIndex).Abilities(ABILITY_USESINERTIA) = True Then
'Friction
If .Position.Z = GroundBlocks(.MapPosition.X, .MapPosition.Y).Height Then
.CurrentSpeed = .CurrentSpeed - (GroundBlocks(.MapPosition.X, .MapPosition.Y).Friction * ObjModels(.ModelIndex).Attributes(ATTRIBUTE_WEIGHT))
If .CurrentSpeed < 0 Then .CurrentSpeed = 0
Else
.CurrentSpeed = .CurrentSpeed - LevelSettings.AirFriction
End If
If .Objective.Speed > .CurrentSpeed Then
.CurrentSpeed = .CurrentSpeed + (ObjModels(.ModelIndex).Attributes(ATTRIBUTE_ENGINEPOWER) / ObjModels(.ModelIndex).Attributes(ATTRIBUTE_WEIGHT))
If .CurrentSpeed > .Objective.Speed Then .CurrentSpeed = .Objective.Speed
End If
If .InertiaSpeed > 0 Then
If .Position.Z = GroundBlocks(.MapPosition.X, .MapPosition.Y).Height Then
.InertiaSpeed = .InertiaSpeed - (GroundBlocks(.MapPosition.X, .MapPosition.Y).Friction / ObjModels(.ModelIndex).Attributes(ATTRIBUTE_WEIGHT))
Else
.InertiaSpeed = .InertiaSpeed - LevelSettings.AirFriction
End If
End If
If .Position.Z > GroundBlocks(.MapPosition.X, .MapPosition.Y).Height Then
.InertiaSpeedUp = .InertiaSpeedUp - (LevelSettings.GravityAmount * (ObjModels(.ModelIndex).Attributes(ATTRIBUTE_WEIGHT) + 1))
End If
Entities.SteerInertialDirection ObjIndex, .Vector.Yaw, 7
.Position.Z = .Position.Z + .InertiaSpeedUp
If .Position.Z <= GroundBlocks(.MapPosition.X, .MapPosition.Y).Height Then
If .InertiaSpeedUp < 0 Then
.Position.Z = GroundBlocks(.MapPosition.X, .MapPosition.Y).Height
.InertiaSpeedUp = -(.InertiaSpeedUp / 4) - LevelSettings.GravityAmount
If .InertiaSpeedUp < 3 Then
.InertiaSpeedUp = 0
End If
End If
End If
Else
.CurrentSpeed = .Objective.Speed
End If
Call RunBehavior(ObjIndex, ObjModels(.ModelIndex).BehaviorType)
If .States(STATE_FIRING) = True Then
If .Properties(PROPERTY_WEAPONCHARGE) <> DELAYWEAPON Then
.Properties(PROPERTY_WEAPONCHARGE) = .Properties(PROPERTY_WEAPONCHARGE) + 1
If .Properties(PROPERTY_WEAPONCHARGE) > ObjModels(.ModelIndex).Attributes(ATTRIBUTE_WEAPONCHARGETIME) Then
.Properties(PROPERTY_WEAPONCHARGE) = DELAYWEAPON
Call Events.SpawnEvent(Events.Event_ObjectFire, ObjIndex, .Objective.TargetPosition.X, .Objective.TargetPosition.Y, .Objective.TargetPosition.Z)
End If
End If
End If
If .CurrentSpeed > 0 Or .InertiaSpeed > 0 Then
If ObjModels(.ModelIndex).Abilities(ABILITY_SPLASHESWATER) = True Then
If GroundBlocks(.MapPosition.X, .MapPosition.Y).TerrainOverlayAmount > 1 Then
If .Position.Z = GroundBlocks(.MapPosition.X, .MapPosition.Y).Height Then
SparkDirection = Int(360 * Rnd)
TempPos = Math.GetPropelCoordinates(.Position, SparkDirection, 0, 7 + (5 * Rnd))
Call SpawnSpark(TempPos.X, TempPos.Y, .Position.Z, PALLETE_BLUE, SparkDirection, 2, 10, 7, 1)
End If
End If
End If
If ObjModels(.ModelIndex).Abilities(ABILITY_LEAVESSPARKLETRAIL) = True Then
Call SpawnSpark(.Position.X, .Position.Y, .Position.Z, PALLETE_YELLOW, Int(360 * Rnd), 1, 25, 0, 1)
End If
Call MoveObject(ObjIndex, .Vector.Yaw, .CurrentSpeed)
Call MoveObject(ObjIndex, .InertiaDirection.Yaw, .InertiaSpeed)
End If
End With
End Sub
Public Sub RunBehavior(ObjIndex, BehaveType)
With Objects(ObjIndex)
Select Case BehaveType
Case BEHAVIORMODE_TANK
Dim TempPos As Point3D
If .ObjectTags(TAG_BLOCKED) = True Then
Call ObjectCommand_CreatePath(ObjIndex, .Objective.MainDestination.X, .Objective.MainDestination.Y)
.ObjectTags(TAG_BLOCKED) = False
End If
Select Case .Objective.Goal
Case GOAL_FOLLOWPATH
If Math.GetDistance(.Position, Map.UnProjectToMap3DPoint(.Objective.CurrentDestination)) < OBJCONST_ObjectStopDistance Then
If .Objective.CurrentPathPoint = .Objective.Path.Points.PathPointsActive Then
.Objective.Speed = 0
.States(STATE_MOVING) = False
Select Case .Properties(PROPERTY_LASTCOMMAND)
Case GOAL_NOTHING
Call ObjectCommand_MoveSomewhere(ObjIndex, .Properties(PROPERTY_POSITIONTEMPX), .Properties(PROPERTY_POSITIONTEMPY))
Case GOAL_MOVESOMEWHERE
Call ObjectCommand_MoveSomewhere(ObjIndex, .Objective.MainDestination.X, .Objective.MainDestination.Y)
Case GOAL_ATTACK
Call ObjectCommand_AttackObject(ObjIndex, Objects(ObjIndex).Objective.Target, Objects(ObjIndex).Objective.TargetPosition.X, Objects(ObjIndex).Objective.TargetPosition.Y)
Case GOAL_GETFARTHERAWAYFROMTARGET
Call ObjectCommand_AttackObject(ObjIndex, Objects(ObjIndex).Objective.Target, Objects(ObjIndex).Objective.TargetPosition.X, Objects(ObjIndex).Objective.TargetPosition.Y)
End Select
Else
.Objective.CurrentPathPoint = .Objective.CurrentPathPoint + 1
.Objective.CurrentDestination.X = .Objective.Path.Points.PathPoints(.Objective.CurrentPathPoint).X
.Objective.CurrentDestination.Y = .Objective.Path.Points.PathPoints(.Objective.CurrentPathPoint).Y
.States(STATE_MOVING) = True
End If
End If
Case GOAL_SITSTILL
.Properties(PROPERTY_TIMEREMAININGONSITSTILL) = .Properties(PROPERTY_TIMEREMAININGONSITSTILL) - 1
If .Properties(PROPERTY_TIMEREMAININGONSITSTILL) = 0 Then
.Objective.Goal = .Properties(PROPERTY_LASTCOMMAND)
End If
Case GOAL_GETOUTOFTHEWAY
If Math.GetDistance(.Position, Map.UnProjectToMap3DPoint(.Objective.CurrentDestination)) > OBJCONST_ObjectStopDistance Then
.States(STATE_MOVING) = True
Else
.Objective.Speed = 0
.States(STATE_MOVING) = False
Select Case .Properties(PROPERTY_LASTCOMMAND)
Case GOAL_NOTHING
Call ObjectCommand_MoveSomewhere(ObjIndex, .Properties(PROPERTY_POSITIONTEMPX), .Properties(PROPERTY_POSITIONTEMPY))
Case GOAL_MOVESOMEWHERE
Call ObjectCommand_MoveSomewhere(ObjIndex, .Objective.MainDestination.X, .Objective.MainDestination.Y)
Case GOAL_ATTACK
Call ObjectCommand_AttackObject(ObjIndex, Objects(ObjIndex).Objective.Target, Objects(ObjIndex).Objective.TargetPosition.X, Objects(ObjIndex).Objective.TargetPosition.Y)
Case GOAL_GETFARTHERAWAYFROMTARGET
Call ObjectCommand_AttackObject(ObjIndex, Objects(ObjIndex).Objective.Target, Objects(ObjIndex).Objective.TargetPosition.X, Objects(ObjIndex).Objective.TargetPosition.Y)
Case Else
.Objective.Goal = GOAL_NOTHING
End Select
End If
Case GOAL_GETFARTHERAWAYFROMTARGET
If Math.GetDistance(.Position, Map.UnProjectToMap3DPoint(.Objective.CurrentDestination)) > OBJCONST_ObjectStopDistance Then
.States(STATE_MOVING) = True
Else
If .Objective.Target <> NOTARGET Then
.States(STATE_MOVING) = False
Call ObjectCommand_AttackObject(ObjIndex, .Objective.Target, .Objective.TargetPosition.X, .Objective.TargetPosition.Y)
End If
End If
Case GOAL_MOVESOMEWHERE
If ObjModels(.ModelIndex).Abilities(ABILITY_BODYISBISECTED) = True Then
Call SteerTurretDirection(ObjIndex, Map.UnProjectToMap3DPoint(.Objective.CurrentDestination))
End If
If .Objective.Speed > 0 Then
If Math.GetDistance(.Position, Map.UnProjectToMap3DPoint(.Objective.CurrentDestination)) < OBJCONST_ObjectStopDistance Then
.Objective.Speed = 0
.States(STATE_MOVING) = False
.Objective.Goal = GOAL_NOTHING
Else
IsOnCourse = SteerObjectDirection(ObjIndex, Map.UnProjectToMap3DPoint(.Objective.CurrentDestination), ObjModels(.ModelIndex).Attributes(ATTRIBUTE_TURNSPEED))
.States(STATE_MOVING) = True
End If
Else
If SteerObjectDirection(ObjIndex, Map.UnProjectToMap3DPoint(.Objective.CurrentDestination), ObjModels(.ModelIndex).Attributes(ATTRIBUTE_TURNSPEED)) = True Then
.States(STATE_MOVING) = True
End If
End If
Case GOAL_ATTACK
'.States(STATE_MOVING) = False
If .Objective.Target <> TARGETGROUND Then
.Objective.TargetPosition = Objects(.Objective.Target).MapPosition
End If
If ObjModels(.ModelIndex).Abilities(ABILITY_BODYISBISECTED) = True Then Steered = SteerTurretDirection(ObjIndex, Map.UnProjectToMap3DPoint(.Objective.TargetPosition))
If .Objective.Target = TARGETGROUND Then
DistOffsetVal = 0
Else
DistOffsetVal = ObjModels(Objects(.Objective.Target).ModelIndex).Attributes(ATTRIBUTE_SIZE) * MapBlockSize
End If
If Math.GetDistance(.Position, Map.UnProjectToMap3DPoint(.Objective.CurrentDestination)) < OBJCONST_ObjectStopDistance Then
.Objective.CurrentDestination = .MapPosition
.States(STATE_MOVING) = False
.Objective.Speed = 0
Else
If .States(STATE_MOVING) = False Then
blah = 43
End If
.States(STATE_MOVING) = True
End If
DistanceFromTarget = Math.GetDistance(.Position, Map.UnProjectToMap3DPoint(.Objective.TargetPosition)) - DistOffsetVal
If DistanceFromTarget < ObjModels(.ModelIndex).Attributes(ATTRIBUTE_SHOOTRADIUS) Then
If DistanceFromTarget > ObjModels(.ModelIndex).Attributes(ATTRIBUTE_MINIMUMSHOOTRADIUS) Then
If ObjModels(.ModelIndex).Abilities(ABILITY_BODYISBISECTED) = True Then
If Steered = True Then
.States(STATE_FIRING) = True
End If
Else
If SteerObjectDirection(ObjIndex, Map.UnProjectToMap3DPoint(.Objective.TargetPosition), ObjModels(.ModelIndex).Attributes(ATTRIBUTE_TURNSPEED)) = True Then
.States(STATE_FIRING) = True
Else
.States(STATE_MOVING) = False
End If
End If
Else
Call ObjectCommand_GetFartherAwayFromTarget(ObjIndex, .Objective.TargetPosition)
End If
Else
If .Objective.Target <> TARGETGROUND Then
Call ObjectCommand_ContinueAttack(ObjIndex, .Objective.Target, .Objective.TargetPosition.X, .Objective.TargetPosition.Y)
End If
.States(STATE_MOVING) = True
End If
End Select
If .States(STATE_MOVING) = True Then
If Math.GetDistance(.Position, Map.UnProjectToMap3DPoint(.Objective.CurrentDestination)) > OBJCONST_ObjectStopDistance Then
If .Objective.Speed > 0 Then
.Properties(PROPERTY_TIMEUNTILADJUSTDIRECTION) = .Properties(PROPERTY_TIMEUNTILADJUSTDIRECTION) - 1
If .Properties(PROPERTY_TIMEUNTILADJUSTDIRECTION) = 0 Then
.Properties(PROPERTY_TIMEUNTILADJUSTDIRECTION) = OBJCONST_TimeTillAdjustDirection
If SteerObjectDirection(ObjIndex, Map.UnProjectToMap3DPoint(.Objective.CurrentDestination), ObjModels(.ModelIndex).Attributes(ATTRIBUTE_TURNSPEED)) = False Then
.Objective.Speed = 0
End If
End If
Else
If SteerObjectDirection(ObjIndex, Map.UnProjectToMap3DPoint(.Objective.CurrentDestination), ObjModels(.ModelIndex).Attributes(ATTRIBUTE_TURNSPEED)) = True Then
.Objective.Speed = ObjModels(.ModelIndex).Attributes(ATTRIBUTE_MAXSPEED)
End If
End If
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -