View Javadoc

1   /**
2    * BaseUnrealEnvironment, an implementation of the environment interface standard that 
3    * facilitates the connection between GOAL and the UT2004 engine. 
4    * 
5    * Copyright (C) 2012 BaseUnrealEnvironment authors.
6    * 
7    * This program is free software: you can redistribute it and/or modify it under
8    * the terms of the GNU General Public License as published by the Free Software
9    * Foundation, either version 3 of the License, or (at your option) any later
10   * version.
11   * 
12   * This program is distributed in the hope that it will be useful, but WITHOUT
13   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14   * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15   * details.
16   * 
17   * You should have received a copy of the GNU General Public License along with
18   * this program. If not, see <http://www.gnu.org/licenses/>.
19   */
20  package nl.tudelft.goal.unreal.messages;
21  
22  import java.util.logging.Level;
23  
24  import nl.tudelft.goal.ut2004.util.Skin;
25  import nl.tudelft.goal.ut2004.util.Team;
26  import cz.cuni.amis.pogamut.base.agent.impl.AgentId;
27  import cz.cuni.amis.pogamut.base.agent.params.IAgentParameters;
28  import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
29  import cz.cuni.amis.pogamut.base3d.worldview.object.Rotation;
30  import cz.cuni.amis.pogamut.ut2004.bot.params.UT2004BotParameters;
31  /**
32   * Holds parameters specific for the bot.
33   * <ul>
34   * Parameters stored are:
35   * <li>{@link BotParametersKey#BOTNAME}</li>
36   * <li>{@link BotParametersKey#LEADTARGET}</li>
37   * <li>{@link BotParametersKey#LOGLEVEL}</li>
38   * <li>{@link BotParametersKey#BOT_SERVER}</li>
39   * <li>{@link BotParametersKey#SKILL}</li>
40   * <li>{@link BotParametersKey#SKIN}</li>
41   * <li>{@link BotParametersKey#TEAM}</li>
42   * <li>{@link BotParametersKey#STARTLOCATION}</li>
43   * <li>{@link BotParametersKey#STARTROTATION}</li>
44   * </ul>
45   * 
46   * Also provides functionality to assign defaults to parameters that have not
47   * been assigned.
48   * 
49   * @author M.P. Korstanje
50   * 
51   */
52  public class BotParameters extends Parameters  {
53  	
54  	// Bot parameters
55  	private Level logLevel;
56  	private Boolean shouldLeadTarget;
57  	private Integer skill;
58  	private Skin skin;
59  
60  
61  	@Override
62  	public void assignDefaults(IAgentParameters defaults) {
63  		super.assignDefaults(defaults);
64  
65  		if (defaults instanceof BotParameters) {
66  			BotParameters parameters = (BotParameters) defaults;
67  
68  			if (logLevel == null)
69  				logLevel = parameters.getLogLevel();
70  			if (shouldLeadTarget == null)
71  				shouldLeadTarget = parameters.shouldLeadTarget();
72  			if (skill == null)
73  				skill = parameters.getSkill();
74  			if (skin == null)
75  				skin = parameters.getSkin();
76  		}
77  	}
78  
79  	public Level getLogLevel() {
80  		return logLevel;
81  	}
82  
83  	public int getSkill() {
84  		return skill;
85  	}
86  
87  	public Skin getSkin() {
88  
89  		return skin;
90  	}
91  
92  	public BotParameters setLogLevel(Level level) {
93  		assert level != null;
94  		this.logLevel = level;
95  		return this;
96  	}
97  
98  	public BotParameters setShouldLeadTarget(boolean shouldLeadTarget) {
99  		this.shouldLeadTarget = shouldLeadTarget;
100 		return this;
101 	}
102 
103 	/**
104 	 * Sets the bots skill between 0..7. The bots skill only influences the bots
105 	 * accuracy. Values outside the valid range are clamped.
106 	 * 
107 	 * @param skill
108 	 *            an integer in the range 0..7
109 	 */
110 	public BotParameters setSkill(int skill) {
111 		// Clamp between 0 and 7.
112 		this.skill = Math.min(7, Math.max(skill, 0));
113 		return this;
114 	}
115 
116 	public BotParameters setSkin(Skin skin) {
117 		this.skin = skin;
118 		return this;
119 	}
120 
121 	/**
122 	 * Sets the bots preferred team. Typically teams are either 0 or 1.
123 	 * 
124 	 * @param team
125 	 */
126 	public BotParameters setTeam(Team team) {
127 		super.setTeam(team.id());
128 		return this;
129 	}
130 
131 	@Override
132 	public BotParameters setInitialLocation(Location location) {
133 		super.setInitialLocation(location);
134 		return this;
135 	}
136 	
137 	@Override
138 	public BotParameters setInitialRotation(Rotation rotation) {
139 		super.setInitialRotation(rotation);
140 		return this;
141 	}
142 
143 	public Boolean shouldLeadTarget() {
144 		return shouldLeadTarget;
145 	}
146 
147 	@Override
148 	public String toString() {
149 		return "BotParameters [logLevel=" + logLevel + ", shouldLeadTarget=" + shouldLeadTarget + ", skill=" + skill
150 				+ ", skin=" + skin + ", getTeam()=" + getTeam() + ", getWorldAddress()=" + getWorldAddress()
151 				+ ", getAgentId()=" + getAgentId() + "]";
152 	}
153 	
154 	public UT2004BotParameters setAgentId(String agentName) {
155 		super.setAgentId(new AgentId(agentName));
156 		return this;
157 	}
158 
159 	
160 	public static BotParameters getDefaults() {
161 
162 		BotParameters parameters = new BotParameters();
163 
164 		parameters.logLevel = Level.WARNING;
165 		parameters.shouldLeadTarget = true;
166 		parameters.skill = 3;
167 		parameters.skin = Skin.BotB;
168 		
169 		return parameters;
170 	}
171 
172 
173 
174 
175 }