1 package SocialSteeringsBeta;
2
3 import SteeringStuff.ISteering;
4 import SteeringStuff.RefBoolean;
5 import SteeringStuff.SteeringManager;
6 import SteeringStuff.SteeringType;
7 import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
8 import cz.cuni.amis.pogamut.ut2004.agent.module.sensomotoric.Raycasting;
9 import cz.cuni.amis.pogamut.ut2004.bot.command.AdvancedLocomotion;
10 import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
11 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.Configuration;
12 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.Move;
13 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.SetWalk;
14 import javax.vecmath.Vector3d;
15
16
17
18
19
20 public class SocialSteeringManager extends SteeringManager{
21
22 protected IAnimationEngine animationEngine;
23 private static final double KPaceTreshold = 100;
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 = 3;
51 if (nextVelocity instanceof SteeringResult) {
52
53 precision = ((SteeringResult) nextVelocity).getAccurancyMultiplier();
54
55 if (SOC_STEER_LOG.DEBUG) {
56 SOC_STEER_LOG.AddLogLine(String.valueOf(precision), SOC_STEER_LOG.KSync);
57 }
58
59 }
60
61
62
63 int walkType;
64
65 double nextVelocityLength = nextVelocity.length() * multiplier;
66
67 if (nextVelocityLength <0.01){
68 myNextVelocity = new Vector3d(0,0,0);
69 locomotion.stopMovement();
70 if(animationEngine.canBeInterupt(botself)){
71 animationEngine.playAnimation("idleanim", botself, false);
72 locomotion.setSpeed(0.0);
73 }
74 lastWS = 0;
75 return;
76 }
77
78 if(precision < 2)
79 {
80 walkType = 1;
81 }else if(nextVelocityLength < WALK_VELOCITY_LENGTH *100)
82 {
83 walkType = 2;
84 }else
85 {
86 walkType = 3;
87 }
88
89
90
91
92
93
94
95
96
97
98
99 double nextVelMult = nextVelocityLength / WALK_VELOCITY_LENGTH;
100 nextVelocityLength = nextVelMult * WALK_VELOCITY_LENGTH;
101 nextVelocity.normalize();
102 nextVelocity.scale(nextVelocityLength);
103
104
105 myNextVelocity = new Vector3d(nextVelocity.x, nextVelocity.y, nextVelocity.z);
106
107 botself.getAct().act(new Configuration().setSpeedMultiplier(nextVelocityLength / WALK_VELOCITY_LENGTH).setAutoTrace(true).setDrawTraceLines(drawRaycasting));
108
109
110
111 if(animationEngine.canBeInterupt(botself))
112 {
113 switch (walkType) {
114 case 1:
115 Location tLoc = new Location(botself.getLocation().x + nextVelocity.x, botself.getLocation().y + nextVelocity.y, botself.getLocation().z);
116
117 Move m = new Move();
118 m.setFirstLocation(tLoc);
119 m.setFocusLocation(focusLocation);
120
121 locomotion.setSpeed(0.3);
122 botself.getAct().act(m);
123 if(lastWS == walkType) break;
124
125 if (SOC_STEER_LOG.DEBUG) {
126 SOC_STEER_LOG.AddLogLine("slowMove", SOC_STEER_LOG.KSync + botself.getName());
127 }
128
129
130 botself.getAct().act(new SetWalk().setWalk(true).setRunAnim("walk_drunk").setWalkAnim("walk_drunk"));
131 animationEngine.playAnimation("walk_drunk", botself, true);
132 break;
133 case 2:
134
135 tLoc = new Location(botself.getLocation().x + nextVelocity.x, botself.getLocation().y + nextVelocity.y, botself.getLocation().z);
136
137 Move mm = new Move();
138 mm.setFirstLocation(tLoc);
139 mm.setFocusLocation(tLoc);
140
141 locomotion.setSpeed(0.9);
142 botself.getAct().act(mm);
143 if(lastWS == walkType) break;
144
145 if (SOC_STEER_LOG.DEBUG) {
146 SOC_STEER_LOG.AddLogLine("Walk", SOC_STEER_LOG.KSync + botself.getName());
147 }
148
149
150 botself.getAct().act(new SetWalk().setWalk(true).setRunAnim("walk_carry01").setWalkAnim("walk_carry01"));
151 animationEngine.playAnimation("walk_carry01", botself, true);
152
153
154 break;
155 }
156 }else
157 {
158
159 if (SOC_STEER_LOG.DEBUG) {
160 SOC_STEER_LOG.AddLogLine("Wait for animation unineruptible animation", SOC_STEER_LOG.KSync + botself.getName());
161 }
162
163 locomotion.setSpeed(0.0);
164
165 }
166 lastWS = walkType;
167
168
169 }
170
171 @Override
172 protected Location setFocusSpecific(SteeringType steeringType, boolean wantsToStop, Location newFocus, Location focusLoc) {
173 if(steeringType == SteeringType.TRIANGLE)
174 {
175 return newFocus;
176 }
177 return super.setFocusSpecific(steeringType, wantsToStop, newFocus, focusLoc);
178 }
179
180 @Override
181 protected Vector3d setVelocitySpecific(ISteering steering, RefBoolean wantsToGoFaster, RefBoolean wantsToStop, Location newFocus) {
182 if(steering instanceof ISocialSteering){
183 return ((ISocialSteering)steering).runSocial(myNextVelocity, wantsToGoFaster, wantsToStop, newFocus);
184 }else{
185 return super.setVelocitySpecific(steering, wantsToGoFaster, wantsToStop, newFocus);
186 }
187 }
188
189
190
191
192
193
194 }