Raised This Month: $ Target: $400
 0% 

[TF2] Get map type without relying on map name


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-20-2013 , 16:23   [TF2] Get map type without relying on map name
Reply With Quote #1

So, I wrote a little snippet that lets you find out what game type the current map is even if it has been renamed to something else.

This also has info on how to determine which type of CP map you're on.

PHP Code:
#include <sdktools>

// These correspond to tf_gamerules m_nGameType netprop
enum
{
    
TF2_GameType_Unknown,
    
TF2_GameType_CTF 1,
    
TF2_GameType_CP 2,
    
TF2_GameType_PL 3,
    
TF2_GameType_Arena 4,
}

enum TF2_GameMode
{
    
TF2_GameMode_Unknown,
    
TF2_GameMode_CTF,
    
TF2_GameMode_5CP,
    
TF2_GameMode_PL,
    
TF2_GameMode_Arena,
    
TF2_GameMode_ADCP,
    
TF2_GameMode_TC,
    
TF2_GameMode_PLR,
    
TF2_GameMode_KOTH,
    
TF2_GameMode_SD,
    
TF2_GameMode_MvM,
    
TF2_GameMode_Training,
    
TF2_GameMode_ItemTest,
}

stock TF2_GameMode:TF2_DetectGameMode()
{
    
    
// If we can get the map type through netprops, do so.
    
if (GameRules_GetProp("m_bIsInTraining"))
    {
        return 
TF2_GameMode_Training;
    }

    if (
GameRules_GetProp("m_bIsInItemTestingMode"))
    {
        return 
TF2_GameMode_ItemTest;
    }
    
    if (
GameRules_GetProp("m_bPlayingSpecialDeliveryMode"))
    {
        return 
TF2_GameMode_SD;
    }
    
    if (
GameRules_GetProp("m_bPlayingMannVsMachine"))
    {
        return 
TF2_GameMode_MvM;
    }
    
    if (
GameRules_GetProp("m_bPlayingKoth"))
    {
        return 
TF2_GameMode_KOTH;
    }

    
// Netprops didn't help, lets check the game type
    
new gameType GameRules_GetProp("m_nGameType");
    
    switch (
gameType)
    {
        case 
TF2_GameType_CTF:
        {
            return 
TF2_GameMode_CTF;
        }
        
        
// 5cp, a/d cp, and tc all show up as this game type
        // koth and mvm  too, but we already filtered those
        
case TF2_GameType_CP:
        {
            
// Check for multi-stage maps first.
            
new roundCount 0;
            new 
roundCP = -1;
            new 
priority = -1;
            
            new 
restrictWinner = -1;
            new 
restrictCount 0;
            
            while ((
roundCP FindEntityByClassname(roundCP"team_control_point_round")) != -1)
            {
                
roundCount++;
                
                
restrictWinner GetEntProp(roundCPProp_Data"m_iInvalidCapWinner");
                if (
restrictWinner 1)
                {
                    
restrictCount++;
                }
                
                new 
newPriority GetEntProp(roundCPProp_Data"m_nPriority");
                if (
newPriority priority)
                {
                    
priority newPriority;
                }
                else if (
newPriority == priority)
                {
                    
// Only TC maps have multiple rounds with the same priority, and it's the highest priority
                    // Sadly, this will fail to detect push/pull TC maps
                    
return TF2_GameMode_TC;
                }
            }
            
            
// All rounds have a winner restriction, so it must be a A/D cp map
            
if (roundCount && roundCount == restrictCount)
            {
                return 
TF2_GameMode_ADCP;
            }
            else if (
roundCount 1)
            {
                
// We had multiple rounds, but not all of them were restricted...
                // must be a push/pull TC map
                
return TF2_GameMode_TC;
            }
            
            
// Now for single round maps... same check on control point master
            
new masterCP FindEntityByClassname(-1"team_control_point_master");
            
            if (
masterCP > -1)
            {
                
restrictWinner GetEntProp(masterCPProp_Data"m_iInvalidCapWinner");
                
// Single round restricted are always A/D (gorge, gravelpit)
                
if (restrictWinner 1)
                {
                    return 
TF2_GameMode_ADCP;
                }
            }
            
            return 
TF2_GameMode_5CP;
        }
        
        
// pl and plr both show up as this game type
        
case TF2_GameType_PL:
        {
            
// All plr maps have this entity
            
if (FindEntityByClassname(-1"tf_logic_multiple_escort") > -1)
            {
                return 
TF2_GameMode_PLR;
            }
            
            return 
TF2_GameMode_PL;
        }
        
        case 
TF2_GameType_Arena:
        {
            return 
TF2_GameMode_Arena;
        }
    }
    return 
TF2_GameMode_Unknown;

Note: I haven't tested it on a hybrid CTF/CP map, but I assume it will be detected by its game type, CTF.

I wrote this code as part of a detection script for what control points are currently active, but that's not done yet.
Attached Files
File Type: inc controlpoints.inc (3.4 KB, 376 views)
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 09-20-2013 at 16:31.
Powerlord is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 09-21-2013 , 16:41   Re: [TF2] Get map type without relying on map name
Reply With Quote #2

Except there are things like trade maps with cps and broken logic and such that do nothing... And these "fun" maps are the type of maps that usually have strange prefixes. Grantd they may not have control point masters, but again, they may.. And a lot of them also have flags.

A better method is to detect and write out kvs to file.. Then ops can modify said kvs to override autodetection, and say.. Execute a servercommand (blag.cfg or something, etc) would be most useful.

Also, you can have multistage arena maps.. Vsh megaman? Or there are multistage cp maps.. Dustbowl, kakario which are not properly made. No idea how they are organized, but there are also castrated versions if these maps that are popularly used in vsh.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.

Last edited by friagram; 09-21-2013 at 16:44.
friagram is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-21-2013 , 23:57   Re: [TF2] Get map type without relying on map name
Reply With Quote #3

Quote:
Originally Posted by friagram View Post
Except there are things like trade maps with cps and broken logic and such that do nothing... And these "fun" maps are the type of maps that usually have strange prefixes. Grantd they may not have control point masters, but again, they may.. And a lot of them also have flags.

A better method is to detect and write out kvs to file.. Then ops can modify said kvs to override autodetection, and say.. Execute a servercommand (blag.cfg or something, etc) would be most useful.

Also, you can have multistage arena maps.. Vsh megaman? Or there are multistage cp maps.. Dustbowl, kakario which are not properly made. No idea how they are organized, but there are also castrated versions if these maps that are popularly used in vsh.
Out of curiosity, did you actually read the code before posting this? Your third paragraph implies heavily that you didn't.

The map type is discovered by first asking the GameRules entity what type of map it thinks is running. It checks the 5 standalone netprops first: MvM, KOTH, SD, ItemTest, and Training.

If it's not one of those, it asks the GameRules entity for the map type, which is one of unknown, CTF, CP, PL, or Arena.

For CTF, it just returns that it's CTF. For Arena, it just returns that it's Arena. For PL, it checks for the existence of the "tf_logic_multiple_escort" entity which is requires for PLR to actually work.

The only complicated checks come for maps that GameRules reports back as CP. For CP maps, it checks first to see how many rounds the map has. While it's checking that, it checks if a round's priority is the same as the highest priority its encountered yet. If it runs into multiple rounds with the same priority, it's a Terriority Control map (this is actually mentioned in the comments).

If it's a multi-round map and one team is marked as unable to win in all rounds, it's an A/D CP map. Any other multi-round CP map is a push/pull TC map.

If it's a single round CP map where one team is marked as unable to win, it's an A/D CP map. Any other single-round CP map is a symmetric CP map keeping in mind that we already checked if it was a KOTH map, and Arena maps aren't considered CP maps.

Incidentally, I checked a good number of standard maps against this, including:

cp_granary
cp_gravelpit
cp_dustbowl
ctf2_fort
sd_doomsday
tr_dustbowl
tr_target
arena_lumberyard
tc_hydro
ph_lumberyard
pl_goldrush
plr_pipeline

One map I know for sure it will fail on is tc_meridian... because it currently doesn't subdivide CTF maps into categories. cp_kakariko may also be subject to this due to it having multiple rounds.

It'd be nice if Valve would subdivide CP in the gamerules stuff, like marking which maps are A/D.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 09-22-2013 at 00:17.
Powerlord is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 09-22-2013 , 11:15   Re: [TF2] Get map type without relying on map name
Reply With Quote #4

I read it, and yes, i see how it works, but isn't the point to detect the type of gameplay regardless of prefix?
And as I posed, what of these odd custom maps or trade maps with wonky logic? Which is probably only time you would need this type of thing, as they are the most likely to be mislabeled.. Dm_ pkmn_ mlp_ achievement_ etc.

Here a "deathmatch" category would be most useful, eventhough it does not officially exist, many many many servers use it.

You can have a map with no logic at all, and just info player teamspawns... It will run fine, the game will tag it as capture points i think, it is not.

You can also have this same kind of maps with item temflags, capture zones, and capture points (tcpm) and again, it could be a trade map with no way to win.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.

Last edited by friagram; 09-22-2013 at 11:21.
friagram is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:29.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode