View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.tournament.capturetheflag;
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 UT2004CaptureTheFlagConfig extends UT2004MatchConfig {
16  	
17  	protected int scoreLimit = 20;
18  	
19  	protected int timeLimitInMin = 20;
20  	
21  	public UT2004CaptureTheFlagConfig() {
22  		super();
23  		getGb2004Ini().setCTFScoreLimit(scoreLimit);
24  		getGb2004Ini().setCTFTimeLimit(timeLimitInMin);
25  		getUccConf().setGameType("BotCTFGame");
26  	}
27  	
28  	/**
29  	 * Copy-constructor.
30  	 * @param orig
31  	 */
32  	public UT2004CaptureTheFlagConfig(UT2004CaptureTheFlagConfig orig) {
33  		super(orig);
34  		this.setScoreLimit(orig.getScoreLimit());
35  		this.setTimeLimit(orig.getTimeLimit());
36  	}
37  	
38  	/**
39  	 * Returns score limit of the match.
40  	 * @return
41  	 */
42  	public int getScoreLimit() {
43  		return scoreLimit;
44  	}
45  
46  	/**
47  	 * Returns time limit of the match in seconds.
48  	 * @return
49  	 */
50  	public int getTimeLimit() {
51  		return timeLimitInMin;
52  	}
53  	
54  	@Override
55  	public UT2004CaptureTheFlagConfig clearBots() {
56  		super.clearBots();
57  		return this;
58  	}
59  	
60  	@Override
61  	public UT2004CaptureTheFlagConfig clearNativeBots() {
62  		super.clearNativeBots();
63  		return this;
64  	}
65  	
66  	@Override
67  	public UT2004CaptureTheFlagConfig setOutputDirectory(File outputDirectory) {
68  		super.setOutputDirectory(outputDirectory);
69  		return this;
70  	}
71  
72  	/**
73  	 * Alters GB2004Ini as well.
74  	 * @param scoreLimit
75  	 * @return
76  	 */
77  	public UT2004CaptureTheFlagConfig setScoreLimit(int scoreLimit) {
78  		if (scoreLimit <= 0) {
79  			throw new PogamutException("Score limit can't be " + scoreLimit + " <= 0.", this);
80  		}
81  		this.scoreLimit = scoreLimit;
82  		getGb2004Ini().setCTFScoreLimit(scoreLimit);
83  		return this;
84  	}
85  
86  	/**
87  	 * Alters GB2004Ini as well.
88  	 * @param timeLimitInMinutes
89  	 * @return
90  	 */
91  	public UT2004CaptureTheFlagConfig setTimeLimit(int timeLimitInMinutes) {
92  		if (timeLimitInMinutes < 1) {
93  			throw new PogamutException("Time limit can't be " + timeLimitInMinutes + " < 1 min.", this);
94  		}
95  		this.timeLimitInMin = timeLimitInMinutes;
96  		getGb2004Ini().setCTFTimeLimit(timeLimitInMinutes);
97  		return this;
98  	}
99  
100 
101 	public UT2004CaptureTheFlagConfig setUccConf(UCCWrapperConf uccConf) {
102 		super.setUccConf(uccConf);
103 		return this;
104 	}
105 	
106 	/**
107 	 * Values from current Frag/Time limit are automatically copied into the ini.
108 	 */
109 	public UT2004CaptureTheFlagConfig setGb2004Ini(GameBots2004Ini gb2004Ini) {
110 		super.setGb2004Ini(gb2004Ini);
111 		if (getGb2004Ini() != null) {
112 			if (getGb2004Ini().getDMFragLimit() != null) {
113 				this.scoreLimit = getGb2004Ini().getCTFScoreLimit();
114 			} else {
115 				getGb2004Ini().setDMFragLimit(scoreLimit);
116 			}
117 			if (getGb2004Ini().getDMTimeLimit() != null) {
118 				this.timeLimitInMin = getGb2004Ini().getCTFTimeLimit();
119 			} else {
120 				getGb2004Ini().setDMTimeLimit(timeLimitInMin);
121 			}
122 		}
123 		return this;
124 	}
125 
126 	public UT2004CaptureTheFlagConfig setBots(Map<IToken, UT2004BotConfig> bots) {
127 		super.setBots(bots);
128 		return this;
129 	}
130 	
131 	public UT2004CaptureTheFlagConfig setNativeBots(Map<IToken, UT2004NativeBotConfig> nativeBots) {
132 		super.setNativeBots(nativeBots);
133 		return this;
134 	}
135 	
136 	public UT2004CaptureTheFlagConfig addBot(UT2004BotConfig... bots) {
137 		super.addBot(bots);
138 		return this;
139 	}
140 	
141 	public UT2004MatchConfig setBot(UT2004BotConfig... bots) {
142 		super.setBot(bots);
143 		return this;
144 	}
145 	
146 	public UT2004CaptureTheFlagConfig addNativeBot(UT2004NativeBotConfig... bots) {
147 		super.addNativeBot(bots);
148 		return this;
149 	}
150 	
151 	public UT2004MatchConfig setNativeBot(UT2004NativeBotConfig... bots) {
152 		super.setNativeBot(bots);
153 		return this;
154 	}
155 	
156 	@Override
157 	protected void validateInner() {
158 		super.validateInner();
159 		if (scoreLimit <= 0) {
160 			validationError = true;
161 			validationBuffer.append(Const.NEW_LINE);
162 			validationBuffer.append("ScoreLimit = " + scoreLimit + " <= 0");
163 		}
164 		if (timeLimitInMin < 1) {
165 			validationError = true;
166 			validationBuffer.append(Const.NEW_LINE);
167 			validationBuffer.append("TimeLimit = " + timeLimitInMin + " < 1 min.");
168 		}
169 		if (getGb2004Ini().getDMFragLimit() <= 0) {
170 			validationError = true;
171 			validationBuffer.append(Const.NEW_LINE);
172 			validationBuffer.append("GameBots2004.ini ScoreLimit = " + getGb2004Ini().getCTFScoreLimit() + " <= 0.");
173 		}
174 		if (getGb2004Ini().getDMTimeLimit() < 1) {
175 			validationError = true;
176 			validationBuffer.append(Const.NEW_LINE);
177 			validationBuffer.append("GameBots2004.ini TimeLimit = " + getGb2004Ini().getCTFTimeLimit() + " < 1 min.");
178 		}
179 	}
180 
181 }