| 1 | /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ |
|---|---|
| 2 | /* If you are missing that file, acquire a complete release at teeworlds.com. */ |
| 3 | |
| 4 | #include "laser_data.h" |
| 5 | |
| 6 | #include <engine/shared/snapshot.h> |
| 7 | |
| 8 | #include <generated/protocol.h> |
| 9 | |
| 10 | #include <game/client/prediction/gameworld.h> |
| 11 | #include <game/collision.h> |
| 12 | |
| 13 | CLaserData ExtractLaserInfo(int NetObjType, const void *pData, CGameWorld *pGameWorld, const CNetObj_EntityEx *pEntEx) |
| 14 | { |
| 15 | CLaserData Result; |
| 16 | |
| 17 | if(NetObjType == NETOBJTYPE_DDNETLASER) |
| 18 | { |
| 19 | Result = ExtractLaserInfoDDNet(pLaser: (const CNetObj_DDNetLaser *)pData, pGameWorld); |
| 20 | } |
| 21 | else |
| 22 | { |
| 23 | CNetObj_Laser *pLaser = (CNetObj_Laser *)pData; |
| 24 | |
| 25 | Result.m_From.x = pLaser->m_FromX; |
| 26 | Result.m_From.y = pLaser->m_FromY; |
| 27 | Result.m_To.x = pLaser->m_X; |
| 28 | Result.m_To.y = pLaser->m_Y; |
| 29 | Result.m_StartTick = pLaser->m_StartTick; |
| 30 | Result.m_ExtraInfo = false; |
| 31 | Result.m_Owner = -1; |
| 32 | Result.m_Type = -1; |
| 33 | Result.m_SwitchNumber = 0; |
| 34 | Result.m_Subtype = -1; |
| 35 | Result.m_TuneZone = pGameWorld && pGameWorld->m_WorldConfig.m_UseTuneZones ? pGameWorld->Collision()->IsTune(Index: pGameWorld->Collision()->GetMapIndex(Pos: Result.m_From)) : 0; |
| 36 | Result.m_Predict = true; |
| 37 | } |
| 38 | |
| 39 | if(pEntEx && !(NetObjType == NETOBJTYPE_DDNETLASER && Result.m_SwitchNumber >= 0)) |
| 40 | { |
| 41 | Result.m_SwitchNumber = pEntEx->m_SwitchNumber; |
| 42 | if(pEntEx->m_EntityClass == ENTITYCLASS_LIGHT) |
| 43 | { |
| 44 | Result.m_Type = LASERTYPE_FREEZE; |
| 45 | } |
| 46 | else if(pEntEx->m_EntityClass >= ENTITYCLASS_GUN_NORMAL && pEntEx->m_EntityClass <= ENTITYCLASS_GUN_UNFREEZE) |
| 47 | { |
| 48 | Result.m_Type = LASERTYPE_GUN; |
| 49 | } |
| 50 | else if(pEntEx->m_EntityClass >= ENTITYCLASS_DRAGGER_WEAK && pEntEx->m_EntityClass <= ENTITYCLASS_DRAGGER_STRONG) |
| 51 | { |
| 52 | Result.m_Type = LASERTYPE_DRAGGER; |
| 53 | } |
| 54 | else if(pEntEx->m_EntityClass == ENTITYCLASS_DOOR) |
| 55 | { |
| 56 | Result.m_Type = LASERTYPE_DOOR; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | return Result; |
| 61 | } |
| 62 | |
| 63 | CLaserData ExtractLaserInfoDDNet(const CNetObj_DDNetLaser *pLaser, CGameWorld *pGameWorld) |
| 64 | { |
| 65 | CLaserData Result; |
| 66 | Result.m_From.x = pLaser->m_FromX; |
| 67 | Result.m_From.y = pLaser->m_FromY; |
| 68 | Result.m_To.x = pLaser->m_ToX; |
| 69 | Result.m_To.y = pLaser->m_ToY; |
| 70 | Result.m_StartTick = pLaser->m_StartTick; |
| 71 | Result.m_ExtraInfo = true; |
| 72 | Result.m_Owner = pLaser->m_Owner; |
| 73 | Result.m_Type = pLaser->m_Type; |
| 74 | Result.m_SwitchNumber = pLaser->m_SwitchNumber; |
| 75 | Result.m_Subtype = pLaser->m_Subtype; |
| 76 | Result.m_TuneZone = pGameWorld && pGameWorld->m_WorldConfig.m_UseTuneZones ? pGameWorld->Collision()->IsTune(Index: pGameWorld->Collision()->GetMapIndex(Pos: Result.m_From)) : 0; |
| 77 | Result.m_Predict = !(pLaser->m_Flags & LASERFLAG_NO_PREDICT); |
| 78 | return Result; |
| 79 | } |
| 80 |