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. */
|
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)
|
2011-01-19 17:27:50 +00:00
|
|
|
: CEntity(pGameWorld, CGameWorld::ENTTYPE_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-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;
|
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
|
|
|
{
|
|
|
|
// wait for respawn
|
2010-05-29 07:25:38 +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;
|
|
|
|
}
|
|
|
|
// 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
|
|
|
{
|
|
|
|
// 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:
|
|
|
|
if(pChr->IncreaseHealth(1))
|
|
|
|
{
|
|
|
|
GameServer()->CreateSound(m_Pos, SOUND_PICKUP_HEALTH);
|
|
|
|
RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case POWERUP_ARMOR:
|
|
|
|
if(pChr->IncreaseArmor(1))
|
|
|
|
{
|
|
|
|
GameServer()->CreateSound(m_Pos, SOUND_PICKUP_ARMOR);
|
|
|
|
RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime;
|
|
|
|
}
|
|
|
|
break;
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
case POWERUP_WEAPON:
|
|
|
|
if(m_Subtype >= 0 && m_Subtype < NUM_WEAPONS)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(pChr->GiveWeapon(m_Subtype, 10))
|
|
|
|
{
|
|
|
|
RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime;
|
2008-07-06 11:21:21 +00:00
|
|
|
|
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();
|
|
|
|
RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime;
|
|
|
|
|
|
|
|
// loop through all players, setting their emotes
|
2011-01-19 17:27:50 +00:00
|
|
|
CCharacter *pC = static_cast<CCharacter *>(GameServer()->m_World.FindFirst(CGameWorld::ENTTYPE_CHARACTER));
|
|
|
|
for(; pC; pC = (CCharacter *)pC->TypeNext())
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if (pC != pChr)
|
|
|
|
pC->SetEmote(EMOTE_SURPRISE, Server()->Tick() + Server()->TickSpeed());
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
pChr->SetEmote(EMOTE_ANGRY, Server()->Tick() + 1200 * Server()->TickSpeed() / 1000);
|
|
|
|
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-05-29 07:25:38 +00:00
|
|
|
if(RespawnTime >= 0)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-08-17 22:06:00 +00:00
|
|
|
char aBuf[256];
|
|
|
|
str_format(aBuf, sizeof(aBuf), "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);
|
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
|
|
|
m_SpawnTick = Server()->Tick() + Server()->TickSpeed() * RespawnTime;
|
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-05-29 07:25:38 +00:00
|
|
|
if(m_SpawnTick != -1 || NetworkClipped(SnappingClient))
|
2008-07-06 11:21:21 +00:00
|
|
|
return;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CNetObj_Pickup *pP = static_cast<CNetObj_Pickup *>(Server()->SnapNewItem(NETOBJTYPE_PICKUP, m_Id, sizeof(CNetObj_Pickup)));
|
2010-12-16 02:29:08 +00:00
|
|
|
if(!pP)
|
|
|
|
return;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
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
|
|
|
}
|