home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 February / Gamestar_81_2006-02_dvd.iso / Red Shark / Common / Helicopter.script < prev    next >
Encoding:
Text File  |  2002-01-22  |  13.8 KB  |  517 lines

  1. //-------------------------------------------------------------------
  2. //
  3. //  This code is copyright 2001 by G5 Software.
  4. //  Any unauthorized usage, either in part or in whole of this code
  5. //  is strictly prohibited. Violators WILL be prosecuted to the
  6. //  maximum extent allowed by law.
  7. //
  8. //-------------------------------------------------------------------
  9.  
  10. class CHelicopterMesh
  11. {
  12.   string MeshFile = "Models/Helicopter.mesh";
  13.   string SkinFile = "Models/Helicopter.skin";
  14.   string AnimFile = "Models/Helicopter.anim";
  15. }
  16.  
  17. class CHelicopterSmokeGenerator
  18. {
  19.   string DustItemEffect = "EFFECTID_HelicopterSmokeTrackEffect";
  20.   float  ItemsPerSecond = 1000.0;
  21.  
  22.   void StartSmokeGeneration()
  23.   {
  24.     EnableDustGeneration();
  25.   }
  26.  
  27.   void StopSmokeGeneration()
  28.   {
  29.     DisableDustGeneration();
  30.   }
  31. }
  32.  
  33. class CHelicopterCollision
  34. {
  35.   float  MaxPositionHeight   = 1100.0f;
  36.   float  PositionRestriction = 500.0f;
  37.   float  RotationSpeed       = 4.0f;
  38.   float  RotateReturnSpeed   = 0.5f;
  39.   float  MaxRotationAngle    = Math_HALFPI * 0.5f;
  40.   float  ThrowMoveFactor     = 0.15;
  41.   float  ThrowRotateFactor   = 0.01f;
  42.   float  ThrowMoveDamper     = 0.5f;
  43.   string CollisionJointName  = "Hull_Collision_Map";
  44.   string CollisionEffect     = "";
  45.   string CollisionSound      = "SOUNDID_HelicopterCollisionSound";
  46.  
  47.   void DisableCollisionControl()
  48.   {
  49.     EnableObjectControl(false);
  50.   }
  51.  
  52.   void SetTerrainCollisionMode()
  53.   {
  54.     RestrictCollisionTo(CLASSIFICATOR_TERRAIN);
  55.   }
  56. }
  57.  
  58. class CHelicopterCameraLinkControl
  59. {
  60.   void CHelicopterCameraLinkControl()
  61.   {
  62.     SetDefaultCameraView();
  63.   }
  64.  
  65.   int m_CurrentViewMode = 0;
  66.   void OnSetCameraView(
  67.       int _ViewType
  68.     )
  69.   {
  70.     if (CVT_DefaultView == _ViewType)
  71.       SetDefaultCameraView();
  72.     else
  73.     if (CVT_NextView == _ViewType)
  74.       SetCameraView(m_CurrentViewMode + 1);
  75.   }
  76.  
  77.   void SetDefaultCameraView()
  78.   {
  79.     SetCameraView(0);
  80.   }
  81.  
  82.   void SetCameraView(
  83.       int _Mode
  84.     )
  85.   {
  86.     m_CurrentViewMode = _Mode % 7;
  87.  
  88.     string RenderMode = CRM_Cocpit;
  89.     if (0 != _Mode)
  90.       RenderMode = CRM_WideScreen;
  91.  
  92.     Core_SendEventTo(
  93.         Core_GetIdentificator(),
  94.         "SetCocpitRenderMode",
  95.         RenderMode
  96.       );
  97.  
  98.     if (0 == _Mode)
  99.     {
  100.       SetCameraPosition(CRDSYS_Local, vector(-34.0, 0.0, -4.0), -1.0, 12.0);
  101.       SetCameraViewTarget(CRDSYS_Local, vector(4000.0, 0.0, 0.0), true, -1.0);
  102.       return;
  103.     }
  104.     else
  105.     if (1 == _Mode)
  106.     {
  107.       SetCameraPosition(CRDSYS_Origin, vector(-1.0, 0.0, 0.0), -1.0, 30.0);
  108.       SetCameraViewTarget(CRDSYS_Local, vector(0.0, 0.0, 0.0), false, -1.0);
  109.       return;
  110.     }
  111.     else
  112.     if (2 == _Mode)
  113.     {
  114.       SetCameraPosition(CRDSYS_Local, vector(25.0, 0.0, 0.0), -1.0, 10.0);
  115.       SetCameraViewTarget(CRDSYS_Local, vector(0.0, 0.0, 0.0), false, -1.0);
  116.       return;
  117.     }
  118.     else
  119.     if (3 == _Mode)
  120.     {
  121.       SetCameraPosition(CRDSYS_Local, vector(0.0, 25.0, 0.0), -1.0, 10.0);
  122.       SetCameraViewTarget(CRDSYS_Local, vector(0.0, 0.0, 0.0), false, -1.0);
  123.       return;
  124.     }
  125.     else
  126.     if (4 == _Mode)
  127.     {
  128.       SetCameraPosition(CRDSYS_Local, vector(0.0, -25.0, 0.0), -1.0, 10.0);
  129.       SetCameraViewTarget(CRDSYS_Local, vector(0.0, 0.0, 0.0), false, -1.0);
  130.       return;
  131.     }
  132.  
  133.     SetDefaultCameraView();
  134.   }
  135.  
  136.   void ShowHelicopterDeath()
  137.   {
  138.     vector CameraPosition = Core_GetMatrixOrigin(GetCurrentCameraPosition());
  139.     vector ObjectPosition = Core_GetMatrixOrigin(GetCurrentObjectPosition());
  140.  
  141.     vector Position = CameraPosition - ObjectPosition;
  142.     Position = vector(Core_GetVectorX(Position), Core_GetVectorY(Position), 0.0);
  143.     Position = (150.0 / Core_Magnitude(Position)) * Position + vector(0.0, 0.0, 40.0);
  144.  
  145.     SetCameraPosition(CRDSYS_Origin, Position, 35.0, 0.0);
  146.     SetCameraViewTarget(CRDSYS_Origin, vector(0.0, 0.0, 0.0), false, Math_PI * 0.1);
  147.   }
  148.  
  149.   void ShowHelicopterFinal()
  150.   {
  151.     vector CameraPosition = Core_GetMatrixOrigin(GetCurrentCameraPosition());
  152.     vector ObjectPosition = Core_GetMatrixOrigin(GetCurrentObjectPosition());
  153.  
  154.     vector Position = CameraPosition - ObjectPosition;
  155.     Position = vector(Core_GetVectorX(Position), Core_GetVectorY(Position), 0.0);
  156.     Position = (75.0 / Core_Magnitude(Position)) * Position + vector(0.0, 0.0, 25.0);
  157.  
  158.     SetCameraPosition(CRDSYS_Origin, Position, 10.0, 0.0);
  159.   }
  160. }
  161.  
  162. class CHelicopterStateControl extends CUnitLifeControl, CDifficultyLevel
  163. {
  164.   bool m_FreeFallEnabled = false;
  165.   bool m_ObjectDetonated = false;
  166.  
  167.   void CHelicopterStateControl()
  168.   {
  169.     CUnitLifeControl(GetHelicopterHP());
  170.     m_DestroyPause = 0.0;
  171.     m_ExplosionId  = "";
  172.     m_SplashOnHit  = false;
  173.   }
  174.  
  175.   void HitpointsWasChanged(
  176.       float _NowHitpoints
  177.     )
  178.   {
  179.     Core_SendEventTo(Core_GetIdentificator(),
  180.       "OnHitpointsWasChanged", _NowHitpoints / m_MaxHitpoints);
  181.   }
  182.  
  183.   void DestroyComponent()
  184.   {
  185.     Core_SendEventTo(
  186.       Core_GetIdentificator(),
  187.       "OnSetCameraView",
  188.       CVT_DefaultView);
  189.  
  190.     Core_SendEventTo(
  191.       Core_GetIdentificator(),
  192.       "StartFreeFall",
  193.       GetUnitSpeed());
  194.  
  195.     Core_SendEventTo(
  196.       Core_GetIdentificator(),
  197.       "StartSmokeGeneration");
  198.  
  199.     // make spherical damage on collision
  200.     Core_DistributeEvent(
  201.         1.0,
  202.         "OnDetonation",
  203.         "SphericExplosion",   // source type (explosion type)
  204.         GetUnitPosition(),  // source place
  205.         50.0
  206.       );
  207.  
  208.     Core_SendEventTo(Core_GetIdentificator(), "ShowHelicopterDeath");
  209.  
  210.     m_FreeFallEnabled = true;
  211.   }
  212.  
  213.   void OnCollisionOccured(
  214.       float _fPower
  215.     )
  216.   {
  217.     bool ToDestroy = m_IsExploded;
  218.  
  219.     OnToDamage(
  220.         GetCollisionDamageFactor() * m_MaxHitpoints * _fPower / m_DeathPower,
  221.         Core_GetIdentificator(),
  222.         "Collision",
  223.         GetUnitPosition()
  224.       );
  225.  
  226.     if (!m_FreeFallEnabled || !ToDestroy)
  227.       return;
  228.  
  229.     if (m_ObjectDetonated)
  230.       return;
  231.     m_ObjectDetonated = true;
  232.  
  233.     Core_SendEventTo(Core_GetIdentificator(), "StopEngineSound");
  234.     Core_SendEventTo(Core_GetIdentificator(), "StopFreeFall");
  235.     Core_SendEventTo(Core_GetIdentificator(), "ShowHelicopterFinal");
  236.     Core_SendEventTo(Core_GetIdentificator(), "StartSmokeGeneration");
  237.  
  238.     Core_CallFunction(
  239.       "Explosions",
  240.       "CreateExplosion",
  241.       "EXPLID_HelicopterExplosion",
  242.       GetUnitPosition());
  243.  
  244.     Core_CallFunction(
  245.       "Effects",
  246.       "CreateEffect",
  247.       "EFFECTID_HelicopterSmokeEffect",
  248.       GetUnitPosition());
  249.  
  250.     GenerateBullets(
  251.         50,
  252.         "BULLETID_ExplosionFireSplash",
  253.         array(0.0, Math_HALFPI),
  254.         0,
  255.         array(0.0, 3.0),
  256.         array(70.0, 90.0),
  257.         GetUnitPosition()
  258.       );
  259.  
  260.     GenerateBullets(
  261.         10,
  262.         "BULLETID_ExplosionSmokeSplash",
  263.         array(0.0, Math_HALFPI),
  264.         0,
  265.         array(0.0, 1.5),
  266.         array(40.0, 50.0),
  267.         GetUnitPosition()
  268.       );
  269.  
  270.     // Destroy object
  271.     Core_PostEventTo(
  272.         SOID_MissionController,
  273.         "DestroyGameObject",
  274.         Core_GetIdentificator()
  275.       );
  276.   }
  277.  
  278.   void ConsoleCommand_SetImmortalMode(
  279.       bool _ImmortalMode
  280.     )
  281.   {
  282.     m_ImmortalMode = _ImmortalMode;
  283.     if (m_ImmortalMode)
  284.       Core_LogMessage("immortal mode on");
  285.     else
  286.       Core_LogMessage("immortal mode off");
  287.   }
  288. }
  289.  
  290. class CHelicopterFreeFallControl extends CWorldPhysics
  291. {
  292.   void CHelicopterFreeFallControl()
  293.   {
  294.     EnableFreeFall(false);
  295.   }
  296.  
  297.   void StartFreeFall(
  298.       vector _InitSpeed
  299.     )
  300.   {
  301.     Core_SendEventTo(
  302.       Core_GetIdentificator(),
  303.       "DisableCollisionControl");
  304.  
  305.     Core_SendEventTo(
  306.       Core_GetIdentificator(),
  307.       "SetTerrainCollisionMode");
  308.  
  309.     Core_CallFunction(
  310.         SOID_GameController,
  311.         "EnableControl",
  312.         Core_GetIdentificator(),
  313.         false
  314.       );
  315.  
  316.     SetFreeFallSpeed(_InitSpeed);
  317.     SetFreeFallAccel(g_Gravity);
  318.     SetFreeFallAngle(Math_PI * 0.05, Math_PI * 0.001);
  319.  
  320.     EnableFreeFall(true);
  321.   }
  322.  
  323.   void StopFreeFall()
  324.   {
  325.     EnableFreeFall(false);
  326.   }
  327. }
  328.  
  329. class CHelicopterRotorAnimator
  330. {
  331.   string AnimationName = "rotor";
  332.   float  SpeedFactor   = 0.15;
  333. }
  334.  
  335. class CHelicopterGun extends CBaseWeaponDescriptor
  336. {
  337.   int    AmmoQuantity      = -1;
  338.   float  BulletSpeed       = 600.0;
  339.   float  FireDeviation     = 0.005;
  340.   string BulletPatternId   = "BULLETID_HelicopterGunBullet";
  341.   string LinkJointName     = "_Gun_Fire_01";
  342.   string EffectOnFire      = "EFFECTID_HelicopterGunFireEffect";
  343.   string SoundOnFire       = "SOUNDID_HelicopterGunFireSound";
  344.   float  TargetingRange    = 3.0;
  345.  
  346.   string WeaponName        = "Gun";
  347.   float  FireWeaponDelay   = 0.15;
  348.   bool   IsAutotargeting   = false;
  349.   int    AttachSlotNumber  = 0;
  350. }
  351.  
  352. class CHelicopterMissileWeapon extends CBaseWeaponDescriptor
  353. {
  354.   void ConsoleCommand_LoadFullAmmo()
  355.   {
  356.     ResetAmmoQuantity();
  357.   }
  358.  
  359.   void ConsoleCommand_SetUnlimitedAmmo(
  360.       bool _Unlimited
  361.     )
  362.   {
  363.     if (_Unlimited)
  364.       ResetAmmoQuantity();
  365.  
  366.     SetUnlimitedAmmo(_Unlimited);
  367.  
  368.     if (_Unlimited)
  369.       Core_LogMessage("unlimited ammo on");
  370.     else
  371.       Core_LogMessage("unlimited ammo off");
  372.   }
  373. }
  374.  
  375. class CHelicopterS8Launcher extends CHelicopterMissileWeapon, CDifficultyLevel
  376. {
  377.   int    AmmoQuantity      = GetS8MissileQuantity();
  378.   float  BulletSpeed       = 250.0;
  379.   float  FireDeviation     = 0.0;
  380.   string LinkJointName     = "";
  381.   string EffectOnFire      = "";
  382.   string FireCloudEffect   = "EFFECTID_HelicopterRocketFireCloudEffect";
  383.   string SoundOnFire       = "SOUNDID_HelicopterMissileFireSound";
  384.   float  TargetingRange    = 5.0;
  385.  
  386.   float  FireWeaponDelay   = 1.0;
  387.   bool   IsAutotargeting   = false;
  388.   string BulletPatternId   = "BULLETID_HelicopterRocket";
  389.  
  390.   bool   NotifyOnFire      = true;
  391. }
  392.  
  393. class CHelicopterVikhrLauncher extends CHelicopterMissileWeapon, CDifficultyLevel
  394. {
  395.   int    AmmoQuantity      = GetVikhrMissileQuantity();
  396.   float  BulletSpeed       = 200.0;
  397.   float  FireDeviation     = 0.0;
  398.   string LinkJointName     = "";
  399.   string EffectOnFire      = "";
  400.   string FireCloudEffect   = "EFFECTID_HelicopterRocketFireCloudEffect";
  401.   string SoundOnFire       = "SOUNDID_HelicopterMissileFireSound";
  402.   float  TargetingRange    = 0.0;
  403.  
  404.   float  FireWeaponDelay   = 1.0;
  405.   bool   IsAutotargeting   = true;
  406.   string BulletPatternId   = "BULLETID_HelicopterMissile";
  407.  
  408.   bool   NotifyOnFire      = true;
  409. }
  410.  
  411. class CHelicopterMissileLauncher_1 extends CHelicopterVikhrLauncher
  412. {
  413.   string LinkJointName     = "_Gun_Fire_05";
  414.   string WeaponName        = "Launcher 1";
  415.   int    AttachSlotNumber  = 1;
  416. }
  417.  
  418. class CHelicopterMissileLauncher_2 extends CHelicopterS8Launcher
  419. {
  420.   string LinkJointName     = "_Gun_Fire_04";
  421.   string WeaponName        = "Launcher 2";
  422.   int    AttachSlotNumber  = 2;
  423. }
  424.  
  425. class CHelicopterMissileLauncher_3 extends CHelicopterS8Launcher
  426. {
  427.   string LinkJointName     = "_Gun_Fire_02";
  428.   string WeaponName        = "Launcher 3";
  429.   int    AttachSlotNumber  = 3;
  430. }
  431.  
  432. class CHelicopterMissileLauncher_4 extends CHelicopterVikhrLauncher
  433. {
  434.   string LinkJointName     = "_Gun_Fire_03";
  435.   string WeaponName        = "Launcher 4";
  436.   int    AttachSlotNumber  = 4;
  437. }
  438.  
  439. class CHelicopter extends
  440.   CFlyingUnit, CArmedUnit, CUnitWithSound, CUnitWithCamera, CUnitWithStateControl
  441. {
  442.   void CreateRotorEffect(
  443.       string Name,
  444.       string Joint
  445.     )
  446.   {
  447.     CreateComponent(Name + "Effect", "StaticEffect", "CHelicopterRotorEffect");
  448.     CreateComponent(Name + "Link", "ObjectEffectLink");
  449.     SetComponentSlaveObject(Name + "Link", Name + "Effect");
  450.     SetComponentPositionable(Name + "Link", "Mesh", Joint);
  451.   }
  452.  
  453.   void CHelicopter()
  454.   {
  455.     InitializeModelAsAnimated("CHelicopterMesh");
  456.     InitializeSound("CHelicopterEngineSound");
  457.     InitializeCamera("CHelicopterCameraLinkControl");
  458.     CUnitWithStateControl("CHelicopterStateControl");
  459.  
  460.     CreateComponent("Rotor", "CircledAnimator", "CHelicopterRotorAnimator");
  461.     SetComponentSlaveObject("Rotor", "Mesh");
  462.  
  463.     CreateStaticWeapon("Weapon", "CHelicopterGun");
  464.  
  465.     CreateStaticWeapon("Missile_1", "CHelicopterMissileLauncher_1");
  466.     CreateStaticWeapon("Missile_2", "CHelicopterMissileLauncher_2");
  467.     CreateStaticWeapon("Missile_3", "CHelicopterMissileLauncher_3");
  468.     CreateStaticWeapon("Missile_4", "CHelicopterMissileLauncher_4");
  469.  
  470.     CreateComponent("Collision", "CollisionControl", "CHelicopterCollision");
  471.     SetComponentSlaveObject("Collision", "Mesh");
  472.  
  473.     CreateRotorEffect("RotorUp", "RH_up");
  474.     CreateRotorEffect("RotorDown", "RH_down");
  475.  
  476.     CreateComponent("FreeFall", "FreeFallControl", "CHelicopterFreeFallControl");
  477.     SetComponentSlaveObject("FreeFall", "Mesh");
  478.  
  479.     CreateComponent("SmokeGenerator", "DustGenerator", "CHelicopterSmokeGenerator");
  480.     SetComponentPositionable("SmokeGenerator", "Mesh");
  481.  
  482.     Core_AddClassificator("FlyingUnit"); // for behavior fire logic
  483.   }
  484. }
  485.  
  486. class CSovietHelicopter extends CHelicopter
  487. {
  488.   void CSovietHelicopter()
  489.   {
  490.     Core_AddClassificator("Russian");
  491.   }
  492. }
  493.  
  494. class CPlayerSovietHelicopter extends CSovietHelicopter
  495. {
  496.   void CPlayerSovietHelicopter()
  497.   {
  498.     // Create movement manual control
  499.     CreateComponent("Manual", "ManualObjectControl");
  500.     SetComponentSlaveObject("Manual", "Mesh");
  501.  
  502.     // Create and initialize cockpit
  503.     CreateComponent("Cockpit", "Cockpit", "CHelicopterCockpit");
  504.     SetComponentPositionable("Cockpit", "Mesh");
  505.  
  506.     for (int Index = 0; Index < m_WeaponNames.size(); Index = Index + 1)
  507.       SetComponentSlaveObject("Cockpit", m_WeaponNames[Index]);
  508.  
  509.     // this classificator marks the model controlled by player in the game
  510.     // it is used by ShadowRender to select the shadow page of the
  511.     // corresponding size
  512.     Core_AddClassificator(CLASSIFICATOR_PLAYER_MODEL);
  513.     Core_AddClassificator(CLASSIFICATOR_CONTROLLABLE);
  514.   }
  515. }
  516.  
  517.