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.ut2004.bot.impl.UT2004Bot;
6   import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
7   import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.SendMessage;
8   import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Self;
9   
10  /**
11   * Class providing Pogamut2 UT2004 communication commands - send message, set
12   * dialogs, text bubble...
13   * 
14   * @author Michal 'Knight' Bida
15   */
16  public class Communication extends BotCommands {
17  
18  	/**
19  	 * Sends global message to UT2004 in-game chat. Everyone will see it, bots
20  	 * will receive information too.
21  	 * 
22  	 * (issues GB MESSAGE command)
23  	 * 
24  	 * @param text
25  	 *            Text of the message to send.
26  	 * 
27  	 * @see sendTeamTextMessage(String)
28  	 * @see sendPrivateTextMessage(UnrealId, String)
29  	 */
30  	public void sendGlobalTextMessage(String text) {
31  		SendMessage message = new SendMessage();
32  
33  		message.setGlobal(true);
34  		message.setText(text);
35  		// This will cause that the text bubble won't be shown.
36  		message.setFadeOut((double)-1);
37  
38  		agent.getAct().act(message);
39  	}
40  
41  	/**
42  	 * Sends a message to UT2004 in-game chat. Only members of the bot current
43  	 * team will see it. If there are no teams (e.g. no team game, just simple
44  	 * deathmatch) it will be handled as global message.
45  	 * 
46  	 * (issues GB MESSAGE command)
47  	 * 
48  	 * @param text
49  	 *            Text of the message to send.
50  	 * 
51  	 * @see sendGlobalTextMessage(String)
52  	 * @see sendPrivateTextMessage(UnrealId, String)
53  	 */
54  	public void sendTeamTextMessage(String text) {
55  		SendMessage message = new SendMessage();
56  
57  		message.setGlobal(false);
58  		message.setText(text);
59  		Self self = worldView.getSingle(Self.class);
60  		if (self != null) {
61  			message.setTeamIndex(self.getTeam());
62  		}
63  		// This will cause that the text bubble won't be shown.
64  		message.setFadeOut((double)-1);
65  
66  		agent.getAct().act(message);
67  	}
68  
69  	/**
70  	 * Sends a private message to desired bot (specified by Id). There will be
71  	 * added "Private:" string in front of the message. Works just for GameBots
72  	 * RemoteBots. If the id is not of RemoteBot nothing will happen - the
73  	 * message won't be sent to anyone.
74  	 * 
75  	 * @param id
76  	 *            Here we can specify Id of the bot, that will receive this
77  	 *            message privately.
78  	 * @param text
79  	 *            Text of the message to send.
80  	 * 
81  	 * @see sendGlobalTextMessage(String)
82  	 * @see sendTeamTextMessage(String)
83  	 * 
84  	 */
85  	public void sendPrivateTextMessage(UnrealId id, String text) {
86  		SendMessage message = new SendMessage();
87  
88  		message.setId(id);
89  		message.setText(text);
90  		// This will cause that the text bubble won't be shown.
91  		message.setFadeOut((double)-1);
92  
93  		agent.getAct().act(message);
94  	}
95  
96  	/**
97  	 * Sends a global message to UT2004 in-game chat and sets the text bubble
98  	 * visible to all human players above the bot head. Everyone will receive
99  	 * the message. The bubble will stay as long as specified in fadeOut
100 	 * variable.
101 	 * 
102 	 * @param text
103 	 *            Text of the message and bubble.
104 	 * @param fadeOut
105 	 *            Sets how long the bubble should stay visible (in seconds,
106 	 *            counted as 12 + fadeOut seconds - probably due to some UT
107 	 *            mechanics). If -1 the bubble won't be shown at all.
108 	 * 
109 	 * @see sendPrivateBubbleMessage(UnrealId, String, double)
110 	 * @see sendPrivateBubbleMessage(UnrealId, String, double)
111 	 */
112 	public void sendGlobalBubbleMessage(String text, double fadeOut) {
113 		SendMessage message = new SendMessage();
114 
115 		message.setGlobal(true);
116 		message.setText(text);
117 		message.setFadeOut(fadeOut);
118 
119 		agent.getAct().act(message);
120 	}
121 
122 	/**
123 	 * Sends a message to UT2004 in-game chat and sets the text bubble visible
124 	 * to all human players above the bot head. The message will be send just to
125 	 * players and bots from the same team (although other human players will
126 	 * still see it through text bubble). If not team game, treated as global
127 	 * message. The bubble will stay as long as specified in fadeOut variable.
128 	 * 
129 	 * @param text
130 	 *            Text of the message and bubble.
131 	 * @param fadeOut
132 	 *            Sets how long the bubble should stay visible (in seconds,
133 	 *            counted as 12 + fadeOut seconds - probably due to some UT
134 	 *            mechanics). If -1 the bubble won't be shown at all.
135 	 * 
136 	 * @see sendGlobalBubbleMessage(String, double)
137 	 * @see sendPrivateBubbleMessage(UnrealId, String, double)
138 	 */
139 	public void sendTeamBubbleMessage(String text, double fadeOut) {
140 		SendMessage message = new SendMessage();
141 
142 		message.setGlobal(false);
143 		message.setText(text);
144 		Self self = worldView.getSingle(Self.class);
145 		if (self != null) {
146 			message.setTeamIndex(self.getTeam());
147 		}
148 		message.setFadeOut(fadeOut);
149 
150 		agent.getAct().act(message);
151 	}
152 
153 	/**
154 	 * Sends a private message to desired bot (specified by Id). There will be
155 	 * added "Private:" string in front of the message. Also sets the text
156 	 * bubble above the bot head, that will be visible to all human players. The
157 	 * message can be received just by GameBots RemoteBots (although all human
158 	 * players will see it through text bubble).
159 	 * 
160 	 * @param id
161 	 *            Here we can specify Id of the bot, that will receive this
162 	 *            message privately. Other players will see this message through
163 	 *            bubble too.
164 	 * @param text
165 	 *            Text of the message and bubble.
166 	 * @param fadeOut
167 	 *            Sets how long the bubble should stay visible (in seconds,
168 	 *            counted as 12 + fadeOut seconds - probably due to some UT
169 	 *            mechanics). If -1 the bubble won't be shown at all.
170 	 * 
171 	 * @see sendGlobalBubbleMessage(String, double)
172 	 * @see sendTeamBubbleMessage(String, double)
173 	 */
174 	public void sendPrivateBubbleMessage(UnrealId id, String text,
175 			double fadeOut) {
176 		SendMessage message = new SendMessage();
177 
178 		message.setId(id);
179 		message.setText(text);
180 		message.setFadeOut(fadeOut);
181 
182 		agent.getAct().act(message);
183 	}
184 
185 	/**
186 	 * Constructor. Setups the command module based on given agent and logger.
187 	 * 
188 	 * @param agent
189 	 *            AbstractUT2004Bot we will send commands for
190 	 * @param log
191 	 *            Logger to be used for logging runtime/debug info.
192 	 */
193 	public Communication(UT2004Bot agent, Logger log) {
194 		super(agent, log);
195 	}
196 
197 }