From fe3d08fb798d461f718b1cce083de57064f09534 Mon Sep 17 00:00:00 2001 From: otta8634 Date: Wed, 8 Jan 2025 18:13:39 +0800 Subject: [PATCH] Slightly refactor mutators code These changes allow mutators to be properly shown in the guide. Renamed .m_name to .mutatorname, and added (new) .m_name which would be displayed in the guide. Allowed use of classes other than Mutator in the Mutators registry, so that m_name, m_icon, and m_color can be stored in such class and then displayed in the guide. Also removed itemstime and waypointsprites mutators from the guide. --- qcsrc/common/mutators/base.qh | 24 +++++++++++++++---- .../mutators/mutator/itemstime/itemstime.qc | 3 +-- .../mutator/waypoints/waypointsprites.qc | 3 +-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/qcsrc/common/mutators/base.qh b/qcsrc/common/mutators/base.qh index 2b4d3e34cb..def5e367ee 100644 --- a/qcsrc/common/mutators/base.qh +++ b/qcsrc/common/mutators/base.qh @@ -155,11 +155,21 @@ USING(mutatorfunc_t, bool(int)); CLASS(Mutator, Object) ATTRIB(Mutator, m_id, int, 0); ATTRIB(Mutator, m_name, string); + ATTRIB(Mutator, m_color, vector, '1 1 1'); + ATTRIB(Mutator, m_icon, string); + ATTRIB(Mutator, mutatorname, string); ATTRIB(Mutator, mutatorfunc, mutatorfunc_t); ATTRIB(Mutator, mutatorcheck, bool()); + METHOD(Mutator, describe, string(entity this)) { + TC(Mutator, this); + return SUPER(Mutator).describe(this); + } + METHOD(Mutator, display, void(entity this, void(string name, string icon) returns)) { + returns(this.m_name, this.m_icon); + } CONSTRUCTOR(Mutator, string _name, mutatorfunc_t func) { CONSTRUCT(Mutator); - this.m_name = _name; + this.mutatorname = _name; this.mutatorfunc = func; } ENDCLASS(Mutator) @@ -226,7 +236,7 @@ bool Mutator_Add(Mutator mut) mutatorfunc_t func = mut.mutatorfunc; if (!func(MUTATOR_ADDING)) { // good - if (mutator_log) LOG_TRACEF("Mutator: added %s", mut.m_name); + if (mutator_log) LOG_TRACEF("Mutator: added %s", mut.mutatorname); #ifdef SVQC Net_LinkEntity(mut, false, 0, Mutator_SendEntity); #endif @@ -254,23 +264,27 @@ void Mutator_Remove(Mutator mut) // baaaaad error("Mutator_Remove: removing mutator failed"); } - if (mutator_log) LOG_TRACEF("Mutator: removed %s", mut.m_name); + if (mutator_log) LOG_TRACEF("Mutator: removed %s", mut.mutatorname); #ifdef SVQC Net_UnlinkEntity(mut); #endif } -#define REGISTER_MUTATOR(id, dependence) \ +#define _REGISTER_MUTATOR(id, dependence, cname) \ bool MUTATORFUNC_##id##_hooks(int mode) { return = false; } \ bool MUTATORFUNC_##id(int mode) { \ return = false; \ bool ret = MUTATORFUNC_##id##_hooks(mode); if (ret) return ret; \ } \ bool MUTATOR_##id##_check() { return dependence; } \ - REGISTER(Mutators, MUTATOR, id, m_id, NEW(Mutator, #id, MUTATORFUNC_##id)) \ + REGISTER(Mutators, MUTATOR, id, m_id, NEW(cname, #id, MUTATORFUNC_##id)) \ { this.mutatorcheck = MUTATOR_##id##_check; } \ ACCUMULATE bool MUTATORFUNC_##id(int mode) +#define REGISTER_MUTATOR(...) EVAL(OVERLOAD(REGISTER_MUTATOR, __VA_ARGS__)) +#define REGISTER_MUTATOR_2(id, dependence) _REGISTER_MUTATOR(id, dependence, Mutator) +#define REGISTER_MUTATOR_3(id, dependence, cname) _REGISTER_MUTATOR(id, dependence, cname) + STATIC_INIT(Mutators) { RegisterHooks(); RegisterCallbacks(); diff --git a/qcsrc/common/mutators/mutator/itemstime/itemstime.qc b/qcsrc/common/mutators/mutator/itemstime/itemstime.qc index 5aa59bffc3..1c96e1b6e3 100644 --- a/qcsrc/common/mutators/mutator/itemstime/itemstime.qc +++ b/qcsrc/common/mutators/mutator/itemstime/itemstime.qc @@ -1,8 +1,7 @@ #include "itemstime.qh" -REGISTER_MUTATOR(itemstime, true); - #ifdef GAMEQC +REGISTER_MUTATOR(itemstime, true); REGISTER_NET_TEMP(itemstime) #endif diff --git a/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc b/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc index f3172c7110..f79dad44b6 100644 --- a/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc +++ b/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc @@ -1,8 +1,7 @@ #include "waypointsprites.qh" -REGISTER_MUTATOR(waypointsprites, true); - #ifdef GAMEQC +REGISTER_MUTATOR(waypointsprites, true); REGISTER_NET_LINKED(waypointsprites) #endif -- 2.39.5