2010-11-20 10:37:14 +00:00
|
|
|
/* (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. */
|
2008-07-06 11:21:21 +00:00
|
|
|
#include <new>
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <engine/shared/config.h>
|
|
|
|
#include <game/server/gamecontext.h>
|
|
|
|
#include <game/mapitems.h>
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
#include "character.h"
|
|
|
|
#include "laser.h"
|
|
|
|
#include "projectile.h"
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
//input count
|
|
|
|
struct CInputCount
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
int m_Presses;
|
|
|
|
int m_Releases;
|
2008-07-06 11:21:21 +00:00
|
|
|
};
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CInputCount CountInput(int Prev, int Cur)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CInputCount c = {0, 0};
|
|
|
|
Prev &= INPUT_STATE_MASK;
|
|
|
|
Cur &= INPUT_STATE_MASK;
|
|
|
|
int i = Prev;
|
|
|
|
|
|
|
|
while(i != Cur)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
|
|
|
i = (i+1)&INPUT_STATE_MASK;
|
|
|
|
if(i&1)
|
2010-05-29 07:25:38 +00:00
|
|
|
c.m_Presses++;
|
2008-07-06 11:21:21 +00:00
|
|
|
else
|
2010-05-29 07:25:38 +00:00
|
|
|
c.m_Releases++;
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2008-09-24 09:03:49 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
MACRO_ALLOC_POOL_ID_IMPL(CCharacter, MAX_CLIENTS)
|
2008-09-24 09:03:49 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// Character, "physical" player's part
|
|
|
|
CCharacter::CCharacter(CGameWorld *pWorld)
|
2011-01-19 17:27:50 +00:00
|
|
|
: CEntity(pWorld, CGameWorld::ENTTYPE_CHARACTER)
|
2008-09-23 07:43:41 +00:00
|
|
|
{
|
2010-06-03 15:39:42 +00:00
|
|
|
m_ProximityRadius = ms_PhysSize;
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Health = 0;
|
|
|
|
m_Armor = 0;
|
2008-09-23 07:43:41 +00:00
|
|
|
}
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CCharacter::Reset()
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
Destroy();
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
bool CCharacter::Spawn(CPlayer *pPlayer, vec2 Pos)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
m_PlayerState = PLAYERSTATE_UNKNOWN;
|
|
|
|
m_EmoteStop = -1;
|
|
|
|
m_LastAction = -1;
|
|
|
|
m_ActiveWeapon = WEAPON_GUN;
|
|
|
|
m_LastWeapon = WEAPON_HAMMER;
|
|
|
|
m_QueuedWeapon = -1;
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
m_pPlayer = pPlayer;
|
|
|
|
m_Pos = Pos;
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Core.Reset();
|
|
|
|
m_Core.Init(&GameServer()->m_World.m_Core, GameServer()->Collision());
|
|
|
|
m_Core.m_Pos = m_Pos;
|
|
|
|
GameServer()->m_World.m_Core.m_apCharacters[m_pPlayer->GetCID()] = &m_Core;
|
|
|
|
|
|
|
|
m_ReckoningTick = 0;
|
|
|
|
mem_zero(&m_SendCore, sizeof(m_SendCore));
|
|
|
|
mem_zero(&m_ReckoningCore, sizeof(m_ReckoningCore));
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
GameServer()->m_World.InsertEntity(this);
|
|
|
|
m_Alive = true;
|
2008-08-27 20:04:07 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
GameServer()->m_pController->OnCharacterSpawn(this);
|
2008-08-27 20:04:07 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CCharacter::Destroy()
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
GameServer()->m_World.m_Core.m_apCharacters[m_pPlayer->GetCID()] = 0;
|
|
|
|
m_Alive = false;
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CCharacter::SetWeapon(int W)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(W == m_ActiveWeapon)
|
2008-07-06 11:21:21 +00:00
|
|
|
return;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
m_LastWeapon = m_ActiveWeapon;
|
|
|
|
m_QueuedWeapon = -1;
|
|
|
|
m_ActiveWeapon = W;
|
|
|
|
GameServer()->CreateSound(m_Pos, SOUND_WEAPON_SWITCH);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_ActiveWeapon < 0 || m_ActiveWeapon >= NUM_WEAPONS)
|
|
|
|
m_ActiveWeapon = 0;
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
bool CCharacter::IsGrounded()
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-06-03 15:39:42 +00:00
|
|
|
if(GameServer()->Collision()->CheckPoint(m_Pos.x+m_ProximityRadius/2, m_Pos.y+m_ProximityRadius/2+5))
|
2008-07-06 11:21:21 +00:00
|
|
|
return true;
|
2010-06-03 15:39:42 +00:00
|
|
|
if(GameServer()->Collision()->CheckPoint(m_Pos.x-m_ProximityRadius/2, m_Pos.y+m_ProximityRadius/2+5))
|
2008-07-06 11:21:21 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CCharacter::HandleNinja()
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_ActiveWeapon != WEAPON_NINJA)
|
|
|
|
return;
|
2008-10-08 18:36:30 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
vec2 Direction = normalize(vec2(m_LatestInput.m_TargetX, m_LatestInput.m_TargetY));
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if ((Server()->Tick() - m_Ninja.m_ActivationTick) > (g_pData->m_Weapons.m_Ninja.m_Duration * Server()->TickSpeed() / 1000))
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
|
|
|
// time's up, return
|
2010-05-29 07:25:38 +00:00
|
|
|
m_aWeapons[WEAPON_NINJA].m_Got = false;
|
|
|
|
m_ActiveWeapon = m_LastWeapon;
|
|
|
|
if(m_ActiveWeapon == WEAPON_NINJA)
|
|
|
|
m_ActiveWeapon = WEAPON_GUN;
|
|
|
|
|
|
|
|
SetWeapon(m_ActiveWeapon);
|
|
|
|
return;
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// force ninja Weapon
|
|
|
|
SetWeapon(WEAPON_NINJA);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Ninja.m_CurrentMoveTime--;
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if (m_Ninja.m_CurrentMoveTime == 0)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
// reset velocity
|
|
|
|
m_Core.m_Vel *= 0.2f;
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if (m_Ninja.m_CurrentMoveTime > 0)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
// Set velocity
|
|
|
|
m_Core.m_Vel = m_Ninja.m_ActivationDir * g_pData->m_Weapons.m_Ninja.m_Velocity;
|
|
|
|
vec2 OldPos = m_Pos;
|
2010-06-03 15:39:42 +00:00
|
|
|
GameServer()->Collision()->MoveBox(&m_Core.m_Pos, &m_Core.m_Vel, vec2(m_ProximityRadius, m_ProximityRadius), 0.f);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
// reset velocity so the client doesn't predict stuff
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Core.m_Vel = vec2(0.f, 0.f);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// check if we Hit anything along the way
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2011-01-19 17:27:50 +00:00
|
|
|
CCharacter *aEnts[MAX_CLIENTS];
|
2010-05-29 07:25:38 +00:00
|
|
|
vec2 Dir = m_Pos - OldPos;
|
2010-06-03 15:39:42 +00:00
|
|
|
float Radius = m_ProximityRadius * 2.0f;
|
2010-05-29 07:25:38 +00:00
|
|
|
vec2 Center = OldPos + Dir * 0.5f;
|
2011-01-19 17:27:50 +00:00
|
|
|
int Num = GameServer()->m_World.FindEntities(Center, Radius, (CEntity**)aEnts, MAX_CLIENTS, CGameWorld::ENTTYPE_CHARACTER);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
for (int i = 0; i < Num; ++i)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if (aEnts[i] == this)
|
2008-07-06 11:21:21 +00:00
|
|
|
continue;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
// make sure we haven't Hit this object before
|
|
|
|
bool bAlreadyHit = false;
|
|
|
|
for (int j = 0; j < m_NumObjectsHit; j++)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if (m_apHitObjects[j] == aEnts[i])
|
|
|
|
bAlreadyHit = true;
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
2010-05-29 07:25:38 +00:00
|
|
|
if (bAlreadyHit)
|
2008-07-06 11:21:21 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// check so we are sufficiently close
|
2010-06-03 15:39:42 +00:00
|
|
|
if (distance(aEnts[i]->m_Pos, m_Pos) > (m_ProximityRadius * 2.0f))
|
2008-07-06 11:21:21 +00:00
|
|
|
continue;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// Hit a player, give him damage and stuffs...
|
|
|
|
GameServer()->CreateSound(aEnts[i]->m_Pos, SOUND_NINJA_HIT);
|
2008-07-06 11:21:21 +00:00
|
|
|
// set his velocity to fast upward (for now)
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_NumObjectsHit < 10)
|
|
|
|
m_apHitObjects[m_NumObjectsHit++] = aEnts[i];
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
aEnts[i]->TakeDamage(vec2(0, 10.0f), g_pData->m_Weapons.m_Ninja.m_pBase->m_Damage, m_pPlayer->GetCID(), WEAPON_NINJA);
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
return;
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
return;
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CCharacter::DoWeaponSwitch()
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
// make sure we can switch
|
|
|
|
if(m_ReloadTimer != 0 || m_QueuedWeapon == -1 || m_aWeapons[WEAPON_NINJA].m_Got)
|
2008-07-06 11:21:21 +00:00
|
|
|
return;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// switch Weapon
|
|
|
|
SetWeapon(m_QueuedWeapon);
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CCharacter::HandleWeaponSwitch()
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
int WantedWeapon = m_ActiveWeapon;
|
|
|
|
if(m_QueuedWeapon != -1)
|
|
|
|
WantedWeapon = m_QueuedWeapon;
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// 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;
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(Next < 128) // make sure we only try sane stuff
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
while(Next) // Next Weapon selection
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
WantedWeapon = (WantedWeapon+1)%NUM_WEAPONS;
|
|
|
|
if(m_aWeapons[WantedWeapon].m_Got)
|
|
|
|
Next--;
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(Prev < 128) // make sure we only try sane stuff
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
while(Prev) // Prev Weapon selection
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
WantedWeapon = (WantedWeapon-1)<0?NUM_WEAPONS-1:WantedWeapon-1;
|
|
|
|
if(m_aWeapons[WantedWeapon].m_Got)
|
|
|
|
Prev--;
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// Direct Weapon selection
|
|
|
|
if(m_LatestInput.m_WantedWeapon)
|
|
|
|
WantedWeapon = m_Input.m_WantedWeapon-1;
|
2008-07-06 11:21:21 +00:00
|
|
|
|
|
|
|
// check for insane values
|
2010-05-29 07:25:38 +00:00
|
|
|
if(WantedWeapon >= 0 && WantedWeapon < NUM_WEAPONS && WantedWeapon != m_ActiveWeapon && m_aWeapons[WantedWeapon].m_Got)
|
|
|
|
m_QueuedWeapon = WantedWeapon;
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
DoWeaponSwitch();
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CCharacter::FireWeapon()
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_ReloadTimer != 0)
|
2008-07-06 11:21:21 +00:00
|
|
|
return;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
DoWeaponSwitch();
|
|
|
|
vec2 Direction = normalize(vec2(m_LatestInput.m_TargetX, m_LatestInput.m_TargetY));
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
bool FullAuto = false;
|
|
|
|
if(m_ActiveWeapon == WEAPON_GRENADE || m_ActiveWeapon == WEAPON_SHOTGUN || m_ActiveWeapon == WEAPON_RIFLE)
|
|
|
|
FullAuto = true;
|
2008-07-06 11:21:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
// check if we gonna fire
|
2010-05-29 07:25:38 +00:00
|
|
|
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)
|
2008-07-06 11:21:21 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// check for ammo
|
2010-05-29 07:25:38 +00:00
|
|
|
if(!m_aWeapons[m_ActiveWeapon].m_Ammo)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2009-01-11 13:54:42 +00:00
|
|
|
// 125ms is a magical limit of how fast a human can click
|
2010-05-29 07:25:38 +00:00
|
|
|
m_ReloadTimer = 125 * Server()->TickSpeed() / 1000;
|
|
|
|
GameServer()->CreateSound(m_Pos, SOUND_WEAPON_NOAMMO);
|
2008-07-06 11:21:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-03 15:39:42 +00:00
|
|
|
vec2 ProjStartPos = m_Pos+Direction*m_ProximityRadius*0.75f;
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
switch(m_ActiveWeapon)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
|
|
|
case WEAPON_HAMMER:
|
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
// reset objects Hit
|
|
|
|
m_NumObjectsHit = 0;
|
|
|
|
GameServer()->CreateSound(m_Pos, SOUND_HAMMER_FIRE);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2011-01-19 17:27:50 +00:00
|
|
|
CCharacter *apEnts[MAX_CLIENTS];
|
2010-05-29 07:25:38 +00:00
|
|
|
int Hits = 0;
|
2011-01-09 19:53:19 +00:00
|
|
|
int Num = GameServer()->m_World.FindEntities(ProjStartPos, m_ProximityRadius*0.5f, (CEntity**)apEnts,
|
2011-01-19 17:27:50 +00:00
|
|
|
MAX_CLIENTS, CGameWorld::ENTTYPE_CHARACTER);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
for (int i = 0; i < Num; ++i)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2011-01-09 19:53:19 +00:00
|
|
|
CCharacter *pTarget = apEnts[i];
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
//for race mod or any other mod, which needs hammer hits through the wall remove second condition
|
2011-01-09 19:53:19 +00:00
|
|
|
if ((pTarget == this) || GameServer()->Collision()->IntersectLine(ProjStartPos, pTarget->m_Pos, NULL, NULL))
|
2008-07-06 11:21:21 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// set his velocity to fast upward (for now)
|
2010-05-29 07:25:38 +00:00
|
|
|
GameServer()->CreateHammerHit(m_Pos);
|
2011-01-09 19:53:19 +00:00
|
|
|
pTarget->TakeDamage(vec2(0.f, -1.f), g_pData->m_Weapons.m_Hammer.m_pBase->m_Damage, m_pPlayer->GetCID(), m_ActiveWeapon);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
vec2 Dir;
|
2011-01-09 19:53:19 +00:00
|
|
|
if (length(pTarget->m_Pos - m_Pos) > 0.0f)
|
|
|
|
Dir = normalize(pTarget->m_Pos - m_Pos);
|
2008-07-06 11:21:21 +00:00
|
|
|
else
|
2010-05-29 07:25:38 +00:00
|
|
|
Dir = vec2(0.f, -1.f);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2011-01-09 19:53:19 +00:00
|
|
|
pTarget->m_Core.m_Vel += normalize(Dir + vec2(0.f, -1.1f)) * 10.0f;
|
2010-05-29 07:25:38 +00:00
|
|
|
Hits++;
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// if we Hit anything, we have to wait for the reload
|
|
|
|
if(Hits)
|
|
|
|
m_ReloadTimer = Server()->TickSpeed()/3;
|
2009-01-11 11:54:41 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case WEAPON_GUN:
|
|
|
|
{
|
2011-01-09 19:53:19 +00:00
|
|
|
CProjectile *pProj = new CProjectile(GameWorld(), WEAPON_GUN,
|
2010-05-29 07:25:38 +00:00
|
|
|
m_pPlayer->GetCID(),
|
|
|
|
ProjStartPos,
|
|
|
|
Direction,
|
|
|
|
(int)(Server()->TickSpeed()*GameServer()->Tuning()->m_GunLifetime),
|
2008-07-06 11:21:21 +00:00
|
|
|
1, 0, 0, -1, WEAPON_GUN);
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// pack the Projectile and send it to the client Directly
|
|
|
|
CNetObj_Projectile p;
|
2011-01-09 19:53:19 +00:00
|
|
|
pProj->FillInfo(&p);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
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);
|
2008-07-06 11:21:21 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case WEAPON_SHOTGUN:
|
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
int ShotSpread = 2;
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CMsgPacker Msg(NETMSGTYPE_SV_EXTRAPROJECTILE);
|
|
|
|
Msg.AddInt(ShotSpread*2+1);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
for(int i = -ShotSpread; i <= ShotSpread; ++i)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
float Spreading[] = {-0.185f, -0.070f, 0, 0.070f, 0.185f};
|
|
|
|
float a = GetAngle(Direction);
|
|
|
|
a += Spreading[i+2];
|
|
|
|
float v = 1-(absolute(i)/(float)ShotSpread);
|
|
|
|
float Speed = mix((float)GameServer()->Tuning()->m_ShotgunSpeeddiff, 1.0f, v);
|
2011-01-09 19:53:19 +00:00
|
|
|
CProjectile *pProj = new CProjectile(GameWorld(), WEAPON_SHOTGUN,
|
2010-05-29 07:25:38 +00:00
|
|
|
m_pPlayer->GetCID(),
|
|
|
|
ProjStartPos,
|
|
|
|
vec2(cosf(a), sinf(a))*Speed,
|
|
|
|
(int)(Server()->TickSpeed()*GameServer()->Tuning()->m_ShotgunLifetime),
|
2008-07-06 11:21:21 +00:00
|
|
|
1, 0, 0, -1, WEAPON_SHOTGUN);
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// pack the Projectile and send it to the client Directly
|
|
|
|
CNetObj_Projectile p;
|
2011-01-09 19:53:19 +00:00
|
|
|
pProj->FillInfo(&p);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
for(unsigned i = 0; i < sizeof(CNetObj_Projectile)/sizeof(int); i++)
|
|
|
|
Msg.AddInt(((int *)&p)[i]);
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
Server()->SendMsg(&Msg, 0,m_pPlayer->GetCID());
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
GameServer()->CreateSound(m_Pos, SOUND_SHOTGUN_FIRE);
|
2008-07-06 11:21:21 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case WEAPON_GRENADE:
|
|
|
|
{
|
2011-01-09 19:53:19 +00:00
|
|
|
CProjectile *pProj = new CProjectile(GameWorld(), WEAPON_GRENADE,
|
2010-05-29 07:25:38 +00:00
|
|
|
m_pPlayer->GetCID(),
|
|
|
|
ProjStartPos,
|
|
|
|
Direction,
|
|
|
|
(int)(Server()->TickSpeed()*GameServer()->Tuning()->m_GrenadeLifetime),
|
|
|
|
1, true, 0, SOUND_GRENADE_EXPLODE, WEAPON_GRENADE);
|
|
|
|
|
|
|
|
// pack the Projectile and send it to the client Directly
|
|
|
|
CNetObj_Projectile p;
|
2011-01-09 19:53:19 +00:00
|
|
|
pProj->FillInfo(&p);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
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());
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
GameServer()->CreateSound(m_Pos, SOUND_GRENADE_FIRE);
|
2008-07-06 11:21:21 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case WEAPON_RIFLE:
|
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
new CLaser(GameWorld(), m_Pos, Direction, GameServer()->Tuning()->m_LaserReach, m_pPlayer->GetCID());
|
|
|
|
GameServer()->CreateSound(m_Pos, SOUND_RIFLE_FIRE);
|
2008-07-06 11:21:21 +00:00
|
|
|
} break;
|
|
|
|
|
2008-10-08 18:36:30 +00:00
|
|
|
case WEAPON_NINJA:
|
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
// reset Hit objects
|
|
|
|
m_NumObjectsHit = 0;
|
2008-10-08 18:36:30 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
m_AttackTick = Server()->Tick();
|
|
|
|
m_Ninja.m_ActivationDir = Direction;
|
|
|
|
m_Ninja.m_CurrentMoveTime = g_pData->m_Weapons.m_Ninja.m_Movetime * Server()->TickSpeed() / 1000;
|
2008-10-08 18:36:30 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
GameServer()->CreateSound(m_Pos, SOUND_NINJA_FIRE);
|
2008-10-08 18:36:30 +00:00
|
|
|
} break;
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
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;
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CCharacter::HandleWeapons()
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
//ninja
|
|
|
|
HandleNinja();
|
|
|
|
|
|
|
|
vec2 Direction = normalize(vec2(m_LatestInput.m_TargetX, m_LatestInput.m_TargetY));
|
2008-10-08 18:36:30 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
// check reload timer
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_ReloadTimer)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
m_ReloadTimer--;
|
|
|
|
return;
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// fire Weapon, if wanted
|
|
|
|
FireWeapon();
|
2008-07-06 11:21:21 +00:00
|
|
|
|
|
|
|
// ammo regen
|
2010-05-29 07:25:38 +00:00
|
|
|
int AmmoRegenTime = g_pData->m_Weapons.m_aId[m_ActiveWeapon].m_Ammoregentime;
|
|
|
|
if(AmmoRegenTime)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
|
|
|
// If equipped and not active, regen ammo?
|
2010-05-29 07:25:38 +00:00
|
|
|
if (m_ReloadTimer <= 0)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if (m_aWeapons[m_ActiveWeapon].m_AmmoRegenStart < 0)
|
|
|
|
m_aWeapons[m_ActiveWeapon].m_AmmoRegenStart = Server()->Tick();
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if ((Server()->Tick() - m_aWeapons[m_ActiveWeapon].m_AmmoRegenStart) >= AmmoRegenTime * Server()->TickSpeed() / 1000)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
|
|
|
// Add some ammo
|
2010-05-29 07:25:38 +00:00
|
|
|
m_aWeapons[m_ActiveWeapon].m_Ammo = min(m_aWeapons[m_ActiveWeapon].m_Ammo + 1, 10);
|
|
|
|
m_aWeapons[m_ActiveWeapon].m_AmmoRegenStart = -1;
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
m_aWeapons[m_ActiveWeapon].m_AmmoRegenStart = -1;
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCharacter::GiveNinja()
|
|
|
|
{
|
|
|
|
m_Ninja.m_ActivationTick = Server()->Tick();
|
|
|
|
m_aWeapons[WEAPON_NINJA].m_Got = true;
|
|
|
|
m_aWeapons[WEAPON_NINJA].m_Ammo = -1;
|
|
|
|
m_LastWeapon = m_ActiveWeapon;
|
|
|
|
m_ActiveWeapon = WEAPON_NINJA;
|
|
|
|
|
|
|
|
GameServer()->CreateSound(m_Pos, SOUND_PICKUP_NINJA);
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CCharacter::SetEmote(int Emote, int Tick)
|
|
|
|
{
|
|
|
|
m_EmoteType = Emote;
|
|
|
|
m_EmoteStop = Tick;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCharacter::OnPredictedInput(CNetObj_PlayerInput *pNewInput)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
|
|
|
// check for changes
|
2010-05-29 07:25:38 +00:00
|
|
|
if(mem_comp(&m_Input, pNewInput, sizeof(CNetObj_PlayerInput)) != 0)
|
|
|
|
m_LastAction = Server()->Tick();
|
2008-07-06 11:21:21 +00:00
|
|
|
|
|
|
|
// copy new input
|
2010-05-29 07:25:38 +00:00
|
|
|
mem_copy(&m_Input, pNewInput, sizeof(m_Input));
|
|
|
|
m_NumInputs++;
|
2008-07-06 11:21:21 +00:00
|
|
|
|
|
|
|
// or are not allowed to aim in the center
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_Input.m_TargetX == 0 && m_Input.m_TargetY == 0)
|
|
|
|
m_Input.m_TargetY = -1;
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CCharacter::OnDirectInput(CNetObj_PlayerInput *pNewInput)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
mem_copy(&m_LatestPrevInput, &m_LatestInput, sizeof(m_LatestInput));
|
|
|
|
mem_copy(&m_LatestInput, pNewInput, sizeof(m_LatestInput));
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2011-01-03 11:50:38 +00:00
|
|
|
if(m_NumInputs > 2 && m_pPlayer->GetTeam() != TEAM_SPECTATORS)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
HandleWeaponSwitch();
|
|
|
|
FireWeapon();
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
2008-09-23 08:55:49 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
mem_copy(&m_LatestPrevInput, &m_LatestInput, sizeof(m_LatestInput));
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CCharacter::Tick()
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_pPlayer->m_ForceBalanced)
|
2008-09-07 08:10:56 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
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());
|
2008-09-07 08:10:56 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
m_pPlayer->m_ForceBalanced = false;
|
2008-09-07 08:10:56 +00:00
|
|
|
}
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Core.m_Input = m_Input;
|
|
|
|
m_Core.Tick(true);
|
2008-09-23 14:10:05 +00:00
|
|
|
|
2011-01-08 10:34:19 +00:00
|
|
|
// handle death-tiles and leaving gamelayer
|
2010-06-03 15:39:42 +00:00
|
|
|
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 ||
|
|
|
|
GameServer()->Collision()->GetCollisionAt(m_Pos.x-m_ProximityRadius/3.f, m_Pos.y-m_ProximityRadius/3.f)&CCollision::COLFLAG_DEATH ||
|
2011-01-08 10:34:19 +00:00
|
|
|
GameServer()->Collision()->GetCollisionAt(m_Pos.x-m_ProximityRadius/3.f, m_Pos.y+m_ProximityRadius/3.f)&CCollision::COLFLAG_DEATH ||
|
|
|
|
GameLayerClipped(m_Pos))
|
2010-06-11 09:39:32 +00:00
|
|
|
{
|
|
|
|
Die(m_pPlayer->GetCID(), WEAPON_WORLD);
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// handle Weapons
|
|
|
|
HandleWeapons();
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
m_PlayerState = m_Input.m_PlayerState;
|
2008-07-06 11:21:21 +00:00
|
|
|
|
|
|
|
// Previnput
|
2010-05-29 07:25:38 +00:00
|
|
|
m_PrevInput = m_Input;
|
2008-07-06 11:21:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CCharacter::TickDefered()
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2008-09-23 07:43:41 +00:00
|
|
|
// advance the dummy
|
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CWorldCore TempWorld;
|
|
|
|
m_ReckoningCore.Init(&TempWorld, GameServer()->Collision());
|
|
|
|
m_ReckoningCore.Tick(false);
|
|
|
|
m_ReckoningCore.Move();
|
|
|
|
m_ReckoningCore.Quantize();
|
2008-09-23 07:43:41 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
//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))
|
|
|
|
{
|
2010-06-09 16:24:38 +00:00
|
|
|
// Hackish solution to get rid of strict-aliasing warning
|
|
|
|
union
|
|
|
|
{
|
|
|
|
float f;
|
|
|
|
unsigned u;
|
|
|
|
}StartPosX, StartPosY, StartVelX, StartVelY;
|
|
|
|
|
|
|
|
StartPosX.f = StartPos.x;
|
|
|
|
StartPosY.f = StartPos.y;
|
|
|
|
StartVelX.f = StartVel.x;
|
|
|
|
StartVelY.f = StartVel.y;
|
|
|
|
|
2010-08-17 22:06:00 +00:00
|
|
|
char aBuf[256];
|
|
|
|
str_format(aBuf, sizeof(aBuf), "STUCK!!! %d %d %d %f %f %f %f %x %x %x %x",
|
2010-05-29 07:25:38 +00:00
|
|
|
StuckBefore,
|
|
|
|
StuckAfterMove,
|
|
|
|
StuckAfterQuant,
|
|
|
|
StartPos.x, StartPos.y,
|
|
|
|
StartVel.x, StartVel.y,
|
2010-06-09 16:24:38 +00:00
|
|
|
StartPosX.u, StartPosY.u,
|
|
|
|
StartVelX.u, StartVelY.u);
|
2010-08-17 22:06:00 +00:00
|
|
|
GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf);
|
2010-05-29 07:25:38 +00:00
|
|
|
}
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
|
2011-01-03 11:50:38 +00:00
|
|
|
if(m_pPlayer->GetTeam() == TEAM_SPECTATORS)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Pos.x = m_Input.m_TargetX;
|
|
|
|
m_Pos.y = m_Input.m_TargetY;
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
2008-09-23 07:43:41 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// update the m_SendCore if needed
|
2008-09-23 07:43:41 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CNetObj_Character Predicted;
|
|
|
|
CNetObj_Character Current;
|
|
|
|
mem_zero(&Predicted, sizeof(Predicted));
|
|
|
|
mem_zero(&Current, sizeof(Current));
|
|
|
|
m_ReckoningCore.Write(&Predicted);
|
|
|
|
m_Core.Write(&Current);
|
2008-11-16 15:10:57 +00:00
|
|
|
|
2008-09-25 14:04:02 +00:00
|
|
|
// only allow dead reackoning for a top of 3 seconds
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_ReckoningTick+Server()->TickSpeed()*3 < Server()->Tick() || mem_comp(&Predicted, &Current, sizeof(CNetObj_Character)) != 0)
|
2008-09-23 07:43:41 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
m_ReckoningTick = Server()->Tick();
|
|
|
|
m_SendCore = m_Core;
|
|
|
|
m_ReckoningCore = m_Core;
|
2008-09-23 07:43:41 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
bool CCharacter::IncreaseHealth(int Amount)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_Health >= 10)
|
2008-07-06 11:21:21 +00:00
|
|
|
return false;
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Health = clamp(m_Health+Amount, 0, 10);
|
2008-07-06 11:21:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
bool CCharacter::IncreaseArmor(int Amount)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_Armor >= 10)
|
2008-07-06 11:21:21 +00:00
|
|
|
return false;
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Armor = clamp(m_Armor+Amount, 0, 10);
|
2008-07-06 11:21:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CCharacter::Die(int Killer, int Weapon)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
int ModeSpecial = GameServer()->m_pController->OnCharacterDeath(this, GameServer()->m_apPlayers[Killer], Weapon);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-08-17 22:06:00 +00:00
|
|
|
char aBuf[256];
|
|
|
|
str_format(aBuf, sizeof(aBuf), "kill killer='%d:%s' victim='%d:%s' weapon=%d special=%d",
|
2010-05-29 07:25:38 +00:00
|
|
|
Killer, Server()->ClientName(Killer),
|
|
|
|
m_pPlayer->GetCID(), Server()->ClientName(m_pPlayer->GetCID()), Weapon, ModeSpecial);
|
2010-08-17 22:06:00 +00:00
|
|
|
GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
|
|
|
// send the kill message
|
2010-05-29 07:25:38 +00:00
|
|
|
CNetMsg_Sv_KillMsg Msg;
|
|
|
|
Msg.m_Killer = Killer;
|
|
|
|
Msg.m_Victim = m_pPlayer->GetCID();
|
|
|
|
Msg.m_Weapon = Weapon;
|
|
|
|
Msg.m_ModeSpecial = ModeSpecial;
|
|
|
|
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, -1);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
|
|
|
// a nice sound
|
2010-05-29 07:25:38 +00:00
|
|
|
GameServer()->CreateSound(m_Pos, SOUND_PLAYER_DIE);
|
2008-11-16 14:28:44 +00:00
|
|
|
|
|
|
|
// this is for auto respawn after 3 secs
|
2010-05-29 07:25:38 +00:00
|
|
|
m_pPlayer->m_DieTick = Server()->Tick();
|
2008-11-16 14:28:44 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Alive = false;
|
|
|
|
GameServer()->m_World.RemoveEntity(this);
|
|
|
|
GameServer()->m_World.m_Core.m_apCharacters[m_pPlayer->GetCID()] = 0;
|
|
|
|
GameServer()->CreateDeath(m_Pos, m_pPlayer->GetCID());
|
2008-11-16 14:28:44 +00:00
|
|
|
|
|
|
|
// we got to wait 0.5 secs before respawning
|
2010-05-29 07:25:38 +00:00
|
|
|
m_pPlayer->m_RespawnTick = Server()->Tick()+Server()->TickSpeed()/2;
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
bool CCharacter::TakeDamage(vec2 Force, int Dmg, int From, int Weapon)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Core.m_Vel += Force;
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(GameServer()->m_pController->IsFriendlyFire(m_pPlayer->GetCID(), From) && !g_Config.m_SvTeamdamage)
|
2008-07-06 11:21:21 +00:00
|
|
|
return false;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// m_pPlayer only inflicts half damage on self
|
|
|
|
if(From == m_pPlayer->GetCID())
|
|
|
|
Dmg = max(1, Dmg/2);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
m_DamageTaken++;
|
2008-07-06 11:21:21 +00:00
|
|
|
|
|
|
|
// create healthmod indicator
|
2010-05-29 07:25:38 +00:00
|
|
|
if(Server()->Tick() < m_DamageTakenTick+25)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
|
|
|
// make sure that the damage indicators doesn't group together
|
2010-05-29 07:25:38 +00:00
|
|
|
GameServer()->CreateDamageInd(m_Pos, m_DamageTaken*0.25f, Dmg);
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
m_DamageTaken = 0;
|
|
|
|
GameServer()->CreateDamageInd(m_Pos, 0, Dmg);
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(Dmg)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_Armor)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(Dmg > 1)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Health--;
|
|
|
|
Dmg--;
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(Dmg > m_Armor)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
Dmg -= m_Armor;
|
|
|
|
m_Armor = 0;
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Armor -= Dmg;
|
|
|
|
Dmg = 0;
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Health -= Dmg;
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
m_DamageTakenTick = Server()->Tick();
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// do damage Hit sound
|
|
|
|
if(From >= 0 && From != m_pPlayer->GetCID() && GameServer()->m_apPlayers[From])
|
|
|
|
GameServer()->CreateSound(GameServer()->m_apPlayers[From]->m_ViewPos, SOUND_HIT, CmaskOne(From));
|
2008-07-06 11:21:21 +00:00
|
|
|
|
|
|
|
// check for death
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_Health <= 0)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
Die(From, Weapon);
|
2008-09-24 14:54:51 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
// set attacker's face to happy (taunt!)
|
2010-05-29 07:25:38 +00:00
|
|
|
if (From >= 0 && From != m_pPlayer->GetCID() && GameServer()->m_apPlayers[From])
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CCharacter *pChr = GameServer()->m_apPlayers[From]->GetCharacter();
|
|
|
|
if (pChr)
|
2008-10-15 16:43:25 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
pChr->m_EmoteType = EMOTE_HAPPY;
|
|
|
|
pChr->m_EmoteStop = Server()->Tick() + Server()->TickSpeed();
|
2008-10-15 16:43:25 +00:00
|
|
|
}
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
2008-09-24 14:54:51 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if (Dmg > 2)
|
|
|
|
GameServer()->CreateSound(m_Pos, SOUND_PLAYER_PAIN_LONG);
|
2008-07-06 11:21:21 +00:00
|
|
|
else
|
2010-05-29 07:25:38 +00:00
|
|
|
GameServer()->CreateSound(m_Pos, SOUND_PLAYER_PAIN_SHORT);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
m_EmoteType = EMOTE_PAIN;
|
|
|
|
m_EmoteStop = Server()->Tick() + 500 * Server()->TickSpeed() / 1000;
|
2008-07-06 11:21:21 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CCharacter::Snap(int SnappingClient)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(NetworkClipped(SnappingClient))
|
2008-07-06 11:21:21 +00:00
|
|
|
return;
|
|
|
|
|
2010-12-16 02:29:08 +00:00
|
|
|
CNetObj_Character *pCharacter = static_cast<CNetObj_Character *>(Server()->SnapNewItem(NETOBJTYPE_CHARACTER, m_pPlayer->GetCID(), sizeof(CNetObj_Character)));
|
|
|
|
if(!pCharacter)
|
|
|
|
return;
|
2008-09-23 07:43:41 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// write down the m_Core
|
2010-08-08 16:56:54 +00:00
|
|
|
if(!m_ReckoningTick || GameServer()->m_World.m_Paused)
|
2008-11-16 15:10:57 +00:00
|
|
|
{
|
|
|
|
// no dead reckoning when paused because the client doesn't know
|
|
|
|
// how far to perform the reckoning
|
2010-12-16 02:29:08 +00:00
|
|
|
pCharacter->m_Tick = 0;
|
|
|
|
m_Core.Write(pCharacter);
|
2008-11-16 15:10:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-12-16 02:29:08 +00:00
|
|
|
pCharacter->m_Tick = m_ReckoningTick;
|
|
|
|
m_SendCore.Write(pCharacter);
|
2008-11-16 15:10:57 +00:00
|
|
|
}
|
2008-09-23 07:43:41 +00:00
|
|
|
|
|
|
|
// set emote
|
2010-05-29 07:25:38 +00:00
|
|
|
if (m_EmoteStop < Server()->Tick())
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
m_EmoteType = EMOTE_NORMAL;
|
|
|
|
m_EmoteStop = -1;
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
2010-12-16 02:29:08 +00:00
|
|
|
pCharacter->m_Emote = m_EmoteType;
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-12-16 02:29:08 +00:00
|
|
|
pCharacter->m_AmmoCount = 0;
|
|
|
|
pCharacter->m_Health = 0;
|
|
|
|
pCharacter->m_Armor = 0;
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-12-16 02:29:08 +00:00
|
|
|
pCharacter->m_Weapon = m_ActiveWeapon;
|
|
|
|
pCharacter->m_AttackTick = m_AttackTick;
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-12-16 02:29:08 +00:00
|
|
|
pCharacter->m_Direction = m_Input.m_Direction;
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_pPlayer->GetCID() == SnappingClient)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-12-16 02:29:08 +00:00
|
|
|
pCharacter->m_Health = m_Health;
|
|
|
|
pCharacter->m_Armor = m_Armor;
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_aWeapons[m_ActiveWeapon].m_Ammo > 0)
|
2010-12-16 02:29:08 +00:00
|
|
|
pCharacter->m_AmmoCount = m_aWeapons[m_ActiveWeapon].m_Ammo;
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
2010-12-16 02:29:08 +00:00
|
|
|
if(pCharacter->m_Emote == EMOTE_NORMAL)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(250 - ((Server()->Tick() - m_LastAction)%(250)) < 5)
|
2010-12-16 02:29:08 +00:00
|
|
|
pCharacter->m_Emote = EMOTE_BLINK;
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
2010-12-16 02:29:08 +00:00
|
|
|
pCharacter->m_PlayerState = m_PlayerState;
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|