Add Door, connector and trigger. Not tested i need work.

Signed-off-by: btd <bardadymchik@gmail.com>
This commit is contained in:
btd 2010-08-11 14:33:37 +04:00
parent afa93fb203
commit 2cf2a5b1d2
7 changed files with 232 additions and 44 deletions

View file

@ -67,7 +67,7 @@ enum
ENTITY_CRAZY_SHOTGUN_L, ENTITY_CRAZY_SHOTGUN_L,
//DDrace - Doors //DDrace - Doors
ENTITY_DOOR, ENTITY_DOOR,
ENTITY_CONNECTOR_D, ENTITY_CONNECTOR_D,//TODO: in ddrace stable used this one no need others rename ENTITY_CONNECTOR
ENTITY_CONNECTOR_DR, ENTITY_CONNECTOR_DR,
ENTITY_CONNECTOR_R, ENTITY_CONNECTOR_R,
ENTITY_CONNECTOR_RU, ENTITY_CONNECTOR_RU,

View file

@ -0,0 +1,77 @@
#include <game/generated/protocol.h>
#include <game/server/gamecontext.h>
#include <engine/shared/config.h>
#include "door.h"
CDoor::CDoor(GameWorld *pGameWorld, vec2 Pos, float Rotation, int Length, bool Opened)
: CEntity(pGameWorld, NETOBJTYPE_LASER)
{
m_Pos = Pos;
m_Opened = Opened;
vec2 Dir = vec2(sin(rotation), cos(rotation));
vec2 To = Pos + normalize(Dir)*Length;
GameServer()->Collision()->IntersectCharacter(Pos, To, &this->m_To, 0);
GameWorld()->InsertEntity(this);
}
void CDoor::Open(int Tick)
{
m_EvalTick = Tick;
m_Opened = true;
}
void CDoor::Close()
{
m_Opened = false;
}
bool CDoor::HitCharacter()
{
vec2 At;
CCharacter *Hit = GameServer()->m_World.IntersectCharacter(m_Pos, m_To, 1.f, At, 0);
if(!Hit)
return false;
Hit->m_Doored = true;
//hit->reset_pos();
return true;
}
void CDoor::Reset()
{
m_Opened = false;
}
void CDoor::Tick()
{
if (!m_Opened)
HitCharacter();
else if (m_EvalTick + 10 < Server()->Tick())
Close();
return;
}
void CDoor::Snap(int SnappingClient)
{
if(NetworkClipped(SnappingClient, m_Pos) && NetworkClipped(SnappingClient, m_To))
return;
CNetObj_Laser *pObj = static_cast<CNetObj_Laser *>(Server()->SnapNewItem(NETOBJTYPE_LASER, m_Id, sizeof(CNetObj_Laser)));
pObj->m_X = (int)m_Pos.x;
pObj->m_Y = (int)m_Pos.y;
if (!m_Opened)
{
pObj->m_FromX = (int)m_To.x;
pObj->m_FromY = (int)m_To.y;
}
else
{
pObj->m_FromX = (int)m_Pos.x;
pObj->m_FromY = (int)m_Pos.y;
}
pObj->m_StartTick = Server()->Tick();
}

View file

@ -0,0 +1,26 @@
#ifndef GAME_SERVER_ENTITY_DOOR_H
#define GAME_SERVER_ENTITY_DOOR_H
#include <game/server/entity.h>
class CTrigger;
class CDoor : public CEntity
{
vec2 m_To;
int m_EvalTick;
bool m_Opened;
bool HitCharacter();
public:
void Open(int Tick);
void Close();
CDoor(GameWorld *pGameWorld, vec2 Pos, float Rotation, int Length, bool Opened);
virtual void Reset();
virtual void Tick();
virtual void Snap(int SnappingClient);
};
#endif

View file

