View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.utils;
2   
3   import cz.cuni.amis.pogamut.base.utils.DefaultPogamutPlatform;
4   import cz.cuni.amis.pogamut.base.utils.Pogamut;
5   import cz.cuni.amis.pogamut.base.utils.PogamutPlatformProxy;
6   import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.AgentInfo;
7   import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.visibility.model.VisibilityMatrix;
8   import cz.cuni.amis.pogamut.ut2004.bot.IUT2004BotController;
9   import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
10  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.Initialize;
11  
12  public enum PogamutUT2004Property {
13  	/**
14  	 * Where the bot should connect to (hostname of the server running
15  	 * GameBots2004)
16  	 */
17  	POGAMUT_UT2004_BOT_HOST("pogamut.ut2004.bot.host", String.class, "localhost"),
18  
19  	/**
20  	 * Where the bot should connect to (bot port of the GameBots2004).
21  	 */
22  	POGAMUT_UT2004_BOT_PORT("pogamut.ut2004.bot.port", Integer.class, 3000),
23  
24  	/**
25  	 * Where the server should connect to (hostname of the server running
26  	 * GameBots2004)
27  	 */
28  	POGAMUT_UT2004_SERVER_HOST("pogamut.ut2004.server.host", String.class, "localhost"),
29  
30  	/**
31  	 * Where the server should connect to (server port of the GameBots2004)
32  	 */
33  	POGAMUT_UT2004_SERVER_PORT("pogamut.ut2004.server.port", Integer.class, 3001),
34  
35  	/**
36  	 * Where the observer should connect to (hostname of the server running
37  	 * GameBots2004)
38  	 */
39  	POGAMUT_UT2004_OBSERVER_HOST("pogamut.ut2004.observer.host", String.class, "localhost"),
40  
41  	/**
42  	 * Where the observer should connect to (observer port of the GameBots2004)
43  	 */
44  	POGAMUT_UT2004_OBSERVER_PORT("pogamut.ut2004.observer.port", Integer.class, 3002),
45  
46  	/** Path to the Unreal home dir. */
47  	POGAMUT_UNREAL_HOME("pogamut.ut2004.home", String.class, null),
48  
49  	/** Should tests use external UCC instance or they will run internal one? */
50  	POGAMUT_UNREAL_TEST_EXT_SERVER("pogamut.test.useExternalUCC", Boolean.class, false), 
51  	
52  	/**
53  	 * Whether UT2004PathExecutor is using SetRoute command (causes RED LINE to appear in UT2004 GUI when enablind "display bot routes").
54  	 */
55  	POGAMUT_UT2004_PATH_EXECUTOR_SEND_SET_ROUTE("pogamut.ut2004.path_executor.send_set_route", Boolean.class, false),
56  	
57  	/**
58  	 * Directory where to search for {@link VisibilityMatrix}es for respective maps.
59  	 */
60  	POGAMUT_UT2004_VISIBILITY_DIRECTORY("pogamut.ut2004.visibility.dir", String.class, "."),
61  	
62  	/**
63  	 * Boolean parameter (true/false) that affects how {@link UT2004Bot} works with {@link IUT2004BotController#getInitializeCommand()}.<br/>
64  	 * False == provide parameters only if NOT specified<br/>
65  	 * True == always set the parameters into {@link Initialize} command (i.e., override any existing settings). 
66  	 */
67  	POGAMUT_UT2004_BOT_INIT_OVERRIDE_PARAMS("pogamut.ut2004.bot.init.override", Boolean.class, false),
68  	
69  	/**
70  	 * Integer parameter (0, 1, 2, 3, 255) that sets team the bot should join into. See {@link AgentInfo} for team constants (e.g. {@link AgentInfo#TEAM_RED}) 
71  	 */
72  	POGAMUT_UT2004_BOT_INIT_TEAM("pogamut.ut2004.bot.init.team", Integer.class, 255),
73  	
74  	/**
75  	 * Integer parameter (0, 1, 2, 3, 4, 5, 6, 7) that sets skill level for the bot, see {@link Initialize#setDesiredSkill(Integer)}.
76  	 */
77  	POGAMUT_UT2004_BOT_INIT_SKILL("pogamut.ut2004.bot.init.skill", Integer.class, 5),
78  	
79  	/**
80  	 * String parameter that sets the skin for the bot, see {@link Initialize#setSkin(String)}.
81  	 */
82  	POGAMUT_UT2004_BOT_INIT_SKIN("pogamut.ut2004.bot.init.skin", String.class, null),
83  	
84  	/**
85  	 * String parameter that sets the name for the bot, see {@link Initialize#setName(String)}.
86  	 */
87  	POGAMUT_UT2004_BOT_INIT_NAME("pogamut.ut2004.bot.init.name", String.class, null),	
88  	;
89  
90  	private String key;
91  	private Class type;
92  	private Object defaultValue;
93  
94  	private PogamutUT2004Property(String key, Class type, Object defaultValue) {
95  		this.key = key;
96  		this.type = type;
97  		this.defaultValue = defaultValue;
98  	}
99  
100 	public String getKey() {
101 		return key;
102 	}
103 
104 	public String toString() {
105 		return key;
106 	}
107 	
108 	public Object getValue() {
109 		String value = Pogamut.getPlatform().getProperty(getKey());
110 		if (value == null) return getDefaultValue();
111 		if (type == String.class) {
112 			return value;
113 		} else
114 		if (type == Integer.class) {
115 			try {
116 				return Integer.parseInt(value);
117 			} catch (Exception e) {
118 				return getDefaultValue();
119 			}
120 		} else
121 		if (type == Float.class) {
122 			try {
123 				return Float.parseFloat(value);
124 			} catch (Exception e) {
125 				return getDefaultValue();
126 			}
127 		} else
128 		if (type == Double.class) {
129 			try {
130 				return Double.parseDouble(value);
131 			} catch (Exception e) {
132 				return getDefaultValue();
133 			}
134 		} else
135 		if (type == Boolean.class) {
136 			if (value.toLowerCase().equals("true")) return true;
137 			return false;
138 		} else {
139 			throw new RuntimeException("Unsupported property type: " + type.getSimpleName());
140 		}
141 	}
142 	
143 	public Object getDefaultValue() {
144 		return defaultValue;
145 	}
146 }