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  	/**
51  	 * Constructs Ini file with defaults taken from 'classpath:/cz/cuni/amis/pogamut/ut2004/tournament/deathmatch/GameBots2004-Deathmatch.ini'.
52  	 */
53  	public GameBots2004Ini() {
54  		InputStream defaults = GameBots2004Ini.class.getResourceAsStream("/cz/cuni/amis/pogamut/ut2004/tournament/deathmatch/GameBots2004-Deathmatch.ini");
55  		load(defaults);
56  	}
57  	
58  	/**
59  	 * Constructs GameBots2004Ini with defaults taken 'source' (file must exists!).
60  	 * 
61  	 * @param source
62  	 */
63  	public GameBots2004Ini(File source) {
64  		if (!source.exists()) {
65  			throw new PogamutException("File with defaults for GameBots2004.ini does not exist at: " + source.getAbsolutePath() + ".", this);
66  		}
67  		load(source);
68  	}
69  	
70  	public GameBots2004Ini(GameBots2004Ini gb2004Ini) {
71  		super(gb2004Ini);
72  	}
73  
74  	/**
75  	 * Returns time limit of the death match game in minutes (or null if not specified).
76  	 * @return
77  	 */
78  	public Integer getDMTimeLimit() {
79  		String value = get(Section_GameBots2004_BotDeathMatch, Key_DM_TimeLimit);
80  		if (value == null) return null;
81  		return Integer.parseInt(value);
82  	}
83  	
84  	/**
85  	 * Sets time limit of the death match game in minutes.
86  	 * 
87  	 * @param timeLimitInMin
88  	 */
89  	public void setDMTimeLimit(int timeLimitInMin) {
90  		set(Section_GameBots2004_BotDeathMatch, Key_DM_TimeLimit, String.valueOf(timeLimitInMin));
91  	}
92  	
93  	/**
94  	 * Gets frag limit of the death match game (or null if not specified).
95  	 * @return
96  	 */
97  	public Integer getDMFragLimit() {
98  		String value = get(Section_GameBots2004_BotDeathMatch, Key_DM_FragLimit);
99  		if (value == null) return null;
100 		return Integer.parseInt(value);
101 	}
102 	
103 	/**
104 	 * Sets frag limit of the death match game.
105 	 * @param fragLimitInSecs
106 	 */
107 	public void setDMFragLimit(int fragLimit) {
108 		set(Section_GameBots2004_BotDeathMatch, Key_DM_FragLimit, String.valueOf(fragLimit));
109 	}
110 	
111 	/**
112 	 * Returns time limit of the capture-the-flag game in minutes (or null if not specified).
113 	 * @return
114 	 */
115 	public Integer getCTFTimeLimit() {
116 		String value = get(Section_GameBots2004_BotCTFGame, Key_CTF_TimeLimit);
117 		if (value == null) return null;
118 		return Integer.parseInt(value);
119 	}
120 	
121 	/**
122 	 * Sets time limit of the capture-the-flag game in minutes.
123 	 * 
124 	 * @param timeLimitInMin
125 	 */
126 	public void setCTFTimeLimit(int timeLimitInMin) {
127 		set(Section_GameBots2004_BotCTFGame, Key_CTF_TimeLimit, String.valueOf(timeLimitInMin));
128 	}
129 	
130 	/**
131 	 * Gets frag limit of the capture-the-flag game (or null if not specified).
132 	 * @return
133 	 */
134 	public Integer getCTFScoreLimit() {
135 		String value = get(Section_GameBots2004_BotCTFGame, Key_CTF_ScoreLimit);
136 		if (value == null) return null;
137 		return Integer.parseInt(value);
138 	}
139 	
140 	/**
141 	 * Sets score limit of the capture-the-flag game.
142 	 * @param fragLimitInSecs
143 	 */
144 	public void setCTFScoreLimit(int scoreLimit) {
145 		set(Section_GameBots2004_BotCTFGame, Key_CTF_ScoreLimit, String.valueOf(scoreLimit));
146 	}
147 	
148 }