4 REGISTRY(Teams, BITS(5))
5 #define Teams_from(i) _Teams_from(i, TEAM_SPECTATOR)
6 REGISTER_REGISTRY(Teams)
10 ATTRIB(Team, m_name, string, string_null)
11 ATTRIB(Team, m_name_nonls, string, string_null)
12 ATTRIB(Team, m_playercolor, int, 0)
13 ATTRIB(Team, m_colorstr, string, string_null)
14 ATTRIB(Team, m_color, vector, '0 0 0')
15 CONSTRUCTOR(Team, string _name, string _name_nonls, int _playercolor, string _colorstr, vector _color) {
20 this.team = _playercolor; // for team numbers that aren't stupid, use `this.m_id`
23 this.m_name_nonls = _name_nonls;
24 this.m_playercolor = _playercolor;
25 this.m_colorstr = _colorstr;
26 this.m_color = _color;
30 #define TEAM(id, ...) REGISTER(Teams, id, m_id, NEW(Team, __VA_ARGS__))
32 TEAM(TEAM_1, _("Red"), "Red", 4, "^1", '1 0.0625 0.0625'); // 0xFF0F0F
33 TEAM(TEAM_2, _("Blue"), "Blue", 13, "^4", '0.0625 0.0625 1 '); // 0x0F0FFF
34 TEAM(TEAM_3, _("Yellow"), "Yellow", 12, "^3", '1 1 0.0625'); // 0xFFFF0F
35 TEAM(TEAM_4, _("Pink"), "Pink", 9, "^6", '1 0.0625 1 '); // 0xFF0FFF
36 TEAM(TEAM_SPEC, _("Neutral"), "Neutral", 1337, "^7", '0 0 0 ');
38 #define NUM_TEAM_1 (TEAM_1.m_playercolor)
39 #define NUM_TEAM_2 (TEAM_2.m_playercolor)
40 #define NUM_TEAM_3 (TEAM_3.m_playercolor)
41 #define NUM_TEAM_4 (TEAM_4.m_playercolor)
42 #define NUM_SPECTATOR (TEAM_SPEC.m_playercolor)
44 #define COL_TEAM_1 (TEAM_1.m_colorstr)
45 #define COL_TEAM_2 (TEAM_2.m_colorstr)
46 #define COL_TEAM_3 (TEAM_3.m_colorstr)
47 #define COL_TEAM_4 (TEAM_4.m_colorstr)
48 /** must be #defined, const globals drop the translation attribute */
49 #define NAME_TEAM _("Team")
50 #define NAME_TEAM_1 (TEAM_1.m_name)
51 #define NAME_TEAM_2 (TEAM_2.m_name)
52 #define NAME_TEAM_3 (TEAM_3.m_name)
53 #define NAME_TEAM_4 (TEAM_4.m_name)
54 #define NAME_NEUTRAL (TEAM_SPEC.m_name)
56 // used for replacement in filenames or such where the name CANNOT be allowed to be translated
57 #define STATIC_NAME_TEAM_1 (TEAM_1.m_name_nonls)
58 #define STATIC_NAME_TEAM_2 (TEAM_2.m_name_nonls)
59 #define STATIC_NAME_TEAM_3 (TEAM_3.m_name_nonls)
60 #define STATIC_NAME_TEAM_4 (TEAM_4.m_name_nonls)
68 if (teamid == 0) return NULL;
69 FOREACH(Teams, it.team == teamid, return it);
70 LOG_SEVEREF("Unknown team: %d", teamid);
74 #define Team_ColorCode(this) (TM(this).m_colorstr)
76 #define Team_ColorRGB(this) (TM(this).m_color)
78 #define Team_ColorName(this) (TM(this).m_name_nonls)
80 // used for replacement in filenames or such where the name CANNOT be allowed to be translated
81 #define Static_Team_ColorName(this) (TM(this).m_name)
83 int Team_ColorToTeam(string team_color)
85 switch(strtolower(team_color))
87 case "red": return NUM_TEAM_1;
88 case "blue": return NUM_TEAM_2;
89 case "yellow": return NUM_TEAM_3;
90 case "pink": return NUM_TEAM_4;
91 case "auto": return 0;
97 int Team_NumberToTeam(int number)
101 case 1: return NUM_TEAM_1;
102 case 2: return NUM_TEAM_2;
103 case 3: return NUM_TEAM_3;
104 case 4: return NUM_TEAM_4;
110 int Team_TeamToNumber(int teamid)
114 case NUM_TEAM_1: return 1;
115 case NUM_TEAM_2: return 2;
116 case NUM_TEAM_3: return 3;
117 case NUM_TEAM_4: return 4;
124 // legacy aliases for shitty code
125 #define ColorByTeam(number) Team_NumberToTeam(number + 1)
128 #define Team_ColorName_Lower(teamid) strtolower(Team_ColorName(teamid))
129 #define Team_ColorName_Upper(teamid) strtoupper(Team_ColorName(teamid))
131 // used for replacement in filenames or such where the name CANNOT be allowed to be translated
132 #define Static_Team_ColorName_Lower(teamid) strtolower(Static_Team_ColorName(teamid))
133 #define Static_Team_ColorName_Upper(teamid) strtoupper(Static_Team_ColorName(teamid))
135 #define Team_FullName(teamid) strcat(Team_ColorName(teamid), " ", NAME_TEAM, "^7")
136 #define Team_ColoredFullName(teamid) strcat(Team_ColorCode(teamid), Team_ColorName(teamid), " ", NAME_TEAM, "^7")
138 #define Team_NumberToFullName(number) Team_FullName(Team_NumberToTeam(number))
139 #define Team_NumberToColoredFullName(number) Team_ColoredFullName(Team_NumberToTeam(number))
141 // replace these flags in a string with the strings provided
142 #define TCR(input,teamcolor,teamtext) strreplace("^TC", teamcolor, strreplace("^TT", teamtext, input))
144 // safe team comparisons
145 #define SAME_TEAM(a,b) (teamplay ? (a.team == b.team) : (a == b))
146 #define DIFF_TEAM(a,b) (teamplay ? (a.team != b.team) : (a != b))