NashGoreHandler.zc 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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 NashGoreHandler : EventHandler
  32. {
  33. int maxgore;
  34. int maxgore_old, maxgore_new;
  35. Array<String> bloodTypes;
  36. //===========================================================================
  37. //
  38. //
  39. //
  40. //===========================================================================
  41. override void PlayerEntered(PlayerEvent e)
  42. {
  43. PlayerPawn plr = players[e.PlayerNumber].mo;
  44. if (!plr.CountInv("NashGoreActor"))
  45. {
  46. plr.A_GiveInventory("NashGoreActor", 1);
  47. }
  48. }
  49. override void PlayerRespawned(PlayerEvent e)
  50. {
  51. PlayerPawn plr = players[e.PlayerNumber].mo;
  52. DoThingRevive(plr);
  53. }
  54. //===========================================================================
  55. //
  56. //
  57. //
  58. //===========================================================================
  59. override void WorldLoaded(WorldEvent e)
  60. {
  61. BuildBloodTypes();
  62. }
  63. override void WorldTick(void)
  64. {
  65. // update gore queue
  66. maxgore_new = nashgore_maxgore;
  67. if (maxgore_old != maxgore_new)
  68. {
  69. maxgore = maxgore_new;
  70. maxgore_old = maxgore_new;
  71. }
  72. }
  73. //===========================================================================
  74. //
  75. //
  76. //
  77. //===========================================================================
  78. override void WorldThingSpawned(WorldEvent e)
  79. {
  80. if (!e.Thing) return;
  81. // monster?
  82. bool isMonster = e.Thing.bIsMonster;
  83. // plug in generic monster behaviour
  84. if (isMonster && !e.Thing.CountInv("NashGoreActor"))
  85. {
  86. e.Thing.A_GiveInventory("NashGoreActor", 1);
  87. let a = NashGoreActor(e.Thing.FindInventory("NashGoreActor", true));
  88. if (a)
  89. {
  90. a.bCanBleed = !e.Thing.bNoBlood;
  91. }
  92. }
  93. }
  94. /*
  95. override void WorldThingDamaged(WorldEvent e)
  96. {
  97. if (!e.Thing) return;
  98. if (!e.Thing.bNoBlood && e.DamageSource)
  99. {
  100. let diffVec = Level.Vec3Diff(e.DamageSource.Pos, e.Thing.Pos);
  101. double angle = VectorAngle(diffVec.X, diffVec.Y);
  102. double pitch = -VectorAngle(diffVec.Length(), diffVec.Z);
  103. NashGoreStatics.TraceWallBleed(e.Damage, e.Thing.Pos, e.Thing, angle, pitch);
  104. }
  105. }
  106. */
  107. override void WorldThingDied(WorldEvent e)
  108. {
  109. if (!e.Thing) return;
  110. DoThingDie(e.Thing);
  111. }
  112. override void WorldThingRevived(WorldEvent e)
  113. {
  114. if (!e.Thing) return;
  115. DoThingRevive(e.Thing);
  116. }
  117. //===========================================================================
  118. //
  119. //
  120. //
  121. //===========================================================================
  122. override void CheckReplacement(ReplaceEvent e)
  123. {
  124. // blood stuff
  125. for (int i = 0; i < bloodTypes.Size(); i++)
  126. {
  127. // find all known blood types from the BLUDTYPE lump
  128. class<Actor> miscBloodCls;
  129. miscBloodCls = String.Format("%s", bloodTypes[i]);
  130. if (e.Replacee == "Blood" || e.Replacee == "BloodSplatter" || e.Replacee == "AxeBlood"
  131. || (miscBloodCls != NULL && e.Replacee == miscBloodCls))
  132. {
  133. class<Actor> bloodCls;
  134. switch(nashgore_bloodtype)
  135. {
  136. default:
  137. case 0:
  138. bloodCls = "NashGoreBlood";
  139. break;
  140. case 1:
  141. bloodCls = "NashGoreClassicBlood";
  142. break;
  143. case 2:
  144. bloodCls = "Blood";
  145. break;
  146. }
  147. e.Replacement = bloodCls;
  148. }
  149. }
  150. // other stuff
  151. if (e.Replacee == "RealGibs") e.Replacement = "NashGoreRealGibs";
  152. if (nashgore_icedeath == true && e.replacee == "IceChunk") e.Replacement = "NashGoreIceChunk";
  153. }
  154. //===========================================================================
  155. //
  156. //
  157. //
  158. //===========================================================================
  159. override void NetworkProcess(ConsoleEvent e)
  160. {
  161. //let p = players[e.Player].mo;
  162. //if (!p) return;
  163. if (e.Name == 'EV_ClearGore')
  164. {
  165. NashGoreStatics.ClearGore();
  166. }
  167. }
  168. //===========================================================================
  169. //
  170. //
  171. //
  172. //===========================================================================
  173. void BuildBloodTypes(void)
  174. {
  175. bloodTypes.Clear();
  176. int lump = -1;
  177. while (-1 != (lump = Wads.FindLump('BLUDTYPE', lump + 1)))
  178. {
  179. String data = Wads.ReadLump(lump);
  180. // split lines
  181. Array<String> lines;
  182. lines.Clear();
  183. data.Split(lines, "\n", TOK_KEEPEMPTY);
  184. // strip comments
  185. for (int i = 0; i < lines.Size(); i++)
  186. {
  187. if (lines[i].IndexOf("//") == 0)
  188. {
  189. continue;
  190. }
  191. else
  192. {
  193. bloodTypes.Push(lines[i]);
  194. }
  195. }
  196. // [lolhack] remove the last line because it's usually blank
  197. //bloodTypes.Delete(bloodTypes.Size() - 1, 1);
  198. }
  199. //Console.Printf("size: %d", bloodTypes.Size());
  200. for (int i = 0; i < bloodTypes.Size(); i++)
  201. {
  202. // delete that weird character that gets added at the end
  203. bloodTypes[i].Truncate(bloodTypes[i].Length() - 1);
  204. /*
  205. if (bloodTypes[i])
  206. {
  207. Console.Printf("%s\n", bloodTypes[i]);
  208. }
  209. */
  210. }
  211. }
  212. //===========================================================================
  213. //
  214. //
  215. //
  216. //===========================================================================
  217. void DoThingDie(Actor mo)
  218. {
  219. bool isMonster = mo.bIsMonster;
  220. bool isPlayer = (mo is "PlayerPawn");
  221. if (isMonster || isPlayer)
  222. {
  223. let a = NashGoreActor(mo.FindInventory("NashGoreActor", true));
  224. if (a)
  225. {
  226. // mark actor as dead
  227. a.bIsDead = true;
  228. }
  229. }
  230. }
  231. void DoThingRevive(Actor mo)
  232. {
  233. //Console.Printf("%s lives again!", mo.GetClassName());
  234. let a = NashGoreActor(mo.FindInventory("NashGoreActor", true));
  235. if (a)
  236. {
  237. a.ResetActor();
  238. }
  239. }
  240. }