NashGoreActor.zc 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. // Copyright 2006-2019 Nash Muhandes
  2. // All rights reserved.
  3. //
  4. // Redistribution and use in source and binary forms, with or without
  5. // modification, are permitted provided that the following conditions
  6. // are met:
  7. //
  8. // 1. Redistributions of source code must retain the above copyright
  9. // notice, this list of conditions and the following disclaimer.
  10. // 2. Redistributions in binary form must reproduce the above copyright
  11. // notice, this list of conditions and the following disclaimer in the
  12. // documentation and/or other materials provided with the distribution.
  13. // 3. The name of the author may not be used to endorse or promote products
  14. // derived from this software without specific prior written permission.
  15. //
  16. // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  17. // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  18. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  19. // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  25. // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. //===========================================================================
  27. //
  28. //
  29. //
  30. //===========================================================================
  31. class NashGoreActor : NashGorePlugin
  32. {
  33. bool bSuperTicked;
  34. bool bCanBleed;
  35. bool bIsDead;
  36. bool bMirroredDeathSprite;
  37. bool bGibbed;
  38. bool bCorpseBlood;
  39. bool bShattered;
  40. bool bSquished;
  41. const MAX_FALLTICS = 20;
  42. int fallTics;
  43. const MAX_FOOTPRINT_DURATION = 65;
  44. const FOOTPRINT_INTERVAL = 7;
  45. int footprintFootSide;
  46. int footprintDuration;
  47. int footprintSpawnInterval;
  48. NashGoreCorpseBlood lastCorpseBlood;
  49. //===========================================================================
  50. //
  51. //
  52. //
  53. //===========================================================================
  54. override void Tick(void)
  55. {
  56. if (!bSuperTicked)
  57. {
  58. Super.Tick();
  59. bSuperTicked = true;
  60. }
  61. if (!bNoTimeFreeze && (isFrozen() || Level.isFrozen())) return;
  62. if (!Owner) return;
  63. // footprint stuff (only for players)
  64. if (Owner is "PlayerPawn")
  65. {
  66. footprintSpawnInterval--;
  67. if (NashGoreStatics.GetVelocity(Owner) > 0 && NashGoreStatics.bIsOnFloor(Owner) && footprintDuration > 0)
  68. {
  69. footprintDuration--;
  70. if (footprintSpawnInterval <= 0)
  71. {
  72. // lower intervals produce more dense footprints
  73. footprintSpawnInterval = FOOTPRINT_INTERVAL;
  74. bool result;
  75. Actor footprint;
  76. // find the last corpse blood that was stepped on
  77. if (lastCorpseBlood && lastCorpseBlood.target)
  78. {
  79. int flags = SXF_USEBLOODCOLOR | SXF_NOCHECKPOSITION | SXF_ABSOLUTEANGLE;
  80. double ang = Owner.Angle;
  81. [result, footprint] =
  82. lastCorpseBlood.target.A_SpawnItemEx("NashGoreFootprint", angle: ang, flags);
  83. //Console.Printf("%s", lastCorpseBlood.target.GetClassName());
  84. if (footprint)
  85. {
  86. // calculate footprint spawn offset
  87. if (footprintFootSide == 0) footprintFootSide = 1;
  88. else if (footprintFootside == 1) footprintFootSide = 0;
  89. double feetDistance = 5;
  90. double angAdjust = 90 * ((footprintFootSide == 0) ? -1 : 1);
  91. Vector3 sPos =
  92. (
  93. Owner.Pos.X + cos(ang + angAdjust) * feetDistance,
  94. Owner.Pos.Y + sin(ang + angAdjust) * feetDistance,
  95. Owner.Pos.Z
  96. );
  97. // move footprint to position
  98. footprint.SetOrigin(sPos, false);
  99. }
  100. }
  101. }
  102. }
  103. }
  104. // death stuff
  105. if (bIsDead)
  106. {
  107. // randomly mirror death sprite
  108. if (nashgore_deathflip && !Owner.bIceCorpse && !bMirroredDeathSprite)
  109. {
  110. NashGoreStatics.RandomXFlip(Owner);
  111. bMirroredDeathSprite = true;
  112. }
  113. // spawn corpse blood when it's stopped moving
  114. if (Owner.Vel ~== (0, 0, 0) && !bCorpseBlood && !Owner.bIceCorpse && bCanBleed)
  115. {
  116. bool result;
  117. Actor corpseblood;
  118. [result, corpseblood] =
  119. Owner.A_SpawnItemEx("NashGoreCorpseBlood", flags: SXF_USEBLOODCOLOR);
  120. // footprint colour needs pointer to owner
  121. if (corpseblood) corpseblood.target = Owner;
  122. // spawn blood spurts
  123. if (nashgore_bloodspurt) Owner.A_SpawnItemEx("NashGoreBloodSpurtSpawner", flags: SXF_USEBLOODCOLOR, 200);
  124. bCorpseBlood = true;
  125. }
  126. // falling death. SPLAT!
  127. if (nashgore_splat && Owner.waterlevel < 2)
  128. {
  129. if (fallTics < MAX_FALLTICS && !NashGoreStatics.bIsOnFloor(Owner)) fallTics++;
  130. if (fallTics == MAX_FALLTICS && NashGoreStatics.bIsOnFloor(Owner) && !Owner.bIceCorpse)
  131. {
  132. Owner.A_PlaySound("nashgore/bodydrop");
  133. if (bCanBleed)
  134. {
  135. for (int i = 0; i < 20; i++)
  136. {
  137. Owner.A_SpawnItemEx("NashGoreBloodSpurt",
  138. frandom(-4, 4), frandom(-4, 4), frandom(10, 20),
  139. frandom(-4.0, 4.0), frandom(-4.0, 4.0), frandom(5.0, 10.0),
  140. frandom(0, 360), SXF_USEBLOODCOLOR);
  141. }
  142. }
  143. fallTics = MAX_FALLTICS + 1;
  144. }
  145. }
  146. if (nashgore_squish)
  147. {
  148. int spawnFlags = SXF_USEBLOODCOLOR | SXF_NOCHECKPOSITION;
  149. double crushHeight = (Owner.Pos.Z + Owner.Height) + Owner.GetDeathHeight();
  150. if (Owner.CeilingZ <= crushHeight && Owner.Pos.Z <= Owner.FloorZ && !bSquished)
  151. {
  152. if (bCanBleed)
  153. {
  154. // spawn crushed gib based on size
  155. if (Owner.Radius <= 20)
  156. {
  157. Owner.A_SpawnItemEx("NashGoreCrushedGibsSmall", flags: spawnFlags);
  158. }
  159. else if (Owner.Radius > 20 && Owner.Radius < 40)
  160. {
  161. Owner.A_SpawnItemEx("NashGoreCrushedGibsMedium", flags: spawnFlags);
  162. }
  163. else if (Owner.Radius >= 40)
  164. {
  165. Owner.A_SpawnItemEx("NashGoreCrushedGibsLarge", flags: spawnFlags);
  166. }
  167. }
  168. bSquished = true;
  169. }
  170. }
  171. // gibbed stuff
  172. bool canGib =
  173. (
  174. Owner.Health < Owner.GetGibHealth() ||
  175. (Owner.FindState('XDeath', true) != NULL && Owner.InStateSequence(Owner.CurState, Owner.ResolveState('XDeath')))
  176. );
  177. if (!bGibbed && canGib && bCanBleed)
  178. {
  179. NashGoreGibs.SpawnGibs(Owner);
  180. bGibbed = true;
  181. }
  182. // spawn ice gore stuff
  183. if (Owner.bShattering && !bShattered && bCanBleed)
  184. {
  185. bShattered = true;
  186. for (int i = 0; i < 20; i++)
  187. {
  188. Owner.A_SpawnItemEx("NashGoreGibs",
  189. zofs: Owner.Height,
  190. frandom(-2, 2), frandom(-2, 2), frandom(-4, 4),
  191. flags: spawnFlags, 125);
  192. }
  193. }
  194. }
  195. }
  196. //===========================================================================
  197. //
  198. //
  199. //
  200. //===========================================================================
  201. void ResetActor(void)
  202. {
  203. bIsDead = false;
  204. bCorpseBlood = false;
  205. bGibbed = false;
  206. fallTics = 0;
  207. footprintDuration = 0;
  208. lastCorpseBlood = NULL;
  209. bMirroredDeathSprite = false;
  210. Owner.bSpriteFlip = false;
  211. }
  212. }