From 5db7748af461e6b414a98438aab63936eaa997d8 Mon Sep 17 00:00:00 2001 From: btd Date: Wed, 22 Sep 2010 14:43:59 +0400 Subject: [PATCH 1/5] Fix ddraggers --- src/game/server/entities/character.cpp | 2 +- src/game/server/entities/dragger.cpp | 109 +++++++++++++------------ src/game/server/entities/dragger.h | 15 +++- src/game/server/gamecontroller.cpp | 4 +- src/game/server/teams.cpp | 30 ++++--- src/game/server/teams.h | 3 + 6 files changed, 92 insertions(+), 71 deletions(-) diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index da90b94d5..dde6c36e1 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -1180,7 +1180,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.m_Core.Team(m_pPlayer->GetCID(), 0); + Controller->m_Teams.SetForceCharacterTeam(m_pPlayer->GetCID(), 0); // send the kill message CNetMsg_Sv_KillMsg Msg; diff --git a/src/game/server/entities/dragger.cpp b/src/game/server/entities/dragger.cpp index 3ce921706..1e7bd5436 100644 --- a/src/game/server/entities/dragger.cpp +++ b/src/game/server/entities/dragger.cpp @@ -11,84 +11,79 @@ const int LENGTH=700; -CDragger::CDragger(CGameWorld *pGameWorld, vec2 Pos, float Strength, bool NW) -: CEntity(pGameWorld, NETOBJTYPE_LASER), m_Targets() +CDragger::CDragger(CGameWorld *pGameWorld, vec2 Pos, float Strength, bool NW, int CatchedTeam) +: CEntity(pGameWorld, NETOBJTYPE_LASER) { m_Pos = Pos; m_Strength = Strength; m_EvalTick = Server()->Tick(); m_NW = NW; - + m_CatchedTeam = CatchedTeam; GameWorld()->InsertEntity(this); } void CDragger::Move() { - if (m_Targets.empty()) + if (m_Target) 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++) { - 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); + m_Target = Ents[i]; + if(m_Target->Team() != m_CatchedTeam) continue; + 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==0) { - int Len=length(Target->m_Pos - m_Pos); - if (LenInTeam[Target->Team()] == 0 || LenInTeam[Target->Team()] > Len) + int Len=length(Ents[i]->m_Pos - m_Pos); + if (MinLen==0 || MinLen>Len) { - LenInTeam[Target->Team()] = Len; - IdInTeam[Target->Team()] = i; + MinLen=Len; + Id=i; } } } - for (int i = 0; i < 16; i++) { - if(IdInTeam[i] != -1) { - CCharacter *Target = Ents[IdInTeam[i]]; - m_Targets.push_back(Target); - } + if (Id!=-1) + { + m_Target = Ents[Id]; + } + else + { + m_Target=0; } } void CDragger::Drag() { - if (!m_Targets.empty()) + if (m_Target) { -/* - 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 + + 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) { - m_Targets.clear(); + m_Target=0; } - else { - for(std::list::iterator i = m_Targets.begin(); i != m_Targets.end(); ++i) { - CCharacter * Target = *i; - if (length(m_Pos-Target->m_Pos)>28) { - if(!((Target->m_CurrentTile >= TILE_STOPL - && Target->m_CurrentTile <= TILE_STOPT) - || (Target->m_CurrentFTile >= TILE_STOPL - && Target->m_CurrentFTile <= TILE_STOPT))) - Target->m_Core.m_Vel+=normalize(m_Pos-Target->m_Pos)*m_Strength; - } - - } - }*/ + else + if (length(m_Pos-m_Target->m_Pos)>28) + if(!((m_Target->m_CurrentTile >= TILE_STOPL && m_Target->m_CurrentTile <= TILE_STOPT) || (m_Target->m_CurrentFTile >= TILE_STOPL && m_Target->m_CurrentFTile <= TILE_STOPT))) + 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); } @@ -113,20 +108,19 @@ void CDragger::Tick() void CDragger::Snap(int SnappingClient) { - /* - if (m_Targets.empty()) + if (m_Target) { - for(std::list::iterator i = m_Targets.begin(); i != m_Targets.end(); ++i) { - if(NetworkClipped(SnappingClient, m_Pos) && NetworkClipped(SnappingClient,(*i)->m_Pos)) - return; - } + if(NetworkClipped(SnappingClient, m_Pos) && NetworkClipped(SnappingClient,m_Target->m_Pos)) + return; } else if(NetworkClipped(SnappingClient,m_Pos)) return; CCharacter * Char = GameServer()->GetPlayerChar(SnappingClient); - if(Char && m_Target && !Char->GetPlayer()->m_ShowOthers && Char->Team() != m_Target->Team()) return; + if(Char && m_Target + && !Char->GetPlayer()->m_ShowOthers + && Char->Team() != m_Target->Team()) return; CNetObj_Laser *obj = static_cast(Server()->SnapNewItem(NETOBJTYPE_LASER, m_Id, sizeof(CNetObj_Laser))); @@ -150,7 +144,18 @@ void CDragger::Snap(int SnappingClient) else if (StartTick>Server()->Tick()) StartTick = Server()->Tick(); obj->m_StartTick = StartTick; - */ } -//я тут был -//я тоже + +CDraggerTeam::CDraggerTeam(CGameWorld *pGameWorld, vec2 Pos, float Strength, bool NW) { + for(int i = 0; i < MAX_CLIENTS; ++i) { + m_Draggers[i] = new CDragger(pGameWorld, Pos, Strength, NW, i); + } +} + +CDraggerTeam::~CDraggerTeam() { + for(int i = 0; i < MAX_CLIENTS; ++i) { + delete m_Draggers[i]; + } +} +//? ??? ??? +//? ???? diff --git a/src/game/server/entities/dragger.h b/src/game/server/entities/dragger.h index c0166f2cb..23c2c6b65 100644 --- a/src/game/server/entities/dragger.h +++ b/src/game/server/entities/dragger.h @@ -4,7 +4,6 @@ #define GAME_SERVER_ENTITY_DRAGGER_H #include -#include class CCharacter; class CDragger : public CEntity @@ -14,16 +13,26 @@ class CDragger : public CEntity int m_EvalTick; void Move(); void Drag(); - std::list m_Targets; + CCharacter * m_Target; bool m_NW; + int m_CatchedTeam; public: - CDragger(CGameWorld *pGameWorld, vec2 Pos, float Strength, bool NW=false); + CDragger(CGameWorld *pGameWorld, vec2 Pos, float Strength, bool NW, int CatchedTeam); virtual void Reset(); virtual void Tick(); virtual void Snap(int snapping_client); }; +class CDraggerTeam { + CDragger * m_Draggers[MAX_CLIENTS]; + +public: + + CDraggerTeam(CGameWorld *pGameWorld, vec2 Pos, float Strength, bool NW=false); + ~CDraggerTeam(); +}; + #endif diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp index a953b4780..561d19481 100644 --- a/src/game/server/gamecontroller.cpp +++ b/src/game/server/gamecontroller.cpp @@ -289,11 +289,11 @@ bool IGameController::OnEntity(int Index, vec2 Pos, bool Front) } else if(Index>=ENTITY_DRAGGER_WEAK && Index <=ENTITY_DRAGGER_STRONG) { - new CDragger(&GameServer()->m_World,Pos,Index-ENTITY_DRAGGER_WEAK+1); + new CDraggerTeam(&GameServer()->m_World,Pos,Index-ENTITY_DRAGGER_WEAK+1, false); } else if(Index>=ENTITY_DRAGGER_WEAK_NW && Index <=ENTITY_DRAGGER_STRONG_NW) { - new CDragger(&GameServer()->m_World, Pos,Index-ENTITY_DRAGGER_WEAK_NW+1,true); + new CDraggerTeam(&GameServer()->m_World, Pos,Index-ENTITY_DRAGGER_WEAK_NW+1,true); } else if(Index==ENTITY_PLASMAE) { diff --git a/src/game/server/teams.cpp b/src/game/server/teams.cpp index 7d93aeb1f..d7cdf2871 100644 --- a/src/game/server/teams.cpp +++ b/src/game/server/teams.cpp @@ -81,6 +81,23 @@ bool CGameTeams::SetCharacterTeam(int id, int Team) { } } } + SetForceCharacterTeam(id, Team); + 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) + { + CNetMsg_Sv_PlayerTeam Msg; + Msg.m_Team = Team; + Msg.m_Cid = id; + Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, -1); + //dbg_msg("Teams", "Sended all"); + } + return true; +} + +void CGameTeams::SetForceCharacterTeam(int id, int Team) { 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) { @@ -97,19 +114,6 @@ bool CGameTeams::SetCharacterTeam(int id, int Team) { 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) - { - CNetMsg_Sv_PlayerTeam Msg; - Msg.m_Team = Team; - Msg.m_Cid = id; - Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, -1); - //dbg_msg("Teams", "Sended all"); - } - return true; } void CGameTeams::ChangeTeamState(int Team, int State) { diff --git a/src/game/server/teams.h b/src/game/server/teams.h index c2578abe4..4be6095f3 100644 --- a/src/game/server/teams.h +++ b/src/game/server/teams.h @@ -41,6 +41,9 @@ public: int TeamMask(int Team); void SendAllInfo(int Cid); + + //need to be very carefull using this method + void SetForceCharacterTeam(int id, int Team); }; #endif From fede6df9730d96dcb22d7c89422a601c01b9fa69 Mon Sep 17 00:00:00 2001 From: btd Date: Wed, 22 Sep 2010 14:49:19 +0400 Subject: [PATCH 2/5] No need in it --- src/game/server/entities/dragger.cpp | 6 +++--- src/game/server/entities/dragger.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/game/server/entities/dragger.cpp b/src/game/server/entities/dragger.cpp index 1e7bd5436..ade83f229 100644 --- a/src/game/server/entities/dragger.cpp +++ b/src/game/server/entities/dragger.cpp @@ -153,9 +153,9 @@ CDraggerTeam::CDraggerTeam(CGameWorld *pGameWorld, vec2 Pos, float Strength, boo } CDraggerTeam::~CDraggerTeam() { - for(int i = 0; i < MAX_CLIENTS; ++i) { - delete m_Draggers[i]; - } + //for(int i = 0; i < MAX_CLIENTS; ++i) { + // delete m_Draggers[i]; + //} } //? ??? ??? //? ???? diff --git a/src/game/server/entities/dragger.h b/src/game/server/entities/dragger.h index 23c2c6b65..5e15a875d 100644 --- a/src/game/server/entities/dragger.h +++ b/src/game/server/entities/dragger.h @@ -32,7 +32,7 @@ class CDraggerTeam { public: CDraggerTeam(CGameWorld *pGameWorld, vec2 Pos, float Strength, bool NW=false); - ~CDraggerTeam(); + //~CDraggerTeam(); }; #endif From 71dd366a49c2f437d94ce30826e48789915d4f6f Mon Sep 17 00:00:00 2001 From: btd Date: Wed, 22 Sep 2010 14:49:48 +0400 Subject: [PATCH 3/5] No need in it --- src/game/server/entities/dragger.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/game/server/entities/dragger.cpp b/src/game/server/entities/dragger.cpp index ade83f229..25259ba76 100644 --- a/src/game/server/entities/dragger.cpp +++ b/src/game/server/entities/dragger.cpp @@ -152,10 +152,10 @@ CDraggerTeam::CDraggerTeam(CGameWorld *pGameWorld, vec2 Pos, float Strength, boo } } -CDraggerTeam::~CDraggerTeam() { +//CDraggerTeam::~CDraggerTeam() { //for(int i = 0; i < MAX_CLIENTS; ++i) { // delete m_Draggers[i]; //} -} +//} //? ??? ??? //? ???? From a00e8a76b11bb908dc7a48e86f2d750244ee0b41 Mon Sep 17 00:00:00 2001 From: btd Date: Wed, 22 Sep 2010 21:36:13 +0400 Subject: [PATCH 4/5] Draggers seems works --- src/game/server/entities/dragger.cpp | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/game/server/entities/dragger.cpp b/src/game/server/entities/dragger.cpp index 25259ba76..b021208a0 100644 --- a/src/game/server/entities/dragger.cpp +++ b/src/game/server/entities/dragger.cpp @@ -27,23 +27,19 @@ void CDragger::Move() if (m_Target) return; CCharacter *Ents[16]; - int Num = -1; - Num = GameServer()->m_World.FindEntities(m_Pos,LENGTH, (CEntity**)Ents, 16, NETOBJTYPE_CHARACTER); + int 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]; if(m_Target->Team() != m_CatchedTeam) continue; - 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); + 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==0) { - int Len=length(Ents[i]->m_Pos - m_Pos); + int Len=length(m_Target->m_Pos - m_Pos); if (MinLen==0 || MinLen>Len) { MinLen=Len; @@ -51,14 +47,7 @@ void CDragger::Move() } } } - if (Id!=-1) - { - m_Target = Ents[Id]; - } - else - { - m_Target=0; - } + m_Target = Id != -1 ? Ents[Id] : 0; } void CDragger::Drag() From 99f5a1d767cd0798a3372bc67944dfe9c189a9bc Mon Sep 17 00:00:00 2001 From: btd Date: Wed, 22 Sep 2010 23:01:09 +0400 Subject: [PATCH 5/5] Fix projecttile --- src/game/server/entities/projectile.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/game/server/entities/projectile.cpp b/src/game/server/entities/projectile.cpp index 324d3b831..4eaf80987 100644 --- a/src/game/server/entities/projectile.cpp +++ b/src/game/server/entities/projectile.cpp @@ -95,20 +95,23 @@ void CProjectile::Tick() if(m_LifeSpan > -1) m_LifeSpan--; + int TeamMask = -1; bool isWeaponCollide = false; if(OwnerChar && TargetChr && OwnerChar->m_Alive && TargetChr->m_Alive - && !TargetChr->CanCollide(m_Owner)) isWeaponCollide = true; - + && !TargetChr->CanCollide(m_Owner)) { + isWeaponCollide = true; + TeamMask = OwnerChar->Teams()->TeamMask( OwnerChar->Team()); + } if( ((TargetChr && (g_Config.m_SvHit || m_Owner == -1 || TargetChr == OwnerChar)) || Collide) && !isWeaponCollide)//TODO:TEAM { if(m_Explosive/*??*/ && (!TargetChr || (TargetChr && !m_Freeze))) { - GameServer()->CreateExplosion(ColPos, m_Owner, m_Weapon, (m_Owner == -1)?true:false, - (m_Owner != -1)? OwnerChar->Teams()->TeamMask(OwnerChar->Team()) : -1); + GameServer()->CreateExplosion(ColPos, m_Owner, m_Weapon, m_Owner == -1, + (m_Owner != -1)? TeamMask : -1); GameServer()->CreateSound(ColPos, m_SoundImpact, - (m_Owner != -1)? OwnerChar->Teams()->TeamMask(OwnerChar->Team()) : -1); + (m_Owner != -1)? TeamMask : -1); } else if(TargetChr && m_Freeze) TargetChr->Freeze(Server()->TickSpeed()*3); @@ -125,7 +128,7 @@ void CProjectile::Tick() else if (m_Weapon == WEAPON_GUN) { GameServer()->CreateDamageInd(CurPos, -atan2(m_Direction.x, m_Direction.y), 10, - (m_Owner != -1)? OwnerChar->Teams()->TeamMask(OwnerChar->Team()) : -1); + (m_Owner != -1)? TeamMask : -1); GameServer()->m_World.DestroyEntity(this); } else @@ -156,7 +159,7 @@ void CProjectile::Snap(int SnappingClient) return; CCharacter * Char = GameServer()->GetPlayerChar(SnappingClient); if(Char && m_Owner != -1 && !Char->GetPlayer()->m_ShowOthers && - Char->Team() != GameServer()->GetPlayerChar(m_Owner)->Team()) return; + Char->CanCollide(m_Owner)) return; CNetObj_Projectile *pProj = static_cast(Server()->SnapNewItem(NETOBJTYPE_PROJECTILE, m_Id, sizeof(CNetObj_Projectile))); FillInfo(pProj); }