@ -0,0 +1,50 @@
/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
#include <game/generated/protocol.h>
#include <game/server/gamecontext.h>
#include "trigger.h"
#include "door.h"
//////////////////////////////////////////////////
// DOOR
//////////////////////////////////////////////////
CTrigger::CTrigger(CGameWorld *pGameWorld, vec2 Pos, CEntity *Target)
: CEntity(pGameWorld, NETOBJTYPE_PICKUP)
{
m_Pos = Pos;
m_Target = Target;
GameWorld()->InsertEntity(this);
}
bool CTrigger::HitCharacter()
{
CCharacter *pChr = GameServer()->m_World.ClosestCharacter(m_Pos, 20.0f, 0);
return (!pChr) ? false : true;
}
void CTrigger::OpenDoor(int Tick)
{
CDoor *connectedDoor = (CDoor*) Target;
connectedDoor->Open(Tick);
}
void CTrigger::Reset()
{
return;
}
void CTrigger::Tick()
{
if (Server()->Tick() % 10 == 0)
{
if (HitCharacter())
OpenDoor(Server()->Tick());
}
return;
}
void CTrigger::Snap(int SnappingClient)
{
return;
}

View file

@ -0,0 +1,26 @@
/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
#ifndef GAME_SERVER_ENTITY_TRIGGER_H
#define GAME_SERVER_ENTITY_TRIGGER_H
#include <game/server/entity.hpp>
//class DOOR;
class CTrigger : public CEntity
{
CEntity *m_Target;
bool HitCharacter();
void OpenDoor(int Tick);
public:
CTrigger(CGameWorld *pGameWorld, vec2 Pos, CEntity *Target);
virtual void Reset();
virtual void Tick();
virtual void Snap(int SnappingClient);
};
#endif

View file

