wreck_santassleigh.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //Christmas Event: Santa's Sleigh
  2. class Wreck_SantasSleigh extends CrashBase
  3. {
  4. XmasSleighLight m_SleighLight;
  5. int m_MaxDeersAmount = 4;
  6. int m_MinDeersAmount = 2;
  7. int m_MaxDeersSpawnRange = 25;
  8. int m_MinDeersSpawnRange = 5;
  9. void Wreck_SantasSleigh()
  10. {
  11. if (!GetGame().IsDedicatedServer())
  12. {
  13. //particles - Aurora trail
  14. m_ParticleEfx = ParticleManager.GetInstance().PlayOnObject(ParticleList.AURORA_SANTA_WRECK,this,vector.Zero,vector.Zero,true);
  15. //lights - green light
  16. m_SleighLight = XmasSleighLight.Cast(ScriptedLightBase.CreateLight(XmasSleighLight,vector.Zero));
  17. m_SleighLight.AttachOnMemoryPoint(this, "light");
  18. }
  19. }
  20. // needs to have the soundset registered in CrashBase.Init()
  21. override string GetSoundSet()
  22. {
  23. return "SledgeCrash_Distant_SoundSet";
  24. }
  25. override void EEOnCECreate()
  26. {
  27. super.EEOnCECreate();
  28. SpawnRandomDeerLater();
  29. }
  30. override void EEDelete(EntityAI parent)
  31. {
  32. super.EEDelete(parent);
  33. if ( !GetGame().IsDedicatedServer() )
  34. {
  35. if ( m_SleighLight )
  36. m_SleighLight.Destroy();
  37. }
  38. }
  39. void SpawnRandomDeerLater()
  40. {
  41. //SpawnRandomDeers();
  42. GetGame().GetCallQueue( CALL_CATEGORY_GAMEPLAY ).CallLater( SpawnRandomDeers, 0);
  43. }
  44. //Spawn a random amount of (dead) deers around the sleigh
  45. void SpawnRandomDeers()
  46. {
  47. EntityAI deer;
  48. vector crash_pos = GetPosition();
  49. int deersAmount = Math.RandomIntInclusive(m_MinDeersAmount,m_MaxDeersAmount);
  50. for (int i = 0; i < m_MaxDeersAmount; i++)
  51. {
  52. vector deer_pos = RandomizePosition(crash_pos);
  53. deer = EntityAI.Cast(GetGame().CreateObject("Animal_RangiferTarandus", deer_pos,false, true));
  54. deer.SetHealth01("","", 0);
  55. vector orientation = deer.GetOrientation();
  56. deer.SetOrientation(Vector(Math.RandomIntInclusive(0,360),orientation[1],orientation[2]));
  57. }
  58. //spawns xmas reindeer
  59. deer_pos = RandomizePosition(crash_pos);
  60. deer = EntityAI.Cast(GetGame().CreateObject("Animal_RangiferTarandus_Xmas", deer_pos,false, true));
  61. deer.SetHealth01("","", 0);
  62. vector redorientation = deer.GetOrientation();
  63. deer.SetOrientation(Vector(Math.RandomIntInclusive(0,360),redorientation[1],redorientation[2]));
  64. }
  65. //Return a new vector scattered around origin.
  66. vector RandomizePosition(vector origin)
  67. {
  68. int randX;
  69. int randZ;
  70. randX = Math.RandomIntInclusive(m_MinDeersSpawnRange, m_MaxDeersSpawnRange);
  71. if (Math.RandomIntInclusive(0,1) < 1)
  72. randX = -randX;
  73. randZ = Math.RandomIntInclusive(m_MinDeersSpawnRange, m_MaxDeersSpawnRange);
  74. if (Math.RandomIntInclusive(0,1) < 1)
  75. randZ = -randZ;
  76. origin[0] = origin[0] + randX;
  77. origin[2] = origin[2] + randZ;
  78. return origin;
  79. }
  80. }