View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.utils;
2   
3   import java.io.Serializable;
4   import java.util.logging.Logger;
5   
6   import cz.cuni.amis.pogamut.base.utils.Pogamut;
7   
8   /**
9    * Configuration object of the UCC wrapper instance.
10   */
11  public class UCCWrapperConf implements Serializable {
12  
13  	/**
14  	 * Auto-generated. 
15  	 */
16  	private static final long serialVersionUID = -8577056681683055775L;
17  	
18  	protected UCCWrapperPatterns patterns = new UCCWrapperPatterns();
19  	protected String unrealHome = null;
20  	protected String mapName = "DM-TrainingDay";
21  	protected String gameBotsPack = "GameBots2004";
22  	protected String gameType = "BotDeathMatch";
23  	protected String mutators = "";
24  	protected String options = "";
25      /** Port for human player - UT2004 client uses this port to connect to the server. */    	
26  	protected int playerPort = -1;
27  	protected boolean startOnUnusedPort = true;
28      transient Logger log = null;
29  
30      public UCCWrapperConf() {        	
31      }
32      
33      public UCCWrapperConf(UCCWrapperConf uccConf) {
34      	this.patterns = new UCCWrapperPatterns(uccConf.getPatterns());
35  		this.unrealHome = uccConf.getUnrealHome();
36  		this.mapName = uccConf.getMapName();
37  		this.gameBotsPack = uccConf.getGameBotsPack();
38  		this.gameType = uccConf.getGameType();
39  		this.mutators = uccConf.getMutators();
40  		this.options = uccConf.getOptions();
41  		this.playerPort = uccConf.getPlayerPort();
42  		this.startOnUnusedPort = uccConf.isStartOnUnusedPort();
43  		this.log = uccConf.getLog();
44      }
45  
46      /** Returns the port for human player - UT2004 client uses this port to connect to the server. */
47  	public int getPlayerPort() {
48  		return playerPort;
49  	}
50  
51  	/** Sets the port for human player - UT2004 client uses this port to connect to the server. */
52  	public void setPlayerPort(int playerPort) {
53  		this.playerPort = playerPort;
54  	}
55  
56  	@Override
57      public String toString() {
58      	if (this == null) return "UCCWrapperConf";
59      	return getClass().getSimpleName() + "[unrealHome=" + unrealHome + ", gameBotsPack=" + gameBotsPack + ", gameType=" + gameType + ", mutators=" + mutators + ", options=" + options + ", startOnUnusedPorts=" + startOnUnusedPort + "]";
60      }
61      
62  	/**
63  	 * Sets patterns that recognizes UCC output for successful startup.		
64  	 * @return
65  	 */
66      public UCCWrapperPatterns getPatterns() {
67  		return patterns;
68  	}
69  
70      /**
71       * Sets patterns that recognizes UCC output for successful startup.
72       * @param patterns
73       */
74  	public void setPatterns(UCCWrapperPatterns patterns) {
75  		this.patterns = patterns;
76  	}
77  
78  	/**
79       * Returns Pogamut.getPlatform().getProperty(PogamutUT2004Property.POGAMUT_UNREAL_HOME) if not specified.
80       * @return
81       */
82      public String getUnrealHome() {
83      	if (unrealHome == null) {
84              return Pogamut.getPlatform().getProperty(PogamutUT2004Property.POGAMUT_UNREAL_HOME.getKey());
85          } else {
86              return unrealHome;
87          }
88  	}
89  
90      /**
91       * Sets path to the UT2004 directory, e.g., 'd:\\games\\ut2004'.
92       * <p><p>
93       * Should not need to be set if provided via property file.
94       * 
95       * @param unrealHome
96       */
97  	public void setUnrealHome(String unrealHome) {
98  		this.unrealHome = unrealHome;
99  	}
100 
101 	/**
102      * Forces UCC to find free port and start on it, otherwise it will start on ports 3000 + 3001.
103      * @param startOnUnusedPort
104      */
105     public UCCWrapperConf setStartOnUnusedPort(boolean startOnUnusedPort) {
106         this.startOnUnusedPort = startOnUnusedPort;
107         return this;
108     }
109 
110     /**
111      * Eg. GameBots2004, GBSceanrio etc.
112      * @param gameBotsPack
113      */
114     public UCCWrapperConf setGameBotsPack(String gameBotsPack) {
115         this.gameBotsPack = gameBotsPack;
116         return this;
117     }
118 
119     public UCCWrapperConf setMapName(String mapName) {
120         this.mapName = mapName;
121         return this;
122     }
123 
124     /**
125      * Eg. BotDeathMatch, BotCTFGame etc. Consult GameBots documentation for
126      * complete list available game types.
127      */
128     public UCCWrapperConf setGameType(String gameType) {
129         this.gameType = gameType;
130         return this;
131     }
132 
133     /**
134      * Can be used for setting mutators etc.
135      * @param options
136      */
137     public UCCWrapperConf setOptions(String options) {
138         this.options = options;
139         return this;
140     }
141 
142     /**
143      * Logger used by the UCC.
144      * @param log
145      */
146     public UCCWrapperConf setLogger(Logger log) {
147         this.log = log;
148         return this;
149     }
150 
151 	public String getMutators() {
152 		return mutators;
153 	}
154 
155 	public void setMutators(String mutators) {
156 		this.mutators = mutators;
157 	}
158 
159 	public Logger getLog() {
160 		return log;
161 	}
162 
163 	public void setLog(Logger log) {
164 		this.log = log;
165 	}
166 
167 	public String getMapName() {
168 		return mapName;
169 	}
170 
171 	public String getGameBotsPack() {
172 		return gameBotsPack;
173 	}
174 
175 	public String getGameType() {
176 		return gameType;
177 	}
178 
179 	public String getOptions() {
180 		return options;
181 	}
182 
183 	public boolean isStartOnUnusedPort() {
184 		return startOnUnusedPort;
185 	}
186     
187 }