dayzintroscene.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. class DayZIntroScene : Managed
  2. {
  3. protected ref IntroSceneCharacter m_Character;
  4. protected Camera m_Camera;
  5. protected vector m_CameraTrans[4];
  6. protected vector m_CharacterPos;
  7. protected vector m_CharacterRot;
  8. protected Weather m_Weather;
  9. protected vector m_Target;
  10. protected ref OptionsMenu m_OptionsMenu;
  11. void DayZIntroScene()
  12. {
  13. string root_path = "cfgCharacterScenes " + g_Game.GetWorldName();
  14. int count = g_Game.ConfigGetChildrenCount(root_path);
  15. int index = Math.RandomInt(0, count - 1);
  16. string childName;
  17. g_Game.ConfigGetChildName(root_path, index, childName);
  18. string scene_path = root_path + " " + childName;
  19. m_Target = SwapYZ(g_Game.ConfigGetVector(scene_path + " target"));
  20. vector position = SwapYZ(g_Game.ConfigGetVector(scene_path + " position"));
  21. TIntArray date = new TIntArray;
  22. TFloatArray storm = new TFloatArray;
  23. g_Game.ConfigGetIntArray(scene_path + " date", date);
  24. float fov = g_Game.ConfigGetFloat(scene_path + " fov");
  25. float overcast = g_Game.ConfigGetFloat(scene_path + " overcast");
  26. float rain = g_Game.ConfigGetFloat(scene_path + " rain");
  27. float snowfall = g_Game.ConfigGetFloat(scene_path + " snowfall");
  28. float fog = g_Game.ConfigGetFloat(scene_path + " fog");
  29. float windspeed = -1;
  30. if ( g_Game.ConfigIsExisting(scene_path + " windspeed") ) windspeed = g_Game.ConfigGetFloat(scene_path + " windspeed");
  31. g_Game.ConfigGetFloatArray(scene_path + " storm", storm);
  32. World world = g_Game.GetWorld();
  33. if (world && date.Count() >= 5)
  34. {
  35. world.SetDate(date.Get(0), date.Get(1), date.Get(2), date.Get(3), date.Get(4));
  36. }
  37. GetGame().ObjectDelete( m_Camera );
  38. Class.CastTo(m_Camera, g_Game.CreateObject("staticcamera", SnapToGround(position), true)); //Vector(position[0] , position[1] + 1, position[2])
  39. Math3D.MatrixIdentity4(m_CameraTrans);
  40. if (m_Camera)
  41. {
  42. //m_Camera.SetPosition(Vector(m_Camera.GetPosition()[0],m_Camera.GetPosition()[1]+0,m_Camera.GetPosition()[2]));
  43. m_Camera.LookAt(m_Target);
  44. m_Camera.SetFOV(fov);
  45. m_Camera.SetFocus(5.0, 0.0); //5.0, 1.0
  46. m_Camera.SetActive(true);
  47. Math3D.DirectionAndUpMatrix(m_Target - SnapToGround(position), "0 1 0", m_CameraTrans);
  48. m_CameraTrans[3] = m_Camera.GetPosition();
  49. m_CharacterPos = Vector(0.685547, -0.988281, 3.68823).Multiply4(m_CameraTrans);
  50. float pos_x = m_CharacterPos[0];
  51. float pos_z = m_CharacterPos[2];
  52. float pos_y = GetGame().SurfaceY(pos_x, pos_z);
  53. vector ground_demo_pos = Vector(pos_x, pos_y, pos_z);
  54. m_CharacterPos = ground_demo_pos;
  55. vector to_cam_dir = m_Camera.GetPosition() - m_CharacterPos;
  56. m_CharacterRot[0] = Math.Atan2(to_cam_dir[0], to_cam_dir[2]) * Math.RAD2DEG;
  57. }
  58. m_Weather = g_Game.GetWeather();
  59. m_Weather.GetOvercast().SetLimits( overcast, overcast );
  60. m_Weather.GetRain().SetLimits( rain, rain );
  61. m_Weather.GetSnowfall().SetLimits( snowfall, snowfall );
  62. m_Weather.GetFog().SetLimits( fog, fog );
  63. m_Weather.GetOvercast().Set( overcast, 0, 0);
  64. m_Weather.GetRain().Set( rain, 0, 0);
  65. m_Weather.GetSnowfall().Set( snowfall, 0, 0);
  66. m_Weather.GetFog().Set( fog, 0, 0);
  67. if ( storm.Count() == 3 )
  68. {
  69. m_Weather.SetStorm(storm.Get(0),storm.Get(1),storm.Get(2));
  70. }
  71. if ( windspeed != -1 )
  72. {
  73. m_Weather.SetWindSpeed(windspeed);
  74. m_Weather.SetWindMaximumSpeed(windspeed);
  75. m_Weather.SetWindFunctionParams(1,1,1);
  76. }
  77. m_Character = new IntroSceneCharacter();
  78. m_Character.LoadCharacterData(m_CharacterPos, m_CharacterRot);
  79. PPEffects.Init(); //Deprecated, left in for legacy purposes only
  80. GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(SetInitPostprocesses);
  81. }
  82. void ~DayZIntroScene()
  83. {
  84. if (PPEManagerStatic.GetPPEManager())
  85. PPEManagerStatic.GetPPEManager().StopAllEffects(PPERequesterCategory.ALL);
  86. }
  87. //==============================================
  88. // GetIntroSceneCharacter
  89. //==============================================
  90. IntroSceneCharacter GetIntroCharacter()
  91. {
  92. return m_Character;
  93. }
  94. //==============================================
  95. // GetIntroCamera
  96. //==============================================
  97. Camera GetIntroCamera()
  98. {
  99. return m_Camera;
  100. }
  101. //==============================================
  102. // ResetIntroCamera
  103. //==============================================
  104. void ResetIntroCamera()
  105. {
  106. if ( GetIntroCharacter().GetCharacterObj() )
  107. {
  108. GetIntroCamera().LookAt( GetIntroCharacter().GetPosition() + Vector( 0, 1, 0 ) );
  109. //GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater( SceneCharacterSetPos, 250 );
  110. }
  111. }
  112. //! Since this can get created at the same time as DayZGame, non-static postprocesses need to be deffered
  113. protected void SetInitPostprocesses()
  114. {
  115. PPERequesterBank.GetRequester(PPERequester_BurlapSackEffects).Stop();
  116. }
  117. protected void GetSelectedUserName()
  118. {
  119. string name;
  120. BiosUserManager user_manager = GetGame().GetUserManager();
  121. if( user_manager )
  122. {
  123. BiosUser user = user_manager.GetSelectedUser();
  124. if( user )
  125. {
  126. g_Game.SetPlayerGameName( user.GetName() );
  127. return;
  128. }
  129. }
  130. g_Game.SetPlayerGameName(GameConstants.DEFAULT_CHARACTER_NAME);
  131. }
  132. // ------------------------------------------------------------
  133. protected vector SwapYZ(vector vec)
  134. {
  135. vector tmp;
  136. tmp[0] = vec[0];
  137. tmp[1] = vec[2];
  138. tmp[2] = vec[1];
  139. return tmp;
  140. }
  141. // ------------------------------------------------------------
  142. protected vector SnapToGround(vector pos)
  143. {
  144. float pos_x = pos[0];
  145. float pos_z = pos[2];
  146. float pos_y = GetGame().SurfaceY(pos_x, pos_z);
  147. vector tmp_pos = Vector(pos_x, pos_y, pos_z);
  148. tmp_pos[1] = tmp_pos[1] + pos[1];
  149. return tmp_pos;
  150. }
  151. };