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