mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
refactored CEntity
This commit is contained in:
parent
453f720212
commit
e86a486688
|
@ -5,6 +5,8 @@
|
|||
|
||||
#include <new>
|
||||
|
||||
#include <base/system.h>
|
||||
|
||||
#define MACRO_ALLOC_HEAP() \
|
||||
public: \
|
||||
void *operator new(size_t Size) \
|
||||
|
|
|
@ -42,9 +42,8 @@ MACRO_ALLOC_POOL_ID_IMPL(CCharacter, MAX_CLIENTS)
|
|||
|
||||
// Character, "physical" player's part
|
||||
CCharacter::CCharacter(CGameWorld *pWorld)
|
||||
: CEntity(pWorld, CGameWorld::ENTTYPE_CHARACTER)
|
||||
: CEntity(pWorld, CGameWorld::ENTTYPE_CHARACTER, vec2(0, 0), ms_PhysSize)
|
||||
{
|
||||
m_ProximityRadius = ms_PhysSize;
|
||||
m_Health = 0;
|
||||
m_Armor = 0;
|
||||
m_TriggeredEvents = 0;
|
||||
|
@ -107,9 +106,9 @@ void CCharacter::SetWeapon(int W)
|
|||
|
||||
bool CCharacter::IsGrounded()
|
||||
{
|
||||
if(GameServer()->Collision()->CheckPoint(m_Pos.x+m_ProximityRadius/2, m_Pos.y+m_ProximityRadius/2+5))
|
||||
if(GameServer()->Collision()->CheckPoint(m_Pos.x+GetProximityRadius()/2, m_Pos.y+GetProximityRadius()/2+5))
|
||||
return true;
|
||||
if(GameServer()->Collision()->CheckPoint(m_Pos.x-m_ProximityRadius/2, m_Pos.y+m_ProximityRadius/2+5))
|
||||
if(GameServer()->Collision()->CheckPoint(m_Pos.x-GetProximityRadius()/2, m_Pos.y+GetProximityRadius()/2+5))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
@ -150,7 +149,7 @@ void CCharacter::HandleNinja()
|
|||
// Set velocity
|
||||
m_Core.m_Vel = m_Ninja.m_ActivationDir * g_pData->m_Weapons.m_Ninja.m_Velocity;
|
||||
vec2 OldPos = m_Pos;
|
||||
GameServer()->Collision()->MoveBox(&m_Core.m_Pos, &m_Core.m_Vel, vec2(m_ProximityRadius, m_ProximityRadius), 0.f);
|
||||
GameServer()->Collision()->MoveBox(&m_Core.m_Pos, &m_Core.m_Vel, vec2(GetProximityRadius(), GetProximityRadius()), 0.f);
|
||||
|
||||
// reset velocity so the client doesn't predict stuff
|
||||
m_Core.m_Vel = vec2(0.f, 0.f);
|
||||
|
@ -159,7 +158,7 @@ void CCharacter::HandleNinja()
|
|||
{
|
||||
CCharacter *aEnts[MAX_CLIENTS];
|
||||
vec2 Dir = m_Pos - OldPos;
|
||||
float Radius = m_ProximityRadius * 2.0f;
|
||||
float Radius = GetProximityRadius() * 2.0f;
|
||||
vec2 Center = OldPos + Dir * 0.5f;
|
||||
int Num = GameServer()->m_World.FindEntities(Center, Radius, (CEntity**)aEnts, MAX_CLIENTS, CGameWorld::ENTTYPE_CHARACTER);
|
||||
|
||||
|
@ -179,7 +178,7 @@ void CCharacter::HandleNinja()
|
|||
continue;
|
||||
|
||||
// check so we are sufficiently close
|
||||
if (distance(aEnts[i]->m_Pos, m_Pos) > (m_ProximityRadius * 2.0f))
|
||||
if (distance(aEnts[i]->m_Pos, m_Pos) > (GetProximityRadius() * 2.0f))
|
||||
continue;
|
||||
|
||||
// Hit a player, give him damage and stuffs...
|
||||
|
@ -287,7 +286,7 @@ void CCharacter::FireWeapon()
|
|||
return;
|
||||
}
|
||||
|
||||
vec2 ProjStartPos = m_Pos+Direction*m_ProximityRadius*0.75f;
|
||||
vec2 ProjStartPos = m_Pos+Direction*GetProximityRadius()*0.75f;
|
||||
|
||||
switch(m_ActiveWeapon)
|
||||
{
|
||||
|
@ -299,7 +298,7 @@ void CCharacter::FireWeapon()
|
|||
|
||||
CCharacter *apEnts[MAX_CLIENTS];
|
||||
int Hits = 0;
|
||||
int Num = GameServer()->m_World.FindEntities(ProjStartPos, m_ProximityRadius*0.5f, (CEntity**)apEnts,
|
||||
int Num = GameServer()->m_World.FindEntities(ProjStartPos, GetProximityRadius()*0.5f, (CEntity**)apEnts,
|
||||
MAX_CLIENTS, CGameWorld::ENTTYPE_CHARACTER);
|
||||
|
||||
for (int i = 0; i < Num; ++i)
|
||||
|
@ -311,7 +310,7 @@ void CCharacter::FireWeapon()
|
|||
|
||||
// set his velocity to fast upward (for now)
|
||||
if(length(pTarget->m_Pos-ProjStartPos) > 0.0f)
|
||||
GameServer()->CreateHammerHit(pTarget->m_Pos-normalize(pTarget->m_Pos-ProjStartPos)*m_ProximityRadius*0.5f);
|
||||
GameServer()->CreateHammerHit(pTarget->m_Pos-normalize(pTarget->m_Pos-ProjStartPos)*GetProximityRadius()*0.5f);
|
||||
else
|
||||
GameServer()->CreateHammerHit(ProjStartPos);
|
||||
|
||||
|
@ -530,10 +529,10 @@ void CCharacter::Tick()
|
|||
m_Core.Tick(true);
|
||||
|
||||
// handle death-tiles and leaving gamelayer
|
||||
if(GameServer()->Collision()->GetCollisionAt(m_Pos.x+m_ProximityRadius/3.f, m_Pos.y-m_ProximityRadius/3.f)&CCollision::COLFLAG_DEATH ||
|
||||
GameServer()->Collision()->GetCollisionAt(m_Pos.x+m_ProximityRadius/3.f, m_Pos.y+m_ProximityRadius/3.f)&CCollision::COLFLAG_DEATH ||
|
||||
GameServer()->Collision()->GetCollisionAt(m_Pos.x-m_ProximityRadius/3.f, m_Pos.y-m_ProximityRadius/3.f)&CCollision::COLFLAG_DEATH ||
|
||||
GameServer()->Collision()->GetCollisionAt(m_Pos.x-m_ProximityRadius/3.f, m_Pos.y+m_ProximityRadius/3.f)&CCollision::COLFLAG_DEATH ||
|
||||
if(GameServer()->Collision()->GetCollisionAt(m_Pos.x+GetProximityRadius()/3.f, m_Pos.y-GetProximityRadius()/3.f)&CCollision::COLFLAG_DEATH ||
|
||||
GameServer()->Collision()->GetCollisionAt(m_Pos.x+GetProximityRadius()/3.f, m_Pos.y+GetProximityRadius()/3.f)&CCollision::COLFLAG_DEATH ||
|
||||
GameServer()->Collision()->GetCollisionAt(m_Pos.x-GetProximityRadius()/3.f, m_Pos.y-GetProximityRadius()/3.f)&CCollision::COLFLAG_DEATH ||
|
||||
GameServer()->Collision()->GetCollisionAt(m_Pos.x-GetProximityRadius()/3.f, m_Pos.y+GetProximityRadius()/3.f)&CCollision::COLFLAG_DEATH ||
|
||||
GameLayerClipped(m_Pos))
|
||||
{
|
||||
Die(m_pPlayer->GetCID(), WEAPON_WORLD);
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
#ifndef GAME_SERVER_ENTITIES_CHARACTER_H
|
||||
#define GAME_SERVER_ENTITIES_CHARACTER_H
|
||||
|
||||
#include <generated/protocol.h>
|
||||
|
||||
#include <game/gamecore.h>
|
||||
#include <game/server/entity.h>
|
||||
|
||||
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
/* (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. */
|
||||
#include <game/server/gamecontext.h>
|
||||
#include <game/server/gamecontroller.h>
|
||||
|
||||
#include "character.h"
|
||||
#include "flag.h"
|
||||
|
||||
CFlag::CFlag(CGameWorld *pGameWorld, int Team)
|
||||
: CEntity(pGameWorld, CGameWorld::ENTTYPE_FLAG)
|
||||
CFlag::CFlag(CGameWorld *pGameWorld, int Team, vec2 StandPos)
|
||||
: CEntity(pGameWorld, CGameWorld::ENTTYPE_FLAG, StandPos, ms_PhysSize)
|
||||
{
|
||||
m_Team = Team;
|
||||
m_ProximityRadius = ms_PhysSize;
|
||||
m_pCarryingCharacter = NULL;
|
||||
m_StandPos = StandPos;
|
||||
m_GrabTick = 0;
|
||||
|
||||
Reset();
|
||||
|
@ -21,15 +22,48 @@ void CFlag::Reset()
|
|||
m_pCarryingCharacter = NULL;
|
||||
m_AtStand = 1;
|
||||
m_Pos = m_StandPos;
|
||||
m_Vel = vec2(0,0);
|
||||
m_Vel = vec2(0, 0);
|
||||
m_GrabTick = 0;
|
||||
}
|
||||
|
||||
void CFlag::Tick()
|
||||
{
|
||||
if(m_pCarryingCharacter)
|
||||
{
|
||||
// update flag position
|
||||
m_Pos = m_pCarryingCharacter->GetPos();
|
||||
}
|
||||
else
|
||||
{
|
||||
// flag hits death-tile or left the game layer, reset it
|
||||
if((GameServer()->Collision()->GetCollisionAt(m_Pos.x, m_Pos.y) & CCollision::COLFLAG_DEATH)
|
||||
|| GameLayerClipped(m_Pos))
|
||||
{
|
||||
Reset();
|
||||
GameServer()->m_pController->OnFlagReturn(this);
|
||||
}
|
||||
|
||||
if(!m_AtStand)
|
||||
{
|
||||
if(Server()->Tick() > m_DropTick + Server()->TickSpeed()*30)
|
||||
{
|
||||
Reset();
|
||||
GameServer()->m_pController->OnFlagReturn(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Vel.y += GameServer()->m_World.m_Core.m_Tuning.m_Gravity;
|
||||
GameServer()->Collision()->MoveBox(&m_Pos, &m_Vel, vec2(ms_PhysSize, ms_PhysSize), 0.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CFlag::TickPaused()
|
||||
{
|
||||
++m_DropTick;
|
||||
m_DropTick++;
|
||||
if(m_GrabTick)
|
||||
++m_GrabTick;
|
||||
m_GrabTick++;
|
||||
}
|
||||
|
||||
void CFlag::Snap(int SnappingClient)
|
||||
|
|
|
@ -18,11 +18,12 @@ public:
|
|||
int m_DropTick;
|
||||
int m_GrabTick;
|
||||
|
||||
CFlag(CGameWorld *pGameWorld, int Team);
|
||||
CFlag(CGameWorld *pGameWorld, int Team, vec2 StandPos);
|
||||
|
||||
virtual void Reset();
|
||||
virtual void TickPaused();
|
||||
virtual void Snap(int SnappingClient);
|
||||
virtual void Tick();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -7,9 +7,8 @@
|
|||
#include "laser.h"
|
||||
|
||||
CLaser::CLaser(CGameWorld *pGameWorld, vec2 Pos, vec2 Direction, float StartEnergy, int Owner)
|
||||
: CEntity(pGameWorld, CGameWorld::ENTTYPE_LASER)
|
||||
: CEntity(pGameWorld, CGameWorld::ENTTYPE_LASER, Pos)
|
||||
{
|
||||
m_Pos = Pos;
|
||||
m_Owner = Owner;
|
||||
m_Energy = StartEnergy;
|
||||
m_Dir = Direction;
|
||||
|
@ -103,7 +102,7 @@ void CLaser::Snap(int SnappingClient)
|
|||
if(NetworkClipped(SnappingClient))
|
||||
return;
|
||||
|
||||
CNetObj_Laser *pObj = static_cast<CNetObj_Laser *>(Server()->SnapNewItem(NETOBJTYPE_LASER, m_ID, sizeof(CNetObj_Laser)));
|
||||
CNetObj_Laser *pObj = static_cast<CNetObj_Laser *>(Server()->SnapNewItem(NETOBJTYPE_LASER, GetID(), sizeof(CNetObj_Laser)));
|
||||
if(!pObj)
|
||||
return;
|
||||
|
||||
|
|
|
@ -7,11 +7,10 @@
|
|||
#include "character.h"
|
||||
#include "pickup.h"
|
||||
|
||||
CPickup::CPickup(CGameWorld *pGameWorld, int Type)
|
||||
: CEntity(pGameWorld, CGameWorld::ENTTYPE_PICKUP)
|
||||
CPickup::CPickup(CGameWorld *pGameWorld, int Type, vec2 Pos)
|
||||
: CEntity(pGameWorld, CGameWorld::ENTTYPE_PICKUP, Pos, PickupPhysSize)
|
||||
{
|
||||
m_Type = Type;
|
||||
m_ProximityRadius = PickupPhysSize;
|
||||
|
||||
Reset();
|
||||
|
||||
|
@ -140,7 +139,7 @@ void CPickup::Snap(int SnappingClient)
|
|||
if(m_SpawnTick != -1 || NetworkClipped(SnappingClient))
|
||||
return;
|
||||
|
||||
CNetObj_Pickup *pP = static_cast<CNetObj_Pickup *>(Server()->SnapNewItem(NETOBJTYPE_PICKUP, m_ID, sizeof(CNetObj_Pickup)));
|
||||
CNetObj_Pickup *pP = static_cast<CNetObj_Pickup *>(Server()->SnapNewItem(NETOBJTYPE_PICKUP, GetID(), sizeof(CNetObj_Pickup)));
|
||||
if(!pP)
|
||||
return;
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ const int PickupPhysSize = 14;
|
|||
class CPickup : public CEntity
|
||||
{
|
||||
public:
|
||||
CPickup(CGameWorld *pGameWorld, int Type);
|
||||
CPickup(CGameWorld *pGameWorld, int Type, vec2 Pos);
|
||||
|
||||
virtual void Reset();
|
||||
virtual void Tick();
|
||||
|
|
|
@ -7,10 +7,9 @@
|
|||
|
||||
CProjectile::CProjectile(CGameWorld *pGameWorld, int Type, int Owner, vec2 Pos, vec2 Dir, int Span,
|
||||
int Damage, bool Explosive, float Force, int SoundImpact, int Weapon)
|
||||
: CEntity(pGameWorld, CGameWorld::ENTTYPE_PROJECTILE)
|
||||
: CEntity(pGameWorld, CGameWorld::ENTTYPE_PROJECTILE, Pos)
|
||||
{
|
||||
m_Type = Type;
|
||||
m_Pos = Pos;
|
||||
m_Direction = Dir;
|
||||
m_LifeSpan = Span;
|
||||
m_Owner = Owner;
|
||||
|
@ -105,7 +104,7 @@ void CProjectile::Snap(int SnappingClient)
|
|||
if(NetworkClipped(SnappingClient, GetPos(Ct)))
|
||||
return;
|
||||
|
||||
CNetObj_Projectile *pProj = static_cast<CNetObj_Projectile *>(Server()->SnapNewItem(NETOBJTYPE_PROJECTILE, m_ID, sizeof(CNetObj_Projectile)));
|
||||
CNetObj_Projectile *pProj = static_cast<CNetObj_Projectile *>(Server()->SnapNewItem(NETOBJTYPE_PROJECTILE, GetID(), sizeof(CNetObj_Projectile)));
|
||||
if(pProj)
|
||||
FillInfo(pProj);
|
||||
}
|
||||
|
|
|
@ -5,22 +5,20 @@
|
|||
#include "gamecontext.h"
|
||||
#include "player.h"
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// Entity
|
||||
//////////////////////////////////////////////////
|
||||
CEntity::CEntity(CGameWorld *pGameWorld, int ObjType)
|
||||
CEntity::CEntity(CGameWorld *pGameWorld, int ObjType, vec2 Pos, int ProximityRadius)
|
||||
{
|
||||
m_pGameWorld = pGameWorld;
|
||||
|
||||
m_ObjType = ObjType;
|
||||
m_Pos = vec2(0,0);
|
||||
m_ProximityRadius = 0;
|
||||
|
||||
m_MarkedForDestroy = false;
|
||||
m_ID = Server()->SnapNewID();
|
||||
|
||||
m_pPrevTypeEntity = 0;
|
||||
m_pNextTypeEntity = 0;
|
||||
|
||||
m_ID = Server()->SnapNewID();
|
||||
m_ObjType = ObjType;
|
||||
|
||||
m_ProximityRadius = ProximityRadius;
|
||||
|
||||
m_MarkedForDestroy = false;
|
||||
m_Pos = Pos;
|
||||
}
|
||||
|
||||
CEntity::~CEntity()
|
||||
|
@ -52,6 +50,8 @@ int CEntity::NetworkClipped(int SnappingClient, vec2 CheckPos)
|
|||
|
||||
bool CEntity::GameLayerClipped(vec2 CheckPos)
|
||||
{
|
||||
return round_to_int(CheckPos.x)/32 < -200 || round_to_int(CheckPos.x)/32 > GameServer()->Collision()->GetWidth()+200 ||
|
||||
round_to_int(CheckPos.y)/32 < -200 || round_to_int(CheckPos.y)/32 > GameServer()->Collision()->GetHeight()+200 ? true : false;
|
||||
int rx = round_to_int(CheckPos.x) / 32;
|
||||
int ry = round_to_int(CheckPos.y) / 32;
|
||||
return (rx < -200 || rx >= GameServer()->Collision()->GetWidth()+200)
|
||||
|| (ry < -200 || ry >= GameServer()->Collision()->GetHeight()+200);
|
||||
}
|
||||
|
|
|
@ -5,9 +5,8 @@
|
|||
|
||||
#include <base/vmath.h>
|
||||
|
||||
#include <game/server/gameworld.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "gameworld.h"
|
||||
|
||||
/*
|
||||
Class: Entity
|
||||
|
@ -17,50 +16,87 @@ class CEntity
|
|||
{
|
||||
MACRO_ALLOC_HEAP()
|
||||
|
||||
friend class CGameWorld; // entity list handling
|
||||
private:
|
||||
/* Friend classes */
|
||||
friend class CGameWorld; // for entity list handling
|
||||
|
||||
/* Identity */
|
||||
class CGameWorld *m_pGameWorld;
|
||||
|
||||
CEntity *m_pPrevTypeEntity;
|
||||
CEntity *m_pNextTypeEntity;
|
||||
|
||||
class CGameWorld *m_pGameWorld;
|
||||
protected:
|
||||
bool m_MarkedForDestroy;
|
||||
int m_ID;
|
||||
int m_ObjType;
|
||||
public:
|
||||
CEntity(CGameWorld *pGameWorld, int Objtype);
|
||||
virtual ~CEntity();
|
||||
|
||||
class CGameWorld *GameWorld() { return m_pGameWorld; }
|
||||
class CGameContext *GameServer() { return GameWorld()->GameServer(); }
|
||||
class IServer *Server() { return GameWorld()->Server(); }
|
||||
|
||||
|
||||
CEntity *TypeNext() { return m_pNextTypeEntity; }
|
||||
CEntity *TypePrev() { return m_pPrevTypeEntity; }
|
||||
|
||||
/*
|
||||
Function: destroy
|
||||
Destorys the entity.
|
||||
Variable: m_ProximityRadius
|
||||
Contains the physical size of the entity.
|
||||
*/
|
||||
float m_ProximityRadius;
|
||||
|
||||
/* State */
|
||||
bool m_MarkedForDestroy;
|
||||
|
||||
protected:
|
||||
/* State */
|
||||
|
||||
/*
|
||||
Variable: m_Pos
|
||||
Contains the current posititon of the entity.
|
||||
*/
|
||||
vec2 m_Pos;
|
||||
|
||||
/* Getters */
|
||||
int GetID() const { return m_ID; }
|
||||
|
||||
public:
|
||||
/* Constructor */
|
||||
CEntity(CGameWorld *pGameWorld, int Objtype, vec2 Pos, int ProximityRadius=0);
|
||||
|
||||
/* Destructor */
|
||||
virtual ~CEntity();
|
||||
|
||||
/* Objects */
|
||||
class CGameWorld *GameWorld() { return m_pGameWorld; }
|
||||
class CGameContext *GameServer() { return m_pGameWorld->GameServer(); }
|
||||
class IServer *Server() { return m_pGameWorld->Server(); }
|
||||
|
||||
/* Getters */
|
||||
CEntity *TypeNext() { return m_pNextTypeEntity; }
|
||||
CEntity *TypePrev() { return m_pPrevTypeEntity; }
|
||||
const vec2 &GetPos() const { return m_Pos; }
|
||||
float GetProximityRadius() const { return m_ProximityRadius; }
|
||||
bool IsMarkedForDestroy() const { return m_MarkedForDestroy; }
|
||||
|
||||
/* Setters */
|
||||
void MarkForDestroy() { m_MarkedForDestroy = true; }
|
||||
|
||||
/* Other functions */
|
||||
|
||||
/*
|
||||
Function: Destroy
|
||||
Destroys the entity.
|
||||
*/
|
||||
virtual void Destroy() { delete this; }
|
||||
|
||||
/*
|
||||
Function: reset
|
||||
Function: Reset
|
||||
Called when the game resets the map. Puts the entity
|
||||
back to it's starting state or perhaps destroys it.
|
||||
back to its starting state or perhaps destroys it.
|
||||
*/
|
||||
virtual void Reset() {}
|
||||
|
||||
/*
|
||||
Function: tick
|
||||
Called progress the entity to the next tick. Updates
|
||||
and moves the entity to it's new state and position.
|
||||
Function: Tick
|
||||
Called to progress the entity to the next tick. Updates
|
||||
and moves the entity to its new state and position.
|
||||
*/
|
||||
virtual void Tick() {}
|
||||
|
||||
/*
|
||||
Function: tick_defered
|
||||
Called after all entities tick() function has been called.
|
||||
Function: TickDefered
|
||||
Called after all entities Tick() function has been called.
|
||||
*/
|
||||
virtual void TickDefered() {}
|
||||
|
||||
|
@ -71,12 +107,12 @@ public:
|
|||
virtual void TickPaused() {}
|
||||
|
||||
/*
|
||||
Function: snap
|
||||
Function: Snap
|
||||
Called when a new snapshot is being generated for a specific
|
||||
client.
|
||||
|
||||
Arguments:
|
||||
snapping_client - ID of the client which snapshot is
|
||||
SnappingClient - ID of the client which snapshot is
|
||||
being generated. Could be -1 to create a complete
|
||||
snapshot of everything in the game for demo
|
||||
recording.
|
||||
|
@ -91,7 +127,7 @@ public:
|
|||
entity.
|
||||
|
||||
Arguments:
|
||||
snapping_client - ID of the client which snapshot is
|
||||
SnappingClient - ID of the client which snapshot is
|
||||
being generated. Could be -1 to create a complete
|
||||
snapshot of everything in the game for demo
|
||||
recording.
|
||||
|
@ -103,18 +139,6 @@ public:
|
|||
int NetworkClipped(int SnappingClient, vec2 CheckPos);
|
||||
|
||||
bool GameLayerClipped(vec2 CheckPos);
|
||||
|
||||
/*
|
||||
Variable: proximity_radius
|
||||
Contains the physical size of the entity.
|
||||
*/
|
||||
float m_ProximityRadius;
|
||||
|
||||
/*
|
||||
Variable: pos
|
||||
Contains the current posititon of the entity.
|
||||
*/
|
||||
vec2 m_Pos;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -141,7 +141,7 @@ void CGameContext::CreateExplosion(vec2 Pos, int Owner, int Weapon, int MaxDamag
|
|||
int Num = m_World.FindEntities(Pos, Radius, (CEntity**)apEnts, MAX_CLIENTS, CGameWorld::ENTTYPE_CHARACTER);
|
||||
for(int i = 0; i < Num; i++)
|
||||
{
|
||||
vec2 Diff = apEnts[i]->m_Pos - Pos;
|
||||
vec2 Diff = apEnts[i]->GetPos() - Pos;
|
||||
vec2 Force(0, MaxForce);
|
||||
float l = length(Diff);
|
||||
if(l)
|
||||
|
|
|
@ -258,6 +258,10 @@ void IGameController::OnCharacterSpawn(CCharacter *pChr)
|
|||
}
|
||||
}
|
||||
|
||||
void IGameController::OnFlagReturn(CFlag *pFlag)
|
||||
{
|
||||
}
|
||||
|
||||
bool IGameController::OnEntity(int Index, vec2 Pos)
|
||||
{
|
||||
// don't add pickups in survival
|
||||
|
@ -302,8 +306,7 @@ bool IGameController::OnEntity(int Index, vec2 Pos)
|
|||
|
||||
if(Type != -1)
|
||||
{
|
||||
CPickup *pPickup = new CPickup(&GameServer()->m_World, Type);
|
||||
pPickup->m_Pos = Pos;
|
||||
CPickup *pPickup = new CPickup(&GameServer()->m_World, Type, Pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -975,7 +978,7 @@ float IGameController::EvaluateSpawnPos(CSpawnEval *pEval, vec2 Pos) const
|
|||
if(pEval->m_FriendlyTeam != -1 && pC->GetPlayer()->GetTeam() == pEval->m_FriendlyTeam)
|
||||
Scoremod = 0.5f;
|
||||
|
||||
float d = distance(Pos, pC->m_Pos);
|
||||
float d = distance(Pos, pC->GetPos());
|
||||
Score += Scoremod * (d == 0 ? 1000000000.0f : 1.0f/d);
|
||||
}
|
||||
|
||||
|
@ -997,7 +1000,7 @@ void IGameController::EvaluateSpawnType(CSpawnEval *pEval, int Type) const
|
|||
Result = Index;
|
||||
for(int c = 0; c < Num; ++c)
|
||||
if(GameServer()->Collision()->CheckPoint(m_aaSpawnPoints[Type][i]+Positions[Index]) ||
|
||||
distance(aEnts[c]->m_Pos, m_aaSpawnPoints[Type][i]+Positions[Index]) <= aEnts[c]->m_ProximityRadius)
|
||||
distance(aEnts[c]->GetPos(), m_aaSpawnPoints[Type][i]+Positions[Index]) <= aEnts[c]->GetProximityRadius())
|
||||
{
|
||||
Result = -1;
|
||||
break;
|
||||
|
|
|
@ -142,6 +142,8 @@ public:
|
|||
*/
|
||||
virtual void OnCharacterSpawn(class CCharacter *pChr);
|
||||
|
||||
virtual void OnFlagReturn(class CFlag *pFlag);
|
||||
|
||||
/*
|
||||
Function: on_entity
|
||||
Called when the map is loaded to process an entity
|
||||
|
|
|
@ -65,6 +65,12 @@ int CGameControllerCTF::OnCharacterDeath(CCharacter *pVictim, CPlayer *pKiller,
|
|||
return HadFlag;
|
||||
}
|
||||
|
||||
void CGameControllerCTF::OnFlagReturn(CFlag *pFlag)
|
||||
{
|
||||
GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", "flag_return");
|
||||
GameServer()->SendGameMsg(GAMEMSG_CTF_RETURN, -1);
|
||||
}
|
||||
|
||||
bool CGameControllerCTF::OnEntity(int Index, vec2 Pos)
|
||||
{
|
||||
if(IGameController::OnEntity(Index, Pos))
|
||||
|
@ -76,9 +82,7 @@ bool CGameControllerCTF::OnEntity(int Index, vec2 Pos)
|
|||
if(Team == -1 || m_apFlags[Team])
|
||||
return false;
|
||||
|
||||
CFlag *F = new CFlag(&GameServer()->m_World, Team);
|
||||
F->m_StandPos = Pos;
|
||||
F->m_Pos = Pos;
|
||||
CFlag *F = new CFlag(&GameServer()->m_World, Team, Pos);
|
||||
m_apFlags[Team] = F;
|
||||
GameServer()->m_World.InsertEntity(F);
|
||||
return true;
|
||||
|
@ -161,24 +165,12 @@ void CGameControllerCTF::Tick()
|
|||
if(!F)
|
||||
continue;
|
||||
|
||||
// flag hits death-tile or left the game layer, reset it
|
||||
if(GameServer()->Collision()->GetCollisionAt(F->m_Pos.x, F->m_Pos.y)&CCollision::COLFLAG_DEATH || F->GameLayerClipped(F->m_Pos))
|
||||
{
|
||||
GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", "flag_return");
|
||||
GameServer()->SendGameMsg(GAMEMSG_CTF_RETURN, -1);
|
||||
F->Reset();
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
if(F->m_pCarryingCharacter)
|
||||
{
|
||||
// update flag position
|
||||
F->m_Pos = F->m_pCarryingCharacter->m_Pos;
|
||||
|
||||
if(m_apFlags[fi^1] && m_apFlags[fi^1]->m_AtStand)
|
||||
{
|
||||
if(distance(F->m_Pos, m_apFlags[fi^1]->m_Pos) < CFlag::ms_PhysSize + CCharacter::ms_PhysSize)
|
||||
if(distance(F->GetPos(), m_apFlags[fi^1]->GetPos()) < CFlag::ms_PhysSize + CCharacter::ms_PhysSize)
|
||||
{
|
||||
// CAPTURE! \o/
|
||||
m_aTeamscore[fi^1] += 100;
|
||||
|
@ -199,10 +191,10 @@ void CGameControllerCTF::Tick()
|
|||
else
|
||||
{
|
||||
CCharacter *apCloseCCharacters[MAX_CLIENTS];
|
||||
int Num = GameServer()->m_World.FindEntities(F->m_Pos, CFlag::ms_PhysSize, (CEntity**)apCloseCCharacters, MAX_CLIENTS, CGameWorld::ENTTYPE_CHARACTER);
|
||||
int Num = GameServer()->m_World.FindEntities(F->GetPos(), CFlag::ms_PhysSize, (CEntity**)apCloseCCharacters, MAX_CLIENTS, CGameWorld::ENTTYPE_CHARACTER);
|
||||
for(int i = 0; i < Num; i++)
|
||||
{
|
||||
if(!apCloseCCharacters[i]->IsAlive() || apCloseCCharacters[i]->GetPlayer()->GetTeam() == TEAM_SPECTATORS || GameServer()->Collision()->IntersectLine(F->m_Pos, apCloseCCharacters[i]->m_Pos, NULL, NULL))
|
||||
if(!apCloseCCharacters[i]->IsAlive() || apCloseCCharacters[i]->GetPlayer()->GetTeam() == TEAM_SPECTATORS || GameServer()->Collision()->IntersectLine(F->GetPos(), apCloseCCharacters[i]->GetPos(), NULL, NULL))
|
||||
continue;
|
||||
|
||||
if(apCloseCCharacters[i]->GetPlayer()->GetTeam() == F->m_Team)
|
||||
|
@ -244,20 +236,6 @@ void CGameControllerCTF::Tick()
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!F->m_pCarryingCharacter && !F->m_AtStand)
|
||||
{
|
||||
if(Server()->Tick() > F->m_DropTick + Server()->TickSpeed()*30)
|
||||
{
|
||||
GameServer()->SendGameMsg(GAMEMSG_CTF_RETURN, -1);
|
||||
F->Reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
F->m_Vel.y += GameServer()->m_World.m_Core.m_Tuning.m_Gravity;
|
||||
GameServer()->Collision()->MoveBox(&F->m_Pos, &F->m_Vel, vec2(F->ms_PhysSize, F->ms_PhysSize), 0.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ public:
|
|||
|
||||
// event
|
||||
virtual int OnCharacterDeath(class CCharacter *pVictim, class CPlayer *pKiller, int Weapon);
|
||||
virtual void OnFlagReturn(class CFlag *pFlag);
|
||||
virtual bool OnEntity(int Index, vec2 Pos);
|
||||
|
||||
// general
|
||||
|
|
|
@ -79,7 +79,7 @@ void CGameWorld::InsertEntity(CEntity *pEnt)
|
|||
|
||||
void CGameWorld::DestroyEntity(CEntity *pEnt)
|
||||
{
|
||||
pEnt->m_MarkedForDestroy = true;
|
||||
pEnt->MarkForDestroy();
|
||||
}
|
||||
|
||||
void CGameWorld::RemoveEntity(CEntity *pEnt)
|
||||
|
@ -152,7 +152,7 @@ void CGameWorld::RemoveEntities()
|
|||
for(CEntity *pEnt = m_apFirstEntityTypes[i]; pEnt; )
|
||||
{
|
||||
m_pNextTraverseEntity = pEnt->m_pNextTypeEntity;
|
||||
if(pEnt->m_MarkedForDestroy)
|
||||
if(pEnt->IsMarkedForDestroy())
|
||||
{
|
||||
RemoveEntity(pEnt);
|
||||
pEnt->Destroy();
|
||||
|
|
|
@ -82,7 +82,7 @@ void CPlayer::Tick()
|
|||
if(m_pCharacter)
|
||||
{
|
||||
if(m_pCharacter->IsAlive())
|
||||
m_ViewPos = m_pCharacter->m_Pos;
|
||||
m_ViewPos = m_pCharacter->GetPos();
|
||||
}
|
||||
else if(m_Spawning && m_RespawnTick <= Server()->Tick())
|
||||
TryRespawn();
|
||||
|
|
Loading…
Reference in a new issue