Getting Flag Information
Posted: Thu Jul 03, 2008 1:39 am
While I was writing a plug-in, I found it useful to be able to get extra information about a flag from its flag code, such as its shot type, quality, full name, and whether or not it is a team flag. I am pretty sure the current API does not have a way to get this information, so I wrote a class that does. The only thing I do not like about this class is it uses a static array to store all of the information. (See attached)
In addition, here is a small function to get the flag code from either the bz_PlayerRecord or the bz_BasePlayerRecord. The PlayerRecord::currentFlag string is formatted with the full name, the flag code, and a plus or minus sign indicating a good or bad flag respectively. For example, the wings flag has this formatting: "WinGs (+WG)." However, not all functions or data members use this same formatting.
In addition, here is a small function to get the flag code from either the bz_PlayerRecord or the bz_BasePlayerRecord. The PlayerRecord::currentFlag string is formatted with the full name, the flag code, and a plus or minus sign indicating a good or bad flag respectively. For example, the wings flag has this formatting: "WinGs (+WG)." However, not all functions or data members use this same formatting.
Code: Select all
// A hack to get the flag code from a bz_BasePlayerRecord
inline std::string extractFlagCode(const std::string& flag)
{
std::size_t begin = flag.find_last_of('(');
std::size_t end = flag.find_last_of(')');
if(begin == std::string::npos || end == std::string::npos)
return std::string("");
return std::string(flag.begin() + begin + 2,
flag.begin() + end);
}