monsters.qc 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. /*
  26. ================
  27. monster_use
  28. Using a monster makes it angry at the current activator
  29. ================
  30. */
  31. void() monster_use =
  32. {
  33. if (self.enemy)
  34. return;
  35. if (self.health <= 0)
  36. return;
  37. if (activator.items & IT_INVISIBILITY)
  38. return;
  39. if (activator.flags & FL_NOTARGET)
  40. return;
  41. if (activator.classname != "player")
  42. return;
  43. // delay reaction so if the monster is teleported, its sound is still heard
  44. self.enemy = activator;
  45. self.nextthink = time + 0.1;
  46. self.think = FoundTarget;
  47. };
  48. /*
  49. ================
  50. monster_death_use
  51. When a mosnter dies, it fires all of its targets with the current
  52. enemy as activator.
  53. ================
  54. */
  55. void() monster_death_use =
  56. {
  57. // fall to ground
  58. if (self.flags & FL_FLY)
  59. self.flags = self.flags - FL_FLY;
  60. if (self.flags & FL_SWIM)
  61. self.flags = self.flags - FL_SWIM;
  62. if (!self.target)
  63. return;
  64. activator = self.enemy;
  65. SUB_UseTargets ();
  66. };
  67. //============================================================================
  68. void() walkmonster_start_go =
  69. {
  70. self.origin_z = self.origin_z + 1; // raise off floor a bit
  71. droptofloor();
  72. if (!walkmove(0,0))
  73. {
  74. dprint ("walkmonster in wall at: ");
  75. dprint (vtos(self.origin));
  76. dprint ("\n");
  77. }
  78. self.takedamage = DAMAGE_AIM;
  79. self.ideal_yaw = self.angles * '0 1 0';
  80. if (!self.yaw_speed)
  81. self.yaw_speed = 20;
  82. self.view_ofs = '0 0 25';
  83. self.use = monster_use;
  84. self.team = TEAM_MONSTERS;
  85. self.flags = self.flags | FL_MONSTER;
  86. if (self.target != string_null)
  87. {
  88. self.goalentity = self.movetarget = find(world, targetname, self.target);
  89. self.ideal_yaw = vectoyaw(self.goalentity.origin - self.origin);
  90. if (!self.movetarget)
  91. {
  92. dprint ("Monster can't find target at ");
  93. dprint (vtos(self.origin));
  94. dprint ("\n");
  95. }
  96. // this used to be an objerror
  97. if (self.movetarget.classname == "path_corner")
  98. self.th_walk ();
  99. else
  100. self.pausetime = 99999999;
  101. self.th_stand ();
  102. }
  103. else
  104. {
  105. self.pausetime = 99999999;
  106. self.th_stand ();
  107. }
  108. // spread think times so they don't all happen at same time
  109. self.nextthink = self.nextthink + random()*0.5;
  110. };
  111. void() walkmonster_start =
  112. {
  113. // delay drop to floor to make sure all doors have been spawned
  114. // spread think times so they don't all happen at same time
  115. self.nextthink = self.nextthink + random()*0.5;
  116. self.think = walkmonster_start_go;
  117. total_monsters = total_monsters + 1;
  118. };
  119. void() flymonster_start_go =
  120. {
  121. self.takedamage = DAMAGE_AIM;
  122. self.ideal_yaw = self.angles * '0 1 0';
  123. if (!self.yaw_speed)
  124. self.yaw_speed = 10;
  125. self.view_ofs = '0 0 25';
  126. self.use = monster_use;
  127. self.team = TEAM_MONSTERS;
  128. self.flags = self.flags | FL_FLY;
  129. self.flags = self.flags | FL_MONSTER;
  130. if (!walkmove(0,0))
  131. {
  132. dprint ("flymonster in wall at: ");
  133. dprint (vtos(self.origin));
  134. dprint ("\n");
  135. }
  136. if (self.target != string_null)
  137. {
  138. self.goalentity = self.movetarget = find(world, targetname, self.target);
  139. if (!self.movetarget)
  140. {
  141. dprint ("Monster can't find target at ");
  142. dprint (vtos(self.origin));
  143. dprint ("\n");
  144. }
  145. // this used to be an objerror
  146. if (self.movetarget.classname == "path_corner")
  147. self.th_walk ();
  148. else
  149. self.pausetime = 99999999;
  150. self.th_stand ();
  151. }
  152. else
  153. {
  154. self.pausetime = 99999999;
  155. self.th_stand ();
  156. }
  157. };
  158. void() flymonster_start =
  159. {
  160. // spread think times so they don't all happen at same time
  161. self.nextthink = self.nextthink + random()*0.5;
  162. self.think = flymonster_start_go;
  163. total_monsters = total_monsters + 1;
  164. };
  165. void() swimmonster_start_go =
  166. {
  167. if (deathmatch)
  168. {
  169. remove(self);
  170. return;
  171. }
  172. self.takedamage = DAMAGE_AIM;
  173. self.ideal_yaw = self.angles * '0 1 0';
  174. if (!self.yaw_speed)
  175. self.yaw_speed = 10;
  176. self.view_ofs = '0 0 10';
  177. self.use = monster_use;
  178. self.team = TEAM_MONSTERS;
  179. self.flags = self.flags | FL_SWIM;
  180. self.flags = self.flags | FL_MONSTER;
  181. if (self.target != string_null)
  182. {
  183. self.goalentity = self.movetarget = find(world, targetname, self.target);
  184. if (!self.movetarget)
  185. {
  186. dprint ("Monster can't find target at ");
  187. dprint (vtos(self.origin));
  188. dprint ("\n");
  189. }
  190. // this used to be an objerror
  191. self.ideal_yaw = vectoyaw(self.goalentity.origin - self.origin);
  192. self.th_walk ();
  193. }
  194. else
  195. {
  196. self.pausetime = 99999999;
  197. self.th_stand ();
  198. }
  199. // spread think times so they don't all happen at same time
  200. self.nextthink = self.nextthink + random()*0.5;
  201. };
  202. void() swimmonster_start =
  203. {
  204. // spread think times so they don't all happen at same time
  205. self.nextthink = self.nextthink + random() * 0.5;
  206. self.think = swimmonster_start_go;
  207. total_monsters = total_monsters + 1;
  208. };