1070 lines · 25.4 KB · C
RawDownload
#include <u.h>#include <libc.h>#include <stdio.h>#include "../dat.h"#include "../fns.h"#include "m_player.h"  static	edict_t		*current_player;static	gclient_t	*current_client; static	vec3_t	forward, right, up;float	xyspeed; float	bobmove;int		bobcycle;		// odd cycles are right foot going forwardfloat	bobfracsin;		// sin(bobfrac*M_PI) /*===============SV_CalcRoll ===============*/float SV_CalcRoll (vec3_t /*angles*/, vec3_t velocity){	float	sign;	float	side;	float	value;		side = DotProduct (velocity, right);	sign = side < 0 ? -1 : 1;	side = fabs(side);		value = sv_rollangle->value; 	if (side < sv_rollspeed->value)		side = side * value / sv_rollspeed->value;	else		side = value;		return side*sign;	}  /*===============P_DamageFeedback Handles color blends and view kicks===============*/void P_DamageFeedback (edict_t *player){	gclient_t	*client;	float	side;	float	realcount, count, kick;	vec3_t	v;	int		r, l;	static	vec3_t	power_color = {0.0, 1.0, 0.0};	static	vec3_t	acolor = {1.0, 1.0, 1.0};	static	vec3_t	bcolor = {1.0, 0.0, 0.0}; 	client = player->client; 	// flash the backgrounds behind the status numbers	client->ps.stats[STAT_FLASHES] = 0;	if (client->damage_blood)		client->ps.stats[STAT_FLASHES] |= 1;	if (client->damage_armor && !(player->flags & FL_GODMODE) && (client->invincible_framenum <= level.framenum))		client->ps.stats[STAT_FLASHES] |= 2; 	// total points of damage shot at the player this frame	count = (client->damage_blood + client->damage_armor + client->damage_parmor);	if (count == 0)		return;		// didn't take any damage 	// start a pain animation if still in the player model	if (client->anim_priority < ANIM_PAIN && player->s.modelindex == 255)	{		static int		i; 		client->anim_priority = ANIM_PAIN;		if (client->ps.pmove.pm_flags & PMF_DUCKED)		{			player->s.frame = FRAME_crpain1-1;			client->anim_end = FRAME_crpain4;		}		else		{			i = (i+1)%3;			switch (i)			{			case 0:				player->s.frame = FRAME_pain101-1;				client->anim_end = FRAME_pain104;				break;			case 1:				player->s.frame = FRAME_pain201-1;				client->anim_end = FRAME_pain204;				break;			case 2:				player->s.frame = FRAME_pain301-1;				client->anim_end = FRAME_pain304;				break;			}		}	} 	realcount = count;	if (count < 10)		count = 10;	// always make a visible effect 	// play an apropriate pain sound	if ((level.time > player->pain_debounce_time) && !(player->flags & FL_GODMODE) && (client->invincible_framenum <= level.framenum))	{		r = 1 + (rand()&1);		player->pain_debounce_time = level.time + 0.7;		if (player->health < 25)			l = 25;		else if (player->health < 50)			l = 50;		else if (player->health < 75)			l = 75;		else			l = 100;		gi.sound (player, CHAN_VOICE, gi.soundindex(va("*pain%i_%i.wav", l, r)), 1, ATTN_NORM, 0);	} 	// the total alpha of the blend is always proportional to count	if (client->damage_alpha < 0)		client->damage_alpha = 0;	client->damage_alpha += count*0.01;	if (client->damage_alpha < 0.2)		client->damage_alpha = 0.2;	if (client->damage_alpha > 0.6)		client->damage_alpha = 0.6;		// don't go too saturated 	// the color of the blend will vary based on how much was absorbed	// by different armors	VectorClear (v);	if (client->damage_parmor)		VectorMA (v, (float)client->damage_parmor/realcount, power_color, v);	if (client->damage_armor)		VectorMA (v, (float)client->damage_armor/realcount,  acolor, v);	if (client->damage_blood)		VectorMA (v, (float)client->damage_blood/realcount,  bcolor, v);	VectorCopy (v, client->damage_blend);  	//	// calculate view angle kicks	//	kick = abs(client->damage_knockback);	if (kick && player->health > 0)	// kick of 0 means no view adjust at all	{		kick = kick * 100 / player->health; 		if (kick < count*0.5)			kick = count*0.5;		if (kick > 50)			kick = 50; 		VectorSubtract (client->damage_from, player->s.origin, v);		VectorNormalize (v);				side = DotProduct (v, right);		client->v_dmg_roll = kick*side*0.3;				side = -DotProduct (v, forward);		client->v_dmg_pitch = kick*side*0.3; 		client->v_dmg_time = level.time + DAMAGE_TIME;	} 	//	// clear totals	//	client->damage_blood = 0;	client->damage_armor = 0;	client->damage_parmor = 0;	client->damage_knockback = 0;}    /*===============SV_CalcViewOffset Auto pitching on slopes?   fall from 128: 400 = 160000  fall from 256: 580 = 336400  fall from 384: 720 = 518400  fall from 512: 800 = 640000  fall from 640: 960 =    damage = deltavelocity*deltavelocity  * 0.0001 ===============*/void SV_CalcViewOffset (edict_t *ent){	float		*angles;	float		bob;	float		ratio;	float		delta;	vec3_t		v;  //=================================== 	// base angles	angles = ent->client->ps.kick_angles; 	// if dead, fix the angle and don't add any kick	if (ent->deadflag)	{		VectorClear (angles); 		ent->client->ps.viewangles[ROLL] = 40;		ent->client->ps.viewangles[PITCH] = -15;		ent->client->ps.viewangles[YAW] = ent->client->killer_yaw;	}	else	{		// add angles based on weapon kick 		VectorCopy (ent->client->kick_angles, angles); 		// add angles based on damage kick 		ratio = (ent->client->v_dmg_time - level.time) / DAMAGE_TIME;		if (ratio < 0)		{			ratio = 0;			ent->client->v_dmg_pitch = 0;			ent->client->v_dmg_roll = 0;		}		angles[PITCH] += ratio * ent->client->v_dmg_pitch;		angles[ROLL] += ratio * ent->client->v_dmg_roll; 		// add pitch based on fall kick 		ratio = (ent->client->fall_time - level.time) / FALL_TIME;		if (ratio < 0)			ratio = 0;		angles[PITCH] += ratio * ent->client->fall_value; 		// add angles based on velocity 		delta = DotProduct (ent->velocity, forward);		angles[PITCH] += delta*run_pitch->value;				delta = DotProduct (ent->velocity, right);		angles[ROLL] += delta*run_roll->value; 		// add angles based on bob 		delta = bobfracsin * bob_pitch->value * xyspeed;		if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)			delta *= 6;		// crouching		angles[PITCH] += delta;		delta = bobfracsin * bob_roll->value * xyspeed;		if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)			delta *= 6;		// crouching		if (bobcycle & 1)			delta = -delta;		angles[ROLL] += delta;	} //=================================== 	// base origin 	VectorClear (v); 	// add view height 	v[2] += ent->viewheight; 	// add fall height 	ratio = (ent->client->fall_time - level.time) / FALL_TIME;	if (ratio < 0)		ratio = 0;	v[2] -= ratio * ent->client->fall_value * 0.4; 	// add bob height 	bob = bobfracsin * xyspeed * bob_up->value;	if (bob > 6)		bob = 6;	//gi.DebugGraph (bob *2, 255);	v[2] += bob; 	// add kick offset 	VectorAdd (v, ent->client->kick_origin, v); 	// absolutely bound offsets	// so the view can never be outside the player box 	if (v[0] < -14)		v[0] = -14;	else if (v[0] > 14)		v[0] = 14;	if (v[1] < -14)		v[1] = -14;	else if (v[1] > 14)		v[1] = 14;	if (v[2] < -22)		v[2] = -22;	else if (v[2] > 30)		v[2] = 30; 	VectorCopy (v, ent->client->ps.viewoffset);} /*==============SV_CalcGunOffset==============*/void SV_CalcGunOffset (edict_t *ent){	int		i;	float	delta; 	// gun angles from bobbing	ent->client->ps.gunangles[ROLL] = xyspeed * bobfracsin * 0.005;	ent->client->ps.gunangles[YAW] = xyspeed * bobfracsin * 0.01;	if (bobcycle & 1)	{		ent->client->ps.gunangles[ROLL] = -ent->client->ps.gunangles[ROLL];		ent->client->ps.gunangles[YAW] = -ent->client->ps.gunangles[YAW];	} 	ent->client->ps.gunangles[PITCH] = xyspeed * bobfracsin * 0.005; 	// gun angles from delta movement	for (i=0 ; i<3 ; i++)	{		delta = ent->client->oldviewangles[i] - ent->client->ps.viewangles[i];		if (delta > 180)			delta -= 360;		if (delta < -180)			delta += 360;		if (delta > 45)			delta = 45;		if (delta < -45)			delta = -45;		if (i == YAW)			ent->client->ps.gunangles[ROLL] += 0.1*delta;		ent->client->ps.gunangles[i] += 0.2 * delta;	} 	// gun height	VectorClear (ent->client->ps.gunoffset);//	ent->ps->gunorigin[2] += bob; 	// gun_x / gun_y / gun_z are development tools	for (i=0 ; i<3 ; i++)	{		ent->client->ps.gunoffset[i] += forward[i]*(gun_y->value);		ent->client->ps.gunoffset[i] += right[i]*gun_x->value;		ent->client->ps.gunoffset[i] += up[i]* (-gun_z->value);	}}  /*=============SV_AddBlend=============*/void SV_AddBlend (float r, float g, float b, float a, float *v_blend){	float	a2, a3; 	if (a <= 0)		return;	a2 = v_blend[3] + (1-v_blend[3])*a;	// new total alpha	a3 = v_blend[3]/a2;		// fraction of color from old 	v_blend[0] = v_blend[0]*a3 + r*(1-a3);	v_blend[1] = v_blend[1]*a3 + g*(1-a3);	v_blend[2] = v_blend[2]*a3 + b*(1-a3);	v_blend[3] = a2;}  /*=============SV_CalcBlend=============*/void SV_CalcBlend (edict_t *ent){	int		contents;	vec3_t	vieworg;	int		remaining; 	ent->client->ps.blend[0] = ent->client->ps.blend[1] = 		ent->client->ps.blend[2] = ent->client->ps.blend[3] = 0; 	// add for contents	VectorAdd (ent->s.origin, ent->client->ps.viewoffset, vieworg);	contents = gi.pointcontents (vieworg);	if (contents & (CONTENTS_LAVA|CONTENTS_SLIME|CONTENTS_WATER) )		ent->client->ps.rdflags |= RDF_UNDERWATER;	else		ent->client->ps.rdflags &= ~RDF_UNDERWATER; 	if (contents & (CONTENTS_SOLID|CONTENTS_LAVA))		SV_AddBlend (1.0, 0.3, 0.0, 0.6, ent->client->ps.blend);	else if (contents & CONTENTS_SLIME)		SV_AddBlend (0.0, 0.1, 0.05, 0.6, ent->client->ps.blend);	else if (contents & CONTENTS_WATER)		SV_AddBlend (0.5, 0.3, 0.2, 0.4, ent->client->ps.blend); 	// add for powerups	if (ent->client->quad_framenum > level.framenum)	{		remaining = ent->client->quad_framenum - level.framenum;		if (remaining == 30)	// beginning to fade			gi.sound(ent, CHAN_ITEM, gi.soundindex("items/damage2.wav"), 1, ATTN_NORM, 0);		if (remaining > 30 || (remaining & 4) )			SV_AddBlend (0, 0, 1, 0.08, ent->client->ps.blend);	}	else if (ent->client->invincible_framenum > level.framenum)	{		remaining = ent->client->invincible_framenum - level.framenum;		if (remaining == 30)	// beginning to fade			gi.sound(ent, CHAN_ITEM, gi.soundindex("items/protect2.wav"), 1, ATTN_NORM, 0);		if (remaining > 30 || (remaining & 4) )			SV_AddBlend (1, 1, 0, 0.08, ent->client->ps.blend);	}	else if (ent->client->enviro_framenum > level.framenum)	{		remaining = ent->client->enviro_framenum - level.framenum;		if (remaining == 30)	// beginning to fade			gi.sound(ent, CHAN_ITEM, gi.soundindex("items/airout.wav"), 1, ATTN_NORM, 0);		if (remaining > 30 || (remaining & 4) )			SV_AddBlend (0, 1, 0, 0.08, ent->client->ps.blend);	}	else if (ent->client->breather_framenum > level.framenum)	{		remaining = ent->client->breather_framenum - level.framenum;		if (remaining == 30)	// beginning to fade			gi.sound(ent, CHAN_ITEM, gi.soundindex("items/airout.wav"), 1, ATTN_NORM, 0);		if (remaining > 30 || (remaining & 4) )			SV_AddBlend (0.4, 1, 0.4, 0.04, ent->client->ps.blend);	} 	// add for damage	if (ent->client->damage_alpha > 0)		SV_AddBlend (ent->client->damage_blend[0],ent->client->damage_blend[1]		,ent->client->damage_blend[2], ent->client->damage_alpha, ent->client->ps.blend); 	if (ent->client->bonus_alpha > 0)		SV_AddBlend (0.85, 0.7, 0.3, ent->client->bonus_alpha, ent->client->ps.blend); 	// drop the damage value	ent->client->damage_alpha -= 0.06;	if (ent->client->damage_alpha < 0)		ent->client->damage_alpha = 0; 	// drop the bonus value	ent->client->bonus_alpha -= 0.1;	if (ent->client->bonus_alpha < 0)		ent->client->bonus_alpha = 0;}  /*=================P_FallingDamage=================*/void P_FallingDamage (edict_t *ent){	float	delta;	int		damage;	vec3_t	dir; 	if (ent->s.modelindex != 255)		return;		// not in the player model 	if (ent->movetype == MOVETYPE_NOCLIP)		return; 	if ((ent->client->oldvelocity[2] < 0) && (ent->velocity[2] > ent->client->oldvelocity[2]) && (!ent->groundentity))	{		delta = ent->client->oldvelocity[2];	}	else

Lines 1–500 of 1070.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t