2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2008-08-14 18:25:44 +00:00
|
|
|
#ifndef GAME_SERVER_ENTITY_H
|
|
|
|
#define GAME_SERVER_ENTITY_H
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <base/vmath.h>
|
2008-08-14 18:25:44 +00:00
|
|
|
|
2021-01-09 13:35:00 +00:00
|
|
|
#include "alloc.h"
|
2021-01-11 17:28:14 +00:00
|
|
|
#include "gamecontext.h"
|
2021-01-09 20:29:12 +00:00
|
|
|
#include "gameworld.h"
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-14 18:25:44 +00:00
|
|
|
/*
|
|
|
|
Class: Entity
|
|
|
|
Basic entity class.
|
|
|
|
*/
|
2010-05-29 07:25:38 +00:00
|
|
|
class CEntity
|
2008-08-14 18:25:44 +00:00
|
|
|
{
|
2008-09-24 09:03:49 +00:00
|
|
|
MACRO_ALLOC_HEAP()
|
2008-08-14 18:25:44 +00:00
|
|
|
|
2021-01-09 20:29:12 +00:00
|
|
|
private:
|
2020-09-26 19:41:58 +00:00
|
|
|
friend class CGameWorld; // entity list handling
|
2010-05-29 07:25:38 +00:00
|
|
|
CEntity *m_pPrevTypeEntity;
|
|
|
|
CEntity *m_pNextTypeEntity;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2021-01-09 20:29:12 +00:00
|
|
|
/* Identity */
|
2013-11-13 12:25:26 +00:00
|
|
|
class CGameWorld *m_pGameWorld;
|
2021-01-09 20:29:12 +00:00
|
|
|
|
2011-02-12 10:40:36 +00:00
|
|
|
int m_ID;
|
2011-01-19 17:27:50 +00:00
|
|
|
int m_ObjType;
|
2020-09-26 19:41:58 +00:00
|
|
|
|
2021-01-09 20:29:12 +00:00
|
|
|
/*
|
|
|
|
Variable: m_ProximityRadius
|
|
|
|
Contains the physical size of the entity.
|
|
|
|
*/
|
|
|
|
float m_ProximityRadius;
|
|
|
|
|
2021-05-22 18:02:00 +00:00
|
|
|
protected:
|
2021-01-09 20:29:12 +00:00
|
|
|
/* State */
|
|
|
|
bool m_MarkedForDestroy;
|
|
|
|
|
|
|
|
public: // TODO: Maybe make protected
|
|
|
|
/*
|
|
|
|
Variable: m_Pos
|
|
|
|
Contains the current posititon of the entity.
|
|
|
|
*/
|
|
|
|
vec2 m_Pos;
|
|
|
|
|
|
|
|
/* Getters */
|
|
|
|
int GetID() const { return m_ID; }
|
|
|
|
|
|
|
|
/* Constructor */
|
|
|
|
CEntity(CGameWorld *pGameWorld, int Objtype, vec2 Pos = vec2(0, 0), int ProximityRadius = 0);
|
|
|
|
|
|
|
|
/* Destructor */
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual ~CEntity();
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2021-01-09 20:29:12 +00:00
|
|
|
/* Objects */
|
2010-05-29 07:25:38 +00:00
|
|
|
class CGameWorld *GameWorld() { return m_pGameWorld; }
|
2021-01-10 12:47:07 +00:00
|
|
|
class CConfig *Config() { return m_pGameWorld->Config(); }
|
2021-01-09 20:29:12 +00:00
|
|
|
class CGameContext *GameServer() { return m_pGameWorld->GameServer(); }
|
|
|
|
class IServer *Server() { return m_pGameWorld->Server(); }
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2021-01-09 20:29:12 +00:00
|
|
|
/* Getters */
|
2010-05-29 07:25:38 +00:00
|
|
|
CEntity *TypeNext() { return m_pNextTypeEntity; }
|
|
|
|
CEntity *TypePrev() { return m_pPrevTypeEntity; }
|
2021-01-09 20:29:12 +00:00
|
|
|
const vec2 &GetPos() const { return m_Pos; }
|
|
|
|
float GetProximityRadius() const { return m_ProximityRadius; }
|
|
|
|
|
|
|
|
/* Other functions */
|
2008-08-14 18:25:44 +00:00
|
|
|
|
|
|
|
/*
|
2021-01-09 20:29:12 +00:00
|
|
|
Function: Destroy
|
2018-07-10 09:29:02 +00:00
|
|
|
Destroys the entity.
|
2008-08-14 18:25:44 +00:00
|
|
|
*/
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void Destroy() { delete this; }
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-14 18:25:44 +00:00
|
|
|
/*
|
2021-01-09 20:29:12 +00:00
|
|
|
Function: Reset
|
2008-10-06 18:05:01 +00:00
|
|
|
Called when the game resets the map. Puts the entity
|
2021-01-09 20:29:12 +00:00
|
|
|
back to its starting state or perhaps destroys it.
|
2008-08-14 18:25:44 +00:00
|
|
|
*/
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void Reset() {}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-14 18:25:44 +00:00
|
|
|
/*
|
2021-01-09 20:29:12 +00:00
|
|
|
Function: Tick
|
|
|
|
Called to progress the entity to the next tick. Updates
|
|
|
|
and moves the entity to its new state and position.
|
2008-08-14 18:25:44 +00:00
|
|
|
*/
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void Tick() {}
|
2008-08-14 18:25:44 +00:00
|
|
|
|
|
|
|
/*
|
2021-01-09 20:29:12 +00:00
|
|
|
Function: TickDefered
|
|
|
|
Called after all entities Tick() function has been called.
|
2008-08-14 18:25:44 +00:00
|
|
|
*/
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void TickDefered() {}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2012-01-09 23:49:31 +00:00
|
|
|
/*
|
|
|
|
Function: TickPaused
|
|
|
|
Called when the game is paused, to freeze the state and position of the entity.
|
|
|
|
*/
|
|
|
|
virtual void TickPaused() {}
|
|
|
|
|
2008-08-14 18:25:44 +00:00
|
|
|
/*
|
2021-01-09 20:29:12 +00:00
|
|
|
Function: Snap
|
2008-10-06 18:05:01 +00:00
|
|
|
Called when a new snapshot is being generated for a specific
|
|
|
|
client.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-14 18:25:44 +00:00
|
|
|
Arguments:
|
2021-01-09 20:29:12 +00:00
|
|
|
SnappingClient - ID of the client which snapshot is
|
2008-08-14 18:25:44 +00:00
|
|
|
being generated. Could be -1 to create a complete
|
|
|
|
snapshot of everything in the game for demo
|
|
|
|
recording.
|
|
|
|
*/
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void Snap(int SnappingClient) {}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2021-12-14 09:35:00 +00:00
|
|
|
/*
|
|
|
|
Function: SwapClients
|
|
|
|
Called when two players have swapped their client ids.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
Client1 - First client ID
|
|
|
|
Client2 - Second client ID
|
|
|
|
*/
|
|
|
|
virtual void SwapClients(int Client1, int Client2) {}
|
|
|
|
|
2008-10-06 18:05:01 +00:00
|
|
|
/*
|
2021-01-11 17:28:14 +00:00
|
|
|
Function: NetworkClipped
|
2008-10-06 18:05:01 +00:00
|
|
|
Performs a series of test to see if a client can see the
|
|
|
|
entity.
|
|
|
|
|
|
|
|
Arguments:
|
2021-01-09 20:29:12 +00:00
|
|
|
SnappingClient - ID of the client which snapshot is
|
2008-10-06 18:05:01 +00:00
|
|
|
being generated. Could be -1 to create a complete
|
|
|
|
snapshot of everything in the game for demo
|
|
|
|
recording.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-10-06 18:05:01 +00:00
|
|
|
Returns:
|
2021-01-11 17:28:14 +00:00
|
|
|
True if the entity doesn't have to be in the snapshot.
|
2008-10-06 18:05:01 +00:00
|
|
|
*/
|
2021-12-08 17:02:04 +00:00
|
|
|
bool NetworkClipped(int SnappingClient) const;
|
|
|
|
bool NetworkClipped(int SnappingClient, vec2 CheckPos) const;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-01-08 10:34:19 +00:00
|
|
|
bool GameLayerClipped(vec2 CheckPos);
|
2008-08-14 18:25:44 +00:00
|
|
|
|
2011-04-09 06:41:31 +00:00
|
|
|
// DDRace
|
2020-09-26 19:41:58 +00:00
|
|
|
|
2022-01-22 13:12:59 +00:00
|
|
|
bool GetNearestAirPos(vec2 Pos, vec2 PrevPos, vec2 *pOutPos);
|
2020-09-26 19:41:58 +00:00
|
|
|
bool GetNearestAirPosPlayer(vec2 PlayerPos, vec2 *OutPos);
|
2011-04-09 06:41:31 +00:00
|
|
|
|
|
|
|
int m_Number;
|
|
|
|
int m_Layer;
|
2008-08-14 18:25:44 +00:00
|
|
|
};
|
|
|
|
|
2021-12-08 17:02:04 +00:00
|
|
|
bool NetworkClipped(const CGameContext *pGameServer, int SnappingClient, vec2 CheckPos);
|
2021-01-11 17:28:14 +00:00
|
|
|
|
2008-08-14 18:25:44 +00:00
|
|
|
#endif
|