diff options
| author | oy <Tom_Adams@web.de> | 2011-04-13 20:37:12 +0200 |
|---|---|---|
| committer | oy <Tom_Adams@web.de> | 2011-04-13 20:37:12 +0200 |
| commit | 06115dd49dca2f8eb5f14606437e8fd20037cc4d (patch) | |
| tree | 5ec4bca6158319b3f5285d7689c5f94ae8da8c93 /src/game/server | |
| parent | 63e059b8fff6498e42b765a1dca000e53005ea77 (diff) | |
| download | zcatch-06115dd49dca2f8eb5f14606437e8fd20037cc4d.tar.gz zcatch-06115dd49dca2f8eb5f14606437e8fd20037cc4d.zip | |
added "Whitespace and line Endings cleanup" by GreYFoX
Diffstat (limited to 'src/game/server')
26 files changed, 392 insertions, 392 deletions
diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index b40e768b..821aade5 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -22,7 +22,7 @@ CInputCount CountInput(int Prev, int Cur) Prev &= INPUT_STATE_MASK; Cur &= INPUT_STATE_MASK; int i = Prev; - + while(i != Cur) { i = (i+1)&INPUT_STATE_MASK; @@ -59,10 +59,10 @@ bool CCharacter::Spawn(CPlayer *pPlayer, vec2 Pos) m_ActiveWeapon = WEAPON_GUN; m_LastWeapon = WEAPON_HAMMER; m_QueuedWeapon = -1; - + m_pPlayer = pPlayer; m_Pos = Pos; - + m_Core.Reset(); m_Core.Init(&GameServer()->m_World.m_Core, GameServer()->Collision()); m_Core.m_Pos = m_Pos; @@ -71,7 +71,7 @@ bool CCharacter::Spawn(CPlayer *pPlayer, vec2 Pos) m_ReckoningTick = 0; mem_zero(&m_SendCore, sizeof(m_SendCore)); mem_zero(&m_ReckoningCore, sizeof(m_ReckoningCore)); - + GameServer()->m_World.InsertEntity(this); m_Alive = true; @@ -90,12 +90,12 @@ void CCharacter::SetWeapon(int W) { if(W == m_ActiveWeapon) return; - + m_LastWeapon = m_ActiveWeapon; m_QueuedWeapon = -1; m_ActiveWeapon = W; GameServer()->CreateSound(m_Pos, SOUND_WEAPON_SWITCH); - + if(m_ActiveWeapon < 0 || m_ActiveWeapon >= NUM_WEAPONS) m_ActiveWeapon = 0; } @@ -114,7 +114,7 @@ void CCharacter::HandleNinja() { if(m_ActiveWeapon != WEAPON_NINJA) return; - + vec2 Direction = normalize(vec2(m_LatestInput.m_TargetX, m_LatestInput.m_TargetY)); if ((Server()->Tick() - m_Ninja.m_ActivationTick) > (g_pData->m_Weapons.m_Ninja.m_Duration * Server()->TickSpeed() / 1000)) @@ -124,11 +124,11 @@ void CCharacter::HandleNinja() m_ActiveWeapon = m_LastWeapon; if(m_ActiveWeapon == WEAPON_NINJA) m_ActiveWeapon = WEAPON_GUN; - + SetWeapon(m_ActiveWeapon); return; } - + // force ninja Weapon SetWeapon(WEAPON_NINJA); @@ -146,7 +146,7 @@ void CCharacter::HandleNinja() 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); - + // reset velocity so the client doesn't predict stuff m_Core.m_Vel = vec2(0.f, 0.f); @@ -162,7 +162,7 @@ void CCharacter::HandleNinja() { if (aEnts[i] == this) continue; - + // make sure we haven't Hit this object before bool bAlreadyHit = false; for (int j = 0; j < m_NumObjectsHit; j++) @@ -182,11 +182,11 @@ void CCharacter::HandleNinja() // set his velocity to fast upward (for now) if(m_NumObjectsHit < 10) m_apHitObjects[m_NumObjectsHit++] = aEnts[i]; - + aEnts[i]->TakeDamage(vec2(0, 10.0f), g_pData->m_Weapons.m_Ninja.m_pBase->m_Damage, m_pPlayer->GetCID(), WEAPON_NINJA); } } - + return; } @@ -209,7 +209,7 @@ void CCharacter::HandleWeaponSwitch() int WantedWeapon = m_ActiveWeapon; if(m_QueuedWeapon != -1) WantedWeapon = m_QueuedWeapon; - + // select Weapon int Next = CountInput(m_LatestPrevInput.m_NextWeapon, m_LatestInput.m_NextWeapon).m_Presses; int Prev = CountInput(m_LatestPrevInput.m_PrevWeapon, m_LatestInput.m_PrevWeapon).m_Presses; @@ -241,7 +241,7 @@ void CCharacter::HandleWeaponSwitch() // check for insane values if(WantedWeapon >= 0 && WantedWeapon < NUM_WEAPONS && WantedWeapon != m_ActiveWeapon && m_aWeapons[WantedWeapon].m_Got) m_QueuedWeapon = WantedWeapon; - + DoWeaponSwitch(); } @@ -249,10 +249,10 @@ void CCharacter::FireWeapon() { if(m_ReloadTimer != 0) return; - + DoWeaponSwitch(); vec2 Direction = normalize(vec2(m_LatestInput.m_TargetX, m_LatestInput.m_TargetY)); - + bool FullAuto = false; if(m_ActiveWeapon == WEAPON_GRENADE || m_ActiveWeapon == WEAPON_SHOTGUN || m_ActiveWeapon == WEAPON_RIFLE) FullAuto = true; @@ -262,13 +262,13 @@ void CCharacter::FireWeapon() bool WillFire = false; if(CountInput(m_LatestPrevInput.m_Fire, m_LatestInput.m_Fire).m_Presses) WillFire = true; - + if(FullAuto && (m_LatestInput.m_Fire&1) && m_aWeapons[m_ActiveWeapon].m_Ammo) WillFire = true; - + if(!WillFire) return; - + // check for ammo if(!m_aWeapons[m_ActiveWeapon].m_Ammo) { @@ -277,9 +277,9 @@ void CCharacter::FireWeapon() GameServer()->CreateSound(m_Pos, SOUND_WEAPON_NOAMMO); return; } - + vec2 ProjStartPos = m_Pos+Direction*m_ProximityRadius*0.75f; - + switch(m_ActiveWeapon) { case WEAPON_HAMMER: @@ -287,16 +287,16 @@ void CCharacter::FireWeapon() // reset objects Hit m_NumObjectsHit = 0; GameServer()->CreateSound(m_Pos, SOUND_HAMMER_FIRE); - + 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, m_ProximityRadius*0.5f, (CEntity**)apEnts, MAX_CLIENTS, CGameWorld::ENTTYPE_CHARACTER); for (int i = 0; i < Num; ++i) { CCharacter *pTarget = apEnts[i]; - + if ((pTarget == this) || GameServer()->Collision()->IntersectLine(ProjStartPos, pTarget->m_Pos, NULL, NULL)) continue; @@ -305,22 +305,22 @@ void CCharacter::FireWeapon() GameServer()->CreateHammerHit(pTarget->m_Pos-normalize(pTarget->m_Pos-ProjStartPos)*m_ProximityRadius*0.5f); else GameServer()->CreateHammerHit(ProjStartPos); - + vec2 Dir; if (length(pTarget->m_Pos - m_Pos) > 0.0f) Dir = normalize(pTarget->m_Pos - m_Pos); else Dir = vec2(0.f, -1.f); - + pTarget->TakeDamage(vec2(0.f, -1.f) + normalize(Dir + vec2(0.f, -1.1f)) * 10.0f, g_pData->m_Weapons.m_Hammer.m_pBase->m_Damage, m_pPlayer->GetCID(), m_ActiveWeapon); Hits++; } - + // if we Hit anything, we have to wait for the reload if(Hits) m_ReloadTimer = Server()->TickSpeed()/3; - + } break; case WEAPON_GUN: @@ -331,28 +331,28 @@ void CCharacter::FireWeapon() Direction, (int)(Server()->TickSpeed()*GameServer()->Tuning()->m_GunLifetime), 1, 0, 0, -1, WEAPON_GUN); - + // pack the Projectile and send it to the client Directly CNetObj_Projectile p; pProj->FillInfo(&p); - + CMsgPacker Msg(NETMSGTYPE_SV_EXTRAPROJECTILE); Msg.AddInt(1); for(unsigned i = 0; i < sizeof(CNetObj_Projectile)/sizeof(int); i++) Msg.AddInt(((int *)&p)[i]); - + Server()->SendMsg(&Msg, 0, m_pPlayer->GetCID()); - + GameServer()->CreateSound(m_Pos, SOUND_GUN_FIRE); } break; - + case WEAPON_SHOTGUN: { int ShotSpread = 2; CMsgPacker Msg(NETMSGTYPE_SV_EXTRAPROJECTILE); Msg.AddInt(ShotSpread*2+1); - + for(int i = -ShotSpread; i <= ShotSpread; ++i) { float Spreading[] = {-0.185f, -0.070f, 0, 0.070f, 0.185f}; @@ -366,17 +366,17 @@ void CCharacter::FireWeapon() vec2(cosf(a), sinf(a))*Speed, (int)(Server()->TickSpeed()*GameServer()->Tuning()->m_ShotgunLifetime), 1, 0, 0, -1, WEAPON_SHOTGUN); - + // pack the Projectile and send it to the client Directly CNetObj_Projectile p; pProj->FillInfo(&p); - + for(unsigned i = 0; i < sizeof(CNetObj_Projectile)/sizeof(int); i++) Msg.AddInt(((int *)&p)[i]); } - Server()->SendMsg(&Msg, 0,m_pPlayer->GetCID()); - + Server()->SendMsg(&Msg, 0,m_pPlayer->GetCID()); + GameServer()->CreateSound(m_Pos, SOUND_SHOTGUN_FIRE); } break; @@ -392,41 +392,41 @@ void CCharacter::FireWeapon() // pack the Projectile and send it to the client Directly CNetObj_Projectile p; pProj->FillInfo(&p); - + CMsgPacker Msg(NETMSGTYPE_SV_EXTRAPROJECTILE); Msg.AddInt(1); for(unsigned i = 0; i < sizeof(CNetObj_Projectile)/sizeof(int); i++) Msg.AddInt(((int *)&p)[i]); Server()->SendMsg(&Msg, 0, m_pPlayer->GetCID()); - + GameServer()->CreateSound(m_Pos, SOUND_GRENADE_FIRE); } break; - + case WEAPON_RIFLE: { new CLaser(GameWorld(), m_Pos, Direction, GameServer()->Tuning()->m_LaserReach, m_pPlayer->GetCID()); GameServer()->CreateSound(m_Pos, SOUND_RIFLE_FIRE); } break; - + case WEAPON_NINJA: { // reset Hit objects m_NumObjectsHit = 0; - + m_Ninja.m_ActivationDir = Direction; m_Ninja.m_CurrentMoveTime = g_pData->m_Weapons.m_Ninja.m_Movetime * Server()->TickSpeed() / 1000; m_Ninja.m_OldVelAmount = length(m_Core.m_Vel); GameServer()->CreateSound(m_Pos, SOUND_NINJA_FIRE); } break; - + } - + m_AttackTick = Server()->Tick(); - + if(m_aWeapons[m_ActiveWeapon].m_Ammo > 0) // -1 == unlimited m_aWeapons[m_ActiveWeapon].m_Ammo--; - + if(!m_ReloadTimer) m_ReloadTimer = g_pData->m_Weapons.m_aId[m_ActiveWeapon].m_Firedelay * Server()->TickSpeed() / 1000; } @@ -435,7 +435,7 @@ void CCharacter::HandleWeapons() { //ninja HandleNinja(); - + vec2 Direction = normalize(vec2(m_LatestInput.m_TargetX, m_LatestInput.m_TargetY)); // check reload timer @@ -470,14 +470,14 @@ void CCharacter::HandleWeapons() m_aWeapons[m_ActiveWeapon].m_AmmoRegenStart = -1; } } - + return; } bool CCharacter::GiveWeapon(int Weapon, int Ammo) { if(m_aWeapons[Weapon].m_Ammo < g_pData->m_Weapons.m_aId[Weapon].m_Maxammo || !m_aWeapons[Weapon].m_Got) - { + { m_aWeapons[Weapon].m_Got = true; m_aWeapons[Weapon].m_Ammo = min(g_pData->m_Weapons.m_aId[Weapon].m_Maxammo, Ammo); return true; @@ -492,7 +492,7 @@ void CCharacter::GiveNinja() m_aWeapons[WEAPON_NINJA].m_Ammo = -1; m_LastWeapon = m_ActiveWeapon; m_ActiveWeapon = WEAPON_NINJA; - + GameServer()->CreateSound(m_Pos, SOUND_PICKUP_NINJA); } @@ -507,27 +507,27 @@ void CCharacter::OnPredictedInput(CNetObj_PlayerInput *pNewInput) // check for changes if(mem_comp(&m_Input, pNewInput, sizeof(CNetObj_PlayerInput)) != 0) m_LastAction = Server()->Tick(); - + // copy new input mem_copy(&m_Input, pNewInput, sizeof(m_Input)); m_NumInputs++; - + // or are not allowed to aim in the center if(m_Input.m_TargetX == 0 && m_Input.m_TargetY == 0) - m_Input.m_TargetY = -1; + m_Input.m_TargetY = -1; } void CCharacter::OnDirectInput(CNetObj_PlayerInput *pNewInput) { mem_copy(&m_LatestPrevInput, &m_LatestInput, sizeof(m_LatestInput)); mem_copy(&m_LatestInput, pNewInput, sizeof(m_LatestInput)); - + if(m_NumInputs > 2 && m_pPlayer->GetTeam() != TEAM_SPECTATORS) { HandleWeaponSwitch(); FireWeapon(); } - + mem_copy(&m_LatestPrevInput, &m_LatestInput, sizeof(m_LatestInput)); } @@ -538,13 +538,13 @@ void CCharacter::Tick() char Buf[128]; str_format(Buf, sizeof(Buf), "You were moved to %s due to team balancing", GameServer()->m_pController->GetTeamName(m_pPlayer->GetTeam())); GameServer()->SendBroadcast(Buf, m_pPlayer->GetCID()); - + m_pPlayer->m_ForceBalanced = false; } m_Core.m_Input = m_Input; 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 || @@ -554,7 +554,7 @@ void CCharacter::Tick() { Die(m_pPlayer->GetCID(), WEAPON_WORLD); } - + // handle Weapons HandleWeapons(); @@ -573,18 +573,18 @@ void CCharacter::TickDefered() m_ReckoningCore.Move(); m_ReckoningCore.Quantize(); } - + //lastsentcore vec2 StartPos = m_Core.m_Pos; vec2 StartVel = m_Core.m_Vel; bool StuckBefore = GameServer()->Collision()->TestBox(m_Core.m_Pos, vec2(28.0f, 28.0f)); - + m_Core.Move(); bool StuckAfterMove = GameServer()->Collision()->TestBox(m_Core.m_Pos, vec2(28.0f, 28.0f)); m_Core.Quantize(); bool StuckAfterQuant = GameServer()->Collision()->TestBox(m_Core.m_Pos, vec2(28.0f, 28.0f)); m_Pos = m_Core.m_Pos; - + if(!StuckBefore && (StuckAfterMove || StuckAfterQuant)) { // Hackish solution to get rid of strict-aliasing warning @@ -600,7 +600,7 @@ void CCharacter::TickDefered() StartVelY.f = StartVel.y; char aBuf[256]; - str_format(aBuf, sizeof(aBuf), "STUCK!!! %d %d %d %f %f %f %f %x %x %x %x", + str_format(aBuf, sizeof(aBuf), "STUCK!!! %d %d %d %f %f %f %f %x %x %x %x", StuckBefore, StuckAfterMove, StuckAfterQuant, @@ -613,20 +613,20 @@ void CCharacter::TickDefered() int Events = m_Core.m_TriggeredEvents; int Mask = CmaskAllExceptOne(m_pPlayer->GetCID()); - + if(Events&COREEVENT_GROUND_JUMP) GameServer()->CreateSound(m_Pos, SOUND_PLAYER_JUMP, Mask); - + if(Events&COREEVENT_HOOK_ATTACH_PLAYER) GameServer()->CreateSound(m_Pos, SOUND_HOOK_ATTACH_PLAYER, CmaskAll()); if(Events&COREEVENT_HOOK_ATTACH_GROUND) GameServer()->CreateSound(m_Pos, SOUND_HOOK_ATTACH_GROUND, Mask); if(Events&COREEVENT_HOOK_HIT_NOHOOK) GameServer()->CreateSound(m_Pos, SOUND_HOOK_NOATTACH, Mask); - + if(m_pPlayer->GetTeam() == TEAM_SPECTATORS) { m_Pos.x = m_Input.m_TargetX; m_Pos.y = m_Input.m_TargetY; } - + // update the m_SendCore if needed { CNetObj_Character Predicted; @@ -684,10 +684,10 @@ void CCharacter::Die(int Killer, int Weapon) // a nice sound GameServer()->CreateSound(m_Pos, SOUND_PLAYER_DIE); - + // this is for auto respawn after 3 secs m_pPlayer->m_DieTick = Server()->Tick(); - + m_Alive = false; GameServer()->m_World.RemoveEntity(this); GameServer()->m_World.m_Core.m_apCharacters[m_pPlayer->GetCID()] = 0; @@ -697,7 +697,7 @@ void CCharacter::Die(int Killer, int Weapon) bool CCharacter::TakeDamage(vec2 Force, int Dmg, int From, int Weapon) { m_Core.m_Vel += Force; - + if(GameServer()->m_pController->IsFriendlyFire(m_pPlayer->GetCID(), From) && !g_Config.m_SvTeamdamage) return false; @@ -728,7 +728,7 @@ bool CCharacter::TakeDamage(vec2 Force, int Dmg, int From, int Weapon) m_Health--; Dmg--; } - + if(Dmg > m_Armor) { Dmg -= m_Armor; @@ -740,7 +740,7 @@ bool CCharacter::TakeDamage(vec2 Force, int Dmg, int From, int Weapon) Dmg = 0; } } - + m_Health -= Dmg; } @@ -754,7 +754,7 @@ bool CCharacter::TakeDamage(vec2 Force, int Dmg, int From, int Weapon) if(m_Health <= 0) { Die(From, Weapon); - + // set attacker's face to happy (taunt!) if (From >= 0 && From != m_pPlayer->GetCID() && GameServer()->m_apPlayers[From]) { @@ -765,7 +765,7 @@ bool CCharacter::TakeDamage(vec2 Force, int Dmg, int From, int Weapon) pChr->m_EmoteStop = Server()->Tick() + Server()->TickSpeed(); } } - + return false; } @@ -784,11 +784,11 @@ void CCharacter::Snap(int SnappingClient) { if(NetworkClipped(SnappingClient)) return; - + CNetObj_Character *pCharacter = static_cast<CNetObj_Character *>(Server()->SnapNewItem(NETOBJTYPE_CHARACTER, m_pPlayer->GetCID(), sizeof(CNetObj_Character))); if(!pCharacter) return; - + // write down the m_Core if(!m_ReckoningTick || GameServer()->m_World.m_Paused) { @@ -802,7 +802,7 @@ void CCharacter::Snap(int SnappingClient) pCharacter->m_Tick = m_ReckoningTick; m_SendCore.Write(pCharacter); } - + // set emote if (m_EmoteStop < Server()->Tick()) { @@ -815,7 +815,7 @@ void CCharacter::Snap(int SnappingClient) pCharacter->m_AmmoCount = 0; pCharacter->m_Health = 0; pCharacter->m_Armor = 0; - + pCharacter->m_Weapon = m_ActiveWeapon; pCharacter->m_AttackTick = m_AttackTick; diff --git a/src/game/server/entities/character.h b/src/game/server/entities/character.h index b4009058..611dc427 100644 --- a/src/game/server/entities/character.h +++ b/src/game/server/entities/character.h @@ -19,25 +19,25 @@ enum class CCharacter : public CEntity { MACRO_ALLOC_POOL_ID() - + public: //character's size static const int ms_PhysSize = 28; CCharacter(CGameWorld *pWorld); - + virtual void Reset(); virtual void Destroy(); virtual void Tick(); virtual void TickDefered(); virtual void Snap(int SnappingClient); - + bool IsGrounded(); - + void SetWeapon(int W); void HandleWeaponSwitch(); void DoWeaponSwitch(); - + void HandleWeapons(); void HandleNinja(); @@ -46,53 +46,53 @@ public: void FireWeapon(); void Die(int Killer, int Weapon); - bool TakeDamage(vec2 Force, int Dmg, int From, int Weapon); + bool TakeDamage(vec2 Force, int Dmg, int From, int Weapon); bool Spawn(class CPlayer *pPlayer, vec2 Pos); bool Remove(); - + bool IncreaseHealth(int Amount); bool IncreaseArmor(int Amount); - + bool GiveWeapon(int Weapon, int Ammo); void GiveNinja(); - + void SetEmote(int Emote, int Tick); - + bool IsAlive() const { return m_Alive; } class CPlayer *GetPlayer() { return m_pPlayer; } - + private: // player controlling this character class CPlayer *m_pPlayer; - + bool m_Alive; // weapon info CEntity *m_apHitObjects[10]; int m_NumObjectsHit; - + struct WeaponStat { int m_AmmoRegenStart; int m_Ammo; int m_Ammocost; bool m_Got; - + } m_aWeapons[NUM_WEAPONS]; - + int m_ActiveWeapon; int m_LastWeapon; int m_QueuedWeapon; - + int m_ReloadTimer; int m_AttackTick; - + int m_DamageTaken; int m_EmoteType; int m_EmoteStop; - + // last tick that the player took any action ie some input int m_LastAction; @@ -100,12 +100,12 @@ private: CNetObj_PlayerInput m_LatestPrevInput; CNetObj_PlayerInput m_LatestInput; - // input + // input CNetObj_PlayerInput m_PrevInput; CNetObj_PlayerInput m_Input; int m_NumInputs; int m_Jumped; - + int m_DamageTakenTick; int m_Health; @@ -120,9 +120,9 @@ private: int m_OldVelAmount; } m_Ninja; - // the player core for the physics + // the player core for the physics CCharacterCore m_Core; - + // info for dead reckoning int m_ReckoningTick; // tick that we are performing dead reckoning From CCharacterCore m_SendCore; // core that we should send diff --git a/src/game/server/entities/flag.cpp b/src/game/server/entities/flag.cpp index 5ac3de47..d279e4df 100644 --- a/src/game/server/entities/flag.cpp +++ b/src/game/server/entities/flag.cpp @@ -10,7 +10,7 @@ CFlag::CFlag(CGameWorld *pGameWorld, int Team) m_ProximityRadius = ms_PhysSize; m_pCarryingCharacter = NULL; m_GrabTick = 0; - + Reset(); } diff --git a/src/game/server/entities/flag.h b/src/game/server/entities/flag.h index 89f5e2c5..2f91bc02 100644 --- a/src/game/server/entities/flag.h +++ b/src/game/server/entities/flag.h @@ -12,12 +12,12 @@ public: CCharacter *m_pCarryingCharacter; vec2 m_Vel; vec2 m_StandPos; - + int m_Team; int m_AtStand; int m_DropTick; int m_GrabTick; - + CFlag(CGameWorld *pGameWorld, int Team); virtual void Reset(); diff --git a/src/game/server/entities/laser.cpp b/src/game/server/entities/laser.cpp index 184702cb..30ed0a9b 100644 --- a/src/game/server/entities/laser.cpp +++ b/src/game/server/entities/laser.cpp @@ -28,7 +28,7 @@ bool CLaser::HitCharacter(vec2 From, vec2 To) m_From = From; m_Pos = At; - m_Energy = -1; + m_Energy = -1; Hit->TakeDamage(vec2(0.f, 0.f), GameServer()->Tuning()->m_LaserDamage, m_Owner, WEAPON_RIFLE); return true; } @@ -36,16 +36,16 @@ bool CLaser::HitCharacter(vec2 From, vec2 To) void CLaser::DoBounce() { m_EvalTick = Server()->Tick(); - + if(m_Energy < 0) { GameServer()->m_World.DestroyEntity(this); return; } - + vec2 To = m_Pos + m_Dir * m_Energy; vec2 OrgTo = To; - + if(GameServer()->Collision()->IntersectLine(m_Pos, To, 0x0, &To)) { if(!HitCharacter(m_Pos, To)) @@ -56,17 +56,17 @@ void CLaser::DoBounce() vec2 TempPos = m_Pos; vec2 TempDir = m_Dir * 4.0f; - + GameServer()->Collision()->MovePoint(&TempPos, &TempDir, 1.0f, 0); m_Pos = TempPos; m_Dir = normalize(TempDir); - + m_Energy -= distance(m_From, m_Pos) + GameServer()->Tuning()->m_LaserBounceCost; m_Bounces++; - + if(m_Bounces > GameServer()->Tuning()->m_LaserBounceNum) m_Energy = -1; - + GameServer()->CreateSound(m_Pos, SOUND_RIFLE_BOUNCE); } } @@ -80,7 +80,7 @@ void CLaser::DoBounce() } } } - + void CLaser::Reset() { GameServer()->m_World.DestroyEntity(this); diff --git a/src/game/server/entities/laser.h b/src/game/server/entities/laser.h index 91ba5df6..1d7fa227 100644 --- a/src/game/server/entities/laser.h +++ b/src/game/server/entities/laser.h @@ -9,15 +9,15 @@ class CLaser : public CEntity { public: CLaser(CGameWorld *pGameWorld, vec2 Pos, vec2 Direction, float StartEnergy, int Owner); - + virtual void Reset(); virtual void Tick(); virtual void Snap(int SnappingClient); - + protected: bool HitCharacter(vec2 From, vec2 To); void DoBounce(); - + private: vec2 m_From; vec2 m_Dir; diff --git a/src/game/server/entities/pickup.cpp b/src/game/server/entities/pickup.cpp index 56b319d2..ba26d85b 100644 --- a/src/game/server/entities/pickup.cpp +++ b/src/game/server/entities/pickup.cpp @@ -12,7 +12,7 @@ CPickup::CPickup(CGameWorld *pGameWorld, int Type, int SubType) m_ProximityRadius = PickupPhysSize; Reset(); - + GameWorld()->InsertEntity(this); } @@ -55,7 +55,7 @@ void CPickup::Tick() RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime; } break; - + case POWERUP_ARMOR: if(pChr->IncreaseArmor(1)) { @@ -83,7 +83,7 @@ void CPickup::Tick() } } break; - + case POWERUP_NINJA: { // activate ninja on target player @@ -101,7 +101,7 @@ void CPickup::Tick() pChr->SetEmote(EMOTE_ANGRY, Server()->Tick() + 1200 * Server()->TickSpeed() / 1000); break; } - + default: break; }; diff --git a/src/game/server/entities/pickup.h b/src/game/server/entities/pickup.h index 47a8ed6f..77347de2 100644 --- a/src/game/server/entities/pickup.h +++ b/src/game/server/entities/pickup.h @@ -11,11 +11,11 @@ class CPickup : public CEntity { public: CPickup(CGameWorld *pGameWorld, int Type, int SubType = 0); - + virtual void Reset(); virtual void Tick(); virtual void Snap(int SnappingClient); - + private: int m_Type; int m_Subtype; diff --git a/src/game/server/entities/projectile.cpp b/src/game/server/entities/projectile.cpp index 07e96627..2baa24b1 100644 --- a/src/game/server/entities/projectile.cpp +++ b/src/game/server/entities/projectile.cpp @@ -32,25 +32,25 @@ vec2 CProjectile::GetPos(float Time) { float Curvature = 0; float Speed = 0; - + switch(m_Type) { case WEAPON_GRENADE: Curvature = GameServer()->Tuning()->m_GrenadeCurvature; Speed = GameServer()->Tuning()->m_GrenadeSpeed; break; - + case WEAPON_SHOTGUN: Curvature = GameServer()->Tuning()->m_ShotgunCurvature; Speed = GameServer()->Tuning()->m_ShotgunSpeed; break; - + case WEAPON_GUN: Curvature = GameServer()->Tuning()->m_GunCurvature; Speed = GameServer()->Tuning()->m_GunSpeed; break; } - + return CalcPos(m_Pos, m_Direction, Curvature, Speed, Time); } @@ -66,7 +66,7 @@ void CProjectile::Tick() CCharacter *TargetChr = GameServer()->m_World.IntersectCharacter(PrevPos, CurPos, 6.0f, CurPos, OwnerChar); m_LifeSpan--; - + if(TargetChr || Collide || m_LifeSpan < 0 || GameLayerClipped(CurPos)) { if(m_LifeSpan >= 0 || m_Weapon == WEAPON_GRENADE) @@ -74,7 +74,7 @@ void CProjectile::Tick() if(m_Explosive) GameServer()->CreateExplosion(CurPos, m_Owner, m_Weapon, false); - + else if(TargetChr) TargetChr->TakeDamage(m_Direction * max(0.001f, m_Force), m_Damage, m_Owner, m_Weapon); @@ -95,7 +95,7 @@ void CProjectile::FillInfo(CNetObj_Projectile *pProj) void CProjectile::Snap(int SnappingClient) { float Ct = (Server()->Tick()-m_StartTick)/(float)Server()->TickSpeed(); - + if(NetworkClipped(SnappingClient, GetPos(Ct))) return; diff --git a/src/game/server/entities/projectile.h b/src/game/server/entities/projectile.h index 5e534066..5df04bcd 100644 --- a/src/game/server/entities/projectile.h +++ b/src/game/server/entities/projectile.h @@ -15,7 +15,7 @@ public: virtual void Reset(); virtual void Tick(); virtual void Snap(int SnappingClient); - + private: vec2 m_Direction; int m_LifeSpan; diff --git a/src/game/server/entity.cpp b/src/game/server/entity.cpp index 03b55982..788c3f45 100644 --- a/src/game/server/entity.cpp +++ b/src/game/server/entity.cpp @@ -10,12 +10,12 @@ CEntity::CEntity(CGameWorld *pGameWorld, int ObjType) { m_pGameWorld = pGameWorld; - + m_ObjType = ObjType; m_Pos = vec2(0,0); m_ProximityRadius = 0; - m_MarkedForDestroy = false; + m_MarkedForDestroy = false; m_ID = Server()->SnapNewID(); m_pPrevTypeEntity = 0; @@ -37,13 +37,13 @@ int CEntity::NetworkClipped(int SnappingClient, vec2 CheckPos) { if(SnappingClient == -1) return 0; - + float dx = GameServer()->m_apPlayers[SnappingClient]->m_ViewPos.x-CheckPos.x; float dy = GameServer()->m_apPlayers[SnappingClient]->m_ViewPos.y-CheckPos.y; - + if(absolute(dx) > 1000.0f || absolute(dy) > 800.0f) return 1; - + if(distance(GameServer()->m_apPlayers[SnappingClient]->m_ViewPos, CheckPos) > 1100.0f) return 1; return 0; diff --git a/src/game/server/entity.h b/src/game/server/entity.h index ff4d82eb..b9b33eb7 100644 --- a/src/game/server/entity.h +++ b/src/game/server/entity.h @@ -28,7 +28,7 @@ void *operator new(size_t Size, int id); \ void operator delete(void *p); \ private: - + #define MACRO_ALLOC_POOL_ID_IMPL(POOLTYPE, PoolSize) \ static char ms_PoolData##POOLTYPE[PoolSize][sizeof(POOLTYPE)] = {{0}}; \ static int ms_PoolUsed##POOLTYPE[PoolSize] = {0}; \ @@ -49,7 +49,7 @@ ms_PoolUsed##POOLTYPE[id] = 0; \ mem_zero(ms_PoolData##POOLTYPE[id], sizeof(POOLTYPE)); \ } - + /* Class: Entity Basic entity class. @@ -61,7 +61,7 @@ class CEntity friend class CGameWorld; // entity list handling CEntity *m_pPrevTypeEntity; CEntity *m_pNextTypeEntity; - + class CGameWorld *m_pGameWorld; protected: bool m_MarkedForDestroy; @@ -70,12 +70,12 @@ protected: 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; } @@ -84,14 +84,14 @@ public: Destorys the entity. */ virtual void Destroy() { delete this; } - + /* Function: reset Called when the game resets the map. Puts the entity back to it's starting state or perhaps destroys it. */ virtual void Reset() {} - + /* Function: tick Called progress the entity to the next tick. Updates @@ -104,12 +104,12 @@ public: Called after all entities tick() function has been called. */ virtual void TickDefered() {} - + /* Function: snap Called when a new snapshot is being generated for a specific client. - + Arguments: snapping_client - ID of the client which snapshot is being generated. Could be -1 to create a complete @@ -117,7 +117,7 @@ public: recording. */ virtual void Snap(int SnappingClient) {} - + /* Function: networkclipped(int snapping_client) Performs a series of test to see if a client can see the @@ -128,13 +128,13 @@ public: being generated. Could be -1 to create a complete snapshot of everything in the game for demo recording. - + Returns: Non-zero if the entity doesn't have to be in the snapshot. */ int NetworkClipped(int SnappingClient); int NetworkClipped(int SnappingClient, vec2 CheckPos); - + bool GameLayerClipped(vec2 CheckPos); /* @@ -142,7 +142,7 @@ public: Contains the physical size of the entity. */ float m_ProximityRadius; - + /* Variable: pos Contains the current posititon of the entity. diff --git a/src/game/server/eventhandler.h b/src/game/server/eventhandler.h index ea9fcb15..721b59af 100644 --- a/src/game/server/eventhandler.h +++ b/src/game/server/eventhandler.h @@ -9,20 +9,20 @@ class CEventHandler static const int MAX_EVENTS = 128; static const int MAX_DATASIZE = 128*64; - int m_aTypes[MAX_EVENTS]; // TODO: remove some of these arrays + int m_aTypes[MAX_EVENTS]; // TODO: remove some of these arrays int m_aOffsets[MAX_EVENTS]; int m_aSizes[MAX_EVENTS]; int m_aClientMasks[MAX_EVENTS]; char m_aData[MAX_DATASIZE]; - + class CGameContext *m_pGameServer; - + int m_CurrentOffset; int m_NumEvents; public: CGameContext *GameServer() const { return m_pGameServer; } void SetGameServer(CGameContext *pGameServer); - + CEventHandler(); void *Create(int Type, int Size, int Mask = -1); void Clear(); diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index a0c1c64a..82adcbef 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -24,10 +24,10 @@ void CGameContext::Construct(int Resetting) { m_Resetting = 0; m_pServer = 0; - + for(int i = 0; i < MAX_CLIENTS; i++) m_apPlayers[i] = 0; - + m_pController = 0; m_VoteCloseTime = 0; m_pVoteOptionFirst = 0; @@ -241,7 +241,7 @@ void CGameContext::SendChat(int ChatterClientID, int Team, const char *pText) Msg.m_Team = 1; Msg.m_ClientID = ChatterClientID; Msg.m_pMessage = pText; - + // pack one for the recording only Server()->SendPackMsg(&Msg, MSGFLAG_VITAL|MSGFLAG_NOSEND, -1); @@ -277,7 +277,7 @@ void CGameContext::SendBroadcast(const char *pText, int ClientID) Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ClientID); } -// +// void CGameContext::StartVote(const char *pDesc, const char *pCommand, const char *pReason) { // check if a vote is already running @@ -294,7 +294,7 @@ void CGameContext::StartVote(const char *pDesc, const char *pCommand, const char m_apPlayers[i]->m_VotePos = 0; } } - + // start vote m_VoteCloseTime = time_get() + time_freq()*25; str_copy(m_aVoteDescription, pDesc, sizeof(m_aVoteDescription)); @@ -338,7 +338,7 @@ void CGameContext::SendVoteStatus(int ClientID, int Total, int Yes, int No) Msg.m_Pass = Total - (Yes+No); Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ClientID); - + } void CGameContext::AbortVoteKickOnDisconnect(int ClientID) @@ -353,7 +353,7 @@ void CGameContext::CheckPureTuning() // might not be created yet during start up if(!m_pController) return; - + if( str_comp(m_pController->m_pGameType, "DM")==0 || str_comp(m_pController->m_pGameType, "TDM")==0 || str_comp(m_pController->m_pGameType, "CTF")==0) @@ -364,13 +364,13 @@ void CGameContext::CheckPureTuning() Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "resetting tuning due to pure server"); m_Tuning = p; } - } + } } void CGameContext::SendTuningParams(int ClientID) { CheckPureTuning(); - + CMsgPacker Msg(NETMSGTYPE_SV_TUNEPARAMS); int *pParams = (int *)&m_Tuning; for(unsigned i = 0; i < sizeof(m_Tuning)/sizeof(int); i++) @@ -389,7 +389,7 @@ void CGameContext::OnTick() //if(world.paused) // make sure that the game object always updates m_pController->Tick(); - + for(int i = 0; i < MAX_CLIENTS; i++) { if(m_apPlayers[i]) @@ -398,7 +398,7 @@ void CGameContext::OnTick() m_apPlayers[i]->PostTick(); } } - + // update voting if(m_VoteCloseTime) { @@ -423,10 +423,10 @@ void CGameContext::OnTick() { if(!m_apPlayers[i] || m_apPlayers[i]->GetTeam() == TEAM_SPECTATORS || aVoteChecked[i]) // don't count in votes by spectators continue; - + int ActVote = m_apPlayers[i]->m_Vote; int ActVotePos = m_apPlayers[i]->m_VotePos; - + // check for more players with the same ip (only use the vote of the one who voted first) for(int j = i+1; j < MAX_CLIENTS; ++j) { @@ -453,13 +453,13 @@ void CGameContext::OnTick() else if(No >= (Total+1)/2) m_VoteEnforce = VOTE_ENFORCE_NO; } - + if(m_VoteEnforce == VOTE_ENFORCE_YES) { Console()->ExecuteLine(m_aVoteCommand); EndVote(); SendChat(-1, CGameContext::CHAT_ALL, "Vote passed"); - + if(m_apPlayers[m_VoteCreator]) m_apPlayers[m_VoteCreator]->m_LastVoteCall = 0; } @@ -475,7 +475,7 @@ void CGameContext::OnTick() } } } - + #ifdef CONF_DEBUG if(g_Config.m_DbgDummies) @@ -487,7 +487,7 @@ void CGameContext::OnTick() m_apPlayers[MAX_CLIENTS-i-1]->OnPredictedInput(&Input); } } -#endif +#endif } // Server hooks @@ -509,7 +509,7 @@ void CGameContext::OnClientEnter(int ClientID) m_apPlayers[ClientID]->Respawn(); char aBuf[512]; str_format(aBuf, sizeof(aBuf), "'%s' entered and joined the %s", Server()->ClientName(ClientID), m_pController->GetTeamName(m_apPlayers[ClientID]->GetTeam())); - SendChat(-1, CGameContext::CHAT_ALL, aBuf); + SendChat(-1, CGameContext::CHAT_ALL, aBuf); str_format(aBuf, sizeof(aBuf), "team_join player='%d:%s' team=%d", ClientID, Server()->ClientName(ClientID), m_apPlayers[ClientID]->GetTeam()); Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf); @@ -525,7 +525,7 @@ void CGameContext::OnClientConnected(int ClientID) m_apPlayers[ClientID] = new(ClientID) CPlayer(this, ClientID, StartTeam); //players[client_id].init(client_id); //players[client_id].client_id = client_id; - + (void)m_pController->CheckTeamBalance(); #ifdef CONF_DEBUG @@ -552,7 +552,7 @@ void CGameContext::OnClientDrop(int ClientID, const char *pReason) m_apPlayers[ClientID]->OnDisconnect(pReason); delete m_apPlayers[ClientID]; m_apPlayers[ClientID] = 0; - + (void)m_pController->CheckTeamBalance(); m_VoteUpdate = true; @@ -568,7 +568,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) { void *pRawMsg = m_NetObjHandler.SecureUnpackMsg(MsgID, pUnpacker); CPlayer *pPlayer = m_apPlayers[ClientID]; - + if(!pRawMsg) { char aBuf[256]; @@ -576,7 +576,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "server", aBuf); return; } - + if(MsgID == NETMSGTYPE_CL_SAY) { CNetMsg_Cl_Say *pMsg = (CNetMsg_Cl_Say *)pRawMsg; @@ -585,10 +585,10 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) Team = pPlayer->GetTeam(); else Team = CGameContext::CHAT_ALL; - + if(g_Config.m_SvSpamprotection && pPlayer->m_LastChat && pPlayer->m_LastChat+Server()->TickSpeed() > Server()->Tick()) return; - + pPlayer->m_LastChat = Server()->Tick(); // check for invalid chars @@ -599,7 +599,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) *pMessage = ' '; pMessage++; } - + SendChat(ClientID, Team, pMsg->m_pMessage); } else if(MsgID == NETMSGTYPE_CL_CALLVOTE) @@ -620,7 +620,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) SendChatTarget(ClientID, "Wait for current vote to end before calling a new one."); return; } - + int Timeleft = pPlayer->m_LastVoteCall + Server()->TickSpeed()*60 - Now; if(pPlayer->m_LastVoteCall && Timeleft > 0) { @@ -629,7 +629,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) SendChatTarget(ClientID, aChatmsg); return; } - + char aChatmsg[512] = {0}; char aDesc[VOTE_DESC_LENGTH] = {0}; char aCmd[VOTE_CMD_LENGTH] = {0}; @@ -652,7 +652,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) pOption = pOption->m_pNext; } - + if(!pOption) { str_format(aChatmsg, sizeof(aChatmsg), "'%s' isn't an option on this server", pMsg->m_Value); @@ -682,7 +682,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) return; } } - + int KickID = str_toint(pMsg->m_Value); if(KickID < 0 || KickID >= MAX_CLIENTS || !m_apPlayers[KickID]) { @@ -702,7 +702,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) SendChatTarget(KickID, aBufKick); return; } - + str_format(aChatmsg, sizeof(aChatmsg), "'%s' called for vote to kick '%s' (%s)", Server()->ClientName(ClientID), Server()->ClientName(KickID), pReason); str_format(aDesc, sizeof(aDesc), "Kick '%s'", Server()->ClientName(KickID)); if (!g_Config.m_SvVoteKickBantime) @@ -722,7 +722,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) SendChatTarget(ClientID, "Server does not allow voting to move players to spectators"); return; } - + int SpectateID = str_toint(pMsg->m_Value); if(SpectateID < 0 || SpectateID >= MAX_CLIENTS || !m_apPlayers[SpectateID] || m_apPlayers[SpectateID]->GetTeam() == TEAM_SPECTATORS) { @@ -734,12 +734,12 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) SendChatTarget(ClientID, "You cant move yourself"); return; } - + str_format(aChatmsg, sizeof(aChatmsg), "'%s' called for vote to move '%s' to spectators (%s)", Server()->ClientName(ClientID), Server()->ClientName(SpectateID), pReason); str_format(aDesc, sizeof(aDesc), "move '%s' to spectators", Server()->ClientName(SpectateID)); str_format(aCmd, sizeof(aCmd), "set_team %d -1", SpectateID); } - + if(aCmd[0]) { SendChat(-1, CGameContext::CHAT_ALL, aChatmsg); @@ -769,7 +769,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) else if (MsgID == NETMSGTYPE_CL_SETTEAM && !m_World.m_Paused) { CNetMsg_Cl_SetTeam *pMsg = (CNetMsg_Cl_SetTeam *)pRawMsg; - + if(pPlayer->GetTeam() == pMsg->m_Team || (g_Config.m_SvSpamprotection && pPlayer->m_LastSetTeam && pPlayer->m_LastSetTeam+Server()->TickSpeed()*3 > Server()->Tick())) return; @@ -797,7 +797,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) else if (MsgID == NETMSGTYPE_CL_SETSPECTATORMODE && !m_World.m_Paused) { CNetMsg_Cl_SetSpectatorMode *pMsg = (CNetMsg_Cl_SetSpectatorMode *)pRawMsg; - + if(pPlayer->GetTeam() != TEAM_SPECTATORS || pPlayer->m_SpectatorID == pMsg->m_SpectatorID || ClientID == pMsg->m_SpectatorID || (g_Config.m_SvSpamprotection && pPlayer->m_LastSetSpectatorMode && pPlayer->m_LastSetSpectatorMode+Server()->TickSpeed()*3 > Server()->Tick())) return; @@ -809,13 +809,13 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) pPlayer->m_SpectatorID = pMsg->m_SpectatorID; } else if (MsgID == NETMSGTYPE_CL_STARTINFO) - { + { if(pPlayer->m_IsReady) return; - CNetMsg_Cl_StartInfo *pMsg = (CNetMsg_Cl_StartInfo *)pRawMsg; + CNetMsg_Cl_StartInfo *pMsg = (CNetMsg_Cl_StartInfo *)pRawMsg; pPlayer->m_LastChangeInfo = Server()->Tick(); - + // set start infos Server()->SetClientName(ClientID, pMsg->m_pName); Server()->SetClientClan(ClientID, pMsg->m_pClan); @@ -829,7 +829,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) // send vote options CNetMsg_Sv_VoteClearOptions ClearMsg; Server()->SendPackMsg(&ClearMsg, MSGFLAG_VITAL, ClientID); - + CNetMsg_Sv_VoteOptionListAdd OptionMsg; int NumOptions = 0; OptionMsg.m_pDescription0 = ""; @@ -897,7 +897,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) Server()->SendPackMsg(&OptionMsg, MSGFLAG_VITAL, ClientID); NumOptions = 0; } - + // send tuning parameters to client SendTuningParams(ClientID); @@ -907,16 +907,16 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) Server()->SendPackMsg(&m, MSGFLAG_VITAL|MSGFLAG_FLUSH, ClientID); } else if (MsgID == NETMSGTYPE_CL_CHANGEINFO) - { + { if(g_Config.m_SvSpamprotection && pPlayer->m_LastChangeInfo && pPlayer->m_LastChangeInfo+Server()->TickSpeed()*5 > Server()->Tick()) return; - + CNetMsg_Cl_ChangeInfo *pMsg = (CNetMsg_Cl_ChangeInfo *)pRawMsg; pPlayer->m_LastChangeInfo = Server()->Tick(); - + // set infos char aOldName[MAX_NAME_LENGTH]; - str_copy(aOldName, Server()->ClientName(ClientID), sizeof(aOldName)); + str_copy(aOldName, Server()->ClientName(ClientID), sizeof(aOldName)); Server()->SetClientName(ClientID, pMsg->m_pName); if(str_comp(aOldName, Server()->ClientName(ClientID)) != 0) { @@ -935,19 +935,19 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) else if (MsgID == NETMSGTYPE_CL_EMOTICON && !m_World.m_Paused) { CNetMsg_Cl_Emoticon *pMsg = (CNetMsg_Cl_Emoticon *)pRawMsg; - + if(g_Config.m_SvSpamprotection && pPlayer->m_LastEmote && pPlayer->m_LastEmote+Server()->TickSpeed()*3 > Server()->Tick()) return; - + pPlayer->m_LastEmote = Server()->Tick(); - + SendEmoticon(ClientID, pMsg->m_Emoticon); } else if (MsgID == NETMSGTYPE_CL_KILL && !m_World.m_Paused) { if(pPlayer->m_LastKill && pPlayer->m_LastKill+Server()->TickSpeed()*3 > Server()->Tick()) return; - + pPlayer->m_LastKill = Server()->Tick(); pPlayer->KillCharacter(WEAPON_SELF); } @@ -1024,14 +1024,14 @@ void CGameContext::ConSetTeam(IConsole::IResult *pResult, void *pUserData) CGameContext *pSelf = (CGameContext *)pUserData; int ClientID = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1); int Team = clamp(pResult->GetInteger(1), -1, 1); - + char aBuf[256]; str_format(aBuf, sizeof(aBuf), "moved client %d to team %d", ClientID, Team); pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); - + if(!pSelf->m_apPlayers[ClientID]) return; - + pSelf->m_apPlayers[ClientID]->SetTeam(Team); (void)pSelf->m_pController->CheckTeamBalance(); } @@ -1040,15 +1040,15 @@ void CGameContext::ConSetTeamAll(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; int Team = clamp(pResult->GetInteger(0), -1, 1); - + char aBuf[256]; str_format(aBuf, sizeof(aBuf), "moved all clients to team %d", Team); pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); - + for(int i = 0; i < MAX_CLIENTS; ++i) if(pSelf->m_apPlayers[i]) pSelf->m_apPlayers[i]->SetTeam(Team); - + (void)pSelf->m_pController->CheckTeamBalance(); } @@ -1063,7 +1063,7 @@ void CGameContext::ConAddVote(IConsole::IResult *pResult, void *pUserData) pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "maximum number of vote options reached"); return; } - + // check for valid option if(!pSelf->Console()->LineIsValid(pCommand) || str_length(pCommand) >= VOTE_CMD_LENGTH) { @@ -1081,7 +1081,7 @@ void CGameContext::ConAddVote(IConsole::IResult *pResult, void *pUserData) pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); return; } - + // check for duplicate entry CVoteOptionServer *pOption = pSelf->m_pVoteOptionFirst; while(pOption) @@ -1095,11 +1095,11 @@ void CGameContext::ConAddVote(IConsole::IResult *pResult, void *pUserData) } pOption = pOption->m_pNext; } - + // add the option ++pSelf->m_NumVoteOptions; int Len = str_length(pCommand); - + pOption = (CVoteOptionServer *)pSelf->m_pVoteOptionHeap->Allocate(sizeof(CVoteOptionServer) + Len); pOption->m_pNext = 0; pOption->m_pPrev = pSelf->m_pVoteOptionLast; @@ -1108,7 +1108,7 @@ void CGameContext::ConAddVote(IConsole::IResult *pResult, void *pUserData) pSelf->m_pVoteOptionLast = pOption; if(!pSelf->m_pVoteOptionFirst) pSelf->m_pVoteOptionFirst = pOption; - + str_copy(pOption->m_aDescription, pDescription, sizeof(pOption->m_aDescription)); mem_copy(pOption->m_aCommand, pCommand, Len+1); char aBuf[256]; @@ -1125,7 +1125,7 @@ void CGameContext::ConRemoveVote(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; const char *pDescription = pResult->GetString(0); - + // check for valid option CVoteOptionServer *pOption = pSelf->m_pVoteOptionFirst; while(pOption) @@ -1146,7 +1146,7 @@ void CGameContext::ConRemoveVote(IConsole::IResult *pResult, void *pUserData) CNetMsg_Sv_VoteOptionRemove OptionMsg; OptionMsg.m_pDescription = pOption->m_aDescription; pSelf->Server()->SendPackMsg(&OptionMsg, MSGFLAG_VITAL, -1); - + // TODO: improve this // remove the option --pSelf->m_NumVoteOptions; @@ -1173,7 +1173,7 @@ void CGameContext::ConRemoveVote(IConsole::IResult *pResult, void *pUserData) pVoteOptionLast = pDst; if(!pVoteOptionFirst) pVoteOptionFirst = pDst; - + str_copy(pDst->m_aDescription, pSrc->m_aDescription, sizeof(pDst->m_aDescription)); mem_copy(pDst->m_aCommand, pSrc->m_aCommand, Len+1); } @@ -1209,7 +1209,7 @@ void CGameContext::ConForceVote(IConsole::IResult *pResult, void *pUserData) pOption = pOption->m_pNext; } - + if(!pOption) { str_format(aBuf, sizeof(aBuf), "'%s' isn't an option on this server", pValue); @@ -1247,7 +1247,7 @@ void CGameContext::ConForceVote(IConsole::IResult *pResult, void *pUserData) pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "Invalid client id to move"); return; } - + str_format(aBuf, sizeof(aBuf), "set_team %d -1", SpectateID); pSelf->Console()->ExecuteLine(aBuf); } @@ -1323,10 +1323,10 @@ void CGameContext::OnInit(/*class IKernel *pKernel*/) m_pConsole = Kernel()->RequestInterface<IConsole>(); m_World.SetGameServer(this); m_Events.SetGameServer(this); - + //if(!data) // only load once //data = load_data_from_memory(internal_data); - + for(int i = 0; i < NUM_NETOBJTYPES; i++) Server()->SnapSetStaticsize(i, m_NetObjHandler.GetObjSize(i)); @@ -1354,22 +1354,22 @@ void CGameContext::OnInit(/*class IKernel *pKernel*/) // create all entities from the game layer CMapItemLayerTilemap *pTileMap = m_Layers.GameLayer(); CTile *pTiles = (CTile *)Kernel()->RequestInterface<IMap>()->GetData(pTileMap->m_Data); - - - - + + + + /* num_spawn_points[0] = 0; num_spawn_points[1] = 0; num_spawn_points[2] = 0; */ - + for(int y = 0; y < pTileMap->m_Height; y++) { for(int x = 0; x < pTileMap->m_Width; x++) { int Index = pTiles[y*pTileMap->m_Width+x].m_Index; - + if(Index >= ENTITY_OFFSET) { vec2 Pos(x*32.0f+16.0f, y*32.0f+16.0f); @@ -1403,7 +1403,7 @@ void CGameContext::OnSnap(int ClientID) m_World.Snap(ClientID); m_pController->Snap(ClientID); m_Events.Snap(ClientID); - + for(int i = 0; i < MAX_CLIENTS; i++) { if(m_apPlayers[i]) diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index 576a1b10..6288850d 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -25,7 +25,7 @@ Remove entities marked for deletion (GAMEWORLD::remove_entities) Game Controller (GAMECONTROLLER::tick) All players (CPlayer::tick) - + Snap Game Context (CGameContext::snap) @@ -60,7 +60,7 @@ class CGameContext : public IGameServer static void ConClearVotes(IConsole::IResult *pResult, void *pUserData); static void ConVote(IConsole::IResult *pResult, void *pUserData); static void ConchainSpecialMotdupdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData); - + CGameContext(int Resetting); void Construct(int Resetting); @@ -73,25 +73,25 @@ public: CGameContext(); ~CGameContext(); - + void Clear(); - + CEventHandler m_Events; CPlayer *m_apPlayers[MAX_CLIENTS]; IGameController *m_pController; CGameWorld m_World; - + // helper functions class CCharacter *GetPlayerChar(int ClientID); - + // voting void StartVote(const char *pDesc, const char *pCommand, const char *pReason); void EndVote(); void SendVoteSet(int ClientID); void SendVoteStatus(int ClientID, int Total, int Yes, int No); void AbortVoteKickOnDisconnect(int ClientID); - + int m_VoteCreator; int64 m_VoteCloseTime; bool m_VoteUpdate; @@ -118,7 +118,7 @@ public: void CreatePlayerSpawn(vec2 Pos); void CreateDeath(vec2 Pos, int Who); void CreateSound(vec2 Pos, int Sound, int Mask=-1); - void CreateSoundGlobal(int Sound, int Target=-1); + void CreateSoundGlobal(int Sound, int Target=-1); enum @@ -135,22 +135,22 @@ public: void SendEmoticon(int ClientID, int Emoticon); void SendWeaponPickup(int ClientID, int Weapon); void SendBroadcast(const char *pText, int ClientID); - - + + // void CheckPureTuning(); void SendTuningParams(int ClientID); - + // engine events virtual void OnInit(); virtual void OnConsoleInit(); virtual void OnShutdown(); - + virtual void OnTick(); virtual void OnPreSnap(); virtual void OnSnap(int ClientID); virtual void OnPostSnap(); - + virtual void OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID); virtual void OnClientConnected(int ClientID); diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp index c5a96570..6685bba3 100644 --- a/src/game/server/gamecontroller.cpp +++ b/src/game/server/gamecontroller.cpp @@ -15,7 +15,7 @@ IGameController::IGameController(class CGameContext *pGameServer) m_pGameServer = pGameServer; m_pServer = m_pGameServer->Server(); m_pGameType = "unknown"; - + // DoWarmup(g_Config.m_SvWarmup); m_GameOverTick = -1; @@ -26,10 +26,10 @@ IGameController::IGameController(class CGameContext *pGameServer) m_aTeamscore[TEAM_RED] = 0; m_aTeamscore[TEAM_BLUE] = 0; m_aMapWish[0] = 0; - + m_UnbalancedTick = -1; m_ForceBalanced = false; - + m_aNumSpawnPoints[0] = 0; m_aNumSpawnPoints[1] = 0; m_aNumSpawnPoints[2] = 0; @@ -49,18 +49,18 @@ float IGameController::EvaluateSpawnPos(CSpawnEval *pEval, vec2 Pos) float Scoremod = 1.0f; if(pEval->m_FriendlyTeam != -1 && pC->GetPlayer()->GetTeam() == pEval->m_FriendlyTeam) Scoremod = 0.5f; - + float d = distance(Pos, pC->m_Pos); Score += Scoremod * (d == 0 ? 1000000000.0f : 1.0f/d); } - + return Score; } void IGameController::EvaluateSpawnType(CSpawnEval *pEval, int Type) { // get spawn point - for(int i = 0; i < m_aNumSpawnPoints[Type]; i++) + for(int i = 0; i < m_aNumSpawnPoints[Type]; i++) { // check if the position is occupado if(GameServer()->m_World.FindEntities(m_aaSpawnPoints[Type][i], 64, 0, 1, CGameWorld::ENTTYPE_CHARACTER)) @@ -80,7 +80,7 @@ void IGameController::EvaluateSpawnType(CSpawnEval *pEval, int Type) void IGameController::FindFreeSpawn(CSpawnEval *pEval, int Type) { // pick the spawn point that is least occupied and has free space for spawning around it - for(int i = 0; i < m_aNumSpawnPoints[Type]; i++) + for(int i = 0; i < m_aNumSpawnPoints[Type]; i++) { CCharacter *aEnts[MAX_CLIENTS]; @@ -88,7 +88,7 @@ void IGameController::FindFreeSpawn(CSpawnEval *pEval, int Type) float Score = 0.0f; for(int c = 0; c < Num; ++c) Score += 96.0f - distance(aEnts[c]->m_Pos, m_aaSpawnPoints[Type][i]); - + if(!pEval->m_Got || pEval->m_Score > Score) { // start, left, up, right, down @@ -121,15 +121,15 @@ void IGameController::FindFreeSpawn(CSpawnEval *pEval, int Type) bool IGameController::CanSpawn(int Team, vec2 *pOutPos) { CSpawnEval Eval; - + // spectators can't spawn if(Team == TEAM_SPECTATORS) return false; - + if(IsTeamplay()) { Eval.m_FriendlyTeam = Team; - + // first try own team spawn, then normal spawn and then enemy EvaluateSpawnType(&Eval, 1+(Team&1)); if(!Eval.m_Got) @@ -167,7 +167,7 @@ bool IGameController::CanSpawn(int Team, vec2 *pOutPos) FindFreeSpawn(&Eval, 2); } } - + *pOutPos = Eval.m_Pos; return Eval.m_Got; } @@ -177,7 +177,7 @@ bool IGameController::OnEntity(int Index, vec2 Pos) { int Type = -1; int SubType = 0; - + if(Index == ENTITY_SPAWN) m_aaSpawnPoints[0][m_aNumSpawnPoints[0]++] = Pos; else if(Index == ENTITY_SPAWN_RED) @@ -208,7 +208,7 @@ bool IGameController::OnEntity(int Index, vec2 Pos) Type = POWERUP_NINJA; SubType = WEAPON_NINJA; } - + if(Type != -1) { CPickup *pPickup = new CPickup(&GameServer()->m_World, Type, SubType); @@ -223,7 +223,7 @@ void IGameController::EndRound() { if(m_Warmup) // game can't end when we are running warmup return; - + GameServer()->m_World.m_Paused = true; m_GameOverTick = Server()->Tick(); m_SuddenDeath = 0; @@ -248,7 +248,7 @@ const char *IGameController::GetTeamName(int Team) if(Team == 0) return "game"; } - + return "spectators"; } @@ -257,7 +257,7 @@ static bool IsSeparator(char c) { return c == ';' || c == ' ' || c == ',' || c = void IGameController::StartRound() { ResetGame(); - + m_RoundStartTick = Server()->Tick(); m_SuddenDeath = 0; m_GameOverTick = -1; @@ -293,11 +293,11 @@ void IGameController::CycleMap() if(m_RoundCount < g_Config.m_SvRoundsPerMap-1) return; - + // handle maprotation const char *pMapRotation = g_Config.m_SvMaprotation; const char *pCurrentMap = g_Config.m_SvMap; - + int CurrentMapLen = str_length(pCurrentMap); const char *pNextMap = pMapRotation; while(*pNextMap) @@ -305,25 +305,25 @@ void IGameController::CycleMap() int WordLen = 0; while(pNextMap[WordLen] && !IsSeparator(pNextMap[WordLen])) WordLen++; - + if(WordLen == CurrentMapLen && str_comp_num(pNextMap, pCurrentMap, CurrentMapLen) == 0) { // map found pNextMap += CurrentMapLen; while(*pNextMap && IsSeparator(*pNextMap)) pNextMap++; - + break; } - + pNextMap++; } - + // restart rotation if(pNextMap[0] == 0) pNextMap = pMapRotation; - // cut out the next map + // cut out the next map char aBuf[512]; for(int i = 0; i < 512; i++) { @@ -334,14 +334,14 @@ void IGameController::CycleMap() break; } } - + // skip spaces int i = 0; while(IsSeparator(aBuf[i])) i++; - + m_RoundCount = 0; - + char aBufMsg[256]; str_format(aBufMsg, sizeof(aBufMsg), "rotating map to %s", &aBuf[i]); GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf); @@ -361,7 +361,7 @@ void IGameController::PostReset() } } } - + void IGameController::OnPlayerInfoChange(class CPlayer *pP) { const int aTeamColors[2] = {65387, 10223467}; @@ -405,7 +405,7 @@ void IGameController::OnCharacterSpawn(class CCharacter *pChr) { // default health pChr->IncreaseHealth(10); - + // give default weapons pChr->GiveWeapon(WEAPON_HAMMER, -1); pChr->GiveWeapon(WEAPON_GUN, 10); @@ -423,16 +423,16 @@ bool IGameController::IsFriendlyFire(int ClientID1, int ClientID2) { if(ClientID1 == ClientID2) return false; - + if(IsTeamplay()) { if(!GameServer()->m_apPlayers[ClientID1] || !GameServer()->m_apPlayers[ClientID2]) return false; - + if(GameServer()->m_apPlayers[ClientID1]->GetTeam() == GameServer()->m_apPlayers[ClientID2]->GetTeam()) return true; } - + return false; } @@ -461,7 +461,7 @@ void IGameController::Tick() if(!m_Warmup) StartRound(); } - + if(m_GameOverTick != -1) { // game over.. wait for restart @@ -472,12 +472,12 @@ void IGameController::Tick() m_RoundCount++; } } - + // do team-balancing if (IsTeamplay() && m_UnbalancedTick != -1 && Server()->Tick() > m_UnbalancedTick+g_Config.m_SvTeambalanceTime*Server()->TickSpeed()*60) { GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", "Balancing teams"); - + int aT[2] = {0,0}; float aTScore[2] = {0,0}; float aPScore[MAX_CLIENTS] = {0.0f}; @@ -491,13 +491,13 @@ void IGameController::Tick() aTScore[GameServer()->m_apPlayers[i]->GetTeam()] += aPScore[i]; } } - + // are teams unbalanced? if(absolute(aT[0]-aT[1]) >= 2) { int M = (aT[0] > aT[1]) ? 0 : 1; int NumBalance = absolute(aT[0]-aT[1]) / 2; - + do { CPlayer *pP = 0; @@ -513,16 +513,16 @@ void IGameController::Tick() PD = absolute((aTScore[M^1]+aPScore[i]) - (aTScore[M]-aPScore[i])); } } - + // move the player to the other team int Temp = pP->m_LastActionTick; pP->SetTeam(M^1); pP->m_LastActionTick = Temp; - + pP->Respawn(); pP->m_ForceBalanced = true; } while (--NumBalance); - + m_ForceBalanced = true; } m_UnbalancedTick = -1; @@ -595,7 +595,7 @@ void IGameController::Snap(int SnappingClient) pGameInfoObj->m_ScoreLimit = g_Config.m_SvScorelimit; pGameInfoObj->m_TimeLimit = g_Config.m_SvTimelimit; - + pGameInfoObj->m_RoundNum = (str_length(g_Config.m_SvMaprotation) && g_Config.m_SvRoundsPerMap) ? g_Config.m_SvRoundsPerMap : 0; pGameInfoObj->m_RoundCurrent = m_RoundCount+1; } @@ -605,7 +605,7 @@ int IGameController::GetAutoTeam(int NotThisID) // this will force the auto balancer to work overtime aswell if(g_Config.m_DbgStress) return 0; - + int aNumplayers[2] = {0,0}; for(int i = 0; i < MAX_CLIENTS; i++) { @@ -619,7 +619,7 @@ int IGameController::GetAutoTeam(int NotThisID) int Team = 0; if(IsTeamplay()) Team = aNumplayers[TEAM_RED] > aNumplayers[TEAM_BLUE] ? TEAM_BLUE : TEAM_RED; - + if(CanJoinTeam(Team, NotThisID)) return Team; return -1; @@ -639,7 +639,7 @@ bool IGameController::CanJoinTeam(int Team, int NotThisID) aNumplayers[GameServer()->m_apPlayers[i]->GetTeam()]++; } } - + return (aNumplayers[0] + aNumplayers[1]) < g_Config.m_SvMaxClients-g_Config.m_SvSpectatorSlots; } @@ -647,7 +647,7 @@ bool IGameController::CheckTeamBalance() { if(!IsTeamplay() || !g_Config.m_SvTeambalanceTime) return true; - + int aT[2] = {0, 0}; for(int i = 0; i < MAX_CLIENTS; i++) { @@ -655,7 +655,7 @@ bool IGameController::CheckTeamBalance() if(pP && pP->GetTeam() != TEAM_SPECTATORS) aT[pP->GetTeam()]++; } - + char aBuf[256]; if(absolute(aT[0]-aT[1]) >= 2) { @@ -677,22 +677,22 @@ bool IGameController::CheckTeamBalance() bool IGameController::CanChangeTeam(CPlayer *pPlayer, int JoinTeam) { int aT[2] = {0, 0}; - + if (!IsTeamplay() || JoinTeam == TEAM_SPECTATORS || !g_Config.m_SvTeambalanceTime) return true; - + for(int i = 0; i < MAX_CLIENTS; i++) { CPlayer *pP = GameServer()->m_apPlayers[i]; if(pP && pP->GetTeam() != TEAM_SPECTATORS) aT[pP->GetTeam()]++; } - + // simulate what would happen if changed team aT[JoinTeam]++; if (pPlayer->GetTeam() != TEAM_SPECTATORS) aT[JoinTeam^1]--; - + // there is a player-difference of at least 2 if(absolute(aT[0]-aT[1]) >= 2) { @@ -708,7 +708,7 @@ bool IGameController::CanChangeTeam(CPlayer *pPlayer, int JoinTeam) void IGameController::DoPlayerScoreWincheck() { - if(m_GameOverTick == -1 && !m_Warmup) + if(m_GameOverTick == -1 && !m_Warmup) { // gather some stats int Topscore = 0; @@ -726,7 +726,7 @@ void IGameController::DoPlayerScoreWincheck() TopscoreCount++; } } - + // check score win condition if((g_Config.m_SvScorelimit > 0 && Topscore >= g_Config.m_SvScorelimit) || (g_Config.m_SvTimelimit > 0 && (Server()->Tick()-m_RoundStartTick) >= g_Config.m_SvTimelimit*Server()->TickSpeed()*60)) diff --git a/src/game/server/gamecontroller.h b/src/game/server/gamecontroller.h index c999f84e..6ccfe977 100644 --- a/src/game/server/gamecontroller.h +++ b/src/game/server/gamecontroller.h @@ -14,10 +14,10 @@ class IGameController { vec2 m_aaSpawnPoints[3][64]; int m_aNumSpawnPoints[3]; - + class CGameContext *m_pGameServer; class IServer *m_pServer; - + protected: CGameContext *GameServer() const { return m_pGameServer; } IServer *Server() const { return m_pServer; } @@ -30,7 +30,7 @@ protected: m_FriendlyTeam = -1; m_Pos = vec2(100,100); } - + vec2 m_Pos; bool m_Got; int m_FriendlyTeam; @@ -44,80 +44,80 @@ protected: void CycleMap(); void ResetGame(); - + char m_aMapWish[128]; - + int m_RoundStartTick; int m_GameOverTick; int m_SuddenDeath; - + int m_aTeamscore[2]; - + int m_Warmup; int m_RoundCount; - + int m_GameFlags; int m_UnbalancedTick; bool m_ForceBalanced; - + public: const char *m_pGameType; bool IsTeamplay() const; - + IGameController(class CGameContext *pGameServer); virtual ~IGameController(); void DoTeamScoreWincheck(); void DoPlayerScoreWincheck(); - + void DoWarmup(int Seconds); - + void StartRound(); void EndRound(); void ChangeMap(const char *pToMap); - + bool IsFriendlyFire(int ClientID1, int ClientID2); - + bool IsForceBalanced(); /* - - */ + + */ virtual bool CanBeMovedOnBalance(int ClientID); virtual void Tick(); - + virtual void Snap(int SnappingClient); - + /* Function: on_entity Called when the map is loaded to process an entity in the map. - + Arguments: index - Entity index. pos - Where the entity is located in the world. - + Returns: bool? */ virtual bool OnEntity(int Index, vec2 Pos); - + /* Function: on_CCharacter_spawn Called when a CCharacter spawns into the game world. - + Arguments: chr - The CCharacter that was spawned. */ virtual void OnCharacterSpawn(class CCharacter *pChr); - + /* Function: on_CCharacter_death Called when a CCharacter in the world dies. - + Arguments: victim - The CCharacter that died. killer - The player that killed it. @@ -133,8 +133,8 @@ public: virtual bool CanSpawn(int Team, vec2 *pPos); /* - - */ + + */ virtual const char *GetTeamName(int Team); virtual int GetAutoTeam(int NotThisID); virtual bool CanJoinTeam(int Team, int NotThisID); diff --git a/src/game/server/gamemodes/ctf.cpp b/src/game/server/gamemodes/ctf.cpp index fb177d5d..b1d3d2fa 100644 --- a/src/game/server/gamemodes/ctf.cpp +++ b/src/game/server/gamemodes/ctf.cpp @@ -20,13 +20,13 @@ bool CGameControllerCTF::OnEntity(int Index, vec2 Pos) { if(IGameController::OnEntity(Index, Pos)) return true; - + int Team = -1; if(Index == ENTITY_FLAGSTAND_RED) Team = TEAM_RED; if(Index == ENTITY_FLAGSTAND_BLUE) Team = TEAM_BLUE; if(Team == -1 || m_apFlags[Team]) return false; - + CFlag *F = new CFlag(&GameServer()->m_World, Team); F->m_StandPos = Pos; F->m_Pos = Pos; @@ -39,7 +39,7 @@ int CGameControllerCTF::OnCharacterDeath(class CCharacter *pVictim, class CPlaye { IGameController::OnCharacterDeath(pVictim, pKiller, WeaponID); int HadFlag = 0; - + // drop flags for(int i = 0; i < 2; i++) { @@ -52,14 +52,14 @@ int CGameControllerCTF::OnCharacterDeath(class CCharacter *pVictim, class CPlaye F->m_DropTick = Server()->Tick(); F->m_pCarryingCharacter = 0; F->m_Vel = vec2(0,0); - + if(pKiller && pKiller->GetTeam() != pVictim->GetPlayer()->GetTeam()) pKiller->m_Score++; - + HadFlag |= 1; } } - + return HadFlag; } @@ -118,14 +118,14 @@ void CGameControllerCTF::Tick() IGameController::Tick(); DoTeamScoreWincheck(); - + for(int fi = 0; fi < 2; fi++) { CFlag *F = m_apFlags[fi]; - + 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)) { @@ -134,13 +134,13 @@ void CGameControllerCTF::Tick() 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) @@ -167,7 +167,7 @@ void CGameControllerCTF::Tick() GameServer()->SendChat(-1, -2, aBuf); for(int i = 0; i < 2; i++) m_apFlags[i]->Reset(); - + GameServer()->CreateSoundGlobal(SOUND_CTF_CAPTURE); } } @@ -180,7 +180,7 @@ void CGameControllerCTF::Tick() { if(!apCloseCCharacters[i]->IsAlive() || apCloseCCharacters[i]->GetPlayer()->GetTeam() == TEAM_SPECTATORS || GameServer()->Collision()->IntersectLine(F->m_Pos, apCloseCCharacters[i]->m_Pos, NULL, NULL)) continue; - + if(apCloseCCharacters[i]->GetPlayer()->GetTeam() == F->m_Team) { // return the flag @@ -207,7 +207,7 @@ void CGameControllerCTF::Tick() m_aTeamscore[fi^1]++; F->m_GrabTick = Server()->Tick(); } - + F->m_AtStand = 0; F->m_pCarryingCharacter = apCloseCCharacters[i]; F->m_pCarryingCharacter->GetPlayer()->m_Score += 1; @@ -217,12 +217,12 @@ void CGameControllerCTF::Tick() F->m_pCarryingCharacter->GetPlayer()->GetCID(), Server()->ClientName(F->m_pCarryingCharacter->GetPlayer()->GetCID())); GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf); - + for(int c = 0; c < MAX_CLIENTS; c++) { if(!GameServer()->m_apPlayers[c]) continue; - + if(GameServer()->m_apPlayers[c]->GetTeam() == fi) GameServer()->CreateSoundGlobal(SOUND_CTF_GRAB_EN, GameServer()->m_apPlayers[c]->GetCID()); else @@ -231,7 +231,7 @@ void CGameControllerCTF::Tick() break; } } - + if(!F->m_pCarryingCharacter && !F->m_AtStand) { if(Server()->Tick() > F->m_DropTick + Server()->TickSpeed()*30) diff --git a/src/game/server/gamemodes/ctf.h b/src/game/server/gamemodes/ctf.h index b9868e70..44bd9e8e 100644 --- a/src/game/server/gamemodes/ctf.h +++ b/src/game/server/gamemodes/ctf.h @@ -9,12 +9,12 @@ class CGameControllerCTF : public IGameController { public: class CFlag *m_apFlags[2]; - + CGameControllerCTF(class CGameContext *pGameServer); virtual bool CanBeMovedOnBalance(int ClientID); virtual void Snap(int SnappingClient); virtual void Tick(); - + virtual bool OnEntity(int Index, vec2 Pos); virtual int OnCharacterDeath(class CCharacter *pVictim, class CPlayer *pKiller, int Weapon); }; diff --git a/src/game/server/gamemodes/mod.cpp b/src/game/server/gamemodes/mod.cpp index ecf06e48..127be2bc 100644 --- a/src/game/server/gamemodes/mod.cpp +++ b/src/game/server/gamemodes/mod.cpp @@ -8,7 +8,7 @@ CGameControllerMOD::CGameControllerMOD(class CGameContext *pGameServer) // Exchange this to a string that identifies your game mode. // DM, TDM and CTF are reserved for teeworlds original modes. m_pGameType = "MOD"; - + //m_GameFlags = GAMEFLAG_TEAMS; // GAMEFLAG_TEAMS makes it a two-team gamemode } @@ -17,6 +17,6 @@ void CGameControllerMOD::Tick() // this is the main part of the gamemode, this function is run every tick DoPlayerScoreWincheck(); // checks for winners, no teams version //DoTeamScoreWincheck(); // checks for winners, two teams version - + IGameController::Tick(); } diff --git a/src/game/server/gamemodes/tdm.cpp b/src/game/server/gamemodes/tdm.cpp index fb0ff783..54e645b3 100644 --- a/src/game/server/gamemodes/tdm.cpp +++ b/src/game/server/gamemodes/tdm.cpp @@ -15,8 +15,8 @@ CGameControllerTDM::CGameControllerTDM(class CGameContext *pGameServer) : IGameC int CGameControllerTDM::OnCharacterDeath(class CCharacter *pVictim, class CPlayer *pKiller, int Weapon) { IGameController::OnCharacterDeath(pVictim, pKiller, Weapon); - - + + if(Weapon != WEAPON_GAME) { // do team scoring @@ -27,7 +27,7 @@ int CGameControllerTDM::OnCharacterDeath(class CCharacter *pVictim, class CPlaye } pVictim->GetPlayer()->m_RespawnTick = max(pVictim->GetPlayer()->m_RespawnTick, Server()->Tick()+Server()->TickSpeed()*g_Config.m_SvRespawnDelayTDM); - + return 0; } diff --git a/src/game/server/gamemodes/tdm.h b/src/game/server/gamemodes/tdm.h index c8d3f328..297b48c0 100644 --- a/src/game/server/gamemodes/tdm.h +++ b/src/game/server/gamemodes/tdm.h @@ -8,7 +8,7 @@ class CGameControllerTDM : public IGameController { public: CGameControllerTDM(class CGameContext *pGameServer); - + int OnCharacterDeath(class CCharacter *pVictim, class CPlayer *pKiller, int Weapon); virtual void Snap(int SnappingClient); virtual void Tick(); diff --git a/src/game/server/gameworld.cpp b/src/game/server/gameworld.cpp index 8fffabc8..6444cce5 100644 --- a/src/game/server/gameworld.cpp +++ b/src/game/server/gameworld.cpp @@ -12,7 +12,7 @@ CGameWorld::CGameWorld() { m_pGameServer = 0x0; m_pServer = 0x0; - + m_Paused = false; m_ResetRequested = false; for(int i = 0; i < NUM_ENTTYPES; i++) @@ -164,7 +164,7 @@ void CGameWorld::Tick() pEnt->Tick(); pEnt = m_pNextTraverseEntity; } - + for(int i = 0; i < NUM_ENTTYPES; i++) for(CEntity *pEnt = m_apFirstEntityTypes[i]; pEnt; ) { @@ -191,7 +191,7 @@ CCharacter *CGameWorld::IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, v { if(p == pNotThis) 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) @@ -205,7 +205,7 @@ CCharacter *CGameWorld::IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, v } } } - + return pClosest; } @@ -215,13 +215,13 @@ CCharacter *CGameWorld::ClosestCharacter(vec2 Pos, float Radius, CEntity *pNotTh // Find other players float ClosestRange = Radius*2; CCharacter *pClosest = 0; - + CCharacter *p = (CCharacter *)GameServer()->m_World.FindFirst(ENTTYPE_CHARACTER); for(; p; p = (CCharacter *)p->TypeNext()) { if(p == pNotThis) continue; - + float Len = distance(Pos, p->m_Pos); if(Len < p->m_ProximityRadius+Radius) { @@ -232,6 +232,6 @@ CCharacter *CGameWorld::ClosestCharacter(vec2 Pos, float Radius, CEntity *pNotTh } } } - + return pClosest; } diff --git a/src/game/server/gameworld.h b/src/game/server/gameworld.h index 38002b87..a2fdbce0 100644 --- a/src/game/server/gameworld.h +++ b/src/game/server/gameworld.h @@ -32,7 +32,7 @@ private: CEntity *m_pNextTraverseEntity; CEntity *m_apFirstEntityTypes[NUM_ENTTYPES]; - + class CGameContext *m_pGameServer; class IServer *m_pServer; @@ -43,18 +43,18 @@ public: bool m_ResetRequested; bool m_Paused; CWorldCore m_Core; - + CGameWorld(); ~CGameWorld(); - + void SetGameServer(CGameContext *pGameServer); - + CEntity *FindFirst(int Type); - + /* Function: find_entities Finds entities close to a position and returns them in a list. - + Arguments: pos - Position. radius - How close the entities have to be. @@ -62,37 +62,37 @@ public: to the entities. max - Number of entities that fits into the ents array. type - Type of the entities to find. - + Returns: Number of entities found and added to the ents array. */ int FindEntities(vec2 Pos, float Radius, CEntity **ppEnts, int Max, int Type); - + /* Function: interserct_CCharacter Finds the closest CCharacter that intersects the line. - + Arguments: pos0 - Start position pos2 - End position radius - How for from the line the CCharacter is allowed to be. new_pos - Intersection position notthis - Entity to ignore intersecting with - + 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); - + /* Function: closest_CCharacter Finds the closest CCharacter to a specific point. - + Arguments: pos - The center position. radius - How far off the CCharacter is allowed to be notthis - Entity to ignore - + Returns: Returns a pointer to the closest CCharacter or NULL if no CCharacter is close enough. */ @@ -101,7 +101,7 @@ public: /* Function: insert_entity Adds an entity to the world. - + Arguments: entity - Entity to add */ @@ -110,7 +110,7 @@ public: /* Function: remove_entity Removes an entity from the world. - + Arguments: entity - Entity to remove */ @@ -119,28 +119,28 @@ public: /* Function: destroy_entity Destroys an entity in the world. - + Arguments: entity - Entity to destroy */ void DestroyEntity(CEntity *pEntity); - + /* Function: snap Calls snap on all the entities in the world to create the snapshot. - + Arguments: snapping_client - ID of the client which snapshot is being created. */ void Snap(int SnappingClient); - + /* Function: tick Calls tick on all the entities in the world to progress the world to the next tick. - + */ void Tick(); }; diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index cf0e6683..aeafe3a4 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -8,7 +8,7 @@ MACRO_ALLOC_POOL_ID_IMPL(CPlayer, MAX_CLIENTS) IServer *CPlayer::Server() const { return m_pGameServer->Server(); } - + CPlayer::CPlayer(CGameContext *pGameServer, int ClientID, int Team) { m_pGameServer = pGameServer; @@ -58,7 +58,7 @@ void CPlayer::Tick() m_Latency.m_AccumMax = 0; } } - + if(!Character && m_DieTick+Server()->TickSpeed()*3 <= Server()->Tick()) m_Spawning = true; @@ -148,9 +148,9 @@ void CPlayer::OnDisconnect(const char *pReason) { char aBuf[512]; if(pReason && *pReason) - str_format(aBuf, sizeof(aBuf), "'%s' has left the game (%s)", Server()->ClientName(m_ClientID), pReason); + str_format(aBuf, sizeof(aBuf), "'%s' has left the game (%s)", Server()->ClientName(m_ClientID), pReason); else - str_format(aBuf, sizeof(aBuf), "'%s' has left the game", Server()->ClientName(m_ClientID)); + str_format(aBuf, sizeof(aBuf), "'%s' has left the game", Server()->ClientName(m_ClientID)); GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf); str_format(aBuf, sizeof(aBuf), "leave player='%d:%s'", m_ClientID, Server()->ClientName(m_ClientID)); @@ -173,7 +173,7 @@ void CPlayer::OnDirectInput(CNetObj_PlayerInput *NewInput) if(!Character && m_Team != TEAM_SPECTATORS && (NewInput->m_Fire&1)) m_Spawning = true; - + if(!Character && m_Team == TEAM_SPECTATORS && m_SpectatorID == SPEC_FREEVIEW) m_ViewPos = vec2(NewInput->m_TargetX, NewInput->m_TargetY); @@ -217,11 +217,11 @@ void CPlayer::SetTeam(int Team) Team = GameServer()->m_pController->ClampTeam(Team); if(m_Team == Team) return; - + char aBuf[512]; str_format(aBuf, sizeof(aBuf), "'%s' joined the %s", Server()->ClientName(m_ClientID), GameServer()->m_pController->GetTeamName(Team)); - GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf); - + GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf); + KillCharacter(); m_Team = Team; @@ -230,7 +230,7 @@ void CPlayer::SetTeam(int Team) m_RespawnTick = Server()->Tick()+Server()->TickSpeed()/2; str_format(aBuf, sizeof(aBuf), "team_join player='%d:%s' m_Team=%d", m_ClientID, Server()->ClientName(m_ClientID), m_Team); GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf); - + GameServer()->m_pController->OnPlayerInfoChange(GameServer()->m_apPlayers[m_ClientID]); if(Team == TEAM_SPECTATORS) @@ -247,7 +247,7 @@ void CPlayer::SetTeam(int Team) void CPlayer::TryRespawn() { vec2 SpawnPos; - + if(!GameServer()->m_pController->CanSpawn(m_Team, &SpawnPos)) return; diff --git a/src/game/server/player.h b/src/game/server/player.h index 50f1c1a0..9d5e462c 100644 --- a/src/game/server/player.h +++ b/src/game/server/player.h @@ -11,7 +11,7 @@ class CPlayer { MACRO_ALLOC_POOL_ID() - + public: CPlayer(CGameContext *pGameServer, int ClientID, int Team); ~CPlayer(); @@ -23,7 +23,7 @@ public: void SetTeam(int Team); int GetTeam() const { return m_Team; }; int GetCID() const { return m_ClientID; }; - + void Tick(); void PostTick(); void Snap(int SnappingClient); @@ -31,10 +31,10 @@ public: void OnDirectInput(CNetObj_PlayerInput *NewInput); void OnPredictedInput(CNetObj_PlayerInput *NewInput); void OnDisconnect(const char *pReason); - + void KillCharacter(int Weapon = WEAPON_GAME); CCharacter *GetCharacter(); - + //--------------------------------------------------------- // this is used for snapping so we know how we can clip the view for the player vec2 m_ViewPos; @@ -49,7 +49,7 @@ public: int m_SpectatorID; bool m_IsReady; - + // int m_Vote; int m_VotePos; @@ -62,16 +62,16 @@ public: int m_LastChangeInfo; int m_LastEmote; int m_LastKill; - + // TODO: clean this up - struct + struct { char m_SkinName[64]; int m_UseCustomColor; int m_ColorBody; int m_ColorFeet; } m_TeeInfos; - + int m_RespawnTick; int m_DieTick; int m_Score; @@ -84,7 +84,7 @@ public: int m_TargetY; } m_LatestActivity; - // network latency calculations + // network latency calculations struct { int m_Accum; @@ -92,16 +92,16 @@ public: int m_AccumMax; int m_Avg; int m_Min; - int m_Max; + int m_Max; } m_Latency; - + private: CCharacter *Character; CGameContext *m_pGameServer; - + CGameContext *GameServer() const { return m_pGameServer; } IServer *Server() const; - + // bool m_Spawning; int m_ClientID; |