diff --git a/datasrc/network.py b/datasrc/network.py index ed561c0e5..24700a7dd 100644 --- a/datasrc/network.py +++ b/datasrc/network.py @@ -231,8 +231,12 @@ Objects = [ NetIntRange("m_SoundID", 0, 'NUM_SOUNDS-1'), ]), - NetEvent("DamageInd:Common", [ + NetEvent("Damage:Common", [ # Unused yet + NetIntRange("m_ClientID", 0, 'MAX_CLIENTS-1'), NetIntAny("m_Angle"), + NetIntRange("m_HealthAmount", 1, 9), + NetIntRange("m_ArmorAmount", 1, 9), + NetBool("m_Self"), ]), ] diff --git a/src/game/client/components/effects.cpp b/src/game/client/components/effects.cpp index bac5e698e..d98a1b93b 100644 --- a/src/game/client/components/effects.cpp +++ b/src/game/client/components/effects.cpp @@ -22,6 +22,8 @@ CEffects::CEffects() { m_Add50hz = false; m_Add100hz = false; + m_DamageTaken = 0; + m_DamageTakenTick = 0; } void CEffects::AirJump(vec2 Pos) @@ -47,9 +49,32 @@ void CEffects::AirJump(vec2 Pos) m_pClient->m_pSounds->PlayAt(CSounds::CHN_WORLD, SOUND_PLAYER_AIRJUMP, 1.0f, Pos); } -void CEffects::DamageIndicator(vec2 Pos, vec2 Dir) +void CEffects::DamageIndicator(vec2 Pos, int Amount) { - m_pClient->m_pDamageind->Create(Pos, Dir); + m_DamageTaken++; + int Angle; + // create healthmod indicator + if(Client()->LocalTime() < m_DamageTakenTick+0.5f) + { + // make sure that the damage indicators don't group together + Angle = m_DamageTaken*0.25f; + } + else + { + m_DamageTaken = 0; + Angle = 0; + } + + float a = 3*pi/2 + Angle; + float s = a-pi/3; + float e = a+pi/3; + for(int i = 0; i < Amount; i++) + { + float f = mix(s, e, float(i+1)/float(Amount+2)); + m_pClient->m_pDamageind->Create(vec2(Pos.x, Pos.y), direction(f)); + } + + m_DamageTakenTick = Client()->LocalTime(); } void CEffects::PowerupShine(vec2 Pos, vec2 size) diff --git a/src/game/client/components/effects.h b/src/game/client/components/effects.h index 9ededb832..d46da9a88 100644 --- a/src/game/client/components/effects.h +++ b/src/game/client/components/effects.h @@ -8,6 +8,9 @@ class CEffects : public CComponent { bool m_Add50hz; bool m_Add100hz; + + int m_DamageTaken; + float m_DamageTakenTick; public: CEffects(); @@ -19,7 +22,7 @@ public: void Explosion(vec2 Pos); void HammerHit(vec2 Pos); void AirJump(vec2 Pos); - void DamageIndicator(vec2 Pos, vec2 Dir); + void DamageIndicator(vec2 Pos, int Amount); void PlayerSpawn(vec2 Pos); void PlayerDeath(vec2 Pos, int ClientID); void PowerupShine(vec2 Pos, vec2 Size); diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 923001b9d..4b3c123cd 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -820,10 +820,10 @@ void CGameClient::ProcessEvents() IClient::CSnapItem Item; const void *pData = Client()->SnapGetItem(SnapType, Index, &Item); - if(Item.m_Type == NETEVENTTYPE_DAMAGEIND) + if(Item.m_Type == NETEVENTTYPE_DAMAGE) { - CNetEvent_DamageInd *ev = (CNetEvent_DamageInd *)pData; - m_pEffects->DamageIndicator(vec2(ev->m_X, ev->m_Y), direction(ev->m_Angle/256.0f)); + CNetEvent_Damage *ev = (CNetEvent_Damage *)pData; + m_pEffects->DamageIndicator(vec2(ev->m_X, ev->m_Y), ev->m_HealthAmount + ev->m_ArmorAmount); } else if(Item.m_Type == NETEVENTTYPE_EXPLOSION) { diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index 47c9cca5c..7ce71dcca 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -187,7 +187,7 @@ void CCharacter::HandleNinja() 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); + aEnts[i]->TakeDamage(vec2(0, -10.0f), m_Ninja.m_ActivationDir*-1, g_pData->m_Weapons.m_Ninja.m_pBase->m_Damage, m_pPlayer->GetCID(), WEAPON_NINJA); } } @@ -320,7 +320,7 @@ void CCharacter::FireWeapon() 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, + pTarget->TakeDamage(vec2(0.f, -1.f) + normalize(Dir + vec2(0.f, -1.1f)) * 10.0f, Dir*-1, g_pData->m_Weapons.m_Hammer.m_pBase->m_Damage, m_pPlayer->GetCID(), m_ActiveWeapon); Hits++; } @@ -620,7 +620,6 @@ void CCharacter::TickDefered() void CCharacter::TickPaused() { ++m_AttackTick; - ++m_DamageTakenTick; ++m_Ninja.m_ActivationTick; ++m_ReckoningTick; if(m_LastAction != -1) @@ -679,7 +678,7 @@ void CCharacter::Die(int Killer, int Weapon) GameServer()->CreateDeath(m_Pos, m_pPlayer->GetCID()); } -bool CCharacter::TakeDamage(vec2 Force, int Dmg, int From, int Weapon) +bool CCharacter::TakeDamage(vec2 Force, vec2 Source, int Dmg, int From, int Weapon) { m_Core.m_Vel += Force; @@ -690,20 +689,7 @@ bool CCharacter::TakeDamage(vec2 Force, int Dmg, int From, int Weapon) if(From == m_pPlayer->GetCID()) Dmg = max(1, Dmg/2); - m_DamageTaken++; - - // create healthmod indicator - if(Server()->Tick() < m_DamageTakenTick+25) - { - // make sure that the damage indicators doesn't group together - GameServer()->CreateDamageInd(m_Pos, m_DamageTaken*0.25f, Dmg); - } - else - { - m_DamageTaken = 0; - GameServer()->CreateDamageInd(m_Pos, 0, Dmg); - } - + int OldHealth = m_Health, OldArmor = m_Armor; if(Dmg) { if(m_Armor) @@ -729,7 +715,8 @@ bool CCharacter::TakeDamage(vec2 Force, int Dmg, int From, int Weapon) m_Health -= Dmg; } - m_DamageTakenTick = Server()->Tick(); + // create healthmod indicator + GameServer()->CreateDamage(m_Pos, m_pPlayer->GetCID(), Source, OldHealth-m_Health, OldArmor-m_Armor, From == m_pPlayer->GetCID()); // do damage Hit sound if(From >= 0 && From != m_pPlayer->GetCID() && GameServer()->m_apPlayers[From]) diff --git a/src/game/server/entities/character.h b/src/game/server/entities/character.h index 12b990ee3..eb3e9e93c 100644 --- a/src/game/server/entities/character.h +++ b/src/game/server/entities/character.h @@ -42,7 +42,7 @@ public: void FireWeapon(); void Die(int Killer, int Weapon); - bool TakeDamage(vec2 Force, int Dmg, int From, int Weapon); + bool TakeDamage(vec2 Force, vec2 Source, int Dmg, int From, int Weapon); bool Spawn(class CPlayer *pPlayer, vec2 Pos); bool Remove(); @@ -83,8 +83,6 @@ private: int m_ReloadTimer; int m_AttackTick; - int m_DamageTaken; - int m_EmoteType; int m_EmoteStop; @@ -101,8 +99,6 @@ private: int m_NumInputs; int m_Jumped; - int m_DamageTakenTick; - int m_Health; int m_Armor; diff --git a/src/game/server/entities/laser.cpp b/src/game/server/entities/laser.cpp index 7edbe627b..198f95979 100644 --- a/src/game/server/entities/laser.cpp +++ b/src/game/server/entities/laser.cpp @@ -30,7 +30,7 @@ bool CLaser::HitCharacter(vec2 From, vec2 To) m_From = From; m_Pos = At; m_Energy = -1; - pHit->TakeDamage(vec2(0.f, 0.f), g_pData->m_Weapons.m_aId[WEAPON_LASER].m_Damage, m_Owner, WEAPON_LASER); + pHit->TakeDamage(vec2(0.f, 0.f), normalize(To-From), g_pData->m_Weapons.m_aId[WEAPON_LASER].m_Damage, m_Owner, WEAPON_LASER); return true; } diff --git a/src/game/server/entities/projectile.cpp b/src/game/server/entities/projectile.cpp index da990034d..ea09fd7e5 100644 --- a/src/game/server/entities/projectile.cpp +++ b/src/game/server/entities/projectile.cpp @@ -76,7 +76,7 @@ void CProjectile::Tick() GameServer()->CreateExplosion(CurPos, m_Owner, m_Weapon, m_Damage); else if(TargetChr) - TargetChr->TakeDamage(m_Direction * max(0.001f, m_Force), m_Damage, m_Owner, m_Weapon); + TargetChr->TakeDamage(m_Direction * max(0.001f, m_Force), m_Direction*-1, m_Damage, m_Owner, m_Weapon); GameServer()->m_World.DestroyEntity(this); } diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index acc4b6784..da51941bd 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -93,22 +93,19 @@ class CCharacter *CGameContext::GetPlayerChar(int ClientID) return m_apPlayers[ClientID]->GetCharacter(); } -void CGameContext::CreateDamageInd(vec2 Pos, float Angle, int Amount) +void CGameContext::CreateDamage(vec2 Pos, int Id, vec2 Source, int HealthAmount, int ArmorAmount, bool Self) { - float a = 3*pi/2 + Angle; - //float a = get_angle(dir); - float s = a-pi/3; - float e = a+pi/3; - for(int i = 0; i < Amount; i++) + float f = angle(Source); + CNetEvent_Damage *pEvent = (CNetEvent_Damage *)m_Events.Create(NETEVENTTYPE_DAMAGE, sizeof(CNetEvent_Damage)); + if(pEvent) { - float f = mix(s, e, float(i+1)/float(Amount+2)); - CNetEvent_DamageInd *pEvent = (CNetEvent_DamageInd *)m_Events.Create(NETEVENTTYPE_DAMAGEIND, sizeof(CNetEvent_DamageInd)); - if(pEvent) - { - pEvent->m_X = (int)Pos.x; - pEvent->m_Y = (int)Pos.y; - pEvent->m_Angle = (int)(f*256.0f); - } + pEvent->m_X = (int)Pos.x; + pEvent->m_Y = (int)Pos.y; + pEvent->m_ClientID = Id; + pEvent->m_Angle = (int)(f*256.0f); + pEvent->m_HealthAmount = HealthAmount; + pEvent->m_ArmorAmount = ArmorAmount; + pEvent->m_Self = Self; } } @@ -149,7 +146,7 @@ void CGameContext::CreateExplosion(vec2 Pos, int Owner, int Weapon, int MaxDamag Force = normalize(Diff) * MaxForce; float Factor = 1 - clamp((l-InnerRadius)/(Radius-InnerRadius), 0.0f, 1.0f); if((int)(Factor * MaxDamage)) - apEnts[i]->TakeDamage(Force * Factor, (int)(Factor * MaxDamage), Owner, Weapon); + apEnts[i]->TakeDamage(Force * Factor, Diff*-1, (int)(Factor * MaxDamage), Owner, Weapon); } } diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index 9c9c03d78..64d169715 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -124,7 +124,7 @@ public: CVoteOptionServer *m_pVoteOptionLast; // helper functions - void CreateDamageInd(vec2 Pos, float AngleMod, int Amount); + void CreateDamage(vec2 Pos, int Id, vec2 Source, int HealthAmount, int ArmorAmount, bool Self); void CreateExplosion(vec2 Pos, int Owner, int Weapon, int MaxDamage); void CreateHammerHit(vec2 Pos); void CreatePlayerSpawn(vec2 Pos);