⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 entities.bas

📁 超级C&C有没有搞错,VB还能编出这种即时策略游戏来!没错,这就是我们的超级C&C!虽然游戏经常无故退出,但是原码仍有很多可圈可点的地方.祝你早日编出中国的超级RA,超级KKND,超级星际,超级家园
💻 BAS
📖 第 1 页 / 共 5 页
字号:
            Else
              .Objective.Speed = 0
              .States(STATE_MOVING) = False
            End If
          Else
            .Objective.Speed = 0
          End If
    Case BEHAVIORMODE_WEAPON
        .Properties(PROPERTY_FUEL) = .Properties(PROPERTY_FUEL) - 1
        If .Properties(PROPERTY_FUEL) < 0 Then Call ObjectEvent_MissileCollide(ObjIndex)
        .Properties(PROPERTY_TIMEUNTILADJUSTDIRECTION) = .Properties(PROPERTY_TIMEUNTILADJUSTDIRECTION) - 1
        If .Properties(PROPERTY_TIMEUNTILADJUSTDIRECTION) = 0 Then
          .Properties(PROPERTY_TIMEUNTILADJUSTDIRECTION) = OBJCONST_TimeTillAdjustDirection
          Call SetObjectDirection(ObjIndex, Map.UnProjectToMap3DPoint(.Objective.CurrentDestination))
        End If
        If ObjModels(.ModelIndex).Abilities(ABILITY_REACHESTARGETINSTANTLY) = True Then
          If ObjModels(.ModelIndex).Abilities(ABILITY_LEAVESSPARKLETRAIL) = True Then
            Call VisualEffects.Effect_RailgunTrail(.Position, Map.UnProjectToMap3DPoint(.Objective.TargetPosition))
            .Position = Map.UnProjectToMap3DPoint(.Objective.TargetPosition)
            Call ObjectEvent_MissileCollide(ObjIndex)
          End If
        Else
          .States(STATE_MOVING) = True
          If .Objective.Target <> TARGETGROUND Then
            If .Objective.Target <> NOTARGET Then
              If ObjModels(.ModelIndex).Abilities(ABILITY_FOLLOWSTARGET) = True Then
                Call ChangeObjectDestination(ObjIndex, Map.ProjectToMapX(Objects(.Objective.Target).Position.X), Map.ProjectToMapY(Objects(.Objective.Target).Position.Y), 0)
              End If
            End If
          End If
          If Math.GetDistance(.Position, Map.UnProjectToMap3DPoint(.Objective.TargetPosition)) < OBJCONST_MissileStopDistance Then
            Call ObjectEvent_MissileCollide(ObjIndex)
          End If
          .Objective.Speed = ObjModels(.ModelIndex).Attributes(ATTRIBUTE_MAXSPEED)
          If GroundBlocks(.MapPosition.X, .MapPosition.Y).Occupied = True Then
            OnObj = GroundBlocks(.MapPosition.X, .MapPosition.Y).OccupyingObject
            If Objects(OnObj).Position.Z = .Position.Z Then
              If CheckObject(OnObj, OBJCHECK_ALIVE) = True Then
                If CheckObject(OnObj, OBJCHECK_HITTABLE) = True Then
                  If Objects(OnObj).Side <> .Side Then
                    Call ObjectEvent_MissileCollide(ObjIndex)
                  End If
                End If
              End If
            End If
          End If
        End If
    Case BEHAVIORMODE_BUILDING
        If ObjModels(.ModelIndex).Attributes(ATTRIBUTE_MAPIMPRINT) <> NOMAPIMPRINT Then Call Map.PlaceMapImprint(ObjModels(.ModelIndex).Attributes(ATTRIBUTE_MAPIMPRINT), .MapPosition.X, .MapPosition.Y, ObjIndex)
        If .States(STATE_BUILDING) = True Then
          .Properties(PROPERTY_BUILDPROGRESS) = .Properties(PROPERTY_BUILDPROGRESS) + 1
          If .Properties(PROPERTY_BUILDPROGRESS) = ObjModels(.ModelIndex).Attributes(ATTRIBUTE_BUILDATFRAME) Then
            newobj = SpawnObject(.Properties(PROPERTY_CLASSTOBUILD), .Side, .MapPosition.X + 1, .MapPosition.Y + 1, 0, 90, 0)
            Call ChangeObjectDestination(newobj, .MapPosition.X + 2, .MapPosition.Y + 2, 0)
            Objects(newobj).States(STATE_MOVING) = True
            Objects(newobj).Objective.Goal = GOAL_MOVESOMEWHERE
            .States(STATE_MOVING) = False
          End If
        End If
    Case BEHAVIORMODE_INANIMATE
        If ObjModels(.ModelIndex).Attributes(ATTRIBUTE_MAPIMPRINT) <> NOMAPIMPRINT Then Call Map.PlaceMapImprint(ObjModels(.ModelIndex).Attributes(ATTRIBUTE_MAPIMPRINT), .MapPosition.X, .MapPosition.Y, ObjIndex)
    End Select
