]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
remove lots of game type listings
authorRudolf Polzer <divverent@xonotic.org>
Thu, 29 Dec 2011 10:27:06 +0000 (11:27 +0100)
committerRudolf Polzer <divverent@xonotic.org>
Thu, 29 Dec 2011 10:27:06 +0000 (11:27 +0100)
qcsrc/client/Main.qc
qcsrc/common/mapinfo.qc
qcsrc/common/mapinfo.qh
qcsrc/menu/menu.qc
qcsrc/server/g_world.qc

index cde4c5cbe85226c89947937db40dc01e7f28c9a9..931e7ea2459b85ed5661b07e20d3e1f0100b036c 100644 (file)
@@ -155,7 +155,9 @@ void CSQC_Init(void)
 
        GetTeam(COLOR_SPECTATOR, true); // add specs first
 
+       // needs to be done so early because of the constants they create
        RegisterWeapons();
+       RegisterGametypes();
 
        WaypointSprite_Load();
 
index 49a7e2978be835af583fd0cc248f788594ac416b..270a30147724bf61b66e7c8893897c24d52b7803 100644 (file)
@@ -663,46 +663,24 @@ void _MapInfo_Map_ApplyGametypeEx(string s, float pWantedType, float pThisType)
 
 float MapInfo_Type_FromString(string t)
 {
-       if     (t == "dm")      return MAPINFO_TYPE_DEATHMATCH;
-       else if(t == "tdm")     return MAPINFO_TYPE_TEAM_DEATHMATCH;
-       else if(t == "dom")     return MAPINFO_TYPE_DOMINATION;
-       else if(t == "ctf")     return MAPINFO_TYPE_CTF;
-       else if(t == "rune")    return MAPINFO_TYPE_RUNEMATCH;
-       else if(t == "lms")     return MAPINFO_TYPE_LMS;
-       else if(t == "arena")   return MAPINFO_TYPE_ARENA;
-       else if(t == "ca")      return MAPINFO_TYPE_CA;
-       else if(t == "kh")      return MAPINFO_TYPE_KEYHUNT;
-       else if(t == "as")      return MAPINFO_TYPE_ASSAULT;
-       else if(t == "ons")     return MAPINFO_TYPE_ONSLAUGHT;
-       else if(t == "rc")      return MAPINFO_TYPE_RACE;
-       else if(t == "nexball") return MAPINFO_TYPE_NEXBALL;
-       else if(t == "cts")     return MAPINFO_TYPE_CTS;
-       else if(t == "freezetag")       return MAPINFO_TYPE_FREEZETAG;
-       else if(t == "keepaway") return MAPINFO_TYPE_KEEPAWAY;
-       else if(t == "all")     return MAPINFO_TYPE_ALL;
-       else                    return 0;
+       entity e;
+       if(t == "all")
+               return MAPINFO_TYPE_ALL;
+       for(e = MapInfo_Type_first; e; e = e.enemy)
+               if(t == e.model2)
+                       return e.weapons;
+       return 0;
 }
 
 string MapInfo_Type_ToString(float t)
 {
-       if     (t == MAPINFO_TYPE_DEATHMATCH)      return "dm";
-       else if(t == MAPINFO_TYPE_TEAM_DEATHMATCH) return "tdm";
-       else if(t == MAPINFO_TYPE_DOMINATION)      return "dom";
-       else if(t == MAPINFO_TYPE_CTF)             return "ctf";
-       else if(t == MAPINFO_TYPE_RUNEMATCH)       return "rune";
-       else if(t == MAPINFO_TYPE_LMS)             return "lms";
-       else if(t == MAPINFO_TYPE_ARENA)           return "arena";
-       else if(t == MAPINFO_TYPE_CA)              return "ca";
-       else if(t == MAPINFO_TYPE_KEYHUNT)         return "kh";
-       else if(t == MAPINFO_TYPE_ASSAULT)         return "as";
-       else if(t == MAPINFO_TYPE_ONSLAUGHT)       return "ons";
-       else if(t == MAPINFO_TYPE_RACE)            return "rc";
-       else if(t == MAPINFO_TYPE_NEXBALL)         return "nexball";
-       else if(t == MAPINFO_TYPE_CTS)             return "cts";
-       else if(t == MAPINFO_TYPE_FREEZETAG)       return "freezetag";
-       else if(t == MAPINFO_TYPE_KEEPAWAY)        return "keepaway";
-       else if(t == MAPINFO_TYPE_ALL)             return "all";
-       else                                       return "";
+       entity e;
+       if(t == MAPINFO_TYPE_ALL)     
+               return "all";
+       for(e = MapInfo_Type_first; e; e = e.enemy)
+               if(t == e.weapons)
+                       return e.model2;
+       return "";
 }
 
 void _MapInfo_Parse_Settemp(string pFilename, string acl, float type, string s, float recurse)
