ddnet/src/game/server/gamecontroller.h

164 lines
3.7 KiB
C
Raw Normal View History

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. */
2010-05-29 07:25:38 +00:00
#ifndef GAME_SERVER_GAMECONTROLLER_H
#define GAME_SERVER_GAMECONTROLLER_H
#include <base/vmath.h>
2020-06-18 16:29:27 +00:00
#include <engine/map.h>
2023-01-26 10:56:48 +00:00
#include <engine/shared/protocol.h>
#include <game/server/teams.h>
2010-05-29 07:25:38 +00:00
#include <map>
#include <vector>
struct CScoreLoadBestTimeResult;
2010-05-29 07:25:38 +00:00
/*
Class: Game Controller
Controls the main game logic. Keeping track of team and player score,
winning conditions and specific game logic.
*/
class IGameController
{
2018-02-04 15:00:47 +00:00
friend class CSaveTeam; // need access to GameServer() and Server()
2015-07-09 00:08:14 +00:00
std::vector<vec2> m_avSpawnPoints[3];
2010-05-29 07:25:38 +00:00
class CGameContext *m_pGameServer;
class CConfig *m_pConfig;
2010-05-29 07:25:38 +00:00
class IServer *m_pServer;
CGameTeams m_Teams;
2010-05-29 07:25:38 +00:00
protected:
CGameContext *GameServer() const { return m_pGameServer; }
CConfig *Config() { return m_pConfig; }
2010-05-29 07:25:38 +00:00
IServer *Server() const { return m_pServer; }
void DoActivityCheck();
2010-05-29 07:25:38 +00:00
struct CSpawnEval
{
CSpawnEval()
{
m_Got = false;
m_FriendlyTeam = -1;
m_Pos = vec2(100, 100);
2010-05-29 07:25:38 +00:00
}
2010-05-29 07:25:38 +00:00
vec2 m_Pos;
bool m_Got;
int m_FriendlyTeam;
float m_Score;
};
float EvaluateSpawnPos(CSpawnEval *pEval, vec2 Pos, int DDTeam);
void EvaluateSpawnType(CSpawnEval *pEval, int Type, int DDTeam);
2010-05-29 07:25:38 +00:00
void ResetGame();
2020-06-18 16:29:27 +00:00
char m_aMapWish[MAX_MAP_LENGTH];
2010-05-29 07:25:38 +00:00
int m_RoundStartTick;
int m_GameOverTick;
int m_SuddenDeath;
2010-05-29 07:25:38 +00:00
int m_Warmup;
int m_RoundCount;
2010-05-29 07:25:38 +00:00
int m_GameFlags;
int m_UnbalancedTick;
bool m_ForceBalanced;
2010-05-29 07:25:38 +00:00
public:
const char *m_pGameType;
IGameController(class CGameContext *pGameServer);
virtual ~IGameController();
// event
2010-05-29 07:25:38 +00:00
/*
Function: OnCharacterDeath
Called when a CCharacter in the world dies.
Arguments:
victim - The CCharacter that died.
killer - The player that killed it.
weapon - What weapon that killed it. Can be -1 for undefined
weapon when switching team or player suicides.
*/
virtual int OnCharacterDeath(class CCharacter *pVictim, class CPlayer *pKiller, int Weapon);
/*
Function: OnCharacterSpawn
Called when a CCharacter spawns into the game world.
Arguments:
chr - The CCharacter that was spawned.
*/
virtual void OnCharacterSpawn(class CCharacter *pChr);
virtual void HandleCharacterTiles(class CCharacter *pChr, int MapIndex);
2010-05-29 07:25:38 +00:00
/*
Function: OnEntity
2010-05-29 07:25:38 +00:00
Called when the map is loaded to process an entity
in the map.
2010-05-29 07:25:38 +00:00
Arguments:
index - Entity index.
pos - Where the entity is located in the world.
2010-05-29 07:25:38 +00:00
Returns:
bool?
*/
virtual bool OnEntity(int Index, int x, int y, int Layer, int Flags, bool Initial, int Number = 0);
virtual void OnPlayerConnect(class CPlayer *pPlayer);
virtual void OnPlayerDisconnect(class CPlayer *pPlayer, const char *pReason);
virtual void OnReset();
// game
void DoWarmup(int Seconds);
void StartRound();
void EndRound();
void ChangeMap(const char *pToMap);
bool IsForceBalanced();
2010-05-29 07:25:38 +00:00
/*
2010-05-29 07:25:38 +00:00
*/
virtual bool CanBeMovedOnBalance(int ClientID);
virtual void Tick();
2010-05-29 07:25:38 +00:00
virtual void Snap(int SnappingClient);
//spawn
virtual bool CanSpawn(int Team, vec2 *pOutPos, int DDTeam);
2010-05-29 07:25:38 +00:00
virtual void DoTeamChange(class CPlayer *pPlayer, int Team, bool DoChatMsg = true);
2010-05-29 07:25:38 +00:00
/*
*/
2010-05-29 07:25:38 +00:00
virtual const char *GetTeamName(int Team);
virtual int GetAutoTeam(int NotThisID);
virtual bool CanJoinTeam(int Team, int NotThisID, char *pErrorReason, int ErrorReasonSize);
2010-05-29 07:25:38 +00:00
int ClampTeam(int Team);
Fix crash in mod controller When creating a non ddrace controller and it uses `IGameController::GetMaskForPlayerWorldEvent` it will crash: #0 0x00007ffff72ac83c in ?? () from /usr/lib/libc.so.6 #1 0x00007ffff725c668 in raise () from /usr/lib/libc.so.6 #2 0x00007ffff72444b8 in abort () from /usr/lib/libc.so.6 #3 0x00007ffff749ca6f in __gnu_cxx::__verbose_terminate_handler () at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/vterminate.cc:95 #4 0x00007ffff74b011c in __cxxabiv1::__terminate (handler=<optimized out>) at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:48 #5 0x00007ffff74b0189 in std::terminate () at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:58 #6 0x00007ffff74b03ed in __cxxabiv1::__cxa_throw (obj=<optimized out>, tinfo=0x7ffff766c0e8 <typeinfo for std::out_of_range>, dest=0x7ffff74c85c0 <std::out_of_range::~out_of_range()>) at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_throw.cc:98 #7 0x00007ffff74a025f in std::__throw_out_of_range_fmt (__fmt=<optimized out>) at /usr/src/debug/gcc/gcc/libstdc++-v3/src/c++11/functexcept.cc:101 #8 0x00005555555bd4a3 in std::bitset<64ul>::_M_check (this=0x7fffffffbb90, __position=0xffffffffffffffff, __s=0x5555557a9881 "bitset::reset") at /usr/include/c++/13.2.1/bitset:823 #9 0x00005555555f83e0 in std::bitset<64ul>::reset (this=0x7fffffffbb90, __position=0xffffffffffffffff) at /usr/include/c++/13.2.1/bitset:1196 #10 0x000055555560262a in IGameController::GetMaskForPlayerWorldEvent (this=0x555555b113d0, Asker=0x0, ExceptID=0xffffffff) at /home/chiller/Desktop/git/ddnet/src/game/server/gamecontroller.cpp:728 #11 0x000055555560be0f in CPlayer::TryRespawn (this=0x55555592e500 <gs_PoolDataCPlayer>) at /home/chiller/Desktop/git/ddnet/src/game/server/player.cpp:695 #12 0x000055555560a1a6 in CPlayer::Tick (this=0x55555592e500 <gs_PoolDataCPlayer>) at /home/chiller/Desktop/git/ddnet/src/game/server/player.cpp:249 #13 0x00005555555e174b in CGameContext::OnTick (this=0x7ffff477d010) at /home/chiller/Desktop/git/ddnet/src/game/server/gamecontext.cpp:964 #14 0x00005555555a7e34 in CServer::Run (this=0x7ffff57d5010) at /home/chiller/Desktop/git/ddnet/src/engine/server/server.cpp:2893 #15 0x0000555555592a2b in main (argc=0x1, argv=0x7fffffffd178) at /home/chiller/Desktop/git/ddnet/src/engine/server/main.cpp:197
2023-11-16 10:27:59 +00:00
CClientMask GetMaskForPlayerWorldEvent(int Asker, int ExceptID = -1);
virtual void InitTeleporter();
// DDRace
2011-01-29 00:59:50 +00:00
float m_CurrentRecord;
std::map<int, std::vector<vec2>> m_TeleOuts;
std::map<int, std::vector<vec2>> m_TeleCheckOuts;
CGameTeams &Teams() { return m_Teams; }
std::shared_ptr<CScoreLoadBestTimeResult> m_pLoadBestTimeResult;
2010-05-29 07:25:38 +00:00
};
2011-02-14 07:43:44 +00:00
#endif