End With
End Sub
Public Sub ObjectEvent_MissileCollide(MissileObj)
With Objects(MissileObj)
  If ObjModels(.ModelIndex).Abilities(ABILITY_THROWSMETALATDEATH) = True Then
    Call SpawnSparkExplosion(.Position.X, .Position.Y, .Position.Z, PALLETE_WHITE, 5, 8)
  End If

  Intensity = ObjModels(.ModelIndex).Attributes(ATTRIBUTE_EXPLOSIONINTENSITY)
  Size = ObjModels(.ModelIndex).Attributes(ATTRIBUTE_EXPLOSIONRADIUS)

  If ObjModels(.ModelIndex).Abilities(ABILITY_THROWSSPARKLESATCOLLIDE) = True Then
    Call SpawnSparkleExplosion(.Position.X, .Position.Y, .Position.Z, PALLETE_YELLOW, 3)
  End If
  Call SpawnSparkDirectionalExplosion(.Position.X, .Position.Y, .Position.Z, PALLETE_YELLOW, Size, Intensity, .Vector.Yaw + 180)
  Call EnviromentEvent_Explosion(.Position, ObjModels(.ModelIndex).Attributes(ATTRIBUTE_EXPLOSIONRADIUS), ObjModels(.ModelIndex).Attributes(ATTRIBUTE_EXPLOSIONINTENSITY), ObjModels(.ModelIndex).Attributes(ATTRIBUTE_EXPLOSIONTYPE))
End With
Call Entities.DestroyObject(MissileObj)
End Sub
Public Sub EnviromentEvent_Explosion(ExplodePosition As Point3D, Radius, Intensity, ExplodeType)
If GroundBlocks(Map.ProjectToMapX(ExplodePosition.X), Map.ProjectToMapY(ExplodePosition.Y)).Occupied = True Then
  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)
End If
For I = 1 To ObjectsActive
  If CheckObject(I, OBJCHECK_ALIVE) = True Then
    If CheckObject(I, OBJCHECK_HITTABLE) = True Then
      With Objects(I)
        If Math.GetDistance(ExplodePosition, .Position) < Radius * 10 Then
          If ObjModels(.ModelIndex).Abilities(ABILITY_THROWSMETALWHENHIT) = True Then
            ExplodeYaw = Math.GetYawFromXY(.Position.X, .Position.Y, ExplodePosition.X, ExplodePosition.Y)
            ExplodeX = SinTable(ExplodeYaw) * (ObjModels(.ModelIndex).Attributes(ATTRIBUTE_SIZE) * HalfMapBlockSize)
            ExplodeY = CosTable(ExplodeYaw) * (ObjModels(.ModelIndex).Attributes(ATTRIBUTE_SIZE) * HalfMapBlockSize)
            Call SpawnSparkDirectionalExplosion(.Position.X + ExplodeX, .Position.Y + ExplodeY, .Position.Z, PALLETE_WHITE, 2, 8, ExplodeYaw)
          End If
          If ObjModels(.ModelIndex).Abilities(ABILITY_CANBEDAMAGED) = True Then Call DamageObject(I, Intensity, DamageType)
        End If
      End With
    End If
  End If
