Page 1 of 1

Getting Flag Information

Posted: Thu Jul 03, 2008 1:39 am
by Enigma
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.

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);  
}

Posted: Wed Jul 23, 2008 5:08 am
by Enigma
Here is the HeaderDoc page.

Posted: Sat Jul 26, 2008 1:44 am
by Enigma
I just realized some of the functions are not declared const, and they should be. Here are the modified source files and an html HeaderDoc page.