items.qc 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359
  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. void() W_SetCurrentAmmo;
  16. /* ALL LIGHTS SHOULD BE 0 1 0 IN COLOR ALL OTHER ITEMS SHOULD
  17. BE .8 .3 .4 IN COLOR */
  18. void() SUB_regen =
  19. {
  20. self.model = self.mdl; // restore original model
  21. self.solid = SOLID_TRIGGER; // allow it to be touched again
  22. sound (self, CHAN_VOICE, "items/itembk2.wav", 1, ATTN_NORM); // play respawn sound
  23. setorigin (self, self.origin);
  24. };
  25. /*QUAKED noclass (0 0 0) (-8 -8 -8) (8 8 8)
  26. prints a warning message when spawned
  27. */
  28. void() noclass =
  29. {
  30. dprint ("noclass spawned at");
  31. dprint (vtos(self.origin));
  32. dprint ("\n");
  33. remove (self);
  34. };
  35. /*
  36. ============
  37. PlaceItem
  38. plants the object on the floor
  39. ============
  40. */
  41. void() PlaceItem =
  42. {
  43. local float oldz;
  44. self.mdl = self.model; // so it can be restored on respawn
  45. self.flags = FL_ITEM; // make extra wide
  46. self.solid = SOLID_TRIGGER;
  47. self.movetype = MOVETYPE_TOSS;
  48. self.velocity = '0 0 0';
  49. self.origin_z = self.origin_z + 6;
  50. oldz = self.origin_z;
  51. if (!droptofloor())
  52. {
  53. dprint ("Bonus item fell out of level at ");
  54. dprint (vtos(self.origin));
  55. dprint ("\n");
  56. remove(self);
  57. return;
  58. }
  59. };
  60. /*
  61. ============
  62. StartItem
  63. Sets the clipping size and plants the object on the floor
  64. ============
  65. */
  66. void() StartItem =
  67. {
  68. self.nextthink = time + 0.2; // items start after other solids
  69. self.think = PlaceItem;
  70. };
  71. /*
  72. =========================================================================
  73. HEALTH BOX
  74. =========================================================================
  75. */
  76. //
  77. // T_Heal: add health to an entity, limiting health to max_health
  78. // "ignore" will ignore max_health limit
  79. //
  80. float (entity e, float healamount, float ignore) T_Heal =
  81. {
  82. if (e.health <= 0)
  83. return 0;
  84. if ((!ignore) && (e.health >= other.max_health))
  85. return 0;
  86. healamount = ceil(healamount);
  87. e.health = e.health + healamount;
  88. if ((!ignore) && (e.health >= other.max_health))
  89. e.health = other.max_health;
  90. if (e.health > 250)
  91. e.health = 250;
  92. return 1;
  93. };
  94. /*QUAKED item_health (.3 .3 1) (0 0 0) (32 32 32) rotten megahealth
  95. Health box. Normally gives 25 points.
  96. Rotten box heals 5-10 points,
  97. megahealth will add 100 health, then
  98. rot you down to your maximum health limit,
  99. one point per second.
  100. */
  101. float H_ROTTEN = 1;
  102. float H_MEGA = 2;
  103. .float healamount, healtype;
  104. void() health_touch;
  105. void() item_megahealth_rot;
  106. void() item_health =
  107. {
  108. self.touch = health_touch;
  109. if (self.spawnflags & H_ROTTEN)
  110. {
  111. precache_model("maps/b_bh10.bsp");
  112. precache_sound("items/r_item1.wav");
  113. setmodel(self, "maps/b_bh10.bsp");
  114. self.noise = "items/r_item1.wav";
  115. self.healamount = 15;
  116. self.healtype = 0;
  117. }
  118. else
  119. if (self.spawnflags & H_MEGA)
  120. {
  121. precache_model("maps/b_bh100.bsp");
  122. precache_sound("items/r_item2.wav");
  123. setmodel(self, "maps/b_bh100.bsp");
  124. self.noise = "items/r_item2.wav";
  125. self.healamount = 100;
  126. self.healtype = 2;
  127. }
  128. else
  129. {
  130. precache_model("maps/b_bh25.bsp");
  131. precache_sound("items/health1.wav");
  132. setmodel(self, "maps/b_bh25.bsp");
  133. self.noise = "items/health1.wav";
  134. self.healamount = 25;
  135. self.healtype = 1;
  136. }
  137. setsize (self, '0 0 0', '32 32 56');
  138. StartItem ();
  139. };
  140. void() health_touch =
  141. {
  142. local float amount;
  143. local string s;
  144. if (other.classname != "player")
  145. return;
  146. if (self.healtype == 2) // Megahealth? Ignore max_health...
  147. {
  148. if (other.health >= 250)
  149. return;
  150. if (!T_Heal(other, self.healamount, 1))
  151. return;
  152. }
  153. else
  154. {
  155. if (!T_Heal(other, self.healamount, 0))
  156. return;
  157. }
  158. sprint(other, "You receive ");
  159. s = ftos(self.healamount);
  160. sprint(other, s);
  161. sprint(other, " health\n");
  162. // health touch sound
  163. sound(other, CHAN_ITEM, self.noise, 1, ATTN_NORM);
  164. stuffcmd (other, "bf\n");
  165. self.model = string_null;
  166. self.solid = SOLID_NOT;
  167. // Megahealth = rot down the player's super health
  168. if (self.healtype == 2)
  169. {
  170. other.items = other.items | IT_SUPERHEALTH;
  171. self.nextthink = time + 5;
  172. self.think = item_megahealth_rot;
  173. self.owner = other;
  174. }
  175. else
  176. {
  177. if (deathmatch != 2) // deathmatch 2 is the silly old rules
  178. {
  179. if (deathmatch)
  180. self.nextthink = time + 20;
  181. self.think = SUB_regen;
  182. }
  183. }
  184. activator = other;
  185. SUB_UseTargets(); // fire all targets / killtargets
  186. };
  187. void() item_megahealth_rot =
  188. {
  189. other = self.owner;
  190. if (other.health > other.max_health)
  191. {
  192. other.health = other.health - 1;
  193. self.nextthink = time + 1;
  194. return;
  195. }
  196. // it is possible for a player to die and respawn between rots, so don't
  197. // just blindly subtract the flag off
  198. other.items = other.items - (other.items & IT_SUPERHEALTH);
  199. if (deathmatch == 1) // deathmatch 2 is silly old rules
  200. {
  201. self.nextthink = time + 20;
  202. self.think = SUB_regen;
  203. }
  204. };
  205. /*
  206. ===============================================================================
  207. ARMOR
  208. ===============================================================================
  209. */
  210. void() armor_touch;
  211. void() armor_touch =
  212. {
  213. local float type, value, bit;
  214. if (other.health <= 0)
  215. return;
  216. if (other.classname != "player")
  217. return;
  218. if (self.classname == "item_armor1")
  219. {
  220. type = 0.3;
  221. value = 100;
  222. bit = IT_ARMOR1;
  223. }
  224. if (self.classname == "item_armor2")
  225. {
  226. type = 0.6;
  227. value = 150;
  228. bit = IT_ARMOR2;
  229. }
  230. if (self.classname == "item_armorInv")
  231. {
  232. type = 0.8;
  233. value = 200;
  234. bit = IT_ARMOR3;
  235. }
  236. if (other.armortype*other.armorvalue >= type*value)
  237. return;
  238. other.armortype = type;
  239. other.armorvalue = value;
  240. other.items = other.items - (other.items & (IT_ARMOR1 | IT_ARMOR2 | IT_ARMOR3)) + bit;
  241. self.solid = SOLID_NOT;
  242. self.model = string_null;
  243. if (deathmatch == 1)
  244. self.nextthink = time + 20;
  245. self.think = SUB_regen;
  246. sprint(other, "You got armor\n");
  247. // armor touch sound
  248. sound(other, CHAN_ITEM, "items/armor1.wav", 1, ATTN_NORM);
  249. stuffcmd (other, "bf\n");
  250. activator = other;
  251. SUB_UseTargets(); // fire all targets / killtargets
  252. };
  253. /*QUAKED item_armor1 (0 .5 .8) (-16 -16 0) (16 16 32)
  254. */
  255. void() item_armor1 =
  256. {
  257. self.touch = armor_touch;
  258. precache_model ("progs/armor.mdl");
  259. setmodel (self, "progs/armor.mdl");
  260. self.skin = 0;
  261. setsize (self, '-16 -16 0', '16 16 56');
  262. StartItem ();
  263. };
  264. /*QUAKED item_armor2 (0 .5 .8) (-16 -16 0) (16 16 32)
  265. */
  266. void() item_armor2 =
  267. {
  268. self.touch = armor_touch;
  269. precache_model ("progs/armor.mdl");
  270. setmodel (self, "progs/armor.mdl");
  271. self.skin = 1;
  272. setsize (self, '-16 -16 0', '16 16 56');
  273. StartItem ();
  274. };
  275. /*QUAKED item_armorInv (0 .5 .8) (-16 -16 0) (16 16 32)
  276. */
  277. void() item_armorInv =
  278. {
  279. self.touch = armor_touch;
  280. precache_model ("progs/armor.mdl");
  281. setmodel (self, "progs/armor.mdl");
  282. self.skin = 2;
  283. setsize (self, '-16 -16 0', '16 16 56');
  284. StartItem ();
  285. };
  286. /*
  287. ===============================================================================
  288. WEAPONS
  289. ===============================================================================
  290. */
  291. void() bound_other_ammo =
  292. {
  293. if (other.ammo_shells > 100)
  294. other.ammo_shells = 100;
  295. if (other.ammo_nails > 200)
  296. other.ammo_nails = 200;
  297. if (other.ammo_rockets > 100)
  298. other.ammo_rockets = 100;
  299. if (other.ammo_cells > 100)
  300. other.ammo_cells = 100;
  301. };
  302. float(float w) RankForWeapon =
  303. {
  304. if (w == IT_LIGHTNING)
  305. return 1;
  306. if (w == IT_ROCKET_LAUNCHER)
  307. return 2;
  308. if (w == IT_SUPER_NAILGUN)
  309. return 3;
  310. if (w == IT_GRENADE_LAUNCHER)
  311. return 4;
  312. if (w == IT_SUPER_SHOTGUN)
  313. return 5;
  314. if (w == IT_NAILGUN)
  315. return 6;
  316. return 7;
  317. };
  318. /*
  319. =============
  320. Deathmatch_Weapon
  321. Deathmatch weapon change rules for picking up a weapon
  322. .float ammo_shells, ammo_nails, ammo_rockets, ammo_cells;
  323. =============
  324. */
  325. void(float old, float new) Deathmatch_Weapon =
  326. {
  327. local float or, nr;
  328. // change self.weapon if desired
  329. or = RankForWeapon (self.weapon);
  330. nr = RankForWeapon (new);
  331. if ( nr < or )
  332. self.weapon = new;
  333. };
  334. /*
  335. =============
  336. weapon_touch
  337. =============
  338. */
  339. float() W_BestWeapon;
  340. void() weapon_touch =
  341. {
  342. local float hadammo, best, new, old;
  343. local entity stemp;
  344. local float leave;
  345. if (!(other.flags & FL_CLIENT))
  346. return;
  347. // if the player was using his best weapon, change up to the new one if better
  348. stemp = self;
  349. self = other;
  350. best = W_BestWeapon();
  351. self = stemp;
  352. if (deathmatch == 2 || coop)
  353. leave = 1;
  354. else
  355. leave = 0;
  356. if (self.classname == "weapon_nailgun")
  357. {
  358. if (leave && (other.items & IT_NAILGUN) )
  359. return;
  360. hadammo = other.ammo_nails;
  361. new = IT_NAILGUN;
  362. other.ammo_nails = other.ammo_nails + 30;
  363. }
  364. else if (self.classname == "weapon_supernailgun")
  365. {
  366. if (leave && (other.items & IT_SUPER_NAILGUN) )
  367. return;
  368. hadammo = other.ammo_rockets;
  369. new = IT_SUPER_NAILGUN;
  370. other.ammo_nails = other.ammo_nails + 30;
  371. }
  372. else if (self.classname == "weapon_supershotgun")
  373. {
  374. if (leave && (other.items & IT_SUPER_SHOTGUN) )
  375. return;
  376. hadammo = other.ammo_rockets;
  377. new = IT_SUPER_SHOTGUN;
  378. other.ammo_shells = other.ammo_shells + 5;
  379. }
  380. else if (self.classname == "weapon_rocketlauncher")
  381. {
  382. if (leave && (other.items & IT_ROCKET_LAUNCHER) )
  383. return;
  384. hadammo = other.ammo_rockets;
  385. new = IT_ROCKET_LAUNCHER;
  386. other.ammo_rockets = other.ammo_rockets + 5;
  387. }
  388. else if (self.classname == "weapon_grenadelauncher")
  389. {
  390. if (leave && (other.items & IT_GRENADE_LAUNCHER) )
  391. return;
  392. hadammo = other.ammo_rockets;
  393. new = IT_GRENADE_LAUNCHER;
  394. other.ammo_rockets = other.ammo_rockets + 5;
  395. }
  396. else if (self.classname == "weapon_lightning")
  397. {
  398. if (leave && (other.items & IT_LIGHTNING) )
  399. return;
  400. hadammo = other.ammo_rockets;
  401. new = IT_LIGHTNING;
  402. other.ammo_cells = other.ammo_cells + 15;
  403. }
  404. else
  405. objerror ("weapon_touch: unknown classname");
  406. sprint (other, "You got the ");
  407. sprint (other, self.netname);
  408. sprint (other, "\n");
  409. // weapon touch sound
  410. sound (other, CHAN_ITEM, "weapons/pkup.wav", 1, ATTN_NORM);
  411. stuffcmd (other, "bf\n");
  412. bound_other_ammo ();
  413. // change to the weapon
  414. old = other.items;
  415. other.items = other.items | new;
  416. stemp = self;
  417. self = other;
  418. if (!deathmatch)
  419. self.weapon = new;
  420. else
  421. Deathmatch_Weapon (old, new);
  422. W_SetCurrentAmmo();
  423. self = stemp;
  424. if (leave)
  425. return;
  426. // remove it in single player, or setup for respawning in deathmatch
  427. self.model = string_null;
  428. self.solid = SOLID_NOT;
  429. if (deathmatch == 1)
  430. self.nextthink = time + 30;
  431. self.think = SUB_regen;
  432. activator = other;
  433. SUB_UseTargets(); // fire all targets / killtargets
  434. };
  435. /*QUAKED weapon_supershotgun (0 .5 .8) (-16 -16 0) (16 16 32)
  436. */
  437. void() weapon_supershotgun =
  438. {
  439. precache_model ("progs/g_shot.mdl");
  440. setmodel (self, "progs/g_shot.mdl");
  441. self.weapon = IT_SUPER_SHOTGUN;
  442. self.netname = "Double-barrelled Shotgun";
  443. self.touch = weapon_touch;
  444. setsize (self, '-16 -16 0', '16 16 56');
  445. StartItem ();
  446. };
  447. /*QUAKED weapon_nailgun (0 .5 .8) (-16 -16 0) (16 16 32)
  448. */
  449. void() weapon_nailgun =
  450. {
  451. precache_model ("progs/g_nail.mdl");
  452. setmodel (self, "progs/g_nail.mdl");
  453. self.weapon = IT_NAILGUN;
  454. self.netname = "nailgun";
  455. self.touch = weapon_touch;
  456. setsize (self, '-16 -16 0', '16 16 56');
  457. StartItem ();
  458. };
  459. /*QUAKED weapon_supernailgun (0 .5 .8) (-16 -16 0) (16 16 32)
  460. */
  461. void() weapon_supernailgun =
  462. {
  463. precache_model ("progs/g_nail2.mdl");
  464. setmodel (self, "progs/g_nail2.mdl");
  465. self.weapon = IT_SUPER_NAILGUN;
  466. self.netname = "Super Nailgun";
  467. self.touch = weapon_touch;
  468. setsize (self, '-16 -16 0', '16 16 56');
  469. StartItem ();
  470. };
  471. /*QUAKED weapon_grenadelauncher (0 .5 .8) (-16 -16 0) (16 16 32)
  472. */
  473. void() weapon_grenadelauncher =
  474. {
  475. precache_model ("progs/g_rock.mdl");
  476. setmodel (self, "progs/g_rock.mdl");
  477. self.weapon = 3;
  478. self.netname = "Grenade Launcher";
  479. self.touch = weapon_touch;
  480. setsize (self, '-16 -16 0', '16 16 56');
  481. StartItem ();
  482. };
  483. /*QUAKED weapon_rocketlauncher (0 .5 .8) (-16 -16 0) (16 16 32)
  484. */
  485. void() weapon_rocketlauncher =
  486. {
  487. precache_model ("progs/g_rock2.mdl");
  488. setmodel (self, "progs/g_rock2.mdl");
  489. self.weapon = 3;
  490. self.netname = "Rocket Launcher";
  491. self.touch = weapon_touch;
  492. setsize (self, '-16 -16 0', '16 16 56');
  493. StartItem ();
  494. };
  495. /*QUAKED weapon_lightning (0 .5 .8) (-16 -16 0) (16 16 32)
  496. */
  497. void() weapon_lightning =
  498. {
  499. precache_model ("progs/g_light.mdl");
  500. setmodel (self, "progs/g_light.mdl");
  501. self.weapon = 3;
  502. self.netname = "Thunderbolt";
  503. self.touch = weapon_touch;
  504. setsize (self, '-16 -16 0', '16 16 56');
  505. StartItem ();
  506. };
  507. /*
  508. ===============================================================================
  509. AMMO
  510. ===============================================================================
  511. */
  512. void() ammo_touch =
  513. {
  514. local entity stemp;
  515. local float best;
  516. if (other.classname != "player")
  517. return;
  518. if (other.health <= 0)
  519. return;
  520. // if the player was using his best weapon, change up to the new one if better
  521. stemp = self;
  522. self = other;
  523. best = W_BestWeapon();
  524. self = stemp;
  525. // shotgun
  526. if (self.weapon == 1)
  527. {
  528. if (other.ammo_shells >= 100)
  529. return;
  530. other.ammo_shells = other.ammo_shells + self.aflag;
  531. }
  532. // spikes
  533. if (self.weapon == 2)
  534. {
  535. if (other.ammo_nails >= 200)
  536. return;
  537. other.ammo_nails = other.ammo_nails + self.aflag;
  538. }
  539. // rockets
  540. if (self.weapon == 3)
  541. {
  542. if (other.ammo_rockets >= 100)
  543. return;
  544. other.ammo_rockets = other.ammo_rockets + self.aflag;
  545. }
  546. // cells
  547. if (self.weapon == 4)
  548. {
  549. if (other.ammo_cells >= 200)
  550. return;
  551. other.ammo_cells = other.ammo_cells + self.aflag;
  552. }
  553. bound_other_ammo ();
  554. sprint (other, "You got the ");
  555. sprint (other, self.netname);
  556. sprint (other, "\n");
  557. // ammo touch sound
  558. sound (other, CHAN_ITEM, "weapons/lock4.wav", 1, ATTN_NORM);
  559. stuffcmd (other, "bf\n");
  560. // change to a better weapon if appropriate
  561. if ( other.weapon == best )
  562. {
  563. stemp = self;
  564. self = other;
  565. self.weapon = W_BestWeapon();
  566. W_SetCurrentAmmo ();
  567. self = stemp;
  568. }
  569. // if changed current ammo, update it
  570. stemp = self;
  571. self = other;
  572. W_SetCurrentAmmo();
  573. self = stemp;
  574. // remove it in single player, or setup for respawning in deathmatch
  575. self.model = string_null;
  576. self.solid = SOLID_NOT;
  577. if (deathmatch == 1)
  578. self.nextthink = time + 30;
  579. self.think = SUB_regen;
  580. activator = other;
  581. SUB_UseTargets(); // fire all targets / killtargets
  582. };
  583. float WEAPON_BIG2 = 1;
  584. /*QUAKED item_shells (0 .5 .8) (0 0 0) (32 32 32) big
  585. */
  586. void() item_shells =
  587. {
  588. self.touch = ammo_touch;
  589. if (self.spawnflags & WEAPON_BIG2)
  590. {
  591. precache_model ("maps/b_shell1.bsp");
  592. setmodel (self, "maps/b_shell1.bsp");
  593. self.aflag = 40;
  594. }
  595. else
  596. {
  597. precache_model ("maps/b_shell0.bsp");
  598. setmodel (self, "maps/b_shell0.bsp");
  599. self.aflag = 20;
  600. }
  601. self.weapon = 1;
  602. self.netname = "shells";
  603. setsize (self, '0 0 0', '32 32 56');
  604. StartItem ();
  605. };
  606. /*QUAKED item_spikes (0 .5 .8) (0 0 0) (32 32 32) big
  607. */
  608. void() item_spikes =
  609. {
  610. self.touch = ammo_touch;
  611. if (self.spawnflags & WEAPON_BIG2)
  612. {
  613. precache_model ("maps/b_nail1.bsp");
  614. setmodel (self, "maps/b_nail1.bsp");
  615. self.aflag = 50;
  616. }
  617. else
  618. {
  619. precache_model ("maps/b_nail0.bsp");
  620. setmodel (self, "maps/b_nail0.bsp");
  621. self.aflag = 25;
  622. }
  623. self.weapon = 2;
  624. self.netname = "nails";
  625. setsize (self, '0 0 0', '32 32 56');
  626. StartItem ();
  627. };
  628. /*QUAKED item_rockets (0 .5 .8) (0 0 0) (32 32 32) big
  629. */
  630. void() item_rockets =
  631. {
  632. self.touch = ammo_touch;
  633. if (self.spawnflags & WEAPON_BIG2)
  634. {
  635. precache_model ("maps/b_rock1.bsp");
  636. setmodel (self, "maps/b_rock1.bsp");
  637. self.aflag = 10;
  638. }
  639. else
  640. {
  641. precache_model ("maps/b_rock0.bsp");
  642. setmodel (self, "maps/b_rock0.bsp");
  643. self.aflag = 5;
  644. }
  645. self.weapon = 3;
  646. self.netname = "rockets";
  647. setsize (self, '0 0 0', '32 32 56');
  648. StartItem ();
  649. };
  650. /*QUAKED item_cells (0 .5 .8) (0 0 0) (32 32 32) big
  651. */
  652. void() item_cells =
  653. {
  654. self.touch = ammo_touch;
  655. if (self.spawnflags & WEAPON_BIG2)
  656. {
  657. precache_model ("maps/b_batt1.bsp");
  658. setmodel (self, "maps/b_batt1.bsp");
  659. self.aflag = 12;
  660. }
  661. else
  662. {
  663. precache_model ("maps/b_batt0.bsp");
  664. setmodel (self, "maps/b_batt0.bsp");
  665. self.aflag = 6;
  666. }
  667. self.weapon = 4;
  668. self.netname = "cells";
  669. setsize (self, '0 0 0', '32 32 56');
  670. StartItem ();
  671. };
  672. /*QUAKED item_weapon (0 .5 .8) (0 0 0) (32 32 32) shotgun rocket spikes big
  673. DO NOT USE THIS!!!! IT WILL BE REMOVED!
  674. */
  675. float WEAPON_SHOTGUN = 1;
  676. float WEAPON_ROCKET = 2;
  677. float WEAPON_SPIKES = 4;
  678. float WEAPON_BIG = 8;
  679. void() item_weapon =
  680. {
  681. self.touch = ammo_touch;
  682. if (self.spawnflags & WEAPON_SHOTGUN)
  683. {
  684. if (self.spawnflags & WEAPON_BIG)
  685. {
  686. precache_model ("maps/b_shell1.bsp");
  687. setmodel (self, "maps/b_shell1.bsp");
  688. self.aflag = 40;
  689. }
  690. else
  691. {
  692. precache_model ("maps/b_shell0.bsp");
  693. setmodel (self, "maps/b_shell0.bsp");
  694. self.aflag = 20;
  695. }
  696. self.weapon = 1;
  697. self.netname = "shells";
  698. }
  699. if (self.spawnflags & WEAPON_SPIKES)
  700. {
  701. if (self.spawnflags & WEAPON_BIG)
  702. {
  703. precache_model ("maps/b_nail1.bsp");
  704. setmodel (self, "maps/b_nail1.bsp");
  705. self.aflag = 40;
  706. }
  707. else
  708. {
  709. precache_model ("maps/b_nail0.bsp");
  710. setmodel (self, "maps/b_nail0.bsp");
  711. self.aflag = 20;
  712. }
  713. self.weapon = 2;
  714. self.netname = "spikes";
  715. }
  716. if (self.spawnflags & WEAPON_ROCKET)
  717. {
  718. if (self.spawnflags & WEAPON_BIG)
  719. {
  720. precache_model ("maps/b_rock1.bsp");
  721. setmodel (self, "maps/b_rock1.bsp");
  722. self.aflag = 10;
  723. }
  724. else
  725. {
  726. precache_model ("maps/b_rock0.bsp");
  727. setmodel (self, "maps/b_rock0.bsp");
  728. self.aflag = 5;
  729. }
  730. self.weapon = 3;
  731. self.netname = "rockets";
  732. }
  733. setsize (self, '0 0 0', '32 32 56');
  734. StartItem ();
  735. };
  736. /*
  737. ===============================================================================
  738. KEYS
  739. ===============================================================================
  740. */
  741. void() key_touch =
  742. {
  743. local entity stemp;
  744. local float best;
  745. if (other.classname != "player")
  746. return;
  747. if (other.health <= 0)
  748. return;
  749. if (other.items & self.items)
  750. return;
  751. sprint (other, "You got the ");
  752. sprint (other, self.netname);
  753. sprint (other,"\n");
  754. sound (other, CHAN_ITEM, self.noise, 1, ATTN_NORM);
  755. stuffcmd (other, "bf\n");
  756. other.items = other.items | self.items;
  757. if (!coop)
  758. {
  759. self.solid = SOLID_NOT;
  760. self.model = string_null;
  761. }
  762. activator = other;
  763. SUB_UseTargets(); // fire all targets / killtargets
  764. };
  765. void() key_setsounds =
  766. {
  767. if (world.worldtype == 0)
  768. {
  769. precache_sound ("misc/medkey.wav");
  770. self.noise = "misc/medkey.wav";
  771. }
  772. if (world.worldtype == 1)
  773. {
  774. precache_sound ("misc/runekey.wav");
  775. self.noise = "misc/runekey.wav";
  776. }
  777. if (world.worldtype == 2)
  778. {
  779. precache_sound2 ("misc/basekey.wav");
  780. self.noise = "misc/basekey.wav";
  781. }
  782. };
  783. /*QUAKED item_key1 (0 .5 .8) (-16 -16 -24) (16 16 32)
  784. SILVER key
  785. In order for keys to work
  786. you MUST set your maps
  787. worldtype to one of the
  788. following:
  789. 0: medieval
  790. 1: metal
  791. 2: base
  792. */
  793. void() item_key1 =
  794. {
  795. if (world.worldtype == 0)
  796. {
  797. precache_model ("progs/w_s_key.mdl");
  798. setmodel (self, "progs/w_s_key.mdl");
  799. self.netname = "silver key";
  800. }
  801. else if (world.worldtype == 1)
  802. {
  803. precache_model ("progs/m_s_key.mdl");
  804. setmodel (self, "progs/m_s_key.mdl");
  805. self.netname = "silver runekey";
  806. }
  807. else if (world.worldtype == 2)
  808. {
  809. precache_model2 ("progs/b_s_key.mdl");
  810. setmodel (self, "progs/b_s_key.mdl");
  811. self.netname = "silver keycard";
  812. }
  813. key_setsounds();
  814. self.touch = key_touch;
  815. self.items = IT_KEY1;
  816. setsize (self, '-16 -16 -24', '16 16 32');
  817. StartItem ();
  818. };
  819. /*QUAKED item_key2 (0 .5 .8) (-16 -16 -24) (16 16 32)
  820. GOLD key
  821. In order for keys to work
  822. you MUST set your maps
  823. worldtype to one of the
  824. following:
  825. 0: medieval
  826. 1: metal
  827. 2: base
  828. */
  829. void() item_key2 =
  830. {
  831. if (world.worldtype == 0)
  832. {
  833. precache_model ("progs/w_g_key.mdl");
  834. setmodel (self, "progs/w_g_key.mdl");
  835. self.netname = "gold key";
  836. }
  837. if (world.worldtype == 1)
  838. {
  839. precache_model ("progs/m_g_key.mdl");
  840. setmodel (self, "progs/m_g_key.mdl");
  841. self.netname = "gold runekey";
  842. }
  843. if (world.worldtype == 2)
  844. {
  845. precache_model2 ("progs/b_g_key.mdl");
  846. setmodel (self, "progs/b_g_key.mdl");
  847. self.netname = "gold keycard";
  848. }
  849. key_setsounds();
  850. self.touch = key_touch;
  851. self.items = IT_KEY2;
  852. setsize (self, '-16 -16 -24', '16 16 32');
  853. StartItem ();
  854. };
  855. /*
  856. ===============================================================================
  857. END OF LEVEL RUNES
  858. ===============================================================================
  859. */
  860. void() sigil_touch =
  861. {
  862. local entity stemp;
  863. local float best;
  864. if (other.classname != "player")
  865. return;
  866. if (other.health <= 0)
  867. return;
  868. centerprint (other, "You got the rune!");
  869. sound (other, CHAN_ITEM, self.noise, 1, ATTN_NORM);
  870. stuffcmd (other, "bf\n");
  871. self.solid = SOLID_NOT;
  872. self.model = string_null;
  873. serverflags = serverflags | (self.spawnflags & 15);
  874. self.classname = ""; // so rune doors won't find it
  875. activator = other;
  876. SUB_UseTargets(); // fire all targets / killtargets
  877. };
  878. /*QUAKED item_sigil (0 .5 .8) (-16 -16 -24) (16 16 32) E1 E2 E3 E4
  879. End of level sigil, pick up to end episode and return to jrstart.
  880. */
  881. void() item_sigil =
  882. {
  883. if (!self.spawnflags)
  884. objerror ("no spawnflags");
  885. precache_sound ("misc/runekey.wav");
  886. self.noise = "misc/runekey.wav";
  887. if (self.spawnflags & 1)
  888. {
  889. precache_model ("progs/end1.mdl");
  890. setmodel (self, "progs/end1.mdl");
  891. }
  892. if (self.spawnflags & 2)
  893. {
  894. precache_model2 ("progs/end2.mdl");
  895. setmodel (self, "progs/end2.mdl");
  896. }
  897. if (self.spawnflags & 4)
  898. {
  899. precache_model2 ("progs/end3.mdl");
  900. setmodel (self, "progs/end3.mdl");
  901. }
  902. if (self.spawnflags & 8)
  903. {
  904. precache_model2 ("progs/end4.mdl");
  905. setmodel (self, "progs/end4.mdl");
  906. }
  907. self.touch = sigil_touch;
  908. setsize (self, '-16 -16 -24', '16 16 32');
  909. StartItem ();
  910. };
  911. /*
  912. ===============================================================================
  913. POWERUPS
  914. ===============================================================================
  915. */
  916. void() powerup_touch;
  917. void() powerup_touch =
  918. {
  919. local entity stemp;
  920. local float best;
  921. if (other.classname != "player")
  922. return;
  923. if (other.health <= 0)
  924. return;
  925. sprint (other, "You got the ");
  926. sprint (other, self.netname);
  927. sprint (other,"\n");
  928. if (deathmatch)
  929. {
  930. self.mdl = self.model;
  931. if ((self.classname == "item_artifact_invulnerability") ||
  932. (self.classname == "item_artifact_invisibility"))
  933. self.nextthink = time + 60*5;
  934. else
  935. self.nextthink = time + 60;
  936. self.think = SUB_regen;
  937. }
  938. sound (other, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  939. stuffcmd (other, "bf\n");
  940. self.solid = SOLID_NOT;
  941. other.items = other.items | self.items;
  942. self.model = string_null;
  943. // do the apropriate action
  944. if (self.classname == "item_artifact_envirosuit")
  945. {
  946. other.rad_time = 1;
  947. other.radsuit_finished = time + 30;
  948. }
  949. if (self.classname == "item_artifact_invulnerability")
  950. {
  951. other.invincible_time = 1;
  952. other.invincible_finished = time + 30;
  953. }
  954. if (self.classname == "item_artifact_invisibility")
  955. {
  956. other.invisible_time = 1;
  957. other.invisible_finished = time + 30;
  958. }
  959. if (self.classname == "item_artifact_super_damage")
  960. {
  961. other.super_time = 1;
  962. other.super_damage_finished = time + 30;
  963. }
  964. activator = other;
  965. SUB_UseTargets(); // fire all targets / killtargets
  966. };
  967. /*QUAKED item_artifact_invulnerability (0 .5 .8) (-16 -16 -24) (16 16 32)
  968. Player is invulnerable for 30 seconds
  969. */
  970. void() item_artifact_invulnerability =
  971. {
  972. self.touch = powerup_touch;
  973. precache_model ("progs/invulner.mdl");
  974. precache_sound ("items/protect.wav");
  975. precache_sound ("items/protect2.wav");
  976. precache_sound ("items/protect3.wav");
  977. self.noise = "items/protect.wav";
  978. setmodel (self, "progs/invulner.mdl");
  979. self.netname = "Pentagram of Protection";
  980. self.items = IT_INVULNERABILITY;
  981. setsize (self, '-16 -16 -24', '16 16 32');
  982. StartItem ();
  983. };
  984. /*QUAKED item_artifact_envirosuit (0 .5 .8) (-16 -16 -24) (16 16 32)
  985. Player takes no damage from water or slime for 30 seconds
  986. */
  987. void() item_artifact_envirosuit =
  988. {
  989. self.touch = powerup_touch;
  990. precache_model ("progs/suit.mdl");
  991. precache_sound ("items/suit.wav");
  992. precache_sound ("items/suit2.wav");
  993. self.noise = "items/suit.wav";
  994. setmodel (self, "progs/suit.mdl");
  995. self.netname = "Biosuit";
  996. self.items = IT_SUIT;
  997. setsize (self, '-16 -16 -24', '16 16 32');
  998. StartItem ();
  999. };
  1000. /*QUAKED item_artifact_invisibility (0 .5 .8) (-16 -16 -24) (16 16 32)
  1001. Player is invisible for 30 seconds
  1002. */
  1003. void() item_artifact_invisibility =
  1004. {
  1005. self.touch = powerup_touch;
  1006. precache_model ("progs/invisibl.mdl");
  1007. precache_sound ("items/inv1.wav");
  1008. precache_sound ("items/inv2.wav");
  1009. precache_sound ("items/inv3.wav");
  1010. self.noise = "items/inv1.wav";
  1011. setmodel (self, "progs/invisibl.mdl");
  1012. self.netname = "Ring of Shadows";
  1013. self.items = IT_INVISIBILITY;
  1014. setsize (self, '-16 -16 -24', '16 16 32');
  1015. StartItem ();
  1016. };
  1017. /*QUAKED item_artifact_super_damage (0 .5 .8) (-16 -16 -24) (16 16 32)
  1018. The next attack from the player will do 4x damage
  1019. */
  1020. void() item_artifact_super_damage =
  1021. {
  1022. self.touch = powerup_touch;
  1023. precache_model ("progs/quaddama.mdl");
  1024. precache_sound ("items/damage.wav");
  1025. precache_sound ("items/damage2.wav");
  1026. precache_sound ("items/damage3.wav");
  1027. self.noise = "items/damage.wav";
  1028. setmodel (self, "progs/quaddama.mdl");
  1029. self.netname = "Quad Damage";
  1030. self.items = IT_QUAD;
  1031. setsize (self, '-16 -16 -24', '16 16 32');
  1032. StartItem ();
  1033. };
  1034. /*
  1035. ===============================================================================
  1036. PLAYER BACKPACKS
  1037. ===============================================================================
  1038. */
  1039. void() BackpackTouch =
  1040. {
  1041. local string s;
  1042. local float best;
  1043. local entity stemp;
  1044. if (other.classname != "player")
  1045. return;
  1046. if (other.health <= 0)
  1047. return;
  1048. // if the player was using his best weapon, change up to the new one if better
  1049. stemp = self;
  1050. self = other;
  1051. best = W_BestWeapon();
  1052. self = stemp;
  1053. // change weapons
  1054. other.ammo_shells = other.ammo_shells + self.ammo_shells;
  1055. other.ammo_nails = other.ammo_nails + self.ammo_nails;
  1056. other.ammo_rockets = other.ammo_rockets + self.ammo_rockets;
  1057. other.ammo_cells = other.ammo_cells + self.ammo_cells;
  1058. other.items = other.items | self.items;
  1059. bound_other_ammo ();
  1060. sprint (other, "You get ");
  1061. if (self.ammo_shells)
  1062. {
  1063. s = ftos(self.ammo_shells);
  1064. sprint (other, s);
  1065. sprint (other, " shells ");
  1066. }
  1067. if (self.ammo_nails)
  1068. {
  1069. s = ftos(self.ammo_nails);
  1070. sprint (other, s);
  1071. sprint (other, " nails ");
  1072. }
  1073. if (self.ammo_rockets)
  1074. {
  1075. s = ftos(self.ammo_rockets);
  1076. sprint (other, s);
  1077. sprint (other, " rockets ");
  1078. }
  1079. if (self.ammo_cells)
  1080. {
  1081. s = ftos(self.ammo_cells);
  1082. sprint (other, s);
  1083. sprint (other, " cells ");
  1084. }
  1085. sprint (other, "\n");
  1086. // backpack touch sound
  1087. sound (other, CHAN_ITEM, "weapons/lock4.wav", 1, ATTN_NORM);
  1088. stuffcmd (other, "bf\n");
  1089. // change to a better weapon if appropriate
  1090. if ( other.weapon == best )
  1091. {
  1092. stemp = self;
  1093. self = other;
  1094. self.weapon = W_BestWeapon();
  1095. self = stemp;
  1096. }
  1097. remove(self);
  1098. self = other;
  1099. W_SetCurrentAmmo ();
  1100. };
  1101. /*
  1102. ===============
  1103. DropBackpack
  1104. ===============
  1105. */
  1106. void() DropBackpack =
  1107. {
  1108. local entity item;
  1109. if (!(self.ammo_shells + self.ammo_nails + self.ammo_rockets + self.ammo_cells))
  1110. return; // nothing in it
  1111. item = spawn();
  1112. item.origin = self.origin - '0 0 24';
  1113. item.items = self.weapon;
  1114. item.ammo_shells = self.ammo_shells;
  1115. item.ammo_nails = self.ammo_nails;
  1116. item.ammo_rockets = self.ammo_rockets;
  1117. item.ammo_cells = self.ammo_cells;
  1118. item.velocity_z = 300;
  1119. item.velocity_x = -100 + (random() * 200);
  1120. item.velocity_y = -100 + (random() * 200);
  1121. item.flags = FL_ITEM;
  1122. item.solid = SOLID_TRIGGER;
  1123. item.movetype = MOVETYPE_TOSS;
  1124. setmodel (item, "progs/backpack.mdl");
  1125. setsize (item, '-16 -16 0', '16 16 56');
  1126. item.touch = BackpackTouch;
  1127. item.nextthink = time + 120; // remove after 2 minutes
  1128. item.think = SUB_Remove;
  1129. };