Move tele vector init from gamecontroller to collision

This commit is contained in:
ChillerDragon 2024-02-08 15:29:03 +08:00
parent c824bcc647
commit 552d466197
7 changed files with 53 additions and 47 deletions

View file

@ -131,6 +131,36 @@ void CCollision::Init(class CLayers *pLayers)
}
}
}
m_TeleIns.clear();
m_TeleOuts.clear();
m_TeleCheckOuts.clear();
if(m_pLayers->TeleLayer())
{
int Width = m_pLayers->TeleLayer()->m_Width;
int Height = m_pLayers->TeleLayer()->m_Height;
for(int i = 0; i < Width * Height; i++)
{
int Number = TeleLayer()[i].m_Number;
int Type = TeleLayer()[i].m_Type;
if(Number > 0)
{
if(Type == TILE_TELEIN)
{
m_TeleIns[Number - 1].emplace_back(i % Width * 32.0f + 16.0f, i / Width * 32.0f + 16.0f);
}
else if(Type == TILE_TELEOUT)
{
m_TeleOuts[Number - 1].emplace_back(i % Width * 32.0f + 16.0f, i / Width * 32.0f + 16.0f);
}
else if(Type == TILE_TELECHECKOUT)
{
m_TeleCheckOuts[Number - 1].emplace_back(i % Width * 32.0f + 16.0f, i / Width * 32.0f + 16.0f);
}
}
}
}
}
void CCollision::FillAntibot(CAntibotMapData *pMapData)

View file

@ -6,6 +6,7 @@
#include <base/vmath.h>
#include <engine/shared/protocol.h>
#include <map>
#include <vector>
enum
@ -116,7 +117,15 @@ public:
class CLayers *Layers() { return m_pLayers; }
int m_HighestSwitchNumber;
std::map<int, std::vector<vec2>> &TeleIns() { return m_TeleIns; }
std::map<int, std::vector<vec2>> &TeleOuts() { return m_TeleOuts; }
std::map<int, std::vector<vec2>> &TeleCheckOuts() { return m_TeleCheckOuts; }
private:
std::map<int, std::vector<vec2>> m_TeleIns;
std::map<int, std::vector<vec2>> m_TeleOuts;
std::map<int, std::vector<vec2>> m_TeleCheckOuts;
class CTeleTile *m_pTele;
class CSpeedupTile *m_pSpeedup;
class CTile *m_pFront;

View file

@ -361,13 +361,13 @@ void CGameContext::ConToTeleporter(IConsole::IResult *pResult, void *pUserData)
CGameContext *pSelf = (CGameContext *)pUserData;
unsigned int TeleTo = pResult->GetInteger(0);
if(!pSelf->m_pController->m_TeleOuts[TeleTo - 1].empty())
if(!pSelf->Collision()->TeleOuts()[TeleTo - 1].empty())
{
CCharacter *pChr = pSelf->GetPlayerChar(pResult->m_ClientId);
if(pChr)
{
int TeleOut = pSelf->m_World.m_Core.RandomOr0(pSelf->m_pController->m_TeleOuts[TeleTo - 1].size());
pSelf->Teleport(pChr, pSelf->m_pController->m_TeleOuts[TeleTo - 1][TeleOut]);
int TeleOut = pSelf->m_World.m_Core.RandomOr0(pSelf->Collision()->TeleOuts()[TeleTo - 1].size());
pSelf->Teleport(pChr, pSelf->Collision()->TeleOuts()[TeleTo - 1][TeleOut]);
}
}
}
@ -377,13 +377,13 @@ void CGameContext::ConToCheckTeleporter(IConsole::IResult *pResult, void *pUserD
CGameContext *pSelf = (CGameContext *)pUserData;
unsigned int TeleTo = pResult->GetInteger(0);
if(!pSelf->m_pController->m_TeleCheckOuts[TeleTo - 1].empty())
if(!pSelf->Collision()->TeleCheckOuts()[TeleTo - 1].empty())
{
CCharacter *pChr = pSelf->GetPlayerChar(pResult->m_ClientId);
if(pChr)
{
int TeleOut = pSelf->m_World.m_Core.RandomOr0(pSelf->m_pController->m_TeleCheckOuts[TeleTo - 1].size());
pSelf->Teleport(pChr, pSelf->m_pController->m_TeleCheckOuts[TeleTo - 1][TeleOut]);
int TeleOut = pSelf->m_World.m_Core.RandomOr0(pSelf->Collision()->TeleCheckOuts()[TeleTo - 1].size());
pSelf->Teleport(pChr, pSelf->Collision()->TeleCheckOuts()[TeleTo - 1][TeleOut]);
pChr->m_TeleCheckpoint = TeleTo;
}
}

View file

@ -164,10 +164,10 @@ void CLaser::DoBounce()
}
m_ZeroEnergyBounceInLastTick = Distance == 0.0f;
if(Res == TILE_TELEINWEAPON && !GameServer()->m_pController->m_TeleOuts[z - 1].empty())
if(Res == TILE_TELEINWEAPON && !GameServer()->Collision()->TeleOuts()[z - 1].empty())
{
int TeleOut = GameServer()->m_World.m_Core.RandomOr0(GameServer()->m_pController->m_TeleOuts[z - 1].size());
m_TelePos = GameServer()->m_pController->m_TeleOuts[z - 1][TeleOut];
int TeleOut = GameServer()->m_World.m_Core.RandomOr0(GameServer()->Collision()->TeleOuts()[z - 1].size());
m_TelePos = GameServer()->Collision()->TeleOuts()[z - 1][TeleOut];
m_WasTele = true;
}
else

