1 package cz.cuni.amis.pogamut.ut2004.tag.tournament;
2
3 import java.io.File;
4 import java.util.Map;
5
6 import cz.cuni.amis.pogamut.ut2004.tournament.GameBots2004Ini;
7 import cz.cuni.amis.pogamut.ut2004.tournament.match.UT2004BotConfig;
8 import cz.cuni.amis.pogamut.ut2004.tournament.match.UT2004MatchConfig;
9 import cz.cuni.amis.pogamut.ut2004.tournament.match.UT2004NativeBotConfig;
10 import cz.cuni.amis.pogamut.ut2004.utils.UCCWrapperConf;
11 import cz.cuni.amis.utils.Const;
12 import cz.cuni.amis.utils.exception.PogamutException;
13 import cz.cuni.amis.utils.token.IToken;
14
15 public class UT2004TagConfig extends UT2004MatchConfig {
16
17 protected int fragLimit = 20;
18
19 protected int timeLimitInMin = 20;
20
21 protected int tagLimit = 20;
22
23 protected boolean humanLikeLog = false;
24
25 public UT2004TagConfig() {
26 super();
27 getGb2004Ini().setDMFragLimit(fragLimit);
28 getGb2004Ini().setDMTimeLimit(timeLimitInMin);
29 getUccConf().setGameType("BotDeathMatch");
30 setMatchId("TagMatch");
31 }
32
33
34
35
36
37 public UT2004TagConfig(UT2004TagConfig orig) {
38 super(orig);
39 this.setFragLimit(orig.getFragLimit());
40 this.setTimeLimit(orig.getTimeLimit());
41 }
42
43 public int getTagLimit() {
44 return tagLimit;
45 }
46
47 public void setTagLimit(int tagLimit) {
48 this.tagLimit = tagLimit;
49 }
50
51
52
53
54
55 public int getFragLimit() {
56 return fragLimit;
57 }
58
59
60
61
62
63 public int getTimeLimit() {
64 return timeLimitInMin;
65 }
66
67 @Override
68 public UT2004TagConfig clearBots() {
69 super.clearBots();
70 return this;
71 }
72
73 @Override
74 public UT2004TagConfig clearNativeBots() {
75 super.clearNativeBots();
76 return this;
77 }
78
79 @Override
80 public UT2004TagConfig setOutputDirectory(File outputDirectory) {
81 super.setOutputDirectory(outputDirectory);
82 return this;
83 }
84
85
86
87
88
89
90 public UT2004TagConfig setFragLimit(int fragLimit) {
91 if (fragLimit <= 0) {
92 throw new PogamutException("Frag limit can't be " + fragLimit + " <= 0.", this);
93 }
94 this.fragLimit = fragLimit;
95 getGb2004Ini().setDMFragLimit(fragLimit);
96 return this;
97 }
98
99
100
101
102
103
104 public UT2004TagConfig setTimeLimit(int timeLimitInMinutes) {
105 if (timeLimitInMinutes < 1) {
106 throw new PogamutException("Time limit can't be " + timeLimitInMinutes + " < 1 min.", this);
107 }
108 this.timeLimitInMin = timeLimitInMinutes;
109 getGb2004Ini().setDMTimeLimit(timeLimitInMinutes);
110 return this;
111 }
112
113
114 public UT2004TagConfig setUccConf(UCCWrapperConf uccConf) {
115 super.setUccConf(uccConf);
116 return this;
117 }
118
119
120
121
122 public UT2004TagConfig setGb2004Ini(GameBots2004Ini gb2004Ini) {
123 super.setGb2004Ini(gb2004Ini);
124 if (getGb2004Ini() != null) {
125 if (getGb2004Ini().getDMFragLimit() != null) {
126 this.fragLimit = getGb2004Ini().getDMFragLimit();
127 } else {
128 getGb2004Ini().setDMFragLimit(fragLimit);
129 }
130 if (getGb2004Ini().getDMTimeLimit() != null) {
131 this.timeLimitInMin = getGb2004Ini().getDMTimeLimit();
132 } else {
133 getGb2004Ini().setDMTimeLimit(timeLimitInMin);
134 }
135 }
136 return this;
137 }
138
139 public UT2004TagConfig setBots(Map<IToken, UT2004BotConfig> bots) {
140 super.setBots(bots);
141 return this;
142 }
143
144 public UT2004TagConfig setNativeBots(Map<IToken, UT2004NativeBotConfig> nativeBots) {
145 super.setNativeBots(nativeBots);
146 return this;
147 }
148
149 public UT2004TagConfig addBot(UT2004BotConfig... bots) {
150 super.addBot(bots);
151 return this;
152 }
153
154 public UT2004MatchConfig setBot(UT2004BotConfig... bots) {
155 super.setBot(bots);
156 return this;
157 }
158
159 public UT2004TagConfig addNativeBot(UT2004NativeBotConfig... bots) {
160 super.addNativeBot(bots);
161 return this;
162 }
163
164 public UT2004TagConfig setNativeBot(UT2004NativeBotConfig... bots) {
165 super.setNativeBot(bots);
166 return this;
167 }
168
169 public UT2004TagConfig setHumanLikeLogEnabled(boolean humanLikeLog) {
170 super.setHumanLikeLogEnabled(humanLikeLog);
171 return this;
172 }
173
174 @Override
175 protected void validateInner() {
176 super.validateInner();
177 if (tagLimit <= 0) {
178 validationError = true;
179 validationBuffer.append(Const.NEW_LINE);
180 validationBuffer.append("TagLimit = " + fragLimit + " <= 0");
181 }
182 if (timeLimitInMin < 1) {
183 validationError = true;
184 validationBuffer.append(Const.NEW_LINE);
185 validationBuffer.append("TimeLimit = " + timeLimitInMin + " < 1 min.");
186 }
187 if (getGb2004Ini().getDMTimeLimit() < 1) {
188 validationError = true;
189 validationBuffer.append(Const.NEW_LINE);
190 validationBuffer.append("GameBots2004.ini TimeLimit = " + getGb2004Ini().getDMTimeLimit() + " < 1 min.");
191 }
192 }
193
194 }