Skip to content

Commit 4e41b25

Browse files
committed
Move clientid to callback ctx member and add emote
1 parent 033080a commit 4e41b25

File tree

11 files changed

+62
-14
lines changed

11 files changed

+62
-14
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ void CCharacter::Tick()
100100
TWBL::SetState(this, &State);
101101
State.m_pCollision = Collision();
102102
State.m_ppPlayers = GameServer()->m_apPlayers;
103+
GameServer()->m_TwblCallbackCtx.m_ClientId = GetPlayer()->GetCid();
103104
State.m_pCallbackCtx = &GameServer()->m_TwblCallbackCtx;
104105
105106
Twbl_SampleTick(&State, &Bot, &GetPlayer()->m_TwblPersistentState, sizeof(GetPlayer()->m_TwblPersistentState));
@@ -141,6 +142,7 @@ void CCharacter::Tick()
141142
TWBL::SetState(this, &State);
142143
State.m_pCollision = Collision();
143144
State.m_ppPlayers = GameServer()->m_apPlayers;
145+
GameServer()->m_TwblCallbackCtx.m_ClientId = GetPlayer()->GetCid();
144146
State.m_pCallbackCtx = &GameServer()->m_TwblCallbackCtx;
145147

146148
// ideally this Init() is moved to the constructor

src/bots/base.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void PushRingInt(int *pBuffer, int New, size_t MaxEntries)
8181

8282
void CBaseBot::_DieRaw() const
8383
{
84-
m_pStateIn->m_pCallbackCtx->Die(m_pStateIn->m_ClientId);
84+
m_pStateIn->m_pCallbackCtx->Die();
8585
}
8686

8787
void CBaseBot::_Die(const char *pComment) const
@@ -92,7 +92,21 @@ void CBaseBot::_Die(const char *pComment) const
9292

9393
void CBaseBot::_SendChatRaw(int Team, const char *pText)
9494
{
95-
m_pStateIn->m_pCallbackCtx->SendChat(m_pStateIn->m_ClientId, Team, pText);
95+
m_pStateIn->m_pCallbackCtx->SendChat(Team, pText);
96+
}
97+
98+
void CBaseBot::_EmoteRaw(int Emote)
99+
{
100+
m_pStateIn->m_pCallbackCtx->Emote(Emote);
101+
}
102+
103+
void CBaseBot::_Emote(int Emote, const char *pComment, const char *pFunction, const char *pFile, int Line)
104+
{
105+
_EmoteRaw(Emote);
106+
PushRingStr(m_pStateOut->m_apEmoteComments, pComment, GetStrBufSize(m_pStateOut->m_apEmoteComments));
107+
PushRingStr(m_pStateOut->m_apEmoteFunctions, pFunction, GetStrBufSize(m_pStateOut->m_apEmoteFunctions));
108+
PushRingStr(m_pStateOut->m_apEmoteFiles, pFile, GetStrBufSize(m_pStateOut->m_apEmoteFiles));
109+
PushRingInt(m_pStateOut->m_aEmoteLines, Line, GetIntBufSize(m_pStateOut->m_aEmoteLines));
96110
}
97111

98112
void CBaseBot::_AimRaw(int TargetX, int TargetY) const

src/bots/base.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ class CBaseBot
7777
void _DieRaw() const;
7878
void _Die(const char *pComment) const;
7979

80+
void _EmoteRaw(int Emote);
81+
void _Emote(int Emote, const char *pComment, const char *pFunction, const char *pFile, int Line);
82+
8083
/* Aim(x, y)
8184
*
8285
* Aim with targets using coordinates

src/bots/def_macros.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#ifdef TWBL_DEBUG
44
#define Die(comment) _Die(comment)
5+
#define Emote(value, comment) _Emote(value, comment)
56
#define Aim(TargetX, TargetY, comment) _Aim(TargetX, TargetY, comment, __func__, __FILE__, __LINE__)
67
#define AimPos(TargetX, TargetY, comment) _AimPos(TargetX, TargetY, comment, __func__, __FILE__, __LINE__)
78
#define SetDirection(value, comment) _SetDirection(value, comment, __func__, __FILE__, __LINE__)
@@ -11,6 +12,7 @@
1112
#define SetWeapon(value, comment) _SetWeapon(value, comment, __func__, __FILE__, __LINE__)
1213
#else
1314
#define Die(comment) _DieRaw()
15+
#define Emote(value, comment) _EmoteRaw()
1416
#define Aim(TargetX, TargetY, comment) _AimRaw(TargetX, TargetY)
1517
#define AimPos(TargetX, TargetY, comment) _AimPosRaw(TargetX, TargetY)
1618
#define SetDirection(value, comment) _SetDirectionRaw(value)

src/bots/undef_macros.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#undef Die
2+
#undef Emote
23
#undef Aim
34
#undef AimPos
45
#undef SetDirection

src/server/ddnet_callback_ctx.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ CGameContext *CDDNetCallbackCtx::GameServer()
99
return m_pGameServer;
1010
}
1111

12-
void CDDNetCallbackCtx::SendChat(int ClientId, int Team, const char *pText)
12+
void CDDNetCallbackCtx::SendChat(int Team, const char *pText)
1313
{
14+
int ClientId = GetCid();
1415
GameServer()->SendChat(ClientId, Team, pText);
1516
}
1617

17-
void CDDNetCallbackCtx::Die(int ClientId)
18+
void CDDNetCallbackCtx::Die()
1819
{
20+
int ClientId = GetCid();
1921
if(ClientId < 0 || ClientId >= MAX_CLIENTS)
2022
return;
2123

@@ -26,4 +28,8 @@ void CDDNetCallbackCtx::Die(int ClientId)
2628
pPlayer->KillCharacter(WEAPON_SELF);
2729
}
2830

31+
void CDDNetCallbackCtx::Emote(int Emote)
32+
{
33+
}
34+
2935
} // namespace TWBL

src/server/ddnet_callback_ctx.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ class CDDNetCallbackCtx : public CCallbackCtx
1313
CGameContext *m_pGameServer = nullptr;
1414
CGameContext *GameServer();
1515

16-
void SendChat(int ClientId, int Team, const char *pText) override;
17-
void Die(int ClientId) override;
16+
void SendChat(int Team, const char *pText) override;
17+
void Die() override;
18+
void Emote(int Emote) override;
1819
};
1920

2021
} // namespace TWBL

src/test/mock_callback_ctx.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33

44
#include "mock_callback_ctx.h"
55

6-
void CMockCallbackCtx::SendChat(int ClientId, int Team, const char *pText)
6+
void CMockCallbackCtx::SendChat(int Team, const char *pText)
77
{
8-
dbg_msg("chat", "%d:%d: %s", ClientId, Team, pText);
8+
dbg_msg("chat", "%d:%d: %s", GetCid(), Team, pText);
99
}
1010

11-
void CMockCallbackCtx::Die(int ClientId)
11+
void CMockCallbackCtx::Die()
12+
{
13+
dbg_msg("game", "killed cid=%d", GetCid());
14+
}
15+
16+
void CMockCallbackCtx::Emote(int Emote)
1217
{
13-
dbg_msg("game", "killed cid=%d", ClientId);
1418
}

src/test/mock_callback_ctx.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
class CMockCallbackCtx : public TWBL::CCallbackCtx
88
{
99
public:
10-
void SendChat(int ClientId, int Team, const char *pText) override;
11-
void Die(int ClientId) override;
10+
void SendChat(int Team, const char *pText) override;
11+
void Die() override;
12+
void Emote(int Emote) override;
1213
};
1314

1415
#endif

src/twbl/callback_ctx.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ class CCallbackCtx
77
{
88
public:
99
virtual ~CCallbackCtx() = default;
10-
virtual void SendChat(int ClientId, int Team, const char *pText) = 0;
11-
virtual void Die(int ClientId) = 0;
10+
virtual void SendChat(int Team, const char *pText) = 0;
11+
virtual void Die() = 0;
12+
virtual void Emote(int Emote) = 0;
13+
14+
int m_ClientId = 0;
15+
int GetCid() { return m_ClientId; }
1216
};
1317

1418
}; // namespace TWBL

src/twbl/types.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ class CServerBotStateOut
7878
const char *m_apSetWeaponFiles[TWBL_MAX_LOG_LEN];
7979
int m_aSetWeaponLines[TWBL_MAX_LOG_LEN];
8080

81+
const char *m_apEmoteComments[TWBL_MAX_LOG_LEN];
82+
const char *m_apEmoteFunctions[TWBL_MAX_LOG_LEN];
83+
const char *m_apEmoteFiles[TWBL_MAX_LOG_LEN];
84+
int m_aEmoteLines[TWBL_MAX_LOG_LEN];
85+
8186
CServerBotStateOut()
8287
{
8388
#ifdef TWBL_DEBUG
@@ -113,6 +118,11 @@ class CServerBotStateOut
113118
m_apSetWeaponFunctions[i] = "";
114119
m_apSetWeaponFiles[i] = "";
115120
m_aSetWeaponLines[i] = 0;
121+
122+
m_apEmoteComments[i] = "";
123+
m_apEmoteFunctions[i] = "";
124+
m_apEmoteFiles[i] = "";
125+
m_aEmoteLines[i] = 0;
116126
}
117127
#endif
118128
}

0 commit comments

Comments
 (0)