dayzintroscene.c 5.4 KB

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