# ****************************************************************************
# CUI
#
# The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
#
# The use, dissemination or disclosure of data in this file is subject to
# limitation or restriction. See accompanying README and LICENSE for details.
# ****************************************************************************
###############################################################################
#                          ------ UNCLASSIFIED ------
#                                  RED_ICBM_2
###############################################################################
#
# NOTE: If you modify any parameter in this file, you must rerun 'weapon_tools'
#       with 'red_icbm_2_lcg.txt' as input to regenerate the launch computer data.
#
###############################################################################
#
# ***** WARNING ***** WARNING ***** WARNING ***** WARNING ***** WARNING *****
#
# This definition is intended to be EXPORTABLE. It is defined using publicly
# available, attributable sources. DO NOT ADD ANYTHING BASED ON OTHER SOURCES!
#
# ***** WARNING ***** WARNING ***** WARNING ***** WARNING ***** WARNING *****
#
###############################################################################
#
# This model is built using data from unclassified sources as follows:
#
# 1) http://www.globalsecurity.org/wmd/world/dprk/td-2-specs.htm
#    http://www.globalsecurity.org/wmd/world/dprk/td-2.htm
#
###############################################################################

###############################################################################
#           Support for explicit representation of spent stages
#
# Platforms will be created for spent stages if one the global script variables
# is defined as follows:
#
# script_variables
#    SHOW_SPENT_STAGES["ALL"] = true;            # For any weapon
#    SHOW_SPENT_STAGES["RED_ICBM_2"] = true;          # For just this weapon type
# end_script_variables
###############################################################################

include_once show_spent_stages.txt

##### Stage 1

aero RED_ICBM_2_SPENT_STAGE_1_AERO WSF_AERO           # TODO
   reference_area            16.62 ft^2
   aspect_ratio              1.0
   cl_max                    5.0
   zero_lift_cd              0.7
end_aero

infrared_signature RED_ICBM_2_SPENT_STAGE_1_INFRARED_SIG
   constant 1 watts/steradian
end_infrared_signature

optical_signature  RED_ICBM_2_SPENT_STAGE_1_OPTICAL_SIG
   constant 1 m^2
end_optical_signature

radar_signature    RED_ICBM_2_SPENT_STAGE_1_RADAR_SIG
   constant 1 m^2
end_radar_signature

platform_type RED_ICBM_2_SPENT_STAGE_1 WSF_PLATFORM
   icon Scud_Missile

   infrared_signature RED_ICBM_2_SPENT_STAGE_1_INFRARED_SIG
   optical_signature  RED_ICBM_2_SPENT_STAGE_1_OPTICAL_SIG
   radar_signature    RED_ICBM_2_SPENT_STAGE_1_RADAR_SIG

   mover WSF_GUIDED_MOVER
      integration_timestep   0.01 secs
      stage 1
         aero                RED_ICBM_2_SPENT_STAGE_1_AERO
         total_mass          3552.0 kg
      end_stage
   end_mover

   processor fuse WSF_GROUND_TARGET_FUSE
   end_processor
end_platform_type

##### Stage 2

aero RED_ICBM_2_SPENT_STAGE_2_AERO WSF_AERO           # TODO
   reference_area            16.62 ft^2
   aspect_ratio              1.0
   cl_max                    5.0
   zero_lift_cd              0.7
end_aero

infrared_signature RED_ICBM_2_SPENT_STAGE_2_INFRARED_SIG
   constant 1 watts/steradian
end_infrared_signature

optical_signature  RED_ICBM_2_SPENT_STAGE_2_OPTICAL_SIG
   constant 1 m^2
end_optical_signature

radar_signature    RED_ICBM_2_SPENT_STAGE_2_RADAR_SIG
   constant 1 m^2
end_radar_signature

platform_type RED_ICBM_2_SPENT_STAGE_2 WSF_PLATFORM
   icon Scud_Missile

   infrared_signature RED_ICBM_2_SPENT_STAGE_2_INFRARED_SIG
   optical_signature  RED_ICBM_2_SPENT_STAGE_2_OPTICAL_SIG
   radar_signature    RED_ICBM_2_SPENT_STAGE_2_RADAR_SIG

   mover WSF_GUIDED_MOVER
      integration_timestep   0.01 secs
      stage 1
         aero                RED_ICBM_2_SPENT_STAGE_2_AERO
         total_mass          2346.0 kg
      end_stage
   end_mover

   processor fuse WSF_GROUND_TARGET_FUSE
   end_processor
end_platform_type

##### Stage 3

aero RED_ICBM_2_SPENT_STAGE_3_AERO WSF_AERO           # TODO
   reference_area            16.62 ft^2
   aspect_ratio              1.0
   cl_max                    5.0
   zero_lift_cd              0.7
end_aero

infrared_signature RED_ICBM_2_SPENT_STAGE_3_INFRARED_SIG
   constant 1 watts/steradian
end_infrared_signature

optical_signature  RED_ICBM_2_SPENT_STAGE_3_OPTICAL_SIG
   constant 1 m^2
end_optical_signature

radar_signature    RED_ICBM_2_SPENT_STAGE_3_RADAR_SIG
   constant 1 m^2
