p_client.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727
  1. /*
  2. Copyright (C) 1997-2001 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #include "g_local.h"
  16. #include "m_player.h"
  17. void ClientUserinfoChanged (edict_t *ent, char *userinfo);
  18. void SP_misc_teleporter_dest (edict_t *ent);
  19. //
  20. // Gross, ugly, disgustuing hack section
  21. //
  22. // this function is an ugly as hell hack to fix some map flaws
  23. //
  24. // the coop spawn spots on some maps are SNAFU. There are coop spots
  25. // with the wrong targetname as well as spots with no name at all
  26. //
  27. // we use carnal knowledge of the maps to fix the coop spot targetnames to match
  28. // that of the nearest named single player spot
  29. static void SP_FixCoopSpots (edict_t *self)
  30. {
  31. edict_t *spot;
  32. vec3_t d;
  33. spot = NULL;
  34. while(1)
  35. {
  36. spot = G_Find(spot, FOFS(classname), "info_player_start");
  37. if (!spot)
  38. return;
  39. if (!spot->targetname)
  40. continue;
  41. VectorSubtract(self->s.origin, spot->s.origin, d);
  42. if (VectorLength(d) < 384)
  43. {
  44. if ((!self->targetname) || stricmp(self->targetname, spot->targetname) != 0)
  45. {
  46. // gi.dprintf("FixCoopSpots changed %s at %s targetname from %s to %s\n", self->classname, vtos(self->s.origin), self->targetname, spot->targetname);
  47. self->targetname = spot->targetname;
  48. }
  49. return;
  50. }
  51. }
  52. }
  53. // now if that one wasn't ugly enough for you then try this one on for size
  54. // some maps don't have any coop spots at all, so we need to create them
  55. // where they should have been
  56. static void SP_CreateCoopSpots (edict_t *self)
  57. {
  58. edict_t *spot;
  59. if(stricmp(level.mapname, "security") == 0)
  60. {
  61. spot = G_Spawn();
  62. spot->classname = "info_player_coop";
  63. spot->s.origin[0] = 188 - 64;
  64. spot->s.origin[1] = -164;
  65. spot->s.origin[2] = 80;
  66. spot->targetname = "jail3";
  67. spot->s.angles[1] = 90;
  68. spot = G_Spawn();
  69. spot->classname = "info_player_coop";
  70. spot->s.origin[0] = 188 + 64;
  71. spot->s.origin[1] = -164;
  72. spot->s.origin[2] = 80;
  73. spot->targetname = "jail3";
  74. spot->s.angles[1] = 90;
  75. spot = G_Spawn();
  76. spot->classname = "info_player_coop";
  77. spot->s.origin[0] = 188 + 128;
  78. spot->s.origin[1] = -164;
  79. spot->s.origin[2] = 80;
  80. spot->targetname = "jail3";
  81. spot->s.angles[1] = 90;
  82. return;
  83. }
  84. }
  85. /*QUAKED info_player_start (1 0 0) (-16 -16 -24) (16 16 32)
  86. The normal starting point for a level.
  87. */
  88. void SP_info_player_start(edict_t *self)
  89. {
  90. if (!coop->value)
  91. return;
  92. if(stricmp(level.mapname, "security") == 0)
  93. {
  94. // invoke one of our gross, ugly, disgusting hacks
  95. self->think = SP_CreateCoopSpots;
  96. self->nextthink = level.time + FRAMETIME;
  97. }
  98. }
  99. /*QUAKED info_player_deathmatch (1 0 1) (-16 -16 -24) (16 16 32)
  100. potential spawning position for deathmatch games
  101. */
  102. void SP_info_player_deathmatch(edict_t *self)
  103. {
  104. if (!deathmatch->value)
  105. {
  106. G_FreeEdict (self);
  107. return;
  108. }
  109. SP_misc_teleporter_dest (self);
  110. }
  111. /*QUAKED info_player_coop (1 0 1) (-16 -16 -24) (16 16 32)
  112. potential spawning position for coop games
  113. */
  114. void SP_info_player_coop(edict_t *self)
  115. {
  116. if (!coop->value)
  117. {
  118. G_FreeEdict (self);
  119. return;
  120. }
  121. if((stricmp(level.mapname, "jail2") == 0) ||
  122. (stricmp(level.mapname, "jail4") == 0) ||
  123. (stricmp(level.mapname, "mine1") == 0) ||
  124. (stricmp(level.mapname, "mine2") == 0) ||
  125. (stricmp(level.mapname, "mine3") == 0) ||
  126. (stricmp(level.mapname, "mine4") == 0) ||
  127. (stricmp(level.mapname, "lab") == 0) ||
  128. (stricmp(level.mapname, "boss1") == 0) ||
  129. (stricmp(level.mapname, "fact3") == 0) ||
  130. (stricmp(level.mapname, "biggun") == 0) ||
  131. (stricmp(level.mapname, "space") == 0) ||
  132. (stricmp(level.mapname, "command") == 0) ||
  133. (stricmp(level.mapname, "power2") == 0) ||
  134. (stricmp(level.mapname, "strike") == 0))
  135. {
  136. // invoke one of our gross, ugly, disgusting hacks
  137. self->think = SP_FixCoopSpots;
  138. self->nextthink = level.time + FRAMETIME;
  139. }
  140. }
  141. /*QUAKED info_player_intermission (1 0 1) (-16 -16 -24) (16 16 32)
  142. The deathmatch intermission point will be at one of these
  143. Use 'angles' instead of 'angle', so you can set pitch or roll as well as yaw. 'pitch yaw roll'
  144. */
  145. void SP_info_player_intermission(void)
  146. {
  147. }
  148. //=======================================================================
  149. void player_pain (edict_t *self, edict_t *other, float kick, int damage)
  150. {
  151. // player pain is handled at the end of the frame in P_DamageFeedback
  152. }
  153. qboolean IsFemale (edict_t *ent)
  154. {
  155. char *info;
  156. if (!ent->client)
  157. return false;
  158. info = Info_ValueForKey (ent->client->pers.userinfo, "skin");
  159. if (info[0] == 'f' || info[0] == 'F')
  160. return true;
  161. return false;
  162. }
  163. void ClientObituary (edict_t *self, edict_t *inflictor, edict_t *attacker)
  164. {
  165. int mod;
  166. char *message;
  167. char *message2;
  168. qboolean ff;
  169. if (coop->value && attacker->client)
  170. meansOfDeath |= MOD_FRIENDLY_FIRE;
  171. if (deathmatch->value || coop->value)
  172. {
  173. ff = meansOfDeath & MOD_FRIENDLY_FIRE;
  174. mod = meansOfDeath & ~MOD_FRIENDLY_FIRE;
  175. message = NULL;
  176. message2 = "";
  177. switch (mod)
  178. {
  179. case MOD_SUICIDE:
  180. message = "suicides";
  181. break;
  182. case MOD_FALLING:
  183. message = "cratered";
  184. break;
  185. case MOD_CRUSH:
  186. message = "was squished";
  187. break;
  188. case MOD_WATER:
  189. message = "sank like a rock";
  190. break;
  191. case MOD_SLIME:
  192. message = "melted";
  193. break;
  194. case MOD_LAVA:
  195. message = "does a back flip into the lava";
  196. break;
  197. case MOD_EXPLOSIVE:
  198. case MOD_BARREL:
  199. message = "blew up";
  200. break;
  201. case MOD_EXIT:
  202. message = "found a way out";
  203. break;
  204. case MOD_TARGET_LASER:
  205. message = "saw the light";
  206. break;
  207. case MOD_TARGET_BLASTER:
  208. message = "got blasted";
  209. break;
  210. case MOD_BOMB:
  211. case MOD_SPLASH:
  212. case MOD_TRIGGER_HURT:
  213. message = "was in the wrong place";
  214. break;
  215. }
  216. if (attacker == self)
  217. {
  218. switch (mod)
  219. {
  220. case MOD_HELD_GRENADE:
  221. message = "tried to put the pin back in";
  222. break;
  223. case MOD_HG_SPLASH:
  224. case MOD_G_SPLASH:
  225. if (IsFemale(self))
  226. message = "tripped on her own grenade";
  227. else
  228. message = "tripped on his own grenade";
  229. break;
  230. case MOD_R_SPLASH:
  231. if (IsFemale(self))
  232. message = "blew herself up";
  233. else
  234. message = "blew himself up";
  235. break;
  236. case MOD_BFG_BLAST:
  237. message = "should have used a smaller gun";
  238. break;
  239. default:
  240. if (IsFemale(self))
  241. message = "killed herself";
  242. else
  243. message = "killed himself";
  244. break;
  245. }
  246. }
  247. if (message)
  248. {
  249. gi.bprintf (PRINT_MEDIUM, "%s %s.\n", self->client->pers.netname, message);
  250. if (deathmatch->value)
  251. self->client->resp.score--;
  252. self->enemy = NULL;
  253. return;
  254. }
  255. self->enemy = attacker;
  256. if (attacker && attacker->client)
  257. {
  258. switch (mod)
  259. {
  260. case MOD_BLASTER:
  261. message = "was blasted by";
  262. break;
  263. case MOD_SHOTGUN:
  264. message = "was gunned down by";
  265. break;
  266. case MOD_SSHOTGUN:
  267. message = "was blown away by";
  268. message2 = "'s super shotgun";
  269. break;
  270. case MOD_MACHINEGUN:
  271. message = "was machinegunned by";
  272. break;
  273. case MOD_CHAINGUN:
  274. message = "was cut in half by";
  275. message2 = "'s chaingun";
  276. break;
  277. case MOD_GRENADE:
  278. message = "was popped by";
  279. message2 = "'s grenade";
  280. break;
  281. case MOD_G_SPLASH:
  282. message = "was shredded by";
  283. message2 = "'s shrapnel";
  284. break;
  285. case MOD_ROCKET:
  286. message = "ate";
  287. message2 = "'s rocket";
  288. break;
  289. case MOD_R_SPLASH:
  290. message = "almost dodged";
  291. message2 = "'s rocket";
  292. break;
  293. case MOD_HYPERBLASTER:
  294. message = "was melted by";
  295. message2 = "'s hyperblaster";
  296. break;
  297. case MOD_RAILGUN:
  298. message = "was railed by";
  299. break;
  300. case MOD_BFG_LASER:
  301. message = "saw the pretty lights from";
  302. message2 = "'s BFG";
  303. break;
  304. case MOD_BFG_BLAST:
  305. message = "was disintegrated by";
  306. message2 = "'s BFG blast";
  307. break;
  308. case MOD_BFG_EFFECT:
  309. message = "couldn't hide from";
  310. message2 = "'s BFG";
  311. break;
  312. case MOD_HANDGRENADE:
  313. message = "caught";
  314. message2 = "'s handgrenade";
  315. break;
  316. case MOD_HG_SPLASH:
  317. message = "didn't see";
  318. message2 = "'s handgrenade";
  319. break;
  320. case MOD_HELD_GRENADE:
  321. message = "feels";
  322. message2 = "'s pain";
  323. break;
  324. case MOD_TELEFRAG:
  325. message = "tried to invade";
  326. message2 = "'s personal space";
  327. break;
  328. //ZOID
  329. case MOD_GRAPPLE:
  330. message = "was caught by";
  331. message2 = "'s grapple";
  332. break;
  333. //ZOID
  334. }
  335. if (message)
  336. {
  337. gi.bprintf (PRINT_MEDIUM,"%s %s %s%s\n", self->client->pers.netname, message, attacker->client->pers.netname, message2);
  338. if (deathmatch->value)
  339. {
  340. if (ff)
  341. attacker->client->resp.score--;
  342. else
  343. attacker->client->resp.score++;
  344. }
  345. return;
  346. }
  347. }
  348. }
  349. gi.bprintf (PRINT_MEDIUM,"%s died.\n", self->client->pers.netname);
  350. if (deathmatch->value)
  351. self->client->resp.score--;
  352. }
  353. void Touch_Item (edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *surf);
  354. void TossClientWeapon (edict_t *self)
  355. {
  356. gitem_t *item;
  357. edict_t *drop;
  358. qboolean quad;
  359. float spread;
  360. if (!deathmatch->value)
  361. return;
  362. item = self->client->pers.weapon;
  363. if (! self->client->pers.inventory[self->client->ammo_index] )
  364. item = NULL;
  365. if (item && (strcmp (item->pickup_name, "Blaster") == 0))
  366. item = NULL;
  367. if (!((int)(dmflags->value) & DF_QUAD_DROP))
  368. quad = false;
  369. else
  370. quad = (self->client->quad_framenum > (level.framenum + 10));
  371. if (item && quad)
  372. spread = 22.5;
  373. else
  374. spread = 0.0;
  375. if (item)
  376. {
  377. self->client->v_angle[YAW] -= spread;
  378. drop = Drop_Item (self, item);
  379. self->client->v_angle[YAW] += spread;
  380. drop->spawnflags = DROPPED_PLAYER_ITEM;
  381. }
  382. if (quad)
  383. {
  384. self->client->v_angle[YAW] += spread;
  385. drop = Drop_Item (self, FindItemByClassname ("item_quad"));
  386. self->client->v_angle[YAW] -= spread;
  387. drop->spawnflags |= DROPPED_PLAYER_ITEM;
  388. drop->touch = Touch_Item;
  389. drop->nextthink = level.time + (self->client->quad_framenum - level.framenum) * FRAMETIME;
  390. drop->think = G_FreeEdict;
  391. }
  392. }
  393. /*
  394. ==================
  395. LookAtKiller
  396. ==================
  397. */
  398. void LookAtKiller (edict_t *self, edict_t *inflictor, edict_t *attacker)
  399. {
  400. vec3_t dir;
  401. if (attacker && attacker != world && attacker != self)
  402. {
  403. VectorSubtract (attacker->s.origin, self->s.origin, dir);
  404. }
  405. else if (inflictor && inflictor != world && inflictor != self)
  406. {
  407. VectorSubtract (inflictor->s.origin, self->s.origin, dir);
  408. }
  409. else
  410. {
  411. self->client->killer_yaw = self->s.angles[YAW];
  412. return;
  413. }
  414. if (dir[0])
  415. self->client->killer_yaw = 180/M_PI*atan2(dir[1], dir[0]);
  416. else {
  417. self->client->killer_yaw = 0;
  418. if (dir[1] > 0)
  419. self->client->killer_yaw = 90;
  420. else if (dir[1] < 0)
  421. self->client->killer_yaw = -90;
  422. }
  423. if (self->client->killer_yaw < 0)
  424. self->client->killer_yaw += 360;
  425. }
  426. /*
  427. ==================
  428. player_die
  429. ==================
  430. */
  431. void player_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
  432. {
  433. int n;
  434. VectorClear (self->avelocity);
  435. self->takedamage = DAMAGE_YES;
  436. self->movetype = MOVETYPE_TOSS;
  437. self->s.modelindex2 = 0; // remove linked weapon model
  438. //ZOID
  439. self->s.modelindex3 = 0; // remove linked ctf flag
  440. //ZOID
  441. self->s.angles[0] = 0;
  442. self->s.angles[2] = 0;
  443. self->s.sound = 0;
  444. self->client->weapon_sound = 0;
  445. self->maxs[2] = -8;
  446. // self->solid = SOLID_NOT;
  447. self->svflags |= SVF_DEADMONSTER;
  448. if (!self->deadflag)
  449. {
  450. self->client->respawn_time = level.time + 1.0;
  451. LookAtKiller (self, inflictor, attacker);
  452. self->client->ps.pmove.pm_type = PM_DEAD;
  453. ClientObituary (self, inflictor, attacker);
  454. //ZOID
  455. // if at start and same team, clear
  456. if (ctf->value && meansOfDeath == MOD_TELEFRAG &&
  457. self->client->resp.ctf_state < 2 &&
  458. self->client->resp.ctf_team == attacker->client->resp.ctf_team) {
  459. attacker->client->resp.score--;
  460. self->client->resp.ctf_state = 0;
  461. }
  462. CTFFragBonuses(self, inflictor, attacker);
  463. //ZOID
  464. TossClientWeapon (self);
  465. //ZOID
  466. CTFPlayerResetGrapple(self);
  467. CTFDeadDropFlag(self);
  468. CTFDeadDropTech(self);
  469. //ZOID
  470. if (deathmatch->value && !self->client->showscores)
  471. Cmd_Help_f (self); // show scores
  472. }
  473. // remove powerups
  474. self->client->quad_framenum = 0;
  475. self->client->invincible_framenum = 0;
  476. self->client->breather_framenum = 0;
  477. self->client->enviro_framenum = 0;
  478. // clear inventory
  479. memset(self->client->pers.inventory, 0, sizeof(self->client->pers.inventory));
  480. if (self->health < -40)
  481. { // gib
  482. gi.sound (self, CHAN_BODY, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
  483. for (n= 0; n < 4; n++)
  484. ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
  485. ThrowClientHead (self, damage);
  486. //ZOID
  487. self->client->anim_priority = ANIM_DEATH;
  488. self->client->anim_end = 0;
  489. //ZOID
  490. self->takedamage = DAMAGE_NO;
  491. }
  492. else
  493. { // normal death
  494. if (!self->deadflag)
  495. {
  496. static int i;
  497. i = (i+1)%3;
  498. // start a death animation
  499. self->client->anim_priority = ANIM_DEATH;
  500. if (self->client->ps.pmove.pm_flags & PMF_DUCKED)
  501. {
  502. self->s.frame = FRAME_crdeath1-1;
  503. self->client->anim_end = FRAME_crdeath5;
  504. }
  505. else switch (i)
  506. {
  507. case 0:
  508. self->s.frame = FRAME_death101-1;
  509. self->client->anim_end = FRAME_death106;
  510. break;
  511. case 1:
  512. self->s.frame = FRAME_death201-1;
  513. self->client->anim_end = FRAME_death206;
  514. break;
  515. case 2:
  516. self->s.frame = FRAME_death301-1;
  517. self->client->anim_end = FRAME_death308;
  518. break;
  519. }
  520. gi.sound (self, CHAN_VOICE, gi.soundindex(va("*death%i.wav", (rand()%4)+1)), 1, ATTN_NORM, 0);
  521. }
  522. }
  523. self->deadflag = DEAD_DEAD;
  524. gi.linkentity (self);
  525. }
  526. //=======================================================================
  527. /*
  528. ==============
  529. InitClientPersistant
  530. This is only called when the game first initializes in single player,
  531. but is called after each death and level change in deathmatch
  532. ==============
  533. */
  534. void InitClientPersistant (gclient_t *client)
  535. {
  536. gitem_t *item;
  537. memset (&client->pers, 0, sizeof(client->pers));
  538. item = FindItem("Blaster");
  539. client->pers.selected_item = ITEM_INDEX(item);
  540. client->pers.inventory[client->pers.selected_item] = 1;
  541. client->pers.weapon = item;
  542. //ZOID
  543. client->pers.lastweapon = item;
  544. //ZOID
  545. //ZOID
  546. item = FindItem("Grapple");
  547. client->pers.inventory[ITEM_INDEX(item)] = 1;
  548. //ZOID
  549. client->pers.health = 100;
  550. client->pers.max_health = 100;
  551. client->pers.max_bullets = 200;
  552. client->pers.max_shells = 100;
  553. client->pers.max_rockets = 50;
  554. client->pers.max_grenades = 50;
  555. client->pers.max_cells = 200;
  556. client->pers.max_slugs = 50;
  557. client->pers.connected = true;
  558. }
  559. void InitClientResp (gclient_t *client)
  560. {
  561. //ZOID
  562. int ctf_team = client->resp.ctf_team;
  563. qboolean id_state = client->resp.id_state;
  564. //ZOID
  565. memset (&client->resp, 0, sizeof(client->resp));
  566. //ZOID
  567. client->resp.ctf_team = ctf_team;
  568. client->resp.id_state = id_state;
  569. //ZOID
  570. client->resp.enterframe = level.framenum;
  571. client->resp.coop_respawn = client->pers;
  572. //ZOID
  573. if (ctf->value && client->resp.ctf_team < CTF_TEAM1)
  574. CTFAssignTeam(client);
  575. //ZOID
  576. }
  577. /*
  578. ==================
  579. SaveClientData
  580. Some information that should be persistant, like health,
  581. is still stored in the edict structure, so it needs to
  582. be mirrored out to the client structure before all the
  583. edicts are wiped.
  584. ==================
  585. */
  586. void SaveClientData (void)
  587. {
  588. int i;
  589. edict_t *ent;
  590. for (i=0 ; i<game.maxclients ; i++)
  591. {
  592. ent = &g_edicts[1+i];
  593. if (!ent->inuse)
  594. continue;
  595. game.clients[i].pers.health = ent->health;
  596. game.clients[i].pers.max_health = ent->max_health;
  597. game.clients[i].pers.powerArmorActive = (ent->flags & FL_POWER_ARMOR);
  598. if (coop->value)
  599. game.clients[i].pers.score = ent->client->resp.score;
  600. }
  601. }
  602. void FetchClientEntData (edict_t *ent)
  603. {
  604. ent->health = ent->client->pers.health;
  605. ent->max_health = ent->client->pers.max_health;
  606. if (ent->client->pers.powerArmorActive)
  607. ent->flags |= FL_POWER_ARMOR;
  608. if (coop->value)
  609. ent->client->resp.score = ent->client->pers.score;
  610. }
  611. /*
  612. =======================================================================
  613. SelectSpawnPoint
  614. =======================================================================
  615. */
  616. /*
  617. ================
  618. PlayersRangeFromSpot
  619. Returns the distance to the nearest player from the given spot
  620. ================
  621. */
  622. float PlayersRangeFromSpot (edict_t *spot)
  623. {
  624. edict_t *player;
  625. float bestplayerdistance;
  626. vec3_t v;
  627. int n;
  628. float playerdistance;
  629. bestplayerdistance = 9999999;
  630. for (n = 1; n <= maxclients->value; n++)
  631. {
  632. player = &g_edicts[n];
  633. if (!player->inuse)
  634. continue;
  635. if (player->health <= 0)
  636. continue;
  637. VectorSubtract (spot->s.origin, player->s.origin, v);
  638. playerdistance = VectorLength (v);
  639. if (playerdistance < bestplayerdistance)
  640. bestplayerdistance = playerdistance;
  641. }
  642. return bestplayerdistance;
  643. }
  644. /*
  645. ================
  646. SelectRandomDeathmatchSpawnPoint
  647. go to a random point, but NOT the two points closest
  648. to other players
  649. ================
  650. */
  651. edict_t *SelectRandomDeathmatchSpawnPoint (void)
  652. {
  653. edict_t *spot, *spot1, *spot2;
  654. int count = 0;
  655. int selection;
  656. float range, range1, range2;
  657. spot = NULL;
  658. range1 = range2 = 99999;
  659. spot1 = spot2 = NULL;
  660. while ((spot = G_Find (spot, FOFS(classname), "info_player_deathmatch")) != NULL)
  661. {
  662. count++;
  663. range = PlayersRangeFromSpot(spot);
  664. if (range < range1)
  665. {
  666. range1 = range;
  667. spot1 = spot;
  668. }
  669. else if (range < range2)
  670. {
  671. range2 = range;
  672. spot2 = spot;
  673. }
  674. }
  675. if (!count)
  676. return NULL;
  677. if (count <= 2)
  678. {
  679. spot1 = spot2 = NULL;
  680. }
  681. else
  682. count -= 2;
  683. selection = rand() % count;
  684. spot = NULL;
  685. do
  686. {
  687. spot = G_Find (spot, FOFS(classname), "info_player_deathmatch");
  688. if (spot == spot1 || spot == spot2)
  689. selection++;
  690. } while(selection--);
  691. return spot;
  692. }
  693. /*
  694. ================
  695. SelectFarthestDeathmatchSpawnPoint
  696. ================
  697. */
  698. edict_t *SelectFarthestDeathmatchSpawnPoint (void)
  699. {
  700. edict_t *bestspot;
  701. float bestdistance, bestplayerdistance;
  702. edict_t *spot;
  703. spot = NULL;
  704. bestspot = NULL;
  705. bestdistance = 0;
  706. while ((spot = G_Find (spot, FOFS(classname), "info_player_deathmatch")) != NULL)
  707. {
  708. bestplayerdistance = PlayersRangeFromSpot (spot);
  709. if (bestplayerdistance > bestdistance)
  710. {
  711. bestspot = spot;
  712. bestdistance = bestplayerdistance;
  713. }
  714. }
  715. if (bestspot)
  716. {
  717. return bestspot;
  718. }
  719. // if there is a player just spawned on each and every start spot
  720. // we have no choice to turn one into a telefrag meltdown
  721. spot = G_Find (NULL, FOFS(classname), "info_player_deathmatch");
  722. return spot;
  723. }
  724. edict_t *SelectDeathmatchSpawnPoint (void)
  725. {
  726. if ( (int)(dmflags->value) & DF_SPAWN_FARTHEST)
  727. return SelectFarthestDeathmatchSpawnPoint ();
  728. else
  729. return SelectRandomDeathmatchSpawnPoint ();
  730. }
  731. edict_t *SelectCoopSpawnPoint (edict_t *ent)
  732. {
  733. int index;
  734. edict_t *spot = NULL;
  735. char *target;
  736. index = ent->client - game.clients;
  737. // player 0 starts in normal player spawn point
  738. if (!index)
  739. return NULL;
  740. spot = NULL;
  741. // assume there are four coop spots at each spawnpoint
  742. while (1)
  743. {
  744. spot = G_Find (spot, FOFS(classname), "info_player_coop");
  745. if (!spot)
  746. return NULL; // we didn't have enough...
  747. target = spot->targetname;
  748. if (!target)
  749. target = "";
  750. if ( Q_stricmp(game.spawnpoint, target) == 0 )
  751. { // this is a coop spawn point for one of the clients here
  752. index--;
  753. if (!index)
  754. return spot; // this is it
  755. }
  756. }
  757. return spot;
  758. }
  759. /*
  760. ===========
  761. SelectSpawnPoint
  762. Chooses a player start, deathmatch start, coop start, etc
  763. ============
  764. */
  765. void SelectSpawnPoint (edict_t *ent, vec3_t origin, vec3_t angles)
  766. {
  767. edict_t *spot = NULL;
  768. if (deathmatch->value)
  769. //ZOID
  770. if (ctf->value)
  771. spot = SelectCTFSpawnPoint(ent);
  772. else
  773. //ZOID
  774. spot = SelectDeathmatchSpawnPoint ();
  775. else if (coop->value)
  776. spot = SelectCoopSpawnPoint (ent);
  777. // find a single player start spot
  778. if (!spot)
  779. {
  780. while ((spot = G_Find (spot, FOFS(classname), "info_player_start")) != NULL)
  781. {
  782. if (!game.spawnpoint[0] && !spot->targetname)
  783. break;
  784. if (!game.spawnpoint[0] || !spot->targetname)
  785. continue;
  786. if (Q_stricmp(game.spawnpoint, spot->targetname) == 0)
  787. break;
  788. }
  789. if (!spot)
  790. {
  791. if (!game.spawnpoint[0])
  792. { // there wasn't a spawnpoint without a target, so use any
  793. spot = G_Find (spot, FOFS(classname), "info_player_start");
  794. }
  795. if (!spot)
  796. gi.error ("Couldn't find spawn point %s\n", game.spawnpoint);
  797. }
  798. }
  799. VectorCopy (spot->s.origin, origin);
  800. origin[2] += 9;
  801. VectorCopy (spot->s.angles, angles);
  802. }
  803. //======================================================================
  804. void InitBodyQue (void)
  805. {
  806. int i;
  807. edict_t *ent;
  808. level.body_que = 0;
  809. for (i=0; i<BODY_QUEUE_SIZE ; i++)
  810. {
  811. ent = G_Spawn();
  812. ent->classname = "bodyque";
  813. }
  814. }
  815. void body_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
  816. {
  817. int n;
  818. if (self->health < -40)
  819. {
  820. gi.sound (self, CHAN_BODY, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
  821. for (n= 0; n < 4; n++)
  822. ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
  823. self->s.origin[2] -= 48;
  824. ThrowClientHead (self, damage);
  825. self->takedamage = DAMAGE_NO;
  826. }
  827. }
  828. void CopyToBodyQue (edict_t *ent)
  829. {
  830. edict_t *body;
  831. // grab a body que and cycle to the next one
  832. body = &g_edicts[(int)maxclients->value + level.body_que + 1];
  833. level.body_que = (level.body_que + 1) % BODY_QUEUE_SIZE;
  834. // FIXME: send an effect on the removed body
  835. gi.unlinkentity (ent);
  836. gi.unlinkentity (body);
  837. body->s = ent->s;
  838. body->s.number = body - g_edicts;
  839. body->svflags = ent->svflags;
  840. VectorCopy (ent->mins, body->mins);
  841. VectorCopy (ent->maxs, body->maxs);
  842. VectorCopy (ent->absmin, body->absmin);
  843. VectorCopy (ent->absmax, body->absmax);
  844. VectorCopy (ent->size, body->size);
  845. body->solid = ent->solid;
  846. body->clipmask = ent->clipmask;
  847. body->owner = ent->owner;
  848. body->movetype = ent->movetype;
  849. body->die = body_die;
  850. body->takedamage = DAMAGE_YES;
  851. gi.linkentity (body);
  852. }
  853. void respawn (edict_t *self)
  854. {
  855. if (deathmatch->value || coop->value)
  856. {
  857. if (self->movetype != MOVETYPE_NOCLIP)
  858. CopyToBodyQue (self);
  859. self->svflags &= ~SVF_NOCLIENT;
  860. PutClientInServer (self);
  861. // add a teleportation effect
  862. self->s.event = EV_PLAYER_TELEPORT;
  863. // hold in place briefly
  864. self->client->ps.pmove.pm_flags = PMF_TIME_TELEPORT;
  865. self->client->ps.pmove.pm_time = 14;
  866. self->client->respawn_time = level.time;
  867. return;
  868. }
  869. // restart the entire server
  870. gi.AddCommandString ("menu_loadgame\n");
  871. }
  872. //==============================================================
  873. /*
  874. ===========
  875. PutClientInServer
  876. Called when a player connects to a server or respawns in
  877. a deathmatch.
  878. ============
  879. */
  880. void PutClientInServer (edict_t *ent)
  881. {
  882. vec3_t mins = {-16, -16, -24};
  883. vec3_t maxs = {16, 16, 32};
  884. int index;
  885. vec3_t spawn_origin, spawn_angles;
  886. gclient_t *client;
  887. int i;
  888. client_persistant_t saved;
  889. client_respawn_t resp;
  890. // find a spawn point
  891. // do it before setting health back up, so farthest
  892. // ranging doesn't count this client
  893. SelectSpawnPoint (ent, spawn_origin, spawn_angles);
  894. index = ent-g_edicts-1;
  895. client = ent->client;
  896. // deathmatch wipes most client data every spawn
  897. if (deathmatch->value)
  898. {
  899. char userinfo[MAX_INFO_STRING];
  900. resp = client->resp;
  901. memcpy (userinfo, client->pers.userinfo, sizeof(userinfo));
  902. InitClientPersistant (client);
  903. ClientUserinfoChanged (ent, userinfo);
  904. }
  905. else if (coop->value)
  906. {
  907. int n;
  908. char userinfo[MAX_INFO_STRING];
  909. resp = client->resp;
  910. memcpy (userinfo, client->pers.userinfo, sizeof(userinfo));
  911. // this is kind of ugly, but it's how we want to handle keys in coop
  912. for (n = 0; n < MAX_ITEMS; n++)
  913. {
  914. if (itemlist[n].flags & IT_KEY)
  915. resp.coop_respawn.inventory[n] = client->pers.inventory[n];
  916. }
  917. client->pers = resp.coop_respawn;
  918. ClientUserinfoChanged (ent, userinfo);
  919. if (resp.score > client->pers.score)
  920. client->pers.score = resp.score;
  921. }
  922. else
  923. {
  924. memset (&resp, 0, sizeof(resp));
  925. }
  926. // clear everything but the persistant data
  927. saved = client->pers;
  928. memset (client, 0, sizeof(*client));
  929. client->pers = saved;
  930. if (client->pers.health <= 0)
  931. InitClientPersistant(client);
  932. client->resp = resp;
  933. // copy some data from the client to the entity
  934. FetchClientEntData (ent);
  935. // clear entity values
  936. ent->groundentity = NULL;
  937. ent->client = &game.clients[index];
  938. ent->takedamage = DAMAGE_AIM;
  939. ent->movetype = MOVETYPE_WALK;
  940. ent->viewheight = 22;
  941. ent->inuse = true;
  942. ent->classname = "player";
  943. ent->mass = 200;
  944. ent->solid = SOLID_BBOX;
  945. ent->deadflag = DEAD_NO;
  946. ent->air_finished = level.time + 12;
  947. ent->clipmask = MASK_PLAYERSOLID;
  948. ent->model = "players/male/tris.md2";
  949. ent->pain = player_pain;
  950. ent->die = player_die;
  951. ent->waterlevel = 0;
  952. ent->watertype = 0;
  953. ent->flags &= ~FL_NO_KNOCKBACK;
  954. ent->svflags &= ~SVF_DEADMONSTER;
  955. VectorCopy (mins, ent->mins);
  956. VectorCopy (maxs, ent->maxs);
  957. VectorClear (ent->velocity);
  958. // clear playerstate values
  959. memset (&ent->client->ps, 0, sizeof(client->ps));
  960. client->ps.pmove.origin[0] = spawn_origin[0]*8;
  961. client->ps.pmove.origin[1] = spawn_origin[1]*8;
  962. client->ps.pmove.origin[2] = spawn_origin[2]*8;
  963. //ZOID
  964. client->ps.pmove.pm_flags &= ~PMF_NO_PREDICTION;
  965. //ZOID
  966. if (deathmatch->value && ((int)dmflags->value & DF_FIXED_FOV))
  967. {
  968. client->ps.fov = 90;
  969. }
  970. else
  971. {
  972. client->ps.fov = atoi(Info_ValueForKey(client->pers.userinfo, "fov"));
  973. if (client->ps.fov < 1)
  974. client->ps.fov = 90;
  975. else if (client->ps.fov > 160)
  976. client->ps.fov = 160;
  977. }
  978. client->ps.gunindex = gi.modelindex(client->pers.weapon->view_model);
  979. // clear entity state values
  980. ent->s.effects = 0;
  981. ent->s.skinnum = ent - g_edicts - 1;
  982. ent->s.modelindex = 255; // will use the skin specified model
  983. ent->s.modelindex2 = 255; // custom gun model
  984. // sknum is player num and weapon number
  985. // weapon number will be added in changeweapon
  986. ent->s.skinnum = ent - g_edicts - 1;
  987. ent->s.frame = 0;
  988. VectorCopy (spawn_origin, ent->s.origin);
  989. ent->s.origin[2] += 1; // make sure off ground
  990. VectorCopy (ent->s.origin, ent->s.old_origin);
  991. // set the delta angle
  992. for (i=0 ; i<3 ; i++)
  993. client->ps.pmove.delta_angles[i] = ANGLE2SHORT(spawn_angles[i] - client->resp.cmd_angles[i]);
  994. ent->s.angles[PITCH] = 0;
  995. ent->s.angles[YAW] = spawn_angles[YAW];
  996. ent->s.angles[ROLL] = 0;
  997. VectorCopy (ent->s.angles, client->ps.viewangles);
  998. VectorCopy (ent->s.angles, client->v_angle);
  999. //ZOID
  1000. if (CTFStartClient(ent))
  1001. return;
  1002. //ZOID
  1003. if (!KillBox (ent))
  1004. { // could't spawn in?
  1005. }
  1006. gi.linkentity (ent);
  1007. // force the current weapon up
  1008. client->newweapon = client->pers.weapon;
  1009. ChangeWeapon (ent);
  1010. }
  1011. /*
  1012. =====================
  1013. ClientBeginDeathmatch
  1014. A client has just connected to the server in
  1015. deathmatch mode, so clear everything out before starting them.
  1016. =====================
  1017. */
  1018. void ClientBeginDeathmatch (edict_t *ent)
  1019. {
  1020. G_InitEdict (ent);
  1021. InitClientResp (ent->client);
  1022. // locate ent at a spawn point
  1023. PutClientInServer (ent);
  1024. // send effect
  1025. gi.WriteByte (svc_muzzleflash);
  1026. gi.WriteShort (ent-g_edicts);
  1027. gi.WriteByte (MZ_LOGIN);
  1028. gi.multicast (ent->s.origin, MULTICAST_PVS);
  1029. gi.bprintf (PRINT_HIGH, "%s entered the game\n", ent->client->pers.netname);
  1030. // make sure all view stuff is valid
  1031. ClientEndServerFrame (ent);
  1032. }
  1033. /*
  1034. ===========
  1035. ClientBegin
  1036. called when a client has finished connecting, and is ready
  1037. to be placed into the game. This will happen every level load.
  1038. ============
  1039. */
  1040. void ClientBegin (edict_t *ent)
  1041. {
  1042. int i;
  1043. ent->client = game.clients + (ent - g_edicts - 1);
  1044. if (deathmatch->value)
  1045. {
  1046. ClientBeginDeathmatch (ent);
  1047. return;
  1048. }
  1049. // if there is already a body waiting for us (a loadgame), just
  1050. // take it, otherwise spawn one from scratch
  1051. if (ent->inuse == true)
  1052. {
  1053. // the client has cleared the client side viewangles upon
  1054. // connecting to the server, which is different than the
  1055. // state when the game is saved, so we need to compensate
  1056. // with deltaangles
  1057. for (i=0 ; i<3 ; i++)
  1058. ent->client->ps.pmove.delta_angles[i] = ANGLE2SHORT(ent->client->ps.viewangles[i]);
  1059. }
  1060. else
  1061. {
  1062. // a spawn point will completely reinitialize the entity
  1063. // except for the persistant data that was initialized at
  1064. // ClientConnect() time
  1065. G_InitEdict (ent);
  1066. ent->classname = "player";
  1067. InitClientResp (ent->client);
  1068. PutClientInServer (ent);
  1069. }
  1070. if (level.intermissiontime)
  1071. {
  1072. MoveClientToIntermission (ent);
  1073. }
  1074. else
  1075. {
  1076. // send effect if in a multiplayer game
  1077. if (game.maxclients > 1)
  1078. {
  1079. gi.WriteByte (svc_muzzleflash);
  1080. gi.WriteShort (ent-g_edicts);
  1081. gi.WriteByte (MZ_LOGIN);
  1082. gi.multicast (ent->s.origin, MULTICAST_PVS);
  1083. gi.bprintf (PRINT_HIGH, "%s entered the game\n", ent->client->pers.netname);
  1084. }
  1085. }
  1086. // make sure all view stuff is valid
  1087. ClientEndServerFrame (ent);
  1088. }
  1089. /*
  1090. ===========
  1091. ClientUserInfoChanged
  1092. called whenever the player updates a userinfo variable.
  1093. The game can override any of the settings in place
  1094. (forcing skins or names, etc) before copying it off.
  1095. ============
  1096. */
  1097. void ClientUserinfoChanged (edict_t *ent, char *userinfo)
  1098. {
  1099. char *s;
  1100. int playernum;
  1101. // check for malformed or illegal info strings
  1102. if (!Info_Validate(userinfo))
  1103. {
  1104. strcpy (userinfo, "\\name\\badinfo\\skin\\male/grunt");
  1105. }
  1106. // set name
  1107. s = Info_ValueForKey (userinfo, "name");
  1108. strncpy (ent->client->pers.netname, s, sizeof(ent->client->pers.netname)-1);
  1109. // set skin
  1110. s = Info_ValueForKey (userinfo, "skin");
  1111. playernum = ent-g_edicts-1;
  1112. // combine name and skin into a configstring
  1113. //ZOID
  1114. if (ctf->value)
  1115. CTFAssignSkin(ent, s);
  1116. else
  1117. //ZOID
  1118. gi.configstring (CS_PLAYERSKINS+playernum, va("%s\\%s", ent->client->pers.netname, s) );
  1119. // fov
  1120. if (deathmatch->value && ((int)dmflags->value & DF_FIXED_FOV))
  1121. {
  1122. ent->client->ps.fov = 90;
  1123. }
  1124. else
  1125. {
  1126. ent->client->ps.fov = atoi(Info_ValueForKey(userinfo, "fov"));
  1127. if (ent->client->ps.fov < 1)
  1128. ent->client->ps.fov = 90;
  1129. else if (ent->client->ps.fov > 160)
  1130. ent->client->ps.fov = 160;
  1131. }
  1132. // handedness
  1133. s = Info_ValueForKey (userinfo, "hand");
  1134. if (strlen(s))
  1135. {
  1136. ent->client->pers.hand = atoi(s);
  1137. }
  1138. // save off the userinfo in case we want to check something later
  1139. strncpy (ent->client->pers.userinfo, userinfo, sizeof(ent->client->pers.userinfo)-1);
  1140. }
  1141. /*
  1142. ===========
  1143. ClientConnect
  1144. Called when a player begins connecting to the server.
  1145. The game can refuse entrance to a client by returning false.
  1146. If the client is allowed, the connection process will continue
  1147. and eventually get to ClientBegin()
  1148. Changing levels will NOT cause this to be called again, but
  1149. loadgames will.
  1150. ============
  1151. */
  1152. qboolean ClientConnect (edict_t *ent, char *userinfo)
  1153. {
  1154. char *value;
  1155. // check to see if they are on the banned IP list
  1156. value = Info_ValueForKey (userinfo, "ip");
  1157. // check for a password
  1158. value = Info_ValueForKey (userinfo, "password");
  1159. if (*password->string && strcmp(password->string, "none") &&
  1160. strcmp(password->string, value)) {
  1161. Info_SetValueForKey(userinfo, "rejmsg", "Password required or incorrect.");
  1162. return false;
  1163. }
  1164. // they can connect
  1165. ent->client = game.clients + (ent - g_edicts - 1);
  1166. // if there is already a body waiting for us (a loadgame), just
  1167. // take it, otherwise spawn one from scratch
  1168. if (ent->inuse == false)
  1169. {
  1170. // clear the respawning variables
  1171. //ZOID -- force team join
  1172. ent->client->resp.ctf_team = -1;
  1173. ent->client->resp.id_state = false;
  1174. //ZOID
  1175. InitClientResp (ent->client);
  1176. if (!game.autosaved || !ent->client->pers.weapon)
  1177. InitClientPersistant (ent->client);
  1178. }
  1179. ClientUserinfoChanged (ent, userinfo);
  1180. if (game.maxclients > 1)
  1181. gi.dprintf ("%s connected\n", ent->client->pers.netname);
  1182. ent->client->pers.connected = true;
  1183. return true;
  1184. }
  1185. /*
  1186. ===========
  1187. ClientDisconnect
  1188. Called when a player drops from the server.
  1189. Will not be called between levels.
  1190. ============
  1191. */
  1192. void ClientDisconnect (edict_t *ent)
  1193. {
  1194. int playernum;
  1195. if (!ent->client)
  1196. return;
  1197. gi.bprintf (PRINT_HIGH, "%s disconnected\n", ent->client->pers.netname);
  1198. //ZOID
  1199. CTFDeadDropFlag(ent);
  1200. CTFDeadDropTech(ent);
  1201. //ZOID
  1202. // send effect
  1203. gi.WriteByte (svc_muzzleflash);
  1204. gi.WriteShort (ent-g_edicts);
  1205. gi.WriteByte (MZ_LOGOUT);
  1206. gi.multicast (ent->s.origin, MULTICAST_PVS);
  1207. gi.unlinkentity (ent);
  1208. ent->s.modelindex = 0;
  1209. ent->solid = SOLID_NOT;
  1210. ent->inuse = false;
  1211. ent->classname = "disconnected";
  1212. ent->client->pers.connected = false;
  1213. playernum = ent-g_edicts-1;
  1214. gi.configstring (CS_PLAYERSKINS+playernum, "");
  1215. }
  1216. //==============================================================
  1217. edict_t *pm_passent;
  1218. // pmove doesn't need to know about passent and contentmask
  1219. trace_t PM_trace (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end)
  1220. {
  1221. if (pm_passent->health > 0)
  1222. return gi.trace (start, mins, maxs, end, pm_passent, MASK_PLAYERSOLID);
  1223. else
  1224. return gi.trace (start, mins, maxs, end, pm_passent, MASK_DEADSOLID);
  1225. }
  1226. unsigned CheckBlock (void *b, int c)
  1227. {
  1228. int v,i;
  1229. v = 0;
  1230. for (i=0 ; i<c ; i++)
  1231. v+= ((byte *)b)[i];
  1232. return v;
  1233. }
  1234. void PrintPmove (pmove_t *pm)
  1235. {
  1236. unsigned c1, c2;
  1237. c1 = CheckBlock (&pm->s, sizeof(pm->s));
  1238. c2 = CheckBlock (&pm->cmd, sizeof(pm->cmd));
  1239. Com_Printf ("sv %3i:%i %i\n", pm->cmd.impulse, c1, c2);
  1240. }
  1241. /*
  1242. ==============
  1243. ClientThink
  1244. This will be called once for each client frame, which will
  1245. usually be a couple times for each server frame.
  1246. ==============
  1247. */
  1248. void ClientThink (edict_t *ent, usercmd_t *ucmd)
  1249. {
  1250. gclient_t *client;
  1251. edict_t *other;
  1252. int i, j;
  1253. pmove_t pm;
  1254. level.current_entity = ent;
  1255. client = ent->client;
  1256. if (level.intermissiontime)
  1257. {
  1258. client->ps.pmove.pm_type = PM_FREEZE;
  1259. // can exit intermission after five seconds
  1260. if (level.time > level.intermissiontime + 5.0
  1261. && (ucmd->buttons & BUTTON_ANY) )
  1262. level.exitintermission = true;
  1263. return;
  1264. }
  1265. pm_passent = ent;
  1266. //ZOID
  1267. if (ent->client->chase_target) {
  1268. client->resp.cmd_angles[0] = SHORT2ANGLE(ucmd->angles[0]);
  1269. client->resp.cmd_angles[1] = SHORT2ANGLE(ucmd->angles[1]);
  1270. client->resp.cmd_angles[2] = SHORT2ANGLE(ucmd->angles[2]);
  1271. return;
  1272. }
  1273. //ZOID
  1274. // set up for pmove
  1275. memset (&pm, 0, sizeof(pm));
  1276. if (ent->movetype == MOVETYPE_NOCLIP)
  1277. client->ps.pmove.pm_type = PM_SPECTATOR;
  1278. else if (ent->s.modelindex != 255)
  1279. client->ps.pmove.pm_type = PM_GIB;
  1280. else if (ent->deadflag)
  1281. client->ps.pmove.pm_type = PM_DEAD;
  1282. else
  1283. client->ps.pmove.pm_type = PM_NORMAL;
  1284. client->ps.pmove.gravity = sv_gravity->value;
  1285. pm.s = client->ps.pmove;
  1286. for (i=0 ; i<3 ; i++)
  1287. {
  1288. pm.s.origin[i] = ent->s.origin[i]*8;
  1289. pm.s.velocity[i] = ent->velocity[i]*8;
  1290. }
  1291. if (memcmp(&client->old_pmove, &pm.s, sizeof(pm.s)))
  1292. {
  1293. pm.snapinitial = true;
  1294. // gi.dprintf ("pmove changed!\n");
  1295. }
  1296. pm.cmd = *ucmd;
  1297. pm.trace = PM_trace; // adds default parms
  1298. pm.pointcontents = gi.pointcontents;
  1299. // perform a pmove
  1300. gi.Pmove (&pm);
  1301. // save results of pmove
  1302. client->ps.pmove = pm.s;
  1303. client->old_pmove = pm.s;
  1304. for (i=0 ; i<3 ; i++)
  1305. {
  1306. ent->s.origin[i] = pm.s.origin[i]*0.125;
  1307. ent->velocity[i] = pm.s.velocity[i]*0.125;
  1308. }
  1309. VectorCopy (pm.mins, ent->mins);
  1310. VectorCopy (pm.maxs, ent->maxs);
  1311. client->resp.cmd_angles[0] = SHORT2ANGLE(ucmd->angles[0]);
  1312. client->resp.cmd_angles[1] = SHORT2ANGLE(ucmd->angles[1]);
  1313. client->resp.cmd_angles[2] = SHORT2ANGLE(ucmd->angles[2]);
  1314. if (ent->groundentity && !pm.groundentity && (pm.cmd.upmove >= 10) && (pm.waterlevel == 0))
  1315. {
  1316. gi.sound(ent, CHAN_VOICE, gi.soundindex("*jump1.wav"), 1, ATTN_NORM, 0);
  1317. PlayerNoise(ent, ent->s.origin, PNOISE_SELF);
  1318. }
  1319. ent->viewheight = pm.viewheight;
  1320. ent->waterlevel = pm.waterlevel;
  1321. ent->watertype = pm.watertype;
  1322. ent->groundentity = pm.groundentity;
  1323. if (pm.groundentity)
  1324. ent->groundentity_linkcount = pm.groundentity->linkcount;
  1325. if (ent->deadflag)
  1326. {
  1327. client->ps.viewangles[ROLL] = 40;
  1328. client->ps.viewangles[PITCH] = -15;
  1329. client->ps.viewangles[YAW] = client->killer_yaw;
  1330. }
  1331. else
  1332. {
  1333. VectorCopy (pm.viewangles, client->v_angle);
  1334. VectorCopy (pm.viewangles, client->ps.viewangles);
  1335. }
  1336. //ZOID
  1337. if (client->ctf_grapple)
  1338. CTFGrapplePull(client->ctf_grapple);
  1339. //ZOID
  1340. gi.linkentity (ent);
  1341. if (ent->movetype != MOVETYPE_NOCLIP)
  1342. G_TouchTriggers (ent);
  1343. // touch other objects
  1344. for (i=0 ; i<pm.numtouch ; i++)
  1345. {
  1346. other = pm.touchents[i];
  1347. for (j=0 ; j<i ; j++)
  1348. if (pm.touchents[j] == other)
  1349. break;
  1350. if (j != i)
  1351. continue; // duplicated
  1352. if (!other->touch)
  1353. continue;
  1354. other->touch (other, ent, NULL, NULL);
  1355. }
  1356. client->oldbuttons = client->buttons;
  1357. client->buttons = ucmd->buttons;
  1358. client->latched_buttons |= client->buttons & ~client->oldbuttons;
  1359. // save light level the player is standing on for
  1360. // monster sighting AI
  1361. ent->light_level = ucmd->lightlevel;
  1362. // fire weapon from final position if needed
  1363. if (client->latched_buttons & BUTTON_ATTACK
  1364. //ZOID
  1365. && ent->movetype != MOVETYPE_NOCLIP
  1366. //ZOID
  1367. )
  1368. {
  1369. if (!client->weapon_thunk)
  1370. {
  1371. client->weapon_thunk = true;
  1372. Think_Weapon (ent);
  1373. }
  1374. }
  1375. //ZOID
  1376. //regen tech
  1377. CTFApplyRegeneration(ent);
  1378. //ZOID
  1379. //ZOID
  1380. for (i = 1; i <= maxclients->value; i++) {
  1381. other = g_edicts + i;
  1382. if (other->inuse && other->client->chase_target == ent)
  1383. UpdateChaseCam(other);
  1384. }
  1385. if (client->menudirty && client->menutime <= level.time) {
  1386. PMenu_Do_Update(ent);
  1387. gi.unicast (ent, true);
  1388. client->menutime = level.time;
  1389. client->menudirty = false;
  1390. }
  1391. //ZOID
  1392. }
  1393. /*
  1394. ==============
  1395. ClientBeginServerFrame
  1396. This will be called once for each server frame, before running
  1397. any other entities in the world.
  1398. ==============
  1399. */
  1400. void ClientBeginServerFrame (edict_t *ent)
  1401. {
  1402. gclient_t *client;
  1403. int buttonMask;
  1404. if (level.intermissiontime)
  1405. return;
  1406. client = ent->client;
  1407. // run weapon animations if it hasn't been done by a ucmd_t
  1408. if (!client->weapon_thunk
  1409. //ZOID
  1410. && ent->movetype != MOVETYPE_NOCLIP
  1411. //ZOID
  1412. )
  1413. Think_Weapon (ent);
  1414. else
  1415. client->weapon_thunk = false;
  1416. if (ent->deadflag)
  1417. {
  1418. // wait for any button just going down
  1419. if ( level.time > client->respawn_time)
  1420. {
  1421. // in deathmatch, only wait for attack button
  1422. if (deathmatch->value)
  1423. buttonMask = BUTTON_ATTACK;
  1424. else
  1425. buttonMask = -1;
  1426. if ( ( client->latched_buttons & buttonMask ) ||
  1427. (deathmatch->value && ((int)dmflags->value & DF_FORCE_RESPAWN) ) ||
  1428. CTFMatchOn())
  1429. {
  1430. respawn(ent);
  1431. client->latched_buttons = 0;
  1432. }
  1433. }
  1434. return;
  1435. }
  1436. // add player trail so monsters can follow
  1437. if (!deathmatch->value)
  1438. if (!visible (ent, PlayerTrail_LastSpot() ) )
  1439. PlayerTrail_Add (ent->s.old_origin);
  1440. client->latched_buttons = 0;
  1441. }