@ -139,6 +139,21 @@ bool IGameController::OnEntity(int Index, vec2 Pos)
m_aaSpawnPoints[1][m_aNumSpawnPoints[1]++] = Pos; m_aaSpawnPoints[1][m_aNumSpawnPoints[1]++] = Pos;
else if(Index == ENTITY_SPAWN_BLUE) else if(Index == ENTITY_SPAWN_BLUE)
m_aaSpawnPoints[2][m_aNumSpawnPoints[2]++] = Pos; m_aaSpawnPoints[2][m_aNumSpawnPoints[2]++] = Pos;
if(Index == ENTITY_DOOR)
{
for(int i=0; i<8;i++)
{
if (sides[i] >= ENTITY_LASER_SHORT && sides[i] <= ENTITY_LASER_LONG)
{
CDoor * door = new CDoor(&GameServer()->m_World, Pos, pi/4*i, 32*3 + 32*(sides[i] - ENTITY_LASER_SHORT)*3, false);
for (int j = 0; j < 8; j++)
if (j != i)
Connector(Pos, door);
}
}
}
if(Index == ENTITY_ARMOR_1) if(Index == ENTITY_ARMOR_1)
Type = POWERUP_ARMOR; Type = POWERUP_ARMOR;
else if(Index == ENTITY_HEALTH_1) else if(Index == ENTITY_HEALTH_1)
@ -165,7 +180,7 @@ bool IGameController::OnEntity(int Index, vec2 Pos)
} }
else if(Index >= ENTITY_LASER_FAST_CW && Index <= ENTITY_LASER_FAST_CCW) else if(Index >= ENTITY_LASER_FAST_CW && Index <= ENTITY_LASER_FAST_CCW)
{ {
int sides2[8]; int sides2[8]; //TODO it seem that every time GetIndex take the same arguments
sides2[0]=GameServer()->Collision()->GetIndex(vec2(Pos.x,Pos.y+2),vec2(Pos.x,Pos.y+2)); sides2[0]=GameServer()->Collision()->GetIndex(vec2(Pos.x,Pos.y+2),vec2(Pos.x,Pos.y+2));
sides2[1]=GameServer()->Collision()->GetIndex(vec2(Pos.x+2,Pos.y+2),vec2(Pos.x+2,Pos.y+2)); sides2[1]=GameServer()->Collision()->GetIndex(vec2(Pos.x+2,Pos.y+2),vec2(Pos.x+2,Pos.y+2));
sides2[2]=GameServer()->Collision()->GetIndex(vec2(Pos.x+2,Pos.y),vec2(Pos.x+2,Pos.y)); sides2[2]=GameServer()->Collision()->GetIndex(vec2(Pos.x+2,Pos.y),vec2(Pos.x+2,Pos.y));
@ -244,6 +259,27 @@ bool IGameController::OnEntity(int Index, vec2 Pos)
return false; return false;
} }
void Connector(vec2 Pos, CDoor* Door) {
int Sides[8];
Sides[0]=GameServer()->Collision()->GetIndex(vec2(Pos.x,Pos.y+1),vec2(Pos.x,Pos.y+1));
Sides[1]=GameServer()->Collision()->GetIndex(vec2(Pos.x+1,Pos.y+1),vec2(Pos.x+1,Pos.y+1));
Sides[2]=GameServer()->Collision()->GetIndex(vec2(Pos.x+1,Pos.y),vec2(Pos.x+1,Pos.y));
Sides[3]=GameServer()->Collision()->GetIndex(vec2(Pos.x+1,Pos.y-1),vec2(Pos.x+1,Pos.y-1));
Sides[4]=GameServer()->Collision()->GetIndex(vec2(Pos.x,Pos.y-1),vec2(Pos.x,Pos.y-1));
Sides[5]=GameServer()->Collision()->GetIndex(vec2(Pos.x-1,Pos.y-1),vec2(Pos.x-1,Pos.y-1));
Sides[6]=GameServer()->Collision()->GetIndex(vec2(Pos.x-1,Pos.y),vec2(Pos.x-1,Pos.y));
Sides[7]=GameServer()->Collision()->GetIndex(vec2(Pos.x-1,Pos.y+1),vec2(Pos.x-1,Pos.y+1));
for (int i = 0;i < 8;i++)
{
if (Sides[i] == ENTITY_CONNECTOR_D + (i + 4) % 8) {
Connector(Pos + GetSidePos(i), Door);
} else if(Sides[i] == ENTITY_TRIGGER)
{
new CTrigger(Pos, Target);
}
}
}
void IGameController::EndRound() void IGameController::EndRound()
{ {
if(m_Warmup) // game can't end when we are running warmup if(m_Warmup) // game can't end when we are running warmup
@ -266,50 +302,21 @@ const char *IGameController::GetTeamName(int Team)
return "spectators"; return "spectators";
} }
void get_side_pos(int side, int &x, int &y) { vec2 GetSidePos(int side) {
if (side==0) switch(side)
{ {
x=0; case 0: return vec2(0, 1);
y=1; case 1: return vec2(1, 1);
} case 2: return vec2(1, 0);
else if(side==1) case 3: return vec2(1, -1);
{ case 4: return vec2(0, -1);
x=1; case 5: return vec2(-1, -1);
y=1; case 6: return vec2(-1, 0);
} case 7: return vec2(-1, 1);
else if(side==2) default:
{ vec2(0, 0);
x=1;
y=0;
} }
else if(side==3)
{
x=1;
y=-1;
}
else if(side==4)
{
x=0;
y=-1;
}
else if(side==5)
{
x=-1;
y=-1;
}
else if(side==6)
{
x=-1;
y=0;
}
else if(side==7)
{
x=-1;
y=+1;
}
} }
bool IsSeparator(char c) { return c == ';' || c == ' ' || c == ',' || c == '\t'; } bool IsSeparator(char c) { return c == ';' || c == ' ' || c == ',' || c == '\t'; }

View file

@ -101,6 +101,8 @@ public:
*/ */
virtual bool OnEntity(int Index, vec2 Pos); virtual bool OnEntity(int Index, vec2 Pos);
virtual void Connector(vec2 Pos, CDoor* Door);
/* /*
Function: on_CCharacter_spawn Function: on_CCharacter_spawn
Called when a CCharacter spawns into the game world. Called when a CCharacter spawns into the game world.