// Revision 22: hook shot origin
#define CSQC_REVISION 22
-const int AS_STRING = 1;
-const int AS_INT = 2;
-const int AS_FLOAT_TRUNCATED = 2;
-const int AS_FLOAT = 8;
-
REGISTER_NET_TEMP(TE_CSQC_PICTURE)
REGISTER_NET_TEMP(TE_CSQC_RACE)
REGISTER_NET_TEMP(TE_CSQC_TEAMNAGGER)
///////////////////////////
// csqc communication stuff
-const int CTF_STATE_ATTACK = 1;
-const int CTF_STATE_DEFEND = 2;
-const int CTF_STATE_COMMANDER = 3;
-
const int HUD_NORMAL = 0;
const int HUD_BUMBLEBEE_GUN = 25;
--- /dev/null
+#ifndef LIB_STATS_H
+#define LIB_STATS_H
+
+#include "registry.qh"
+#include "sort.qh"
+
+.int m_id;
+
+#if defined(CSQC)
+ /** Get all stats and store them as globals, access with `STAT(ID)` */
+ void stats_get() {}
+ #define STAT(...) EVAL(OVERLOAD(STAT, __VA_ARGS__))
+ #define STAT_1(id) STAT_2(id, NULL)
+ #define STAT_2(id, cl) (0, _STAT(id))
+
+ #define getstat_int(id) getstati(id, 0, 24)
+ #define getstat_bool(id) boolean(getstati(id))
+ #define getstat_float(id) getstatf(id)
+
+ #define _STAT(id) g_stat_##id
+ #define REGISTER_STAT(id, type) \
+ type _STAT(id); \
+ REGISTER(RegisterStats, STAT, Stats, id, m_id, new(stat)) \
+ { \
+ make_pure(this); \
+ } \
+ [[accumulate]] void stats_get() \
+ { \
+ _STAT(id) = getstat_##type(STAT_##id.m_id); \
+ }
+#elif defined(SVQC)
+ /** Add all registered stats, access with `STAT(ID, player)` or `.type stat = _STAT(ID); player.stat` */
+ void stats_add() {}
+ #define STAT(id, cl) (cl._STAT(id))
+
+ #define addstat_int(id, fld) addstat(id, AS_INT, fld)
+ #define addstat_bool(id, fld) addstat(id, AS_INT, fld)
+ #define addstat_float(id, fld) addstat(id, AS_FLOAT, fld)
+ const int AS_STRING = 1;
+ const int AS_INT = 2;
+ const int AS_FLOAT = 8;
+
+ #define _STAT(id) stat_##id
+ #define REGISTER_STAT(id, type) \
+ .type _STAT(id); \
+ REGISTER(RegisterStats, STAT, Stats, id, m_id, new(stat)) \
+ { \
+ make_pure(this); \
+ } \
+ [[accumulate]] void stats_add() \
+ { \
+ addstat_##type(STAT_##id.m_id, _STAT(id)); \
+ }
+#else
+ #define REGISTER_STAT(id, type)
+#endif
+
+const int STATS_ENGINE_RESERVE = 32;
+
+REGISTRY(Stats, BITS(8) - STATS_ENGINE_RESERVE)
+REGISTER_REGISTRY(RegisterStats)
+REGISTRY_SORT(Stats, 0)
+REGISTRY_CHECK(Stats)
+STATIC_INIT(RegisterStats_renumber)
+{
+ FOREACH(Stats, true, LAMBDA(it.m_id = STATS_ENGINE_RESERVE + i));
+}
+#ifdef SVQC
+STATIC_INIT(stats_add) { stats_add(); }
+#endif
+
+#endif
// bits 5- 9: team of key 2, or 0 for no such key, or 30 for dropped, or 31 for self
// bits 10-14: team of key 3, or 0 for no such key, or 30 for dropped, or 31 for self
// bits 15-19: team of key 4, or 0 for no such key, or 30 for dropped, or 31 for self
-.float kh_state;
+.float kh_state = _STAT(KH_KEYS);
.float siren_time; // time delay the siren
//.float stuff_time; // time delay to stuffcmd a cvar
kh_controller.model = "";
kh_controller.modelindex = 0;
- addstat(STAT_KH_KEYS, AS_INT, kh_state);
-
kh_ScoreRules(kh_teams);
}