end_radar_signature

platform_type RED_ICBM_2_SPENT_STAGE_3 WSF_PLATFORM
   icon Scud_Missile

   infrared_signature RED_ICBM_2_SPENT_STAGE_3_INFRARED_SIG
   optical_signature  RED_ICBM_2_SPENT_STAGE_3_OPTICAL_SIG
   radar_signature    RED_ICBM_2_SPENT_STAGE_3_RADAR_SIG

   mover WSF_GUIDED_MOVER
      integration_timestep   0.01 secs
      stage 1
         aero                RED_ICBM_2_SPENT_STAGE_3_AERO
         total_mass          833.0 kg
      end_stage
   end_mover

   processor fuse WSF_GROUND_TARGET_FUSE
   end_processor
end_platform_type

###############################################################################
# Signature data is unknown...

infrared_signature RED_ICBM_2_INFRARED_SIG
   constant 1 watts/steradian
end_infrared_signature

optical_signature  RED_ICBM_2_OPTICAL_SIG
   constant 1 m^2
end_optical_signature

radar_signature    RED_ICBM_2_RADAR_SIG
   constant 1 m^2
end_radar_signature

# Nominal lethality data.

weapon_effects RED_ICBM_2_EFFECT WSF_GRADUATED_LETHALITY
   radius_and_pk 1000.0 m 1.0
end_weapon_effects

###############################################################################

aero RED_ICBM_2_STAGE_1_AERO WSF_AERO
   reference_area            3.8013 m^2          # 2.2 m diameter (Ref 1)
   aspect_ratio              2.0
   cl_max                    4.5

   zero_lift_cd              0.2
   zero_lift_cd              0.4
end_aero

aero RED_ICBM_2_STAGE_2_AERO WSF_AERO
   reference_area            1.767 m^2           # 1.5 m diameter (Ref 1)
   aspect_ratio              2.0
   cl_max                    4.5

   zero_lift_cd              0.2
   zero_lift_cd              0.4
end_aero

aero RED_ICBM_2_STAGE_3_AERO WSF_AERO
   reference_area            3.079 m^2           # 1.98 m diameter (Ref 1)
   aspect_ratio              2.0
   cl_max                    4.5

   zero_lift_cd              0.2
   zero_lift_cd              0.4
end_aero

aero RED_ICBM_2_RV_AERO WSF_AERO
   reference_area            3.079 m^2           # 1.98 m diameter (Ref 1)
   aspect_ratio              2.0
   cl_max                    4.5

   zero_lift_cd              0.18
end_aero

###############################################################################

mover RED_ICBM_2_MOVER WSF_GUIDED_MOVER
   integration_timestep      0.005 secs
   update_interval           0.05 secs

   # NOTE: There are many slight inconsistencies in the values in Ref 1.
   #       The thrust_duration and thrust in Ref 1 are assumed to be consistent.
   #       The specific_impulse and burn_rate are allowed to be internally
   #       computed so as to use all the fuel.

   stage 1
      aero                   RED_ICBM_2_STAGE_1_AERO
      total_mass             55898 kg            # Ref 1, Mi
      fuel_mass              52124 kg            # Ref 1, Mp
 #     fuel_mass              114672.0 lbs        # Brian's value

      # Dry 3340 + 212 inter-stage = 3552

      # Note: Using The Isp eff. SL of 226 caused more fuel to be used than available.
      #specific_impulse       230 sec             # Ref 1, Isp actual SL
      thrust_duration        112 sec             # Ref 1
      thrust                 107040 kgf          # Ref 1
   end_stage

   stage 2
      aero                   RED_ICBM_2_STAGE_2_AERO
      total_mass             19106.5 kg          # Ref 1, Mi, lower value
      fuel_mass              16760.5 kg          # Ref 1, Mp
#      fuel_mass              36872.0 lbs         # Brian's value

      # Dry 2146.75 + 200 inter-stage = 2346.75

      #specific_impulse       296 sec             # Ref 1 vacuum
      #burn_rate              93.1138 kg/s        # fuel_mass / thrust_duration
      thrust_duration        180 sec             # Ref 1
      thrust                 29600 kgf           # Ref 1
   end_stage

   stage 3
      aero                   RED_ICBM_2_STAGE_3_AERO
      total_mass             2422 kg             # Ref 1, Mi
      fuel_mass              1804 kg             # Ref 1, Mp (1589-1804 given)
#      fuel_mass              3968.0 lbs          # Brian's value

      #empty_mass             833 kg              # Ref 1, Mf
      #Dry 246, Adapter 37, Shroud 250

      #specific_impulse       289 sec             # Ref 1
      #burn_rate              72.16 kg/s          # fuel_mass / thrust_duration
      # The thrust duration was quoted as either 25 or 28. 25 was chosen because it
      # results in the 317 sec total burn time that was quoted.
      thrust_duration        25 sec              # Ref 1 (25, 28 given)
      thrust                 18354.89 kgf        # Ref 1
   end_stage

   stage 4
      aero                   RED_ICBM_2_RV_AERO
#      total_mass             300 kg              # Ref 1
      total_mass             2200 lbs            # Brian's value
   end_stage