Next I
End Sub
Public Sub DamageObject(ObjIndex, DamageAmount, DamageType)
With Objects(ObjIndex)
  .Properties(PROPERTY_HEALTH) = .Properties(PROPERTY_HEALTH) - DamageAmount
  If .Properties(PROPERTY_HEALTH) <= 0 Then
    .Frozen = True
    Call Events.SpawnEvent(Events.Event_DestroyObject, ObjIndex)
  End If
End With
End Sub
Public Sub SetObjectMapPosition(ObjIndex)
With Objects(ObjIndex)
  .MapPosition.X = Map.ProjectToMapX(.Position.X)
  .MapPosition.Y = Map.ProjectToMapY(.Position.Y)
End With
End Sub
Public Sub MoveObject(ObjIndex, Yaw, Speed)
Dim TempPos As Point3D
TempPos = Math.GetPropelCoordinates(Objects(ObjIndex).Position, Yaw, 0, Speed)
With Objects(ObjIndex)
  If CheckIfIllegalObjectPosition3D(TempPos) = False Then
    SetPosition = True
    If CheckObject(ObjIndex, OBJCHECK_OCCUPIESMAPSPACE) = True Then
      Call SetGroundUnOccupiedByObject(ObjIndex)
      MapX = Map.ProjectToMapX(TempPos.X)
      MapY = Map.ProjectToMapY(TempPos.Y)
      Size = ObjModels(Objects(ObjIndex).ModelIndex).Attributes(ATTRIBUTE_SIZE)
      If Map.GetGroundOccupied(MapX, MapY, Size) = False Then
        If ObjModels(.ModelIndex).BehaviorType = BEHAVIORMODE_TANK Then
          If GroundBlocks(MapX, MapY).Height - .Position.Z > ObjModels(.ModelIndex).Attributes(ATTRIBUTE_LENGTHZ) Then
            .ObjectTags(TAG_BLOCKED) = True
            'Call ObjectCommand_AvoidCollision(ObjIndex, TempPos.X, TempPos.Y)
            SetPosition = False
          End If
          If GroundBlocks(MapX, MapY).TerrainType = TERRAINTYPE_WATER Then
            .ObjectTags(TAG_BLOCKED) = True
            'Call ObjectCommand_AvoidCollision(ObjIndex, TempPos.X, TempPos.Y)
            SetPosition = False
          End If
        End If
      Else
        Call DetermineMoveFromCollide(ObjIndex, GroundBlocks(MapX, MapY).OccupyingObject)
        SetPosition = False
      End If
    End If
    If SetPosition = True Then
      TempPos.Z = .Position.Z
      If .Position.Z < GroundBlocks(MapX, MapY).Height Then
        'Goes up
        If ObjModels(.ModelIndex).Abilities(ABILITY_ISPHYSICAL) = True Then
          If ((GroundBlocks(MapX, MapY).Height - .Position.Z) / ObjModels(.ModelIndex).Attributes(ATTRIBUTE_WEIGHT)) > 2 Then
            .InertiaSpeedUp = .InertiaSpeedUp + (((GroundBlocks(MapX, MapY).Height - .Position.Z) * (.CurrentSpeed / 2)) / ObjModels(.ModelIndex).Attributes(ATTRIBUTE_WEIGHT))
          End If
        End If
        TempPos.Z = GroundBlocks(MapX, MapY).Height
      End If
      .Position = TempPos
      Call SetObjectMapPosition(ObjIndex)
    End If
    If CheckObject(ObjIndex, OBJCHECK_OCCUPIESMAPSPACE) = True Then Call SetGroundOccupiedByObject(ObjIndex)
  End If
