View Javadoc

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