Skip to content

Commit

Permalink
game: Add third person view
Browse files Browse the repository at this point in the history
Based on codes:
 * Lazarus mod
 * KMQuake2 codes
 * Slight Mechanical Destruction mod

https://bitbucket.org/Knightmare66/kmquake2_stable/src/master/game/p_chase.c
  • Loading branch information
0lvin committed Dec 24, 2023
1 parent 4576796 commit 6b4f197
Show file tree
Hide file tree
Showing 13 changed files with 842 additions and 73 deletions.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -926,6 +926,7 @@ GAME_OBJS_ = \
src/game/monster/turret/turret.o \
src/game/monster/widow/widow2.o \
src/game/monster/widow/widow.o \
src/game/player/chase.o \
src/game/player/client.o \
src/game/player/hud.o \
src/game/player/trail.o \
Expand Down
2 changes: 2 additions & 0 deletions doc/050_commands.md
Expand Up @@ -46,3 +46,5 @@ original clients (Vanilla Quake II) commands are still in place.
* **set** / **seta** / **setu** / **sets**: set cvar valu with different flags.

* **listlights**: Show lights style and dlights list.

* **thirdperson**: Third person view.
1 change: 1 addition & 0 deletions src/client/cl_main.c
Expand Up @@ -628,6 +628,7 @@ CL_InitLocal(void)
Cmd_AddCommand("spawnentity", NULL);
Cmd_AddCommand("spawnonstart", NULL);
Cmd_AddCommand("cycleweap", NULL);
Cmd_AddCommand("thirdperson", NULL);
}

/*
Expand Down
4 changes: 4 additions & 0 deletions src/game/g_cmds.c
Expand Up @@ -2255,6 +2255,10 @@ ClientCommand(edict_t *ent)
{
CTFObserver(ent);
}
else if (Q_stricmp(cmd, "thirdperson") == 0)
{
Cmd_Chasecam_Toggle(ent);
}
else /* anything that doesn't match a command will be a chat */
{
Cmd_Say_f(ent, false, true);
Expand Down
22 changes: 13 additions & 9 deletions src/game/g_phys.c
Expand Up @@ -1072,20 +1072,24 @@ SV_Physics_Toss(edict_t *ent)
ent->waterlevel = 0;
}

if (!wasinwater && isinwater)
/* Don't do the sounds for the camera */
if (Q_stricmp(ent->classname,"chasecam"))
{
/* don't play splash sound for entities already in water on level start */
if (level.framenum > 3)
if (!wasinwater && isinwater)
{
/* don't play splash sound for entities already in water on level start */
if (level.framenum > 3)
{
gi.positioned_sound(old_origin, g_edicts, CHAN_AUTO,
gi.soundindex("misc/h2ohit1.wav"), 1, 1, 0);
}
}
else if (wasinwater && !isinwater)
{
gi.positioned_sound(old_origin, g_edicts, CHAN_AUTO,
gi.positioned_sound(ent->s.origin, g_edicts, CHAN_AUTO,
gi.soundindex("misc/h2ohit1.wav"), 1, 1, 0);
}
}
else if (wasinwater && !isinwater)
{
gi.positioned_sound(ent->s.origin, g_edicts, CHAN_AUTO,
gi.soundindex("misc/h2ohit1.wav"), 1, 1, 0);
}

/* move teamslaves */
for (slave = ent->teamchain; slave; slave = slave->teamchain)
Expand Down
24 changes: 19 additions & 5 deletions src/game/header/local.h
Expand Up @@ -1143,6 +1143,7 @@ typedef struct
int helpchanged;

qboolean spectator; /* client is a spectator */
int chasetoggle; /* Chasetoggle */

int max_tesla;
int max_prox;
Expand Down Expand Up @@ -1292,6 +1293,14 @@ struct gclient_s
float tracker_pain_framenum;

edict_t *owned_sphere; /* this points to the player's sphere */

/* Third person view */
int chasetoggle;
edict_t *chasecam;
edict_t *oldplayer;
int use;
int zoom;
int delayedstart;
};

struct edict_s
Expand Down Expand Up @@ -1452,6 +1461,10 @@ struct edict_s
edict_t *target_hint_chain;
int hint_chain_id;
float lastMoveTime;

/* Third person view */
int chasedist1;
int chasedist2;
};

#define SPHERE_DEFENDER 0x0001
Expand Down Expand Up @@ -1596,6 +1609,7 @@ typedef struct ghost_s
} ghost_t;

extern cvar_t *ctf;
extern char *ctf_statusbar;

#define CTF_TEAM1_SKIN "ctf_r"
#define CTF_TEAM2_SKIN "ctf_b"
Expand Down Expand Up @@ -1702,11 +1716,11 @@ qboolean CTFCheckRules(void);
void SP_misc_ctf_banner(edict_t *ent);
void SP_misc_ctf_small_banner(edict_t *ent);

extern char *ctf_statusbar;

void UpdateChaseCam(edict_t *ent);
void ChaseNext(edict_t *ent);
void ChasePrev(edict_t *ent);
void Cmd_Chasecam_Toggle(edict_t *ent);
void ChasecamStart(edict_t *ent);
void ChasecamRemove(edict_t *ent);
void CheckChasecam_Viewent(edict_t *ent);
void ChasecamTrack(edict_t *ent);

void CTFObserver(edict_t *ent);

Expand Down

0 comments on commit 6b4f197

Please sign in to comment.