client.qc 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457
  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. // prototypes
  16. void () W_WeaponFrame;
  17. void() W_SetCurrentAmmo;
  18. void() player_pain;
  19. void() player_stand1;
  20. void (vector org) spawn_tfog;
  21. void (vector org, entity death_owner) spawn_tdeath;
  22. float modelindex_eyes, modelindex_player;
  23. /*
  24. =============================================================================
  25. LEVEL CHANGING / INTERMISSION
  26. =============================================================================
  27. */
  28. float intermission_running;
  29. float intermission_exittime;
  30. /*QUAKED info_intermission (1 0.5 0.5) (-16 -16 -16) (16 16 16)
  31. This is the camera point for the intermission.
  32. Use mangle instead of angle, so you can set pitch or roll as well as yaw. 'pitch roll yaw'
  33. */
  34. void() info_intermission =
  35. {
  36. };
  37. void() SetChangeParms =
  38. {
  39. // remove items
  40. self.items = self.items - (self.items &
  41. (IT_KEY1 | IT_KEY2 | IT_INVISIBILITY | IT_INVULNERABILITY | IT_SUIT | IT_QUAD) );
  42. // cap super health
  43. if (self.health > 100)
  44. self.health = 100;
  45. if (self.health < 50)
  46. self.health = 50;
  47. parm1 = self.items;
  48. parm2 = self.health;
  49. parm3 = self.armorvalue;
  50. if (self.ammo_shells < 25)
  51. parm4 = 25;
  52. else
  53. parm4 = self.ammo_shells;
  54. parm5 = self.ammo_nails;
  55. parm6 = self.ammo_rockets;
  56. parm7 = self.ammo_cells;
  57. parm8 = self.weapon;
  58. parm9 = self.armortype * 100;
  59. };
  60. void() SetNewParms =
  61. {
  62. parm1 = IT_SHOTGUN | IT_AXE;
  63. parm2 = 100;
  64. parm3 = 0;
  65. parm4 = 25;
  66. parm5 = 0;
  67. parm6 = 0;
  68. parm6 = 0;
  69. parm8 = 1;
  70. parm9 = 0;
  71. };
  72. void() DecodeLevelParms =
  73. {
  74. if (serverflags)
  75. {
  76. if (world.model == "maps/start.bsp")
  77. SetNewParms (); // take away all stuff on starting new episode
  78. }
  79. self.items = parm1;
  80. self.health = parm2;
  81. self.armorvalue = parm3;
  82. self.ammo_shells = parm4;
  83. self.ammo_nails = parm5;
  84. self.ammo_rockets = parm6;
  85. self.ammo_cells = parm7;
  86. self.weapon = parm8;
  87. self.armortype = parm9 * 0.01;
  88. };
  89. /*
  90. ============
  91. FindIntermission
  92. Returns the entity to view from
  93. ============
  94. */
  95. entity() FindIntermission =
  96. {
  97. local entity spot;
  98. local float cyc;
  99. // look for info_intermission first
  100. spot = find (world, classname, "info_intermission");
  101. if (spot)
  102. { // pick a random one
  103. cyc = random() * 4;
  104. while (cyc > 1)
  105. {
  106. spot = find (spot, classname, "info_intermission");
  107. if (!spot)
  108. spot = find (spot, classname, "info_intermission");
  109. cyc = cyc - 1;
  110. }
  111. return spot;
  112. }
  113. // then look for the start position
  114. spot = find (world, classname, "info_player_start");
  115. if (spot)
  116. return spot;
  117. // testinfo_player_start is only found in regioned levels
  118. spot = find (world, classname, "testplayerstart");
  119. if (spot)
  120. return spot;
  121. objerror ("FindIntermission: no spot");
  122. };
  123. string nextmap;
  124. void() GotoNextMap =
  125. {
  126. if (cvar("samelevel")) // if samelevel is set, stay on same level
  127. changelevel (mapname);
  128. else
  129. changelevel (nextmap);
  130. };
  131. void() ExitIntermission =
  132. {
  133. // skip any text in deathmatch
  134. if (deathmatch)
  135. {
  136. GotoNextMap ();
  137. return;
  138. }
  139. intermission_exittime = time + 1;
  140. intermission_running = intermission_running + 1;
  141. //
  142. // run some text if at the end of an episode
  143. //
  144. if (intermission_running == 2)
  145. {
  146. if (world.model == "maps/e1m7.bsp")
  147. {
  148. WriteByte (MSG_ALL, SVC_CDTRACK);
  149. WriteByte (MSG_ALL, 2);
  150. WriteByte (MSG_ALL, 3);
  151. if (!cvar("registered"))
  152. {
  153. WriteByte (MSG_ALL, SVC_FINALE);
  154. WriteString (MSG_ALL, "As the corpse of the monstrous entity\nChthon sinks back into the lava whence\nit rose, you grip the Rune of Earth\nMagic tightly. Now that you have\nconquered the Dimension of the Doomed,\nrealm of Earth Magic, you are ready to\ncomplete your task in the other three\nhaunted lands of Quake. Or are you? If\nyou don't register Quake, you'll never\nknow what awaits you in the Realm of\nBlack Magic, the Netherworld, and the\nElder World!");
  155. }
  156. else
  157. {
  158. WriteByte (MSG_ALL, SVC_FINALE);
  159. WriteString (MSG_ALL, "As the corpse of the monstrous entity\nChthon sinks back into the lava whence\nit rose, you grip the Rune of Earth\nMagic tightly. Now that you have\nconquered the Dimension of the Doomed,\nrealm of Earth Magic, you are ready to\ncomplete your task. A Rune of magic\npower lies at the end of each haunted\nland of Quake. Go forth, seek the\ntotality of the four Runes!");
  160. }
  161. return;
  162. }
  163. else if (world.model == "maps/e2m6.bsp")
  164. {
  165. WriteByte (MSG_ALL, SVC_CDTRACK);
  166. WriteByte (MSG_ALL, 2);
  167. WriteByte (MSG_ALL, 3);
  168. WriteByte (MSG_ALL, SVC_FINALE);
  169. WriteString (MSG_ALL, "The Rune of Black Magic throbs evilly in\nyour hand and whispers dark thoughts\ninto your brain. You learn the inmost\nlore of the Hell-Mother; Shub-Niggurath!\nYou now know that she is behind all the\nterrible plotting which has led to so\nmuch death and horror. But she is not\ninviolate! Armed with this Rune, you\nrealize that once all four Runes are\ncombined, the gate to Shub-Niggurath's\nPit will open, and you can face the\nWitch-Goddess herself in her frightful\notherworld cathedral.");
  170. return;
  171. }
  172. else if (world.model == "maps/e3m6.bsp")
  173. {
  174. WriteByte (MSG_ALL, SVC_CDTRACK);
  175. WriteByte (MSG_ALL, 2);
  176. WriteByte (MSG_ALL, 3);
  177. WriteByte (MSG_ALL, SVC_FINALE);
  178. WriteString (MSG_ALL, "The charred viscera of diabolic horrors\nbubble viscously as you seize the Rune\nof Hell Magic. Its heat scorches your\nhand, and its terrible secrets blight\nyour mind. Gathering the shreds of your\ncourage, you shake the devil's shackles\nfrom your soul, and become ever more\nhard and determined to destroy the\nhideous creatures whose mere existence\nthreatens the souls and psyches of all\nthe population of Earth.");
  179. return;
  180. }
  181. else if (world.model == "maps/e4m7.bsp")
  182. {
  183. WriteByte (MSG_ALL, SVC_CDTRACK);
  184. WriteByte (MSG_ALL, 2);
  185. WriteByte (MSG_ALL, 3);
  186. WriteByte (MSG_ALL, SVC_FINALE);
  187. WriteString (MSG_ALL, "Despite the awful might of the Elder\nWorld, you have achieved the Rune of\nElder Magic, capstone of all types of\narcane wisdom. Beyond good and evil,\nbeyond life and death, the Rune\npulsates, heavy with import. Patient and\npotent, the Elder Being Shub-Niggurath\nweaves her dire plans to clear off all\nlife from the Earth, and bring her own\nfoul offspring to our world! For all the\ndwellers in these nightmare dimensions\nare her descendants! Once all Runes of\nmagic power are united, the energy\nbehind them will blast open the Gateway\nto Shub-Niggurath, and you can travel\nthere to foil the Hell-Mother's plots\nin person.");
  188. return;
  189. }
  190. GotoNextMap();
  191. }
  192. if (intermission_running == 3)
  193. {
  194. if (!cvar("registered"))
  195. { // shareware episode has been completed, go to sell screen
  196. WriteByte (MSG_ALL, SVC_SELLSCREEN);
  197. return;
  198. }
  199. if ( (serverflags&15) == 15)
  200. {
  201. WriteByte (MSG_ALL, SVC_FINALE);
  202. WriteString (MSG_ALL, "Now, you have all four Runes. You sense\ntremendous invisible forces moving to\nunseal ancient barriers. Shub-Niggurath\nhad hoped to use the Runes Herself to\nclear off the Earth, but now instead,\nyou will use them to enter her home and\nconfront her as an avatar of avenging\nEarth-life. If you defeat her, you will\nbe remembered forever as the savior of\nthe planet. If she conquers, it will be\nas if you had never been born.");
  203. return;
  204. }
  205. }
  206. GotoNextMap();
  207. };
  208. /*
  209. ============
  210. IntermissionThink
  211. When the player presses attack or jump, change to the next level
  212. ============
  213. */
  214. void() IntermissionThink =
  215. {
  216. if (time < intermission_exittime)
  217. return;
  218. if (!self.button0 && !self.button1 && !self.button2)
  219. return;
  220. ExitIntermission ();
  221. };
  222. void() execute_changelevel =
  223. {
  224. local entity pos;
  225. intermission_running = 1;
  226. // enforce a wait time before allowing changelevel
  227. if (deathmatch)
  228. intermission_exittime = time + 5;
  229. else
  230. intermission_exittime = time + 2;
  231. WriteByte (MSG_ALL, SVC_CDTRACK);
  232. WriteByte (MSG_ALL, 3);
  233. WriteByte (MSG_ALL, 3);
  234. pos = FindIntermission ();
  235. other = find (world, classname, "player");
  236. while (other != world)
  237. {
  238. other.view_ofs = '0 0 0';
  239. other.angles = other.v_angle = pos.mangle;
  240. other.fixangle = TRUE; // turn this way immediately
  241. other.nextthink = time + 0.5;
  242. other.takedamage = DAMAGE_NO;
  243. other.solid = SOLID_NOT;
  244. other.movetype = MOVETYPE_NONE;
  245. other.modelindex = 0;
  246. setorigin (other, pos.origin);
  247. other = find (other, classname, "player");
  248. }
  249. WriteByte (MSG_ALL, SVC_INTERMISSION);
  250. };
  251. void() changelevel_touch =
  252. {
  253. local entity pos;
  254. if (other.classname != "player")
  255. return;
  256. if (cvar("noexit"))
  257. {
  258. T_Damage (other, self, self, 50000);
  259. return;
  260. }
  261. bprint (other.netname);
  262. bprint (" exited the level\n");
  263. nextmap = self.map;
  264. SUB_UseTargets ();
  265. if ( (self.spawnflags & 1) && (deathmatch == 0) )
  266. { // NO_INTERMISSION
  267. GotoNextMap();
  268. return;
  269. }
  270. self.touch = SUB_Null;
  271. // we can't move people right now, because touch functions are called
  272. // in the middle of C movement code, so set a think time to do it
  273. self.think = execute_changelevel;
  274. self.nextthink = time + 0.1;
  275. };
  276. /*QUAKED trigger_changelevel (0.5 0.5 0.5) ? NO_INTERMISSION
  277. When the player touches this, he gets sent to the map listed in the "map" variable. Unless the NO_INTERMISSION flag is set, the view will go to the info_intermission spot and display stats.
  278. */
  279. void() trigger_changelevel =
  280. {
  281. if (!self.map)
  282. objerror ("chagnelevel trigger doesn't have map");
  283. InitTrigger ();
  284. self.touch = changelevel_touch;
  285. };
  286. /*
  287. =============================================================================
  288. PLAYER GAME EDGE FUNCTIONS
  289. =============================================================================
  290. */
  291. void() set_suicide_frame;
  292. // called by ClientKill and DeadThink
  293. void() respawn =
  294. {
  295. if (coop)
  296. {
  297. // make a copy of the dead body for appearances sake
  298. CopyToBodyQue (self);
  299. // get the spawn parms as they were at level start
  300. setspawnparms (self);
  301. // respawn
  302. PutClientInServer ();
  303. }
  304. else if (deathmatch)
  305. {
  306. // make a copy of the dead body for appearances sake
  307. CopyToBodyQue (self);
  308. // set default spawn parms
  309. SetNewParms ();
  310. // respawn
  311. PutClientInServer ();
  312. }
  313. else
  314. { // restart the entire server
  315. localcmd ("restart\n");
  316. }
  317. };
  318. /*
  319. ============
  320. ClientKill
  321. Player entered the suicide command
  322. ============
  323. */
  324. void() ClientKill =
  325. {
  326. bprint (self.netname);
  327. bprint (" suicides\n");
  328. set_suicide_frame ();
  329. self.modelindex = modelindex_player;
  330. self.frags = self.frags - 2; // extra penalty
  331. respawn ();
  332. };
  333. float(vector v) CheckSpawnPoint =
  334. {
  335. return FALSE;
  336. };
  337. /*
  338. ============
  339. SelectSpawnPoint
  340. Returns the entity to spawn at
  341. ============
  342. */
  343. entity() SelectSpawnPoint =
  344. {
  345. local entity spot;
  346. // testinfo_player_start is only found in regioned levels
  347. spot = find (world, classname, "testplayerstart");
  348. if (spot)
  349. return spot;
  350. // choose a info_player_deathmatch point
  351. if (coop)
  352. {
  353. lastspawn = find(lastspawn, classname, "info_player_coop");
  354. if (lastspawn == world)
  355. lastspawn = find (lastspawn, classname, "info_player_start");
  356. if (lastspawn != world)
  357. return lastspawn;
  358. }
  359. else if (deathmatch)
  360. {
  361. lastspawn = find(lastspawn, classname, "info_player_deathmatch");
  362. if (lastspawn == world)
  363. lastspawn = find (lastspawn, classname, "info_player_deathmatch");
  364. if (lastspawn != world)
  365. return lastspawn;
  366. }
  367. if (serverflags)
  368. { // return with a rune to start
  369. spot = find (world, classname, "info_player_start2");
  370. if (spot)
  371. return spot;
  372. }
  373. spot = find (world, classname, "info_player_start");
  374. if (!spot)
  375. error ("PutClientInServer: no info_player_start on level");
  376. return spot;
  377. };
  378. /*
  379. ===========
  380. PutClientInServer
  381. called each time a player is spawned
  382. ============
  383. */
  384. void() DecodeLevelParms;
  385. void() PlayerDie;
  386. void() PutClientInServer =
  387. {
  388. local entity spot;
  389. self.classname = "player";
  390. self.health = 100;
  391. self.takedamage = DAMAGE_AIM;
  392. self.solid = SOLID_SLIDEBOX;
  393. self.movetype = MOVETYPE_WALK;
  394. self.show_hostile = 0;
  395. self.max_health = 100;
  396. self.flags = FL_CLIENT;
  397. self.air_finished = time + 12;
  398. self.dmg = 2; // initial water damage
  399. self.super_damage_finished = 0;
  400. self.radsuit_finished = 0;
  401. self.invisible_finished = 0;
  402. self.invincible_finished = 0;
  403. self.effects = 0;
  404. self.invincible_time = 0;
  405. DecodeLevelParms ();
  406. W_SetCurrentAmmo ();
  407. self.attack_finished = time;
  408. self.th_pain = player_pain;
  409. self.th_die = PlayerDie;
  410. self.deadflag = DEAD_NO;
  411. // paustime is set by teleporters to keep the player from moving a while
  412. self.pausetime = 0;
  413. spot = SelectSpawnPoint ();
  414. self.origin = spot.origin + '0 0 1';
  415. self.angles = spot.angles;
  416. self.fixangle = TRUE; // turn this way immediately
  417. // oh, this is a hack!
  418. setmodel (self, "progs/eyes.mdl");
  419. modelindex_eyes = self.modelindex;
  420. setmodel (self, "progs/player.mdl");
  421. modelindex_player = self.modelindex;
  422. setsize (self, VEC_HULL_MIN, VEC_HULL_MAX);
  423. self.view_ofs = '0 0 22';
  424. player_stand1 ();
  425. if (deathmatch || coop)
  426. {
  427. makevectors(self.angles);
  428. spawn_tfog (self.origin + v_forward*20);
  429. }
  430. spawn_tdeath (self.origin, self);
  431. };
  432. /*
  433. =============================================================================
  434. QUAKED FUNCTIONS
  435. =============================================================================
  436. */
  437. /*QUAKED info_player_start (1 0 0) (-16 -16 -24) (16 16 24)
  438. The normal starting point for a level.
  439. */
  440. void() info_player_start =
  441. {
  442. };
  443. /*QUAKED info_player_start2 (1 0 0) (-16 -16 -24) (16 16 24)
  444. Only used on start map for the return point from an episode.
  445. */
  446. void() info_player_start2 =
  447. {
  448. };
  449. /*
  450. saved out by quaked in region mode
  451. */
  452. void() testplayerstart =
  453. {
  454. };
  455. /*QUAKED info_player_deathmatch (1 0 1) (-16 -16 -24) (16 16 24)
  456. potential spawning position for deathmatch games
  457. */
  458. void() info_player_deathmatch =
  459. {
  460. };
  461. /*QUAKED info_player_coop (1 0 1) (-16 -16 -24) (16 16 24)
  462. potential spawning position for coop games
  463. */
  464. void() info_player_coop =
  465. {
  466. };
  467. /*
  468. ===============================================================================
  469. RULES
  470. ===============================================================================
  471. */
  472. void(entity c) PrintClientScore =
  473. {
  474. if (c.frags > -10 && c.frags < 0)
  475. bprint (" ");
  476. else if (c.frags >= 0)
  477. {
  478. if (c.frags < 100)
  479. bprint (" ");
  480. if (c.frags < 10)
  481. bprint (" ");
  482. }
  483. bprint (ftos(c.frags));
  484. bprint (" ");
  485. bprint (c.netname);
  486. bprint ("\n");
  487. };
  488. void() DumpScore =
  489. {
  490. local entity e, sort, walk;
  491. if (world.chain)
  492. error ("DumpScore: world.chain is set");
  493. // build a sorted lis
  494. e = find(world, classname, "player");
  495. sort = world;
  496. while (e)
  497. {
  498. if (!sort)
  499. {
  500. sort = e;
  501. e.chain = world;
  502. }
  503. else
  504. {
  505. if (e.frags > sort.frags)
  506. {
  507. e.chain = sort;
  508. sort = e;
  509. }
  510. else
  511. {
  512. walk = sort;
  513. do
  514. {
  515. if (!walk.chain)
  516. {
  517. e.chain = world;
  518. walk.chain = e;
  519. }
  520. else if (walk.chain.frags < e.frags)
  521. {
  522. e.chain = walk.chain;
  523. walk.chain = e;
  524. }
  525. else
  526. walk = walk.chain;
  527. } while (walk.chain != e);
  528. }
  529. }
  530. e = find(e, classname, "player");
  531. }
  532. // print the list
  533. bprint ("\n");
  534. while (sort)
  535. {
  536. PrintClientScore (sort);
  537. sort = sort.chain;
  538. }
  539. bprint ("\n");
  540. };
  541. /*
  542. go to the next level for deathmatch
  543. */
  544. void() NextLevel =
  545. {
  546. local entity o;
  547. // find a trigger changelevel
  548. o = find(world, classname, "trigger_changelevel");
  549. if (!o || mapname == "start")
  550. { // go back to same map if no trigger_changelevel
  551. o = spawn();
  552. o.map = mapname;
  553. }
  554. nextmap = o.map;
  555. if (o.nextthink < time)
  556. {
  557. o.think = execute_changelevel;
  558. o.nextthink = time + 0.1;
  559. }
  560. };
  561. /*
  562. ============
  563. CheckRules
  564. Exit deathmatch games upon conditions
  565. ============
  566. */
  567. void() CheckRules =
  568. {
  569. local float timelimit;
  570. local float fraglimit;
  571. if (gameover) // someone else quit the game already
  572. return;
  573. timelimit = cvar("timelimit") * 60;
  574. fraglimit = cvar("fraglimit");
  575. if (timelimit && time >= timelimit)
  576. {
  577. NextLevel ();
  578. /*
  579. gameover = TRUE;
  580. bprint ("\n\n\n==============================\n");
  581. bprint ("game exited after ");
  582. bprint (ftos(timelimit/60));
  583. bprint (" minutes\n");
  584. DumpScore ();
  585. localcmd ("killserver\n");
  586. */
  587. return;
  588. }
  589. if (fraglimit && self.frags >= fraglimit)
  590. {
  591. NextLevel ();
  592. /*
  593. gameover = TRUE;
  594. bprint ("\n\n\n==============================\n");
  595. bprint ("game exited after ");
  596. bprint (ftos(self.frags));
  597. bprint (" frags\n");
  598. DumpScore ();
  599. localcmd ("killserver\n");
  600. */
  601. return;
  602. }
  603. };
  604. //============================================================================
  605. void() PlayerDeathThink =
  606. {
  607. local entity old_self;
  608. local float forward;
  609. if ((self.flags & FL_ONGROUND))
  610. {
  611. forward = vlen (self.velocity);
  612. forward = forward - 20;
  613. if (forward <= 0)
  614. self.velocity = '0 0 0';
  615. else
  616. self.velocity = forward * normalize(self.velocity);
  617. }
  618. // wait for all buttons released
  619. if (self.deadflag == DEAD_DEAD)
  620. {
  621. if (self.button2 || self.button1 || self.button0)
  622. return;
  623. self.deadflag = DEAD_RESPAWNABLE;
  624. return;
  625. }
  626. // wait for any button down
  627. if (!self.button2 && !self.button1 && !self.button0)
  628. return;
  629. self.button0 = 0;
  630. self.button1 = 0;
  631. self.button2 = 0;
  632. respawn();
  633. };
  634. void() PlayerJump =
  635. {
  636. local vector start, end;
  637. if (self.flags & FL_WATERJUMP)
  638. return;
  639. if (self.waterlevel >= 2)
  640. {
  641. if (self.watertype == CONTENT_WATER)
  642. self.velocity_z = 100;
  643. else if (self.watertype == CONTENT_SLIME)
  644. self.velocity_z = 80;
  645. else
  646. self.velocity_z = 50;
  647. // play swiming sound
  648. if (self.swim_flag < time)
  649. {
  650. self.swim_flag = time + 1;
  651. if (random() < 0.5)
  652. sound (self, CHAN_BODY, "misc/water1.wav", 1, ATTN_NORM);
  653. else
  654. sound (self, CHAN_BODY, "misc/water2.wav", 1, ATTN_NORM);
  655. }
  656. return;
  657. }
  658. if (!(self.flags & FL_ONGROUND))
  659. return;
  660. if ( !(self.flags & FL_JUMPRELEASED) )
  661. return; // don't pogo stick
  662. self.flags = self.flags - (self.flags & FL_JUMPRELEASED);
  663. self.flags = self.flags - FL_ONGROUND; // don't stairwalk
  664. self.button2 = 0;
  665. // player jumping sound
  666. sound (self, CHAN_BODY, "player/plyrjmp8.wav", 1, ATTN_NORM);
  667. self.velocity_z = self.velocity_z + 270;
  668. };
  669. /*
  670. ===========
  671. WaterMove
  672. ============
  673. */
  674. .float dmgtime;
  675. void() WaterMove =
  676. {
  677. //dprint (ftos(self.waterlevel));
  678. if (self.movetype == MOVETYPE_NOCLIP)
  679. return;
  680. if (self.health < 0)
  681. return;
  682. if (self.waterlevel != 3)
  683. {
  684. if (self.air_finished < time)
  685. sound (self, CHAN_VOICE, "player/gasp2.wav", 1, ATTN_NORM);
  686. else if (self.air_finished < time + 9)
  687. sound (self, CHAN_VOICE, "player/gasp1.wav", 1, ATTN_NORM);
  688. self.air_finished = time + 12;
  689. self.dmg = 2;
  690. }
  691. else if (self.air_finished < time)
  692. { // drown!
  693. if (self.pain_finished < time)
  694. {
  695. self.dmg = self.dmg + 2;
  696. if (self.dmg > 15)
  697. self.dmg = 10;
  698. T_Damage (self, world, world, self.dmg);
  699. self.pain_finished = time + 1;
  700. }
  701. }
  702. if (!self.waterlevel)
  703. {
  704. if (self.flags & FL_INWATER)
  705. {
  706. // play leave water sound
  707. sound (self, CHAN_BODY, "misc/outwater.wav", 1, ATTN_NORM);
  708. self.flags = self.flags - FL_INWATER;
  709. }
  710. return;
  711. }
  712. if (self.watertype == CONTENT_LAVA)
  713. { // do damage
  714. if (self.dmgtime < time)
  715. {
  716. if (self.radsuit_finished > time)
  717. self.dmgtime = time + 1;
  718. else
  719. self.dmgtime = time + 0.2;
  720. T_Damage (self, world, world, 10*self.waterlevel);
  721. }
  722. }
  723. else if (self.watertype == CONTENT_SLIME)
  724. { // do damage
  725. if (self.dmgtime < time && self.radsuit_finished < time)
  726. {
  727. self.dmgtime = time + 1;
  728. T_Damage (self, world, world, 4*self.waterlevel);
  729. }
  730. }
  731. if ( !(self.flags & FL_INWATER) )
  732. {
  733. // player enter water sound
  734. if (self.watertype == CONTENT_LAVA)
  735. sound (self, CHAN_BODY, "player/inlava.wav", 1, ATTN_NORM);
  736. if (self.watertype == CONTENT_WATER)
  737. sound (self, CHAN_BODY, "player/inh2o.wav", 1, ATTN_NORM);
  738. if (self.watertype == CONTENT_SLIME)
  739. sound (self, CHAN_BODY, "player/slimbrn2.wav", 1, ATTN_NORM);
  740. self.flags = self.flags + FL_INWATER;
  741. self.dmgtime = 0;
  742. }
  743. if (! (self.flags & FL_WATERJUMP) )
  744. self.velocity = self.velocity - 0.8*self.waterlevel*frametime*self.velocity;
  745. };
  746. void() CheckWaterJump =
  747. {
  748. local vector start, end;
  749. // check for a jump-out-of-water
  750. makevectors (self.angles);
  751. start = self.origin;
  752. start_z = start_z + 8;
  753. v_forward_z = 0;
  754. normalize(v_forward);
  755. end = start + v_forward*24;
  756. traceline (start, end, TRUE, self);
  757. if (trace_fraction < 1)
  758. { // solid at waist
  759. start_z = start_z + self.maxs_z - 8;
  760. end = start + v_forward*24;
  761. self.movedir = trace_plane_normal * -50;
  762. traceline (start, end, TRUE, self);
  763. if (trace_fraction == 1)
  764. { // open at eye level
  765. self.flags = self.flags | FL_WATERJUMP;
  766. self.velocity_z = 225;
  767. self.flags = self.flags - (self.flags & FL_JUMPRELEASED);
  768. self.teleport_time = time + 2; // safety net
  769. return;
  770. }
  771. }
  772. };
  773. /*
  774. ================
  775. PlayerPreThink
  776. Called every frame before physics are run
  777. ================
  778. */
  779. void() PlayerPreThink =
  780. {
  781. local float mspeed, aspeed;
  782. local float r;
  783. if (intermission_running)
  784. {
  785. IntermissionThink (); // otherwise a button could be missed between
  786. return; // the think tics
  787. }
  788. if (self.view_ofs == '0 0 0')
  789. return; // intermission or finale
  790. makevectors (self.v_angle); // is this still used
  791. CheckRules ();
  792. WaterMove ();
  793. if (self.waterlevel == 2)
  794. CheckWaterJump ();
  795. if (self.deadflag >= DEAD_DEAD)
  796. {
  797. PlayerDeathThink ();
  798. return;
  799. }
  800. if (self.deadflag == DEAD_DYING)
  801. return; // dying, so do nothing
  802. if (self.button2)
  803. {
  804. PlayerJump ();
  805. }
  806. else
  807. self.flags = self.flags | FL_JUMPRELEASED;
  808. // teleporters can force a non-moving pause time
  809. if (time < self.pausetime)
  810. self.velocity = '0 0 0';
  811. };
  812. /*
  813. ================
  814. CheckPowerups
  815. Check for turning off powerups
  816. ================
  817. */
  818. void() CheckPowerups =
  819. {
  820. if (self.health <= 0)
  821. return;
  822. // invisibility
  823. if (self.invisible_finished)
  824. {
  825. // sound and screen flash when items starts to run out
  826. if (self.invisible_sound < time)
  827. {
  828. sound (self, CHAN_AUTO, "items/inv3.wav", 0.5, ATTN_IDLE);
  829. self.invisible_sound = time + ((random() * 3) + 1);
  830. }
  831. if (self.invisible_finished < time + 3)
  832. {
  833. if (self.invisible_time == 1)
  834. {
  835. sprint (self, "Ring of Shadows magic is fading\n");
  836. stuffcmd (self, "bf\n");
  837. sound (self, CHAN_AUTO, "items/inv2.wav", 1, ATTN_NORM);
  838. self.invisible_time = time + 1;
  839. }
  840. if (self.invisible_time < time)
  841. {
  842. self.invisible_time = time + 1;
  843. stuffcmd (self, "bf\n");
  844. }
  845. }
  846. if (self.invisible_finished < time)
  847. { // just stopped
  848. self.items = self.items - IT_INVISIBILITY;
  849. self.invisible_finished = 0;
  850. self.invisible_time = 0;
  851. }
  852. // use the eyes
  853. self.frame = 0;
  854. self.modelindex = modelindex_eyes;
  855. }
  856. else
  857. self.modelindex = modelindex_player; // don't use eyes
  858. // invincibility
  859. if (self.invincible_finished)
  860. {
  861. // sound and screen flash when items starts to run out
  862. if (self.invincible_finished < time + 3)
  863. {
  864. if (self.invincible_time == 1)
  865. {
  866. sprint (self, "Protection is almost burned out\n");
  867. stuffcmd (self, "bf\n");
  868. sound (self, CHAN_AUTO, "items/protect2.wav", 1, ATTN_NORM);
  869. self.invincible_time = time + 1;
  870. }
  871. if (self.invincible_time < time)
  872. {
  873. self.invincible_time = time + 1;
  874. stuffcmd (self, "bf\n");
  875. }
  876. }
  877. if (self.invincible_finished < time)
  878. { // just stopped
  879. self.items = self.items - IT_INVULNERABILITY;
  880. self.invincible_time = 0;
  881. self.invincible_finished = 0;
  882. }
  883. if (self.invincible_finished > time)
  884. self.effects = self.effects | EF_DIMLIGHT;
  885. else
  886. self.effects = self.effects - (self.effects & EF_DIMLIGHT);
  887. }
  888. // super damage
  889. if (self.super_damage_finished)
  890. {
  891. // sound and screen flash when items starts to run out
  892. if (self.super_damage_finished < time + 3)
  893. {
  894. if (self.super_time == 1)
  895. {
  896. sprint (self, "Quad Damage is wearing off\n");
  897. stuffcmd (self, "bf\n");
  898. sound (self, CHAN_AUTO, "items/damage2.wav", 1, ATTN_NORM);
  899. self.super_time = time + 1;
  900. }
  901. if (self.super_time < time)
  902. {
  903. self.super_time = time + 1;
  904. stuffcmd (self, "bf\n");
  905. }
  906. }
  907. if (self.super_damage_finished < time)
  908. { // just stopped
  909. self.items = self.items - IT_QUAD;
  910. self.super_damage_finished = 0;
  911. self.super_time = 0;
  912. }
  913. if (self.super_damage_finished > time)
  914. self.effects = self.effects | EF_DIMLIGHT;
  915. else
  916. self.effects = self.effects - (self.effects & EF_DIMLIGHT);
  917. }
  918. // suit
  919. if (self.radsuit_finished)
  920. {
  921. self.air_finished = time + 12; // don't drown
  922. // sound and screen flash when items starts to run out
  923. if (self.radsuit_finished < time + 3)
  924. {
  925. if (self.rad_time == 1)
  926. {
  927. sprint (self, "Air supply in Biosuit expiring\n");
  928. stuffcmd (self, "bf\n");
  929. sound (self, CHAN_AUTO, "items/suit2.wav", 1, ATTN_NORM);
  930. self.rad_time = time + 1;
  931. }
  932. if (self.rad_time < time)
  933. {
  934. self.rad_time = time + 1;
  935. stuffcmd (self, "bf\n");
  936. }
  937. }
  938. if (self.radsuit_finished < time)
  939. { // just stopped
  940. self.items = self.items - IT_SUIT;
  941. self.rad_time = 0;
  942. self.radsuit_finished = 0;
  943. }
  944. }
  945. };
  946. /*
  947. ================
  948. PlayerPostThink
  949. Called every frame after physics are run
  950. ================
  951. */
  952. void() PlayerPostThink =
  953. {
  954. local float mspeed, aspeed;
  955. local float r;
  956. if (self.view_ofs == '0 0 0')
  957. return; // intermission or finale
  958. if (self.deadflag)
  959. return;
  960. // do weapon stuff
  961. W_WeaponFrame ();
  962. // check to see if player landed and play landing sound
  963. if ((self.jump_flag < -300) && (self.flags & FL_ONGROUND) && (self.health > 0))
  964. {
  965. if (self.watertype == CONTENT_WATER)
  966. sound (self, CHAN_BODY, "player/h2ojump.wav", 1, ATTN_NORM);
  967. else if (self.jump_flag < -650)
  968. {
  969. T_Damage (self, world, world, 5);
  970. sound (self, CHAN_VOICE, "player/land2.wav", 1, ATTN_NORM);
  971. self.deathtype = "falling";
  972. }
  973. else
  974. sound (self, CHAN_VOICE, "player/land.wav", 1, ATTN_NORM);
  975. self.jump_flag = 0;
  976. }
  977. if (!(self.flags & FL_ONGROUND))
  978. self.jump_flag = self.velocity_z;
  979. CheckPowerups ();
  980. };
  981. /*
  982. ===========
  983. ClientConnect
  984. called when a player connects to a server
  985. ============
  986. */
  987. void() ClientConnect =
  988. {
  989. bprint (self.netname);
  990. bprint (" entered the game\n");
  991. // a client connecting during an intermission can cause problems
  992. if (intermission_running)
  993. ExitIntermission ();
  994. };
  995. /*
  996. ===========
  997. ClientDisconnect
  998. called when a player disconnects from a server
  999. ============
  1000. */
  1001. void() ClientDisconnect =
  1002. {
  1003. if (gameover)
  1004. return;
  1005. // if the level end trigger has been activated, just return
  1006. // since they aren't *really* leaving
  1007. // let everyone else know
  1008. bprint (self.netname);
  1009. bprint (" left the game with ");
  1010. bprint (ftos(self.frags));
  1011. bprint (" frags\n");
  1012. sound (self, CHAN_BODY, "player/tornoff2.wav", 1, ATTN_NONE);
  1013. set_suicide_frame ();
  1014. };
  1015. /*
  1016. ===========
  1017. ClientObituary
  1018. called when a player dies
  1019. ============
  1020. */
  1021. void(entity targ, entity attacker) ClientObituary =
  1022. {
  1023. local float rnum;
  1024. local string deathstring, deathstring2;
  1025. rnum = random();
  1026. if (targ.classname == "player")
  1027. {
  1028. if (attacker.classname == "teledeath")
  1029. {
  1030. bprint (targ.netname);
  1031. bprint (" was telefragged by ");
  1032. bprint (attacker.owner.netname);
  1033. bprint ("\n");
  1034. attacker.owner.frags = attacker.owner.frags + 1;
  1035. return;
  1036. }
  1037. if (attacker.classname == "teledeath2")
  1038. {
  1039. bprint ("Satan's power deflects ");
  1040. bprint (targ.netname);
  1041. bprint ("'s telefrag\n");
  1042. targ.frags = targ.frags - 1;
  1043. return;
  1044. }
  1045. if (attacker.classname == "player")
  1046. {
  1047. if (targ == attacker)
  1048. {
  1049. // killed self
  1050. attacker.frags = attacker.frags - 1;
  1051. bprint (targ.netname);
  1052. if (targ.weapon == 64 && targ.waterlevel > 1)
  1053. {
  1054. bprint (" discharges into the water.\n");
  1055. return;
  1056. }
  1057. if (targ.weapon == 16)
  1058. bprint (" tries to put the pin back in\n");
  1059. else if (rnum)
  1060. bprint (" becomes bored with life\n");
  1061. else
  1062. bprint (" checks if his weapon is loaded\n");
  1063. return;
  1064. }
  1065. else
  1066. {
  1067. attacker.frags = attacker.frags + 1;
  1068. rnum = attacker.weapon;
  1069. if (rnum == IT_AXE)
  1070. {
  1071. deathstring = " was ax-murdered by ";
  1072. deathstring2 = "\n";
  1073. }
  1074. if (rnum == IT_SHOTGUN)
  1075. {
  1076. deathstring = " chewed on ";
  1077. deathstring2 = "'s boomstick\n";
  1078. }
  1079. if (rnum == IT_SUPER_SHOTGUN)
  1080. {
  1081. deathstring = " ate 2 loads of ";
  1082. deathstring2 = "'s buckshot\n";
  1083. }
  1084. if (rnum == IT_NAILGUN)
  1085. {
  1086. deathstring = " was nailed by ";
  1087. deathstring2 = "\n";
  1088. }
  1089. if (rnum == IT_SUPER_NAILGUN)
  1090. {
  1091. deathstring = " was punctured by ";
  1092. deathstring2 = "\n";
  1093. }
  1094. if (rnum == IT_GRENADE_LAUNCHER)
  1095. {
  1096. deathstring = " eats ";
  1097. deathstring2 = "'s pineapple\n";
  1098. if (targ.health < -40)
  1099. {
  1100. deathstring = " was gibbed by ";
  1101. deathstring2 = "'s grenade\n";
  1102. }
  1103. }
  1104. if (rnum == IT_ROCKET_LAUNCHER)
  1105. {
  1106. deathstring = " rides ";
  1107. deathstring2 = "'s rocket\n";
  1108. if (targ.health < -40)
  1109. {
  1110. deathstring = " was gibbed by ";
  1111. deathstring2 = "'s rocket\n" ;
  1112. }
  1113. }
  1114. if (rnum == IT_LIGHTNING)
  1115. {
  1116. deathstring = " accepts ";
  1117. if (attacker.waterlevel > 1)
  1118. deathstring2 = "'s discharge\n";
  1119. else
  1120. deathstring2 = "'s shaft\n";
  1121. }
  1122. bprint (targ.netname);
  1123. bprint (deathstring);
  1124. bprint (attacker.netname);
  1125. bprint (deathstring2);
  1126. }
  1127. return;
  1128. }
  1129. else
  1130. {
  1131. targ.frags = targ.frags - 1; // killed self
  1132. rnum = targ.watertype;
  1133. bprint (targ.netname);
  1134. if (rnum == -3)
  1135. {
  1136. if (random() < 0.5)
  1137. bprint (" sleeps with the fishes\n");
  1138. else
  1139. bprint (" sucks it down\n");
  1140. return;
  1141. }
  1142. else if (rnum == -4)
  1143. {
  1144. if (random() < 0.5)
  1145. bprint (" gulped a load of slime\n");
  1146. else
  1147. bprint (" can't exist on slime alone\n");
  1148. return;
  1149. }
  1150. else if (rnum == -5)
  1151. {
  1152. if (targ.health < -15)
  1153. {
  1154. bprint (" burst into flames\n");
  1155. return;
  1156. }
  1157. if (random() < 0.5)
  1158. bprint (" turned into hot slag\n");
  1159. else
  1160. bprint (" visits the Volcano God\n");
  1161. return;
  1162. }
  1163. if (attacker.flags & FL_MONSTER)
  1164. {
  1165. if (attacker.classname == "monster_army")
  1166. bprint (" was shot by a Grunt\n");
  1167. if (attacker.classname == "monster_demon1")
  1168. bprint (" was eviscerated by a Fiend\n");
  1169. if (attacker.classname == "monster_dog")
  1170. bprint (" was mauled by a Rottweiler\n");
  1171. if (attacker.classname == "monster_dragon")
  1172. bprint (" was fried by a Dragon\n");
  1173. if (attacker.classname == "monster_enforcer")
  1174. bprint (" was blasted by an Enforcer\n");
  1175. if (attacker.classname == "monster_fish")
  1176. bprint (" was fed to the Rotfish\n");
  1177. if (attacker.classname == "monster_hell_knight")
  1178. bprint (" was slain by a Death Knight\n");
  1179. if (attacker.classname == "monster_knight")
  1180. bprint (" was slashed by a Knight\n");
  1181. if (attacker.classname == "monster_ogre")
  1182. bprint (" was destroyed by an Ogre\n");
  1183. if (attacker.classname == "monster_oldone")
  1184. bprint (" became one with Shub-Niggurath\n");
  1185. if (attacker.classname == "monster_shalrath")
  1186. bprint (" was exploded by a Vore\n");
  1187. if (attacker.classname == "monster_shambler")
  1188. bprint (" was smashed by a Shambler\n");
  1189. if (attacker.classname == "monster_tarbaby")
  1190. bprint (" was slimed by a Spawn\n");
  1191. if (attacker.classname == "monster_vomit")
  1192. bprint (" was vomited on by a Vomitus\n");
  1193. if (attacker.classname == "monster_wizard")
  1194. bprint (" was scragged by a Scrag\n");
  1195. if (attacker.classname == "monster_zombie")
  1196. bprint (" joins the Zombies\n");
  1197. return;
  1198. }
  1199. if (attacker.classname == "explo_box")
  1200. {
  1201. bprint (" blew up\n");
  1202. return;
  1203. }
  1204. if (attacker.solid == SOLID_BSP && attacker != world)
  1205. {
  1206. bprint (" was squished\n");
  1207. return;
  1208. }
  1209. if (targ.deathtype == "falling")
  1210. {
  1211. targ.deathtype = "";
  1212. bprint (" fell to his death\n");
  1213. return;
  1214. }
  1215. if (attacker.classname == "trap_shooter" || attacker.classname == "trap_spikeshooter")
  1216. {
  1217. bprint (" was spiked\n");
  1218. return;
  1219. }
  1220. if (attacker.classname == "fireball")
  1221. {
  1222. bprint (" ate a lavaball\n");
  1223. return;
  1224. }
  1225. if (attacker.classname == "trigger_changelevel")
  1226. {
  1227. bprint (" tried to leave\n");
  1228. return;
  1229. }
  1230. bprint (" died\n");
  1231. }
  1232. }
  1233. };