Getting Flag Information

Questions, comments, and news on the server side plug-ins and it's API
Post Reply
Enigma
Private First Class
Private First Class
Posts: 212
Joined: Sat Apr 23, 2005 3:13 am

Getting Flag Information

Post 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);  
}
Attachments
FlagInfo.h
(11.7 KiB) Downloaded 270 times
FlagInfo.cpp
(9.27 KiB) Downloaded 276 times
Enigma
Private First Class
Private First Class
Posts: 212
Joined: Sat Apr 23, 2005 3:13 am

Post by Enigma »

Here is the HeaderDoc page.
Attachments
FlagInfo.pdf
(72.85 KiB) Downloaded 240 times
Enigma
Private First Class
Private First Class
Posts: 212
Joined: Sat Apr 23, 2005 3:13 am

Post 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.
Attachments
FlagInfo.tar
(80 KiB) Downloaded 216 times
Post Reply