End With
End Sub
Public Sub DetermineMoveFromCollide(ObjIndex, CollidedWithObject)
With Objects(ObjIndex)
  If ObjModels(Objects(CollidedWithObject).ModelIndex).Abilities(ABILITY_MOVES) = True Then
    If ObjModels(.ModelIndex).Attributes(ATTRIBUTE_IMPORTANCE) >= ObjModels(Objects(CollidedWithObject).ModelIndex).Attributes(ATTRIBUTE_IMPORTANCE) Then
      If Objects(CollidedWithObject).States(STATE_MOVING) = False Then
        If GroundBlocks(.MapPosition.X - 1, .MapPosition.Y - 1).Occupied = True Then
          IsBoxedInAmount = IsBoxedInAmount + 1
        End If
        If GroundBlocks(.MapPosition.X, .MapPosition.Y - 1).Occupied = True Then
          IsBoxedInAmount = IsBoxedInAmount + 1
        End If
        If GroundBlocks(.MapPosition.X + 1, .MapPosition.Y - 1).Occupied = True Then
          IsBoxedInAmount = IsBoxedInAmount + 1
        End If
        If GroundBlocks(.MapPosition.X + 1, .MapPosition.Y).Occupied = True Then
          IsBoxedInAmount = IsBoxedInAmount + 1
        End If
        If GroundBlocks(.MapPosition.X + 1, .MapPosition.Y + 1).Occupied = True Then
          IsBoxedInAmount = IsBoxedInAmount + 1
        End If
        If GroundBlocks(.MapPosition.X, .MapPosition.Y + 1).Occupied = True Then
          IsBoxedInAmount = IsBoxedInAmount + 1
        End If
        If GroundBlocks(.MapPosition.X - 1, .MapPosition.Y + 1).Occupied = True Then
          IsBoxedInAmount = IsBoxedInAmount + 1
        End If
        If GroundBlocks(.MapPosition.X - 1, .MapPosition.Y).Occupied = True Then
          IsBoxedInAmount = IsBoxedInAmount + 1
        End If
        If IsBoxedInAmount > 4 Then
          Call Entities.ObjectCommand_GetOutOfTheWay(CollidedWithObject, ObjIndex, 50)
          Call Entities.ObjectCommand_SitStillForTime(ObjIndex, 20)
        Else
          Call ObjectCommand_AvoidCollision(ObjIndex, Objects(CollidedWithObject).Position.X, Objects(CollidedWithObject).Position.Y)
        End If
      Else
        Call ObjectCommand_AvoidCollision(ObjIndex, Objects(CollidedWithObject).Position.X, Objects(CollidedWithObject).Position.Y)
      End If
    Else
      Call ObjectCommand_AvoidCollision(ObjIndex, Objects(CollidedWithObject).Position.X, Objects(CollidedWithObject).Position.Y)
    End If
  Else
    Call ObjectCommand_AvoidCollision(ObjIndex, Objects(CollidedWithObject).Position.X, Objects(CollidedWithObject).Position.Y)
  End If
End With
End Sub
Public Function CheckIfIllegalObjectPosition3D(Position As Point3D) As Boolean
If Position.X < 0 Then CheckIfIllegalObjectPosition3D = True: Exit Function
If Position.Y < 0 Then CheckIfIllegalObjectPosition3D = True: Exit Function
If Position.X > Map.BattleMap.RealWidth Then CheckIfIllegalObjectPosition3D = True: Exit Function
If Position.Y > Map.BattleMap.RealHeight Then CheckIfIllegalObjectPosition3D = True: Exit Function
End Function
Public Function GetMapImprintNum(Imprint$)
For I = 1 To MAXIMPRINTS
  If MapImprints(I).ImprintName = Imprint$ Then
    GetMapImprintNum = I
    Exit For
  End If
