View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.bot.command;
2   
3   import java.util.logging.Logger;
4   
5   import cz.cuni.amis.pogamut.base3d.worldview.object.ILocated;
6   import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
7   import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.Jump;
8   import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.Move;
9   import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.Rotate;
10  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.SetWalk;
11  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.Stop;
12  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.TurnTo;
13  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Item;
14  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player;
15  
16  /**
17   * Class providing Pogamut2 UT2004 simple locomotion commands for the bot -
18   * basic movement and turning.
19   * 
20   * @author Michal 'Knight' Bida
21   */
22  public class SimpleLocomotion extends BotCommands {
23  
24  	/**
25  	 * Bot will move to supplied location. (issues GB MOVE command)
26  	 * 
27  	 * @param locatedTarget
28  	 *            Object with location. We will move to this location.
29  	 * 
30  	 * @see stopMovement()
31  	 */
32  	public void moveTo(ILocated location) {
33  		Move move = new Move().setFirstLocation(location.getLocation());
34  		agent.getAct().act(move);
35  	}
36  
37  	/**
38  	 * Makes the bot to stop all movement or turning. (Does not stop shooting.)
39  	 * 
40  	 * (issues GB STOP command)
41  	 * 
42  	 * @see moveTo(ILocated)
43  	 */
44  	public void stopMovement() {
45  		agent.getAct().act(new Stop());
46  	}
47  
48  	/**
49  	 * Bot will turn to face supported location (issues GB TURNTO command)
50  	 * 
51  	 * @param location
52  	 *            Location we will face.
53  	 * 
54  	 * @see turnHorizontal(int)
55  	 * @see turnVertical(int)
56  	 */
57  	public void turnTo(ILocated location) {
58  		TurnTo turnTo = new TurnTo();
59  		turnTo.setLocation(location.getLocation());
60  		agent.getAct().act(turnTo);
61  	}
62  	
63  	/**
64  	 * Bot will turn to face 'player' (isseus GB TURNTO command), the bot will face the player even if it or the player moves.
65  	 * 
66  	 * @param player
67  	 * 			Player we will face.
68  	 * 
69  	 */
70  	public void turnTo(Player player) {
71      	TurnTo turnTo = new TurnTo();
72  		turnTo.setTarget(player.getId());
73  		agent.getAct().act(turnTo);
74      }
75      
76  	/**
77  	 * Bot will turn to face 'item' (isseus GB TURNTO command), the bot will face the item even if it or the item moves.
78  	 * 
79  	 * @param item
80  	 * 			Item we will face.
81  	 */
82      public void turnTo(Item item) {
83      	TurnTo turnTo = new TurnTo();
84  		turnTo.setTarget(item.getId());
85  		agent.getAct().act(turnTo);
86      }
87  
88  	/**
89  	 * Rotates the bot by the supported amount (in degrees) in left/right
90  	 * direction (issues GB ROTATE command)
91  	 * 
92  	 * @param amount
93  	 *            Amount of rotation in degrees.
94  	 * 
95  	 * @see turnVertical(int)
96  	 * @see turnTo(ILocated)
97  	 */
98  	public void turnHorizontal(int amount) {
99  		Rotate rotate = new Rotate();
100 		// full rotation in UT units is 65535
101 		rotate.setAmount(amount * 65535 / 360);
102 		agent.getAct().act(rotate);
103 	}
104 
105 	/**
106 	 * Rotates the bot by the supported amount (in degrees) in up/down direction.	
107 	 * Note: This moves bot's head which is unable to rotate freely in 360 degrees.
108 	 * There is a certain angle limit (close to look perpendicular to the floor plane).
109 	 * Going beyond this limit results in bot turning horizontaly in place and looking
110 	 * to desired position under complementary angle.
111 	 * (issues GB ROTATE command)
112 	 * 
113 	 * @param amount
114 	 *            Amount of rotation in degrees.
115 	 * 
116 	 * @see turnHorizontal(int)
117 	 * @see turnTo(ILocated)
118 	 */
119 	public void turnVertical(int amount) {
120 		Rotate rotate = new Rotate();
121 		// full rotation in UT units is 65535
122 		rotate.setAmount(amount * 65535 / 360);
123 		rotate.setAxis("Vertical");
124 		agent.getAct().act(rotate);
125 	}
126 
127 	/**
128 	 * Bot will make simple jump (Issues GB JUMP command)
129 	 */
130 	public void jump() {
131 		agent.getAct().act(new Jump());
132 	}
133 
134 	/**
135 	 * Sets the walking speed for the bot movement commands. (issues GB SETWALK
136 	 * command)
137 	 * 
138 	 * @see setRun()
139 	 */
140 	public void setWalk() {
141 		agent.getAct().act(new SetWalk().setWalk(true));
142 	}
143 
144 	/**
145 	 * Sets the running speed for the bot movement commands. (issues GB SETWALK
146 	 * command)
147 	 * 
148 	 * @see setWalk()
149 	 */
150 	public void setRun() {
151 		agent.getAct().act(new SetWalk().setWalk(false));
152 	}
153 
154 	/**
155 	 * Constructor. Setups the command module based on given agent and logger.
156 	 * 
157 	 * @param agent
158 	 *            AbstractUT2004Bot we will send commands for
159 	 * @param log
160 	 *            Logger to be used for logging runtime/debug info.
161 	 */
162 	public SimpleLocomotion(UT2004Bot agent, Logger log) {
163 		super(agent, log);
164 	}
165 }