mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Clean up Doors and Teleport initialization.
This commit is contained in:
parent
b1cadd2d4d
commit
6969851ca3
|
@ -2411,9 +2411,11 @@ void CGameContext::OnInit(/*class IKernel *pKernel*/)
|
|||
if (m_Layers.FrontLayer())
|
||||
pFront = (CTile *)Kernel()->RequestInterface<IMap>()->GetData(pTileMap->m_Front);
|
||||
m_pSwitch=0;
|
||||
if (m_Layers.SwitchLayer())
|
||||
if (m_Layers.SwitchLayer()) {
|
||||
m_pSwitch = (CTeleTile *)Kernel()->RequestInterface<IMap>()->GetData(pTileMap->m_Switch);
|
||||
((CGameControllerDDRace *)m_pController)->InitSwitcher();
|
||||
}
|
||||
|
||||
|
||||
for(int y = 0; y < pTileMap->m_Height; y++)
|
||||
{
|
||||
|
@ -2450,15 +2452,6 @@ void CGameContext::OnInit(/*class IKernel *pKernel*/)
|
|||
m_pController->OnEntity(Index-ENTITY_OFFSET, Pos,true);
|
||||
}
|
||||
}
|
||||
if (m_pSwitch)
|
||||
{
|
||||
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);
|
||||
if(Index == ENTITY_TRIGGER)
|
||||
for(int i=0;i<((CGameControllerDDRace *)m_pController)->m_Size;i++)
|
||||
if(((CGameControllerDDRace *)m_pController)->m_SDoors[i].m_Number == m_pSwitch[y*pTileMap->m_Width+x].m_Number)
|
||||
new CTrigger(&m_World,Pos, ((CGameControllerDDRace *)m_pController)->m_SDoors[i].m_Address);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <game/server/gamecontext.h>
|
||||
#include "DDRace.h"
|
||||
|
||||
CGameControllerDDRace::CGameControllerDDRace(class CGameContext *pGameServer) : IGameController(pGameServer), m_Teams(pGameServer)
|
||||
CGameControllerDDRace::CGameControllerDDRace(class CGameContext *pGameServer) : IGameController(pGameServer), m_Teams(pGameServer), m_SDoors(50)
|
||||
{
|
||||
m_pGameType = "DDRace";
|
||||
|
||||
|
@ -37,6 +37,8 @@ void CGameControllerDDRace::InitTeleporter()
|
|||
if(GameServer()->Collision()->TeleLayer()[i].m_Number > m_ArraySize)
|
||||
m_ArraySize = GameServer()->Collision()->TeleLayer()[i].m_Number;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!m_ArraySize)
|
||||
|
@ -68,12 +70,12 @@ void CGameControllerDDRace::InitTeleporter()
|
|||
m_TotalTele++;
|
||||
}
|
||||
}
|
||||
m_pTele1D = new vec2[m_TotalTele];
|
||||
mem_zero(m_pTele1D, m_TotalTele*sizeof(vec2));
|
||||
//m_pTele1D = new vec2[m_TotalTele];
|
||||
//mem_zero(m_pTele1D, m_TotalTele*sizeof(vec2));
|
||||
|
||||
//Please rewrite this place in next lines you broke all initialization
|
||||
m_pTele2D = (vec2**)m_pTele1D;
|
||||
for (int i = 0; i < m_ArraySize; ++i)
|
||||
m_pTele2D = new vec2 * [m_TotalTele];
|
||||
for (int i = 0; i < m_TotalTele; ++i)
|
||||
{
|
||||
m_pTele2D[i] = new vec2[m_pNumTele[i]];
|
||||
mem_zero(m_pTele2D[i], m_pNumTele[i]*sizeof(vec2));
|
||||
|
@ -81,9 +83,12 @@ void CGameControllerDDRace::InitTeleporter()
|
|||
|
||||
for(int i = 0; i < Width*Height; i++)
|
||||
{
|
||||
if(GameServer()->Collision()->TeleLayer()[i].m_Number > 0 && GameServer()->Collision()->TeleLayer()[i].m_Type == TILE_TELEOUT)
|
||||
if(GameServer()->Collision()->TeleLayer()[i].m_Number > 0
|
||||
&& GameServer()->Collision()->TeleLayer()[i].m_Type == TILE_TELEOUT)
|
||||
{
|
||||
m_pTele2D[GameServer()->Collision()->TeleLayer()[i].m_Number-1][--Count[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_pTele2D[GameServer()->Collision()->TeleLayer()[i].m_Number-1][--Count[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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -95,7 +100,11 @@ void CGameControllerDDRace::InitSwitcher()
|
|||
if (GameServer()->m_pSwitch)
|
||||
{
|
||||
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;
|
||||
|
@ -114,46 +123,42 @@ void CGameControllerDDRace::InitSwitcher()
|
|||
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])
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
SDoors tmp;
|
||||
tmp.m_Pos = Pos;
|
||||
tmp.m_Address = new CDoor(
|
||||
&GameServer()->m_World,
|
||||
Pos,
|
||||
pi/4*i,
|
||||
(32*3 + 32*(sides[i][0] - ENTITY_LASER_SHORT)*3),
|
||||
false);
|
||||
tmp.m_Number = GameServer()->Collision()->SwitchLayer()[y*pTileMap->m_Width+x].m_Number;
|
||||
m_SDoors.push_back(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int y = 0; y < pTileMap->m_Height; y++)
|
||||
{
|
||||
for(int x = 0; x < pTileMap->m_Width; x++)
|
||||
{
|
||||
if(GameServer()->m_pSwitch[y*pTileMap->m_Width+x].m_Type - ENTITY_OFFSET == ENTITY_TRIGGER) {
|
||||
for(int i = 0; i < m_SDoors.size(); ++i) {
|
||||
if(m_SDoors[i].m_Number == GameServer()->m_pSwitch[y*pTileMap->m_Width+x].m_Number) {
|
||||
new CTrigger(
|
||||
&GameServer()->m_World,
|
||||
vec2(x*32.0f+16.0f, y*32.0f+16.0f),
|
||||
m_SDoors[i].m_Address);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#include <game/server/entities/door.h>
|
||||
#include <game/server/entities/trigger.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
class CGameControllerDDRace : public IGameController
|
||||
{
|
||||
|
@ -34,7 +36,7 @@ public:
|
|||
CDoor * m_Address;
|
||||
};
|
||||
|
||||
SDoors* m_SDoors;
|
||||
std::vector < SDoors > m_SDoors;
|
||||
|
||||
virtual void Tick();
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue