2017-06-06 05:31:56 +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. */
|
|
|
|
|
|
|
|
#include <engine/shared/snapshot.h>
|
|
|
|
#include <game/generated/protocol.h>
|
|
|
|
#include <base/math.h>
|
|
|
|
#include "extrainfo.h"
|
|
|
|
|
|
|
|
bool UseExtraInfo(const CNetObj_Projectile *pProj)
|
|
|
|
{
|
2017-06-06 08:11:42 +00:00
|
|
|
bool ExtraInfoFlag = ((abs(pProj->m_VelY) & (1<<9)) != 0);
|
|
|
|
return ExtraInfoFlag;
|
2017-06-06 05:31:56 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 08:51:43 +00:00
|
|
|
void ExtractInfo(const CNetObj_Projectile *pProj, vec2 *StartPos, vec2 *StartVel)
|
2017-06-06 05:31:56 +00:00
|
|
|
{
|
2019-05-21 08:51:43 +00:00
|
|
|
if(!UseExtraInfo(pProj))
|
2017-06-06 08:11:42 +00:00
|
|
|
{
|
|
|
|
StartPos->x = pProj->m_X;
|
|
|
|
StartPos->y = pProj->m_Y;
|
|
|
|
StartVel->x = pProj->m_VelX/100.0f;
|
|
|
|
StartVel->y = pProj->m_VelY/100.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
StartPos->x = pProj->m_X/100.0f;
|
|
|
|
StartPos->y = pProj->m_Y/100.0f;
|
|
|
|
float Angle = pProj->m_VelX/1000000.0f;
|
|
|
|
StartVel->x = sin(-Angle);
|
|
|
|
StartVel->y = cos(-Angle);
|
|
|
|
}
|
2017-06-06 05:31:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExtractExtraInfo(const CNetObj_Projectile *pProj, int *Owner, bool *Explosive, int *Bouncing, bool *Freeze)
|
|
|
|
{
|
2017-06-06 08:11:42 +00:00
|
|
|
int Data = pProj->m_VelY;
|
|
|
|
if(Owner)
|
|
|
|
{
|
|
|
|
*Owner = Data & 255;
|
|
|
|
if((Data>>8) & 1)
|
|
|
|
*Owner = -(*Owner);
|
|
|
|
}
|
|
|
|
if(Bouncing)
|
|
|
|
*Bouncing = (Data>>10) & 3;
|
|
|
|
if(Explosive)
|
|
|
|
*Explosive = (Data>>12) & 1;
|
|
|
|
if(Freeze)
|
|
|
|
*Freeze = (Data>>13) & 1;
|
2017-06-06 05:31:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SnapshotRemoveExtraInfo(unsigned char *pData)
|
|
|
|
{
|
2017-06-06 08:11:42 +00:00
|
|
|
CSnapshot *pSnap = (CSnapshot*) pData;
|
|
|
|
for(int Index = 0; Index < pSnap->NumItems(); Index++)
|
|
|
|
{
|
|
|
|
CSnapshotItem *pItem = pSnap->GetItem(Index);
|
|
|
|
if(pItem->Type() == NETOBJTYPE_PROJECTILE)
|
|
|
|
{
|
|
|
|
CNetObj_Projectile *pProj = (CNetObj_Projectile*) ((void*)pItem->Data());
|
|
|
|
if(UseExtraInfo(pProj))
|
|
|
|
{
|
|
|
|
vec2 Pos;
|
|
|
|
vec2 Vel;
|
2019-05-21 08:51:43 +00:00
|
|
|
ExtractInfo(pProj, &Pos, &Vel);
|
2017-06-06 08:11:42 +00:00
|
|
|
pProj->m_X = Pos.x;
|
|
|
|
pProj->m_Y = Pos.y;
|
|
|
|
pProj->m_VelX = (int)(Vel.x*100.0f);
|
|
|
|
pProj->m_VelY = (int)(Vel.y*100.0f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-06 05:31:56 +00:00
|
|
|
}
|