NashGoreBloodPlane.zc 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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 NashGoreBloodPlane : Actor
  32. {
  33. Default
  34. {
  35. Height 2;
  36. FloatBobPhase 0;
  37. +NOGRAVITY
  38. }
  39. bool bSloped;
  40. bool bCheckedFloating;
  41. bool bOnCeiling;
  42. bool bStopTicking;
  43. int tryCheckFloating;
  44. double rndzoffset;
  45. double zOld, zNew;
  46. //===========================================================================
  47. //
  48. //
  49. //
  50. //===========================================================================
  51. override void BeginPlay(void)
  52. {
  53. ChangeStatNum(STAT_NashGore_Gore);
  54. NashGoreStatics.QueueGore();
  55. rndzoffset = frandom(0.0001, 0.0100);
  56. A_SetScale(frandom(0.9, 1.0));
  57. Super.BeginPlay();
  58. if (!level.IsPointInLevel(Pos))
  59. {
  60. Destroy();
  61. return;
  62. }
  63. }
  64. override void PostBeginPlay(void)
  65. {
  66. if (!bOnCeiling && Pos.Z > FloorZ) { Destroy(); return; }
  67. if (bOnCeiling) rndzoffset *= -1;
  68. if (!(self is "NashGoreFootPrint")) Angle = NashGoreStatics.RandomAngle4();
  69. zOld = zNew = Pos.Z;
  70. Super.PostBeginPlay();
  71. }
  72. override void Tick()
  73. {
  74. if (!bNoTimeFreeze && (isFrozen() || Level.isFrozen())) return;
  75. if (!bStopTicking)
  76. {
  77. Super.Tick();
  78. bStopTicking = true;
  79. }
  80. else
  81. {
  82. zNew = Pos.Z;
  83. if (zOld != zNew && tryCheckFloating == 0)
  84. {
  85. if (bOnCeiling && NashGoreStatics.CheckFloating(self, true))
  86. {
  87. Destroy();
  88. return;
  89. }
  90. else if (!bOnCeiling && NashGoreStatics.CheckFloating(self, false))
  91. {
  92. Destroy();
  93. return;
  94. }
  95. zOld = zNew;
  96. tryCheckFloating = 1;
  97. }
  98. // advance states
  99. if (tics != -1)
  100. {
  101. if (--tics <= 0)
  102. {
  103. if (!SetState(curstate.NextState)) return;
  104. }
  105. }
  106. return;
  107. }
  108. if (NashGoreStatics.CheckSky(self) || NashGoreStatics.CheckLiquid(self))
  109. {
  110. if (NashGoreStatics.CheckLiquid(self))
  111. {
  112. NashGoreLiquidBlood.SpawnLiquidBlood(self);
  113. }
  114. Destroy();
  115. return;
  116. }
  117. // don't float beyond ledges
  118. if (!bCheckedFloating)
  119. {
  120. if (!bOnCeiling)
  121. {
  122. // floor
  123. if (Pos.Z <= FloorZ && NashGoreStatics.CheckFloating(self, false))
  124. {
  125. Destroy();
  126. return;
  127. }
  128. }
  129. else
  130. {
  131. // ceiling
  132. if (Pos.Z <= CeilingZ && NashGoreStatics.CheckFloating(self, true))
  133. {
  134. Destroy();
  135. return;
  136. }
  137. }
  138. bCheckedFloating = true;
  139. }
  140. // align to slope
  141. if (!bSloped)
  142. {
  143. NashGoreStatics.AlignToPlane(self, ceiling: bOnCeiling);
  144. bSloped = true;
  145. }
  146. // corpse blood needs collision for footprint effects
  147. if (!(self is "NashGoreCorpseBlood")) bNoInteraction = true;
  148. }
  149. }
  150. //===========================================================================
  151. //
  152. //
  153. //
  154. //===========================================================================
  155. class NashGoreBloodSpot : NashGoreBloodPlane
  156. {
  157. Default
  158. {
  159. Radius 32;
  160. }
  161. int dripDuration, dripInterval;
  162. // 30 seconds
  163. const dripDuration_MAX = 35 * 30;
  164. //===========================================================================
  165. //
  166. //
  167. //
  168. //===========================================================================
  169. override void PostBeginPlay(void)
  170. {
  171. if (random() < (255 - nashgore_bloodamount)) { Destroy(); return; }
  172. /*
  173. if (target && !nashgore_spriteblood)
  174. {
  175. Color bc = target.BloodColor;
  176. if (bc == 0) bc = gameinfo.defaultbloodcolor;
  177. else bc = Color(bc.R / 2, bc.G / 2, bc.B / 2);
  178. A_SetRenderStyle(1, STYLE_Shaded);
  179. SetShade(bc);
  180. }
  181. */
  182. if (nashgore_spriteblood)
  183. {
  184. NashGoreStatics.RandomXFlip(self);
  185. bForceXYBillboard = true;
  186. }
  187. Super.PostBeginPlay();
  188. }
  189. override void Tick(void)
  190. {
  191. Super.Tick();
  192. if (!bNoTimeFreeze && (isFrozen() || Level.isFrozen())) return;
  193. if (bOnCeiling)
  194. {
  195. if (dripDuration < dripDuration_MAX)
  196. {
  197. dripDuration++;
  198. if (dripInterval <= 0)
  199. {
  200. dripInterval = random(20, 200);
  201. A_SpawnItemEx("NashGoreBloodDrop", flags: NashGoreBloodBase.BLOOD_FLAGS);
  202. }
  203. dripInterval--;
  204. }
  205. }
  206. }
  207. //===========================================================================
  208. //
  209. //
  210. //
  211. //===========================================================================
  212. States
  213. {
  214. Spawn:
  215. TNT1 A 1 NoDelay
  216. {
  217. A_PlaySound("nashgore/bloodsplash");
  218. if (nashgore_spriteblood) return A_Jump(256, "BloodSpotSprite1", "BloodSpotSprite2", "BloodSpotSprite3", "BloodSpotSprite4");
  219. return A_Jump(256, "BloodSpot1", "BloodSpot2", "BloodSpot3", "BloodSpot4");
  220. }
  221. Stop;
  222. BloodSpot1:
  223. NGMV A -1;
  224. Stop;
  225. BloodSpot2:
  226. NGMV B -1;
  227. Stop;
  228. BloodSpot3:
  229. NGMV C -1;
  230. Stop;
  231. BloodSpot4:
  232. NGMV D -1;
  233. Stop;
  234. BloodSpotSprite1:
  235. NSPT A -1;
  236. Stop;
  237. BloodSpotSprite2:
  238. NSPT B -1;
  239. Stop;
  240. BloodSpotSprite3:
  241. NSPT C -1;
  242. Stop;
  243. BloodSpotSprite4:
  244. NSPT D -1;
  245. Stop;
  246. }
  247. }
  248. class NashGoreBloodSpotSmall : NashGoreBloodSpot
  249. {
  250. Default
  251. {
  252. Radius 8;
  253. }
  254. }
  255. class NashGoreBloodSpotCeiling : NashGoreBloodSpot
  256. {
  257. // uses a different Z offset in the MODELDEF
  258. }
  259. class NashGoreBloodSpotClassic : NashGoreBloodSpot
  260. {
  261. Default
  262. {
  263. Radius 8;
  264. }
  265. }
  266. class NashGoreBloodSpotClassicCeiling : NashGoreBloodSpotClassic
  267. {
  268. // uses a different Z offset in the MODELDEF
  269. }
  270. //===========================================================================
  271. //
  272. //
  273. //
  274. //===========================================================================
  275. class NashGoreCorpseBlood : NashGoreBloodPlane
  276. {
  277. Default
  278. {
  279. Radius 32;
  280. Height 1;
  281. +SPECIAL
  282. -SOLID
  283. -NOGRAVITY
  284. }
  285. bool bDepletedCorpseBlood;
  286. //===========================================================================
  287. //
  288. //
  289. //
  290. //===========================================================================
  291. override void BeginPlay(void)
  292. {
  293. if (nashgore_corpseblood == 0) { Destroy(); return; }
  294. Super.BeginPlay();
  295. }
  296. override void Tick()
  297. {
  298. Super.Tick();
  299. if (!bNoTimeFreeze && (isFrozen() || Level.isFrozen())) return;
  300. if (!target || bDepletedCorpseBlood)
  301. {
  302. Destroy();
  303. return;
  304. }
  305. }
  306. override void Touch(Actor other)
  307. {
  308. if (other && other is "PlayerPawn")
  309. {
  310. let a = NashGoreActor(other.FindInventory("NashGoreActor", true));
  311. if (a)
  312. {
  313. a.lastCorpseBlood = self;
  314. a.footprintDuration = NashGoreActor.MAX_FOOTPRINT_DURATION;
  315. // reduce blood size every time it is stepped on
  316. if (NashGoreStatics.GetVelocity(other) > 0.5)
  317. {
  318. A_SetSize(Radius - 0.28);
  319. A_SetScale(Scale.X - 0.01);
  320. }
  321. if (Scale.X <= 0.01)
  322. {
  323. // mark it for destruction later
  324. bDepletedCorpseBlood = true;
  325. }
  326. }
  327. }
  328. }
  329. //===========================================================================
  330. //
  331. //
  332. //
  333. //===========================================================================
  334. States
  335. {
  336. Spawn:
  337. NGMV A 200;
  338. NGMV B -1;
  339. Stop;
  340. }
  341. }
  342. //===========================================================================
  343. //
  344. //
  345. //
  346. //===========================================================================
  347. class NashGoreFootprint : NashGoreBloodPlane
  348. {
  349. Default
  350. {
  351. Radius 10;
  352. }
  353. //===========================================================================
  354. //
  355. //
  356. //
  357. //===========================================================================
  358. override void BeginPlay(void)
  359. {
  360. if (nashgore_footprints == 0) { Destroy(); return; }
  361. Super.BeginPlay();
  362. }
  363. //===========================================================================
  364. //
  365. //
  366. //
  367. //===========================================================================
  368. States
  369. {
  370. Spawn:
  371. NGMV A -1;
  372. Stop;
  373. }
  374. }