@@ -1193,59 +1171,14 @@ float MapInfo_CurrentFeatures()
 float MapInfo_CurrentGametype()
 {
        float prev, i;
+       entity e;
        prev = cvar("gamecfg");
-       for(i = 0; i < 2; ++i)
-       {
-               if(cvar("g_dm"))
-                       if(prev != MAPINFO_TYPE_DEATHMATCH)
-                               return MAPINFO_TYPE_DEATHMATCH;
-               if(cvar("g_domination"))
-                       if(prev != MAPINFO_TYPE_DOMINATION)
-                               return MAPINFO_TYPE_DOMINATION;
-               if(cvar("g_ctf"))
-                       if(prev != MAPINFO_TYPE_CTF)
-                               return MAPINFO_TYPE_CTF;
-               if(cvar("g_runematch"))
-                       if(prev != MAPINFO_TYPE_RUNEMATCH)
-                               return MAPINFO_TYPE_RUNEMATCH;
-               if(cvar("g_tdm"))
-                       if(prev != MAPINFO_TYPE_TEAM_DEATHMATCH)
-                               return MAPINFO_TYPE_TEAM_DEATHMATCH;
-               if(cvar("g_assault"))
-                       if(prev != MAPINFO_TYPE_ASSAULT)
-                               return MAPINFO_TYPE_ASSAULT;
-               if(cvar("g_lms"))
-                       if(prev != MAPINFO_TYPE_LMS)
-                               return MAPINFO_TYPE_LMS;
-               if(cvar("g_arena"))
-                       if(prev != MAPINFO_TYPE_ARENA)
-                               return MAPINFO_TYPE_ARENA;
-               if(cvar("g_ca"))
-                       if(prev != MAPINFO_TYPE_CA)
-                               return MAPINFO_TYPE_CA; 
-               if(cvar("g_keyhunt"))
-                       if(prev != MAPINFO_TYPE_KEYHUNT)
-                               return MAPINFO_TYPE_KEYHUNT;
-               if(cvar("g_onslaught"))
-                       if(prev != MAPINFO_TYPE_ONSLAUGHT)
-                               return MAPINFO_TYPE_ONSLAUGHT;
-               if(cvar("g_race"))
-                       if(prev != MAPINFO_TYPE_RACE)
-                               return MAPINFO_TYPE_RACE;
-               if(cvar("g_nexball"))
-                       if(prev != MAPINFO_TYPE_NEXBALL)
-                               return MAPINFO_TYPE_NEXBALL;
-               if(cvar("g_cts"))
-                       if(prev != MAPINFO_TYPE_CTS)
-                               return MAPINFO_TYPE_CTS;
-               if(cvar("g_freezetag"))
-                       if(prev != MAPINFO_TYPE_FREEZETAG)
-                               return MAPINFO_TYPE_FREEZETAG;
-               if(cvar("g_keepaway"))
-                       if(prev != MAPINFO_TYPE_KEEPAWAY)
-                               return MAPINFO_TYPE_KEEPAWAY;
-               prev = -1;
-       }
+       for(e = MapInfo_Type_first; e; e = e.enemy)
+               if(cvar(e.mdl))
+                       if(prev != e.weapons)
+                               return e.weapons;
+       if(prev)
+               return prev;
        return MAPINFO_TYPE_DEATHMATCH;
 }
 
