client.qc 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065
  1. /* Copyright (C) 1996-2022 id Software LLC
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; either version 2 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  13. See file, 'COPYING', for details.
  14. */
  15. void(entity temp_player) horde_set_keys; // yoder sept24
  16. void() GibMonster;
  17. float() HordeGetPlayersAlive;
  18. // prototypes
  19. void () W_WeaponFrame;
  20. void() W_SetCurrentAmmo;
  21. void(entity attacker, float damage) player_pain;
  22. void() player_stand1;
  23. void (vector org) spawn_tfog;
  24. void (vector org, entity death_owner) spawn_tdeath;
  25. float modelindex_eyes, modelindex_player;
  26. const float NO_INTERMISSION = 1;
  27. /*
  28. =============================================================================
  29. LEVEL CHANGING / INTERMISSION
  30. =============================================================================
  31. */
  32. float intermission_running;
  33. float intermission_exittime;
  34. /*QUAKED info_intermission (1 0.5 0.5) (-16 -16 -16) (16 16 16)
  35. This is the camera point for the intermission.
  36. Use mangle instead of angle, so you can set pitch or roll as well as yaw. 'pitch roll yaw'
  37. */
  38. void() info_intermission =
  39. {
  40. };
  41. void intermission_clear_powerups(entity e)
  42. {
  43. e.items (-) IT_QUAD | IT_INVISIBILITY | IT_INVULNERABILITY | IT_SUIT;
  44. e.super_damage_finished = 0;
  45. e.super_time = 0;
  46. e.invisible_finished = 0;
  47. e.invisible_time = 0;
  48. e.invincible_finished = 0;
  49. e.invincible_time = 0;
  50. e.radsuit_finished = 0;
  51. e.rad_time = 0;
  52. }
  53. float reset_flag;
  54. void() SetChangeParms =
  55. {
  56. if(reset_flag)
  57. {
  58. setspawnparms(self);
  59. return;
  60. }
  61. if (self.health <= 0 || deathmatch)
  62. {
  63. SetNewParms ();
  64. return;
  65. }
  66. if (world.worldtype == WORLDTYPE_HUB)
  67. {
  68. SetNewParms ();
  69. return;
  70. }
  71. // remove items
  72. self.items = self.items - (self.items &
  73. (IT_KEY1 | IT_KEY2 | IT_INVISIBILITY | IT_INVULNERABILITY | IT_SUIT | IT_QUAD) );
  74. // cap super health
  75. if (self.health > self.max_health)
  76. self.health = self.max_health;
  77. if (self.health < self.max_health / 2)
  78. self.health = self.max_health / 2;
  79. // replenish ammo
  80. if (self.ammo_shells < 25)
  81. {
  82. self.ammo_shells = 25;
  83. }
  84. parm1 = self.items;
  85. parm2 = self.health;
  86. parm3 = self.armorvalue;
  87. parm4 = self.ammo_shells;
  88. parm5 = self.ammo_nails;
  89. parm6 = self.ammo_rockets;
  90. parm7 = self.ammo_cells;
  91. parm8 = self.weapon;
  92. parm9 = self.armortype * 100;
  93. };
  94. void() SetNewParms =
  95. {
  96. parm1 = IT_SHOTGUN | IT_AXE;
  97. if (skill == 3 && !deathmatch)
  98. parm2 = 50;
  99. else
  100. parm2 = 100;
  101. parm3 = 0;
  102. parm4 = 25;
  103. parm5 = 0;
  104. parm6 = 0;
  105. parm7 = 0;
  106. parm8 = 1;
  107. parm9 = 0;
  108. };
  109. void() DecodeLevelParms =
  110. {
  111. if (world.model == "maps/start.bsp" || world.worldtype == WORLDTYPE_HUB)
  112. {
  113. SetNewParms (); // take away all stuff on starting new episode
  114. }
  115. // Yoder Oct25, reset weapons between map loads
  116. if (cvar("horde"))
  117. SetNewParms ();
  118. self.items = parm1;
  119. self.health = parm2;
  120. self.armorvalue = parm3;
  121. self.ammo_shells = parm4;
  122. self.ammo_nails = parm5;
  123. self.ammo_rockets = parm6;
  124. self.ammo_cells = parm7;
  125. self.weapon = parm8;
  126. self.armortype = parm9 * 0.01;
  127. };
  128. /*
  129. ============
  130. FindIntermission
  131. Returns the entity to view from
  132. ============
  133. */
  134. entity() FindIntermission =
  135. {
  136. local entity spot;
  137. local float cyc;
  138. // look for info_intermission first
  139. spot = find (world, classname, "info_intermission");
  140. if (spot)
  141. { // pick a random one
  142. cyc = random() * 4;
  143. while (cyc > 1)
  144. {
  145. spot = find (spot, classname, "info_intermission");
  146. if (!spot)
  147. spot = find (spot, classname, "info_intermission");
  148. cyc = cyc - 1;
  149. }
  150. return spot;
  151. }
  152. // then look for the start position
  153. spot = find (world, classname, "info_player_start");
  154. if (spot)
  155. return spot;
  156. // testinfo_player_start is only found in regioned levels
  157. spot = find (world, classname, "testplayerstart");
  158. if (spot)
  159. return spot;
  160. objerror ("FindIntermission: no spot");
  161. return world;
  162. };
  163. /*
  164. ============
  165. HORDE random map pick
  166. added Aug31, 2021
  167. ============
  168. */
  169. string() HordeRandomMap =
  170. {
  171. /*local float r, loops;
  172. local string newmap;
  173. loops = 0;
  174. while(loops < 4)
  175. {
  176. r = random() * 4;
  177. if (r <= 1)
  178. newmap = "horde1";
  179. else if (r <= 2)
  180. newmap = "horde2";
  181. else if (r <= 3)
  182. newmap = "horde3";
  183. else
  184. newmap = "horde4";
  185. if !(mapname == newmap)
  186. return newmap;
  187. else
  188. loops += 1;
  189. }
  190. */
  191. //dprint("go with next map in progression\n");
  192. if (mapname == "horde1")
  193. return "horde2";
  194. else if (mapname == "horde2")
  195. return "horde3";
  196. else if (mapname == "horde3")
  197. return "horde4";
  198. else
  199. return "horde1";
  200. };
  201. string nextmap;
  202. void() GotoNextMap =
  203. {
  204. if (cvar("samelevel")) // if samelevel is set, stay on same level
  205. changelevel (mapname);
  206. else
  207. {
  208. if (cvar("horde"))
  209. changelevel(HordeRandomMap());
  210. else
  211. changelevel (nextmap);
  212. }
  213. };
  214. string intermissiontext;
  215. void() ExitIntermission =
  216. {
  217. // skip any text in deathmatch
  218. if (deathmatch)
  219. {
  220. GotoNextMap ();
  221. return;
  222. }
  223. intermission_exittime = time + 1;
  224. intermission_running = intermission_running + 1;
  225. //
  226. // run some text if at the end of an episode
  227. //
  228. if (intermission_running == 2)
  229. {
  230. if (world.model == "maps/e1m7.bsp")
  231. {
  232. if (!cvar("registered"))
  233. {
  234. intermissiontext = "$qc_finale_e1_shareware";
  235. }
  236. else
  237. {
  238. intermissiontext = "$qc_finale_e1";
  239. }
  240. }
  241. else if (world.model == "maps/e2m6.bsp")
  242. {
  243. intermissiontext = "$qc_finale_e2";
  244. }
  245. else if (world.model == "maps/e3m6.bsp")
  246. {
  247. intermissiontext = "$qc_finale_e3";
  248. }
  249. else if (world.model == "maps/e4m7.bsp")
  250. {
  251. intermissiontext = "$qc_finale_e4";
  252. }
  253. else if (world.endtext)
  254. {
  255. intermissiontext = world.endtext;
  256. }
  257. if (intermissiontext)
  258. {
  259. WriteByte (MSG_ALL, SVC_CDTRACK);
  260. WriteByte (MSG_ALL, 2);
  261. WriteByte (MSG_ALL, 3);
  262. WriteByte (MSG_ALL, SVC_FINALE);
  263. WriteString (MSG_ALL, intermissiontext);
  264. intermissiontext = string_null;
  265. return;
  266. }
  267. if ( nextmap == "start" && !coop && !cvar("horde")) // Yoder modify Oct25 to check against horde
  268. {
  269. localcmd("menu_credits\n");
  270. localcmd("disconnect\n");
  271. }
  272. else
  273. {
  274. GotoNextMap();
  275. }
  276. }
  277. if (intermission_running == 3)
  278. {
  279. if (!cvar("registered"))
  280. { // shareware episode has been completed, go to sell screen
  281. WriteByte (MSG_ALL, SVC_SELLSCREEN);
  282. return;
  283. }
  284. if ( (serverflags & SIGIL_ALL) == SIGIL_ALL)
  285. {
  286. WriteByte (MSG_ALL, SVC_FINALE);
  287. WriteString (MSG_ALL, "$qc_mg1_endtext_all_runes");
  288. return;
  289. }
  290. }
  291. if ( nextmap == "start" && !coop && !cvar("horde")) // Yoder modify Oct25 to check against horde
  292. {
  293. localcmd("menu_credits\n");
  294. localcmd("disconnect\n");
  295. }
  296. else
  297. {
  298. GotoNextMap();
  299. }
  300. };
  301. /*
  302. ============
  303. IntermissionThink
  304. When the player presses attack or jump, change to the next level
  305. ============
  306. */
  307. void() IntermissionThink =
  308. {
  309. if (time < intermission_exittime)
  310. return;
  311. if (!self.button0 && !self.button1 && !self.button2)
  312. return;
  313. ExitIntermission ();
  314. };
  315. void() execute_changelevel =
  316. {
  317. local entity pos;
  318. intermission_running = 1;
  319. // enforce a wait time before allowing changelevel
  320. if (deathmatch)
  321. intermission_exittime = time + 5;
  322. else
  323. intermission_exittime = time + 2;
  324. WriteByte (MSG_ALL, SVC_CDTRACK);
  325. WriteByte (MSG_ALL, 3);
  326. WriteByte (MSG_ALL, 3);
  327. pos = FindIntermission ();
  328. other = find (world, classname, "player");
  329. while (other != world)
  330. {
  331. other.view_ofs = '0 0 0';
  332. other.angles = other.v_angle = pos.mangle;
  333. other.fixangle = TRUE; // turn this way immediately
  334. other.nextthink = time + 0.5;
  335. other.takedamage = DAMAGE_NO;
  336. other.solid = SOLID_NOT;
  337. other.movetype = MOVETYPE_NONE;
  338. other.modelindex = 0;
  339. intermission_clear_powerups(other);
  340. setorigin (other, pos.origin);
  341. FogPushSettingsFrom(other, pos, 0);
  342. other = find (other, classname, "player");
  343. }
  344. WriteByte (MSG_ALL, SVC_INTERMISSION);
  345. if (campaign && world.model == "maps/e5end.bsp")
  346. {
  347. WriteByte (MSG_ALL, SVC_ACHIEVEMENT);
  348. WriteString(MSG_ALL, "ACH_COMPLETE_E5END");
  349. if (skill == 3)
  350. {
  351. WriteByte (MSG_ALL, SVC_ACHIEVEMENT);
  352. WriteString(MSG_ALL, "ACH_COMPLETE_E5END_NIGHTMARE");
  353. }
  354. }
  355. else if (campaign && world.model == "maps/mgend.bsp")
  356. {
  357. WriteByte (MSG_ALL, SVC_ACHIEVEMENT);
  358. WriteString(MSG_ALL, "ACH_COMPLETE_MGEND");
  359. if (skill == 3)
  360. {
  361. WriteByte (MSG_ALL, SVC_ACHIEVEMENT);
  362. WriteString(MSG_ALL, "ACH_COMPLETE_MGEND_NIGHTMARE");
  363. }
  364. }
  365. if (world.model == "maps/e5m6.bsp" && nextmap == "e5sm2")
  366. {
  367. WriteByte (MSG_ALL, SVC_ACHIEVEMENT);
  368. WriteString(MSG_ALL, "ACH_FIND_E5M8");
  369. }
  370. if (world.model == "maps/mge1m1.bsp" && nextmap == "mge1m3")
  371. {
  372. WriteByte (MSG_ALL, SVC_ACHIEVEMENT);
  373. WriteString(MSG_ALL, "ACH_FIND_MGE1M3");
  374. }
  375. // Yoder merge Horde sept24 2021
  376. if (horde_ent)
  377. {
  378. horde_ent.think = SUB_Null;
  379. horde_ent.nextthink = -1;
  380. other = find (world, category, CATEGORY_MONSTER);
  381. while (other != world)
  382. {
  383. //void(entity targ, entity inflictor, entity attacker, float damage)
  384. //T_Damage(other, world, world, 4000);
  385. other.think = GibMonster;
  386. other.nextthink = time + 0.2 + random() * 1.8;
  387. other = find(other, category, CATEGORY_MONSTER);
  388. }
  389. }
  390. if(self.spawnflags & NO_INTERMISSION)
  391. {
  392. //Go directly to intermission text.
  393. ExitIntermission();
  394. }
  395. };
  396. void() changelevel_touch =
  397. {
  398. if (other.classname != "player")
  399. return;
  400. if ((cvar("noexit") == 1) || ((cvar("noexit") == 2) && (mapname != "start")))
  401. {
  402. T_Damage (other, self, self, 50000);
  403. return;
  404. }
  405. if (coop || deathmatch)
  406. {
  407. bprint("$qc_exited", other.netname);
  408. }
  409. nextmap = self.map;
  410. intermissiontext = self.endtext;
  411. if(world.model == "maps/mgend.bsp")
  412. {
  413. //Finished the whole pack, clear the runes.
  414. serverflags = 0;
  415. }
  416. SUB_UseTargets ();
  417. if ( (self.spawnflags & NO_INTERMISSION) && (deathmatch == 0) && (self.endtext == string_null))
  418. {
  419. GotoNextMap();
  420. return;
  421. }
  422. self.touch = SUB_Null;
  423. // we can't move people right now, because touch functions are called
  424. // in the middle of C movement code, so set a think time to do it
  425. self.think = execute_changelevel;
  426. self.nextthink = time + 0.1;
  427. };
  428. /*QUAKED trigger_changelevel (0.5 0.5 0.5) ? NO_INTERMISSION
  429. 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.
  430. */
  431. void() trigger_changelevel =
  432. {
  433. if (!self.map)
  434. objerror ("changelevel trigger doesn't have map");
  435. InitTrigger ();
  436. self.touch = changelevel_touch;
  437. };
  438. /*
  439. =============================================================================
  440. PLAYER GAME EDGE FUNCTIONS
  441. =============================================================================
  442. */
  443. void LoadGame()
  444. {
  445. dprint("\n\nLoadGame: self.classname = ");
  446. dprint(self.classname);
  447. dprint("\n\n");
  448. //For each player...
  449. entity cl = find(world, classname, "player");
  450. while(cl)
  451. {
  452. if(cl.fog_density)
  453. {
  454. //Restore fog
  455. SetFog(cl, cl.fog_density, cl.fog_color, 0.0);
  456. }
  457. cl = find(cl, classname, "player");
  458. }
  459. }
  460. void() set_suicide_frame;
  461. // called by ClientKill and DeadThink
  462. void() respawn =
  463. {
  464. self.velocity = '0 0 0';
  465. if (coop)
  466. {
  467. // make a copy of the dead body for appearances sake
  468. CopyToBodyQue (self);
  469. // get the spawn parms as they were at level start
  470. setspawnparms (self);
  471. // respawn
  472. PutClientInServer ();
  473. }
  474. else if (deathmatch)
  475. {
  476. // make a copy of the dead body for appearances sake
  477. CopyToBodyQue (self);
  478. // set default spawn parms
  479. SetNewParms ();
  480. // respawn
  481. PutClientInServer ();
  482. }
  483. else
  484. { // restart the entire server
  485. // put serverflags back to map's initial setting
  486. serverflags = startingserverflags;
  487. // request a reset to the parms
  488. reset_flag = TRUE;
  489. // "change" to the same level
  490. localcmd ("changelevel ");
  491. localcmd(mapname);
  492. localcmd("\n");
  493. }
  494. };
  495. // Yoder, Sept24, 2021
  496. // when in horde coop, respawn a dead teammate with this:
  497. void() horde_respawn_teammate =
  498. {
  499. CopyToBodyQue (self);
  500. //setspawnparms (self);
  501. //SetNewParms();
  502. PutClientInServer ();
  503. };
  504. // Yoder, Sept24, 2021
  505. // when in horde (coop or solo), respawn all by restarting the server:
  506. void() horde_respawn_all =
  507. {
  508. // restart the entire server
  509. // put serverflags back to map's initial setting
  510. serverflags = startingserverflags;
  511. // request a reset to the parms
  512. reset_flag = TRUE;
  513. // "change" to the same level
  514. localcmd ("changelevel ");
  515. localcmd(mapname);
  516. localcmd("\n");
  517. };
  518. void PlayerDie();
  519. /*
  520. ============
  521. ClientKill
  522. Player entered the suicide command
  523. ============
  524. */
  525. void() ClientKill =
  526. {
  527. bprint("$qc_suicides", self.netname);
  528. if (cvar("horde")) // horde mode behavior
  529. {
  530. PlayerDie();
  531. self.health = 0;
  532. }
  533. else // standard behavior
  534. {
  535. set_suicide_frame ();
  536. self.modelindex = modelindex_player;
  537. self.frags = self.frags - 2; // extra penalty
  538. respawn ();
  539. }
  540. };
  541. float(vector v) CheckSpawnPoint =
  542. {
  543. return FALSE;
  544. };
  545. /*
  546. ============
  547. PlayerVisibleToSpawnPoint
  548. Returns true if player can see this point
  549. ============
  550. */
  551. float PlayerVisibleToSpawnPoint( entity point ) {
  552. local vector spot1, spot2;
  553. local entity player = find( world, classname, "player" );
  554. while ( player ) {
  555. if ( player.health > 0 ) {
  556. spot1 = point.origin + player.view_ofs;
  557. spot2 = player.origin + player.view_ofs;
  558. traceline( spot1, spot2, TRUE, point );
  559. if ( trace_fraction >= 1.0f ) {
  560. return TRUE;
  561. }
  562. }
  563. player = find( player, classname, "player" );
  564. }
  565. return FALSE;
  566. }
  567. float IDEAL_DIST_FROM_DM_SPAWN_POINT = 384;
  568. float MIN_DIST_FROM_DM_SPAWN_POINT = 84;
  569. float MIN_DIST_FROM_HORDE_SPAWN_POINT = 72;
  570. float predicate_is_active_spawnpoint(entity e)
  571. {
  572. return (e.state == COOP_SPAWN_ACTIVE);
  573. }
  574. /*
  575. ============
  576. SelectSpawnPoint
  577. Returns the entity to spawn at
  578. ============
  579. */
  580. entity SelectSpawnPoint(float forceSpawn) {
  581. local entity spot, thing;
  582. local float numspots, totalspots;
  583. local float pcount;
  584. local entity spots;
  585. local entity hordeSpawn;
  586. numspots = 0;
  587. totalspots = 0;
  588. // testinfo_player_start is only found in regioned levels
  589. spot = find( world, classname, "testplayerstart" );
  590. if ( spot )
  591. return spot;
  592. if ( cvar( "horde" ) ) { // run simpler logic for horde - just need a spot with noone on top of it...
  593. hordeSpawn = find( world, classname, "info_player_coop" );
  594. while( hordeSpawn ) {
  595. thing = findradius( hordeSpawn.origin, MIN_DIST_FROM_HORDE_SPAWN_POINT );
  596. pcount = 0;
  597. while( thing ) {
  598. if ( thing.classname == "player" && thing.health > 0 ) {
  599. pcount++;
  600. }
  601. thing = thing.chain;
  602. }
  603. if ( pcount == 0 ) {
  604. return hordeSpawn;
  605. }
  606. // Get the next spot in the chain
  607. hordeSpawn = find( hordeSpawn, classname, "info_player_coop" );
  608. }
  609. if (coop) // fix for singleplayer
  610. return world; // didn't find anything....
  611. } else if ( coop ) {
  612. // choose a info_player_coop point that is active
  613. entity startedAt = lastspawn;
  614. lastspawn = find( lastspawn, classname, "info_player_coop" );
  615. while( lastspawn.state != COOP_SPAWN_ACTIVE ) {
  616. if ( lastspawn == startedAt ) {
  617. break;
  618. }
  619. lastspawn = find(lastspawn, classname, "info_player_coop");
  620. }
  621. if ( lastspawn != world ) {
  622. return lastspawn;
  623. }
  624. } else if ( deathmatch ) {
  625. // find all spots that don't have visible players nearby
  626. spots = world;
  627. spot = find( world, classname, "info_player_deathmatch" );
  628. while( spot ) {
  629. totalspots = totalspots + 1;
  630. thing = findradius( spot.origin, IDEAL_DIST_FROM_DM_SPAWN_POINT );
  631. pcount = 0;
  632. while( thing ) {
  633. if ( thing.classname == "player" && thing.health > 0 ) {
  634. pcount = pcount + 1;
  635. }
  636. thing = thing.chain;
  637. }
  638. if ( pcount == 0 ) {
  639. if ( PlayerVisibleToSpawnPoint( spot ) ) {
  640. pcount = pcount + 1;
  641. }
  642. }
  643. if ( pcount == 0 ) { // good spot!
  644. spot.goalentity = spots;
  645. spots = spot;
  646. numspots = numspots + 1;
  647. }
  648. // Get the next spot in the chain
  649. spot = find( spot, classname, "info_player_deathmatch" );
  650. }
  651. totalspots = totalspots - 1;
  652. // on small maps with few spawn points, our "ideal" spawn conditions may not be possible to meet
  653. // so fallback to just trying to pick a point without a player on top of it, so we don't start
  654. // a spawn frag loop
  655. if ( numspots == 0 ) {
  656. spot = find( world, classname, "info_player_deathmatch" );
  657. while( spot ) {
  658. thing = findradius( spot.origin, MIN_DIST_FROM_DM_SPAWN_POINT );
  659. pcount = 0;
  660. while( thing ) {
  661. if ( thing.classname == "player" && thing.health > 0 ) {
  662. pcount = pcount + 1;
  663. }
  664. thing = thing.chain;
  665. }
  666. if ( pcount == 0 ) { // good spot!
  667. spot.goalentity = spots;
  668. spots = spot;
  669. numspots = numspots + 1;
  670. }
  671. // Get the next spot in the chain
  672. spot = find( spot, classname, "info_player_deathmatch" );
  673. }
  674. }
  675. // uncomment to force a deferred spawn
  676. // if (forceSpawn == FALSE) return world;
  677. if ( !numspots ) {
  678. if (forceSpawn == FALSE) {
  679. return world;
  680. }
  681. // no spots available so just pick one at random
  682. totalspots = rint( ( random() * totalspots ) );
  683. spot = find( world, classname, "info_player_deathmatch" );
  684. while( totalspots > 0 ) {
  685. totalspots = totalspots - 1;
  686. spot = find( spot, classname, "info_player_deathmatch" );
  687. }
  688. return spot;
  689. }
  690. // Generate a random number between 1 and numspots
  691. numspots = numspots - 1;
  692. numspots = rint( ( random() * numspots ) );
  693. spot = spots;
  694. while( numspots > 0 ) {
  695. spot = spot.goalentity;
  696. numspots = numspots - 1;
  697. }
  698. return spot;
  699. }
  700. if (serverflags)
  701. { // return with a rune to start
  702. float lastPickup = sigil_getLastPickup();
  703. if(lastPickup)
  704. {
  705. string spname = string_null;
  706. if(lastPickup & SIGIL_E1) spname = "start_1";
  707. else if(lastPickup & SIGIL_E2) spname = "start_2";
  708. else if(lastPickup & SIGIL_E3) spname = "start_3";
  709. else if(lastPickup & SIGIL_E4) spname = "start_4";
  710. else if(lastPickup & SIGIL_E5) spname = "start_5";
  711. else if(lastPickup & SIGIL_E6) spname = "start_6";
  712. if(spname)
  713. {
  714. spot = find (world, netname, spname);
  715. if(spot)
  716. {
  717. if(spot.classname == "info_player_start_hub")
  718. {
  719. sigil_clearLastPickup();
  720. return spot;
  721. }
  722. }
  723. }
  724. }
  725. spot = find (world, classname, "info_player_start2");
  726. if (spot)
  727. return spot;
  728. }
  729. spot = find (world, classname, "info_player_start");
  730. if (!spot)
  731. error ("PutClientInServer: no info_player_start on level");
  732. return spot;
  733. };
  734. /*
  735. ===========
  736. PutClientInServer
  737. called each time a player is spawned
  738. ============
  739. */
  740. void() DecodeLevelParms;
  741. void() PlayerDie;
  742. void RunPostPutClientInServer()
  743. {
  744. entity oself = self;
  745. self = self.owner;
  746. entity spot = oself.enemy;
  747. // Yoder Sept24, 2021
  748. horde_set_keys(self); // reset player's key count accordingly
  749. // Fog settings sometimes (?) need to be set a frame after the client has spawned.
  750. // Not sure why, or why it sometimes works on the same frame.
  751. if(!FogPushSettingsFrom(self, spot, 0))
  752. {
  753. FogPushSettingsFrom(self, world, 0);
  754. }
  755. remove(oself);
  756. }
  757. void() PutClientInServer =
  758. {
  759. local entity spot;
  760. self.classname = "player";
  761. if (skill == 3 && !deathmatch)
  762. self.health = 50;
  763. else
  764. self.health = 100;
  765. self.takedamage = DAMAGE_AIM;
  766. self.solid = SOLID_SLIDEBOX;
  767. self.movetype = MOVETYPE_WALK;
  768. self.show_hostile = 0;
  769. if (skill == 3 && !deathmatch)
  770. self.max_health = 50;
  771. else
  772. self.max_health = 100;
  773. self.flags = FL_CLIENT;
  774. self.air_finished = time + 12;
  775. self.dmg = 2; // initial water damage
  776. self.super_damage_finished = 0;
  777. self.radsuit_finished = 0;
  778. self.invisible_finished = 0;
  779. self.invincible_finished = 0;
  780. self.effects = 0;
  781. self.invincible_time = 0;
  782. if ( coop ) {
  783. self.team = TEAM_HUMANS;
  784. }
  785. DecodeLevelParms ();
  786. W_SetCurrentAmmo ();
  787. self.attack_finished = time;
  788. self.th_pain = player_pain;
  789. self.th_die = PlayerDie;
  790. self.deadflag = DEAD_NO;
  791. // paustime is set by teleporters to keep the player from moving a while
  792. self.pausetime = 0;
  793. local float shouldTelefrag;
  794. if (self.spawn_deferred > 0 && time >= self.spawn_deferred) {
  795. dprint("forcing telefrag on this spawn\n");
  796. shouldTelefrag = TRUE;
  797. } else {
  798. shouldTelefrag = FALSE;
  799. }
  800. spot = SelectSpawnPoint(shouldTelefrag);
  801. if (spot == world) {
  802. self.takedamage = DAMAGE_NO;
  803. self.solid = SOLID_NOT;
  804. self.movetype = MOVETYPE_NONE;
  805. self.deadflag = DEAD_DEAD;
  806. setmodel(self, "");
  807. self.view_ofs = '0 0 1'; // not 0 because PlayerPreThink would return out
  808. self.velocity = '0 0 0';
  809. if (self.spawn_deferred == 0) {
  810. dprint("no spawns available! deferring\n");
  811. self.spawn_deferred = time + 5;
  812. }
  813. spot = FindIntermission();
  814. self.angles = self.v_angle = spot.mangle;
  815. self.fixangle = TRUE;
  816. self.origin = spot.origin;
  817. self.weaponmodel = "";
  818. self.weaponframe = 0;
  819. self.weapon = 0;
  820. return;
  821. }
  822. self.spawn_deferred = 0;
  823. self.origin = spot.origin + '0 0 1';
  824. self.angles = spot.angles;
  825. self.fixangle = TRUE; // turn this way immediately
  826. #ifdef COOP_RESPAWN_KEEP_WEAPONS
  827. if(coop)
  828. {
  829. // In coop we want to give back the players the weapons they progressed with
  830. self.items |= (spot.items & IT_ALL_WEAPONS);
  831. if(self.items & (IT_NAILGUN | IT_SUPER_NAILGUN)) self.ammo_nails = 30;
  832. if(self.items & (IT_GRENADE_LAUNCHER | IT_ROCKET_LAUNCHER)) self.ammo_rockets = 4;
  833. if(self.items & IT_LIGHTNING) self.ammo_cells = 12;
  834. }
  835. #endif
  836. // oh, this is a hack!
  837. setmodel (self, "progs/eyes.mdl");
  838. modelindex_eyes = self.modelindex;
  839. setmodel (self, "progs/player.mdl");
  840. modelindex_player = self.modelindex;
  841. setsize (self, VEC_HULL_MIN, VEC_HULL_MAX);
  842. self.view_ofs = '0 0 22';
  843. player_stand1 ();
  844. if (deathmatch || coop)
  845. {
  846. makevectors(self.angles);
  847. spawn_tfog (self.origin + v_forward*20);
  848. }
  849. spawn_tdeath (self.origin, self);
  850. entity postSpawn = spawn();
  851. postSpawn.owner = self;
  852. postSpawn.enemy = spot;
  853. postSpawn.think = RunPostPutClientInServer;
  854. postSpawn.nextthink = time + 0.05;
  855. stuffcmd(self, "-attack\n"); // prevent shooting after respawning
  856. };
  857. /*
  858. =============================================================================
  859. QUAKED FUNCTIONS
  860. =============================================================================
  861. */
  862. /*QUAKED info_player_start (1 0 0) (-16 -16 -24) (16 16 24)
  863. The normal starting point for a level.
  864. */
  865. void() info_player_start =
  866. {
  867. self.netname = "info_player_start"; // for bot nav support.
  868. };
  869. /*QUAKED info_player_start2 (1 0 0) (-16 -16 -24) (16 16 24)
  870. Only used on start map for the return point from an episode.
  871. */
  872. void() info_player_start2 =
  873. {
  874. self.netname = "info_player_start2"; // for bot nav support.
  875. };
  876. /*QUAKED info_player_start_hub (1 0 0) (-16 -16 -24) (16 16 24)
  877. Only used on start map for the return point from an episode.
  878. */
  879. void() info_player_start_hub =
  880. {
  881. };
  882. /*QUAKED info_player_deathmatch (1 0 1) (-16 -16 -24) (16 16 24)
  883. potential spawning position for deathmatch games
  884. */
  885. void() info_player_deathmatch =
  886. {
  887. if(!deathmatch)
  888. {
  889. remove(self);
  890. return;
  891. }
  892. self.netname = "info_player_deathmatch"; // for bot nav support.
  893. };
  894. //////////////////////////////////////////////////////////////////////////
  895. void trigger_activate_coop_spawns_use()
  896. {
  897. float it = 0;
  898. #ifdef COOP_RESPAWN_KEEP_WEAPONS
  899. entity p = find (world, classname, "player");
  900. while (p != world)
  901. {
  902. it |= p.items;
  903. p = find (p, classname, "player");
  904. }
  905. it &= IT_ALL_WEAPONS;
  906. dprint("Activating coop spawn \"");
  907. dprint(self.target);
  908. dprint("\": Collected ");
  909. dprint(ftos(it));
  910. dprint(" from players.\n");
  911. #endif
  912. entity s = find(world, classname, "info_player_coop");
  913. while(s)
  914. {
  915. if(s.targetname == self.target)
  916. {
  917. s.state = COOP_SPAWN_ACTIVE;
  918. s.items = it;
  919. }
  920. else
  921. {
  922. s.state = 0;
  923. s.items = 0;
  924. }
  925. s = find(s, classname, "info_player_coop");
  926. }
  927. }
  928. /*QUAKED trigger_activate_coop_spawns (1 0 1) (-8 -8 -8) (8 8 8)
  929. Activates a set of coop spawnpoints.
  930. */
  931. void trigger_activate_coop_spawns()
  932. {
  933. if(!coop)
  934. {
  935. remove(self);
  936. return;
  937. }
  938. self.use = trigger_activate_coop_spawns_use;
  939. }
  940. const float COOP_SPAWN_START_ACTIVE = 1;
  941. /*QUAKED info_player_coop (1 0 1) (-16 -16 -24) (16 16 24)
  942. potential spawning position for coop games
  943. */
  944. void() info_player_coop =
  945. {
  946. if(!coop)
  947. {
  948. remove(self);
  949. return;
  950. }
  951. self.netname = "info_player_coop"; // for bot nav support.
  952. if(!self.targetname) self.state = COOP_SPAWN_ACTIVE;
  953. if(self.spawnflags & COOP_SPAWN_START_ACTIVE) self.state = COOP_SPAWN_ACTIVE;
  954. };
  955. /*
  956. ===============================================================================
  957. RULES
  958. ===============================================================================
  959. */
  960. /*
  961. go to the next level for deathmatch
  962. only called if a time or frag limit has expired
  963. */
  964. void() NextLevel =
  965. {
  966. local entity o;
  967. if (mapname == "start")
  968. {
  969. if (!cvar("registered"))
  970. {
  971. mapname = "e1m1";
  972. }
  973. else if (!(serverflags & 1))
  974. {
  975. mapname = "e1m1";
  976. serverflags = serverflags | 1;
  977. }
  978. else if (!(serverflags & 2))
  979. {
  980. mapname = "e2m1";
  981. serverflags = serverflags | 2;
  982. }
  983. else if (!(serverflags & 4))
  984. {
  985. mapname = "e3m1";
  986. serverflags = serverflags | 4;
  987. }
  988. else if (!(serverflags & 8))
  989. {
  990. mapname = "e4m1";
  991. serverflags = serverflags - 7;
  992. }
  993. o = spawn();
  994. o.map = mapname;
  995. }
  996. else if (world.model == "maps/mgdm1.bsp")
  997. {
  998. o = spawn();
  999. o.map = "mgdm2";
  1000. }
  1001. else if (world.model == "maps/mgdm2.bsp")
  1002. {
  1003. o = spawn();
  1004. o.map = "mgdm3";
  1005. }
  1006. else if (world.model == "maps/mgdm3.bsp")
  1007. {
  1008. o = spawn();
  1009. o.map = "mgdm4";
  1010. }
  1011. else if (world.model == "maps/mgdm4.bsp")
  1012. {
  1013. o = spawn();
  1014. o.map = "mgdm1";
  1015. }
  1016. else
  1017. {
  1018. // find a trigger changelevel
  1019. o = find(world, classname, "trigger_changelevel");
  1020. // Stay on same level if no changelevel is found
  1021. if (!o)
  1022. {
  1023. o = spawn();
  1024. o.map = mapname;
  1025. }
  1026. }
  1027. nextmap = o.map;
  1028. gameover = TRUE;
  1029. if (o.nextthink < time)
  1030. {
  1031. o.think = execute_changelevel;
  1032. o.nextthink = time + 0.1;
  1033. }
  1034. };
  1035. /*
  1036. ============
  1037. CheckRules
  1038. Exit deathmatch games upon conditions
  1039. ============
  1040. */
  1041. void() CheckRules =
  1042. {
  1043. local float timelimit;
  1044. local float fraglimit;
  1045. if (gameover) // someone else quit the game already
  1046. return;
  1047. timelimit = cvar("timelimit") * 60;
  1048. fraglimit = cvar("fraglimit");
  1049. if (timelimit && time >= timelimit)
  1050. {
  1051. NextLevel ();
  1052. return;
  1053. }
  1054. if (fraglimit && self.frags >= fraglimit)
  1055. {
  1056. NextLevel ();
  1057. return;
  1058. }
  1059. };
  1060. //============================================================================
  1061. void() PlayerDeathThink =
  1062. {
  1063. local float forward;
  1064. if ((self.flags & FL_ONGROUND))
  1065. {
  1066. forward = vlen (self.velocity);
  1067. forward = forward - 20;
  1068. if (forward <= 0)
  1069. self.velocity = '0 0 0';
  1070. else
  1071. self.velocity = forward * normalize(self.velocity);
  1072. }
  1073. if (self.spawn_deferred)
  1074. {
  1075. local entity spot;
  1076. spot = SelectSpawnPoint(FALSE);
  1077. //dprint("time {} >= self.spawn_deferred {}\n", ftos(time), ftos(self.spawn_deferred));
  1078. if (spot != world || time >= self.spawn_deferred) {
  1079. respawn();
  1080. }
  1081. return;
  1082. }
  1083. // wait for all buttons released
  1084. if (self.deadflag == DEAD_DEAD)
  1085. {
  1086. if (self.button2 || self.button1 || self.button0)
  1087. return;
  1088. self.deadflag = DEAD_RESPAWNABLE;
  1089. return;
  1090. }
  1091. // wait for any button down
  1092. if (!self.button2 && !self.button1 && !self.button0)
  1093. return;
  1094. self.button0 = 0;
  1095. self.button1 = 0;
  1096. self.button2 = 0;
  1097. // Yoder Sept24, 2021
  1098. if (horde_ent)
  1099. {
  1100. if ((coop && HordeGetPlayersAlive() <= 0) || (!coop))
  1101. {
  1102. horde_respawn_all();
  1103. }
  1104. return;
  1105. }
  1106. respawn();
  1107. };
  1108. void() PlayerJump =
  1109. {
  1110. if (self.flags & FL_WATERJUMP)
  1111. return;
  1112. if (self.waterlevel >= 2)
  1113. {
  1114. if (self.watertype == CONTENT_WATER)
  1115. self.velocity_z = 100;
  1116. else if (self.watertype == CONTENT_SLIME)
  1117. self.velocity_z = 80;
  1118. else
  1119. self.velocity_z = 50;
  1120. // play swiming sound
  1121. if (self.swim_flag < time)
  1122. {
  1123. self.swim_flag = time + 1;
  1124. if (random() < 0.5)
  1125. sound (self, CHAN_BODY, "misc/water1.wav", 1, ATTN_NORM);
  1126. else
  1127. sound (self, CHAN_BODY, "misc/water2.wav", 1, ATTN_NORM);
  1128. }
  1129. return;
  1130. }
  1131. if (!(self.flags & FL_ONGROUND))
  1132. return;
  1133. if ( !(self.flags & FL_JUMPRELEASED) )
  1134. return; // don't pogo stick
  1135. self.flags = self.flags - (self.flags & FL_JUMPRELEASED);
  1136. self.flags = self.flags - FL_ONGROUND; // don't stairwalk
  1137. self.button2 = 0;
  1138. // player jumping sound
  1139. sound (self, CHAN_BODY, "player/plyrjmp8.wav", 1, ATTN_NORM);
  1140. self.velocity_z = self.velocity_z + 270;
  1141. };
  1142. /*
  1143. ===========
  1144. WaterMove
  1145. ============
  1146. */
  1147. .float dmgtime;
  1148. void() WaterMove =
  1149. {
  1150. //dprint (ftos(self.waterlevel));
  1151. if (self.movetype == MOVETYPE_NOCLIP)
  1152. return;
  1153. if (self.health < 0)
  1154. return;
  1155. if (self.waterlevel != 3)
  1156. {
  1157. if (self.air_finished < time)
  1158. sound (self, CHAN_VOICE, "player/gasp2.wav", 1, ATTN_NORM);
  1159. else if (self.air_finished < time + 9)
  1160. sound (self, CHAN_VOICE, "player/gasp1.wav", 1, ATTN_NORM);
  1161. self.air_finished = time + 12;
  1162. self.dmg = 2;
  1163. }
  1164. else if (self.air_finished < time)
  1165. { // drown!
  1166. if (self.pain_finished < time)
  1167. {
  1168. self.dmg = self.dmg + 2;
  1169. if (self.dmg > 15)
  1170. self.dmg = 10;
  1171. T_Damage (self, world, world, self.dmg);
  1172. self.pain_finished = time + 1;
  1173. }
  1174. }
  1175. if (!self.waterlevel)
  1176. {
  1177. if (self.flags & FL_INWATER)
  1178. {
  1179. // play leave water sound
  1180. sound (self, CHAN_BODY, "misc/outwater.wav", 1, ATTN_NORM);
  1181. self.flags = self.flags - FL_INWATER;
  1182. }
  1183. return;
  1184. }
  1185. if (self.watertype == CONTENT_LAVA)
  1186. { // do damage
  1187. if (self.dmgtime < time)
  1188. {
  1189. if (self.radsuit_finished > time)
  1190. self.dmgtime = time + 1;
  1191. else
  1192. self.dmgtime = time + 0.2;
  1193. T_Damage (self, world, world, 10*self.waterlevel);
  1194. }
  1195. }
  1196. else if (self.watertype == CONTENT_SLIME)
  1197. { // do damage
  1198. if (self.dmgtime < time && self.radsuit_finished < time)
  1199. {
  1200. self.dmgtime = time + 1;
  1201. T_Damage (self, world, world, 4*self.waterlevel);
  1202. }
  1203. }
  1204. if ( !(self.flags & FL_INWATER) )
  1205. {
  1206. // player enter water sound
  1207. if (self.watertype == CONTENT_LAVA)
  1208. sound (self, CHAN_BODY, "player/inlava.wav", 1, ATTN_NORM);
  1209. if (self.watertype == CONTENT_WATER)
  1210. sound (self, CHAN_BODY, "player/inh2o.wav", 1, ATTN_NORM);
  1211. if (self.watertype == CONTENT_SLIME)
  1212. sound (self, CHAN_BODY, "player/slimbrn2.wav", 1, ATTN_NORM);
  1213. self.flags = self.flags + FL_INWATER;
  1214. self.dmgtime = 0;
  1215. }
  1216. if (! (self.flags & FL_WATERJUMP) )
  1217. self.velocity = self.velocity - 0.8*self.waterlevel*frametime*self.velocity;
  1218. };
  1219. void() CheckWaterJump =
  1220. {
  1221. local vector start, end;
  1222. // check for a jump-out-of-water
  1223. makevectors (self.angles);
  1224. start = self.origin;
  1225. start_z = start_z + 8;
  1226. v_forward_z = 0;
  1227. normalize(v_forward);
  1228. end = start + v_forward*24;
  1229. traceline (start, end, TRUE, self);
  1230. if (trace_fraction < 1)
  1231. { // solid at waist
  1232. start_z = start_z + self.maxs_z - 8;
  1233. end = start + v_forward*24;
  1234. self.movedir = trace_plane_normal * -50;
  1235. traceline (start, end, TRUE, self);
  1236. if (trace_fraction == 1)
  1237. { // open at eye level
  1238. self.flags = self.flags | FL_WATERJUMP;
  1239. self.velocity_z = 225;
  1240. self.flags = self.flags - (self.flags & FL_JUMPRELEASED);
  1241. self.teleport_time = time + 2; // safety net
  1242. return;
  1243. }
  1244. }
  1245. };
  1246. /*
  1247. ================
  1248. PlayerPreThink
  1249. Called every frame before physics are run
  1250. ================
  1251. */
  1252. void() PlayerPreThink =
  1253. {
  1254. if (intermission_running)
  1255. {
  1256. IntermissionThink (); // otherwise a button could be missed between
  1257. return; // the think tics
  1258. }
  1259. if (self.view_ofs == '0 0 0')
  1260. return; // intermission or finale
  1261. makevectors (self.v_angle); // is this still used
  1262. CheckRules ();
  1263. WaterMove ();
  1264. if (self.waterlevel == 2)
  1265. CheckWaterJump ();
  1266. if (self.deadflag >= DEAD_DEAD)
  1267. {
  1268. PlayerDeathThink ();
  1269. return;
  1270. }
  1271. if (self.deadflag == DEAD_DYING)
  1272. return; // dying, so do nothing
  1273. if (self.button2)
  1274. {
  1275. PlayerJump ();
  1276. }
  1277. else
  1278. self.flags = self.flags | FL_JUMPRELEASED;
  1279. // teleporters can force a non-moving pause time
  1280. if (time < self.pausetime)
  1281. self.velocity = '0 0 0';
  1282. if(time > self.attack_finished && self.currentammo == 0 && self.weapon != IT_AXE)
  1283. {
  1284. self.weapon = W_BestWeapon ();
  1285. W_SetCurrentAmmo ();
  1286. }
  1287. };
  1288. /*
  1289. ================
  1290. CheckPowerups
  1291. Check for turning off powerups
  1292. ================
  1293. */
  1294. void() CheckPowerups =
  1295. {
  1296. if (self.health <= 0)
  1297. return;
  1298. // invisibility
  1299. if (self.invisible_finished)
  1300. {
  1301. // sound and screen flash when items starts to run out
  1302. if (self.invisible_sound < time)
  1303. {
  1304. sound (self, CHAN_AUTO, "items/inv3.wav", 0.5, ATTN_IDLE);
  1305. self.invisible_sound = time + ((random() * 3) + 1);
  1306. }
  1307. if (self.invisible_finished < time + 3)
  1308. {
  1309. if (self.invisible_time == 1)
  1310. {
  1311. sprint(self, "$qc_ring_fade");
  1312. stuffcmd (self, "bf\n");
  1313. sound (self, CHAN_AUTO, "items/inv2.wav", 1, ATTN_NORM);
  1314. self.invisible_time = time + 1;
  1315. }
  1316. if (self.invisible_time < time)
  1317. {
  1318. self.invisible_time = time + 1;
  1319. stuffcmd (self, "bf\n");
  1320. }
  1321. }
  1322. if (self.invisible_finished < time)
  1323. { // just stopped
  1324. self.items = self.items - IT_INVISIBILITY;
  1325. self.invisible_finished = 0;
  1326. self.invisible_time = 0;
  1327. }
  1328. // use the eyes
  1329. self.frame = 0;
  1330. self.modelindex = modelindex_eyes;
  1331. }
  1332. else
  1333. self.modelindex = modelindex_player; // don't use eyes
  1334. // invincibility
  1335. if (self.invincible_finished)
  1336. {
  1337. // sound and screen flash when items starts to run out
  1338. if (self.invincible_finished < time + 3)
  1339. {
  1340. if (self.invincible_time == 1)
  1341. {
  1342. sprint (self, "$qc_protection_fade");
  1343. stuffcmd (self, "bf\n");
  1344. sound (self, CHAN_AUTO, "items/protect2.wav", 1, ATTN_NORM);
  1345. self.invincible_time = time + 1;
  1346. }
  1347. if (self.invincible_time < time)
  1348. {
  1349. self.invincible_time = time + 1;
  1350. stuffcmd (self, "bf\n");
  1351. }
  1352. }
  1353. if (self.invincible_finished < time)
  1354. { // just stopped
  1355. self.items = self.items - IT_INVULNERABILITY;
  1356. self.invincible_time = 0;
  1357. self.invincible_finished = 0;
  1358. }
  1359. if (self.invincible_finished > time)
  1360. self.effects = self.effects | EF_PENTLIGHT;
  1361. else
  1362. self.effects = self.effects - (self.effects & EF_PENTLIGHT);
  1363. }
  1364. // super damage
  1365. if (self.super_damage_finished)
  1366. {
  1367. // sound and screen flash when items starts to run out
  1368. if (self.super_damage_finished < time + 3)
  1369. {
  1370. if (self.super_time == 1)
  1371. {
  1372. sprint (self, "$qc_quad_fade");
  1373. stuffcmd (self, "bf\n");
  1374. sound (self, CHAN_AUTO, "items/damage2.wav", 1, ATTN_NORM);
  1375. self.super_time = time + 1;
  1376. }
  1377. if (self.super_time < time)
  1378. {
  1379. self.super_time = time + 1;
  1380. stuffcmd (self, "bf\n");
  1381. }
  1382. }
  1383. if (self.super_damage_finished < time)
  1384. { // just stopped
  1385. self.items = self.items - IT_QUAD;
  1386. self.super_damage_finished = 0;
  1387. self.super_time = 0;
  1388. }
  1389. if (self.super_damage_finished > time)
  1390. self.effects = self.effects | EF_QUADLIGHT;
  1391. else
  1392. self.effects = self.effects - (self.effects & EF_QUADLIGHT);
  1393. }
  1394. // suit
  1395. if (self.radsuit_finished)
  1396. {
  1397. self.air_finished = time + 12; // don't drown
  1398. // sound and screen flash when items starts to run out
  1399. if (self.radsuit_finished < time + 3)
  1400. {
  1401. if (self.rad_time == 1)
  1402. {
  1403. sprint (self, "$qc_biosuit_fade");
  1404. stuffcmd (self, "bf\n");
  1405. sound (self, CHAN_AUTO, "items/suit2.wav", 1, ATTN_NORM);
  1406. self.rad_time = time + 1;
  1407. }
  1408. if (self.rad_time < time)
  1409. {
  1410. self.rad_time = time + 1;
  1411. stuffcmd (self, "bf\n");
  1412. }
  1413. }
  1414. if (self.radsuit_finished < time)
  1415. { // just stopped
  1416. self.items = self.items - IT_SUIT;
  1417. self.rad_time = 0;
  1418. self.radsuit_finished = 0;
  1419. }
  1420. }
  1421. };
  1422. /*
  1423. ================
  1424. PlayerPostThink
  1425. Called every frame after physics are run
  1426. ================
  1427. */
  1428. void() PlayerPostThink =
  1429. {
  1430. if (self.view_ofs == '0 0 0')
  1431. return; // intermission or finale
  1432. if (self.deadflag)
  1433. return;
  1434. // do weapon stuff
  1435. W_WeaponFrame ();
  1436. // check to see if player landed and play landing sound
  1437. if ((self.jump_flag < -300) && (self.flags & FL_ONGROUND) && (self.health > 0))
  1438. {
  1439. if (self.watertype == CONTENT_WATER)
  1440. sound (self, CHAN_BODY, "player/h2ojump.wav", 1, ATTN_NORM);
  1441. else if (self.jump_flag < -650)
  1442. {
  1443. T_Damage (self, world, world, 5);
  1444. sound (self, CHAN_VOICE, "player/land2.wav", 1, ATTN_NORM);
  1445. self.deathtype = "falling";
  1446. }
  1447. else
  1448. sound (self, CHAN_VOICE, "player/land.wav", 1, ATTN_NORM);
  1449. self.jump_flag = 0;
  1450. }
  1451. if (!(self.flags & FL_ONGROUND))
  1452. self.jump_flag = self.velocity_z;
  1453. // AY 11 Nov 2021, check killspree end
  1454. local float score;
  1455. if ((self.killspree > 0) && (time > self.killtime))
  1456. {
  1457. dprint("killspree ended.\n");
  1458. //score = (self.killspree + (self.killspree - 1) -1) * 5; // previously was "attacker.killspree - 1"
  1459. if (self.killspree > 1)
  1460. {
  1461. score = ceil((self.killspree * self.killspree)/2);
  1462. sprint(self, "$qc_horde_streak_ended", ftos(score));
  1463. self.frags += score;
  1464. }
  1465. self.killspree = 0; // reset killspree
  1466. }
  1467. CheckPowerups ();
  1468. };
  1469. /*
  1470. ===========
  1471. ClientConnect
  1472. called when a player connects to a server
  1473. ============
  1474. */
  1475. void() ClientConnect =
  1476. {
  1477. bprint("$qc_entered", self.netname);
  1478. num_players++;
  1479. // a client connecting during an intermission can cause problems
  1480. if (intermission_running)
  1481. ExitIntermission ();
  1482. };
  1483. /*
  1484. ===========
  1485. ClientDisconnect
  1486. called when a player disconnects from a server
  1487. ============
  1488. */
  1489. void() ClientDisconnect =
  1490. {
  1491. // if the level end trigger has been activated, just return
  1492. // since they aren't *really* leaving
  1493. if (gameover)
  1494. {
  1495. return;
  1496. }
  1497. num_players--;
  1498. // yoder oct13, horde fix for dc-ing players
  1499. if(cvar("horde"))
  1500. {
  1501. dprint("horde mode, player disconnect\n");
  1502. self.health = 0;
  1503. }
  1504. // let everyone else know
  1505. bprint("$qc_left_game", self.netname, ftos(self.frags));
  1506. sound (self, CHAN_BODY, "player/tornoff2.wav", 1, ATTN_NONE);
  1507. set_suicide_frame ();
  1508. };
  1509. /*
  1510. ===========
  1511. ClientObituary
  1512. called when a player dies
  1513. ============
  1514. */
  1515. void(entity targ, entity attacker) ClientObituary =
  1516. {
  1517. local float rnum;
  1518. rnum = random();
  1519. if (targ.classname == "player")
  1520. {
  1521. if (attacker.classname == "teledeath")
  1522. {
  1523. bprint("$qc_telefragged", targ.netname, attacker.owner.netname);
  1524. attacker.owner.frags = attacker.owner.frags + 1;
  1525. return;
  1526. }
  1527. if (attacker.classname == "teledeath2")
  1528. {
  1529. bprint("$qc_satans_power", targ.netname);
  1530. targ.frags = targ.frags - 1;
  1531. return;
  1532. }
  1533. if (attacker.classname == "player")
  1534. {
  1535. if (targ == attacker)
  1536. {
  1537. // killed self
  1538. attacker.frags = attacker.frags - 1;
  1539. if (targ.weapon == 64 && targ.waterlevel > 1)
  1540. {
  1541. if (targ.watertype == CONTENT_SLIME)
  1542. bprint("$qc_discharge_slime", targ.netname);
  1543. else if (targ.watertype == CONTENT_LAVA)
  1544. bprint("$qc_discharge_lava", targ.netname);
  1545. else
  1546. bprint("$qc_discharge_water", targ.netname);
  1547. return;
  1548. }
  1549. if (targ.weapon == IT_GRENADE_LAUNCHER)
  1550. {
  1551. bprint("$qc_suicide_pin", targ.netname);
  1552. }
  1553. else
  1554. {
  1555. bprint("$qc_suicide_bored", targ.netname);
  1556. }
  1557. return;
  1558. }
  1559. else if ( (teamplay == 2) && (targ.team > 0)&&(targ.team == attacker.team) )
  1560. {
  1561. if (rnum < 0.25)
  1562. bprint("$qc_ff_teammate", attacker.netname);
  1563. else if (rnum < 0.50)
  1564. bprint("$qc_ff_glasses", attacker.netname);
  1565. else if (rnum < 0.75)
  1566. bprint("$qc_ff_otherteam", attacker.netname);
  1567. else
  1568. bprint("$qc_ff_friend", attacker.netname);
  1569. attacker.frags = attacker.frags - 1;
  1570. return;
  1571. }
  1572. else
  1573. {
  1574. attacker.frags = attacker.frags + 1;
  1575. rnum = attacker.weapon;
  1576. if (rnum == IT_AXE)
  1577. {
  1578. bprint("$qc_death_ax", targ.netname, attacker.netname);
  1579. return;
  1580. }
  1581. if (rnum == IT_SHOTGUN)
  1582. {
  1583. bprint("$qc_death_sg", targ.netname, attacker.netname);
  1584. return;
  1585. }
  1586. if (rnum == IT_SUPER_SHOTGUN)
  1587. {
  1588. bprint("$qc_death_dbl", targ.netname, attacker.netname);
  1589. return;
  1590. }
  1591. if (rnum == IT_NAILGUN)
  1592. {
  1593. bprint("$qc_death_nail", targ.netname, attacker.netname);
  1594. return;
  1595. }
  1596. if (rnum == IT_SUPER_NAILGUN)
  1597. {
  1598. bprint("$qc_death_sng", targ.netname, attacker.netname);
  1599. return;
  1600. }
  1601. if (rnum == IT_GRENADE_LAUNCHER)
  1602. {
  1603. if (targ.health < -40)
  1604. {
  1605. bprint("$qc_death_gl1", targ.netname, attacker.netname);
  1606. return;
  1607. }
  1608. else
  1609. {
  1610. bprint("$qc_death_gl2", targ.netname, attacker.netname);
  1611. return;
  1612. }
  1613. }
  1614. if (rnum == IT_ROCKET_LAUNCHER)
  1615. {
  1616. if (targ.health < -40)
  1617. {
  1618. bprint("$qc_death_rl2", targ.netname, attacker.netname);
  1619. return;
  1620. }
  1621. else
  1622. {
  1623. bprint("$qc_death_rl3", targ.netname, attacker.netname);
  1624. return;
  1625. }
  1626. }
  1627. if (rnum == IT_LIGHTNING)
  1628. {
  1629. if (attacker.waterlevel > 1)
  1630. {
  1631. bprint("$qc_death_lg1", targ.netname, attacker.netname);
  1632. if (attacker.invincible_finished)
  1633. {
  1634. msg_entity = attacker;
  1635. WriteByte (MSG_ONE, SVC_ACHIEVEMENT);
  1636. WriteString(MSG_ONE, "ACH_SURVIVE_DISCHARGE");
  1637. }
  1638. }
  1639. else
  1640. bprint("$qc_death_lg2", targ.netname, attacker.netname);
  1641. return;
  1642. }
  1643. }
  1644. return;
  1645. }
  1646. else
  1647. {
  1648. targ.frags = targ.frags - 1;
  1649. // killed by a montser?
  1650. if (attacker.flags & FL_MONSTER)
  1651. {
  1652. if (attacker.classname == "monster_army")
  1653. bprint ("$qc_ks_grunt", targ.netname);
  1654. if (attacker.classname == "monster_demon1")
  1655. bprint ("$qc_ks_fiend", targ.netname);
  1656. if (attacker.classname == "monster_dog")
  1657. bprint ("$qc_ks_rottweiler", targ.netname);
  1658. if (attacker.classname == "monster_enforcer")
  1659. bprint ("$qc_ks_enforcer", targ.netname);
  1660. if (attacker.classname == "monster_fish")
  1661. bprint ("$qc_ks_rotfish", targ.netname);
  1662. if (attacker.classname == "monster_hell_knight")
  1663. bprint ("$qc_ks_deathknight", targ.netname);
  1664. if (attacker.classname == "monster_knight")
  1665. bprint ("$qc_ks_knight", targ.netname);
  1666. if (attacker.classname == "monster_ogre")
  1667. bprint ("$qc_ks_ogre", targ.netname);
  1668. if (attacker.classname == "monster_shalrath")
  1669. bprint ("$qc_ks_vore", targ.netname);
  1670. if (attacker.classname == "monster_shambler")
  1671. bprint ("$qc_ks_shambler", targ.netname);
  1672. if (attacker.classname == "monster_tarbaby")
  1673. bprint ("$qc_ks_spawn", targ.netname);
  1674. if (attacker.classname == "monster_wizard")
  1675. bprint ("$qc_ks_scrag", targ.netname);
  1676. if (attacker.classname == "monster_zombie")
  1677. bprint ("$qc_ks_zombie", targ.netname);
  1678. return;
  1679. }
  1680. // tricks and traps
  1681. if (attacker.classname == "explo_box")
  1682. {
  1683. bprint ("$qc_ks_blew_up", targ.netname);
  1684. return;
  1685. }
  1686. if (attacker.solid == SOLID_BSP && attacker != world)
  1687. {
  1688. bprint ("$qc_death_squish", targ.netname);
  1689. return;
  1690. }
  1691. if (attacker.classname == "trap_shooter" || attacker.classname == "trap_spikeshooter")
  1692. {
  1693. bprint ("$qc_ks_spiked", targ.netname);
  1694. return;
  1695. }
  1696. if (attacker.classname == "fireball")
  1697. {
  1698. bprint ("$qc_ks_lavaball", targ.netname);
  1699. return;
  1700. }
  1701. if (attacker.classname == "trigger_changelevel")
  1702. {
  1703. bprint ("$qc_ks_tried_leave", targ.netname);
  1704. return;
  1705. }
  1706. // in-water deaths
  1707. rnum = targ.watertype;
  1708. if (rnum == -3)
  1709. {
  1710. if (random() < 0.5)
  1711. bprint("$qc_death_drown1", targ.netname);
  1712. else
  1713. bprint("$qc_death_drown2", targ.netname);
  1714. return;
  1715. }
  1716. else if (rnum == -4)
  1717. {
  1718. if (random() < 0.5)
  1719. bprint("$qc_death_slime1", targ.netname);
  1720. else
  1721. bprint("$qc_death_slime2", targ.netname);
  1722. return;
  1723. }
  1724. else if (rnum == -5)
  1725. {
  1726. if (targ.health < -15)
  1727. {
  1728. bprint("$qc_death_lava1", targ.netname);
  1729. return;
  1730. }
  1731. if (random() < 0.5)
  1732. bprint("$qc_death_lava2", targ.netname);
  1733. else
  1734. bprint("$qc_death_lava3", targ.netname);
  1735. return;
  1736. }
  1737. // fell to their death?
  1738. if (targ.deathtype == "falling")
  1739. {
  1740. bprint("$qc_death_fall", targ.netname);
  1741. return;
  1742. }
  1743. // hell if I know; he's just dead!!!
  1744. bprint("$qc_death_died", targ.netname);
  1745. }
  1746. }
  1747. };