Next I
End Function
Public Sub ChangeObjectDestination(ObjIndex, NewX, NewY, NewZ)
Dim EmptyBlock As Point3D
If NewX < 0 Then NewX = 0
If NewY < 0 Then NewY = 0
If CheckObject(ObjIndex, OBJCHECK_OCCUPIESMAPSPACE) = True Then
  EmptyBlock = Map.GetNearestEmptyBlock(NewX, NewY, TERRAINTYPE_WATER, True)
Else
  EmptyBlock.X = NewX
  EmptyBlock.Y = NewY
End If
With Objects(ObjIndex)
  .Objective.MainDestination.X = EmptyBlock.X
  .Objective.MainDestination.Y = EmptyBlock.Y
  .Objective.MainDestination.Z = NewZ
  .Objective.CurrentDestination = .Objective.MainDestination
End With
End Sub
Public Sub ChangeObjectCurrentDestination(ObjIndex, NewX, NewY, NewZ)
Dim EmptyBlock As Point3D
If NewX < 0 Then NewX = 0
If NewY < 0 Then NewY = 0
If CheckObject(ObjIndex, OBJCHECK_OCCUPIESMAPSPACE) = True Then
  EmptyBlock = Map.GetNearestEmptyBlock(NewX, NewY, TERRAINTYPE_WATER, True)
Else
  EmptyBlock.X = NewX
  EmptyBlock.Y = NewY
End If
With Objects(ObjIndex).Objective.CurrentDestination
  .X = EmptyBlock.X
  .Y = EmptyBlock.Y
  .Z = NewZ
End With
Call SetObjectDirection(ObjIndex, Map.UnProjectToMap3DPoint(Objects(ObjIndex).Objective.CurrentDestination))
End Sub

Sub SetObjectDirection(ObjIndex, ObjDest As Point3D)
With Objects(ObjIndex)
  .Vector.Yaw = Math.GetYawFromXY(.Position.X, .Position.Y, ObjDest.X, ObjDest.Y)
  Call Math.CheckVector(.Vector)
  .Vector.ZIncline = 0
  Call SetDisplayDirection(ObjIndex)
End With
End Sub
Sub SteerInertialDirection(ObjIndex, DestYaw, TurnSpeed)
If TurnSpeed < 22 Then
  Speed = TurnSpeed
Else
  Speed = 11
End If
With Objects(ObjIndex)
    If .InertiaDirection.Yaw - 3 < DestYaw Then
      If .InertiaDirection.Yaw + 3 > DestYaw Then
        .InertiaDirection.Yaw = DestYaw
        Exit Sub
      End If
    End If
    If DestYaw > .Vector.Yaw Then
      If DestYaw - .Vector.Yaw < 180 Then
        .InertiaDirection.Yaw = .InertiaDirection.Yaw + Speed
      Else
        .InertiaDirection.Yaw = .InertiaDirection.Yaw - Speed
      End If
    Else
      If .InertiaDirection.Yaw - DestYaw < 180 Then
        .InertiaDirection.Yaw = .InertiaDirection.Yaw - Speed
      Else
        .InertiaDirection.Yaw = .InertiaDirection.Yaw + Speed
      End If
    End If
    If .InertiaDirection.Yaw + (Speed + 4) > DestYaw Then
      If .InertiaDirection.Yaw - (Speed + 4) < DestYaw Then
        .InertiaDirection.Yaw = DestYaw
      End If
    End If
    Call Math.CheckVector(.InertiaDirection)
End With
End Sub
Function SteerObjectDirection(ObjIndex, ObjDest As Point3D, ObjTurnSpeed) As Boolean
With Objects(ObjIndex)
    TurnSpeed = ObjTurnSpeed
    If .Position.Z > GroundBlocks(.MapPosition.X, .MapPosition.Y).Height Then

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -