mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Merge branch 'master' of http://github.com/btd/DDRace
Conflicts: src/game/server/entities/dragger.cpp src/game/server/gamecontext.cpp Signed-off-by: GreYFoXGTi <GreYFoXGTi@GMaiL.CoM>
This commit is contained in:
commit
806046fe76
|
@ -223,7 +223,7 @@ void CCharacterCore::Tick(bool UseInput)
|
|||
CCharacterCore *p = m_pWorld->m_apCharacters[i];
|
||||
|
||||
|
||||
if(!p || p == this || !m_pTeams->SameTeam(i, m_Id))
|
||||
if(!p || p == this || !m_pTeams->CanCollide(i, m_Id))
|
||||
continue;
|
||||
//char aBuf[512];
|
||||
//str_format(aBuf, sizeof(aBuf), "ThisId = %d Id = %d TheSameTeam? = %d", ThisId, i, m_pTeams->SameTeam(i, ThisId));
|
||||
|
@ -327,7 +327,7 @@ void CCharacterCore::Tick(bool UseInput)
|
|||
continue;
|
||||
|
||||
//player *p = (player*)ent;
|
||||
if(p == this || (m_Id != -1 && !m_pTeams->SameTeam(m_Id, i))) { // || !(p->flags&FLAG_ALIVE)
|
||||
if(p == this || (m_Id != -1 && !m_pTeams->CanCollide(m_Id, i))) { // || !(p->flags&FLAG_ALIVE)
|
||||
continue; // make sure that we don't nudge our self
|
||||
}
|
||||
// handle player <-> player collision
|
||||
|
@ -424,4 +424,3 @@ void CCharacterCore::Quantize()
|
|||
Write(&Core);
|
||||
Read(&Core);
|
||||
}
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ bool CCharacter::Spawn(CPlayer *pPlayer, vec2 Pos)
|
|||
m_Core.m_Pos = m_Pos;
|
||||
m_Core.m_Id = GetPlayer()->GetCID();
|
||||
GameServer()->m_World.m_Core.m_apCharacters[m_pPlayer->GetCID()] = &m_Core;
|
||||
|
||||
|
||||
m_ReckoningTick = 0;
|
||||
mem_zero(&m_SendCore, sizeof(m_SendCore));
|
||||
mem_zero(&m_ReckoningCore, sizeof(m_ReckoningCore));
|
||||
|
@ -116,6 +116,14 @@ void CCharacter::SetWeapon(int W)
|
|||
m_ActiveWeapon = 0;
|
||||
}
|
||||
|
||||
bool CCharacter::CanCollide(int Cid) {
|
||||
return Teams()->m_Core.CanCollide(GetPlayer()->GetCID(), Cid);
|
||||
}
|
||||
|
||||
bool CCharacter::SameTeam(int Cid) {
|
||||
return Teams()->m_Core.SameTeam(GetPlayer()->GetCID(), Cid);
|
||||
}
|
||||
|
||||
bool CCharacter::IsGrounded()
|
||||
{
|
||||
if(GameServer()->Collision()->CheckPoint(m_Pos.x+m_ProximityRadius/2, m_Pos.y+m_ProximityRadius/2+5))
|
||||
|
@ -315,7 +323,7 @@ void CCharacter::FireWeapon()
|
|||
CCharacter *Target = aEnts[i];
|
||||
|
||||
//for DDRace mod or any other mod, which needs hammer hits through the wall remove second condition
|
||||
if ((Target == this || Target->Team() != this->Team()) /*|| GameServer()->Collision()->IntersectLine(ProjStartPos, Target->m_Pos, NULL, NULL)*/)
|
||||
if ((Target == this || !CanCollide(i)) /*|| GameServer()->Collision()->IntersectLine(ProjStartPos, Target->m_Pos, NULL, NULL)*/)
|
||||
continue;
|
||||
|
||||
// set his velocity to fast upward (for now)
|
||||
|
@ -1190,7 +1198,7 @@ void CCharacter::Die(int Killer, int Weapon)
|
|||
m_pPlayer->GetCID(), Server()->ClientName(m_pPlayer->GetCID()), Weapon, ModeSpecial);
|
||||
GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf);
|
||||
|
||||
Controller->m_Teams.SetCharacterTeam(m_pPlayer->GetCID(), 0);
|
||||
Controller->m_Teams.m_Core.Team(m_pPlayer->GetCID(), 0);
|
||||
|
||||
// send the kill message
|
||||
CNetMsg_Sv_KillMsg Msg;
|
||||
|
|
|
@ -97,6 +97,8 @@ public:
|
|||
|
||||
void OnFinish();
|
||||
int Team();
|
||||
bool CanCollide(int Cid);
|
||||
bool SameTeam(int Cid);
|
||||
|
||||
struct
|
||||
{
|
||||
|
|
|
@ -12,92 +12,89 @@
|
|||
const int LENGTH=700;
|
||||
|
||||
CDragger::CDragger(CGameWorld *pGameWorld, vec2 Pos, float Strength, bool NW)
|
||||
: CEntity(pGameWorld, NETOBJTYPE_LASER)
|
||||
: CEntity(pGameWorld, NETOBJTYPE_LASER), m_Targets()
|
||||
{
|
||||
m_Pos = Pos;
|
||||
m_Strength = Strength;
|
||||
m_EvalTick = Server()->Tick();
|
||||
m_NW = NW;
|
||||
|
||||
|
||||
GameWorld()->InsertEntity(this);
|
||||
}
|
||||
|
||||
void CDragger::Move()
|
||||
{
|
||||
if (m_Target)
|
||||
if (m_Targets.empty())
|
||||
return;
|
||||
CCharacter *Ents[16];
|
||||
int IdInTeam[16];
|
||||
int LenInTeam[16];
|
||||
for (int i = 0; i < 16; i++) {
|
||||
IdInTeam[i] = -1;
|
||||
LenInTeam[i] = 0;
|
||||
}
|
||||
int Num = -1;
|
||||
Num = GameServer()->m_World.FindEntities(m_Pos,LENGTH, (CEntity**)Ents, 16, NETOBJTYPE_CHARACTER);
|
||||
int Id=-1;
|
||||
int MinLen=0;
|
||||
for (int i = 0; i < Num; i++)
|
||||
{
|
||||
m_Target = Ents[i];
|
||||
int Res=0;
|
||||
if (!m_NW)
|
||||
Res = GameServer()->Collision()->IntersectNoLaser(m_Pos, m_Target->m_Pos, 0, 0);
|
||||
else
|
||||
Res = GameServer()->Collision()->IntersectNoLaserNW(m_Pos, m_Target->m_Pos, 0, 0);
|
||||
CCharacter * Target = Ents[i];
|
||||
int Res = m_NW ? GameServer()->Collision()->IntersectNoLaserNW(m_Pos, Target->m_Pos, 0, 0) :
|
||||
GameServer()->Collision()->IntersectNoLaser(m_Pos, Target->m_Pos, 0, 0);
|
||||
|
||||
if (Res==0)
|
||||
{
|
||||
int Len=length(Ents[i]->m_Pos - m_Pos);
|
||||
if (MinLen==0 || MinLen>Len)
|
||||
int Len=length(Target->m_Pos - m_Pos);
|
||||
if (LenInTeam[Target->Team()] == 0 || LenInTeam[Target->Team()] > Len)
|
||||
{
|
||||
MinLen=Len;
|
||||
Id=i;
|
||||
LenInTeam[Target->Team()] = Len;
|
||||
IdInTeam[Target->Team()] = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Id!=-1)
|
||||
{
|
||||
m_Target = Ents[Id];
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Target=0;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
if(IdInTeam[i] != -1) {
|
||||
CCharacter *Target = Ents[IdInTeam[i]];
|
||||
m_Targets.push_back(Target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CDragger::Drag()
|
||||
{
|
||||
if (m_Target)
|
||||
if (!m_Targets.empty())
|
||||
{
|
||||
|
||||
int Res = 0;
|
||||
if (!m_NW)
|
||||
Res = GameServer()->Collision()->IntersectNoLaser(m_Pos, m_Target->m_Pos, 0, 0);
|
||||
else
|
||||
Res = GameServer()->Collision()->IntersectNoLaserNW(m_Pos, m_Target->m_Pos, 0, 0);
|
||||
if (Res || length(m_Pos-m_Target->m_Pos)>700)
|
||||
/*
|
||||
int Res = m_NW ? GameServer()->Collision()->IntersectNoLaserNW(m_Pos, m_Target->m_Pos, 0, 0) :
|
||||
GameServer()->Collision()->IntersectNoLaser(m_Pos, m_Target->m_Pos, 0, 0);
|
||||
if (Res || length(m_Pos-m_Target->m_Pos)>700)//TODO: USE CONSTANTS IDIOT
|
||||
{
|
||||
m_Target=0;
|
||||
m_Targets.clear();
|
||||
}
|
||||
else
|
||||
if (length(m_Pos-m_Target->m_Pos)>28)
|
||||
{
|
||||
//vec2 Temp = m_Target->m_Core.m_Vel +(normalize(m_Pos-m_Target->m_Pos)*m_Strength);
|
||||
if(((m_Target->m_TileIndexL == TILE_STOPA || m_Target->m_TileFIndexL == TILE_STOPA || m_Target->m_TileIndex == TILE_STOPL || m_Target->m_TileIndexL == TILE_STOPL || m_Target->m_TileFIndex == TILE_STOPL || m_Target->m_TileFIndexL == TILE_STOPL || m_Target->m_TileIndexL == TILE_STOPH || m_Target->m_TileFIndexL == TILE_STOPH)) || ((m_Target->m_TileIndexR == TILE_STOPA || m_Target->m_TileFIndexR == TILE_STOPA || m_Target->m_TileIndex == TILE_STOPR || m_Target->m_TileIndexR == TILE_STOPR || m_Target->m_TileFIndex == TILE_STOPR || m_Target->m_TileFIndexR == TILE_STOPR || m_Target->m_TileIndexR == TILE_STOPH || m_Target->m_TileFIndexR == TILE_STOPH)))
|
||||
else {
|
||||
for(std::list<CCharacter * >::iterator i = m_Targets.begin(); i != m_Targets.end(); ++i) {
|
||||
CCharacter * Target = *i;
|
||||
if (length(m_Pos-Target->m_Pos)>28) {
|
||||
if(((m_Target->m_TileIndexL == TILE_STOPA || m_Target->m_TileFIndexL == TILE_STOPA || m_Target->m_TileIndex == TILE_STOPL || m_Target->m_TileIndexL == TILE_STOPL || m_Target->m_TileFIndex == TILE_STOPL || m_Target->m_TileFIndexL == TILE_STOPL || m_Target->m_TileIndexL == TILE_STOPH || m_Target->m_TileFIndexL == TILE_STOPH)) || ((m_Target->m_TileIndexR == TILE_STOPA || m_Target->m_TileFIndexR == TILE_STOPA || m_Target->m_TileIndex == TILE_STOPR || m_Target->m_TileIndexR == TILE_STOPR || m_Target->m_TileFIndex == TILE_STOPR || m_Target->m_TileFIndexR == TILE_STOPR || m_Target->m_TileIndexR == TILE_STOPH || m_Target->m_TileFIndexR == TILE_STOPH)))
|
||||
{
|
||||
m_Target->m_Core.m_Vel.y +=(normalize(m_Pos-m_Target->m_Pos)*m_Strength).y;
|
||||
//dbg_msg("","x");
|
||||
return;
|
||||
}
|
||||
if(((m_Target->m_TileIndexB == TILE_STOPA || m_Target->m_TileFIndexB == TILE_STOPA || m_Target->m_TileIndex == TILE_STOPB || m_Target->m_TileIndexB == TILE_STOPB || m_Target->m_TileFIndex == TILE_STOPB || m_Target->m_TileFIndexB == TILE_STOPB|| m_Target->m_TileIndexB == TILE_STOPV || m_Target->m_TileFIndexB == TILE_STOPV)) || ((m_Target->m_TileIndexT == TILE_STOPA || m_Target->m_TileFIndexT == TILE_STOPA || m_Target->m_TileIndex == TILE_STOPT || m_Target->m_TileIndexT == TILE_STOPT || m_Target->m_TileFIndex == TILE_STOPT || m_Target->m_TileFIndexT == TILE_STOPT || m_Target->m_TileIndexT == TILE_STOPV || m_Target->m_TileFIndexT == TILE_STOPV)))
|
||||
if(((m_Target->m_TileIndexB == TILE_STOPA || m_Target->m_TileFIndexB == TILE_STOPA || m_Target->m_TileIndex == TILE_STOPB || m_Target->m_TileIndexB == TILE_STOPB || m_Target->m_TileFIndex == TILE_STOPB || m_Target->m_TileFIndexB == TILE_STOPB|| m_Target->m_TileIndexB == TILE_STOPV || m_Target->m_TileFIndexB == TILE_STOPV)) || ((m_Target->m_TileIndexT == TILE_STOPA || m_Target->m_TileFIndexT == TILE_STOPA || m_Target->m_TileIndex == TILE_STOPT || m_Target->m_TileIndexT == TILE_STOPT || m_Target->m_TileFIndex == TILE_STOPT || m_Target->m_TileFIndexT == TILE_STOPT || m_Target->m_TileIndexT == TILE_STOPV || m_Target->m_TileFIndexT == TILE_STOPV)))
|
||||
{
|
||||
m_Target->m_Core.m_Vel.x +=(normalize(m_Pos-m_Target->m_Pos)*m_Strength).x;
|
||||
//dbg_msg("y","");
|
||||
return;
|
||||
}
|
||||
//m_Target->m_Core.m_Vel = Temp;
|
||||
m_Target->m_Core.m_Vel +=(normalize(m_Pos-m_Target->m_Pos)*m_Strength);
|
||||
m_Target->m_Core.m_Vel +=(normalize(m_Pos-m_Target->m_Pos)*m_Strength);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CDragger::Reset()
|
||||
{
|
||||
m_Targets.clear();
|
||||
GameServer()->m_World.DestroyEntity(this);
|
||||
}
|
||||
|
||||
|
@ -122,10 +119,13 @@ void CDragger::Tick()
|
|||
|
||||
void CDragger::Snap(int SnappingClient)
|
||||
{
|
||||
if (m_Target)
|
||||
/*
|
||||
if (m_Targets.empty())
|
||||
{
|
||||
if(NetworkClipped(SnappingClient, m_Pos) && NetworkClipped(SnappingClient,m_Target->m_Pos))
|
||||
return;
|
||||
for(std::list<CCharacter * >::iterator i = m_Targets.begin(); i != m_Targets.end(); ++i) {
|
||||
if(NetworkClipped(SnappingClient, m_Pos) && NetworkClipped(SnappingClient,(*i)->m_Pos))
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
if(NetworkClipped(SnappingClient,m_Pos))
|
||||
|
@ -156,6 +156,7 @@ void CDragger::Snap(int SnappingClient)
|
|||
else if (StartTick>Server()->Tick())
|
||||
StartTick = Server()->Tick();
|
||||
obj->m_StartTick = StartTick;
|
||||
*/
|
||||
}
|
||||
//ÿ òóò áûë
|
||||
//ÿ òîæå
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#define GAME_SERVER_ENTITY_DRAGGER_H
|
||||
|
||||
#include <game/server/entity.h>
|
||||
|
||||
#include <list>
|
||||
class CCharacter;
|
||||
|
||||
class CDragger : public CEntity
|
||||
|
@ -14,7 +14,7 @@ class CDragger : public CEntity
|
|||
int m_EvalTick;
|
||||
void Move();
|
||||
void Drag();
|
||||
CCharacter * m_Target;
|
||||
std::list<CCharacter *> m_Targets;
|
||||
bool m_NW;
|
||||
public:
|
||||
|
||||
|
|
|
@ -22,11 +22,10 @@ CLaser::CLaser(CGameWorld *pGameWorld, vec2 Pos, vec2 Direction, float StartEner
|
|||
bool CLaser::HitCharacter(vec2 From, vec2 To)
|
||||
{
|
||||
vec2 At;
|
||||
CCharacter *OwnerChar = GameServer()->GetPlayerChar(m_Owner);//TODO: Find all and get closest non in Team
|
||||
CCharacter *Hit = GameServer()->m_World.IntersectCharacter(m_Pos, To, 0.f, At, m_Bounces != 0 ? 0: OwnerChar);
|
||||
CCharacter *OwnerChar = GameServer()->GetPlayerChar(m_Owner);
|
||||
CCharacter *Hit = GameServer()->m_World.IntersectCharacter(m_Pos, To, 0.f, At, m_Bounces != 0 ? 0: OwnerChar, m_Owner);
|
||||
if(!Hit)
|
||||
return false;
|
||||
if(OwnerChar != 0 && OwnerChar->Team() != Hit->Team()) return false;
|
||||
m_From = From;
|
||||
m_Pos = At;
|
||||
m_Energy = -1;
|
||||
|
|
|
@ -97,8 +97,8 @@ void CProjectile::Tick()
|
|||
|
||||
bool isWeaponCollide = false;
|
||||
if(OwnerChar && TargetChr
|
||||
&& OwnerChar->m_Alive && TargetChr->m_Alive
|
||||
&& OwnerChar->Team() != TargetChr->Team()) isWeaponCollide = true;
|
||||
&& OwnerChar->m_Alive && TargetChr->m_Alive
|
||||
&& !TargetChr->CanCollide(m_Owner)) isWeaponCollide = true;
|
||||
|
||||
if( ((TargetChr && (g_Config.m_SvHit || m_Owner == -1 || TargetChr == OwnerChar)) || Collide) && !isWeaponCollide)//TODO:TEAM
|
||||
{
|
||||
|
|
|
@ -149,7 +149,7 @@ void CGameContext::CreateExplosion(vec2 P, int Owner, int Weapon, bool NoDamage,
|
|||
if((int)Dmg)
|
||||
if((g_Config.m_SvHit||NoDamage) || Owner == apEnts[i]->m_pPlayer->GetCID())
|
||||
{
|
||||
if(Owner != -1 && apEnts[i]->m_Alive && apEnts[i]->Team() != GetPlayerChar(Owner)->Team()) continue;
|
||||
if(Owner != -1 && apEnts[i]->m_Alive && !apEnts[i]->CanCollide(Owner)) continue;
|
||||
apEnts[i]->TakeDamage(ForceDir*Dmg*2, (int)Dmg, Owner, Weapon);
|
||||
if(!g_Config.m_SvHit||NoDamage) break;
|
||||
}
|
||||
|
@ -1055,6 +1055,8 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId)
|
|||
{
|
||||
pPlayer->m_IsUsingRaceClient = true;
|
||||
pPlayer->m_ShowOthers = true;
|
||||
pPlayer->m_ShowOthers = true;
|
||||
((CGameControllerDDRace*)m_pController)->m_Teams.SendAllInfo(pPlayer->GetCID());
|
||||
// send time of all players
|
||||
for(int i = 0; i < MAX_CLIENTS; i++)
|
||||
{
|
||||
|
@ -1859,6 +1861,7 @@ void CGameContext::ConSuper(IConsole::IResult *pResult, void *pUserData, int Cli
|
|||
{
|
||||
chr->m_Super = true;
|
||||
chr->UnFreeze();
|
||||
chr->Teams()->SetCharacterTeam(Victim, TEAM_SUPER);
|
||||
if(!g_Config.m_SvCheatTime)
|
||||
chr->m_RaceState = RACE_CHEAT;
|
||||
}
|
||||
|
@ -1891,6 +1894,7 @@ void CGameContext::ConSuperMe(IConsole::IResult *pResult, void *pUserData, int C
|
|||
{
|
||||
chr->m_Super = true;
|
||||
chr->UnFreeze();
|
||||
chr->Teams()->SetCharacterTeam(ClientId, TEAM_SUPER);
|
||||
if(!g_Config.m_SvCheatTime)
|
||||
chr->m_RaceState = RACE_CHEAT;
|
||||
}
|
||||
|
|
|
@ -169,7 +169,7 @@ void CGameWorld::Tick()
|
|||
|
||||
|
||||
// TODO: should be more general
|
||||
CCharacter *CGameWorld::IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, vec2& NewPos, CEntity *pNotThis)
|
||||
CCharacter *CGameWorld::IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, vec2& NewPos, CCharacter *pNotThis, int CollideWith)
|
||||
{
|
||||
// Find other players
|
||||
float ClosestLen = distance(Pos0, Pos1) * 100.0f;
|
||||
|
@ -181,7 +181,7 @@ CCharacter *CGameWorld::IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, v
|
|||
{
|
||||
if(p == pNotThis)
|
||||
continue;
|
||||
|
||||
if(CollideWith != -1 && !p->CanCollide(CollideWith)) continue;
|
||||
vec2 IntersectPos = closest_point_on_line(Pos0, Pos1, p->m_Pos);
|
||||
float Len = distance(p->m_Pos, IntersectPos);
|
||||
if(Len < p->m_ProximityRadius+Radius)
|
||||
|
|
|
@ -76,7 +76,7 @@ public:
|
|||
Returns:
|
||||
Returns a pointer to the closest hit or NULL of there is no intersection.
|
||||
*/
|
||||
class CCharacter *IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, vec2 &NewPos, class CEntity *pNotThis = 0);
|
||||
class CCharacter *IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, vec2 &NewPos, class CCharacter *pNotThis = 0, int CollideWith = -1);
|
||||
|
||||
/*
|
||||
Function: closest_CCharacter
|
||||
|
|
|
@ -10,7 +10,7 @@ CGameTeams::CGameTeams(CGameContext *pGameContext) : m_pGameContext(pGameContext
|
|||
|
||||
void CGameTeams::OnCharacterStart(int id) {
|
||||
int Tick = Server()->Tick();
|
||||
if(m_Core.Team(id) == 0) {
|
||||
if(m_Core.Team(id) == TEAM_FLOCK || m_Core.Team(id) == TEAM_SUPER) {
|
||||
CCharacter* Char = Character(id);
|
||||
Char->m_RaceState = RACE_STARTED;
|
||||
Char->m_StartTime = Tick;
|
||||
|
@ -20,7 +20,7 @@ void CGameTeams::OnCharacterStart(int id) {
|
|||
ChangeTeamState(m_Core.Team(id), STARTED);
|
||||
|
||||
for(int i = 0; i < MAX_CLIENTS; ++i) {
|
||||
if(m_Core.SameTeam(i, id)) {
|
||||
if(m_Core.Team(id) == m_Core.Team(i)) {
|
||||
CCharacter* Char = Character(i);
|
||||
|
||||
Char->m_RaceState = RACE_STARTED;
|
||||
|
@ -33,14 +33,14 @@ void CGameTeams::OnCharacterStart(int id) {
|
|||
}
|
||||
|
||||
void CGameTeams::OnCharacterFinish(int id) {
|
||||
if(m_Core.Team(id) == 0) {
|
||||
if(m_Core.Team(id) == TEAM_FLOCK || m_Core.Team(id) == TEAM_SUPER) {
|
||||
Character(id)->OnFinish();
|
||||
} else {
|
||||
m_TeeFinished[id] = true;
|
||||
if(TeamFinished(m_Core.Team(id))) {
|
||||
ChangeTeamState(m_Core.Team(id), FINISHED);//TODO: Make it better
|
||||
for(int i = 0; i < MAX_CLIENTS; ++i) {
|
||||
if(m_Core.SameTeam(i, id)) {
|
||||
if(m_Core.Team(id) == m_Core.Team(i)) {
|
||||
CCharacter * Char = Character(i);
|
||||
if(Char != 0) {
|
||||
Char->OnFinish();
|
||||
|
@ -56,24 +56,35 @@ void CGameTeams::OnCharacterFinish(int id) {
|
|||
}
|
||||
|
||||
bool CGameTeams::SetCharacterTeam(int id, int Team) {
|
||||
//TODO: Send error message
|
||||
if(id < 0 || id >= MAX_CLIENTS || Team < 0 || Team >= MAX_CLIENTS) {
|
||||
//Check on wrong parameters. +1 for TEAM_SUPER
|
||||
if(id < 0 || id >= MAX_CLIENTS || Team < 0 || Team >= MAX_CLIENTS + 1) {
|
||||
return false;
|
||||
}
|
||||
if(m_TeamState[Team] >= CLOSED) {
|
||||
//You can join to TEAM_SUPER at any time, but any other group you cannot if it started
|
||||
if(Team != TEAM_SUPER && m_TeamState[Team] >= CLOSED) {
|
||||
return false;
|
||||
}
|
||||
//No need to switch team if you there
|
||||
if(m_Core.Team(id) == Team) {
|
||||
return false;
|
||||
}
|
||||
//You cannot be in TEAM_SUPER if you not super
|
||||
if(Team == TEAM_SUPER && !Character(id)->m_Super) return false;
|
||||
//if you begin race
|
||||
if(Character(id)->m_RaceState != RACE_NONE) {
|
||||
if(Team == 0 && m_Core.Team(id) != 0) {
|
||||
//you will be killed if you try to join FLOCK
|
||||
if(Team == TEAM_FLOCK && m_Core.Team(id) != TEAM_FLOCK) {
|
||||
Character(id)->GetPlayer()->KillCharacter(WEAPON_GAME);
|
||||
} else {
|
||||
return false;
|
||||
if(Team != TEAM_SUPER) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(m_Core.Team(id) != 0 && m_TeamState[m_Core.Team(id)] != EMPTY) {
|
||||
if(m_Core.Team(id) != TEAM_FLOCK && m_Core.Team(id) != TEAM_SUPER && m_TeamState[m_Core.Team(id)] != EMPTY) {
|
||||
bool NoOneInOldTeam = true;
|
||||
for(int i = 0; i < MAX_CLIENTS; ++i) {
|
||||
if(i != id && m_Core.SameTeam(i, id)) {
|
||||
if(i != id && m_Core.Team(id) == m_Core.Team(i)) {
|
||||
NoOneInOldTeam = false;//all good exists someone in old team
|
||||
break;
|
||||
}
|
||||
|
@ -83,9 +94,12 @@ bool CGameTeams::SetCharacterTeam(int id, int Team) {
|
|||
}
|
||||
}
|
||||
m_Core.Team(id, Team);
|
||||
if(m_TeamState[Team] == EMPTY) {
|
||||
if(Team != TEAM_SUPER && m_TeamState[Team] == EMPTY) {
|
||||
ChangeTeamState(Team, OPEN);
|
||||
}
|
||||
char aBuf[512];
|
||||
str_format(aBuf, sizeof(aBuf), "Id = %d Team = %d", id, Team);
|
||||
dbg_msg("Teams", aBuf);
|
||||
//GameServer()->CreatePlayerSpawn(Character(id)->m_Core.m_Pos, TeamMask());
|
||||
if(Character(id)->GetPlayer()->m_IsUsingRaceClient)
|
||||
{
|
||||
|
@ -93,9 +107,7 @@ bool CGameTeams::SetCharacterTeam(int id, int Team) {
|
|||
Msg.m_Team = Team;
|
||||
Msg.m_Cid = id;
|
||||
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, -1);
|
||||
char aBuf[512];
|
||||
str_format(aBuf, sizeof(aBuf), "Id = %d Team = %d", id, Team);
|
||||
dbg_msg("Teams", aBuf);
|
||||
//dbg_msg("Teams", "Sended all");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -116,11 +128,14 @@ bool CGameTeams::TeamFinished(int Team) {
|
|||
}
|
||||
|
||||
int CGameTeams::TeamMask(int Team) {
|
||||
if(Team == TEAM_SUPER) return -1;
|
||||
int Mask = 0;
|
||||
for(int i = 0; i < MAX_CLIENTS; ++i) {
|
||||
if(m_Core.Team(i) == Team || (Character(i)
|
||||
if(m_Core.Team(i) == Team
|
||||
|| (Character(i)
|
||||
&& Character(i)->GetPlayer()
|
||||
&& Character(i)->GetPlayer()->m_ShowOthers)) {
|
||||
&& Character(i)->GetPlayer()->m_ShowOthers)
|
||||
|| m_Core.Team(i) == TEAM_SUPER) {
|
||||
Mask |= 1 << i;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
CTeamsCore::CTeamsCore() {
|
||||
for(int i = 0; i < MAX_CLIENTS; ++i) {
|
||||
m_Team[i] = 0;
|
||||
m_Team[i] = TEAM_FLOCK;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,4 +16,9 @@ int CTeamsCore::Team(int Cid) {
|
|||
|
||||
void CTeamsCore::Team(int Cid, int Team) {
|
||||
m_Team[Cid] = Team;
|
||||
}
|
||||
|
||||
bool CTeamsCore::CanCollide(int Cid1, int Cid2) {
|
||||
if(m_Team[Cid1] == TEAM_SUPER || m_Team[Cid2] == TEAM_SUPER) return true;
|
||||
return m_Team[Cid1] == m_Team[Cid2];
|
||||
}
|
|
@ -3,6 +3,11 @@
|
|||
|
||||
#include <engine/shared/protocol.h>
|
||||
|
||||
enum {
|
||||
TEAM_FLOCK = 0,
|
||||
TEAM_SUPER = 16
|
||||
};
|
||||
|
||||
class CTeamsCore {
|
||||
|
||||
int m_Team[MAX_CLIENTS];
|
||||
|
@ -11,6 +16,8 @@ public:
|
|||
CTeamsCore(void);
|
||||
|
||||
bool SameTeam(int Cid1, int Cid2);
|
||||
|
||||
bool CanCollide(int Cid1, int Cid2);
|
||||
|
||||
int Team(int Cid);
|
||||
void Team(int Cid, int Team);
|
||||
|
|
Loading…
Reference in a new issue