View file

@ -276,10 +276,10 @@ void CProjectile::Tick()
z = GameServer()->Collision()->IsTeleport(x);
else
z = GameServer()->Collision()->IsTeleportWeapon(x);
if(z && !GameServer()->m_pController->m_TeleOuts[z - 1].empty())
if(z && !GameServer()->Collision()->TeleOuts()[z - 1].empty())
{
int TeleOut = GameServer()->m_World.m_Core.RandomOr0(GameServer()->m_pController->m_TeleOuts[z - 1].size());
m_Pos = GameServer()->m_pController->m_TeleOuts[z - 1][TeleOut];
int TeleOut = GameServer()->m_World.m_Core.RandomOr0(GameServer()->Collision()->TeleOuts()[z - 1].size());
m_Pos = GameServer()->Collision()->TeleOuts()[z - 1][TeleOut];
m_StartTick = Server()->Tick();
}
}

View file

@ -40,8 +40,6 @@ IGameController::IGameController(class CGameContext *pGameServer) :
m_ForceBalanced = false;
m_CurrentRecord = 0;
InitTeleporter();
}
IGameController::~IGameController() = default;
@ -485,7 +483,7 @@ void IGameController::OnCharacterSpawn(class CCharacter *pChr)
pChr->GiveWeapon(WEAPON_HAMMER);
pChr->GiveWeapon(WEAPON_GUN);
pChr->SetTeleports(&m_TeleOuts, &m_TeleCheckOuts);
pChr->SetTeleports(&GameServer()->Collision()->TeleOuts(), &GameServer()->Collision()->TeleCheckOuts());
}
void IGameController::HandleCharacterTiles(CCharacter *pChr, int MapIndex)
@ -712,31 +710,6 @@ CClientMask IGameController::GetMaskForPlayerWorldEvent(int Asker, int ExceptId)
return Teams().TeamMask(GameServer()->GetDDRaceTeam(Asker), ExceptId, Asker);
}
void IGameController::InitTeleporter()
{
if(!GameServer()->Collision()->Layers()->TeleLayer())
return;
int Width = GameServer()->Collision()->Layers()->TeleLayer()->m_Width;
int Height = GameServer()->Collision()->Layers()->TeleLayer()->m_Height;
for(int i = 0; i < Width * Height; i++)
{
int Number = GameServer()->Collision()->TeleLayer()[i].m_Number;
int Type = GameServer()->Collision()->TeleLayer()[i].m_Type;
if(Number > 0)
{
if(Type == TILE_TELEOUT)
{
m_TeleOuts[Number - 1].emplace_back(i % Width * 32.0f + 16.0f, i / Width * 32.0f + 16.0f);
}
else if(Type == TILE_TELECHECKOUT)
{
m_TeleCheckOuts[Number - 1].emplace_back(i % Width * 32.0f + 16.0f, i / Width * 32.0f + 16.0f);
}
}
}
}
void IGameController::DoTeamChange(CPlayer *pPlayer, int Team, bool DoChatMsg)
{
Team = ClampTeam(Team);

View file

@ -8,9 +8,6 @@
#include <engine/shared/protocol.h>
#include <game/server/teams.h>
#include <map>
#include <vector>
struct CScoreLoadBestTimeResult;
/*
@ -148,15 +145,12 @@ public:
virtual bool CanJoinTeam(int Team, int NotThisId, char *pErrorReason, int ErrorReasonSize);
int ClampTeam(int Team);
CClientMask GetMaskForPlayerWorldEvent(int Asker, int ExceptId = -1);
virtual void InitTeleporter();
CClientMask GetMaskForPlayerWorldEvent(int Asker, int ExceptID = -1);
bool IsTeamPlay() { return m_GameFlags & GAMEFLAG_TEAMS; }
// DDRace
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;
};