monsters.qc 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /* Copyright (C) 1996-2022 id Software LLC
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; either version 2 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  13. See file, 'COPYING', for details.
  14. */
  15. /* ALL MONSTERS SHOULD BE 1 0 0 IN COLOR */
  16. // name =[framenum, nexttime, nextthink] {code}
  17. // expands to:
  18. // name ()
  19. // {
  20. // self.frame=framenum;
  21. // self.nextthink = time + nexttime;
  22. // self.think = nextthink
  23. // <code>
  24. // };
  25. float MONSTER_SPAWNED = 4;
  26. float MONSTER_SPAWNED_ANGRY = 8;
  27. float MONSTER_SPAWNED_TFOG = 16;
  28. float MONSTER_WAITWALK = 4096;
  29. float MONSTER_TYPE_WALK = 1;
  30. float MONSTER_TYPE_FLY = 2;
  31. float MONSTER_TYPE_SWIM = 3;
  32. float MONSTER_SIZE_SMALL = 1;
  33. float MONSTER_SIZE_LARGE = 2;
  34. /*
  35. ================
  36. monster_use
  37. Using a monster makes it angry at the current activator
  38. ================
  39. */
  40. void() monster_use =
  41. {
  42. if (self.enemy)
  43. return;
  44. if (self.health <= 0)
  45. return;
  46. if (activator.items & IT_INVISIBILITY)
  47. return;
  48. if (activator.flags & FL_NOTARGET)
  49. return;
  50. if (activator.classname != "player")
  51. return;
  52. // delay reaction so if the monster is teleported, its sound is still
  53. // heard
  54. self.enemy = activator;
  55. self.nextthink = time + 0.1;
  56. self.think = FoundTarget;
  57. };
  58. /*
  59. ================
  60. monster_death_use
  61. When a mosnter dies, it fires all of its targets with the current
  62. enemy as activator.
  63. ================
  64. */
  65. void() monster_death_use =
  66. {
  67. // fall to ground
  68. if (self.flags & FL_FLY)
  69. self.flags = self.flags - FL_FLY;
  70. if (self.flags & FL_SWIM)
  71. self.flags = self.flags - FL_SWIM;
  72. if (cvar("horde") && self.classname != "monster_zombie")
  73. {
  74. remote_wavecheck();
  75. }
  76. if (!self.target)
  77. return;
  78. activator = self.enemy;
  79. SUB_UseTargets ();
  80. };
  81. void monster_begin_walking()
  82. {
  83. self.use = monster_use;
  84. self.pausetime = 0;
  85. self.th_walk();
  86. }
  87. //============================================================================
  88. void() StartMonster =
  89. {
  90. self.solid = SOLID_SLIDEBOX;
  91. self.movetype = MOVETYPE_STEP;
  92. setmodel (self, self.mdl);
  93. if(self.state == MONSTER_SIZE_SMALL) setsize (self, VEC_HULL_MIN, VEC_HULL_MAX);
  94. if(self.state == MONSTER_SIZE_LARGE) setsize (self, VEC_HULL2_MIN, VEC_HULL2_MAX);
  95. if(self.lefty == MONSTER_TYPE_WALK)
  96. {
  97. self.origin_z = self.origin_z + 1; // raise off floor a bit
  98. droptofloor();
  99. }
  100. if (!walkmove(0,0))
  101. {
  102. dprint ("monster in wall at: ");
  103. dprint (vtos(self.origin));
  104. dprint (":\n");
  105. dprint (self.classname);
  106. if(self.target){
  107. dprint (" (target = ");
  108. dprint (self.target);
  109. dprint (" )");
  110. }
  111. if(self.targetname){
  112. dprint (" (targetname = ");
  113. dprint (self.targetname);
  114. dprint (" )");
  115. }
  116. dprint ("\n");
  117. }
  118. if(self.spawnflags & MONSTER_SPAWNED)
  119. {
  120. spawn_tdeath (self.origin, self);
  121. if(self.spawnflags & MONSTER_SPAWNED_TFOG)
  122. {
  123. spawn_tfog(self.origin);
  124. }
  125. }
  126. self.takedamage = DAMAGE_AIM;
  127. self.ideal_yaw = self.angles * '0 1 0';
  128. if (!self.yaw_speed)
  129. self.yaw_speed = 20;
  130. self.view_ofs = '0 0 25';
  131. self.use = monster_use;
  132. self.team = TEAM_MONSTERS;
  133. self.flags = self.flags | FL_MONSTER;
  134. if(self.lefty == MONSTER_TYPE_FLY) self.flags = self.flags | FL_FLY;
  135. if(self.lefty == MONSTER_TYPE_SWIM) self.flags = self.flags | FL_SWIM;
  136. if (self.target)
  137. {
  138. if(self.spawnflags & MONSTER_ATTACK_FRIEND)
  139. {
  140. entity f = SUB_RandomTarget(self, CanTakedamage);
  141. if(f)
  142. {
  143. self.enemy = f;
  144. FoundTarget ();
  145. return;
  146. }
  147. }
  148. self.goalentity = self.movetarget = find(world, targetname, self.target);
  149. self.ideal_yaw = vectoyaw(self.goalentity.origin - self.origin);
  150. if (!self.movetarget)
  151. {
  152. dprint ("Monster can't find target at ");
  153. dprint (vtos(self.origin));
  154. dprint ("\n");
  155. }
  156. if (self.movetarget.classname == "path_corner")
  157. {
  158. if(self.spawnflags & MONSTER_WAITWALK)
  159. {
  160. self.pausetime = 99999999;
  161. self.th_stand ();
  162. self.use = monster_begin_walking;
  163. }
  164. else
  165. {
  166. self.th_walk ();
  167. }
  168. }
  169. else
  170. {
  171. self.pausetime = 99999999;
  172. self.th_stand ();
  173. }
  174. }
  175. else
  176. {
  177. self.pausetime = 99999999;
  178. self.th_stand ();
  179. }
  180. if(self.spawnflags & MONSTER_SPAWNED)
  181. {
  182. // Yoder, Sept29, horde fix so that preplaced monsters are counted on spawn_tdeath
  183. if (horde_ent)
  184. total_monsters = total_monsters + 1;
  185. // end Yoder chunk, back to normal
  186. if(self.spawnflags & MONSTER_SPAWNED_ANGRY)
  187. {
  188. monster_use(); //Make monster angry!
  189. }
  190. }
  191. else
  192. {
  193. // spread think times so they don't all happen at same time
  194. self.nextthink = self.nextthink + random()*0.5;
  195. }
  196. };
  197. void InitMonster(string model, float type, float size)
  198. {
  199. if (deathmatch)
  200. {
  201. remove(self);
  202. return;
  203. }
  204. INHIBIT_COOP
  205. if (RemovedOutsideCoop()) return;
  206. self.flags |= FL_FUTUREMONSTER;
  207. self.mdl = model;
  208. self.lefty = type;
  209. self.state = size;
  210. // CG: This was removed because it caused the entity alpha to differ from the baseline alpha somehow, causing it to be transmitted over the network every frame for every monster.
  211. // self.alpha = 1;
  212. // Yoder, Sept29, fix for preplaced monsters in horde_ent
  213. // in horde, mosnters shouldn't increase total count until spawned
  214. if (cvar("horde"))
  215. {
  216. if (!(self.spawnflags & MONSTER_SPAWNED))
  217. total_monsters = total_monsters + 1;
  218. }
  219. else // normal behavior
  220. total_monsters = total_monsters + 1;
  221. if(self.spawnflags & MONSTER_SPAWNED)
  222. {
  223. self.use = StartMonster;
  224. return;
  225. }
  226. // delay drop to floor to make sure all doors have been spawned
  227. // spread think times so they don't all happen at same time
  228. self.nextthink = self.nextthink + random()*0.5;
  229. self.think = StartMonster;
  230. }
  231. // Yoder Sept24 2021, Horde Merge
  232. // Monster fade, used to fade out the model a few seconds after deathmatch
  233. void() MonsterFade2 =
  234. {
  235. if (self.alpha > 0)
  236. {
  237. self.alpha = self.alpha - 1 * frametime;
  238. //self.think = MonsterFade;
  239. self.nextthink = time; // think next frame
  240. }
  241. else
  242. remove(self);
  243. }
  244. void() MonsterFade =
  245. {
  246. if (!cvar("horde"))
  247. {
  248. self.think = SUB_Null;
  249. return;
  250. }
  251. if (!self.alpha)
  252. self.alpha = 1;
  253. self.think = MonsterFade2;
  254. self.nextthink = time + 10 + random() * 5; // wait a bit before fading
  255. };