View Javadoc

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   * @author Petr
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       * DOCASNY komentar v CZ
39       * Pridana funkcionalita by mela byt schopna <br/>
40       * a)zastavit pohyb pokud bude animationEngine prehravat neprerusitelnou animaci<br/>
41       * b)pouzivat 3 rychlosti pohybu misto puvodnich 2<br/>
42       * c)treti rychlost pohybu nechava postavu natocenou do focus celou dobu pohybu, tedy je vhodne pouzit "animaci slapani zeli" <br/>
43       * @param nextVelocity
44       * @param everyoneWantsToGoFaster
45       * @param focusLocation
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              //<editor-fold defaultstate="collapsed" desc="debug">
55              if (SOC_STEER_LOG.DEBUG) {
56                  SOC_STEER_LOG.AddLogLine(String.valueOf(precision), SOC_STEER_LOG.KSync);
57              }
58              //</editor-fold>
59          }
60          //super.moveTheBot(nextVelocity, everyoneWantsToGoFaster, focusLocation);
61  
62          //determinates how we will move(run = 3, walk = 2, pace = 1)
63          int walkType;
64  
65          double nextVelocityLength = nextVelocity.length() * multiplier; //The multiplier enables to enlarge or decrease the velocity. E.g. to make the bot to run.
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); //just for sure:D
73              }
74              lastWS = 0;
75              return;
76          }
77          
78          if(precision < 2)
79          {
80              walkType = 1;
81          }else if(nextVelocityLength < WALK_VELOCITY_LENGTH *100) //TODO: hack, we will just test pace and walk
82          {
83              walkType = 2;
84          }else //running
85          {
86              walkType = 3;
87          }
88          
89          
90          
91          //<editor-fold defaultstate="collapsed" desc="wants to go faster">
92  //        if (nextVelocityLength < 0.8*WALK_VELOCITY_LENGTH && everyoneWantsToGoFaster) {
93  //            if (SteeringManager.DEBUG) System.out.println("we enlarge the velocity");
94  //            nextVelocityLength = 0.8 * WALK_VELOCITY_LENGTH;
95  //        }
96          
97           //</editor-fold>
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                      //<editor-fold defaultstate="collapsed" desc="debug">
125                      if (SOC_STEER_LOG.DEBUG) {
126                     SOC_STEER_LOG.AddLogLine("slowMove", SOC_STEER_LOG.KSync + botself.getName());
127                      }
128                     //</editor-fold>
129                     //TODO: hack used wrong animation 
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                     //<editor-fold defaultstate="collapsed" desc="debug">
145                      if (SOC_STEER_LOG.DEBUG) {
146                     SOC_STEER_LOG.AddLogLine("Walk", SOC_STEER_LOG.KSync + botself.getName());
147                      }
148                     //</editor-fold> 
149                      //TODO: hack used wrong animation 
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             //<editor-fold defaultstate="collapsed" desc="debug">
159              if (SOC_STEER_LOG.DEBUG) {
160             SOC_STEER_LOG.AddLogLine("Wait for animation unineruptible animation", SOC_STEER_LOG.KSync + botself.getName());
161              }
162             //</editor-fold>
163             locomotion.setSpeed(0.0);
164             //animation that can not be interrupted is played on botself, so we do not move
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 }