ddnet/src/game/server/entities/pickup.cpp

191 lines
5.6 KiB
C++
Raw Normal View History

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"
#include <game/server/teams.h>
CPickup::CPickup(CGameWorld *pGameWorld, int Type, int SubType, int Layer, int Number)
: CEntity(pGameWorld, CGameWorld::ENTTYPE_PICKUP)
{
2010-05-29 07:25:38 +00:00
m_Type = Type;
m_Subtype = SubType;
m_ProximityRadius = PickupPhysSize;
m_Layer = Layer;
m_Number = Number;
2010-05-29 07:25:38 +00:00
Reset();
2010-05-29 07:25:38 +00:00
GameWorld()->InsertEntity(this);
}
2010-05-29 07:25:38 +00:00
void CPickup::Reset()
{
/*if (g_pData->m_aPickups[m_Type].m_Spawndelay > 0)
2010-05-29 07:25:38 +00:00
m_SpawnTick = Server()->Tick() + Server()->TickSpeed() * g_pData->m_aPickups[m_Type].m_Spawndelay;
else
m_SpawnTick = -1;*/
}
2010-05-29 07:25:38 +00:00
void CPickup::Tick()
{
Move();
/*// wait for respawn
2010-05-29 07:25:38 +00:00
if(m_SpawnTick > 0)
{
2010-05-29 07:25:38 +00:00
if(Server()->Tick() > m_SpawnTick)
{
// respawn
2010-05-29 07:25:38 +00:00
m_SpawnTick = -1;
2010-05-29 07:25:38 +00:00
if(m_Type == POWERUP_WEAPON)
GameServer()->CreateSound(m_Pos, SOUND_WEAPON_SPAWN);
}
else
return;
}*/
// Check if a player intersected us
CCharacter *apEnts[MAX_CLIENTS];
2014-01-02 00:56:09 +00:00
int Num = GameWorld()->FindEntities(m_Pos, 20.0f, (CEntity**)apEnts, MAX_CLIENTS, CGameWorld::ENTTYPE_CHARACTER);
for(int i = 0; i < Num; ++i) {
CCharacter * pChr = apEnts[i];
if(pChr && pChr->IsAlive())
{
if(m_Layer == LAYER_SWITCH && !GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[pChr->Team()]) continue;
2017-03-21 10:24:44 +00:00
bool Sound = false;
// player picked us up, is someone was hooking us, let them go
switch (m_Type)
{
case POWERUP_HEALTH:
2011-01-29 00:59:50 +00:00
if(pChr->Freeze()) GameServer()->CreateSound(m_Pos, SOUND_PICKUP_HEALTH, pChr->Teams()->TeamMask(pChr->Team()));
break;
case POWERUP_ARMOR:
if(pChr->Team() == TEAM_SUPER) continue;
2011-01-29 00:59:50 +00:00
for(int i = WEAPON_SHOTGUN; i < NUM_WEAPONS; i++)
{
2011-01-29 00:59:50 +00:00
if(pChr->GetWeaponGot(i))
{
if(!(pChr->m_FreezeTime && i == WEAPON_NINJA))
{
2011-01-29 00:59:50 +00:00
pChr->SetWeaponGot(i, false);
pChr->SetWeaponAmmo(i, 0);
2017-03-21 10:24:44 +00:00
Sound = true;
}
}
}
2011-01-29 00:59:50 +00:00
pChr->SetNinjaActivationDir(vec2(0,0));
pChr->SetNinjaActivationTick(-500);
pChr->SetNinjaCurrentMoveTime(0);
2017-03-21 10:24:44 +00:00
if (Sound)
2010-05-29 07:25:38 +00:00
{
2011-01-29 00:59:50 +00:00
pChr->SetLastWeapon(WEAPON_GUN);
2011-11-08 12:15:31 +00:00
GameServer()->CreateSound(m_Pos, SOUND_PICKUP_ARMOR, pChr->Teams()->TeamMask(pChr->Team()));
2010-05-29 07:25:38 +00:00
}
if(!pChr->m_FreezeTime && pChr->GetActiveWeapon() >= WEAPON_SHOTGUN)
pChr->SetActiveWeapon(WEAPON_HAMMER);
2010-05-29 07:25:38 +00:00
break;
case POWERUP_WEAPON:
2016-10-08 17:42:42 +00:00
if (m_Subtype >= 0 && m_Subtype < NUM_WEAPONS && (!pChr->GetWeaponGot(m_Subtype) || (pChr->GetWeaponAmmo(m_Subtype) != -1 && !pChr->m_FreezeTime)))
{
2016-10-08 17:42:42 +00:00
pChr->GiveWeapon(m_Subtype);
2016-10-08 17:42:42 +00:00
//RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime;
if (m_Subtype == WEAPON_GRENADE)
GameServer()->CreateSound(m_Pos, SOUND_PICKUP_GRENADE, pChr->Teams()->TeamMask(pChr->Team()));
else if (m_Subtype == WEAPON_SHOTGUN)
GameServer()->CreateSound(m_Pos, SOUND_PICKUP_SHOTGUN, pChr->Teams()->TeamMask(pChr->Team()));
else if (m_Subtype == WEAPON_RIFLE)
GameServer()->CreateSound(m_Pos, SOUND_PICKUP_SHOTGUN, pChr->Teams()->TeamMask(pChr->Team()));
if (pChr->GetPlayer())
GameServer()->SendWeaponPickup(pChr->GetPlayer()->GetCID(), m_Subtype);
}
break;
2010-05-29 07:25:38 +00:00
case POWERUP_NINJA:
{
2010-05-29 07:25:38 +00:00
// activate ninja on target player
pChr->GiveNinja();
//RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime;
2010-05-29 07:25:38 +00:00
/*// loop through all players, setting their emotes
CCharacter *pC = static_cast<CCharacter *>(GameServer()->m_World.FindFirst(CGameWorld::ENTTYPE_CHARACTER));
for(; pC; pC = (CCharacter *)pC->TypeNext())
{
2010-05-29 07:25:38 +00:00
if (pC != pChr)
pC->SetEmote(EMOTE_SURPRISE, Server()->Tick() + Server()->TickSpeed());
}*/
2010-05-29 07:25:38 +00:00
break;
}
default:
break;
};
/*if(RespawnTime >= 0)
{
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, m_Subtype);
GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf);
m_SpawnTick = Server()->Tick() + Server()->TickSpeed() * RespawnTime;
}*/
}
}
}
2012-01-09 23:49:31 +00:00
void CPickup::TickPaused()
{
/*if(m_SpawnTick != -1)
++m_SpawnTick;*/
2012-01-09 23:49:31 +00:00
}
2010-05-29 07:25:38 +00:00
void CPickup::Snap(int SnappingClient)
{
/*if(m_SpawnTick != -1 || NetworkClipped(SnappingClient))
return;*/
2014-01-13 16:00:49 +00:00
CCharacter *Char = GameServer()->GetPlayerChar(SnappingClient);
if(SnappingClient > -1 && (GameServer()->m_apPlayers[SnappingClient]->GetTeam() == -1
2017-04-08 22:20:41 +00:00
|| GameServer()->m_apPlayers[SnappingClient]->IsPaused())
2014-01-13 16:00:49 +00:00
&& GameServer()->m_apPlayers[SnappingClient]->m_SpectatorID != SPEC_FREEVIEW)
Char = GameServer()->GetPlayerChar(GameServer()->m_apPlayers[SnappingClient]->m_SpectatorID);
int Tick = (Server()->Tick()%Server()->TickSpeed())%11;
2014-01-13 16:00:49 +00:00
if (Char && Char->IsAlive() &&
(m_Layer == LAYER_SWITCH &&
2014-01-13 16:00:49 +00:00
!GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[Char->Team()])
&& (!Tick))
return;
CNetObj_Pickup *pP = static_cast<CNetObj_Pickup *>(Server()->SnapNewItem(NETOBJTYPE_PICKUP, m_ID, sizeof(CNetObj_Pickup)));
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;
}
void CPickup::Move()
{
if (Server()->Tick()%int(Server()->TickSpeed() * 0.15f) == 0)
{
int Flags;
int index = GameServer()->Collision()->IsMover(m_Pos.x,m_Pos.y, &Flags);
if (index)
{
m_Core=GameServer()->Collision()->CpSpeed(index, Flags);
}
m_Pos += m_Core;
}
2011-11-08 12:15:31 +00:00
}