From 5556b29e6e05600840f89209717f1b5ac1030870 Mon Sep 17 00:00:00 2001 From: div0 Date: Sun, 13 Jan 2008 14:55:54 +0000 Subject: [PATCH] next improvement to mapinfo: Q3A SG/MG swap, mapinfo now applies map-specific settings at the RIGHT time git-svn-id: svn://svn.icculus.org/nexuiz/trunk@3137 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/default.cfg | 3 ++ data/qcsrc/common/mapinfo.qc | 90 ++++++++++++++++++++++++++++------- data/qcsrc/common/mapinfo.qh | 3 ++ data/qcsrc/server/defs.qh | 1 + data/qcsrc/server/g_world.qc | 8 ++++ data/qcsrc/server/t_items.qc | 44 +++++++++++++++++ data/qcsrc/server/t_quake3.qc | 2 + 7 files changed, 135 insertions(+), 16 deletions(-) diff --git a/data/default.cfg b/data/default.cfg index a4c32c5a0..0fc46da2c 100644 --- a/data/default.cfg +++ b/data/default.cfg @@ -842,3 +842,6 @@ sbar_flagstatus_pos 115 // for menu server list (eventually make them have engine support?) seta menu_slist_showfull 1 seta menu_slist_showempty 1 + +// Q3A +set sv_q3acompat_machineshotgunswap 0 // settemp this in mapinfo for instant Q3A map conversion diff --git a/data/qcsrc/common/mapinfo.qc b/data/qcsrc/common/mapinfo.qc index e27630dd2..0289a3847 100644 --- a/data/qcsrc/common/mapinfo.qc +++ b/data/qcsrc/common/mapinfo.qc @@ -1,3 +1,28 @@ +// internal toy +void cvar_settemp(string key, string value) +{ + //localcmd(strcat("\nsettemp ", t, " \"", s, "\"\n")); + + // duplicate what this alias does: + // alias settemp "settemp_list \"1 $1 $settemp_var $settemp_list\"; set $settemp_var \"${$1}\"; settemp_var ${settemp_var}x; $1 \"$2\"" + + cvar_set("settemp_list", strcat("1 ", key, " ", cvar_string("settemp_var"), " ", cvar_string("settemp_list"))); + registercvar(cvar_string("settemp_var"), ""); + cvar_set(cvar_string("settemp_var"), cvar_string(key)); + cvar_set("settemp_var", strcat(cvar_string("settemp_var"), "x")); + cvar_set(key, value); +} + +void cvar_settemp_restore() +{ + // undo what cvar_settemp did + float n, i; + n = tokenize(cvar_string("settemp_list")); + for(i = 0; i < n - 3; i += 3) + cvar_set(argv(i + 1), cvar_string(argv(i + 2))); + cvar_set("settemp_list", "0"); +} + // HUGE SET - stored in a string string HugeSetOfIntegers_empty() { @@ -282,6 +307,7 @@ float _MapInfo_Generate(string pFilename) // 0: failure, 1: ok ent, 2: ok bsp } fclose(fh); + return r; } @@ -342,7 +368,7 @@ float MapInfo_Get_ByName(string pFilename, float pAllowGenerate, float pGametype { string fn; string s, t; - float fh; + float fh, fh2; float r, f; r = 1; @@ -377,6 +403,14 @@ float MapInfo_Get_ByName(string pFilename, float pAllowGenerate, float pGametype if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_KEYHUNT) fputs(fh, "type kh 1000 20 3\n"); if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_ASSAULT) fputs(fh, "type as 20\n"); if(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_ONSLAUGHT) fputs(fh, "type ons 20\n"); + + fh2 = fopen(strcat("scripts/", pFilename, ".arena"), FILE_READ); + if(fh2 >= 0) + { + fclose(fh2); + fputs(fh, "settemp_for_type all sv_q3acompat_machineshotgunswap 1\n"); + } + fclose(fh); r = 2; // return r; @@ -440,7 +474,7 @@ float MapInfo_Get_ByName(string pFilename, float pAllowGenerate, float pGametype else { dprint("Applying temporary setting ", t, " := ", s, "\n"); - localcmd(strcat("\nsettemp ", t, " \"", s, "\"\n")); + cvar_settemp(t, s); } } } @@ -561,28 +595,27 @@ float MapInfo_CheckMap(string s) // returns 0 if the map can't be played with th void MapInfo_SwitchGameType(float t) { cvar_set("gamecfg", "0"); - cvar_set("g_dm", (t == MAPINFO_TYPE_DEATHMATCH) ? "0" : "1"); - cvar_set("g_tdm", (t == MAPINFO_TYPE_TEAM_DEATHMATCH) ? "0" : "1"); - cvar_set("g_domination", (t == MAPINFO_TYPE_DOMINATION) ? "0" : "1"); - cvar_set("g_ctf", (t == MAPINFO_TYPE_CTF) ? "0" : "1"); - cvar_set("g_runematch", (t == MAPINFO_TYPE_RUNEMATCH) ? "0" : "1"); - cvar_set("g_lms", (t == MAPINFO_TYPE_LMS) ? "0" : "1"); - cvar_set("g_arena", (t == MAPINFO_TYPE_ARENA) ? "0" : "1"); - cvar_set("g_keyhunt", (t == MAPINFO_TYPE_KEYHUNT) ? "0" : "1"); - cvar_set("g_assault", (t == MAPINFO_TYPE_ASSAULT) ? "0" : "1"); - cvar_set("g_onslaught", (t == MAPINFO_TYPE_ONSLAUGHT) ? "0" : "1"); + 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_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"); } void MapInfo_LoadMap(string s) { + MapInfo_Map_supportedGametypes = 0; if(!MapInfo_CheckMap(s)) { - print("EMERGENCY: can't play the selected map in the given game mode. Falling back to deathmatch.\n"); + print("EMERGENCY: can't play the selected map in the given game mode. Falling back to DM.\n"); MapInfo_SwitchGameType(MAPINFO_TYPE_DEATHMATCH); } - localcmd("\nsettemp_restore\n"); - MapInfo_Get_ByName(s, 1, MapInfo_CurrentGametype()); - localcmd(strcat("\nchangelevel ", s, "\n")); + localcmd(strcat("\nsettemp_restore\nchangelevel ", s, "\n")); } string MapInfo_ListAllowedMaps() @@ -599,3 +632,28 @@ string MapInfo_ListAllowedMaps() out = strcat(out, " ", _MapInfo_GlobItem(HugeSetOfIntegers_get(_MapInfo_filtered, i))); return substring(out, 1, strlen(out) - 1); } + +void MapInfo_LoadMapSettings(string s) // to be called from worldspawn +{ + float t; + if(!MapInfo_CheckMap(s)) + { + if(MapInfo_Map_supportedGametypes <= 0) + error("Mapinfo system is not functional at all. BAILED OUT.\n"); + + t = 1; + while(!(MapInfo_Map_supportedGametypes & 1)) + { + t *= 2; + MapInfo_Map_supportedGametypes = floor(MapInfo_Map_supportedGametypes / 2); + } + // t is now a supported mode! + print("EMERGENCY: can't play the selected map in the given game mode. Falling back to a supported mode.\n"); + print(ftos(t), "\n"); + MapInfo_SwitchGameType(t); + print(ftos(MapInfo_CurrentGametype()), "\n"); + } + print(ftos(MapInfo_CurrentGametype()), "\n"); + cvar_settemp_restore(); + MapInfo_Get_ByName(s, 1, MapInfo_CurrentGametype()); +} diff --git a/data/qcsrc/common/mapinfo.qh b/data/qcsrc/common/mapinfo.qh index d2b9b2832..fc9cc8038 100644 --- a/data/qcsrc/common/mapinfo.qh +++ b/data/qcsrc/common/mapinfo.qh @@ -54,3 +54,6 @@ string MapInfo_ListAllowedMaps(); // gets a gametype from a string float MapInfo_Type_FromString(string t); void MapInfo_SwitchGameType(float t); + +// to be called from worldspawn to set up cvars +void MapInfo_LoadMapSettings(string s); diff --git a/data/qcsrc/server/defs.qh b/data/qcsrc/server/defs.qh index 5ab521af2..b70d509b2 100644 --- a/data/qcsrc/server/defs.qh +++ b/data/qcsrc/server/defs.qh @@ -380,3 +380,4 @@ float assault_attacker_team; .float notsingle; .float notfree; .float notq3a; +float q3acompat_machineshotgunswap; diff --git a/data/qcsrc/server/g_world.qc b/data/qcsrc/server/g_world.qc index e3ef31456..00a669ddb 100644 --- a/data/qcsrc/server/g_world.qc +++ b/data/qcsrc/server/g_world.qc @@ -90,6 +90,10 @@ void worldspawn (void) error("world already spawned - you may have EXACTLY ONE worldspawn!"); world_already_spawned = TRUE; +#ifdef MAPINFO + MapInfo_LoadMapSettings(mapname); +#endif + /* TODO sound pack system // initialize sound pack system @@ -140,6 +144,10 @@ void worldspawn (void) // 63 testing lightstyle(63, "a"); + // for setting by mapinfo + q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap"); + cvar_set("sv_q3acompat_machineshotgunswap", "0"); + player_count = 0; lms_lowest_lives = 0; lms_next_place = 0; diff --git a/data/qcsrc/server/t_items.qc b/data/qcsrc/server/t_items.qc index 61bd5d4a7..cc76afa4b 100644 --- a/data/qcsrc/server/t_items.qc +++ b/data/qcsrc/server/t_items.qc @@ -527,7 +527,20 @@ void minst_remove_item (void) { remove(self); } +float weaponswapping; + +void weapon_shotgun (void); void weapon_uzi (void) { + if(!weaponswapping) + if(q3acompat_machineshotgunswap) + if(self.classname != "droppedweapon") + { + weaponswapping = TRUE; + weapon_shotgun(); + weaponswapping = FALSE; + return; + } + if(!self.ammo_nails) self.ammo_nails = cvar("g_pickup_nails"); StartItem ("models/weapons/g_uzi.md3", "weapons/weaponpickup.wav", 15, W_Name(WEP_UZI), IT_UZI, FL_WEAPON, weapon_pickupevalfunc, 1000); @@ -536,6 +549,16 @@ void weapon_uzi (void) { } void weapon_shotgun (void) { + if(!weaponswapping) + if(q3acompat_machineshotgunswap) + if(self.classname != "droppedweapon") + { + weaponswapping = TRUE; + weapon_uzi(); + weaponswapping = FALSE; + return; + } + if(!self.ammo_shells) self.ammo_shells = cvar("g_pickup_shells"); StartItem ("models/weapons/g_shotgun.md3", "weapons/weaponpickup.wav", 15, W_Name(WEP_SHOTGUN), IT_SHOTGUN, FL_WEAPON, weapon_pickupevalfunc, 1000); @@ -623,7 +646,18 @@ void item_rockets (void) { StartItem ("models/items/a_rockets.md3", "misc/itempickup.wav", 15, "rockets", IT_ROCKETS, 0, commodity_pickupevalfunc, 100); } +void item_shells (void); void item_bullets (void) { + if(!weaponswapping) + if(q3acompat_machineshotgunswap) + if(self.classname != "droppedweapon") + { + weaponswapping = TRUE; + item_shells(); + weaponswapping = FALSE; + return; + } + if(!self.ammo_nails) self.ammo_nails = g_pickup_nails; StartItem ("models/items/a_bullets.mdl", "misc/itempickup.wav", 15, "bullets", IT_NAILS, 0, commodity_pickupevalfunc, 100); @@ -636,6 +670,16 @@ void item_cells (void) { } void item_shells (void) { + if(!weaponswapping) + if(q3acompat_machineshotgunswap) + if(self.classname != "droppedweapon") + { + weaponswapping = TRUE; + item_bullets(); + weaponswapping = FALSE; + return; + } + if(!self.ammo_shells) self.ammo_shells = g_pickup_shells; StartItem ("models/items/a_shells.md3", "misc/itempickup.wav", 15, "shells", IT_SHELLS, 0, commodity_pickupevalfunc, 100); diff --git a/data/qcsrc/server/t_quake3.qc b/data/qcsrc/server/t_quake3.qc index 278242453..c999c73c9 100644 --- a/data/qcsrc/server/t_quake3.qc +++ b/data/qcsrc/server/t_quake3.qc @@ -50,3 +50,5 @@ void spawnfunc_team_CTF_redflag() { item_flag_team1(); } void spawnfunc_team_CTF_blueflag() { item_flag_team2(); } void spawnfunc_team_CTF_redplayer() { info_player_team1(); } void spawnfunc_team_CTF_blueplayer() { info_player_team2(); } +void spawnfunc_team_CTF_redspawn() { info_player_team1(); } +void spawnfunc_team_CTF_bluespawn() { info_player_team2(); } -- 2.39.2