2022-12-17 13:32:43 +01:00
|
|
|
/***
|
2013-08-30 13:34:05 -07:00
|
|
|
*
|
|
|
|
* Copyright (c) 1996-2001, Valve LLC. All rights reserved.
|
|
|
|
*
|
|
|
|
* This product contains software technology licensed from Id
|
|
|
|
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use, distribution, and modification of this source code and/or resulting
|
|
|
|
* object code is restricted to non-commercial enhancements to products from
|
|
|
|
* Valve LLC. All other use, distribution, or modification is prohibited
|
|
|
|
* without written permission from Valve LLC.
|
|
|
|
*
|
|
|
|
****/
|
|
|
|
// CBaseSpectator
|
|
|
|
|
|
|
|
// YWB: UNDONE
|
|
|
|
|
|
|
|
// Spectator functions
|
2021-11-28 16:54:48 +01:00
|
|
|
//
|
|
|
|
#include "extdll.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "cbase.h"
|
|
|
|
#include "monsters.h"
|
|
|
|
#include "spectator.h"
|
2013-08-30 13:34:05 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
===========
|
|
|
|
SpectatorConnect
|
|
|
|
|
|
|
|
called when a spectator connects to a server
|
|
|
|
============
|
|
|
|
*/
|
2021-03-05 20:54:33 +01:00
|
|
|
void CBaseSpectator::SpectatorConnect()
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
|
|
|
pev->flags = FL_SPECTATOR;
|
|
|
|
pev->solid = SOLID_NOT;
|
|
|
|
pev->movetype = MOVETYPE_NOCLIP;
|
2021-11-28 16:54:48 +01:00
|
|
|
|
2013-08-30 13:34:05 -07:00
|
|
|
m_pGoalEnt = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===========
|
|
|
|
SpectatorDisconnect
|
|
|
|
|
|
|
|
called when a spectator disconnects from a server
|
|
|
|
============
|
|
|
|
*/
|
2021-03-05 20:54:33 +01:00
|
|
|
void CBaseSpectator::SpectatorDisconnect()
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
SpectatorImpulseCommand
|
|
|
|
|
|
|
|
Called by SpectatorThink if the spectator entered an impulse
|
|
|
|
================
|
|
|
|
*/
|
2021-03-05 20:54:33 +01:00
|
|
|
void CBaseSpectator::SpectatorImpulseCommand()
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
2021-11-28 16:54:48 +01:00
|
|
|
static edict_t* pGoal = NULL;
|
|
|
|
edict_t* pPreviousGoal;
|
|
|
|
edict_t* pCurrentGoal;
|
|
|
|
bool bFound;
|
|
|
|
|
2013-08-30 13:34:05 -07:00
|
|
|
switch (pev->impulse)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
// teleport the spectator to the next spawn point
|
|
|
|
// note that if the spectator is tracking, this doesn't do
|
|
|
|
// much
|
|
|
|
pPreviousGoal = pGoal;
|
2021-11-28 16:54:48 +01:00
|
|
|
pCurrentGoal = pGoal;
|
2013-08-30 13:34:05 -07:00
|
|
|
// Start at the current goal, skip the world, and stop if we looped
|
|
|
|
// back around
|
|
|
|
|
2021-11-19 13:43:33 +01:00
|
|
|
bFound = false;
|
2021-11-28 15:32:26 +01:00
|
|
|
while (true)
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
|
|
|
pCurrentGoal = FIND_ENTITY_BY_CLASSNAME(pCurrentGoal, "info_player_deathmatch");
|
|
|
|
// Looped around, failure
|
|
|
|
if (pCurrentGoal == pPreviousGoal)
|
|
|
|
{
|
|
|
|
ALERT(at_console, "Could not find a spawn spot.\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Found a non-world entity, set success, otherwise, look for the next one.
|
|
|
|
if (!FNullEnt(pCurrentGoal))
|
|
|
|
{
|
2021-11-19 13:45:16 +01:00
|
|
|
bFound = true;
|
2013-08-30 13:34:05 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
if (!bFound) // Didn't find a good spot.
|
2013-08-30 13:34:05 -07:00
|
|
|
break;
|
2021-11-28 16:54:48 +01:00
|
|
|
|
2013-08-30 13:34:05 -07:00
|
|
|
pGoal = pCurrentGoal;
|
2021-11-28 16:54:48 +01:00
|
|
|
UTIL_SetOrigin(pev, pGoal->v.origin);
|
2013-08-30 13:34:05 -07:00
|
|
|
pev->angles = pGoal->v.angles;
|
2021-11-28 15:32:26 +01:00
|
|
|
pev->fixangle = 0;
|
2013-08-30 13:34:05 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ALERT(at_console, "Unknown spectator impulse\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pev->impulse = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
SpectatorThink
|
|
|
|
|
|
|
|
Called every frame after physics are run
|
|
|
|
================
|
|
|
|
*/
|
2021-11-28 16:54:48 +01:00
|
|
|
void CBaseSpectator::SpectatorThink()
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
2021-11-28 15:32:26 +01:00
|
|
|
if ((pev->flags & FL_SPECTATOR) == 0)
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
|
|
|
pev->flags = FL_SPECTATOR;
|
|
|
|
}
|
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
pev->solid = SOLID_NOT;
|
|
|
|
pev->movetype = MOVETYPE_NOCLIP;
|
2013-08-30 13:34:05 -07:00
|
|
|
|
2021-11-28 15:32:26 +01:00
|
|
|
if (0 != pev->impulse)
|
2013-08-30 13:34:05 -07:00
|
|
|
SpectatorImpulseCommand();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===========
|
|
|
|
Spawn
|
|
|
|
|
|
|
|
Called when spectator is initialized:
|
|
|
|
UNDONE: Is this actually being called because spectators are not allocated in normal fashion?
|
|
|
|
============
|
|
|
|
*/
|
|
|
|
void CBaseSpectator::Spawn()
|
|
|
|
{
|
|
|
|
pev->flags = FL_SPECTATOR;
|
|
|
|
pev->solid = SOLID_NOT;
|
|
|
|
pev->movetype = MOVETYPE_NOCLIP;
|
2021-11-28 16:54:48 +01:00
|
|
|
|
2013-08-30 13:34:05 -07:00
|
|
|
m_pGoalEnt = NULL;
|
|
|
|
}
|