2010-05-29 07:25:38 +00:00
|
|
|
#include <game/generated/protocol.h>
|
|
|
|
#include <game/server/gamecontext.h>
|
|
|
|
#include "pickup.h"
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CPickup::CPickup(CGameWorld *pGameWorld, int Type, int SubType)
|
|
|
|
: CEntity(pGameWorld, NETOBJTYPE_PICKUP)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Type = Type;
|
|
|
|
m_Subtype = SubType;
|
|
|
|
m_ProximityRadius = PickupPhysSize;
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
Reset();
|
|
|
|
|
|
|
|
GameWorld()->InsertEntity(this);
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CPickup::Reset()
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-07-29 05:21:18 +00:00
|
|
|
/*
|
2010-05-29 07:25:38 +00:00
|
|
|
if (g_pData->m_aPickups[m_Type].m_Spawndelay > 0)
|
|
|
|
m_SpawnTick = Server()->Tick() + Server()->TickSpeed() * g_pData->m_aPickups[m_Type].m_Spawndelay;
|
2008-07-06 11:21:21 +00:00
|
|
|
else
|
2010-05-29 07:25:38 +00:00
|
|
|
m_SpawnTick = -1;
|
2010-07-29 05:21:18 +00:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPickup::Move()
|
|
|
|
{
|
|
|
|
if (Server()->Tick()%int(Server()->TickSpeed() * 0.15f) == 0)
|
|
|
|
{
|
|
|
|
int index = GameServer()->Collision()->IsCp(m_Pos.x, m_Pos.y);
|
|
|
|
if (index)
|
|
|
|
{
|
|
|
|
m_Core = GameServer()->Collision()->CpSpeed(index);
|
|
|
|
}
|
|
|
|
m_Pos += m_Core;
|
|
|
|
}
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CPickup::Tick()
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-07-29 05:21:18 +00:00
|
|
|
Move();
|
2008-07-06 11:21:21 +00:00
|
|
|
// wait for respawn
|
2010-07-29 05:21:18 +00:00
|
|
|
/*if(m_SpawnTick > 0)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(Server()->Tick() > m_SpawnTick)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
|
|
|
// respawn
|
2010-05-29 07:25:38 +00:00
|
|
|
m_SpawnTick = -1;
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_Type == POWERUP_WEAPON)
|
|
|
|
GameServer()->CreateSound(m_Pos, SOUND_WEAPON_SPAWN);
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return;
|
2010-07-29 05:21:18 +00:00
|
|
|
}*/
|
2008-07-06 11:21:21 +00:00
|
|
|
// Check if a player intersected us
|
2010-05-29 07:25:38 +00:00
|
|
|
CCharacter *pChr = GameServer()->m_World.ClosestCharacter(m_Pos, 20.0f, 0);
|
|
|
|
if(pChr && pChr->IsAlive())
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-07-29 05:21:18 +00:00
|
|
|
bool sound = false;
|
2008-07-06 11:21:21 +00:00
|
|
|
// player picked us up, is someone was hooking us, let them go
|
2010-05-29 07:25:38 +00:00
|
|
|
int RespawnTime = -1;
|
|
|
|
switch (m_Type)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
case POWERUP_HEALTH:
|
2010-07-29 05:21:18 +00:00
|
|
|
if(pChr->Freeze()) GameServer()->CreateSound(m_Pos, SOUND_PICKUP_HEALTH);
|
2010-05-29 07:25:38 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case POWERUP_ARMOR:
|
2010-07-29 05:21:18 +00:00
|
|
|
for(int i=WEAPON_SHOTGUN;i<NUM_WEAPONS;i++)
|
|
|
|
{
|
|
|
|
if (pChr->m_aWeapons[i].m_Got)
|
|
|
|
{
|
|
|
|
pChr->m_aWeapons[i].m_Got = false;
|
|
|
|
pChr->m_aWeapons[i].m_Ammo = 0;
|
|
|
|
sound = true;
|
|
|
|
}
|
2010-08-22 22:04:26 +00:00
|
|
|
if(pChr->m_FreezeTime)
|
|
|
|
{
|
|
|
|
pChr->m_aWeapons[WEAPON_GUN].m_Ammo = 0;
|
|
|
|
pChr->m_aWeapons[WEAPON_HAMMER].m_Ammo =0;
|
|
|
|
}
|
2010-08-22 22:46:39 +00:00
|
|
|
pChr->m_Ninja.m_ActivationDir=vec2(0,0);
|
|
|
|
pChr->m_Ninja.m_ActivationTick=0;
|
|
|
|
pChr->m_Ninja.m_CurrentMoveTime=0;
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
|
|
|
if (sound)
|
2010-05-29 07:25:38 +00:00
|
|
|
{
|
2010-07-29 05:21:18 +00:00
|
|
|
pChr->m_LastWeapon = WEAPON_GUN;
|
2010-05-29 07:25:38 +00:00
|
|
|
GameServer()->CreateSound(m_Pos, SOUND_PICKUP_ARMOR);
|
|
|
|
}
|
2010-07-29 05:21:18 +00:00
|
|
|
pChr->m_ActiveWeapon = WEAPON_HAMMER;
|
2010-05-29 07:25:38 +00:00
|
|
|
break;
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
case POWERUP_WEAPON:
|
2010-07-29 05:21:18 +00:00
|
|
|
|
2010-08-22 22:04:26 +00:00
|
|
|
if(m_Subtype >= 0 && m_Subtype < NUM_WEAPONS && (!pChr->m_aWeapons[m_Subtype].m_Got || pChr->m_aWeapons[m_Subtype].m_Ammo != -1))
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-07-29 05:21:18 +00:00
|
|
|
if(pChr->GiveWeapon(m_Subtype, -1))
|
2010-05-29 07:25:38 +00:00
|
|
|
{
|
2010-07-29 05:21:18 +00:00
|
|
|
//RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_Subtype == WEAPON_GRENADE)
|
|
|
|
GameServer()->CreateSound(m_Pos, SOUND_PICKUP_GRENADE);
|
|
|
|
else if(m_Subtype == WEAPON_SHOTGUN)
|
|
|
|
GameServer()->CreateSound(m_Pos, SOUND_PICKUP_SHOTGUN);
|
|
|
|
else if(m_Subtype == WEAPON_RIFLE)
|
|
|
|
GameServer()->CreateSound(m_Pos, SOUND_PICKUP_SHOTGUN);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(pChr->GetPlayer())
|
|
|
|
GameServer()->SendWeaponPickup(pChr->GetPlayer()->GetCID(), m_Subtype);
|
|
|
|
}
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
2010-05-29 07:25:38 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case POWERUP_NINJA:
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
// activate ninja on target player
|
|
|
|
pChr->GiveNinja();
|
2010-07-29 05:21:18 +00:00
|
|
|
//RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
default:
|
2008-07-06 11:21:21 +00:00
|
|
|
break;
|
|
|
|
};
|
2010-07-29 05:21:18 +00:00
|
|
|
/*
|
2010-05-29 07:25:38 +00:00
|
|
|
if(RespawnTime >= 0)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
|
|
|
dbg_msg("game", "pickup player='%d:%s' item=%d/%d",
|
2010-05-29 07:25:38 +00:00
|
|
|
pChr->GetPlayer()->GetCID(), Server()->ClientName(pChr->GetPlayer()->GetCID()), m_Type, m_Subtype);
|
|
|
|
m_SpawnTick = Server()->Tick() + Server()->TickSpeed() * RespawnTime;
|
2010-07-29 05:21:18 +00:00
|
|
|
}*/
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CPickup::Snap(int SnappingClient)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-07-29 05:21:18 +00:00
|
|
|
/*
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_SpawnTick != -1 || NetworkClipped(SnappingClient))
|
2008-07-06 11:21:21 +00:00
|
|
|
return;
|
2010-07-29 05:21:18 +00:00
|
|
|
*/
|
2010-05-29 07:25:38 +00:00
|
|
|
CNetObj_Pickup *pP = static_cast<CNetObj_Pickup *>(Server()->SnapNewItem(NETOBJTYPE_PICKUP, m_Id, sizeof(CNetObj_Pickup)));
|
|
|
|
pP->m_X = (int)m_Pos.x;
|
|
|
|
pP->m_Y = (int)m_Pos.y;
|
|
|
|
pP->m_Type = m_Type;
|
|
|
|
pP->m_Subtype = m_Subtype;
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|