@@ -1270,46 +1203,18 @@ float MapInfo_CheckMap(string s) // returns 0 if the map can't be played with th
 
 string MapInfo_GetGameTypeCvar(float t)
 {
-       switch(t)
-       {
-               case MAPINFO_TYPE_DEATHMATCH: return "g_dm";
-               case MAPINFO_TYPE_TEAM_DEATHMATCH: return "g_tdm";
-               case MAPINFO_TYPE_DOMINATION: return "g_domination";
-               case MAPINFO_TYPE_CTF: return "g_ctf";
-               case MAPINFO_TYPE_RUNEMATCH: return "g_runematch";
-               case MAPINFO_TYPE_LMS: return "g_lms";
-               case MAPINFO_TYPE_ARENA: return "g_arena";
-               case MAPINFO_TYPE_CA: return "g_ca";
-               case MAPINFO_TYPE_KEYHUNT: return "g_kh";
-               case MAPINFO_TYPE_ASSAULT: return "g_assault";
-               case MAPINFO_TYPE_ONSLAUGHT: return "g_onslaught";
-               case MAPINFO_TYPE_RACE: return "g_race";
-               case MAPINFO_TYPE_NEXBALL: return "g_nexball";
-               case MAPINFO_TYPE_FREEZETAG: return "g_freezetag";
-               case MAPINFO_TYPE_CTS: return "g_cts";
-               case MAPINFO_TYPE_KEEPAWAY:             return "g_keepaway";
-               default: return "";
-       }
+       entity e;
+       for(e = MapInfo_Type_first; e; e = e.enemy)
+               if(e.weapons == t)
+                       return e.mdl;
+       return "";
 }
 
 void MapInfo_SwitchGameType(float t)
 {
-       cvar_set("g_dm",         (t == MAPINFO_TYPE_DEATHMATCH)      ? "1" : "0");
-       cvar_set("g_tdm",        (t == MAPINFO_TYPE_TEAM_DEATHMATCH) ? "1" : "0");
-       cvar_set("g_domination", (t == MAPINFO_TYPE_DOMINATION)      ? "1" : "0");
-       cvar_set("g_ctf",        (t == MAPINFO_TYPE_CTF)             ? "1" : "0");
-       cvar_set("g_runematch",  (t == MAPINFO_TYPE_RUNEMATCH)       ? "1" : "0");
-       cvar_set("g_lms",        (t == MAPINFO_TYPE_LMS)             ? "1" : "0");
-       cvar_set("g_arena",      (t == MAPINFO_TYPE_ARENA)           ? "1" : "0");
-       cvar_set("g_ca",         (t == MAPINFO_TYPE_CA)              ? "1" : "0");
-       cvar_set("g_keyhunt",    (t == MAPINFO_TYPE_KEYHUNT)         ? "1" : "0");
-       cvar_set("g_assault",    (t == MAPINFO_TYPE_ASSAULT)         ? "1" : "0");
-       cvar_set("g_onslaught",  (t == MAPINFO_TYPE_ONSLAUGHT)       ? "1" : "0");
-       cvar_set("g_race",       (t == MAPINFO_TYPE_RACE)            ? "1" : "0");
-       cvar_set("g_nexball",    (t == MAPINFO_TYPE_NEXBALL)         ? "1" : "0");
-       cvar_set("g_cts",        (t == MAPINFO_TYPE_CTS)             ? "1" : "0");
-       cvar_set("g_freezetag",  (t == MAPINFO_TYPE_FREEZETAG)       ? "1" : "0");
-       cvar_set("g_keepaway",   (t == MAPINFO_TYPE_KEEPAWAY)        ? "1" : "0");
+       entity e;
+       for(e = MapInfo_Type_first; e; e = e.enemy)
+               cvar_set(e.mdl, (t == e.weapons) ? "1" : "0");
 }
 
 void MapInfo_LoadMap(string s, float reinit)
