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. */
|
2020-09-26 19:41:58 +00:00
|
|
|
#include "pickup.h"
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <game/generated/protocol.h>
|
|
|
|
#include <game/server/gamecontext.h>
|
2021-01-09 14:37:02 +00:00
|
|
|
#include <game/server/player.h>
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2011-04-09 06:41:31 +00:00
|
|
|
#include <game/server/teams.h>
|
2021-09-19 12:14:00 +00:00
|
|
|
#include <game/version.h>
|
2011-04-09 06:41:31 +00:00
|
|
|
|
2021-01-09 14:18:52 +00:00
|
|
|
#include "character.h"
|
|
|
|
|
2022-03-21 08:01:56 +00:00
|
|
|
static constexpr int PickupPhysSize = 14;
|
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
CPickup::CPickup(CGameWorld *pGameWorld, int Type, int SubType, int Layer, int Number) :
|
2021-01-09 20:40:03 +00:00
|
|
|
CEntity(pGameWorld, CGameWorld::ENTTYPE_PICKUP, vec2(0, 0), PickupPhysSize)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Type = Type;
|
|
|
|
m_Subtype = SubType;
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2011-04-09 06:41:31 +00:00
|
|
|
m_Layer = Layer;
|
|
|
|
m_Number = Number;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
Reset();
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
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
|
|
|
{
|
2011-04-09 06:41:31 +00:00
|
|
|
/*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;
|
2008-07-06 11:21:21 +00:00
|
|
|
else
|
2011-04-09 06:41:31 +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
|
|
|
{
|
2010-07-29 05:21:18 +00:00
|
|
|
Move();
|
2011-04-09 06:41:31 +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;
|
2010-07-29 05:21:18 +00:00
|
|
|
}*/
|
2008-07-06 11:21:21 +00:00
|
|
|
// Check if a player intersected us
|
2010-09-08 16:22:11 +00:00
|
|
|
CCharacter *apEnts[MAX_CLIENTS];
|
2020-09-26 19:41:58 +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];
|
2021-08-15 08:11:00 +00:00
|
|
|
|
2010-09-08 16:22:11 +00:00
|
|
|
if(pChr && pChr->IsAlive())
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2021-01-20 19:00:16 +00:00
|
|
|
if(m_Layer == LAYER_SWITCH && m_Number > 0 && !GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[pChr->Team()])
|
2020-09-26 19:41:58 +00:00
|
|
|
continue;
|
2017-03-21 10:24:44 +00:00
|
|
|
bool Sound = false;
|
2010-09-08 16:22:11 +00:00
|
|
|
// player picked us up, is someone was hooking us, let them go
|
2020-09-26 19:41:58 +00:00
|
|
|
switch(m_Type)
|
2010-09-08 16:22:11 +00:00
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
case POWERUP_HEALTH:
|
|
|
|
if(pChr->Freeze())
|
2021-08-14 14:11:57 +00:00
|
|
|
GameServer()->CreateSound(m_Pos, SOUND_PICKUP_HEALTH, pChr->TeamMask());
|
2020-09-26 19:41:58 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case POWERUP_ARMOR:
|
|
|
|
if(pChr->Team() == TEAM_SUPER)
|
|
|
|
continue;
|
2022-03-20 11:57:50 +00:00
|
|
|
for(int j = WEAPON_SHOTGUN; j < NUM_WEAPONS; j++)
|
2020-09-26 19:41:58 +00:00
|
|
|
{
|
2022-03-20 11:57:50 +00:00
|
|
|
if(pChr->GetWeaponGot(j))
|
2010-05-29 07:25:38 +00:00
|
|
|
{
|
2022-03-20 11:57:50 +00:00
|
|
|
pChr->SetWeaponGot(j, false);
|
|
|
|
pChr->SetWeaponAmmo(j, 0);
|
2020-09-26 19:41:58 +00:00
|
|
|
Sound = true;
|
2010-05-29 07:25:38 +00:00
|
|
|
}
|
2020-09-26 19:41:58 +00:00
|
|
|
}
|
|
|
|
pChr->SetNinjaActivationDir(vec2(0, 0));
|
|
|
|
pChr->SetNinjaActivationTick(-500);
|
|
|
|
pChr->SetNinjaCurrentMoveTime(0);
|
|
|
|
if(Sound)
|
|
|
|
{
|
|
|
|
pChr->SetLastWeapon(WEAPON_GUN);
|
2021-08-14 14:11:57 +00:00
|
|
|
GameServer()->CreateSound(m_Pos, SOUND_PICKUP_ARMOR, pChr->TeamMask());
|
2020-09-26 19:41:58 +00:00
|
|
|
}
|
|
|
|
if(pChr->GetActiveWeapon() >= WEAPON_SHOTGUN)
|
|
|
|
pChr->SetActiveWeapon(WEAPON_HAMMER);
|
|
|
|
break;
|
2011-04-09 06:41:31 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
case POWERUP_WEAPON:
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
if(m_Subtype >= 0 && m_Subtype < NUM_WEAPONS && (!pChr->GetWeaponGot(m_Subtype) || pChr->GetWeaponAmmo(m_Subtype) != -1))
|
|
|
|
{
|
|
|
|
pChr->GiveWeapon(m_Subtype);
|
2016-10-08 17:42:42 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
//RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime;
|
2016-10-08 17:42:42 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
if(m_Subtype == WEAPON_GRENADE)
|
2021-08-14 14:11:57 +00:00
|
|
|
GameServer()->CreateSound(m_Pos, SOUND_PICKUP_GRENADE, pChr->TeamMask());
|
2020-09-26 19:41:58 +00:00
|
|
|
else if(m_Subtype == WEAPON_SHOTGUN)
|
2021-08-14 14:11:57 +00:00
|
|
|
GameServer()->CreateSound(m_Pos, SOUND_PICKUP_SHOTGUN, pChr->TeamMask());
|
2020-09-26 19:41:58 +00:00
|
|
|
else if(m_Subtype == WEAPON_LASER)
|
2021-08-14 14:11:57 +00:00
|
|
|
GameServer()->CreateSound(m_Pos, SOUND_PICKUP_SHOTGUN, pChr->TeamMask());
|
2010-09-08 16:22:11 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
if(pChr->GetPlayer())
|
|
|
|
GameServer()->SendWeaponPickup(pChr->GetPlayer()->GetCID(), m_Subtype);
|
|
|
|
}
|
|
|
|
break;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
case POWERUP_NINJA:
|
2020-09-26 19:41:58 +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
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
/*// 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())
|
2010-08-30 23:45:42 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if (pC != pChr)
|
|
|
|
pC->SetEmote(EMOTE_SURPRISE, Server()->Tick() + Server()->TickSpeed());
|
2011-01-20 14:10:32 +00:00
|
|
|
}*/
|
2020-09-26 19:41:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
2010-09-08 16:22:11 +00:00
|
|
|
};
|
2011-04-13 23:27:49 +00:00
|
|
|
|
|
|
|
/*if(RespawnTime >= 0)
|
2010-09-08 16:22:11 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}*/
|
|
|
|
}
|
2010-08-30 23:45:42 +00:00
|
|
|
}
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
2012-01-09 23:49:31 +00:00
|
|
|
void CPickup::TickPaused()
|
|
|
|
{
|
2012-04-12 00:09:31 +00:00
|
|
|
/*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)
|
2008-07-06 11:21:21 +00:00
|
|
|
{
|
2021-10-26 13:34:00 +00:00
|
|
|
if(NetworkClipped(SnappingClient))
|
|
|
|
return;
|
2011-04-09 06:41:31 +00:00
|
|
|
|
2014-01-13 16:00:49 +00:00
|
|
|
CCharacter *Char = GameServer()->GetPlayerChar(SnappingClient);
|
|
|
|
|
2022-03-07 21:16:28 +00:00
|
|
|
if(SnappingClient != SERVER_DEMO_CLIENT && (GameServer()->m_apPlayers[SnappingClient]->GetTeam() == TEAM_SPECTATORS || GameServer()->m_apPlayers[SnappingClient]->IsPaused()) && GameServer()->m_apPlayers[SnappingClient]->m_SpectatorID != SPEC_FREEVIEW)
|
2014-01-13 16:00:49 +00:00
|
|
|
Char = GameServer()->GetPlayerChar(GameServer()->m_apPlayers[SnappingClient]->m_SpectatorID);
|
|
|
|
|
2022-03-04 20:23:32 +00:00
|
|
|
int SnappingClientVersion = SnappingClient != SERVER_DEMO_CLIENT ? GameServer()->GetClientVersion(SnappingClient) : CLIENT_VERSIONNR;
|
2021-08-30 22:05:56 +00:00
|
|
|
|
2021-11-06 11:13:42 +00:00
|
|
|
CNetObj_EntityEx *pEntData = 0;
|
|
|
|
if(SnappingClientVersion >= VERSION_DDNET_SWITCH && (m_Layer == LAYER_SWITCH || length(m_Core) > 0))
|
|
|
|
pEntData = static_cast<CNetObj_EntityEx *>(Server()->SnapNewItem(NETOBJTYPE_ENTITYEX, GetID(), sizeof(CNetObj_EntityEx)));
|
2021-08-30 22:05:56 +00:00
|
|
|
|
2021-11-06 11:13:42 +00:00
|
|
|
if(pEntData)
|
|
|
|
{
|
|
|
|
pEntData->m_SwitchNumber = m_Number;
|
|
|
|
pEntData->m_Layer = m_Layer;
|
|
|
|
pEntData->m_EntityClass = ENTITYCLASS_PICKUP;
|
|
|
|
}
|
|
|
|
else
|
2021-09-19 12:14:00 +00:00
|
|
|
{
|
|
|
|
int Tick = (Server()->Tick() % Server()->TickSpeed()) % 11;
|
|
|
|
if(Char && Char->IsAlive() && m_Layer == LAYER_SWITCH && m_Number > 0 && !GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[Char->Team()] && !Tick)
|
|
|
|
return;
|
|
|
|
}
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
int Size = Server()->IsSixup(SnappingClient) ? 3 * 4 : sizeof(CNetObj_Pickup);
|
2021-01-09 20:40:17 +00:00
|
|
|
CNetObj_Pickup *pP = static_cast<CNetObj_Pickup *>(Server()->SnapNewItem(NETOBJTYPE_PICKUP, GetID(), Size));
|
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;
|
2020-03-29 02:36:38 +00:00
|
|
|
if(Server()->IsSixup(SnappingClient))
|
|
|
|
{
|
|
|
|
if(m_Type == POWERUP_WEAPON)
|
|
|
|
pP->m_Type = m_Subtype == WEAPON_SHOTGUN ? 3 : m_Subtype == WEAPON_GRENADE ? 2 : 4;
|
|
|
|
else if(m_Type == POWERUP_NINJA)
|
|
|
|
pP->m_Type = 5;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
pP->m_Subtype = m_Subtype;
|
2008-07-06 11:21:21 +00:00
|
|
|
}
|
2011-04-09 06:41:31 +00:00
|
|
|
|
|
|
|
void CPickup::Move()
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
if(Server()->Tick() % int(Server()->TickSpeed() * 0.15f) == 0)
|
2011-04-09 06:41:31 +00:00
|
|
|
{
|
|
|
|
int Flags;
|
2020-09-26 19:41:58 +00:00
|
|
|
int index = GameServer()->Collision()->IsMover(m_Pos.x, m_Pos.y, &Flags);
|
|
|
|
if(index)
|
2011-04-09 06:41:31 +00:00
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
m_Core = GameServer()->Collision()->CpSpeed(index, Flags);
|
2011-04-09 06:41:31 +00:00
|
|
|
}
|
|
|
|
m_Pos += m_Core;
|
|
|
|
}
|
2011-11-08 12:15:31 +00:00
|
|
|
}
|