View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.tournament;
2   
3   import java.io.File;
4   import java.io.InputStream;
5   import java.net.URISyntaxException;
6   
7   import cz.cuni.amis.utils.IniFile;
8   import cz.cuni.amis.utils.exception.PogamutException;
9   
10  /**
11   * Ordinary {@link IniFile} that loads its defaults from classpath:/cz/cuni/amis/pogamut/ut2004/tournament/deathmatch/GameBots2004-Deathmatch.ini 
12   * if not specified.
13   * <p><p>
14   * Additionally it provides definitions of common constants that applies to the GameBots2004.ini as well as handy shortcuts for setting
15   * various interesting properties such as time limit or frag limit, etc.
16   * 
17   * @author Jimmy
18   */
19  public class GameBots2004Ini extends IniFile {
20  
21  	//
22  	// SECTION
23  	// 
24  	
25  	public static final String Section_GameBots2004_BotConnection = "GameBots2004.BotConnection";
26  	public static final String Section_GameBots2004_RemoteBot = "GameBots2004.RemoteBot";
27  	public static final String Section_GameBots2004_GBHUD = "GameBots2004.GBHUD";
28  	public static final String Section_GameBots2004_ControlConnection = "GameBots2004.ControlConnection";
29  	public static final String Section_GameBots2004_ControlServer = "GameBots2004.ControlServer";
30  	public static final String Section_GameBots2004_BotScenario = "GameBots2004.BotScenario";
31  	public static final String Section_GameBots2004_BotDeathMatch = "GameBots2004.BotDeathMatch";
32  	public static final String Section_GameBots2004_BotTeamGame = "GameBots2004.BotTeamGame";
33  	public static final String Section_GameBots2004_BotCTFGame = "GameBots2004.BotCTFGame";
34  	public static final String Section_GameBots2004_BotDoubleDomination = "GameBots2004.BotDoubleDomination";
35  	public static final String Section_Engine_GameInfo = "Engine.GameInfo";
36  	public static final String Section_UnrealGame_UnrealMPGameInfo = "UnrealGame.UnrealMPGameInfo";
37  	public static final String Section_UnrealGame_DeathMatch = "UnrealGame.DeathMatch";
38  	public static final String Section_GameBots2004_GBScenarioMutator = "GameBots2004.GBScenarioMutator";
39  	
40  	//
41  	// PROPERTY KEYS
42  	//
43  	
44  	public static final String Key_DM_TimeLimit = "TimeLimit";
45  	public static final String Key_DM_FragLimit = "GoalScore";
46  	
47  	public static final String Key_CTF_TimeLimit = "TimeLimit";
48  	public static final String Key_CTF_ScoreLimit = "GoalScore";
49  	
50  	public static final String Key_CC_UpdateTime = "UpdateTime";
51  	
52  	/**
53  	 * Constructs Ini file with defaults taken from 'classpath:/cz/cuni/amis/pogamut/ut2004/tournament/deathmatch/GameBots2004-Deathmatch.ini'.
54  	 */
55  	public GameBots2004Ini() {
56  		InputStream defaults = GameBots2004Ini.class.getResourceAsStream("/cz/cuni/amis/pogamut/ut2004/tournament/deathmatch/GameBots2004-Deathmatch.ini");
57  		load(defaults);
58  	}
59  	
60  	/**
61  	 * Constructs GameBots2004Ini with defaults taken 'source' (file must exists!).
62  	 * 
63  	 * @param source
64  	 */
65  	public GameBots2004Ini(File source) {
66  		if (!source.exists()) {
67  			throw new PogamutException("File with defaults for GameBots2004.ini does not exist at: " + source.getAbsolutePath() + ".", this);
68  		}
69  		load(source);
70  	}
71  	
72  	public GameBots2004Ini(GameBots2004Ini gb2004Ini) {
73  		super(gb2004Ini);
74  	}
75  
76  	/**
77  	 * Returns time limit of the death match game in minutes (or null if not specified).
78  	 * @return
79  	 */
80  	public Integer getDMTimeLimit() {
81  		String value = get(Section_GameBots2004_BotDeathMatch, Key_DM_TimeLimit);
82  		if (value == null) return null;
83  		return Integer.parseInt(value);
84  	}
85  	
86  	/**
87  	 * Sets time limit of the death match game in minutes.
88  	 * 
89  	 * @param timeLimitInMin
90  	 */
91  	public void setDMTimeLimit(int timeLimitInMin) {
92  		set(Section_GameBots2004_BotDeathMatch, Key_DM_TimeLimit, String.valueOf(timeLimitInMin));
93  	}
94  	
95  	/**
96  	 * Gets frag limit of the death match game (or null if not specified).
97  	 * @return
98  	 */
99  	public Integer getDMFragLimit() {
100 		String value = get(Section_GameBots2004_BotDeathMatch, Key_DM_FragLimit);
101 		if (value == null) return null;
102 		return Integer.parseInt(value);
103 	}
104 	
105 	/**
106 	 * Sets frag limit of the death match game.
107 	 * @param fragLimitInSecs
108 	 */
109 	public void setDMFragLimit(int fragLimit) {
110 		set(Section_GameBots2004_BotDeathMatch, Key_DM_FragLimit, String.valueOf(fragLimit));
111 	}
112 	
113 	/**
114 	 * Returns time limit of the capture-the-flag game in minutes (or null if not specified).
115 	 * @return
116 	 */
117 	public Integer getCTFTimeLimit() {
118 		String value = get(Section_GameBots2004_BotCTFGame, Key_CTF_TimeLimit);
119 		if (value == null) return null;
120 		return Integer.parseInt(value);
121 	}
122 	
123 	/**
124 	 * Sets time limit of the capture-the-flag game in minutes.
125 	 * 
126 	 * @param timeLimitInMin
127 	 */
128 	public void setCTFTimeLimit(int timeLimitInMin) {
129 		set(Section_GameBots2004_BotCTFGame, Key_CTF_TimeLimit, String.valueOf(timeLimitInMin));
130 	}
131 	
132 	/**
133 	 * Gets frag limit of the capture-the-flag game (or null if not specified).
134 	 * @return
135 	 */
136 	public Integer getCTFScoreLimit() {
137 		String value = get(Section_GameBots2004_BotCTFGame, Key_CTF_ScoreLimit);
138 		if (value == null) return null;
139 		return Integer.parseInt(value);
140 	}
141 	
142 	/**
143 	 * Sets score limit of the capture-the-flag game.
144 	 * @param fragLimitInSecs
145 	 */
146 	public void setCTFScoreLimit(int scoreLimit) {
147 		set(Section_GameBots2004_BotCTFGame, Key_CTF_ScoreLimit, String.valueOf(scoreLimit));
148 	}
149 	
150 	/**
151 	 * Returns update time (in seconds) set for ControlConnection. 
152 	 * @return
153 	 */
154 	public Double getControlConnectionUpdateTime() {
155 		String value = get(Section_GameBots2004_BotCTFGame, Key_CTF_ScoreLimit);
156 		if (value == null) return null;
157 		return Double.parseDouble(value);
158 	}
159 
160 	/**
161 	 * Sets frequency of updates for control connection.
162 	 * @param timeInSeconds
163 	 */
164 	public void setControlConnectionUpdateTime(double timeInSeconds) {
165 		set(Section_GameBots2004_ControlConnection, Key_CC_UpdateTime, String.valueOf(timeInSeconds));		
166 	}
167 	
168 }