Skip to content

Commit 78ab2e8

Browse files
committed
add some support for projectiles and kill messages
1 parent 001ce77 commit 78ab2e8

4 files changed

Lines changed: 48 additions & 10 deletions

File tree

src/game/client/components/infomessages.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <game/client/gameclient.h>
1010
#include <game/client/animstate.h>
11+
#include <game/client/components/resources.h>
1112
#include "infomessages.h"
1213

1314
#include "chat.h"
@@ -247,7 +248,15 @@ void CInfoMessages::RenderKillMsg(CInfoMsg *pInfoMsg, float x, float y) const
247248

248249
// render weapon
249250
x -= 44.0f;
250-
if(pInfoMsg->m_Weapon >= 0)
251+
if(pInfoMsg->m_Weapon >= NUM_WEAPONS)
252+
{
253+
Graphics()->TextureSet(m_pClient->m_pResources->GetWeaponResource(pInfoMsg->m_Weapon)->m_Texture);
254+
Graphics()->QuadsBegin();
255+
IGraphics::CQuadItem QuadItem(x-16, y+28, 128, 128);
256+
Graphics()->QuadsDraw(&QuadItem, 1);
257+
Graphics()->QuadsEnd();
258+
}
259+
else if(pInfoMsg->m_Weapon >= 0)
251260
{
252261
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_GAME].m_Id);
253262
Graphics()->QuadsBegin();

src/game/client/components/items.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,24 @@ void CItems::RenderProjectile(const CNetObj_Projectile *pCurrent, int ItemID)
2222
// get positions
2323
float Curvature = 0;
2424
float Speed = 0;
25-
if(pCurrent->m_Type == WEAPON_GRENADE)
25+
26+
int WeaponPredict = pCurrent->m_Type >= NUM_WEAPONS ? m_pClient->m_pResources->GetWeaponResourcePredictsLike(pCurrent->m_Type) : pCurrent->m_Type;
27+
if(WeaponPredict == WEAPON_GRENADE)
2628
{
2729
Curvature = m_pClient->m_Tuning.m_GrenadeCurvature;
2830
Speed = m_pClient->m_Tuning.m_GrenadeSpeed;
2931
}
30-
else if(pCurrent->m_Type == WEAPON_SHOTGUN)
32+
else if(WeaponPredict == WEAPON_SHOTGUN)
3133
{
3234
Curvature = m_pClient->m_Tuning.m_ShotgunCurvature;
3335
Speed = m_pClient->m_Tuning.m_ShotgunSpeed;
3436
}
35-
else if(pCurrent->m_Type == WEAPON_GUN)
37+
else if(WeaponPredict == WEAPON_GUN)
3638
{
3739
Curvature = m_pClient->m_Tuning.m_GunCurvature;
3840
Speed = m_pClient->m_Tuning.m_GunSpeed;
3941
}
42+
4043

4144
static float s_LastGameTickTime = Client()->GameTickTime();
4245
if(!m_pClient->IsWorldPaused() && !m_pClient->IsDemoPlaybackPaused())
@@ -75,14 +78,20 @@ void CItems::RenderProjectile(const CNetObj_Projectile *pCurrent, int ItemID)
7578
vec2 Pos = CalcPos(StartPos, StartVel, Curvature, Speed, Ct);
7679
vec2 PrevPos = CalcPos(StartPos, StartVel, Curvature, Speed, Ct-0.001f);
7780

78-
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_GAME].m_Id);
81+
if (pCurrent->m_Type >= NUM_WEAPONS)
82+
Graphics()->TextureSet(m_pClient->m_pResources->GetWeaponResourceProjectile(pCurrent->m_Type)->m_Texture);
83+
else
84+
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_GAME].m_Id);
7985
Graphics()->QuadsBegin();
8086

81-
RenderTools()->SelectSprite(g_pData->m_Weapons.m_aId[clamp(pCurrent->m_Type, 0, NUM_WEAPONS-1)].m_pSpriteProj);
87+
if (pCurrent->m_Type < NUM_WEAPONS)
88+
RenderTools()->SelectSprite(g_pData->m_Weapons.m_aId[clamp(pCurrent->m_Type, 0, NUM_WEAPONS-1)].m_pSpriteProj);
89+
8290
const vec2 Vel = Pos-PrevPos;
8391

