p_view.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179
  1. // Copyright (c) ZeniMax Media Inc.
  2. // Licensed under the GNU General Public License 2.0.
  3. #include "g_local.h"
  4. #include "m_player.h"
  5. static edict_t *current_player;
  6. static gclient_t *current_client;
  7. static vec3_t forward, right, up;
  8. float xyspeed;
  9. float bobmove;
  10. int bobcycle; // odd cycles are right foot going forward
  11. float bobfracsin; // sin(bobfrac*M_PI)
  12. /*
  13. ===============
  14. SV_CalcRoll
  15. ===============
  16. */
  17. float SV_CalcRoll (vec3_t angles, vec3_t velocity)
  18. {
  19. float sign;
  20. float side;
  21. float value;
  22. side = DotProduct (velocity, right);
  23. sign = side < 0 ? -1 : 1;
  24. side = fabs(side);
  25. value = sv_rollangle->value;
  26. if (side < sv_rollspeed->value)
  27. side = side * value / sv_rollspeed->value;
  28. else
  29. side = value;
  30. return side*sign;
  31. }
  32. /*
  33. ===============
  34. P_DamageFeedback
  35. Handles color blends and view kicks
  36. ===============
  37. */
  38. void P_DamageFeedback (edict_t *player)
  39. {
  40. gclient_t *client;
  41. float side;
  42. float realcount, count, kick;
  43. vec3_t v;
  44. int r, l;
  45. static vec3_t power_color = {0.0, 1.0, 0.0};
  46. static vec3_t acolor = {1.0, 1.0, 1.0};
  47. static vec3_t bcolor = {1.0, 0.0, 0.0};
  48. client = player->client;
  49. // flash the backgrounds behind the status numbers
  50. client->ps.stats[STAT_FLASHES] = 0;
  51. if (client->damage_blood)
  52. client->ps.stats[STAT_FLASHES] |= 1;
  53. if (client->damage_armor && !(player->flags & FL_GODMODE) && (client->invincible_framenum <= level.framenum))
  54. client->ps.stats[STAT_FLASHES] |= 2;
  55. // total points of damage shot at the player this frame
  56. count = (client->damage_blood + client->damage_armor + client->damage_parmor);
  57. if (count == 0)
  58. return; // didn't take any damage
  59. // start a pain animation if still in the player model
  60. if (client->anim_priority < ANIM_PAIN && player->s.modelindex == 255)
  61. {
  62. static int i;
  63. client->anim_priority = ANIM_PAIN;
  64. if (client->ps.pmove.pm_flags & PMF_DUCKED)
  65. {
  66. player->s.frame = FRAME_crpain1-1;
  67. client->anim_end = FRAME_crpain4;
  68. }
  69. else
  70. {
  71. i = (i+1)%3;
  72. switch (i)
  73. {
  74. case 0:
  75. player->s.frame = FRAME_pain101-1;
  76. client->anim_end = FRAME_pain104;
  77. break;
  78. case 1:
  79. player->s.frame = FRAME_pain201-1;
  80. client->anim_end = FRAME_pain204;
  81. break;
  82. case 2:
  83. player->s.frame = FRAME_pain301-1;
  84. client->anim_end = FRAME_pain304;
  85. break;
  86. }
  87. }
  88. }
  89. realcount = count;
  90. if (count < 10)
  91. count = 10; // always make a visible effect
  92. // play an apropriate pain sound
  93. if ((level.time > player->pain_debounce_time) && !(player->flags & FL_GODMODE) && (client->invincible_framenum <= level.framenum))
  94. {
  95. r = 1 + (rand()&1);
  96. player->pain_debounce_time = level.time + 0.7;
  97. if (player->health < 25)
  98. l = 25;
  99. else if (player->health < 50)
  100. l = 50;
  101. else if (player->health < 75)
  102. l = 75;
  103. else
  104. l = 100;
  105. gi.sound (player, CHAN_VOICE, gi.soundindex(va("*pain%i_%i.wav", l, r)), 1, ATTN_NORM, 0);
  106. }
  107. // the total alpha of the blend is always proportional to count
  108. if (client->damage_alpha < 0)
  109. client->damage_alpha = 0;
  110. client->damage_alpha += count*0.01;
  111. if (client->damage_alpha < 0.2)
  112. client->damage_alpha = 0.2;
  113. if (client->damage_alpha > 0.6)
  114. client->damage_alpha = 0.6; // don't go too saturated
  115. // the color of the blend will vary based on how much was absorbed
  116. // by different armors
  117. VectorClear (v);
  118. if (client->damage_parmor)
  119. VectorMA (v, (float)client->damage_parmor/realcount, power_color, v);
  120. if (client->damage_armor)
  121. VectorMA (v, (float)client->damage_armor/realcount, acolor, v);
  122. if (client->damage_blood)
  123. VectorMA (v, (float)client->damage_blood/realcount, bcolor, v);
  124. VectorCopy (v, client->damage_blend);
  125. //
  126. // calculate view angle kicks
  127. //
  128. kick = abs(client->damage_knockback);
  129. if (kick && player->health > 0) // kick of 0 means no view adjust at all
  130. {
  131. kick = kick * 100 / player->health;
  132. if (kick < count*0.5)
  133. kick = count*0.5;
  134. if (kick > 50)
  135. kick = 50;
  136. VectorSubtract (client->damage_from, player->s.origin, v);
  137. VectorNormalize (v);
  138. side = DotProduct (v, right);
  139. client->v_dmg_roll = kick*side*0.3;
  140. side = -DotProduct (v, forward);
  141. client->v_dmg_pitch = kick*side*0.3;
  142. client->v_dmg_time = level.time + DAMAGE_TIME;
  143. }
  144. //
  145. // clear totals
  146. //
  147. client->damage_blood = 0;
  148. client->damage_armor = 0;
  149. client->damage_parmor = 0;
  150. client->damage_knockback = 0;
  151. }
  152. /*
  153. ===============
  154. SV_CalcViewOffset
  155. Auto pitching on slopes?
  156. fall from 128: 400 = 160000
  157. fall from 256: 580 = 336400
  158. fall from 384: 720 = 518400
  159. fall from 512: 800 = 640000
  160. fall from 640: 960 =
  161. damage = deltavelocity*deltavelocity * 0.0001
  162. ===============
  163. */
  164. void SV_CalcViewOffset (edict_t *ent)
  165. {
  166. float *angles;
  167. float bob;
  168. float ratio;
  169. float delta;
  170. vec3_t v;
  171. //===================================
  172. // base angles
  173. angles = ent->client->ps.kick_angles;
  174. // if dead, fix the angle and don't add any kick
  175. if (ent->deadflag)
  176. {
  177. VectorClear (angles);
  178. if(ent->flags & FL_SAM_RAIMI)
  179. {
  180. ent->client->ps.viewangles[ROLL] = 0;
  181. ent->client->ps.viewangles[PITCH] = 0;
  182. }
  183. else
  184. {
  185. ent->client->ps.viewangles[ROLL] = 40;
  186. ent->client->ps.viewangles[PITCH] = -15;
  187. }
  188. ent->client->ps.viewangles[YAW] = ent->client->killer_yaw;
  189. }
  190. else
  191. {
  192. // add angles based on weapon kick
  193. VectorCopy (ent->client->kick_angles, angles);
  194. // add angles based on damage kick
  195. ratio = (ent->client->v_dmg_time - level.time) / DAMAGE_TIME;
  196. if (ratio < 0)
  197. {
  198. ratio = 0;
  199. ent->client->v_dmg_pitch = 0;
  200. ent->client->v_dmg_roll = 0;
  201. }
  202. angles[PITCH] += ratio * ent->client->v_dmg_pitch;
  203. angles[ROLL] += ratio * ent->client->v_dmg_roll;
  204. // add pitch based on fall kick
  205. ratio = (ent->client->fall_time - level.time) / FALL_TIME;
  206. if (ratio < 0)
  207. ratio = 0;
  208. angles[PITCH] += ratio * ent->client->fall_value;
  209. // add angles based on velocity
  210. delta = DotProduct (ent->velocity, forward);
  211. angles[PITCH] += delta*run_pitch->value;
  212. delta = DotProduct (ent->velocity, right);
  213. angles[ROLL] += delta*run_roll->value;
  214. // add angles based on bob
  215. delta = bobfracsin * bob_pitch->value * xyspeed;
  216. if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
  217. delta *= 6; // crouching
  218. angles[PITCH] += delta;
  219. delta = bobfracsin * bob_roll->value * xyspeed;
  220. if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
  221. delta *= 6; // crouching
  222. if (bobcycle & 1)
  223. delta = -delta;
  224. angles[ROLL] += delta;
  225. }
  226. //===================================
  227. // base origin
  228. VectorClear (v);
  229. // add view height
  230. v[2] += ent->viewheight;
  231. // add fall height
  232. ratio = (ent->client->fall_time - level.time) / FALL_TIME;
  233. if (ratio < 0)
  234. ratio = 0;
  235. v[2] -= ratio * ent->client->fall_value * 0.4;
  236. // add bob height
  237. bob = bobfracsin * xyspeed * bob_up->value;
  238. if (bob > 6)
  239. bob = 6;
  240. //gi.DebugGraph (bob *2, 255);
  241. v[2] += bob;
  242. // add kick offset
  243. VectorAdd (v, ent->client->kick_origin, v);
  244. // absolutely bound offsets
  245. // so the view can never be outside the player box
  246. if (v[0] < -14)
  247. v[0] = -14;
  248. else if (v[0] > 14)
  249. v[0] = 14;
  250. if (v[1] < -14)
  251. v[1] = -14;
  252. else if (v[1] > 14)
  253. v[1] = 14;
  254. if (v[2] < -22)
  255. v[2] = -22;
  256. else if (v[2] > 30)
  257. v[2] = 30;
  258. VectorCopy (v, ent->client->ps.viewoffset);
  259. }
  260. /*
  261. ==============
  262. SV_CalcGunOffset
  263. ==============
  264. */
  265. void SV_CalcGunOffset (edict_t *ent)
  266. {
  267. int i;
  268. float delta;
  269. //ROGUE
  270. static gitem_t *heatbeam;
  271. if (!heatbeam)
  272. heatbeam = FindItemByClassname ("weapon_plasmabeam");
  273. //ROGUE - heatbeam shouldn't bob so the beam looks right
  274. if (ent->client->pers.weapon != heatbeam)
  275. {
  276. // ROGUE
  277. // gun angles from bobbing
  278. ent->client->ps.gunangles[ROLL] = xyspeed * bobfracsin * 0.005;
  279. ent->client->ps.gunangles[YAW] = xyspeed * bobfracsin * 0.01;
  280. if (bobcycle & 1)
  281. {
  282. ent->client->ps.gunangles[ROLL] = -ent->client->ps.gunangles[ROLL];
  283. ent->client->ps.gunangles[YAW] = -ent->client->ps.gunangles[YAW];
  284. }
  285. ent->client->ps.gunangles[PITCH] = xyspeed * bobfracsin * 0.005;
  286. // gun angles from delta movement
  287. for (i=0 ; i<3 ; i++)
  288. {
  289. delta = ent->client->oldviewangles[i] - ent->client->ps.viewangles[i];
  290. if (delta > 180)
  291. delta -= 360;
  292. if (delta < -180)
  293. delta += 360;
  294. if (delta > 45)
  295. delta = 45;
  296. if (delta < -45)
  297. delta = -45;
  298. if (i == YAW)
  299. ent->client->ps.gunangles[ROLL] += 0.1*delta;
  300. ent->client->ps.gunangles[i] += 0.2 * delta;
  301. }
  302. }
  303. // ROGUE
  304. else
  305. {
  306. for (i=0; i<3; i++)
  307. ent->client->ps.gunangles[i] = 0;
  308. }
  309. //ROGUE
  310. // gun height
  311. VectorClear (ent->client->ps.gunoffset);
  312. // ent->ps->gunorigin[2] += bob;
  313. // gun_x / gun_y / gun_z are development tools
  314. for (i=0 ; i<3 ; i++)
  315. {
  316. ent->client->ps.gunoffset[i] += forward[i]*(gun_y->value);
  317. ent->client->ps.gunoffset[i] += right[i]*gun_x->value;
  318. ent->client->ps.gunoffset[i] += up[i]* (-gun_z->value);
  319. }
  320. }
  321. /*
  322. =============
  323. SV_AddBlend
  324. =============
  325. */
  326. void SV_AddBlend (float r, float g, float b, float a, float *v_blend)
  327. {
  328. float a2, a3;
  329. if (a <= 0)
  330. return;
  331. a2 = v_blend[3] + (1-v_blend[3])*a; // new total alpha
  332. a3 = v_blend[3]/a2; // fraction of color from old
  333. v_blend[0] = v_blend[0]*a3 + r*(1-a3);
  334. v_blend[1] = v_blend[1]*a3 + g*(1-a3);
  335. v_blend[2] = v_blend[2]*a3 + b*(1-a3);
  336. v_blend[3] = a2;
  337. }
  338. /*
  339. =============
  340. SV_CalcBlend
  341. =============
  342. */
  343. void SV_CalcBlend (edict_t *ent)
  344. {
  345. int contents;
  346. vec3_t vieworg;
  347. int remaining;
  348. ent->client->ps.blend[0] = ent->client->ps.blend[1] =
  349. ent->client->ps.blend[2] = ent->client->ps.blend[3] = 0;
  350. // add for contents
  351. VectorAdd (ent->s.origin, ent->client->ps.viewoffset, vieworg);
  352. contents = gi.pointcontents (vieworg);
  353. if (contents & (CONTENTS_LAVA|CONTENTS_SLIME|CONTENTS_WATER) )
  354. ent->client->ps.rdflags |= RDF_UNDERWATER;
  355. else
  356. ent->client->ps.rdflags &= ~RDF_UNDERWATER;
  357. if (contents & (CONTENTS_SOLID|CONTENTS_LAVA))
  358. SV_AddBlend (1.0, 0.3, 0.0, 0.6, ent->client->ps.blend);
  359. else if (contents & CONTENTS_SLIME)
  360. SV_AddBlend (0.0, 0.1, 0.05, 0.6, ent->client->ps.blend);
  361. else if (contents & CONTENTS_WATER)
  362. SV_AddBlend (0.5, 0.3, 0.2, 0.4, ent->client->ps.blend);
  363. // add for powerups
  364. if (ent->client->quad_framenum > level.framenum)
  365. {
  366. remaining = ent->client->quad_framenum - level.framenum;
  367. if (remaining == 30) // beginning to fade
  368. gi.sound(ent, CHAN_ITEM, gi.soundindex("items/damage2.wav"), 1, ATTN_NORM, 0);
  369. if (remaining > 30 || (remaining & 4) )
  370. SV_AddBlend (0, 0, 1, 0.08, ent->client->ps.blend);
  371. }
  372. // PMM - double damage
  373. else if (ent->client->double_framenum > level.framenum)
  374. {
  375. remaining = ent->client->double_framenum - level.framenum;
  376. if (remaining == 30) // beginning to fade
  377. gi.sound(ent, CHAN_ITEM, gi.soundindex("misc/ddamage2.wav"), 1, ATTN_NORM, 0);
  378. if (remaining > 30 || (remaining & 4) )
  379. SV_AddBlend (0.9, 0.7, 0, 0.08, ent->client->ps.blend);
  380. }
  381. // PMM
  382. else if (ent->client->invincible_framenum > level.framenum)
  383. {
  384. remaining = ent->client->invincible_framenum - level.framenum;
  385. if (remaining == 30) // beginning to fade
  386. gi.sound(ent, CHAN_ITEM, gi.soundindex("items/protect2.wav"), 1, ATTN_NORM, 0);
  387. if (remaining > 30 || (remaining & 4) )
  388. SV_AddBlend (1, 1, 0, 0.08, ent->client->ps.blend);
  389. }
  390. else if (ent->client->enviro_framenum > level.framenum)
  391. {
  392. remaining = ent->client->enviro_framenum - level.framenum;
  393. if (remaining == 30) // beginning to fade
  394. gi.sound(ent, CHAN_ITEM, gi.soundindex("items/airout.wav"), 1, ATTN_NORM, 0);
  395. if (remaining > 30 || (remaining & 4) )
  396. SV_AddBlend (0, 1, 0, 0.08, ent->client->ps.blend);
  397. }
  398. else if (ent->client->breather_framenum > level.framenum)
  399. {
  400. remaining = ent->client->breather_framenum - level.framenum;
  401. if (remaining == 30) // beginning to fade
  402. gi.sound(ent, CHAN_ITEM, gi.soundindex("items/airout.wav"), 1, ATTN_NORM, 0);
  403. if (remaining > 30 || (remaining & 4) )
  404. SV_AddBlend (0.4, 1, 0.4, 0.04, ent->client->ps.blend);
  405. }
  406. //PGM
  407. if(ent->client->nuke_framenum > level.framenum)
  408. {
  409. float brightness;
  410. brightness = (ent->client->nuke_framenum - level.framenum) / 20.0;
  411. SV_AddBlend (1, 1, 1, brightness, ent->client->ps.blend);
  412. }
  413. if (ent->client->ir_framenum > level.framenum)
  414. {
  415. remaining = ent->client->ir_framenum - level.framenum;
  416. if(remaining > 30 || (remaining & 4))
  417. {
  418. ent->client->ps.rdflags |= RDF_IRGOGGLES;
  419. SV_AddBlend (1, 0, 0, 0.2, ent->client->ps.blend);
  420. }
  421. else
  422. ent->client->ps.rdflags &= ~RDF_IRGOGGLES;
  423. }
  424. else
  425. {
  426. ent->client->ps.rdflags &= ~RDF_IRGOGGLES;
  427. }
  428. //PGM
  429. // add for damage
  430. if (ent->client->damage_alpha > 0)
  431. SV_AddBlend (ent->client->damage_blend[0],ent->client->damage_blend[1]
  432. ,ent->client->damage_blend[2], ent->client->damage_alpha, ent->client->ps.blend);
  433. if (ent->client->bonus_alpha > 0)
  434. SV_AddBlend (0.85, 0.7, 0.3, ent->client->bonus_alpha, ent->client->ps.blend);
  435. // drop the damage value
  436. ent->client->damage_alpha -= 0.06;
  437. if (ent->client->damage_alpha < 0)
  438. ent->client->damage_alpha = 0;
  439. // drop the bonus value
  440. ent->client->bonus_alpha -= 0.1;
  441. if (ent->client->bonus_alpha < 0)
  442. ent->client->bonus_alpha = 0;
  443. }
  444. /*
  445. =================
  446. P_FallingDamage
  447. =================
  448. */
  449. void P_FallingDamage (edict_t *ent)
  450. {
  451. float delta;
  452. int damage;
  453. vec3_t dir;
  454. if (ent->s.modelindex != 255)
  455. return; // not in the player model
  456. if (ent->movetype == MOVETYPE_NOCLIP)
  457. return;
  458. if ((ent->client->oldvelocity[2] < 0) && (ent->velocity[2] > ent->client->oldvelocity[2]) && (!ent->groundentity))
  459. {
  460. delta = ent->client->oldvelocity[2];
  461. }
  462. else
  463. {
  464. if (!ent->groundentity)
  465. return;
  466. delta = ent->velocity[2] - ent->client->oldvelocity[2];
  467. }
  468. delta = delta*delta * 0.0001;
  469. // never take falling damage if completely underwater
  470. if (ent->waterlevel == 3)
  471. return;
  472. if (ent->waterlevel == 2)
  473. delta *= 0.25;
  474. if (ent->waterlevel == 1)
  475. delta *= 0.5;
  476. if (delta < 1)
  477. return;
  478. if (delta < 15)
  479. {
  480. ent->s.event = EV_FOOTSTEP;
  481. return;
  482. }
  483. ent->client->fall_value = delta*0.5;
  484. if (ent->client->fall_value > 40)
  485. ent->client->fall_value = 40;
  486. ent->client->fall_time = level.time + FALL_TIME;
  487. if (delta > 30)
  488. {
  489. if (ent->health > 0)
  490. {
  491. if (delta >= 55)
  492. ent->s.event = EV_FALLFAR;
  493. else
  494. ent->s.event = EV_FALL;
  495. }
  496. ent->pain_debounce_time = level.time; // no normal pain sound
  497. damage = (delta-30)/2;
  498. if (damage < 1)
  499. damage = 1;
  500. VectorSet (dir, 0, 0, 1);
  501. if (!deathmatch->value || !((int)dmflags->value & DF_NO_FALLING) )
  502. T_Damage (ent, world, world, dir, ent->s.origin, vec3_origin, damage, 0, 0, MOD_FALLING);
  503. }
  504. else
  505. {
  506. ent->s.event = EV_FALLSHORT;
  507. return;
  508. }
  509. }
  510. /*
  511. =============
  512. P_WorldEffects
  513. =============
  514. */
  515. void P_WorldEffects (void)
  516. {
  517. qboolean breather;
  518. qboolean envirosuit;
  519. int waterlevel, old_waterlevel;
  520. if (current_player->movetype == MOVETYPE_NOCLIP)
  521. {
  522. current_player->air_finished = level.time + 12; // don't need air
  523. return;
  524. }
  525. waterlevel = current_player->waterlevel;
  526. old_waterlevel = current_client->old_waterlevel;
  527. current_client->old_waterlevel = waterlevel;
  528. breather = current_client->breather_framenum > level.framenum;
  529. envirosuit = current_client->enviro_framenum > level.framenum;
  530. //
  531. // if just entered a water volume, play a sound
  532. //
  533. if (!old_waterlevel && waterlevel)
  534. {
  535. PlayerNoise(current_player, current_player->s.origin, PNOISE_SELF);
  536. if (current_player->watertype & CONTENTS_LAVA)
  537. gi.sound (current_player, CHAN_BODY, gi.soundindex("player/lava_in.wav"), 1, ATTN_NORM, 0);
  538. else if (current_player->watertype & CONTENTS_SLIME)
  539. gi.sound (current_player, CHAN_BODY, gi.soundindex("player/watr_in.wav"), 1, ATTN_NORM, 0);
  540. else if (current_player->watertype & CONTENTS_WATER)
  541. gi.sound (current_player, CHAN_BODY, gi.soundindex("player/watr_in.wav"), 1, ATTN_NORM, 0);
  542. current_player->flags |= FL_INWATER;
  543. // clear damage_debounce, so the pain sound will play immediately
  544. current_player->damage_debounce_time = level.time - 1;
  545. }
  546. //
  547. // if just completely exited a water volume, play a sound
  548. //
  549. if (old_waterlevel && ! waterlevel)
  550. {
  551. PlayerNoise(current_player, current_player->s.origin, PNOISE_SELF);
  552. gi.sound (current_player, CHAN_BODY, gi.soundindex("player/watr_out.wav"), 1, ATTN_NORM, 0);
  553. current_player->flags &= ~FL_INWATER;
  554. }
  555. //
  556. // check for head just going under water
  557. //
  558. if (old_waterlevel != 3 && waterlevel == 3)
  559. {
  560. gi.sound (current_player, CHAN_BODY, gi.soundindex("player/watr_un.wav"), 1, ATTN_NORM, 0);
  561. }
  562. //
  563. // check for head just coming out of water
  564. //
  565. if (old_waterlevel == 3 && waterlevel != 3)
  566. {
  567. if (current_player->air_finished < level.time)
  568. { // gasp for air
  569. gi.sound (current_player, CHAN_VOICE, gi.soundindex("player/gasp1.wav"), 1, ATTN_NORM, 0);
  570. PlayerNoise(current_player, current_player->s.origin, PNOISE_SELF);
  571. }
  572. else if (current_player->air_finished < level.time + 11)
  573. { // just break surface
  574. gi.sound (current_player, CHAN_VOICE, gi.soundindex("player/gasp2.wav"), 1, ATTN_NORM, 0);
  575. }
  576. }
  577. //
  578. // check for drowning
  579. //
  580. if (waterlevel == 3)
  581. {
  582. // breather or envirosuit give air
  583. if (breather || envirosuit)
  584. {
  585. current_player->air_finished = level.time + 10;
  586. if (((int)(current_client->breather_framenum - level.framenum) % 25) == 0)
  587. {
  588. if (!current_client->breather_sound)
  589. gi.sound (current_player, CHAN_AUTO, gi.soundindex("player/u_breath1.wav"), 1, ATTN_NORM, 0);
  590. else
  591. gi.sound (current_player, CHAN_AUTO, gi.soundindex("player/u_breath2.wav"), 1, ATTN_NORM, 0);
  592. current_client->breather_sound ^= 1;
  593. PlayerNoise(current_player, current_player->s.origin, PNOISE_SELF);
  594. //FIXME: release a bubble?
  595. }
  596. }
  597. // if out of air, start drowning
  598. if (current_player->air_finished < level.time)
  599. { // drown!
  600. if (current_player->client->next_drown_time < level.time
  601. && current_player->health > 0)
  602. {
  603. current_player->client->next_drown_time = level.time + 1;
  604. // take more damage the longer underwater
  605. current_player->dmg += 2;
  606. if (current_player->dmg > 15)
  607. current_player->dmg = 15;
  608. // play a gurp sound instead of a normal pain sound
  609. if (current_player->health <= current_player->dmg)
  610. gi.sound (current_player, CHAN_VOICE, gi.soundindex("player/drown1.wav"), 1, ATTN_NORM, 0);
  611. else if (rand()&1)
  612. gi.sound (current_player, CHAN_VOICE, gi.soundindex("*gurp1.wav"), 1, ATTN_NORM, 0);
  613. else
  614. gi.sound (current_player, CHAN_VOICE, gi.soundindex("*gurp2.wav"), 1, ATTN_NORM, 0);
  615. current_player->pain_debounce_time = level.time;
  616. T_Damage (current_player, world, world, vec3_origin, current_player->s.origin, vec3_origin, current_player->dmg, 0, DAMAGE_NO_ARMOR, MOD_WATER);
  617. }
  618. }
  619. }
  620. else
  621. {
  622. current_player->air_finished = level.time + 12;
  623. current_player->dmg = 2;
  624. }
  625. //
  626. // check for sizzle damage
  627. //
  628. if (waterlevel && (current_player->watertype&(CONTENTS_LAVA|CONTENTS_SLIME)) )
  629. {
  630. if (current_player->watertype & CONTENTS_LAVA)
  631. {
  632. if (current_player->health > 0
  633. && current_player->pain_debounce_time <= level.time
  634. && current_client->invincible_framenum < level.framenum)
  635. {
  636. if (rand()&1)
  637. gi.sound (current_player, CHAN_VOICE, gi.soundindex("player/burn1.wav"), 1, ATTN_NORM, 0);
  638. else
  639. gi.sound (current_player, CHAN_VOICE, gi.soundindex("player/burn2.wav"), 1, ATTN_NORM, 0);
  640. current_player->pain_debounce_time = level.time + 1;
  641. }
  642. if (envirosuit) // take 1/3 damage with envirosuit
  643. T_Damage (current_player, world, world, vec3_origin, current_player->s.origin, vec3_origin, 1*waterlevel, 0, 0, MOD_LAVA);
  644. else
  645. T_Damage (current_player, world, world, vec3_origin, current_player->s.origin, vec3_origin, 3*waterlevel, 0, 0, MOD_LAVA);
  646. }
  647. if (current_player->watertype & CONTENTS_SLIME)
  648. {
  649. if (!envirosuit)
  650. { // no damage from slime with envirosuit
  651. T_Damage (current_player, world, world, vec3_origin, current_player->s.origin, vec3_origin, 1*waterlevel, 0, 0, MOD_SLIME);
  652. }
  653. }
  654. }
  655. }
  656. /*
  657. ===============
  658. G_SetClientEffects
  659. ===============
  660. */
  661. void G_SetClientEffects (edict_t *ent)
  662. {
  663. int pa_type;
  664. int remaining;
  665. ent->s.effects = 0;
  666. // ent->s.renderfx = 0;
  667. // PGM - player is always ir visible, even dead.
  668. ent->s.renderfx = RF_IR_VISIBLE;
  669. if (ent->health <= 0 || level.intermissiontime)
  670. return;
  671. //=========
  672. //PGM
  673. if(ent->flags & FL_DISGUISED)
  674. ent->s.renderfx |= RF_USE_DISGUISE;
  675. if (gamerules && gamerules->value)
  676. {
  677. if(DMGame.PlayerEffects)
  678. DMGame.PlayerEffects(ent);
  679. }
  680. //PGM
  681. //=========
  682. if (ent->powerarmor_time > level.time)
  683. {
  684. pa_type = PowerArmorType (ent);
  685. if (pa_type == POWER_ARMOR_SCREEN)
  686. {
  687. ent->s.effects |= EF_POWERSCREEN;
  688. }
  689. else if (pa_type == POWER_ARMOR_SHIELD)
  690. {
  691. ent->s.effects |= EF_COLOR_SHELL;
  692. ent->s.renderfx |= RF_SHELL_GREEN;
  693. }
  694. }
  695. if (ent->client->quad_framenum > level.framenum)
  696. {
  697. remaining = ent->client->quad_framenum - level.framenum;
  698. if (remaining > 30 || (remaining & 4) )
  699. ent->s.effects |= EF_QUAD;
  700. }
  701. //=======
  702. //ROGUE
  703. if (ent->client->double_framenum > level.framenum)
  704. {
  705. remaining = ent->client->double_framenum - level.framenum;
  706. if (remaining > 30 || (remaining & 4) )
  707. ent->s.effects |= EF_DOUBLE;
  708. }
  709. if ((ent->client->owned_sphere) && (ent->client->owned_sphere->spawnflags == 1))
  710. {
  711. ent->s.effects |= EF_HALF_DAMAGE;
  712. }
  713. if (ent->client->tracker_pain_framenum > level.framenum)
  714. {
  715. ent->s.effects |= EF_TRACKERTRAIL;
  716. }
  717. //ROGUE
  718. //=======
  719. if (ent->client->invincible_framenum > level.framenum)
  720. {
  721. remaining = ent->client->invincible_framenum - level.framenum;
  722. if (remaining > 30 || (remaining & 4) )
  723. ent->s.effects |= EF_PENT;
  724. }
  725. // show cheaters!!!
  726. if (ent->flags & FL_GODMODE)
  727. {
  728. ent->s.effects |= EF_COLOR_SHELL;
  729. ent->s.renderfx |= (RF_SHELL_RED|RF_SHELL_GREEN|RF_SHELL_BLUE);
  730. }
  731. //PGM
  732. /*
  733. if (ent->client->torch_framenum > level.framenum)
  734. {
  735. gi.WriteByte (svc_temp_entity);
  736. gi.WriteByte (TE_FLASHLIGHT);
  737. gi.WritePosition (ent->s.origin);
  738. gi.WriteShort (ent - g_edicts);
  739. gi.multicast (ent->s.origin, MULTICAST_PVS);
  740. }
  741. */
  742. //PGM
  743. }
  744. /*
  745. ===============
  746. G_SetClientEvent
  747. ===============
  748. */
  749. void G_SetClientEvent (edict_t *ent)
  750. {
  751. if (ent->s.event)
  752. return;
  753. if ( ent->groundentity && xyspeed > 225)
  754. {
  755. if ( (int)(current_client->bobtime+bobmove) != bobcycle )
  756. ent->s.event = EV_FOOTSTEP;
  757. }
  758. }
  759. /*
  760. ===============
  761. G_SetClientSound
  762. ===============
  763. */
  764. void G_SetClientSound (edict_t *ent)
  765. {
  766. char *weap;
  767. if (ent->client->pers.game_helpchanged != game.helpchanged)
  768. {
  769. ent->client->pers.game_helpchanged = game.helpchanged;
  770. ent->client->pers.helpchanged = 1;
  771. }
  772. // help beep (no more than three times)
  773. if (ent->client->pers.helpchanged && ent->client->pers.helpchanged <= 3 && !(level.framenum&63) )
  774. {
  775. ent->client->pers.helpchanged++;
  776. gi.sound (ent, CHAN_VOICE, gi.soundindex ("misc/pc_up.wav"), 1, ATTN_STATIC, 0);
  777. }
  778. if (ent->client->pers.weapon)
  779. weap = ent->client->pers.weapon->classname;
  780. else
  781. weap = "";
  782. if (ent->waterlevel && (ent->watertype&(CONTENTS_LAVA|CONTENTS_SLIME)) )
  783. ent->s.sound = snd_fry;
  784. else if (strcmp(weap, "weapon_railgun") == 0)
  785. ent->s.sound = gi.soundindex("weapons/rg_hum.wav");
  786. else if (strcmp(weap, "weapon_bfg") == 0)
  787. ent->s.sound = gi.soundindex("weapons/bfg_hum.wav");
  788. else if (ent->client->weapon_sound)
  789. ent->s.sound = ent->client->weapon_sound;
  790. else
  791. ent->s.sound = 0;
  792. }
  793. /*
  794. ===============
  795. G_SetClientFrame
  796. ===============
  797. */
  798. void G_SetClientFrame (edict_t *ent)
  799. {
  800. gclient_t *client;
  801. qboolean duck, run;
  802. if (ent->s.modelindex != 255)
  803. return; // not in the player model
  804. client = ent->client;
  805. if (client->ps.pmove.pm_flags & PMF_DUCKED)
  806. duck = true;
  807. else
  808. duck = false;
  809. if (xyspeed)
  810. run = true;
  811. else
  812. run = false;
  813. // check for stand/duck and stop/go transitions
  814. if (duck != client->anim_duck && client->anim_priority < ANIM_DEATH)
  815. goto newanim;
  816. if (run != client->anim_run && client->anim_priority == ANIM_BASIC)
  817. goto newanim;
  818. if (!ent->groundentity && client->anim_priority <= ANIM_WAVE)
  819. goto newanim;
  820. if(client->anim_priority == ANIM_REVERSE)
  821. {
  822. if(ent->s.frame > client->anim_end)
  823. {
  824. ent->s.frame--;
  825. return;
  826. }
  827. }
  828. else if (ent->s.frame < client->anim_end)
  829. { // continue an animation
  830. ent->s.frame++;
  831. return;
  832. }
  833. if (client->anim_priority == ANIM_DEATH)
  834. return; // stay there
  835. if (client->anim_priority == ANIM_JUMP)
  836. {
  837. if (!ent->groundentity)
  838. return; // stay there
  839. ent->client->anim_priority = ANIM_WAVE;
  840. ent->s.frame = FRAME_jump3;
  841. ent->client->anim_end = FRAME_jump6;
  842. return;
  843. }
  844. newanim:
  845. // return to either a running or standing frame
  846. client->anim_priority = ANIM_BASIC;
  847. client->anim_duck = duck;
  848. client->anim_run = run;
  849. if (!ent->groundentity)
  850. {
  851. client->anim_priority = ANIM_JUMP;
  852. if (ent->s.frame != FRAME_jump2)
  853. ent->s.frame = FRAME_jump1;
  854. client->anim_end = FRAME_jump2;
  855. }
  856. else if (run)
  857. { // running
  858. if (duck)
  859. {
  860. ent->s.frame = FRAME_crwalk1;
  861. client->anim_end = FRAME_crwalk6;
  862. }
  863. else
  864. {
  865. ent->s.frame = FRAME_run1;
  866. client->anim_end = FRAME_run6;
  867. }
  868. }
  869. else
  870. { // standing
  871. if (duck)
  872. {
  873. ent->s.frame = FRAME_crstnd01;
  874. client->anim_end = FRAME_crstnd19;
  875. }
  876. else
  877. {
  878. ent->s.frame = FRAME_stand01;
  879. client->anim_end = FRAME_stand40;
  880. }
  881. }
  882. }
  883. /*
  884. =================
  885. ClientEndServerFrame
  886. Called for each player at the end of the server frame
  887. and right after spawning
  888. =================
  889. */
  890. void ClientEndServerFrame (edict_t *ent)
  891. {
  892. float bobtime;
  893. int i;
  894. current_player = ent;
  895. current_client = ent->client;
  896. //
  897. // If the origin or velocity have changed since ClientThink(),
  898. // update the pmove values. This will happen when the client
  899. // is pushed by a bmodel or kicked by an explosion.
  900. //
  901. // If it wasn't updated here, the view position would lag a frame
  902. // behind the body position when pushed -- "sinking into plats"
  903. //
  904. for (i=0 ; i<3 ; i++)
  905. {
  906. current_client->ps.pmove.origin[i] = ent->s.origin[i]*8.0;
  907. current_client->ps.pmove.velocity[i] = ent->velocity[i]*8.0;
  908. }
  909. //
  910. // If the end of unit layout is displayed, don't give
  911. // the player any normal movement attributes
  912. //
  913. if (level.intermissiontime)
  914. {
  915. // FIXME: add view drifting here?
  916. current_client->ps.blend[3] = 0;
  917. current_client->ps.fov = 90;
  918. G_SetStats (ent);
  919. return;
  920. }
  921. AngleVectors (ent->client->v_angle, forward, right, up);
  922. // burn from lava, etc
  923. P_WorldEffects ();
  924. //
  925. // set model angles from view angles so other things in
  926. // the world can tell which direction you are looking
  927. //
  928. if (ent->client->v_angle[PITCH] > 180)
  929. ent->s.angles[PITCH] = (-360 + ent->client->v_angle[PITCH])/3;
  930. else
  931. ent->s.angles[PITCH] = ent->client->v_angle[PITCH]/3;
  932. ent->s.angles[YAW] = ent->client->v_angle[YAW];
  933. ent->s.angles[ROLL] = 0;
  934. ent->s.angles[ROLL] = SV_CalcRoll (ent->s.angles, ent->velocity)*4;
  935. //
  936. // calculate speed and cycle to be used for
  937. // all cyclic walking effects
  938. //
  939. xyspeed = sqrt(ent->velocity[0]*ent->velocity[0] + ent->velocity[1]*ent->velocity[1]);
  940. if (xyspeed < 5)
  941. {
  942. bobmove = 0;
  943. current_client->bobtime = 0; // start at beginning of cycle again
  944. }
  945. else if (ent->groundentity)
  946. { // so bobbing only cycles when on ground
  947. if (xyspeed > 210)
  948. bobmove = 0.25;
  949. else if (xyspeed > 100)
  950. bobmove = 0.125;
  951. else
  952. bobmove = 0.0625;
  953. }
  954. bobtime = (current_client->bobtime += bobmove);
  955. if (current_client->ps.pmove.pm_flags & PMF_DUCKED)
  956. bobtime *= 4;
  957. bobcycle = (int)bobtime;
  958. bobfracsin = fabs(sin(bobtime*M_PI));
  959. // detect hitting the floor
  960. P_FallingDamage (ent);
  961. // apply all the damage taken this frame
  962. P_DamageFeedback (ent);
  963. // determine the view offsets
  964. SV_CalcViewOffset (ent);
  965. // determine the gun offsets
  966. SV_CalcGunOffset (ent);
  967. // determine the full screen color blend
  968. // must be after viewoffset, so eye contents can be
  969. // accurately determined
  970. // FIXME: with client prediction, the contents
  971. // should be determined by the client
  972. SV_CalcBlend (ent);
  973. // chase cam stuff
  974. if (ent->client->resp.spectator)
  975. G_SetSpectatorStats(ent);
  976. else
  977. G_SetStats (ent);
  978. G_CheckChaseStats(ent);
  979. G_SetClientEvent (ent);
  980. G_SetClientEffects (ent);
  981. G_SetClientSound (ent);
  982. G_SetClientFrame (ent);
  983. VectorCopy (ent->velocity, ent->client->oldvelocity);
  984. VectorCopy (ent->client->ps.viewangles, ent->client->oldviewangles);
  985. // clear weapon kicks
  986. VectorClear (ent->client->kick_origin);
  987. VectorClear (ent->client->kick_angles);
  988. // if the scoreboard is up, update it
  989. if (ent->client->showscores && !(level.framenum & 31) )
  990. {
  991. DeathmatchScoreboardMessage (ent, ent->enemy);
  992. gi.unicast (ent, false);
  993. }
  994. }