1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
2
3 #include "TeamBase.h"
4
5 #include <cstdlib>
6 #include <sstream>
7
8 #include "System/Util.h"
9 #include "System/creg/STL_Map.h"
10
11
12 CR_BIND(TeamBase, )
13 CR_REG_METADATA(TeamBase, (
14 CR_MEMBER(leader),
15 CR_MEMBER(color),
16 CR_MEMBER(teamStartNum),
17 CR_MEMBER(teamAllyteam),
18 CR_MEMBER(incomeMultiplier),
19 CR_MEMBER(side),
20 CR_MEMBER(startPos),
21 CR_MEMBER(customValues)
22 ))
23
24
25 unsigned char TeamBase::teamDefaultColor[10][4] =
26 {
27 { 90, 90, 255, 255}, // blue
28 { 200, 0, 0, 255}, // red
29 { 255, 255, 255, 255}, // white
30 { 38, 155, 32, 255}, // green
31 { 7, 31, 125, 255}, // blue
32 { 150, 10, 180, 255}, // purple
33 { 255, 255, 0, 255}, // yellow
34 { 50, 50, 50, 255}, // black
35 { 152, 200, 220, 255}, // ltblue
36 { 171, 171, 131, 255} // tan
37 };
38
TeamBase()39 TeamBase::TeamBase() :
40 leader(-1),
41 teamStartNum(-1),
42 teamAllyteam(-1),
43 incomeMultiplier(1.0f)
44 {
45 color[0] = 255;
46 color[1] = 255;
47 color[2] = 255;
48 color[3] = 255;
49 }
50
SetValue(const std::string & key,const std::string & value)51 void TeamBase::SetValue(const std::string& key, const std::string& value)
52 {
53 if (key == "handicap") {
54 // handicap is used for backwards compatibility only
55 // it was renamed to advantage and is now a direct factor, not % anymore
56 // see SetAdvantage()
57 SetAdvantage(std::atof(value.c_str()) / 100.0f);
58 }
59 else if (key == "advantage") {
60 SetAdvantage(std::atof(value.c_str()));
61 }
62 else if (key == "incomemultiplier") {
63 SetIncomeMultiplier(std::atof(value.c_str()));
64 }
65 else if (key == "teamleader") {
66 leader = std::atoi(value.c_str());
67 }
68 else if (key == "side") {
69 side = StringToLower(value);
70 }
71 else if (key == "allyteam") {
72 teamAllyteam = std::atoi(value.c_str());
73 }
74 else if (key == "rgbcolor") {
75 std::istringstream buf(value);
76 for (size_t b = 0; b < 3; ++b) {
77 float tmp;
78 buf >> tmp;
79 color[b] = tmp * 255;
80 }
81 color[3] = 255;
82 }
83 else if (key == "startposx") {
84 if (!value.empty())
85 startPos.x = atoi(value.c_str());
86 }
87 else if (key == "startposz") {
88 if (!value.empty())
89 startPos.z = atoi(value.c_str());
90 }
91 else {
92 customValues[key] = value;
93 }
94 }
95
96
SetAdvantage(float advantage)97 void TeamBase::SetAdvantage(float advantage) {
98
99 advantage = std::max(0.0f, advantage);
100
101 SetIncomeMultiplier(advantage + 1.0f);
102 }
103
SetIncomeMultiplier(float incomeMultiplier)104 void TeamBase::SetIncomeMultiplier(float incomeMultiplier) {
105 this->incomeMultiplier = std::max(0.0f, incomeMultiplier);
106 }
107