end_mover

###############################################################################

processor RED_ICBM_2_GUIDANCE WSF_GUIDANCE_COMPUTER

   # Go vertical for a short time.

   phase LIFTOFF
      guidance_delay                   100.0 sec

      # NOTE: Do not use altitude for the criteria for starting pitch over as
      # trajectory is VERY sensitive to the TIME when pitch over starts. If it
      # were to be used, a minor changes in the launcher altitude would cause
      # pitch over to start at a different time!

      next_phase PITCH_OVER when phase_time >= 2.0 sec     # About 100 ft
   end_phase

   # Pitch over to the desired flight path angle from the launch computer.

   phase PITCH_OVER
      commanded_flight_path_angle      from_launch_computer
      proportional_navigation_gain     0.0                 # Don't guide to target
      velocity_pursuit_gain            0.0                 # Don't guide to target
      maximum_commanded_g              1.0 g
      next_phase BALLISTIC when on_commanded_flight_path_angle
   end_phase

   # Continue flight without guidance (gravity turn).

   phase BALLISTIC
      # Turn the guidance processor off once pure ballistic mode is started.
      # This shaves several percent off the processor time.
      on_entry
         TurnOff();
      end_on_entry
      guidance_delay                   9000.0 sec
   end_phase

end_processor

###############################################################################

platform_type RED_ICBM_2 WSF_PLATFORM
   icon Scud_Missile

   infrared_signature RED_ICBM_2_INFRARED_SIG
   optical_signature  RED_ICBM_2_OPTICAL_SIG
   radar_signature    RED_ICBM_2_RADAR_SIG

   weapon_effects     RED_ICBM_2_EFFECT

   mover RED_ICBM_2_MOVER
      #show_status
   end_mover

   processor guidance RED_ICBM_2_GUIDANCE
      #show_status
      #show_graphics
   end_processor

   processor fuse WSF_GROUND_TARGET_FUSE
      # If the target is killed by another weapon we want to still keep going.
      coast_time_on_loss_of_target     10000.0 secs
   end_processor

   weapon stage_1 WSF_EXPLICIT_WEAPON
      launched_platform_type RED_ICBM_2_SPENT_STAGE_1
      launch_delta_v         -100.0 0.0 0.0 m/s
      quantity 1
   end_weapon

   weapon stage_2 WSF_EXPLICIT_WEAPON
      launched_platform_type RED_ICBM_2_SPENT_STAGE_2
      launch_delta_v         -100.0 0.0 0.0 m/s
      quantity 1
   end_weapon

   weapon stage_3 WSF_EXPLICIT_WEAPON
      launched_platform_type RED_ICBM_2_SPENT_STAGE_3
      launch_delta_v         -100.0 0.0 0.0 m/s
      quantity 1
   end_weapon

   script void on_stage_separation(int aStage)
      extern Map<string, bool> SHOW_SPENT_STAGES;
      if (SHOW_SPENT_STAGES["ALL"] ||
          SHOW_SPENT_STAGES["RED_ICBM_2"])
      {
         if (aStage == 1) Weapon("stage_1").Fire(WsfTrack());
         if (aStage == 2) Weapon("stage_2").Fire(WsfTrack());
         if (aStage == 3) Weapon("stage_3").Fire(WsfTrack());
      }
   end_script
end_platform_type

###############################################################################

launch_computer RED_ICBM_2_LAUNCH_COMPUTER WSF_BALLISTIC_MISSILE_LAUNCH_COMPUTER
   surface_to_surface_table weapons/ssm/red_icbm_2_launch_data.txt
end_launch_computer

###############################################################################
# Provide the aero and mass data to WSF_BALLISTIC_MISSILE_LAUNCH_COMPUTER. This
# is 'truth data' used by the launch computer for 'trajectory estimation'.

ballistic_missile_launch_computer
   target_data RED_ICBM_2
      aero RED_ICBM_2_RV_AERO               # Aero type of final stage
      mass 2200 lbs                    # Mass of final stage
   end_target_data
end_ballistic_missile_launch_computer

###############################################################################

weapon RED_ICBM_2 WSF_EXPLICIT_WEAPON

   # The location offset puts the weapon center at half the length - 1 m.
   # This assumes the scenario creator puts the launching platform at 1 m agl.

   location 0.0 0.0 -15.915 m                     # Ref 1, length = 33.83 m

   launched_platform_type RED_ICBM_2

   launch_computer RED_ICBM_2_LAUNCH_COMPUTER
   end_launch_computer

   # The missiles are launched vertically.
   # We can't specify 90 degrees because of a singularity
   tilt  89.9 degrees

   # This causes a call to the launch computer to compute the predicted intercept.
   # The launcher will then be cued to the proper angles (Subject to the slewing
   # limits defined below). This is a bit of a hack until the guidance computer
   # is changed...

   cue_to_predicted_intercept true
   slew_mode azimuth
   azimuth_slew_limits -180 deg 180 deg

   # Default to a single weapon on the vehicle
   quantity 1

   # Abort the launch if the launch computer didn't provide the required data
   require_loft_angle

end_weapon