8492
// add particle for this projectile
85-
if(pCurrent->m_Type == WEAPON_GRENADE)
93+
int WeaponLooks = pCurrent->m_Type >= NUM_WEAPONS ? m_pClient->m_pResources->GetWeaponResourceLooksLike(pCurrent->m_Type) : pCurrent->m_Type;
94+
if(WeaponLooks == WEAPON_GRENADE)
8695
{
8796
m_pClient->m_pEffects->SmokeTrail(Pos, Vel*-1);
8897
const float Now = Client()->LocalTime();
@@ -98,7 +107,8 @@ void CItems::RenderProjectile(const CNetObj_Projectile *pCurrent, int ItemID)
98107
Graphics()->QuadsSetRotation(length(Vel) > 0.00001f ? angle(Vel) : 0);
99108
}
100109

101-
IGraphics::CQuadItem QuadItem(Pos.x, Pos.y, 32, 32);
110+
const int Size = pCurrent->m_Type >= NUM_WEAPONS ? 64 : 32;
111+
IGraphics::CQuadItem QuadItem(Pos.x, Pos.y, Size, Size);
102112
Graphics()->QuadsDraw(&QuadItem, 1);
103113
Graphics()->QuadsSetRotation(0);
104114
Graphics()->QuadsEnd();

src/game/client/components/resources.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,22 @@ const CResources::CResource *CResources::GetWeaponResourceAmmo(int WeaponId)
119119
return Get(WeaponMapping[WeaponId][3]);
120120
}
121121

122+
const int CResources::GetWeaponResourceLooksLike(int WeaponId)
123+
{
124+
if (WeaponId < 0 || WeaponId >= MAX_RESOURCES)
125+
return -1;
126+
else
127+
return WeaponMapping[WeaponId][4];
128+
}
129+
130+
const int CResources::GetWeaponResourcePredictsLike(int WeaponId)
131+
{
132+
if (WeaponId < 0 || WeaponId >= MAX_RESOURCES)
133+
return -1;
134+
else
135+
return WeaponMapping[WeaponId][5];
136+
}
137+
122138
int CResources::Find(const char *pName)
123139
{
124140
for(int i = 0; i < m_aResources.size(); i++)
@@ -171,10 +187,11 @@ void CResources::OnCustomWeaponInfoMessage(CNetMsg_Sv_CustomWeaponInfo* msg)
171187
str_format(aBuf, sizeof(aBuf), "got weapon id %i", WeaponId);
172188
Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "resources", aBuf);
173189

174-
// msg->m_LooksLike;
175-
// msg->m_PredictsLike;
190+
176191
WeaponMapping[WeaponId][0] = msg->m_ResourceIdWeapon;
177192
WeaponMapping[WeaponId][1] = msg->m_ResourceIdProjectile;
178193
WeaponMapping[WeaponId][2] = msg->m_ResourceIdCrosshair;
179194
WeaponMapping[WeaponId][3] = msg->m_ResourceIdAmmo;
195+
WeaponMapping[WeaponId][4] = msg->m_LooksLike;
196+
WeaponMapping[WeaponId][5] = msg->m_PredictsLike;
180197
}

src/game/client/components/resources.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class CResources : public CComponent
3131
const CResource *GetWeaponResourceCrosshair(int WeaponId);
3232
const CResource *GetWeaponResourceAmmo(int WeaponId);
3333
const CResource *GetWeaponResourceProjectile(int WeaponId);
34+
const int GetWeaponResourceLooksLike(int WeaponId);
35+
const int GetWeaponResourcePredictsLike(int WeaponId);
3436

3537
void OnResourceMessage(CNetMsg_Sv_ImageResource* msg);
3638
void OnCustomWeaponInfoMessage(CNetMsg_Sv_CustomWeaponInfo* msg);

0 commit comments

Comments
 (0)