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 	 * (issues GB ROTATE command)
108 	 * 
109 	 * @param amount
110 	 *            Amount of rotation in degrees.
111 	 * 
112 	 * @see turnHorizontal(int)
113 	 * @see turnTo(ILocated)
114 	 */
115 	public void turnVertical(int amount) {
116 		Rotate rotate = new Rotate();
117 		// full rotation in UT units is 65535
118 		rotate.setAmount(amount * 65535 / 360);
119 		rotate.setAxis("Vertical");
120 		agent.getAct().act(rotate);
121 	}
122 
123 	/**
124 	 * Bot will make simple jump (Issues GB JUMP command)
125 	 */
126 	public void jump() {
127 		agent.getAct().act(new Jump());
128 	}
129 
130 	/**
131 	 * Sets the walking speed for the bot movement commands. (issues GB SETWALK
132 	 * command)
133 	 * 
134 	 * @see setRun()
135 	 */
136 	public void setWalk() {
137 		agent.getAct().act(new SetWalk().setWalk(true));
138 	}
139 
140 	/**
141 	 * Sets the running speed for the bot movement commands. (issues GB SETWALK
142 	 * command)
143 	 * 
144 	 * @see setWalk()
145 	 */
146 	public void setRun() {
147 		agent.getAct().act(new SetWalk().setWalk(false));
148 	}
149 
150 	/**
151 	 * Constructor. Setups the command module based on given agent and logger.
152 	 * 
153 	 * @param agent
154 	 *            AbstractUT2004Bot we will send commands for
155 	 * @param log
156 	 *            Logger to be used for logging runtime/debug info.
157 	 */
158 	public SimpleLocomotion(UT2004Bot agent, Logger log) {
159 		super(agent, log);
160 	}
161 }