mirror of
https://github.com/ddnet/ddnet.git
synced 2024-09-20 17:44:18 +00:00
Moved Switch layer Initialization from CGameContext to GameControllerDDRace
i Quote btd "gamecontext as a global rubbish" xD Signed-off-by: GreYFoXGTi <GreYFoXGTi@GMaiL.CoM>
This commit is contained in:
parent
1fe93f4592
commit
3df855df00
|
@ -876,7 +876,6 @@ void CCharacter::Tick()
|
||||||
|
|
||||||
if(z)
|
if(z)
|
||||||
{
|
{
|
||||||
dbg_msg("Collision", "This is teleport");
|
|
||||||
m_Core.m_HookedPlayer = -1;
|
m_Core.m_HookedPlayer = -1;
|
||||||
m_Core.m_HookState = HOOK_RETRACTED;
|
m_Core.m_HookState = HOOK_RETRACTED;
|
||||||
m_Core.m_TriggeredEvents |= COREEVENT_HOOK_RETRACT;
|
m_Core.m_TriggeredEvents |= COREEVENT_HOOK_RETRACT;
|
||||||
|
|
|
@ -1919,7 +1919,6 @@ void CGameContext::OnInit(/*class IKernel *pKernel*/)
|
||||||
m_pConsole = Kernel()->RequestInterface<IConsole>();
|
m_pConsole = Kernel()->RequestInterface<IConsole>();
|
||||||
m_World.SetGameServer(this);
|
m_World.SetGameServer(this);
|
||||||
m_Events.SetGameServer(this);
|
m_Events.SetGameServer(this);
|
||||||
m_Size = 0;
|
|
||||||
//if(!data) // only load once
|
//if(!data) // only load once
|
||||||
//data = load_data_from_memory(internal_data);
|
//data = load_data_from_memory(internal_data);
|
||||||
|
|
||||||
|
@ -1941,6 +1940,7 @@ void CGameContext::OnInit(/*class IKernel *pKernel*/)
|
||||||
// dbg_msg("Note","For map cfgs in windows and linux u need the files");
|
// dbg_msg("Note","For map cfgs in windows and linux u need the files");
|
||||||
// dbg_msg("Note","in a folder i nthe same dir as teeworlds_srv");
|
// dbg_msg("Note","in a folder i nthe same dir as teeworlds_srv");
|
||||||
// dbg_msg("Note","data/maps/%s.cfg", config.sv_map);
|
// dbg_msg("Note","data/maps/%s.cfg", config.sv_map);
|
||||||
|
|
||||||
// select gametype
|
// select gametype
|
||||||
m_pController = new CGameControllerDDRace(this);
|
m_pController = new CGameControllerDDRace(this);
|
||||||
|
|
||||||
|
@ -1959,7 +1959,6 @@ void CGameContext::OnInit(/*class IKernel *pKernel*/)
|
||||||
// setup core world
|
// setup core world
|
||||||
//for(int i = 0; i < MAX_CLIENTS; i++)
|
//for(int i = 0; i < MAX_CLIENTS; i++)
|
||||||
// game.players[i].core.world = &game.world.core;
|
// game.players[i].core.world = &game.world.core;
|
||||||
|
|
||||||
// create all entities from the game layer
|
// create all entities from the game layer
|
||||||
CMapItemLayerTilemap *pTileMap = m_Layers.GameLayer();
|
CMapItemLayerTilemap *pTileMap = m_Layers.GameLayer();
|
||||||
CTile *pTiles = (CTile *)Kernel()->RequestInterface<IMap>()->GetData(pTileMap->m_Data);
|
CTile *pTiles = (CTile *)Kernel()->RequestInterface<IMap>()->GetData(pTileMap->m_Data);
|
||||||
|
@ -1967,72 +1966,10 @@ void CGameContext::OnInit(/*class IKernel *pKernel*/)
|
||||||
CTile *pFront=0;
|
CTile *pFront=0;
|
||||||
if (m_Layers.FrontLayer())
|
if (m_Layers.FrontLayer())
|
||||||
pFront = (CTile *)Kernel()->RequestInterface<IMap>()->GetData(pTileMap->m_Front);
|
pFront = (CTile *)Kernel()->RequestInterface<IMap>()->GetData(pTileMap->m_Front);
|
||||||
CTeleTile *pSwitch=0;
|
m_pSwitch=0;
|
||||||
if (m_Layers.SwitchLayer())
|
if (m_Layers.SwitchLayer())
|
||||||
pSwitch = (CTeleTile *)Kernel()->RequestInterface<IMap>()->GetData(pTileMap->m_Switch);
|
m_pSwitch = (CTeleTile *)Kernel()->RequestInterface<IMap>()->GetData(pTileMap->m_Switch);
|
||||||
if (pSwitch)
|
((CGameControllerDDRace *)m_pController)->InitSwitcher();
|
||||||
{
|
|
||||||
if(Collision()->Layers()->SwitchLayer())
|
|
||||||
for(int y = 0; y < pTileMap->m_Height; y++)
|
|
||||||
for(int x = 0; x < pTileMap->m_Width; x++)
|
|
||||||
{
|
|
||||||
int sides[8][2];
|
|
||||||
sides[0][0]=pSwitch[(x)+pTileMap->m_Width*(y+1)].m_Type - ENTITY_OFFSET;
|
|
||||||
sides[1][0]=pSwitch[(x+1)+pTileMap->m_Width*(y+1)].m_Type - ENTITY_OFFSET;
|
|
||||||
sides[2][0]=pSwitch[(x+1)+pTileMap->m_Width*(y)].m_Type - ENTITY_OFFSET;
|
|
||||||
sides[3][0]=pSwitch[(x+1)+pTileMap->m_Width*(y-1)].m_Type - ENTITY_OFFSET;
|
|
||||||
sides[4][0]=pSwitch[(x)+pTileMap->m_Width*(y-1)].m_Type - ENTITY_OFFSET;
|
|
||||||
sides[5][0]=pSwitch[(x-1)+pTileMap->m_Width*(y-1)].m_Type - ENTITY_OFFSET;
|
|
||||||
sides[6][0]=pSwitch[(x-1)+pTileMap->m_Width*(y)].m_Type - ENTITY_OFFSET;
|
|
||||||
sides[7][0]=pSwitch[(x-1)+pTileMap->m_Width*(y+1)].m_Type - ENTITY_OFFSET;
|
|
||||||
sides[0][1]=pSwitch[(x)+pTileMap->m_Width*(y+1)].m_Number;
|
|
||||||
sides[1][1]=pSwitch[(x+1)+pTileMap->m_Width*(y+1)].m_Number;
|
|
||||||
sides[2][1]=pSwitch[(x+1)+pTileMap->m_Width*(y)].m_Number;
|
|
||||||
sides[3][1]=pSwitch[(x+1)+pTileMap->m_Width*(y-1)].m_Number;
|
|
||||||
sides[4][1]=pSwitch[(x)+pTileMap->m_Width*(y-1)].m_Number;
|
|
||||||
sides[5][1]=pSwitch[(x-1)+pTileMap->m_Width*(y-1)].m_Number;
|
|
||||||
sides[6][1]=pSwitch[(x-1)+pTileMap->m_Width*(y)].m_Number;
|
|
||||||
sides[7][1]=pSwitch[(x-1)+pTileMap->m_Width*(y+1)].m_Number;
|
|
||||||
for(int i=0; i<8;i++)
|
|
||||||
if ((sides[i][0] >= ENTITY_LASER_SHORT && sides[i][0] <= ENTITY_LASER_LONG) && Collision()->SwitchLayer()[y*pTileMap->m_Width+x].m_Number == sides[i][1])
|
|
||||||
m_Size++;
|
|
||||||
}
|
|
||||||
if(m_Size)
|
|
||||||
{
|
|
||||||
m_SDoors = new SDoors[m_Size];
|
|
||||||
int num=0;
|
|
||||||
for(int y = 0; y < pTileMap->m_Height; y++)
|
|
||||||
for(int x = 0; x < pTileMap->m_Width; x++)
|
|
||||||
if(Collision()->SwitchLayer()[y*pTileMap->m_Width+x].m_Type == (ENTITY_DOOR + ENTITY_OFFSET))
|
|
||||||
{
|
|
||||||
int sides[8][2];
|
|
||||||
sides[0][0]=pSwitch[(x)+pTileMap->m_Width*(y+1)].m_Type - ENTITY_OFFSET;
|
|
||||||
sides[1][0]=pSwitch[(x+1)+pTileMap->m_Width*(y+1)].m_Type - ENTITY_OFFSET;
|
|
||||||
sides[2][0]=pSwitch[(x+1)+pTileMap->m_Width*(y)].m_Type - ENTITY_OFFSET;
|
|
||||||
sides[3][0]=pSwitch[(x+1)+pTileMap->m_Width*(y-1)].m_Type - ENTITY_OFFSET;
|
|
||||||
sides[4][0]=pSwitch[(x)+pTileMap->m_Width*(y-1)].m_Type - ENTITY_OFFSET;
|
|
||||||
sides[5][0]=pSwitch[(x-1)+pTileMap->m_Width*(y-1)].m_Type - ENTITY_OFFSET;
|
|
||||||
sides[6][0]=pSwitch[(x-1)+pTileMap->m_Width*(y)].m_Type - ENTITY_OFFSET;
|
|
||||||
sides[7][0]=pSwitch[(x-1)+pTileMap->m_Width*(y+1)].m_Type - ENTITY_OFFSET;
|
|
||||||
sides[0][1]=pSwitch[(x)+pTileMap->m_Width*(y+1)].m_Number;
|
|
||||||
sides[1][1]=pSwitch[(x+1)+pTileMap->m_Width*(y+1)].m_Number;
|
|
||||||
sides[2][1]=pSwitch[(x+1)+pTileMap->m_Width*(y)].m_Number;
|
|
||||||
sides[3][1]=pSwitch[(x+1)+pTileMap->m_Width*(y-1)].m_Number;
|
|
||||||
sides[4][1]=pSwitch[(x)+pTileMap->m_Width*(y-1)].m_Number;
|
|
||||||
sides[5][1]=pSwitch[(x-1)+pTileMap->m_Width*(y-1)].m_Number;
|
|
||||||
sides[6][1]=pSwitch[(x-1)+pTileMap->m_Width*(y)].m_Number;
|
|
||||||
sides[7][1]=pSwitch[(x-1)+pTileMap->m_Width*(y+1)].m_Number;
|
|
||||||
for(int i=0; i<8;i++)
|
|
||||||
if ((sides[i][0] >= ENTITY_LASER_SHORT && sides[i][0] <= ENTITY_LASER_LONG) && Collision()->SwitchLayer()[y*pTileMap->m_Width+x].m_Number == sides[i][1])
|
|
||||||
{
|
|
||||||
vec2 Pos(x*32.0f+16.0f, y*32.0f+16.0f);
|
|
||||||
m_SDoors[num].m_Address = new CDoor(&m_World, Pos, pi/4*i, (32*3 + 32*(sides[i][0] - ENTITY_LASER_SHORT)*3), false);
|
|
||||||
m_SDoors[num].m_Pos = Pos;
|
|
||||||
m_SDoors[num++].m_Number = Collision()->SwitchLayer()[y*pTileMap->m_Width+x].m_Number;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int y = 0; y < pTileMap->m_Height; y++)
|
for(int y = 0; y < pTileMap->m_Height; y++)
|
||||||
{
|
{
|
||||||
|
@ -2073,14 +2010,14 @@ void CGameContext::OnInit(/*class IKernel *pKernel*/)
|
||||||
m_pController->OnEntity(Index-ENTITY_OFFSET, Pos,true);
|
m_pController->OnEntity(Index-ENTITY_OFFSET, Pos,true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pSwitch)
|
if (m_pSwitch)
|
||||||
{
|
{
|
||||||
int Index = pSwitch[y*pTileMap->m_Width+x].m_Type - ENTITY_OFFSET;
|
int Index = m_pSwitch[y*pTileMap->m_Width+x].m_Type - ENTITY_OFFSET;
|
||||||
vec2 Pos(x*32.0f+16.0f, y*32.0f+16.0f);
|
vec2 Pos(x*32.0f+16.0f, y*32.0f+16.0f);
|
||||||
if(Index == ENTITY_TRIGGER)
|
if(Index == ENTITY_TRIGGER)
|
||||||
for(int i=0;i<m_Size;i++)
|
for(int i=0;i<((CGameControllerDDRace *)m_pController)->m_Size;i++)
|
||||||
if(m_SDoors[i].m_Number == pSwitch[y*pTileMap->m_Width+x].m_Number)
|
if(((CGameControllerDDRace *)m_pController)->m_SDoors[i].m_Number == m_pSwitch[y*pTileMap->m_Width+x].m_Number)
|
||||||
new CTrigger(&m_World,Pos, m_SDoors[i].m_Address);
|
new CTrigger(&m_World,Pos, ((CGameControllerDDRace *)m_pController)->m_SDoors[i].m_Address);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,6 +114,7 @@ public:
|
||||||
IServer *Server() const { return m_pServer; }
|
IServer *Server() const { return m_pServer; }
|
||||||
class IConsole *Console() { return m_pConsole; }
|
class IConsole *Console() { return m_pConsole; }
|
||||||
CCollision *Collision() { return &m_Collision; }
|
CCollision *Collision() { return &m_Collision; }
|
||||||
|
CLayers *Layers() { return &m_Layers; }
|
||||||
CTuningParams *Tuning() { return &m_Tuning; }
|
CTuningParams *Tuning() { return &m_Tuning; }
|
||||||
|
|
||||||
class IScore *Score() { return m_pScore; }
|
class IScore *Score() { return m_pScore; }
|
||||||
|
@ -128,17 +129,7 @@ public:
|
||||||
|
|
||||||
IGameController *m_pController;
|
IGameController *m_pController;
|
||||||
CGameWorld m_World;
|
CGameWorld m_World;
|
||||||
int m_Size;
|
CTeleTile *m_pSwitch;
|
||||||
|
|
||||||
struct SDoors
|
|
||||||
{
|
|
||||||
int m_Number;
|
|
||||||
vec2 m_Pos;
|
|
||||||
CDoor * m_Address;
|
|
||||||
};
|
|
||||||
|
|
||||||
SDoors* m_SDoors;
|
|
||||||
|
|
||||||
// helper functions
|
// helper functions
|
||||||
class CCharacter *GetPlayerChar(int ClientId);
|
class CCharacter *GetPlayerChar(int ClientId);
|
||||||
|
|
||||||
|
|
|
@ -52,3 +52,73 @@ void CGameControllerDDRace::InitTeleporter()
|
||||||
m_pTeleporter[GameServer()->Collision()->TeleLayer()[i].m_Number-1] = vec2(i%GameServer()->Collision()->Layers()->TeleLayer()->m_Width*32+16, i/GameServer()->Collision()->Layers()->TeleLayer()->m_Width*32+16);
|
m_pTeleporter[GameServer()->Collision()->TeleLayer()[i].m_Number-1] = vec2(i%GameServer()->Collision()->Layers()->TeleLayer()->m_Width*32+16, i/GameServer()->Collision()->Layers()->TeleLayer()->m_Width*32+16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CGameControllerDDRace::InitSwitcher()
|
||||||
|
{
|
||||||
|
m_Size = 0;
|
||||||
|
CMapItemLayerTilemap *pTileMap = GameServer()->Layers()->GameLayer();
|
||||||
|
if (GameServer()->m_pSwitch)
|
||||||
|
{
|
||||||
|
for(int y = 0; y < pTileMap->m_Height; y++)
|
||||||
|
for(int x = 0; x < pTileMap->m_Width; x++)
|
||||||
|
{
|
||||||
|
int sides[8][2];
|
||||||
|
sides[0][0]=GameServer()->m_pSwitch[(x)+pTileMap->m_Width*(y+1)].m_Type - ENTITY_OFFSET;
|
||||||
|
sides[1][0]=GameServer()->m_pSwitch[(x+1)+pTileMap->m_Width*(y+1)].m_Type - ENTITY_OFFSET;
|
||||||
|
sides[2][0]=GameServer()->m_pSwitch[(x+1)+pTileMap->m_Width*(y)].m_Type - ENTITY_OFFSET;
|
||||||
|
sides[3][0]=GameServer()->m_pSwitch[(x+1)+pTileMap->m_Width*(y-1)].m_Type - ENTITY_OFFSET;
|
||||||
|
sides[4][0]=GameServer()->m_pSwitch[(x)+pTileMap->m_Width*(y-1)].m_Type - ENTITY_OFFSET;
|
||||||
|
sides[5][0]=GameServer()->m_pSwitch[(x-1)+pTileMap->m_Width*(y-1)].m_Type - ENTITY_OFFSET;
|
||||||
|
sides[6][0]=GameServer()->m_pSwitch[(x-1)+pTileMap->m_Width*(y)].m_Type - ENTITY_OFFSET;
|
||||||
|
sides[7][0]=GameServer()->m_pSwitch[(x-1)+pTileMap->m_Width*(y+1)].m_Type - ENTITY_OFFSET;
|
||||||
|
sides[0][1]=GameServer()->m_pSwitch[(x)+pTileMap->m_Width*(y+1)].m_Number;
|
||||||
|
sides[1][1]=GameServer()->m_pSwitch[(x+1)+pTileMap->m_Width*(y+1)].m_Number;
|
||||||
|
sides[2][1]=GameServer()->m_pSwitch[(x+1)+pTileMap->m_Width*(y)].m_Number;
|
||||||
|
sides[3][1]=GameServer()->m_pSwitch[(x+1)+pTileMap->m_Width*(y-1)].m_Number;
|
||||||
|
sides[4][1]=GameServer()->m_pSwitch[(x)+pTileMap->m_Width*(y-1)].m_Number;
|
||||||
|
sides[5][1]=GameServer()->m_pSwitch[(x-1)+pTileMap->m_Width*(y-1)].m_Number;
|
||||||
|
sides[6][1]=GameServer()->m_pSwitch[(x-1)+pTileMap->m_Width*(y)].m_Number;
|
||||||
|
sides[7][1]=GameServer()->m_pSwitch[(x-1)+pTileMap->m_Width*(y+1)].m_Number;
|
||||||
|
for(int i=0; i<8;i++)
|
||||||
|
if ((sides[i][0] >= ENTITY_LASER_SHORT && sides[i][0] <= ENTITY_LASER_LONG) && GameServer()->Collision()->SwitchLayer()[y*pTileMap->m_Width+x].m_Number == sides[i][1])
|
||||||
|
m_Size++;
|
||||||
|
}
|
||||||
|
if(m_Size)
|
||||||
|
{
|
||||||
|
m_SDoors = new SDoors[m_Size];
|
||||||
|
mem_zero(m_SDoors, m_Size*sizeof(SDoors));
|
||||||
|
int num=0;
|
||||||
|
for(int y = 0; y < pTileMap->m_Height; y++)
|
||||||
|
for(int x = 0; x < pTileMap->m_Width; x++)
|
||||||
|
if(GameServer()->Collision()->SwitchLayer()[y*pTileMap->m_Width+x].m_Type == (ENTITY_DOOR + ENTITY_OFFSET))
|
||||||
|
{
|
||||||
|
int sides[8][2];
|
||||||
|
sides[0][0]=GameServer()->m_pSwitch[(x)+pTileMap->m_Width*(y+1)].m_Type - ENTITY_OFFSET;
|
||||||
|
sides[1][0]=GameServer()->m_pSwitch[(x+1)+pTileMap->m_Width*(y+1)].m_Type - ENTITY_OFFSET;
|
||||||
|
sides[2][0]=GameServer()->m_pSwitch[(x+1)+pTileMap->m_Width*(y)].m_Type - ENTITY_OFFSET;
|
||||||
|
sides[3][0]=GameServer()->m_pSwitch[(x+1)+pTileMap->m_Width*(y-1)].m_Type - ENTITY_OFFSET;
|
||||||
|
sides[4][0]=GameServer()->m_pSwitch[(x)+pTileMap->m_Width*(y-1)].m_Type - ENTITY_OFFSET;
|
||||||
|
sides[5][0]=GameServer()->m_pSwitch[(x-1)+pTileMap->m_Width*(y-1)].m_Type - ENTITY_OFFSET;
|
||||||
|
sides[6][0]=GameServer()->m_pSwitch[(x-1)+pTileMap->m_Width*(y)].m_Type - ENTITY_OFFSET;
|
||||||
|
sides[7][0]=GameServer()->m_pSwitch[(x-1)+pTileMap->m_Width*(y+1)].m_Type - ENTITY_OFFSET;
|
||||||
|
sides[0][1]=GameServer()->m_pSwitch[(x)+pTileMap->m_Width*(y+1)].m_Number;
|
||||||
|
sides[1][1]=GameServer()->m_pSwitch[(x+1)+pTileMap->m_Width*(y+1)].m_Number;
|
||||||
|
sides[2][1]=GameServer()->m_pSwitch[(x+1)+pTileMap->m_Width*(y)].m_Number;
|
||||||
|
sides[3][1]=GameServer()->m_pSwitch[(x+1)+pTileMap->m_Width*(y-1)].m_Number;
|
||||||
|
sides[4][1]=GameServer()->m_pSwitch[(x)+pTileMap->m_Width*(y-1)].m_Number;
|
||||||
|
sides[5][1]=GameServer()->m_pSwitch[(x-1)+pTileMap->m_Width*(y-1)].m_Number;
|
||||||
|
sides[6][1]=GameServer()->m_pSwitch[(x-1)+pTileMap->m_Width*(y)].m_Number;
|
||||||
|
sides[7][1]=GameServer()->m_pSwitch[(x-1)+pTileMap->m_Width*(y+1)].m_Number;
|
||||||
|
for(int i=0; i<8;i++)
|
||||||
|
if ((sides[i][0] >= ENTITY_LASER_SHORT && sides[i][0] <= ENTITY_LASER_LONG) && GameServer()->Collision()->SwitchLayer()[y*pTileMap->m_Width+x].m_Number == sides[i][1])
|
||||||
|
{
|
||||||
|
vec2 Pos(x*32.0f+16.0f, y*32.0f+16.0f);
|
||||||
|
m_SDoors[num].m_Address = new CDoor(&GameServer()->m_World, Pos, pi/4*i, (32*3 + 32*(sides[i][0] - ENTITY_LASER_SHORT)*3), false);
|
||||||
|
m_SDoors[num].m_Pos = Pos;
|
||||||
|
m_SDoors[num++].m_Number = GameServer()->Collision()->SwitchLayer()[y*pTileMap->m_Width+x].m_Number;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
#define DDRACE_H
|
#define DDRACE_H
|
||||||
#include <game/server/gamecontroller.h>
|
#include <game/server/gamecontroller.h>
|
||||||
#include <game/server/score.h>
|
#include <game/server/score.h>
|
||||||
|
#include <game/server/entities/door.h>
|
||||||
|
#include <game/server/entities/trigger.h>
|
||||||
|
|
||||||
class CGameControllerDDRace : public IGameController
|
class CGameControllerDDRace : public IGameController
|
||||||
{
|
{
|
||||||
|
@ -15,6 +17,17 @@ public:
|
||||||
vec2 *m_pTeleporter;
|
vec2 *m_pTeleporter;
|
||||||
|
|
||||||
void InitTeleporter();
|
void InitTeleporter();
|
||||||
|
void InitSwitcher();
|
||||||
|
int m_Size;
|
||||||
|
|
||||||
|
struct SDoors
|
||||||
|
{
|
||||||
|
int m_Number;
|
||||||
|
vec2 m_Pos;
|
||||||
|
CDoor * m_Address;
|
||||||
|
};
|
||||||
|
|
||||||
|
SDoors* m_SDoors;
|
||||||
|
|
||||||
virtual void Tick();
|
virtual void Tick();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue