Skip to content

Commit c088cd4

Browse files
authored
Merge branch 'master' into master
2 parents a7907f6 + a092936 commit c088cd4

File tree

13 files changed

+360
-130
lines changed

13 files changed

+360
-130
lines changed

src/kz/paint/kz_paint.cpp

Lines changed: 114 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ void KZPaintService::Reset()
1212
// Reset to default: red color and default size
1313
player->optionService->SetPreferenceInt("paintColor", 0xFF0000FF); // Red (RGBA format)
1414
player->optionService->SetPreferenceFloat("paintSize", DEFAULT_PAINT_SIZE);
15+
player->optionService->SetPreferenceBool("showAllPaint", false);
16+
17+
this->autoPaintEnabled = false;
18+
this->hasLastAutoPaintPosition = false;
19+
this->nextAutoPaintTime = 0.0;
1520
}
1621

1722
Color KZPaintService::GetColor() const
@@ -137,16 +142,56 @@ const char *KZPaintService::GetColorName() const
137142
return "Custom";
138143
}
139144

145+
bool KZPaintService::ShouldShowAllPaint() const
146+
{
147+
return this->player->optionService->GetPreferenceBool("showAllPaint", false);
148+
}
149+
150+
bool KZPaintService::IsAutoPaintEnabled() const
151+
{
152+
return this->autoPaintEnabled;
153+
}
154+
155+
void KZPaintService::OnGameFrame()
156+
{
157+
for (i32 i = 1; i <= MAXPLAYERS; i++)
158+
{
159+
KZPlayer *player = g_pKZPlayerManager->ToPlayer(i);
160+
if (!player || !player->paintService)
161+
{
162+
continue;
163+
}
164+
165+
player->paintService->TryAutoPaint();
166+
}
167+
}
168+
169+
void KZPaintService::ToggleAutoPaint()
170+
{
171+
this->autoPaintEnabled = !this->autoPaintEnabled;
172+
if (this->autoPaintEnabled)
173+
{
174+
this->hasLastAutoPaintPosition = false;
175+
this->nextAutoPaintTime = 0.0;
176+
}
177+
}
178+
179+
void KZPaintService::ToggleShowAllPaint()
180+
{
181+
bool newValue = !this->player->optionService->GetPreferenceBool("showAllPaint", false);
182+
this->player->optionService->SetPreferenceBool("showAllPaint", newValue);
183+
}
184+
140185
// Commands
141186

142187
#define KZ_PAINT_TRACE_DISTANCE 32768.0f
143188

144-
void KZPaintService::PlacePaint()
189+
bool KZPaintService::TracePaint(trace_t &tr) const
145190
{
146191
CCSPlayerPawnBase *pawn = static_cast<CCSPlayerPawnBase *>(this->player->GetCurrentPawn());
147192
if (!pawn)
148193
{
149-
return;
194+
return false;
150195
}
151196

152197
Vector origin;
@@ -157,23 +202,63 @@ void KZPaintService::PlacePaint()
157202
AngleVectors(angles, &forward);
158203
Vector endPos = origin + forward * KZ_PAINT_TRACE_DISTANCE;
159204

160-
trace_t tr;
161205
bbox_t bounds({vec3_origin, vec3_origin});
162206
CTraceFilterPlayerMovementCS filter(pawn);
163207
filter.EnableInteractsExcludeLayer(LAYER_INDEX_CONTENTS_PLAYER_CLIP);
164208
filter.EnableInteractsExcludeLayer(LAYER_INDEX_CONTENTS_PLAYER);
165209
g_pKZUtils->TracePlayerBBox(origin, endPos, bounds, &filter, tr);
166210

167-
if (!tr.DidHit())
211+
return tr.DidHit();
212+
}
213+
214+
void KZPaintService::PlacePaint()
215+
{
216+
trace_t tr;
217+
if (!this->TracePaint(tr))
168218
{
169219
return;
170220
}
221+
171222
CGlobalSymbol paintDecal = MakeGlobalSymbol("paint");
172223
this->pendingPaint = true;
173224
g_pKZUtils->DecalTrace(&tr, &paintDecal, 0.0f);
174225
this->pendingPaint = false;
175226
}
176227

228+
void KZPaintService::TryAutoPaint()
229+
{
230+
if (!this->autoPaintEnabled)
231+
{
232+
return;
233+
}
234+
235+
f64 curTime = g_pKZUtils->GetGlobals()->curtime;
236+
if (curTime < this->nextAutoPaintTime)
237+
{
238+
return;
239+
}
240+
this->nextAutoPaintTime = curTime + 0.05;
241+
242+
trace_t tr;
243+
if (!this->TracePaint(tr))
244+
{
245+
return;
246+
}
247+
248+
if (this->hasLastAutoPaintPosition && (tr.m_vEndPos - this->lastAutoPaintPosition).LengthSqr() < 1.0f)
249+
{
250+
return;
251+
}
252+
253+
CGlobalSymbol paintDecal = MakeGlobalSymbol("paint");
254+
this->pendingPaint = true;
255+
g_pKZUtils->DecalTrace(&tr, &paintDecal, 0.0f);
256+
this->pendingPaint = false;
257+
258+
this->lastAutoPaintPosition = tr.m_vEndPos;
259+
this->hasLastAutoPaintPosition = true;
260+
}
261+
177262
SCMD(kz_paint, SCFL_MISC)
178263
{
179264
KZPlayer *player = g_pKZPlayerManager->ToPlayer(controller);
@@ -191,14 +276,14 @@ SCMD(kz_paintcolor, SCFL_PREFERENCE | SCFL_MISC)
191276
player->languageService->PrintChat(true, false, "Current Paint Color", player->paintService->GetColorName(),
192277
player->paintService->GetColor().r(), player->paintService->GetColor().g(),
193278
player->paintService->GetColor().b());
194-
return MRES_HANDLED;
279+
return MRES_SUPERCEDE;
195280
}
196281

197282
// Check for predefined colors
198283
if (player->paintService->SetColor(args->Arg(1)))
199284
{
200285
player->languageService->PrintChat(true, false, "Paint Color Set", player->paintService->GetColorName());
201-
return MRES_HANDLED;
286+
return MRES_SUPERCEDE;
202287
}
203288

204289
// Try to parse as RGB values
@@ -216,11 +301,11 @@ SCMD(kz_paintcolor, SCFL_PREFERENCE | SCFL_MISC)
216301

217302
player->paintService->SetColorRGB(r, g, b, a);
218303
player->languageService->PrintChat(true, false, "Paint Color RGB Set", r, g, b, a);
219-
return MRES_HANDLED;
304+
return MRES_SUPERCEDE;
220305
}
221306

222307
player->languageService->PrintChat(true, false, "Paint Color Command Usage");
223-
return MRES_HANDLED;
308+
return MRES_SUPERCEDE;
224309
}
225310

226311
SCMD(kz_paintsize, SCFL_PREFERENCE | SCFL_MISC)
@@ -231,18 +316,36 @@ SCMD(kz_paintsize, SCFL_PREFERENCE | SCFL_MISC)
231316
{
232317
player->languageService->PrintChat(true, false, "Paint Size Command Usage");
233318
player->languageService->PrintChat(true, false, "Current Paint Size", player->paintService->GetSize());
234-
return MRES_HANDLED;
319+
return MRES_SUPERCEDE;
235320
}
236321

237322
f32 value = (f32)atof(args->Arg(1));
238323
if (player->paintService->SetSize(value))
239324
{
240325
player->languageService->PrintChat(true, false, "Paint Size Set", player->paintService->GetSize());
241-
return MRES_HANDLED;
326+
return MRES_SUPERCEDE;
242327
}
243328

244329
player->languageService->PrintChat(true, false, "Paint Size Command Usage");
245-
return MRES_HANDLED;
330+
return MRES_SUPERCEDE;
331+
}
332+
333+
SCMD(kz_togglepaint, SCFL_MISC | SCFL_PREFERENCE)
334+
{
335+
KZPlayer *player = g_pKZPlayerManager->ToPlayer(controller);
336+
player->paintService->ToggleAutoPaint();
337+
338+
player->languageService->PrintChat(true, false, player->paintService->IsAutoPaintEnabled() ? "Paint Toggle Enabled" : "Paint Toggle Disabled");
339+
return MRES_SUPERCEDE;
340+
}
341+
342+
SCMD(kz_showpaint, SCFL_MISC | SCFL_PREFERENCE)
343+
{
344+
KZPlayer *player = g_pKZPlayerManager->ToPlayer(controller);
345+
player->paintService->ToggleShowAllPaint();
346+
347+
player->languageService->PrintChat(true, false, player->paintService->ShouldShowAllPaint() ? "Show Paint Enabled" : "Show Paint Disabled");
348+
return MRES_SUPERCEDE;
246349
}
247350

248351
SCMD(kz_cleardecals, SCFL_MISC)

src/kz/paint/kz_paint.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,21 @@ class KZPaintService : public KZBaseService
3939
Color GetColor() const;
4040
f32 GetSize() const;
4141
const char *GetColorName() const;
42+
bool ShouldShowAllPaint() const;
43+
bool IsAutoPaintEnabled() const;
44+
static void OnGameFrame();
4245

4346
void PlacePaint();
47+
void ToggleAutoPaint();
48+
void ToggleShowAllPaint();
4449

4550
bool pendingPaint = false;
51+
bool autoPaintEnabled = false;
52+
bool hasLastAutoPaintPosition = false;
53+
f64 nextAutoPaintTime = 0.0;
54+
Vector lastAutoPaintPosition = vec3_origin;
55+
56+
private:
57+
bool TracePaint(trace_t &tr) const;
58+
void TryAutoPaint();
4659
};

src/kz/quiet/kz_quiet.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ void KZ::quiet::OnPostEvent(INetworkMessageInternal *pEvent, const CNetMessage *
149149
return;
150150
}
151151

152-
// Find the player who initiated this paint and restrict delivery to only them.
152+
u64 currentRecipients = *(const u64 *)clients;
153+
154+
// Find the player who initiated this paint.
153155
for (i32 i = 1; i <= MAXPLAYERS; i++)
154156
{
155157
KZPlayer *painter = g_pKZPlayerManager->ToPlayer(i);
@@ -158,11 +160,33 @@ void KZ::quiet::OnPostEvent(INetworkMessageInternal *pEvent, const CNetMessage *
158160
continue;
159161
}
160162

161-
*(uint64 *)clients = 1ull << (i - 1);
163+
u64 paintRecipients = 0;
164+
for (i32 recipientPlayerIndex = 1; recipientPlayerIndex <= MAXPLAYERS; recipientPlayerIndex++)
165+
{
166+
u64 recipientBit = 1ull << (recipientPlayerIndex - 1);
167+
if ((currentRecipients & recipientBit) == 0)
168+
{
169+
continue;
170+
}
171+
172+
if (recipientPlayerIndex == i)
173+
{
174+
paintRecipients |= recipientBit;
175+
continue;
176+
}
177+
178+
KZPlayer *recipient = g_pKZPlayerManager->ToPlayer(recipientPlayerIndex);
179+
if (recipient && recipient->paintService && recipient->paintService->ShouldShowAllPaint())
180+
{
181+
paintRecipients |= recipientBit;
182+
}
183+
}
184+
185+
*(uint64 *)clients = paintRecipients;
162186

163187
Color color = painter->paintService->GetColor();
164-
// Game expects ARGB; internal storage and user input are RGBA.
165-
u32 colorPacked = ((u32)color.a() << 24) | ((u32)color.r() << 16) | ((u32)color.g() << 8) | (u32)color.b();
188+
// Game expects ABGR; internal storage and user input are RGBA.
189+
u32 colorPacked = ((u32)color.a() << 24) | ((u32)color.b() << 16) | ((u32)color.g() << 8) | (u32)color.r();
166190
msg->set_color(colorPacked);
167191
msg->set_size_override(painter->paintService->GetSize());
168192
return;

0 commit comments

Comments
 (0)