Fixed spectator follow and free and updated zcam to 1.04 and added the

missing zcam files.
This commit is contained in:
Richard Allen 2002-02-09 00:10:12 +00:00
parent 884994dfaa
commit e619e05d3a
10 changed files with 1603 additions and 14 deletions

View File

@ -48,6 +48,8 @@ GOBJ = \
$(GDIRNAME)/rxn_game.o \
$(GDIRNAME)/g_teamplay.o \
$(GDIRNAME)/g_matchmode.o
# $(GDIRNAME)/zcam.o \
# $(GDIRNAME)/zcam_target.o
CGOBJ = \
$(CGDIRNAME)/cg_main.o \

View File

@ -5,6 +5,10 @@
//-----------------------------------------------------------------------------
//
// $Log$
// Revision 1.27 2002/02/09 00:10:12 jbravo
// Fixed spectator follow and free and updated zcam to 1.04 and added the
// missing zcam files.
//
// Revision 1.26 2002/02/08 05:59:09 niceass
// scoreboard timer thing added
//
@ -821,6 +825,10 @@ void CG_InitConsoleCommands( void ) {
// JBravo: adding choose and drop commands.
trap_AddCommand ("choose");
trap_AddCommand ("drop");
// JBravo: for zcam
#ifdef __ZCAM__
trap_AddCommand ("camera");
#endif
// Slicer: Matchmode
trap_AddCommand ("captain");
trap_AddCommand ("ready");

View File

@ -5,6 +5,10 @@
//-----------------------------------------------------------------------------
//
// $Log$
// Revision 1.48 2002/02/09 00:10:12 jbravo
// Fixed spectator follow and free and updated zcam to 1.04 and added the
// missing zcam files.
//
// Revision 1.47 2002/02/08 18:59:01 slicer
// Spec code changes
//
@ -473,28 +477,34 @@ NiceAss: Heavy modifications will be here for AQ2-like spectator mode and zcam!?
void SpectatorThink( gentity_t *ent, usercmd_t *ucmd ) {
pmove_t pm;
gclient_t *client;
int clientNum;
client = ent->client;
clientNum = client - level.clients;
client->oldbuttons = client->buttons;
client->buttons = ucmd->buttons;
//Slicer - Changing this for aq2 way
// Jump button cycles throught spectators
if(client->sess.spectatorState == SPECTATOR_FOLLOW && ucmd->upmove ) {
if(client->sess.spectatorState == SPECTATOR_FOLLOW && ucmd->upmove >=10 ) {
if (!(client->ps.pm_flags & PMF_JUMP_HELD)) {
client->ps.pm_flags |= PMF_JUMP_HELD;
Cmd_FollowCycle_f( ent, 1 );
ucmd->upmove = 0;
}
} else {
if (ucmd->upmove == 0) {
client->ps.pm_flags &= ~PMF_JUMP_HELD;
}
}
// Attack Button cycles throught free view or follow
if((ucmd->buttons & BUTTON_ATTACK) && !( client->oldbuttons & BUTTON_ATTACK )) {
if (client->sess.spectatorState == SPECTATOR_FREE) {
if (client->sess.spectatorState == SPECTATOR_FREE && OKtoFollow(clientNum)) {
client->sess.spectatorState = SPECTATOR_FOLLOW;
client->ps.pm_flags |= PMF_FOLLOW;
Cmd_FollowCycle_f( ent, 1 );
} else {
client->sess.spectatorState = SPECTATOR_FREE;
client->ps.pm_flags &= ~PMF_FOLLOW;
StopFollowing(ent);
}
}
@ -517,13 +527,16 @@ void SpectatorThink( gentity_t *ent, usercmd_t *ucmd ) {
} */
#ifdef __ZCAM__
if ( client->sess.spectatorState == SPECTATOR_CAMERA_FLIC &&
client->sess.spectatorState == SPECTATOR_CAMERA_SWING )
client->ps.commandTime = ucmd->serverTime;
client->oldbuttons = client->buttons;
client->buttons = ucmd->buttons;
if (client->sess.spectatorState != SPECTATOR_FOLLOW)
{
camera_think(ent);
return;
}
#endif
#else
if ( client->sess.spectatorState != SPECTATOR_FOLLOW ) {
client->ps.pm_type = PM_SPECTATOR;
@ -545,6 +558,7 @@ void SpectatorThink( gentity_t *ent, usercmd_t *ucmd ) {
G_TouchTriggers( ent );
trap_UnlinkEntity( ent );
}
#endif
}

View File

@ -5,6 +5,10 @@
//-----------------------------------------------------------------------------
//
// $Log$
// Revision 1.49 2002/02/09 00:10:12 jbravo
// Fixed spectator follow and free and updated zcam to 1.04 and added the
// missing zcam files.
//
// Revision 1.48 2002/02/05 23:41:27 slicer
// More on matchmode..
//
@ -2722,9 +2726,8 @@ void ClientCommand( int clientNum ) {
else if (Q_stricmp (cmd, "dropitem") == 0)
Cmd_DropItem_f( ent );
#ifdef __ZCAM__
// NiceAss: removed
//else if (Q_stricmp (cmd, "camera") == 0)
// camera_cmd ( ent );
else if (Q_stricmp (cmd, "camera") == 0)
camera_cmd ( ent );
#endif /* __ZCAM__ */
else if (Q_stricmp (cmd, "playerstats") == 0)
{

View File

@ -5,6 +5,10 @@
//-----------------------------------------------------------------------------
//
// $Log$
// Revision 1.8 2002/02/09 00:10:12 jbravo
// Fixed spectator follow and free and updated zcam to 1.04 and added the
// missing zcam files.
//
// Revision 1.7 2002/02/03 21:23:51 slicer
// More Matchmode code and fixed 2 bugs in TP
//
@ -20,6 +24,10 @@
//
#include "g_local.h"
#ifdef __ZCAM__
#include "zcam.h"
#endif /* __ZCAM__ */
/*
=======================================================================
@ -55,6 +63,10 @@ void G_WriteClientSessionData( gclient_t *client ) {
var = va( "session%i", client - level.clients );
trap_Cvar_Set( var, s );
#ifdef __ZCAM__
camera_state_save (client);
#endif /* __ZCAM__ */
}
/*
@ -90,6 +102,10 @@ void G_ReadSessionData( gclient_t *client ) {
client->sess.sessionTeam = (team_t)sessionTeam;
client->sess.spectatorState = (spectatorState_t)spectatorState;
client->sess.teamLeader = (qboolean)teamLeader;
#ifdef __ZCAM__
camera_state_load (client);
#endif /* __ZCAM__ */
}

View File

@ -5,6 +5,10 @@
//-----------------------------------------------------------------------------
//
// $Log$
// Revision 1.13 2002/02/09 00:10:12 jbravo
// Fixed spectator follow and free and updated zcam to 1.04 and added the
// missing zcam files.
//
// Revision 1.12 2002/02/06 03:10:43 jbravo
// Fix the instant spectate on death and an attempt to fix the scores
//
@ -684,3 +688,27 @@ void MakeSpectator( gentity_t *ent )
client->sess.sessionTeam = TEAM_SPECTATOR;
ClientSpawn(ent);
}
qboolean OKtoFollow( int clientnum )
{
int i, x;
x = 0;
for (i = 0; i < level.maxclients ; i++) {
if (i == clientnum) {
continue;
}
if (level.clients[i].pers.connected != CON_CONNECTED) {
continue;
}
if (level.clients[i].sess.sessionTeam == TEAM_SPECTATOR) {
continue;
}
x++;
};
if (x > 0) {
return qtrue;
}
return qfalse;
}

View File

@ -5,6 +5,10 @@
//-----------------------------------------------------------------------------
//
// $Log$
// Revision 1.4 2002/02/09 00:10:12 jbravo
// Fixed spectator follow and free and updated zcam to 1.04 and added the
// missing zcam files.
//
// Revision 1.3 2002/02/06 03:10:43 jbravo
// Fix the instant spectate on death and an attempt to fix the scores
//
@ -39,3 +43,4 @@ void RQ3_Cmd_Choose_f(gentity_t *ent);
void RQ3_Cmd_Drop_f( gentity_t *ent );
void UnstickPlayer( gentity_t *ent );
void MakeSpectator( gentity_t *ent );
qboolean OKtoFollow( int clientnum );

1261
reaction/game/zcam.c Normal file

File diff suppressed because it is too large Load Diff

29
reaction/game/zcam.h Normal file
View File

@ -0,0 +1,29 @@
/*
* ZCam v1.0.4
* Spectator Camera for Quake III Arena
* Copyright (C), 2001 by Avi "Zung!" Rozen
*
* http://www.telefragged.com/zungbang/zcam
*
* Credits:
* FLIC camera mode is based on code taken from q2cam by Paul Jordan
* SWING camera mode is based on ideas taken from CreepCam for Quake I
*
*/
#ifndef __ZCAM_H__
#define __ZCAM_H__
#define MAX_VISIBLE_RANGE 1000
void camera_init (void);
void camera_shutdown (void);
void camera_state_save (gclient_t *client);
void camera_state_load (gclient_t *client);
void camera_begin (gentity_t *ent);
void camera_disconnect (gentity_t *ent);
void camera_think (gentity_t *ent);
void camera_cmd (gentity_t *ent);
#endif /* __ZCAM_H__ */

223
reaction/game/zcam_target.c Normal file
View File

@ -0,0 +1,223 @@
/*
* ZCam v1.0.4
* Spectator Camera for Quake III Arena
* Copyright (C), 2001 by Avi "Zung!" Rozen
*
* http://www.telefragged.com/zungbang/zcam
*
* Credits:
* FLIC camera mode is based on code taken from q2cam by Paul Jordan
* SWING camera mode is based on ideas taken from CreepCam for Quake I
*
*/
/* Camera Target Selection */
#include "g_local.h"
#include "zcam.h"
/* IsVisible:
* Is player #1 visible by player #2 ?
*/
qboolean IsVisible(gentity_t *player1, gentity_t *player2, float maxrange)
{
vec3_t length;
float distance;
trace_t trace;
// check for looking through non-transparent water
if (!trap_InPVS(player1->client->ps.origin, player2->client->ps.origin))
return qfalse;
trap_Trace ( &trace,
player1->client->ps.origin,
NULL,
NULL,
player2->client->ps.origin,
player1->s.clientNum,
MASK_SOLID );
VectorSubtract(player1->client->ps.origin, player2->client->ps.origin, length);
distance = VectorLength(length);
return ((maxrange == 0 || distance < maxrange) && trace.fraction == 1.0f);
}
/* NumPlayersVisible:
* Return the number of players visible by the specified viewer.
*/
int NumPlayersVisible(gentity_t *viewer, float maxrange)
{
int count = 0;
int i;
if (viewer == NULL)
{
return 0;
}
for (i = 0; i < level.maxclients; i++)
{
if (viewer->s.clientNum != i
&& level.clients[i].pers.connected == CON_CONNECTED
&& level.clients[i].sess.sessionTeam != TEAM_SPECTATOR
&& level.clients[i].ps.pm_type != PM_DEAD)
{
if (IsVisible(viewer, &g_entities[i], maxrange))
{
count++;
}
}
}
return count;
}
/* PriorityTarget:
* Override camera target selection. Returns the new favorite
* player (or the one already selected).
* Currently used to select flag carriers in CTF.
*/
gentity_t *PriorityTarget(gentity_t *target, qboolean *override)
{
int i;
gentity_t *favorite = NULL;
for (i = 0; i < level.maxclients; i++)
{
if (level.clients[i].pers.connected == CON_CONNECTED
&& level.clients[i].sess.sessionTeam != TEAM_SPECTATOR
&& level.clients[i].ps.pm_type == PM_NORMAL
&& (level.clients[i].ps.powerups[PW_REDFLAG]
|| level.clients[i].ps.powerups[PW_BLUEFLAG]))
{
if (favorite == NULL
|| NumPlayersVisible (favorite, MAX_VISIBLE_RANGE) < NumPlayersVisible (&g_entities[i], MAX_VISIBLE_RANGE))
{
favorite = &g_entities[i];
}
}
}
/* set override flag */
if (favorite)
*override = qtrue;
else
*override = qfalse;
return (favorite)? favorite:target;
}
/* PlayerToFollow:
* Select camera target. Selects the player that sees the maximum
* number of other players, unless a priority target exists (as
* determined by the function PriorityTarget above).
*/
gentity_t *PlayerToFollow(gentity_t *ent, qboolean *override)
{
gentity_t *viewer;
gentity_t *best = NULL;
int i, players, best_count = -1;
*override = qfalse;
for (i = 0; i < level.maxclients; i++)
{
/* don't switch to dead people */
viewer = &g_entities[i];
if (viewer->client->pers.connected != CON_CONNECTED)
continue;
if (viewer->client->sess.sessionTeam != TEAM_SPECTATOR
&& viewer->client->ps.pm_type == PM_NORMAL)
{
players = NumPlayersVisible(viewer, MAX_VISIBLE_RANGE);
if (players > best_count)
{
best_count = players;
best = viewer;
}
else if (players == best_count)
{
if (best->client->ps.persistant[PERS_SCORE] <
viewer->client->ps.persistant[PERS_SCORE])
{
best = viewer;
}
}
}
}
if (best == NULL)
return best;
return PriorityTarget(best, override);
}
/* PlayerToTrack:
* select swing camera target in the following priority order:
* - enemy flag carrier
* - closest enemy player
* - own team flag carrier
* - closest own team player
* (in DM this amount to picking the closest player)
*/
gentity_t *PlayerToTrack (gentity_t *ent, gentity_t *target1st)
{
int i;
gentity_t *target2nd;
gentity_t *best1 = NULL;
gentity_t *best2 = NULL;
vec3_t distance;
float current, closest1 = -1.0F, closest2 = -1.0F;
for (i = 0; i < level.maxclients; i++)
{
target2nd = &g_entities[i];
if (target1st != target2nd
&& target2nd->client->pers.connected == CON_CONNECTED
&& target2nd->client->sess.sessionTeam != TEAM_SPECTATOR
&& target2nd->client->ps.pm_type == PM_NORMAL
&& trap_InPVS (target1st->client->ps.origin, target2nd->client->ps.origin))
{
VectorSubtract(target1st->client->ps.origin, target2nd->client->ps.origin, distance);
current = VectorLength(distance);
if (target1st->client->sess.sessionTeam == target2nd->client->sess.sessionTeam)
{
if (target2nd->client->ps.powerups[PW_REDFLAG]
|| target2nd->client->ps.powerups[PW_BLUEFLAG])
{
best1 = target2nd;
}
if (!(best1
&& (best1->client->ps.powerups[PW_REDFLAG]
|| best1->client->ps.powerups[PW_BLUEFLAG]))
&& (closest1 < 0 || current < closest1))
{
best1 = target2nd;
closest1 = current;
}
}
else
{
if (target2nd->client->ps.powerups[PW_REDFLAG]
|| target2nd->client->ps.powerups[PW_BLUEFLAG])
{
best2 = target2nd;
}
if (!(best2
&& (best2->client->ps.powerups[PW_REDFLAG]
|| best2->client->ps.powerups[PW_BLUEFLAG]))
&& (closest2 < 0 || current < closest2))
{
best2 = target2nd;
closest2 = current;
}
}
}
}
return ((best2)? best2:best1);
}