]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Objectify gametypes
authorTimePath <andrew.hardaker1995@gmail.com>
Fri, 14 Aug 2015 00:11:36 +0000 (10:11 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Fri, 14 Aug 2015 00:11:36 +0000 (10:11 +1000)
qcsrc/client/main.qc
qcsrc/common/items/all.qh
qcsrc/common/mapinfo.qc
qcsrc/common/mapinfo.qh
qcsrc/common/monsters/all.qh
qcsrc/common/nades.qh
qcsrc/common/registry.qh
qcsrc/menu/menu.qc
qcsrc/server/g_world.qc

index a544e4fbd5ba3cd3e1ee3d3afc042602911047fe..25cbf8e881dd8793dad78ed883b24e1fe84a3c0d 100644 (file)
@@ -142,8 +142,6 @@ void CSQC_Init(void)
        // needs to be done so early because of the constants they create
        static_init();
        CALL_ACCUMULATED_FUNCTION(RegisterWeapons);
-       CALL_ACCUMULATED_FUNCTION(RegisterMonsters);
-       CALL_ACCUMULATED_FUNCTION(RegisterGametypes);
        CALL_ACCUMULATED_FUNCTION(RegisterNotifications);
        CALL_ACCUMULATED_FUNCTION(RegisterDeathtypes);
        CALL_ACCUMULATED_FUNCTION(RegisterHUD_Panels);
index c42139e25f6a1b4f4c12cba0e350e8ec2daac506..3bbd1946f3ca7bd6191767f9eb4f9b06c340d782 100644 (file)
@@ -5,7 +5,7 @@
 
 void RegisterItems();
 const int MAX_ITEMS = 24;
-entity ITEMS[MAX_ITEMS];
+entity ITEMS[MAX_ITEMS], ITEMS_first, ITEMS_last;
 int ITEM_COUNT;
 /** If you register a new item, make sure to add it to all.inc */
 #define REGISTER_ITEM(id, class) REGISTER(RegisterItems, ITEM, ITEMS, ITEM_COUNT, id, class, m_id)
index 55165a12c2efa02fe371e683c49b0a89f18e5d15..b8622fd321b5f868617220d431ace32b44dd7daa 100644 (file)
@@ -603,7 +603,7 @@ void _MapInfo_Map_ApplyGametype(string s, int pWantedType, int pThisType, int lo
 string _MapInfo_GetDefaultEx(float t)
 {
        entity e;
-       for(e = MapInfo_Type_first; e; e = e.enemy)
+       for(e = MAPINFO_TYPES_first; e; e = e.enemy)
                if(t == e.items)
                        return e.model2;
        return "";
@@ -612,7 +612,7 @@ string _MapInfo_GetDefaultEx(float t)
 float _MapInfo_GetTeamPlayBool(float t)
 {
        entity e;
-       for(e = MapInfo_Type_first; e; e = e.enemy)
+       for(e = MAPINFO_TYPES_first; e; e = e.enemy)
                if(t == e.items)
                        return e.team;
        return false;
@@ -754,7 +754,7 @@ float MapInfo_Type_FromString(string t)
        }
        if(t == "all")
                return MAPINFO_TYPE_ALL;
-       for(e = MapInfo_Type_first; e; e = e.enemy)
+       for(e = MAPINFO_TYPES_first; e; e = e.enemy)
                if(t == e.mdl)
                        return e.items;
        return 0;
@@ -763,7 +763,7 @@ float MapInfo_Type_FromString(string t)
 string MapInfo_Type_Description(float t)
 {
        entity e;
-       for(e = MapInfo_Type_first; e; e = e.enemy)
+       for(e = MAPINFO_TYPES_first; e; e = e.enemy)
                if(t == e.items)
                        return e.gametype_description;
        return "";
@@ -774,7 +774,7 @@ string MapInfo_Type_ToString(float t)
        entity e;
        if(t == MAPINFO_TYPE_ALL)
                return "all";
-       for(e = MapInfo_Type_first; e; e = e.enemy)
+       for(e = MAPINFO_TYPES_first; e; e = e.enemy)
                if(t == e.items)
                        return e.mdl;
        return "";
@@ -783,7 +783,7 @@ string MapInfo_Type_ToString(float t)
 string MapInfo_Type_ToText(float t)
 {
        entity e;
-       for(e = MapInfo_Type_first; e; e = e.enemy)
+       for(e = MAPINFO_TYPES_first; e; e = e.enemy)
                if(t == e.items)
                        return e.message;
        /* xgettext:no-c-format */
@@ -1285,7 +1285,7 @@ int MapInfo_CurrentGametype()
 {
        entity e;
        int prev = cvar("gamecfg");
-       for(e = MapInfo_Type_first; e; e = e.enemy)
+       for(e = MAPINFO_TYPES_first; e; e = e.enemy)
                if(cvar(e.netname))
                        if(prev != e.items)
                                return e.items;
@@ -1315,7 +1315,7 @@ float MapInfo_CheckMap(string s) // returns 0 if the map can't be played with th
 
 void MapInfo_SwitchGameType(int t)
 {
-       for (entity e = MapInfo_Type_first; e; e = e.enemy) {
+       for (entity e = MAPINFO_TYPES_first; e; e = e.enemy) {
                cvar_set(e.netname, (t == e.items) ? "1" : "0");
        }
 }
index 3038cce60e70a0ebe8380f2c47f350a779a151ba..8d10b02ab5519a1da69a8f5644cd39b2c37ae511 100644 (file)
@@ -3,44 +3,52 @@
 
 #include "util.qh"
 
+CLASS(Gametype, Object)
+    ATTRIB(Gametype, m_id, int, 0)
+    /** game type ID */
+    ATTRIB(Gametype, items, int, 0)
+    /** game type name as in cvar (with g_ prefix) */
+    ATTRIB(Gametype, netname, string, string_null)
+    /** game type short name */
+    ATTRIB(Gametype, mdl, string, string_null)
+    /** human readable name */
+    ATTRIB(Gametype, message, string, string_null)
+    /** does this gametype support teamplay? */
+    ATTRIB(Gametype, team, bool, false)
+    /** game type defaults */
+    ATTRIB(Gametype, model2, string, string_null)
+    /** game type description */
+    ATTRIB(Gametype, gametype_description, string, string_null)
+    CONSTRUCTOR(Gametype, string hname, string sname, string g_name, bool gteamplay, string defaults, string gdescription)
+    {
+        this.netname = g_name;
+        this.mdl = sname;
+        this.message = hname;
+        this.team = gteamplay;
+        this.model2 = defaults;
+        this.gametype_description = gdescription;
+        return this;
+    }
+ENDCLASS(Gametype)
+
+void RegisterGametypes();
+const int MAX_MAPINFO_TYPES = 24;
+entity MAPINFO_TYPES[MAX_MAPINFO_TYPES], MAPINFO_TYPES_first, MAPINFO_TYPES_last;
+int MAPINFO_TYPE_COUNT;
 int MAPINFO_TYPE_ALL;
-entity MapInfo_Type_first;
-entity MapInfo_Type_last;
-.entity enemy; // internal next pointer
-
-.int items; // game type ID
-.string netname; // game type name as in cvar (with g_ prefix)
-.string mdl; // game type short name
-.string message; // human readable name
-.int team; // does this gametype support teamplay?
-.string model2; // game type defaults
-.string gametype_description; // game type description
-
-#define REGISTER_GAMETYPE(hname,sname,g_name,NAME,gteamplay,defaults,gdescription) \
-       int MAPINFO_TYPE_##NAME; \
-       entity MapInfo_Type##g_name; \
-       void RegisterGametypes_##g_name() \
-       { \
-               MAPINFO_TYPE_##NAME = MAPINFO_TYPE_ALL + 1; \
-               MAPINFO_TYPE_ALL |= MAPINFO_TYPE_##NAME; \
-               MapInfo_Type##g_name = spawn(); \
-               MapInfo_Type##g_name.items = MAPINFO_TYPE_##NAME; \
-               MapInfo_Type##g_name.netname = #g_name; \
-               MapInfo_Type##g_name.mdl = #sname; \
-               MapInfo_Type##g_name.message = hname; \
-               MapInfo_Type##g_name.team = gteamplay; \
-               MapInfo_Type##g_name.model2 = defaults; \
-               MapInfo_Type##g_name.gametype_description = gdescription; \
-               if(!MapInfo_Type_first) \
-                       MapInfo_Type_first = MapInfo_Type##g_name; \
-               if(MapInfo_Type_last) \
-                       MapInfo_Type_last.enemy = MapInfo_Type##g_name; \
-               MapInfo_Type_last = MapInfo_Type##g_name; \
-       } \
-       ACCUMULATE_FUNCTION(RegisterGametypes, RegisterGametypes_##g_name)
+
+#define REGISTER_GAMETYPE(hname, sname, g_name, NAME, gteamplay, defaults, gdescription)                    \
+    int MAPINFO_TYPE_##NAME;                                                                                \
+    REGISTER(RegisterGametypes, MAPINFO_TYPE, MAPINFO_TYPES, MAPINFO_TYPE_COUNT, g_name, Gametype, m_id) {  \
+        CONSTRUCT(Gametype, hname, #sname, #g_name, gteamplay, defaults, gdescription);                     \
+        /* same as `1 << m_id` */                                                                           \
+        MAPINFO_TYPE_##NAME = MAPINFO_TYPE_ALL + 1; MAPINFO_TYPE_ALL |= MAPINFO_TYPE_##NAME;                \
+        this.items = MAPINFO_TYPE_##NAME;                                                                   \
+    }
+REGISTER_REGISTRY(RegisterGametypes)
 
 #define IS_GAMETYPE(NAME) \
-       (MapInfo_LoadedGametype == MAPINFO_TYPE_##NAME)
+    (MapInfo_LoadedGametype == MAPINFO_TYPE_##NAME)
 
 REGISTER_GAMETYPE(_("Deathmatch"),dm,g_dm,DEATHMATCH,false,"timelimit=20 pointlimit=30 leadlimit=0",_("Kill all enemies"));
 #define g_dm IS_GAMETYPE(DEATHMATCH)
index 30de42cd9f1051bfb550c140ca0ee96db1aa0848..38a83a0f1685801583b3543351eabfe042714a9b 100644 (file)
@@ -5,7 +5,7 @@
 
 void RegisterMonsters();
 const int MON_MAXCOUNT = 24;
-entity monster_info[MON_MAXCOUNT];
+entity monster_info[MON_MAXCOUNT], monster_info_first, monster_info_last;
 entity get_monsterinfo(float id);
 int MON_COUNT;
 const int MON_FIRST = 1;
@@ -24,6 +24,7 @@ const int MON_FIRST = 1;
         this.model = strzone(strcat("models/monsters/", modelname));    \
     }                                                                   \
     REGISTER_INIT(MON, id)
+REGISTER_REGISTRY(RegisterMonsters)
 
 #include "../util.qh"
 
index 75495abca694da6cc4bed39cc64d8cd02dd77f46..7b50bcc563b88fe0bb1f6f10d8113fefeb88232a 100644 (file)
@@ -25,7 +25,7 @@ const int PROJECTILE_NADE_MONSTER_BURN = 83;
 
 void RegisterNades();
 const int NADES_MAX = 8;
-entity NADES[NADES_MAX];
+entity NADES[NADES_MAX], NADES_first, NADES_last;
 int NADES_COUNT;
 #define REGISTER_NADE(id) REGISTER(RegisterNades, NADE_TYPE, NADES, NADES_COUNT, id, Nade, m_id)
 REGISTER_REGISTRY(RegisterNades)
index 0087c1bf71b77b69cf3513fcb0da62aa42017fed..3ce8c471e5442019462b7266fda6d347668b5a9e 100644 (file)
@@ -8,11 +8,15 @@
 #define REGISTER(initfunc, ns, array, counter, id, class, fld)  \
     entity ns##_##id;                                           \
     REGISTER_INIT(ns, id) { }                                   \
+    .entity enemy; /* internal next pointer */                  \
     void Register_##ns##_##id() {                               \
         entity this = NEW(class);                               \
         ns##_##id = this;                                       \
         this.fld = counter;                                     \
         array[counter++] = this;                                \
+        if (!array##_first)    array##_first = this;            \
+        if ( array##_last)     array##_last.enemy = this;       \
+        array##_last = this;                                    \
         Register_##ns##_##id##_init(this);                      \
     }                                                           \
     ACCUMULATE_FUNCTION(initfunc, Register_##ns##_##id)         \
index b0146349f756adbc24ff3842cdae1e345de1cc20..b2a85093c6ecc21a5258692ac5df1db8fa1c4ccc 100644 (file)
@@ -82,7 +82,6 @@ void m_init()
        // needs to be done so early because of the constants they create
        static_init();
        CALL_ACCUMULATED_FUNCTION(RegisterWeapons);
-       CALL_ACCUMULATED_FUNCTION(RegisterGametypes);
 
        RegisterSLCategories();
 
index 1c88f0472fe97d21a2b4f4ee437dfb95b2d6ef8a..9f9f1f246536f48b75570a384558c5d808e7aae6 100644 (file)
@@ -561,8 +561,6 @@ void spawnfunc___init_dedicated_server(void)
        // needs to be done so early because of the constants they create
        static_init();
        CALL_ACCUMULATED_FUNCTION(RegisterWeapons);
-       CALL_ACCUMULATED_FUNCTION(RegisterMonsters);
-       CALL_ACCUMULATED_FUNCTION(RegisterGametypes);
        CALL_ACCUMULATED_FUNCTION(RegisterNotifications);
        CALL_ACCUMULATED_FUNCTION(RegisterDeathtypes);
        CALL_ACCUMULATED_FUNCTION(RegisterBuffs);
@@ -612,8 +610,6 @@ void spawnfunc_worldspawn (void)
        // needs to be done so early because of the constants they create
        static_init();
        CALL_ACCUMULATED_FUNCTION(RegisterWeapons);
-       CALL_ACCUMULATED_FUNCTION(RegisterMonsters);
-       CALL_ACCUMULATED_FUNCTION(RegisterGametypes);
        CALL_ACCUMULATED_FUNCTION(RegisterNotifications);
        CALL_ACCUMULATED_FUNCTION(RegisterDeathtypes);
        CALL_ACCUMULATED_FUNCTION(RegisterBuffs);