protected void performNotification(
     long perceiverOid, long perceivedOid, boolean inRadius, boolean wasInRadius) {
   if (Log.loggingDebug)
     Log.debug(
         "ProximityTracker.performNotification: perceiverOid "
             + perceiverOid
             + ", perceivedOid "
             + perceivedOid
             + ", inRadius "
             + inRadius
             + ", wasInRadius "
             + wasInRadius);
   if (notifyCallback != null) {
     notifyCallback.notifyReactionRadius(perceivedOid, perceiverOid, inRadius, wasInRadius);
     notifyCallback.notifyReactionRadius(perceiverOid, perceivedOid, inRadius, wasInRadius);
   } else {
     ObjectTracker.NotifyReactionRadiusMessage nmsg =
         new ObjectTracker.NotifyReactionRadiusMessage(
             perceivedOid, perceiverOid, inRadius, wasInRadius);
     Engine.getAgent().sendBroadcast(nmsg);
     nmsg =
         new ObjectTracker.NotifyReactionRadiusMessage(
             perceiverOid, perceivedOid, inRadius, wasInRadius);
     Engine.getAgent().sendBroadcast(nmsg);
   }
 }
Ejemplo n.º 2
0
 public void handleMessage(Message msg, int flags) {
   try {
     lock.lock();
     if (activated == false) return; // return true;
     if (msg.getMsgType() == Behavior.MSG_TYPE_COMMAND) {
       Behavior.CommandMessage cmdMsg = (Behavior.CommandMessage) msg;
       String command = cmdMsg.getCmd();
       // Remove the executor, because anything we do will
       // end the current execution.
       Engine.getExecutor().remove(this);
       if (Log.loggingDebug)
         Log.debug(
             "BaseBehavior.onMessage: command = "
                 + command
                 + "; oid = "
                 + obj.getOid()
                 + "; name "
                 + obj.getName());
       if (command.equals(MSG_CMD_TYPE_GOTO)) {
         GotoCommandMessage gotoMsg = (GotoCommandMessage) msg;
         Point destination = gotoMsg.getDestination();
         mode = MSG_CMD_TYPE_GOTO;
         roamingBehavior = true;
         gotoSetup(destination, gotoMsg.getSpeed());
       } else if (command.equals(MSG_CMD_TYPE_STOP)) {
         followTarget = null;
         pathState.clear();
         obj.getWorldNode().setDir(new MVVector(0, 0, 0));
         obj.updateWorldNode();
         mode = MSG_CMD_TYPE_STOP;
         // If roamingBehavior is set, that means that we
         // used formerly had a roaming behavior, so send
         // an ArrivedEventMessage so that the other
         // behavior starts up again.
         if (roamingBehavior) {
           try {
             Engine.getAgent().sendBroadcast(new ArrivedEventMessage(obj));
           } catch (Exception e) {
             Log.error(
                 "BaseBehavior.onMessage: Error sending ArrivedEventMessage, error was '"
                     + e.getMessage()
                     + "'");
             throw new RuntimeException(e);
           }
         }
       } else if (command.equals(BaseBehavior.MSG_CMD_TYPE_FOLLOW)) {
         FollowCommandMessage followMsg = (FollowCommandMessage) msg;
         mode = MSG_CMD_TYPE_FOLLOW;
         followSetup(followMsg.getTarget(), followMsg.getSpeed());
       }
     } else if (msg.getMsgType() == WorldManagerClient.MSG_TYPE_MOB_PATH_CORRECTION) {
       Engine.getExecutor().remove(this);
       interpolatePath();
       interpolatingPath = false;
     }
     // return true;
   } finally {
     lock.unlock();
   }
 }
Ejemplo n.º 3
0
 protected void cancelPathInterpolator(long oid) {
   WorldManagerClient.MobPathReqMessage cancelMsg = new WorldManagerClient.MobPathReqMessage(oid);
   try {
     Engine.getAgent().sendBroadcast(cancelMsg);
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
Ejemplo n.º 4
0
 public void initialize() {
   lock = LockFactory.makeLock("BaseBehaviorLock");
   long oid = obj.getOid();
   SubjectFilter filter = new SubjectFilter(oid);
   filter.addType(Behavior.MSG_TYPE_COMMAND);
   filter.addType(WorldManagerClient.MSG_TYPE_MOB_PATH_CORRECTION);
   pathState = new PathState(oid, pathObjectTypeName, true);
   commandSub = Engine.getAgent().createSubscription(filter, this);
 }
Ejemplo n.º 5
0
 public void deactivate() {
   lock.lock();
   try {
     activated = false;
     if (commandSub != null) {
       Engine.getExecutor().remove(this);
       Engine.getAgent().removeSubscription(commandSub);
       commandSub = null;
     }
   } finally {
     lock.unlock();
   }
 }
Ejemplo n.º 6
0
 protected long setupPathInterpolator(
     long oid, Point myLoc, Point dest, boolean follow, boolean followsTerrain) {
   long timeNow = System.currentTimeMillis();
   WorldManagerClient.MobPathReqMessage reqMsg =
       pathState.setupPathInterpolator(timeNow, myLoc, dest, mobSpeed, follow, followsTerrain);
   if (reqMsg != null) {
     try {
       Engine.getAgent().sendBroadcast(reqMsg);
       if (Log.loggingDebug)
         Log.debug("BaseBehavior.setupPathInterpolator: send MobPathReqMessage " + reqMsg);
     } catch (Exception e) {
       throw new RuntimeException(e);
     }
     interpolatingPath = true;
     return pathState.pathTimeRemaining();
   } else {
     interpolatingPath = false;
     return 0;
   }
 }
Ejemplo n.º 7
0
 public void gotoUpdate() {
   Point myLoc = obj.getWorldNode().getLoc();
   long oid = obj.getOid();
   if (interpolatingPath) {
     interpolatePath();
     if (!interpolatingPath) {
       Engine.getAgent().sendBroadcast(new ArrivedEventMessage(obj));
       if (Log.loggingDebug)
         Log.debug(
             "BaseBehavior.gotoUpdate sending ArrivedEventMessage: oid = "
                 + oid
                 + "; myLoc = "
                 + myLoc
                 + "; destLoc = "
                 + destLoc);
       mode = MSG_CMD_TYPE_STOP;
     }
   }
   if (interpolatingPath) scheduleMe(pathState.pathTimeRemaining());
 }