diff --git a/datasrc/content.py b/datasrc/content.py index 62022f2d0..7ea04417c 100644 --- a/datasrc/content.py +++ b/datasrc/content.py @@ -157,6 +157,12 @@ class Weapons(Struct): self.ninja = Weapon_Ninja() self.id = Array(WeaponSpec()) +class Explosion(Struct): + def __init__(self): + Struct.__init__(self, "CDataExplosion") + self.radius = Float(135) + self.max_force = Float(12) + class DataContainer(Struct): def __init__(self): Struct.__init__(self, "CDataContainer") @@ -167,6 +173,7 @@ class DataContainer(Struct): self.sprites = Array(Sprite()) self.animations = Array(Animation()) self.weapons = Weapons() + self.explosion = Explosion() def FileList(format, num): return [format%(x+1) for x in range(0,num)] @@ -532,6 +539,7 @@ container.weapons.id.Add(weapon) weapon = WeaponSpec(container, "gun") weapon.firedelay.Set(125) +weapon.damage.Set(1) weapon.ammoregentime.Set(500) weapon.visual_size.Set(64) weapon.offsetx.Set(32) @@ -543,6 +551,7 @@ container.weapons.id.Add(weapon) weapon = WeaponSpec(container, "shotgun") weapon.firedelay.Set(500) +weapon.damage.Set(1) weapon.visual_size.Set(96) weapon.offsetx.Set(24) weapon.offsety.Set(-2) @@ -553,6 +562,7 @@ container.weapons.id.Add(weapon) weapon = WeaponSpec(container, "grenade") weapon.firedelay.Set(500) # TODO: fix this +weapon.damage.Set(6) weapon.visual_size.Set(96) weapon.offsetx.Set(24) weapon.offsety.Set(-2) @@ -561,8 +571,8 @@ container.weapons.id.Add(weapon) weapon = WeaponSpec(container, "laser") weapon.firedelay.Set(800) -weapon.visual_size.Set(92) weapon.damage.Set(5) +weapon.visual_size.Set(92) weapon.offsetx.Set(24) weapon.offsety.Set(-2) container.weapons.laser.base.Set(weapon) diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index f5241be13..590f746ff 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -338,7 +338,7 @@ void CCharacter::FireWeapon() ProjStartPos, Direction, (int)(Server()->TickSpeed()*GameServer()->Tuning()->m_GunLifetime), - 1, 0, 0, -1, WEAPON_GUN); + g_pData->m_Weapons.m_Gun.m_pBase->m_Damage, false, 0, -1, WEAPON_GUN); // pack the Projectile and send it to the client Directly CNetObj_Projectile p; @@ -373,7 +373,7 @@ void CCharacter::FireWeapon() ProjStartPos, vec2(cosf(a), sinf(a))*Speed, (int)(Server()->TickSpeed()*GameServer()->Tuning()->m_ShotgunLifetime), - 1, 0, 0, -1, WEAPON_SHOTGUN); + g_pData->m_Weapons.m_Shotgun.m_pBase->m_Damage, false, 0, -1, WEAPON_SHOTGUN); // pack the Projectile and send it to the client Directly CNetObj_Projectile p; @@ -395,7 +395,7 @@ void CCharacter::FireWeapon() ProjStartPos, Direction, (int)(Server()->TickSpeed()*GameServer()->Tuning()->m_GrenadeLifetime), - 1, true, 0, SOUND_GRENADE_EXPLODE, WEAPON_GRENADE); + g_pData->m_Weapons.m_Grenade.m_pBase->m_Damage, true, 0, SOUND_GRENADE_EXPLODE, WEAPON_GRENADE); // pack the Projectile and send it to the client Directly CNetObj_Projectile p; @@ -456,7 +456,7 @@ void CCharacter::HandleWeapons() // ammo regen int AmmoRegenTime = g_pData->m_Weapons.m_aId[m_ActiveWeapon].m_Ammoregentime; - if(AmmoRegenTime) + if(AmmoRegenTime && m_aWeapons[m_ActiveWeapon].m_Ammo >= 0) { // If equipped and not active, regen ammo? if (m_ReloadTimer <= 0) @@ -467,7 +467,8 @@ void CCharacter::HandleWeapons() if ((Server()->Tick() - m_aWeapons[m_ActiveWeapon].m_AmmoRegenStart) >= AmmoRegenTime * Server()->TickSpeed() / 1000) { // Add some ammo - m_aWeapons[m_ActiveWeapon].m_Ammo = min(m_aWeapons[m_ActiveWeapon].m_Ammo + 1, 10); + m_aWeapons[m_ActiveWeapon].m_Ammo = min(m_aWeapons[m_ActiveWeapon].m_Ammo + 1, + g_pData->m_Weapons.m_aId[m_ActiveWeapon].m_Maxammo); m_aWeapons[m_ActiveWeapon].m_AmmoRegenStart = -1; } } diff --git a/src/game/server/entities/character.h b/src/game/server/entities/character.h index 8135eaf80..20df60859 100644 --- a/src/game/server/entities/character.h +++ b/src/game/server/entities/character.h @@ -69,7 +69,6 @@ private: { int m_AmmoRegenStart; int m_Ammo; - int m_Ammocost; bool m_Got; } m_aWeapons[NUM_WEAPONS]; diff --git a/src/game/server/entities/laser.cpp b/src/game/server/entities/laser.cpp index 67e2b4a8d..a23e52ef2 100644 --- a/src/game/server/entities/laser.cpp +++ b/src/game/server/entities/laser.cpp @@ -1,5 +1,6 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ +#include #include #include "character.h" @@ -30,7 +31,7 @@ bool CLaser::HitCharacter(vec2 From, vec2 To) m_From = From; m_Pos = At; m_Energy = -1; - pHit->TakeDamage(vec2(0.f, 0.f), GameServer()->Tuning()->m_LaserDamage, m_Owner, WEAPON_LASER); + pHit->TakeDamage(vec2(0.f, 0.f), g_pData->m_Weapons.m_aId[WEAPON_LASER].m_Damage, m_Owner, WEAPON_LASER); return true; } diff --git a/src/game/server/entities/pickup.cpp b/src/game/server/entities/pickup.cpp index dea07e0f1..7b9c1e5ae 100644 --- a/src/game/server/entities/pickup.cpp +++ b/src/game/server/entities/pickup.cpp @@ -47,47 +47,47 @@ void CPickup::Tick() if(pChr && pChr->IsAlive()) { // player picked us up, is someone was hooking us, let them go - int RespawnTime = -1; + bool Picked = false; switch (m_Type) { case PICKUP_HEALTH: if(pChr->IncreaseHealth(1)) { + Picked = true; GameServer()->CreateSound(m_Pos, SOUND_PICKUP_HEALTH); - RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime; } break; case PICKUP_ARMOR: if(pChr->IncreaseArmor(1)) { + Picked = true; GameServer()->CreateSound(m_Pos, SOUND_PICKUP_ARMOR); - RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime; } break; case PICKUP_GRENADE: - if(pChr->GiveWeapon(WEAPON_GRENADE, 10)) + if(pChr->GiveWeapon(WEAPON_GRENADE, g_pData->m_Weapons.m_aId[WEAPON_GRENADE].m_Maxammo)) { - RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime; + Picked = true; GameServer()->CreateSound(m_Pos, SOUND_PICKUP_GRENADE); if(pChr->GetPlayer()) GameServer()->SendWeaponPickup(pChr->GetPlayer()->GetCID(), WEAPON_GRENADE); } break; case PICKUP_SHOTGUN: - if(pChr->GiveWeapon(WEAPON_SHOTGUN, 10)) + if(pChr->GiveWeapon(WEAPON_SHOTGUN, g_pData->m_Weapons.m_aId[WEAPON_SHOTGUN].m_Maxammo)) { - RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime; + Picked = true; GameServer()->CreateSound(m_Pos, SOUND_PICKUP_SHOTGUN); if(pChr->GetPlayer()) GameServer()->SendWeaponPickup(pChr->GetPlayer()->GetCID(), WEAPON_SHOTGUN); } break; case PICKUP_LASER: - if(pChr->GiveWeapon(WEAPON_LASER, 10)) + if(pChr->GiveWeapon(WEAPON_LASER, g_pData->m_Weapons.m_aId[WEAPON_LASER].m_Maxammo)) { - RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime; + Picked = true; GameServer()->CreateSound(m_Pos, SOUND_PICKUP_SHOTGUN); if(pChr->GetPlayer()) GameServer()->SendWeaponPickup(pChr->GetPlayer()->GetCID(), WEAPON_LASER); @@ -96,9 +96,9 @@ void CPickup::Tick() case PICKUP_NINJA: { + Picked = true; // activate ninja on target player pChr->GiveNinja(); - RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime; // loop through all players, setting their emotes CCharacter *pC = static_cast(GameServer()->m_World.FindFirst(CGameWorld::ENTTYPE_CHARACTER)); @@ -116,13 +116,15 @@ void CPickup::Tick() break; }; - if(RespawnTime >= 0) + if(Picked) { char aBuf[256]; str_format(aBuf, sizeof(aBuf), "pickup player='%d:%s' item=%d/%d", pChr->GetPlayer()->GetCID(), Server()->ClientName(pChr->GetPlayer()->GetCID()), m_Type); GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf); - m_SpawnTick = Server()->Tick() + Server()->TickSpeed() * RespawnTime; + int RespawnTime = g_pData->m_aPickups[m_Type].m_RespawnTime; + if(RespawnTime >= 0) + m_SpawnTick = Server()->Tick() + Server()->TickSpeed() * RespawnTime; } } } diff --git a/src/game/server/entities/projectile.cpp b/src/game/server/entities/projectile.cpp index 5357b6e71..7f4d38ab4 100644 --- a/src/game/server/entities/projectile.cpp +++ b/src/game/server/entities/projectile.cpp @@ -74,7 +74,7 @@ void CProjectile::Tick() GameServer()->CreateSound(CurPos, m_SoundImpact); if(m_Explosive) - GameServer()->CreateExplosion(CurPos, m_Owner, m_Weapon, false); + 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); diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index fead8f2d9..77d58462c 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -122,7 +123,7 @@ void CGameContext::CreateHammerHit(vec2 Pos) } -void CGameContext::CreateExplosion(vec2 Pos, int Owner, int Weapon, bool NoDamage) +void CGameContext::CreateExplosion(vec2 Pos, int Owner, int Weapon, int MaxDamage) { // create the event CNetEvent_Explosion *pEvent = (CNetEvent_Explosion *)m_Events.Create(NETEVENTTYPE_EXPLOSION, sizeof(CNetEvent_Explosion)); @@ -132,25 +133,21 @@ void CGameContext::CreateExplosion(vec2 Pos, int Owner, int Weapon, bool NoDamag pEvent->m_Y = (int)Pos.y; } - if (!NoDamage) + // deal damage + CCharacter *apEnts[MAX_CLIENTS]; + float Radius = g_pData->m_Explosion.m_Radius; + float InnerRadius = 48.0f; + float MaxForce = g_pData->m_Explosion.m_MaxForce; + int Num = m_World.FindEntities(Pos, Radius, (CEntity**)apEnts, MAX_CLIENTS, CGameWorld::ENTTYPE_CHARACTER); + for(int i = 0; i < Num; i++) { - // deal damage - CCharacter *apEnts[MAX_CLIENTS]; - float Radius = 135.0f; - float InnerRadius = 48.0f; - int Num = m_World.FindEntities(Pos, Radius, (CEntity**)apEnts, MAX_CLIENTS, CGameWorld::ENTTYPE_CHARACTER); - for(int i = 0; i < Num; i++) - { - vec2 Diff = apEnts[i]->m_Pos - Pos; - vec2 ForceDir(0,1); - float l = length(Diff); - if(l) - ForceDir = normalize(Diff); - l = 1-clamp((l-InnerRadius)/(Radius-InnerRadius), 0.0f, 1.0f); - float Dmg = 6 * l; - if((int)Dmg) - apEnts[i]->TakeDamage(ForceDir*Dmg*2, (int)Dmg, Owner, Weapon); - } + vec2 Diff = apEnts[i]->m_Pos - Pos; + vec2 Force(0, MaxForce); + float l = length(Diff); + if(l) + Force = normalize(Diff) * MaxForce; + float Factor = 1 - clamp((l-InnerRadius)/(Radius-InnerRadius), 0.0f, 1.0f); + apEnts[i]->TakeDamage(Force * Factor, (int)(Factor * MaxDamage), Owner, Weapon); } } diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index df2b3a8d7..0f8eea0fe 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -122,7 +122,7 @@ public: // helper functions void CreateDamageInd(vec2 Pos, float AngleMod, int Amount); - void CreateExplosion(vec2 Pos, int Owner, int Weapon, bool NoDamage); + void CreateExplosion(vec2 Pos, int Owner, int Weapon, int MaxDamage); void CreateHammerHit(vec2 Pos); void CreatePlayerSpawn(vec2 Pos); void CreateDeath(vec2 Pos, int Who); diff --git a/src/game/tuning.h b/src/game/tuning.h index 5bdb576e0..ecd7ef08d 100644 --- a/src/game/tuning.h +++ b/src/game/tuning.h @@ -41,7 +41,6 @@ MACRO_TUNING_PARAM(LaserReach, laser_reach, 800.0f) MACRO_TUNING_PARAM(LaserBounceDelay, laser_bounce_delay, 150) MACRO_TUNING_PARAM(LaserBounceNum, laser_bounce_num, 1) MACRO_TUNING_PARAM(LaserBounceCost, laser_bounce_cost, 0) -MACRO_TUNING_PARAM(LaserDamage, laser_damage, 5) MACRO_TUNING_PARAM(PlayerCollision, player_collision, 1) MACRO_TUNING_PARAM(PlayerHooking, player_hooking, 1)