index 965cff460f12bdbfa776b26991e245861384fee8..72b066288f86b14a6c53d3a02c8f41dd82a83514 100644 (file)
@@ -1,20 +1,81 @@
-float MAPINFO_TYPE_DEATHMATCH          = 1;
-float MAPINFO_TYPE_LMS                 = 2;
-float MAPINFO_TYPE_ARENA               = 4;
-float MAPINFO_TYPE_RUNEMATCH           = 8;
-float MAPINFO_TYPE_RACE                        = 16;
-float MAPINFO_TYPE_CTS                 = 32;
-float MAPINFO_TYPE_TEAM_DEATHMATCH     = 64;
-float MAPINFO_TYPE_CTF                 = 128;
-float MAPINFO_TYPE_CA                  = 256;
-float MAPINFO_TYPE_DOMINATION          = 512;
-float MAPINFO_TYPE_KEYHUNT             = 1024;
-float MAPINFO_TYPE_ASSAULT             = 2048;
-float MAPINFO_TYPE_ONSLAUGHT           = 4096;
-float MAPINFO_TYPE_NEXBALL             = 8192;
-float MAPINFO_TYPE_FREEZETAG           = 16384;
-float MAPINFO_TYPE_KEEPAWAY            = 32768;
-float MAPINFO_TYPE_ALL                 = 65535; // this has to include all above bits
+var float MAPINFO_TYPE_ALL = 0;
+entity MapInfo_Type_first;
+entity MapInfo_Type_last;
+
+#define REGISTER_GAMETYPE_LONG(name,sname,NAME,g_name,MAPINFO_TYPE_NAME,MapInfo_Type_name) \
+       var float MAPINFO_TYPE_NAME; \
+       var entity MapInfo_Type_name; \
+       void RegisterGametypes_##name() \
+       { \
+               MAPINFO_TYPE_NAME = MAPINFO_TYPE_ALL + 1; \
+               MAPINFO_TYPE_ALL |= MAPINFO_TYPE_NAME; \
+               MapInfo_Type_name = spawn(); \
+               MapInfo_Type_name.weapons = MAPINFO_TYPE_NAME; \
+               MapInfo_Type_name.netname = #name; \
+               MapInfo_Type_name.message = #NAME; \
+               MapInfo_Type_name.mdl = #g_name; \
+               MapInfo_Type_name.model2 = #sname; \
+               if(!MapInfo_Type_first) \
+                       MapInfo_Type_first = MapInfo_Type_name; \
+               if(MapInfo_Type_last) \
+                       MapInfo_Type_last.enemy = MapInfo_Type_name; \
+               MapInfo_Type_last = MapInfo_Type_name; \
+       } \
+       ACCUMULATE_FUNCTION(RegisterGametypes, RegisterGametypes_##name)
+
+#define REGISTER_GAMETYPE(name,sname,NAME) \
+       REGISTER_GAMETYPE_LONG(name,sname,NAME,g_##name,MAPINFO_TYPE_##NAME,MapInfo_Type_##name)
+
+#define IS_GAMETYPE(NAME) \
+       (MapInfo_LoadedGametype == MAPINFO_TYPE_##NAME)
+
+REGISTER_GAMETYPE(dm,dm,DEATHMATCH)
+#define g_dm IS_GAMETYPE(DEATHMATCH)
+
+REGISTER_GAMETYPE(lms,lms,LMS)
+#define g_lms IS_GAMETYPE(LMS)
+
+REGISTER_GAMETYPE(arena,arena,ARENA)
+#define g_arena IS_GAMETYPE(ARENA)
+
+REGISTER_GAMETYPE(runematch,rune,RUNEMATCH)
+#define g_runematch IS_GAMETYPE(RUNEMATCH)
+
+REGISTER_GAMETYPE(race,rc,RACE)
+#define g_race IS_GAMETYPE(RACE)
+
+REGISTER_GAMETYPE(cts,cts,CTS)
+#define g_cts IS_GAMETYPE(CTS)
+
+REGISTER_GAMETYPE(tdm,tdm,TEAM_DEATHMATCH)
+#define g_tdm IS_GAMETYPE(TEAM_DEATHMATCH)
+
+REGISTER_GAMETYPE(ctf,ctf,CTF)
+#define g_ctf IS_GAMETYPE(CTF)
+
+REGISTER_GAMETYPE(ca,ca,CA)
+#define g_ca IS_GAMETYPE(CA)
+
+REGISTER_GAMETYPE(domination,dom,DOMINATION)
+#define g_domination IS_GAMETYPE(DOMINATION)
+
+REGISTER_GAMETYPE(keyhunt,kh,KEYHUNT)
+#define g_keyhunt IS_GAMETYPE(KEYHUNT)
+
+REGISTER_GAMETYPE(assault,as,ASSAULT)
+#define g_assault IS_GAMETYPE(ASSAULT)
+
+REGISTER_GAMETYPE(onslaught,ons,ONSLAUGHT)
+#define g_onslaught IS_GAMETYPE(ONSLAUGHT)
+
+REGISTER_GAMETYPE(nexball,nexball,NEXBALL)
+#define g_nexball IS_GAMETYPE(NEXBALL)
+
+REGISTER_GAMETYPE(freezetag,freezetag,FREEZETAG)
+#define g_freezetag IS_GAMETYPE(FREEZETAG)
+
+REGISTER_GAMETYPE(keepaway,keepaway,KEEPAWAY)
+#define g_keepaway IS_GAMETYPE(KEEPAWAY)
 
 float MAPINFO_FEATURE_WEAPONS       = 1; // not defined for minstagib-only maps
 float MAPINFO_FEATURE_VEHICLES      = 2;
@@ -94,20 +155,3 @@ void MapInfo_Shutdown(); // call this in the shutdown handler
 
 #define MAPINFO_SETTEMP_ACL_USER cvar_string("g_mapinfo_settemp_acl")
 #define MAPINFO_SETTEMP_ACL_SYSTEM "-g_mapinfo_* -rcon_* -_* -g_ban* +*"
-
-#define g_dm (MapInfo_LoadedGametype == MAPINFO_TYPE_DEATHMATCH)
-#define g_tdm (MapInfo_LoadedGametype == MAPINFO_TYPE_TEAM_DEATHMATCH)
-#define g_domination (MapInfo_LoadedGametype == MAPINFO_TYPE_DOMINATION)
-#define g_ctf (MapInfo_LoadedGametype == MAPINFO_TYPE_CTF)
-#define g_runematch (MapInfo_LoadedGametype == MAPINFO_TYPE_RUNEMATCH)
-#define g_lms (MapInfo_LoadedGametype == MAPINFO_TYPE_LMS)
-#define g_arena (MapInfo_LoadedGametype == MAPINFO_TYPE_ARENA)
-#define g_ca (MapInfo_LoadedGametype == MAPINFO_TYPE_CA)
-#define g_keyhunt (MapInfo_LoadedGametype == MAPINFO_TYPE_KEYHUNT)
-#define g_assault (MapInfo_LoadedGametype == MAPINFO_TYPE_ASSAULT)
-#define g_onslaught (MapInfo_LoadedGametype == MAPINFO_TYPE_ONSLAUGHT)
-#define g_race (MapInfo_LoadedGametype == MAPINFO_TYPE_RACE)
-#define g_nexball (MapInfo_LoadedGametype == MAPINFO_TYPE_NEXBALL)
-#define g_cts (MapInfo_LoadedGametype == MAPINFO_TYPE_CTS)
-#define g_freezetag (MapInfo_LoadedGametype == MAPINFO_TYPE_FREEZETAG)
-#define g_keepaway (MapInfo_LoadedGametype == MAPINFO_TYPE_KEEPAWAY)
index 594844117c1afc7ee50bc9e929276f67a9e00f40..ff91f5359482f24761af700ef724d6bc0f6fe317 100644 (file)
@@ -117,7 +117,9 @@ void m_init_delayed()
                return;
        menuInitialized = 1;
 
+       // needs to be done so early because of the constants they create
        RegisterWeapons();
+       RegisterGametypes();
 
        fh = -1;
        if(cvar_string("menu_skin") != "")
index 48373974720a2df25ea47df40499b8746819b321..4d24b5a91380562e28704e9d556f71fba23436a2 100644 (file)
@@ -611,6 +611,10 @@ void spawnfunc___init_dedicated_server(void)
 
        self.classname = "worldspawn"; // safeguard against various stuff ;)
 
+       // needs to be done so early because of the constants they create
+       RegisterWeapons();
+       RegisterGametypes();
+
        MapInfo_Enumerate();
        MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
 }
@@ -654,8 +658,9 @@ void spawnfunc_worldspawn (void)
                head = nextent(head);
        }
 
-       // needs to be done so early as they would still spawn
+       // needs to be done so early because of the constants they create
        RegisterWeapons();
+       RegisterGametypes();
 
        ServerProgsDB = db_load(strcat("server.db", autocvar_sessionid));