wizard.qc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. /* Copyright (C) 1996-1997 Id Software, Inc.
  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. /*
  16. ==============================================================================
  17. WIZARD
  18. ==============================================================================
  19. */
  20. $cd /raid/quake/id1/models/a_wizard
  21. $origin 0 0 24
  22. $base wizbase
  23. $skin wizbase
  24. $frame hover1 hover2 hover3 hover4 hover5 hover6 hover7 hover8
  25. $frame hover9 hover10 hover11 hover12 hover13 hover14 hover15
  26. $frame fly1 fly2 fly3 fly4 fly5 fly6 fly7 fly8 fly9 fly10
  27. $frame fly11 fly12 fly13 fly14
  28. $frame magatt1 magatt2 magatt3 magatt4 magatt5 magatt6 magatt7
  29. $frame magatt8 magatt9 magatt10 magatt11 magatt12 magatt13
  30. $frame pain1 pain2 pain3 pain4
  31. $frame death1 death2 death3 death4 death5 death6 death7 death8
  32. /*
  33. ==============================================================================
  34. WIZARD
  35. If the player moves behind cover before the missile is launched, launch it
  36. at the last visible spot with no velocity leading, in hopes that the player
  37. will duck back out and catch it.
  38. ==============================================================================
  39. */
  40. /*
  41. =============
  42. LaunchMissile
  43. Sets the given entities velocity and angles so that it will hit self.enemy
  44. if self.enemy maintains it's current velocity
  45. 0.1 is moderately accurate, 0.0 is totally accurate
  46. =============
  47. */
  48. void(entity missile, float mspeed, float accuracy) LaunchMissile =
  49. {
  50. local vector vec, move;
  51. local float fly;
  52. makevectors (self.angles);
  53. // set missile speed
  54. vec = self.enemy.origin + self.enemy.mins + self.enemy.size * 0.7 - missile.origin;
  55. // calc aproximate time for missile to reach vec
  56. fly = vlen (vec) / mspeed;
  57. // get the entities xy velocity
  58. move = self.enemy.velocity;
  59. move_z = 0;
  60. // project the target forward in time
  61. vec = vec + move * fly;
  62. vec = normalize(vec);
  63. vec = vec + accuracy*v_up*(random()- 0.5) + accuracy*v_right*(random()- 0.5);
  64. missile.velocity = vec * mspeed;
  65. missile.angles = '0 0 0';
  66. missile.angles_y = vectoyaw(missile.velocity);
  67. // set missile duration
  68. missile.nextthink = time + 5;
  69. missile.think = SUB_Remove;
  70. };
  71. void() wiz_run1;
  72. void() wiz_side1;
  73. /*
  74. =================
  75. WizardCheckAttack
  76. =================
  77. */
  78. float() WizardCheckAttack =
  79. {
  80. local vector spot1, spot2;
  81. local entity targ;
  82. local float chance;
  83. if (time < self.attack_finished)
  84. return FALSE;
  85. if (!enemy_vis)
  86. return FALSE;
  87. if (enemy_range == RANGE_FAR)
  88. {
  89. if (self.attack_state != AS_STRAIGHT)
  90. {
  91. self.attack_state = AS_STRAIGHT;
  92. wiz_run1 ();
  93. }
  94. return FALSE;
  95. }
  96. targ = self.enemy;
  97. // see if any entities are in the way of the shot
  98. spot1 = self.origin + self.view_ofs;
  99. spot2 = targ.origin + targ.view_ofs;
  100. traceline (spot1, spot2, FALSE, self);
  101. if (trace_ent != targ)
  102. { // don't have a clear shot, so move to a side
  103. if (self.attack_state != AS_STRAIGHT)
  104. {
  105. self.attack_state = AS_STRAIGHT;
  106. wiz_run1 ();
  107. }
  108. return FALSE;
  109. }
  110. if (enemy_range == RANGE_MELEE)
  111. chance = 0.9;
  112. else if (enemy_range == RANGE_NEAR)
  113. chance = 0.6;
  114. else if (enemy_range == RANGE_MID)
  115. chance = 0.2;
  116. else
  117. chance = 0;
  118. if (random () < chance)
  119. {
  120. self.attack_state = AS_MISSILE;
  121. return TRUE;
  122. }
  123. if (enemy_range == RANGE_MID)
  124. {
  125. if (self.attack_state != AS_STRAIGHT)
  126. {
  127. self.attack_state = AS_STRAIGHT;
  128. wiz_run1 ();
  129. }
  130. }
  131. else
  132. {
  133. if (self.attack_state != AS_SLIDING)
  134. {
  135. self.attack_state = AS_SLIDING;
  136. wiz_side1 ();
  137. }
  138. }
  139. return FALSE;
  140. };
  141. /*
  142. =================
  143. WizardAttackFinished
  144. =================
  145. */
  146. float() WizardAttackFinished =
  147. {
  148. if (enemy_range >= RANGE_MID || !enemy_vis)
  149. {
  150. self.attack_state = AS_STRAIGHT;
  151. self.think = wiz_run1;
  152. }
  153. else
  154. {
  155. self.attack_state = AS_SLIDING;
  156. self.think = wiz_side1;
  157. }
  158. };
  159. /*
  160. ==============================================================================
  161. FAST ATTACKS
  162. ==============================================================================
  163. */
  164. void() Wiz_FastFire =
  165. {
  166. local vector vec;
  167. local vector dst;
  168. if (self.owner.health > 0)
  169. {
  170. self.owner.effects = self.owner.effects | EF_MUZZLEFLASH;
  171. makevectors (self.enemy.angles);
  172. dst = self.enemy.origin - 13*self.movedir;
  173. vec = normalize(dst - self.origin);
  174. sound (self, CHAN_WEAPON, "wizard/wattack.wav", 1, ATTN_NORM);
  175. launch_spike (self.origin, vec);
  176. newmis.velocity = vec*600;
  177. newmis.owner = self.owner;
  178. newmis.classname = "wizspike";
  179. setmodel (newmis, "progs/w_spike.mdl");
  180. setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);
  181. }
  182. remove (self);
  183. };
  184. void() Wiz_StartFast =
  185. {
  186. local entity missile;
  187. sound (self, CHAN_WEAPON, "wizard/wattack.wav", 1, ATTN_NORM);
  188. self.v_angle = self.angles;
  189. makevectors (self.angles);
  190. missile = spawn ();
  191. missile.owner = self;
  192. missile.nextthink = time + 0.6;
  193. setsize (missile, '0 0 0', '0 0 0');
  194. setorigin (missile, self.origin + '0 0 30' + v_forward*14 + v_right*14);
  195. missile.enemy = self.enemy;
  196. missile.nextthink = time + 0.8;
  197. missile.think = Wiz_FastFire;
  198. missile.movedir = v_right;
  199. missile = spawn ();
  200. missile.owner = self;
  201. missile.nextthink = time + 1;
  202. setsize (missile, '0 0 0', '0 0 0');
  203. setorigin (missile, self.origin + '0 0 30' + v_forward*14 + v_right* -14);
  204. missile.enemy = self.enemy;
  205. missile.nextthink = time + 0.3;
  206. missile.think = Wiz_FastFire;
  207. missile.movedir = VEC_ORIGIN - v_right;
  208. };
  209. void() Wiz_idlesound =
  210. {
  211. local float wr;
  212. wr = random() * 5;
  213. if (self.waitmin < time)
  214. {
  215. self.waitmin = time + 2;
  216. if (wr > 4.5)
  217. sound (self, CHAN_VOICE, "wizard/widle1.wav", 1, ATTN_IDLE);
  218. if (wr < 1.5)
  219. sound (self, CHAN_VOICE, "wizard/widle2.wav", 1, ATTN_IDLE);
  220. }
  221. return;
  222. };
  223. void() wiz_stand1 =[ $hover1, wiz_stand2 ] {ai_stand();};
  224. void() wiz_stand2 =[ $hover2, wiz_stand3 ] {ai_stand();};
  225. void() wiz_stand3 =[ $hover3, wiz_stand4 ] {ai_stand();};
  226. void() wiz_stand4 =[ $hover4, wiz_stand5 ] {ai_stand();};
  227. void() wiz_stand5 =[ $hover5, wiz_stand6 ] {ai_stand();};
  228. void() wiz_stand6 =[ $hover6, wiz_stand7 ] {ai_stand();};
  229. void() wiz_stand7 =[ $hover7, wiz_stand8 ] {ai_stand();};
  230. void() wiz_stand8 =[ $hover8, wiz_stand1 ] {ai_stand();};
  231. void() wiz_walk1 =[ $hover1, wiz_walk2 ] {ai_walk(8);
  232. Wiz_idlesound();};
  233. void() wiz_walk2 =[ $hover2, wiz_walk3 ] {ai_walk(8);};
  234. void() wiz_walk3 =[ $hover3, wiz_walk4 ] {ai_walk(8);};
  235. void() wiz_walk4 =[ $hover4, wiz_walk5 ] {ai_walk(8);};
  236. void() wiz_walk5 =[ $hover5, wiz_walk6 ] {ai_walk(8);};
  237. void() wiz_walk6 =[ $hover6, wiz_walk7 ] {ai_walk(8);};
  238. void() wiz_walk7 =[ $hover7, wiz_walk8 ] {ai_walk(8);};
  239. void() wiz_walk8 =[ $hover8, wiz_walk1 ] {ai_walk(8);};
  240. void() wiz_side1 =[ $hover1, wiz_side2 ] {ai_run(8);
  241. Wiz_idlesound();};
  242. void() wiz_side2 =[ $hover2, wiz_side3 ] {ai_run(8);};
  243. void() wiz_side3 =[ $hover3, wiz_side4 ] {ai_run(8);};
  244. void() wiz_side4 =[ $hover4, wiz_side5 ] {ai_run(8);};
  245. void() wiz_side5 =[ $hover5, wiz_side6 ] {ai_run(8);};
  246. void() wiz_side6 =[ $hover6, wiz_side7 ] {ai_run(8);};
  247. void() wiz_side7 =[ $hover7, wiz_side8 ] {ai_run(8);};
  248. void() wiz_side8 =[ $hover8, wiz_side1 ] {ai_run(8);};
  249. void() wiz_run1 =[ $fly1, wiz_run2 ] {ai_run(16);
  250. Wiz_idlesound();
  251. };
  252. void() wiz_run2 =[ $fly2, wiz_run3 ] {ai_run(16);};
  253. void() wiz_run3 =[ $fly3, wiz_run4 ] {ai_run(16);};
  254. void() wiz_run4 =[ $fly4, wiz_run5 ] {ai_run(16);};
  255. void() wiz_run5 =[ $fly5, wiz_run6 ] {ai_run(16);};
  256. void() wiz_run6 =[ $fly6, wiz_run7 ] {ai_run(16);};
  257. void() wiz_run7 =[ $fly7, wiz_run8 ] {ai_run(16);};
  258. void() wiz_run8 =[ $fly8, wiz_run9 ] {ai_run(16);};
  259. void() wiz_run9 =[ $fly9, wiz_run10 ] {ai_run(16);};
  260. void() wiz_run10 =[ $fly10, wiz_run11 ] {ai_run(16);};
  261. void() wiz_run11 =[ $fly11, wiz_run12 ] {ai_run(16);};
  262. void() wiz_run12 =[ $fly12, wiz_run13 ] {ai_run(16);};
  263. void() wiz_run13 =[ $fly13, wiz_run14 ] {ai_run(16);};
  264. void() wiz_run14 =[ $fly14, wiz_run1 ] {ai_run(16);};
  265. void() wiz_fast1 =[ $magatt1, wiz_fast2 ] {ai_face();Wiz_StartFast();};
  266. void() wiz_fast2 =[ $magatt2, wiz_fast3 ] {ai_face();};
  267. void() wiz_fast3 =[ $magatt3, wiz_fast4 ] {ai_face();};
  268. void() wiz_fast4 =[ $magatt4, wiz_fast5 ] {ai_face();};
  269. void() wiz_fast5 =[ $magatt5, wiz_fast6 ] {ai_face();};
  270. void() wiz_fast6 =[ $magatt6, wiz_fast7 ] {ai_face();};
  271. void() wiz_fast7 =[ $magatt5, wiz_fast8 ] {ai_face();};
  272. void() wiz_fast8 =[ $magatt4, wiz_fast9 ] {ai_face();};
  273. void() wiz_fast9 =[ $magatt3, wiz_fast10 ] {ai_face();};
  274. void() wiz_fast10 =[ $magatt2, wiz_run1 ] {ai_face();SUB_AttackFinished(2);WizardAttackFinished ();};
  275. void() wiz_pain1 =[ $pain1, wiz_pain2 ] {};
  276. void() wiz_pain2 =[ $pain2, wiz_pain3 ] {};
  277. void() wiz_pain3 =[ $pain3, wiz_pain4 ] {};
  278. void() wiz_pain4 =[ $pain4, wiz_run1 ] {};
  279. void() wiz_death1 =[ $death1, wiz_death2 ] {
  280. self.velocity_x = -200 + 400*random();
  281. self.velocity_y = -200 + 400*random();
  282. self.velocity_z = 100 + 100*random();
  283. self.flags = self.flags - (self.flags & FL_ONGROUND);
  284. sound (self, CHAN_VOICE, "wizard/wdeath.wav", 1, ATTN_NORM);
  285. };
  286. void() wiz_death2 =[ $death2, wiz_death3 ] {};
  287. void() wiz_death3 =[ $death3, wiz_death4 ]{self.solid = SOLID_NOT;};
  288. void() wiz_death4 =[ $death4, wiz_death5 ] {};
  289. void() wiz_death5 =[ $death5, wiz_death6 ] {};
  290. void() wiz_death6 =[ $death6, wiz_death7 ] {};
  291. void() wiz_death7 =[ $death7, wiz_death8 ] {};
  292. void() wiz_death8 =[ $death8, wiz_death8 ] {};
  293. void() wiz_die =
  294. {
  295. // check for gib
  296. if (self.health < -40)
  297. {
  298. sound (self, CHAN_VOICE, "player/udeath.wav", 1, ATTN_NORM);
  299. ThrowHead ("progs/h_wizard.mdl", self.health);
  300. ThrowGib ("progs/gib2.mdl", self.health);
  301. ThrowGib ("progs/gib2.mdl", self.health);
  302. ThrowGib ("progs/gib2.mdl", self.health);
  303. return;
  304. }
  305. wiz_death1 ();
  306. };
  307. void(entity attacker, float damage) Wiz_Pain =
  308. {
  309. sound (self, CHAN_VOICE, "wizard/wpain.wav", 1, ATTN_NORM);
  310. if (random()*70 > damage)
  311. return; // didn't flinch
  312. wiz_pain1 ();
  313. };
  314. void() Wiz_Missile =
  315. {
  316. wiz_fast1();
  317. };
  318. /*QUAKED monster_wizard (1 0 0) (-16 -16 -24) (16 16 40) Ambush
  319. */
  320. void() monster_wizard =
  321. {
  322. if (deathmatch)
  323. {
  324. remove(self);
  325. return;
  326. }
  327. precache_model ("progs/wizard.mdl");
  328. precache_model ("progs/h_wizard.mdl");
  329. precache_model ("progs/w_spike.mdl");
  330. precache_sound ("wizard/hit.wav"); // used by c code
  331. precache_sound ("wizard/wattack.wav");
  332. precache_sound ("wizard/wdeath.wav");
  333. precache_sound ("wizard/widle1.wav");
  334. precache_sound ("wizard/widle2.wav");
  335. precache_sound ("wizard/wpain.wav");
  336. precache_sound ("wizard/wsight.wav");
  337. self.solid = SOLID_SLIDEBOX;
  338. self.movetype = MOVETYPE_STEP;
  339. setmodel (self, "progs/wizard.mdl");
  340. setsize (self, '-16 -16 -24', '16 16 40');
  341. self.health = 80;
  342. self.th_stand = wiz_stand1;
  343. self.th_walk = wiz_walk1;
  344. self.th_run = wiz_run1;
  345. self.th_missile = Wiz_Missile;
  346. self.th_pain = Wiz_Pain;
  347. self.th_die = wiz_die;
  348. flymonster_start ();
  349. };