1 package SocialSteeringsBeta;
2
3 import SteeringStuff.ISteering;
4 import SteeringStuff.RefBoolean;
5 import SteeringStuff.SteeringManager;
6 import SteeringStuff.SteeringTools;
7 import SteeringStuff.SteeringType;
8 import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
9 import cz.cuni.amis.pogamut.ut2004.agent.module.sensomotoric.Raycasting;
10 import cz.cuni.amis.pogamut.ut2004.bot.command.AdvancedLocomotion;
11 import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
12 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.Configuration;
13 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.Move;
14 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.SetWalk;
15 import javax.vecmath.Vector3d;
16
17
18
19
20
21 public class SocialSteeringManager extends SteeringManager {
22
23 protected IAnimationEngine animationEngine;
24 private int lastWS = 0;
25
26 public SocialSteeringManager(UT2004Bot bot, Raycasting raycasting, AdvancedLocomotion locomotion, IAnimationEngine engine, double multiplier) {
27 super(bot, raycasting, locomotion, multiplier);
28 animationEngine = engine;
29 }
30
31 public SocialSteeringManager(UT2004Bot bot, Raycasting raycasting, AdvancedLocomotion locomotion, IAnimationEngine engine) {
32 this(bot, raycasting, locomotion, engine, 1);
33
34 }
35
36
37
38
39
40
41
42
43
44
45
46
47 @Override
48 public void moveTheBot(Vector3d nextVelocity, boolean everyoneWantsToGoFaster, Location focusLocation) {
49
50 double precision;
51 if (nextVelocity instanceof SteeringResult && nextVelocity.length() > 0.001) {
52
53 precision = ((SteeringResult) nextVelocity).getAccurancyMultiplier();
54
55 } else if(nextVelocity.length() > 0.001){
56 if (animationEngine.canBeInterupt(botself)) {
57
58 if (SOC_STEER_LOG.DEBUG) {
59 SOC_STEER_LOG.AddLogLine("basic steering manager", SOC_STEER_LOG.KSync + botself.getName());
60 }
61
62 animationEngine.playAnimation(2, botself, true,0);
63
64 super.moveTheBot(nextVelocity, everyoneWantsToGoFaster, focusLocation);
65 return;
66 }else
67 {
68
69 if (SOC_STEER_LOG.DEBUG) {
70 SOC_STEER_LOG.AddLogLine("basic steering manager, wait for anim", SOC_STEER_LOG.KSync + botself.getName());
71 }
72
73 stopMovement(focusLocation);
74 return;
75 }
76 }else
77 {
78 precision = 0;
79 }
80
81 if (SteeringManager.DEBUG) System.out.println("Precision: "+precision);
82
83
84 int walkType;
85
86 double nextVelocityLength = nextVelocity.length() * multiplier;
87
88 if (precision == 0) {
89 walkType = 0;
90 } else if (precision < 3) {
91 walkType = 1;
92 } else if (nextVelocityLength < WALK_VELOCITY_LENGTH * 100)
93 {
94 walkType = 2;
95 } else
96 {
97 walkType = 3;
98 }
99
100
101
102
103
104
105
106
107
108
109
110 double nextVelMult = nextVelocityLength / WALK_VELOCITY_LENGTH;
111 nextVelocityLength = nextVelMult * WALK_VELOCITY_LENGTH;
112 nextVelocity.normalize();
113 nextVelocity.scale(nextVelocityLength);
114
115
116 myNextVelocity = new Vector3d(nextVelocity.x, nextVelocity.y, nextVelocity.z);
117 botself.getAct().act(new Configuration().setSpeedMultiplier(nextVelocityLength / WALK_VELOCITY_LENGTH).setAutoTrace(true).setDrawTraceLines(drawRaycasting));
118
119 if (SteeringManager.DEBUG) System.out.println("animationEngine.canBeInterupt "+animationEngine.canBeInterupt(botself));
120
121 if (animationEngine.canBeInterupt(botself)) {
122 switch (walkType) {
123 case 0:
124
125 if (SOC_STEER_LOG.DEBUG) {
126 SOC_STEER_LOG.AddLogLine("correct place, idling", SOC_STEER_LOG.KSync + botself.getName());
127 }
128
129 stopMovement( focusLocation);
130 if (SteeringManager.DEBUG) System.out.println("stopMovement1");
131 break;
132
133 case 1:
134
135 Location tLoc = new Location(botself.getLocation().x + nextVelocity.x, botself.getLocation().y + nextVelocity.y, botself.getLocation().z);
136
137 Move m = new Move();
138
139 int direction;
140 double angle = SteeringTools.getAngle(botself.getLocation(), botself.getRotation(), tLoc);
141 if(angle < Math.PI / 4)
142 {
143 direction = 0;
144 }else if (angle > ( Math.PI / 4) * 3 )
145 {
146 direction = 2;
147 }else
148 {
149 if(SteeringTools.pointIsLeftFromTheVector(focusLocation.sub(botself.getLocation()).asVector3d(), tLoc.asVector3d()))
150 {
151 direction = 3;
152 }else
153 {
154 direction = 1;
155 }
156 }
157
158 m.setFirstLocation(tLoc);
159 m.setFocusLocation(focusLocation);
160 Configuration c = new Configuration();
161
162 c.setSpeedMultiplier(0.4);
163 botself.getAct().act(c);
164
165 botself.getAct().act(m);
166
167 if (lastWS == walkType) {
168 break;
169 }
170 String s = "";
171 if (myNextVelocity.length() > 20) {
172 s = animationEngine.playAnimation(1, botself, true, direction);
173 if (SteeringManager.DEBUG) System.out.println("Play animation strafe.");
174 } else {
175
176 if (SOC_STEER_LOG.DEBUG) {
177 SOC_STEER_LOG.AddLogLine("slowMove not anim", SOC_STEER_LOG.KSync + botself.getName());
178 }
179
180 }
181 if (SOC_STEER_LOG.DEBUG) {
182 SOC_STEER_LOG.AddLogLine("slowMove " + angle + " angle " + s, SOC_STEER_LOG.KSync + botself.getName());
183 }
184
185
186
187
188 break;
189
190 case 2:
191
192 tLoc = new Location(botself.getLocation().x + nextVelocity.x, botself.getLocation().y + nextVelocity.y, botself.getLocation().z);
193
194 Move mm = new Move();
195 mm.setFirstLocation(tLoc);
196 mm.setFocusLocation(tLoc);
197
198 Configuration cc = new Configuration();
199
200 cc.setSpeedMultiplier(0.8);
201 botself.getAct().act(cc);
202
203 botself.getAct().act(mm);
204 if (lastWS == walkType) {
205 break;
206 }
207
208 String s2 = animationEngine.playAnimation(2, botself, true,0);
209
210 if (SOC_STEER_LOG.DEBUG) {
211 SOC_STEER_LOG.AddLogLine("Walk" + s2, SOC_STEER_LOG.KSync + botself.getName());
212 }
213
214 botself.getAct().act(new SetWalk().setWalk(true).setWalkAnim(s2));
215 break;
216 case 3: break;
217 }
218 } else {
219
220
221 if (SOC_STEER_LOG.DEBUG) {
222 SOC_STEER_LOG.AddLogLine("Wait for animation unineruptible animation", SOC_STEER_LOG.KSync + botself.getName());
223 }
224
225
226 stopMovement(focusLocation);
227 if (SteeringManager.DEBUG) System.out.println("stopMovement2");
228
229 }
230
231
232
233 lastWS = walkType;
234 }
235
236 private void stopMovement(Location focusLocation) {
237
238 myNextVelocity = new Vector3d(0, 0, 0);
239 locomotion.setSpeed(0.0);
240 locomotion.stopMovement();
241 if (!focusLocation.equals(new Location(0,0,0))) {
242 locomotion.turnTo(focusLocation);
243 }
244 if (SteeringManager.DEBUG) System.out.println(botself.getName()+" We turn to "+focusLocation);
245 if(animationEngine.canBeInterupt(botself)){
246 animationEngine.playAnimation("ambi_stand_normal01", botself, false);
247 }
248 }
249
250 @Override
251 protected Location setFocusSpecific(SteeringType steeringType, boolean wantsToStop, Location newFocus, Location focusLoc) {
252 if (steeringType == SteeringType.TRIANGLE) {
253 return newFocus;
254 }
255 return super.setFocusSpecific(steeringType, wantsToStop, newFocus, focusLoc);
256 }
257
258 @Override
259 protected Vector3d setVelocitySpecific(ISteering steering, RefBoolean wantsToGoFaster, RefBoolean wantsToStop, RefLocation newFocus) {
260 if (steering instanceof ISocialSteering) {
261 return ((ISocialSteering) steering).runSocial(myNextVelocity, wantsToGoFaster, wantsToStop, newFocus);
262 } else {
263 return super.setVelocitySpecific(steering, wantsToGoFaster, wantsToStop, newFocus);
264 }
265 }
266 }