From 52605b5b4766bf11d4bf55999ed4b4aeafbecdef Mon Sep 17 00:00:00 2001 From: div0 Date: Thu, 15 Nov 2007 19:07:03 +0000 Subject: [PATCH] added some primitives to the mapinfo system to be aware of game mode requirements git-svn-id: svn://svn.icculus.org/nexuiz/trunk@2960 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/qcsrc/common/mapinfo.qc | 62 +++++++++++++++++++++++++++++++++++ data/qcsrc/common/mapinfo.qh | 6 ++++ data/qcsrc/server/teamplay.qc | 3 +- 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/data/qcsrc/common/mapinfo.qc b/data/qcsrc/common/mapinfo.qc index 5f5d0d575..1dbab5d87 100644 --- a/data/qcsrc/common/mapinfo.qc +++ b/data/qcsrc/common/mapinfo.qc @@ -355,3 +355,65 @@ string MapInfo_FixName(string s) return string_null; // ambigous match return match; } + +float MapInfo_CurrentFeatures() +{ + float req; + req = 0; + if(!(cvar("g_instagib") || cvar("g_minstagib") || cvar("g_nixnex") || cvar("g_rocketarena"))) + req |= MAPINFO_FEATURE_WEAPONS; + return req; +} + +float MapInfo_CurrentGametype() +{ + if(cvar("g_domination")) + return MAPINFO_TYPE_DOMINATION; + else if(cvar("g_ctf")) + return MAPINFO_TYPE_CTF; + else if(cvar("g_runematch")) + return MAPINFO_TYPE_RUNEMATCH; + else if(cvar("g_tdm")) + return MAPINFO_TYPE_TEAM_DEATHMATCH; + else if(cvar("g_assault")) + return MAPINFO_TYPE_ASSAULT; + else if(cvar("g_lms")) + return MAPINFO_TYPE_LMS; + else if(cvar("g_arena")) + return MAPINFO_TYPE_ARENA; + else if(cvar("g_keyhunt")) + return MAPINFO_TYPE_KEYHUNT; + else if(cvar("g_onslaught")) + return MAPINFO_TYPE_ONSLAUGHT; + else + return MAPINFO_TYPE_DEATHMATCH; +} + +float MapInfo_CheckMap(string s) // returns 0 if the map can't be played with the current settings, 1 otherwise +{ + if(!MapInfo_Get_ByName(s, 1)) + return 0; + if((MapInfo_Map_supportedGametypes & MapInfo_CurrentGametype()) == 0) + return 0; + if((MapInfo_Map_supportedFeatures & MapInfo_CurrentFeatures()) != MapInfo_CurrentFeatures()) + return 0; + return 1; +} + +void MapInfo_LoadMap(string s) +{ + if(!MapInfo_CheckMap(s)) + { + print("EMERGENCY: can't play the selected map in the given game mode. Falling back to deathmatch.\n"); + cvar_set("g_domination", "0"); + cvar_set("g_ctf", "0"); + cvar_set("g_runematch", "0"); + cvar_set("g_tdm", "0"); + cvar_set("g_assault", "0"); + cvar_set("g_lms", "0"); + cvar_set("g_arena", "0"); + cvar_set("g_keyhunt", "0"); + cvar_set("g_onslaught", "0"); + } + localcmd(strcat("\nchangelevel ", s, "\n")); +} diff --git a/data/qcsrc/common/mapinfo.qh b/data/qcsrc/common/mapinfo.qh index 65c05829f..2152e496d 100644 --- a/data/qcsrc/common/mapinfo.qh +++ b/data/qcsrc/common/mapinfo.qh @@ -28,6 +28,8 @@ void MapInfo_Enumerate(); // filter the info by game type mask (updates MapInfo_count) float MapInfo_FilterGametype(float gametype, float features); // 1 on success, 0 on temporary failure (call it again next frame then) +float MapInfo_CurrentFeatures(); // retrieves currently required features from cvars +float MapInfo_CurrentGametype(); // retrieves current gametype from cvars // load info about the i-th map into the MapInfo_Map_* globals float MapInfo_Get_ByID(float i); // 1 on success, 0 on failure @@ -37,3 +39,7 @@ float MapInfo_Get_ByName(string s, float allowGenerate); // 1 on success, 0 on f // look for a map by a prefix, returns the actual map name on success, string_null on failure or ambigous match string MapInfo_FixName(string s); + +// play a map +float MapInfo_CheckMap(string s); // returns 0 if the map can't be played with the current settings +void MapInfo_LoadMap(string s); diff --git a/data/qcsrc/server/teamplay.qc b/data/qcsrc/server/teamplay.qc index 3b9816772..c57bcbed7 100644 --- a/data/qcsrc/server/teamplay.qc +++ b/data/qcsrc/server/teamplay.qc @@ -162,10 +162,11 @@ void InitGameplayMode() gamemode_name = "Capture the Flag"; teams_matter = 1; } - else if((game == GAME_RUNEMATCH || cvar("g_runematch")) && !g_minstagib) + else if(game == GAME_RUNEMATCH || cvar("g_runematch")) { game = GAME_RUNEMATCH; cvar_set("g_runematch", "1"); + cvar_set("g_minstagib", "0"); if(cvar("deathmatch_force_teamplay")) ActivateTeamplay(); -- 2.39.2