Ejemplo n.º 1
0
        private void TimeTick(SimulationEvent e)
        {
            int oldTime = time;
            DataValue dv = null;

            Vec3D landIntersect;
            Vec3D obstructionIntersect;

            Vec3D curLocVec = new Vec3D(0, 0, 0);
            Vec3D newLocVec = new Vec3D(0, 0, 0);
            Vec3D destVec = new Vec3D(0, 0, 0);
            Vec3D velVec = new Vec3D(0, 0, 0);
            Vec3D headingVector = new Vec3D(0, 0, 0);


            dv = e["Time"];
            time = ((IntegerValue)dv).value;

            double dTime = ((double)(time - oldTime)) / 1000;
            SimulationObjectProxy obProx = null;
            SimulationObjectProxy parentProx = null;

            bool launchStarted, launchDone;
            int launchEndTime;

            bool pursueStarted;
            string pursueTargetID;
            string parentObjectID;

            ScoringDB.ActorFrame actorFrame = new ScoringDB.ActorFrame();
            foreach (string id in objectProxies.Keys)
            {
                obProx = objectProxies[id];


                //*********************************
                // Launch movement logic 
                //*********************************
                #region Launch Logic
                launchStarted = ((BooleanValue)obProx["LaunchStarted"].GetDataValue()).value;
                launchDone = ((BooleanValue)obProx["LaunchDone"].GetDataValue()).value;

                pursueStarted = ((BooleanValue)obProx["PursueStarted"].GetDataValue()).value;
                pursueTargetID = ((StringValue)obProx["PursueTargetID"].GetDataValue()).value;

                if (launchStarted == false && launchDone == true)
                {
                    dv = obProx["LaunchDone"].GetDataValue();
                    ((BooleanValue)dv).value = false;
                    obProx["LaunchDone"].SetDataValue(dv);
                    launchDone = false;
                }
                if (launchStarted == true && launchDone == false)
                {
                    parentObjectID = ((StringValue)obProx["ParentObjectID"].GetDataValue()).value;
                    parentProx = objectProxies[parentObjectID];
                    launchEndTime = ((IntegerValue)obProx["LaunchEndTime"].GetDataValue()).value;
                    if (time >= launchEndTime)
                    {
                        Vec3D parentVec = new Vec3D((LocationValue)parentProx["Location"].GetDataValue());
                        dv = obProx["LaunchDestinationLocation"].GetDataValue();
                        Vec3D launchDestVec = new Vec3D((LocationValue)dv);
                        bool sendMoveRequest = ((LocationValue)dv).exists;

                        obProx["Location"].SetDataValue(parentVec.ToLocationValue());
                        //Now that location has been updated, set in helper library:
                        ObjectDistances.UpdateObjectLocation(id, parentVec);

                        dv = obProx["LaunchDone"].GetDataValue();
                        ((BooleanValue)dv).value = true;
                        obProx["LaunchDone"].SetDataValue(dv);

                        if (sendMoveRequest)
                        {
                            string userID = ((StringValue)obProx["OwnerID"].GetDataValue()).value;
                            distClient.PutEvent(SimUtility.BuildMoveObjectRequestEvent(ref simModel, time, userID, id, launchDestVec, 1.0));
                        }

                        if (((BooleanValue)obProx["LaunchIsWeapon"].GetDataValue()).value == true)
                        {
                            dv = obProx["PursueStarted"].GetDataValue();
                            ((BooleanValue)dv).value = true;
                            obProx["PursueStarted"].SetDataValue(dv);
                            pursueStarted = true;

                            dv = obProx["LaunchWeaponTargetID"].GetDataValue();
                            pursueTargetID = ((StringValue)dv).value;

                            dv = obProx["PursueTargetID"].GetDataValue();
                            ((StringValue)dv).value = pursueTargetID;
                            obProx["PursueTargetID"].SetDataValue(dv);

                            distClient.PutEvent(SimUtility.BuildSystemMessageEvent(ref simModel,
                                                           time,
                                                           ((StringValue)(obProx["OwnerID"].GetDataValue())).value,
                                                           id + " has been launched from " + parentObjectID + " at " + pursueTargetID));
                            distClient.PutEvent(SimUtility.BuildHistory_SubplatformLaunchEvent(ref simModel,
                                                                                               time,
                                                                                               id,
                                                                                               parentObjectID,
                                                                                               parentVec,
                                                                                               launchDestVec,
                                                                                               true,
                                                                                               pursueTargetID));
                        }
                        else
                        {
                            distClient.PutEvent(SimUtility.BuildSystemMessageEvent(ref simModel,
                                                           time,
                                                           ((StringValue)(obProx["OwnerID"].GetDataValue())).value,
                                                           id + " has been undocked from " + parentObjectID));
                            distClient.PutEvent(SimUtility.BuildHistory_SubplatformLaunchEvent(ref simModel,
                                                                                               time,
                                                                                               id,
                                                                                               parentObjectID,
                                                                                               parentVec,
                                                                                               launchDestVec,
                                                                                               false,
                                                                                               ""));
                        }
                    }
                }
                #endregion

                #region Pursue Logic
                /*if (pursueStarted)
                {
                    if (objectProxies.ContainsKey(pursueTargetID))
                    {
                        dv = objectProxies[pursueTargetID]["Location"].GetDataValue();

                        String targetState = ((StringValue)objectProxies[pursueTargetID]["State"].GetDataValue()).value;
                        if (!((LocationValue)dv).exists || targetState == "Dead")
                        {
                            //if my target is dead or not existant, kill this weapon too.

                            obProx["PursueStarted"].SetDataValue(DataValueFactory.BuildBoolean(false));
                            obProx["PursueTargetID"].SetDataValue(DataValueFactory.BuildString(String.Empty));
                            distClient.PutEvent(SimUtility.BuildStateChangeEvent(ref simModel, time, id, "Dead"));
                            continue;
                        }

                        destVec.Set((LocationValue)dv);
                        obProx["DestinationLocation"].SetDataValue(destVec.ToLocationValue());

                        dv = obProx["Throttle"].GetDataValue();
                        ((DoubleValue)dv).value = 1;
                        obProx["Throttle"].SetDataValue(dv);

                        distClient.PutEvent(SimUtility.BuildHistory_PursueEvent(ref simModel,
                                                                                time,
                                                                                id,
                                                                                curLocVec,
                                                                                pursueTargetID,
                                                                                destVec));
                    }
                }*/
                #endregion

                //*********************************
                //   MoveObject logic
                //*********************************
                //
                /*
                // Ignore objects that don't have a location
                //
                dv = obProx["Location"].GetDataValue();
                if (!((LocationValue)dv).exists)
                {
                    continue;
                }
                curLocVec.Set((LocationValue)dv);


                //dv = obProx["Velocity"].GetDataValue();
                //velVec.Set((VelocityValue)dv);

                dv = obProx["DestinationLocation"].GetDataValue();
                if (!((LocationValue)dv).exists)
                {
                    destVec.Set(curLocVec);
                    obProx["DestinationLocation"].SetDataValue(destVec.ToLocationValue());
                }
                else
                {
                    destVec.Set((LocationValue)dv);
                }

                dv = obProx["Throttle"].GetDataValue();
                double throttle = ((DoubleValue)dv).value;

                dv = obProx["MaximumSpeed"].GetDataValue();
                double maxSpeed = ((DoubleValue)dv).value;


                //
                // If the object's throttle or maximum speed are zero, set velocity to (0,0,0) and 
                // set the destination to the current location
                //
                if (throttle == 0 || maxSpeed == 0 || ((StringValue)obProx["State"].GetDataValue()).value == "Dead")
                {
                    velVec.Set(0, 0, 0);
                    obProx["Velocity"].SetDataValue(velVec.ToVelocityValue());

                    destVec.Set(curLocVec);
                    obProx["DestinationLocation"].SetDataValue(destVec.ToLocationValue());

                    dv = obProx["Throttle"].GetDataValue();
                    ((DoubleValue)dv).value = 0;
                    obProx["Throttle"].SetDataValue(dv);
                }
                */

                //
                // Update what active regions the object is in.
                //
                StateDB.physicalObjects[id].activeRegions = GetActiveRegions(curLocVec);
                dv = obProx["InActiveRegions"].GetDataValue();
                ((StringListValue)dv).strings = StateDB.physicalObjects[id].activeRegions;
                obProx["InActiveRegions"].SetDataValue(dv);


                double speedMultiplier = GetActiveRegionSpeedMultiplier(StateDB.physicalObjects[id].activeRegions);
                dv = obProx["ActiveRegionSpeedMultiplier"].GetDataValue();
                if (((DoubleValue)dv).value != speedMultiplier)
                {
                    ((DoubleValue)dv).value = speedMultiplier;
                    obProx["ActiveRegionSpeedMultiplier"].SetDataValue(dv);
                    //distClient.PutEvent(SimUtility.BuildActiveRegionSpeedMultiplierUpdateEvent(ref simModel, time, id));
                    distributor.viewProBackChannelEvents.Add(SimUtility.BuildActiveRegionSpeedMultiplierUpdateEvent(ref simModel, time, id));
                }

                if (time % 1000 == 0)
                {
                    actorFrame.objectID = id;
                    actorFrame.speciesName = StateDB.physicalObjects[id].speciesName;
                    actorFrame.ownerID = StateDB.physicalObjects[id].ownerID;
                    actorFrame.activeRegions = StateDB.physicalObjects[id].activeRegions;

                    ScoringDB.UpdateScore_ObjectExists(actorFrame);
                }

                //
                // Update the object's velocity based on its destinations, throttle, and maximum speed.
                //
                /*
                if (curLocVec.ScalerDistanceTo(destVec) > 0.01)
                {
                    double degCurHeading = 0.0;
                    double degDestHeading = 0.0;
                    // headingVector = new Vec3D(((VelocityValue)obProx["Heading"].GetDataValue()));
                    degCurHeading = ((DoubleValue)obProx["Heading"].GetDataValue()).value;//180 / Math.PI * Math.Atan2(headingVector.X, headingVector.Y);
                    double tx = Math.Sin(degCurHeading / 180 * Math.PI);// /180*Math.PI;
                    double ty = Math.Cos(degCurHeading / 180 * Math.PI);///180*Math.PI;
                    headingVector = new Vec3D(tx, ty, 0);
                    //TODO: Adjust velocity vector based on heading
                    if (curLocVec.ScalerDistanceTo(destVec) >= (maxSpeed * throttle * dTime * speedMultiplier))
                    {
                        velVec = headingVector;
                        velVec = velVec.Multiply(maxSpeed * throttle * speedMultiplier);
                        //
                        // Update the object's location based on its velocity
                        //
                        newLocVec.X = curLocVec.X + (velVec.X * dTime);
                        newLocVec.Y = curLocVec.Y + (velVec.Y * dTime);
                        newLocVec.Z = curLocVec.Z + (velVec.Z * dTime);
                    }
                    else
                    {
                        velVec = destVec.Subtract(curLocVec);
                        //
                        // Update the object's location based on its velocity
                        //
                        newLocVec.X = curLocVec.X + (velVec.X);
                        newLocVec.Y = curLocVec.Y + (velVec.Y);
                        newLocVec.Z = curLocVec.Z + (velVec.Z);
                    }

                    //TODO: adjust position based on velocity vector
                    obProx["Velocity"].SetDataValue(velVec.ToVelocityValue());
                    //
                    // Update the object's location based on its velocity
                    // -- AD: Moved up, as dTime was exponentially reducing object speed rather than stopping quickly.
                    //newLocVec.X = curLocVec.X + (velVec.X * dTime);
                    //newLocVec.Y = curLocVec.Y + (velVec.Y * dTime);
                    //newLocVec.Z = curLocVec.Z + (velVec.Z * dTime);

                    //TODO: Adjust heading if needed                    

                    if (curLocVec.ScalerDistanceTo(destVec) >= (maxSpeed * throttle * dTime * speedMultiplier))
                    {
                        headingVector = curLocVec.VectorDistanceTo(destVec);
                        headingVector.Normalize();
                        //velVec = velVec.Multiply(maxSpeed * throttle * speedMultiplier);
                    }
                    else
                    {
                        headingVector = destVec.Subtract(curLocVec);
                        headingVector.Normalize();
                    }
                    degDestHeading = 180 / Math.PI * Math.Atan2(headingVector.X, headingVector.Y);
                    double newDiff = 0.0;
                    if (degDestHeading > degCurHeading)
                    {
                        newDiff = degDestHeading - degCurHeading;
                    }
                    else
                    {
                        newDiff = degCurHeading - degDestHeading;
                    }
                    if (degDestHeading < 0)
                        degDestHeading = 360 + degDestHeading;
                    if (degCurHeading < 0)
                        degCurHeading = 360 + degCurHeading;

                    if (degDestHeading != degCurHeading)
                    {
                        double deltaDegrees = _maxTurnAngle;
                        double diff = Math.Abs(degDestHeading - degCurHeading);
                        deltaDegrees = Math.Min(deltaDegrees, diff);

                        if ((degDestHeading > degCurHeading && diff < 180) || (degDestHeading < degCurHeading && diff > 180))
                        {
                            //add to heading
                            degCurHeading += deltaDegrees;
                        }
                        else
                        {
                            //subtract from heading
                            degCurHeading -= deltaDegrees;
                        }
                        degCurHeading = degCurHeading % 360;
                        Vec3D newHeadingVector = new Vec3D(Math.Sin(degCurHeading / 180 * Math.PI), Math.Cos(degCurHeading / 180 * Math.PI), 0);
                        headingVector = newHeadingVector;
                    }
                    else
                    {

                    }
                    //obProx["Heading"].SetDataValue(headingVector.ToVelocityValue());
                    obProx["Heading"].SetDataValue(DataValueFactory.BuildDouble(degCurHeading));
                    Console.WriteLine(String.Format("Tick; New Location:({0},{1}); New Heading Vector:({2},{3}); Heading:{4}", newLocVec.X, newLocVec.Y, headingVector.X, headingVector.Y, degCurHeading));
                    //Console.WriteLine("New Location: {"+newLocVec.X+","+newLocVec.Y+"}");
                    //Console.WriteLine("New Velocity Vector: {" + velVec.X + "," + velVec.Y + "}");



                    // TODO: Do obstruction check here

                    bool stopMotion = false;
                    switch (obProx.GetObjectType())
                    {
                        case "SeaObject":
                            if (!IsOnSea(newLocVec))
                            {
                                stopMotion = true;
                                distClient.PutEvent(SimUtility.BuildSystemMessageEvent(ref simModel,
                                            time,
                                            ((StringValue)(obProx["OwnerID"].GetDataValue())).value,
                                            id + " has been blocked by land"));
                            }
                            break;
                        case "LandObject":
                            if (!IsOnLand(newLocVec))
                            {
                                stopMotion = true;
                                distClient.PutEvent(SimUtility.BuildSystemMessageEvent(ref simModel,
                                            time,
                                            ((StringValue)(obProx["OwnerID"].GetDataValue())).value,
                                            id + " has been blocked by sea"));
                            }
                            break;
                        default:
                            break;
                    }

                    if (IsObstructed(curLocVec, newLocVec, id))
                    {
                        stopMotion = true;
                    }

                    if (!stopMotion)
                    {
                        curLocVec.Set(newLocVec);
                        obProx["Location"].SetDataValue(curLocVec.ToLocationValue());
                        //Now that location has been updated, set in helper library:
                        ObjectDistances.UpdateObjectLocation(id, curLocVec);
                    }
                    else
                    {
                        obProx["Location"].SetDataValue(curLocVec.ToLocationValue());
                        //Now that location has been updated, set in helper library:
                        ObjectDistances.UpdateObjectLocation(id, curLocVec);
                        destVec.Set(curLocVec);
                        obProx["DestinationLocation"].SetDataValue(destVec.ToLocationValue());
                        distClient.PutEvent(SimUtility.BuildMoveDoneEvent(ref simModel, time, id, "Obstruction"));
                        distributor.viewProBackChannelEvents.Add(SimUtility.BuildMoveDoneEvent(ref simModel, time, id, "Obstruction"));
                        dv = obProx["Throttle"].GetDataValue();
                        ((DoubleValue)dv).value = 0;
                        obProx["Throttle"].SetDataValue(dv);
                        distClient.PutEvent(SimUtility.BuildSystemMessageEvent(ref simModel,
                                            time,
                                            ((StringValue)(obProx["OwnerID"].GetDataValue())).value,
                                            id + " was stopped by an obstruction"));
                   }
                  

                }
                else // if the object has reached its destination and is not pursuing, send MoveDone
                {
                    velVec.Set(0, 0, 0);
                    newLocVec.Set(destVec);
                    obProx["Location"].SetDataValue(newLocVec.ToLocationValue());
                    //Now that location has been updated, set in helper library:
                    ObjectDistances.UpdateObjectLocation(id, newLocVec);
                    obProx["Velocity"].SetDataValue(velVec.ToVelocityValue());

                    if (!pursueStarted && throttle > 0)
                    {
                        // TODO: Make sure MoveDone is being sent correctly.

                        distClient.PutEvent(SimUtility.BuildMoveDoneEvent(ref simModel, time, id, "ReachedDestination"));
                        distributor.viewProBackChannelEvents.Add(SimUtility.BuildMoveDoneEvent(ref simModel, time, id, "ReachedDestination"));
                        dv = obProx["Throttle"].GetDataValue();
                        ((DoubleValue)dv).value = 0;
                        obProx["Throttle"].SetDataValue(dv);

                        distClient.PutEvent(SimUtility.BuildSystemMessageEvent(ref simModel,
                                            time,
                                            ((StringValue)(obProx["OwnerID"].GetDataValue())).value,
                                            id + " has reached its destination"));
                    }
                }*/
            }
        }
Ejemplo n.º 2
0
        /*
        Vec3D FindLandBoundaryIntersection(Vec3D fromP, Vec3D toP)
        {
            Vec2D r = null;

            Vec2D myFromP = new Vec2D(fromP.X, fromP.Y);
            Vec2D myToP = new Vec2D(toP.X, toP.Y);

            List<Vec2D> points = new List<Vec2D>();
            foreach (LandRegion reg in landRegions.Values)
            {
                r = Polygon2D.FindIntersect(reg.poly, myFromP, myToP);
                if (r != null)
                {
                    points.Add(r);
                }
            }

            if (points.Count == 0)
            {
                return null;
            }
            Vec2D closest = new Vec2D(points[0]);

            foreach (Vec2D p in points)
            {
                if (myFromP.ScalerDistanceTo(p) < myFromP.ScalerDistanceTo(closest))
                {
                    closest.Set(p);
                }
            }

            // return point on from side of intersection.
            if (myFromP.X < closest.X)
            {
                closest.X -= 1;
            }
            else if (myFromP.X > closest.X)
            {
                closest.X += 1;
            }
            if (myFromP.Y < closest.Y)
            {
                closest.Y -= 1;
            }
            else if (myFromP.Y > closest.Y)
            {
                closest.Y += 1;
            }

            return new Vec3D(closest.X, closest.Y, fromP.Z);
        }
        */
        /*
        Vec3D FindObstructionBoundaryIntersection(Vec3D fromP, Vec3D toP)
        {
            Vec3D r = null;

            List<Vec3D> points = new List<Vec3D>();
            foreach (BlockingRegion reg in blockingRegions.Values)
            {
                r = Polygon3D.FindIntersect(reg.poly, fromP, toP);
                if (r != null)
                {
                    points.Add(r);
                }
            }

            if (points.Count == 0)
            {
                return null;
            }
            Vec3D closest = new Vec3D(points[0]);

            foreach (Vec3D p in points)
            {
                if (fromP.ScalerDistanceTo(p) < fromP.ScalerDistanceTo(closest))
                {
                    closest.Set(p);
                }
            }

            // return point on from side of intersection.
            if (fromP.X < closest.X)
            {
                closest.X -= 1;
            }
            else if (fromP.X > closest.X)
            {
                closest.X += 1;
            }
            if (fromP.Y < closest.Y)
            {
                closest.Y -= 1;
            }
            else if (fromP.Y > closest.Y)
            {
                closest.Y += 1;
            }

            return closest;
        }
        */
        private void TimeTick(SimulationEvent e)
        {
            int oldTime = time;
            DataValue dv = null;

            Vec3D landIntersect;
            Vec3D obstructionIntersect;

            Vec3D curLocVec = new Vec3D(0, 0, 0);
            Vec3D newLocVec = new Vec3D(0, 0, 0);
            Vec3D destVec = new Vec3D(0, 0, 0);
            Vec3D velVec = new Vec3D(0, 0, 0);

            dv = e["Time"];
            time = ((IntegerValue)dv).value;

            double dTime = ((double)(time - oldTime)) / 1000;
            SimulationObjectProxy obProx = null;
            SimulationObjectProxy parentProx = null;

            bool launchStarted, launchDone;
            int launchEndTime;

            bool pursueStarted;
            string pursueTargetID;
            string parentObjectID;

            ScoringDB.ActorFrame actorFrame = new ScoringDB.ActorFrame();
            foreach (string id in objectProxies.Keys)
            {
                obProx = objectProxies[id];


                //*********************************
                // Launch movement logic 
                //*********************************

                launchStarted = ((BooleanValue)obProx["LaunchStarted"].GetDataValue()).value;
                launchDone = ((BooleanValue)obProx["LaunchDone"].GetDataValue()).value;

                pursueStarted = ((BooleanValue)obProx["PursueStarted"].GetDataValue()).value;
                pursueTargetID = ((StringValue)obProx["PursueTargetID"].GetDataValue()).value;

                if (launchStarted == false && launchDone == true)
                {
                    dv = obProx["LaunchDone"].GetDataValue();
                    ((BooleanValue)dv).value = false;
                    obProx["LaunchDone"].SetDataValue(dv);
                    launchDone = false;
                }
                if (launchStarted == true && launchDone == false)
                {
                    parentObjectID = ((StringValue)obProx["ParentObjectID"].GetDataValue()).value;
                    parentProx = objectProxies[parentObjectID];
                    launchEndTime = ((IntegerValue)obProx["LaunchEndTime"].GetDataValue()).value;
                    if (time >= launchEndTime)
                    {
                        Vec3D parentVec = new Vec3D((LocationValue)parentProx["Location"].GetDataValue());
                        dv = obProx["LaunchDestinationLocation"].GetDataValue();
                        Vec3D launchDestVec = new Vec3D((LocationValue)dv);
                        bool sendMoveRequest = ((LocationValue)dv).exists;

                        obProx["Location"].SetDataValue(parentVec.ToLocationValue());
                        //Now that location has been updated, set in helper library:
                        ObjectDistances.UpdateObjectLocation(id, parentVec);

                        dv = obProx["LaunchDone"].GetDataValue();
                        ((BooleanValue)dv).value = true;
                        obProx["LaunchDone"].SetDataValue(dv);

                        if (sendMoveRequest)
                        {
                            string userID = ((StringValue)obProx["OwnerID"].GetDataValue()).value;
                            distClient.PutEvent(SimUtility.BuildMoveObjectRequestEvent(ref simModel, time, userID, id, launchDestVec, 1.0));
                        }

                        if (((BooleanValue)obProx["LaunchIsWeapon"].GetDataValue()).value == true)
                        {
                            dv = obProx["PursueStarted"].GetDataValue();
                            ((BooleanValue)dv).value = true;
                            obProx["PursueStarted"].SetDataValue(dv);
                            pursueStarted = true;

                            dv = obProx["LaunchWeaponTargetID"].GetDataValue();
                            pursueTargetID = ((StringValue)dv).value;

                            dv = obProx["PursueTargetID"].GetDataValue();
                            ((StringValue)dv).value = pursueTargetID;
                            obProx["PursueTargetID"].SetDataValue(dv);

                            distClient.PutEvent(SimUtility.BuildSystemMessageEvent(ref simModel,
                                                           time,
                                                           ((StringValue)(obProx["OwnerID"].GetDataValue())).value,
                                                           id + " has been launched from " + parentObjectID + " at " + pursueTargetID));
                            distClient.PutEvent(SimUtility.BuildHistory_SubplatformLaunchEvent(ref simModel,
                                                                                               time,
                                                                                               id,
                                                                                               parentObjectID,
                                                                                               parentVec,
                                                                                               launchDestVec,
                                                                                               true,
                                                                                               pursueTargetID));
                        }
                        else
                        {
                            distClient.PutEvent(SimUtility.BuildSystemMessageEvent(ref simModel,
                                                           time,
                                                           ((StringValue)(obProx["OwnerID"].GetDataValue())).value,
                                                           id + " has been undocked from " + parentObjectID));
                            distClient.PutEvent(SimUtility.BuildHistory_SubplatformLaunchEvent(ref simModel,
                                                                                               time,
                                                                                               id,
                                                                                               parentObjectID,
                                                                                               parentVec,
                                                                                               launchDestVec,
                                                                                               false,
                                                                                               ""));
                        }
                    }
                }

                if (pursueStarted)
                {
                    if (objectProxies.ContainsKey(pursueTargetID))
                    {
                        dv = objectProxies[pursueTargetID]["Location"].GetDataValue();

                        String targetState = ((StringValue)objectProxies[pursueTargetID]["State"].GetDataValue()).value;
                        if (!((LocationValue)dv).exists || targetState == "Dead")
                        {
                            //if my target is dead or not existant, kill this weapon too.

                            obProx["PursueStarted"].SetDataValue(DataValueFactory.BuildBoolean(false));
                            obProx["PursueTargetID"].SetDataValue(DataValueFactory.BuildString(String.Empty));
                            distClient.PutEvent(SimUtility.BuildStateChangeEvent(ref simModel, time, id, "Dead"));
                            continue;
                        }

                        destVec.Set((LocationValue)dv);
                        obProx["DestinationLocation"].SetDataValue(destVec.ToLocationValue());

                        dv = obProx["Throttle"].GetDataValue();
                        ((DoubleValue)dv).value = 1;
                        obProx["Throttle"].SetDataValue(dv);

                        distClient.PutEvent(SimUtility.BuildHistory_PursueEvent(ref simModel,
                                                                                time,
                                                                                id,
                                                                                curLocVec,
                                                                                pursueTargetID,
                                                                                destVec));
                    }
                }


                //*********************************
                //   MoveObject logic
                //*********************************

                //
                // Ignore objects that don't have a location
                //
                dv = obProx["Location"].GetDataValue();
                if (!((LocationValue)dv).exists)
                {
                    continue;
                }
                curLocVec.Set((LocationValue)dv);
                

                //dv = obProx["Velocity"].GetDataValue();
                //velVec.Set((VelocityValue)dv);

                dv = obProx["DestinationLocation"].GetDataValue();
                if (!((LocationValue)dv).exists)
                {
                    destVec.Set(curLocVec);
                    obProx["DestinationLocation"].SetDataValue(destVec.ToLocationValue());
                }
                else
                {
                    destVec.Set((LocationValue)dv);
                }

                dv = obProx["Throttle"].GetDataValue();
                double throttle = ((DoubleValue)dv).value;

                dv = obProx["MaximumSpeed"].GetDataValue();
                double maxSpeed = ((DoubleValue)dv).value;




                //
                // If the object's throttle or maximum speed are zero, set velocity to (0,0,0) and 
                // set the destination to the current location
                //
                if (throttle == 0 || maxSpeed == 0 || ((StringValue)obProx["State"].GetDataValue()).value == "Dead")
                {
                    velVec.Set(0, 0, 0);
                    obProx["Velocity"].SetDataValue(velVec.ToVelocityValue());

                    destVec.Set(curLocVec);
                    obProx["DestinationLocation"].SetDataValue(destVec.ToLocationValue());

                    dv = obProx["Throttle"].GetDataValue();
                    ((DoubleValue)dv).value = 0;
                    obProx["Throttle"].SetDataValue(dv);

                }


                //
                // Update what active regions the object is in.
                //
                StateDB.physicalObjects[id].activeRegions = GetActiveRegions(curLocVec);
                dv = obProx["InActiveRegions"].GetDataValue();
                StateDB.physicalObjects[id].activeRegions.Remove(id);// dont want to be blocked by itself.
                ((StringListValue)dv).strings = StateDB.physicalObjects[id].activeRegions;
                obProx["InActiveRegions"].SetDataValue(dv);


                double speedMultiplier = GetActiveRegionSpeedMultiplier(StateDB.physicalObjects[id].activeRegions);
                dv = obProx["ActiveRegionSpeedMultiplier"].GetDataValue();
                if (((DoubleValue)dv).value != speedMultiplier)
                {
                    ((DoubleValue)dv).value = speedMultiplier;
                    obProx["ActiveRegionSpeedMultiplier"].SetDataValue(dv);
                    //distClient.PutEvent(SimUtility.BuildActiveRegionSpeedMultiplierUpdateEvent(ref simModel, time, id));
                    distributor.viewProBackChannelEvents.Add(SimUtility.BuildActiveRegionSpeedMultiplierUpdateEvent(ref simModel, time, id));
                }

                if (time % 1000 == 0)
                {
                    actorFrame.objectID = id;
                    actorFrame.speciesName = StateDB.physicalObjects[id].speciesName;
                    actorFrame.ownerID = StateDB.physicalObjects[id].ownerID;
                    actorFrame.activeRegions = StateDB.physicalObjects[id].activeRegions;

                    ScoringDB.UpdateScore_ObjectExists(actorFrame);
                }

                //
                // Update the object's velocity based on its destinations, throttle, and maximum speed.
                //

                if (curLocVec.ScalerDistanceTo(destVec) > 0.01)
                {
                    if (curLocVec.ScalerDistanceTo(destVec) >= (maxSpeed * throttle * dTime * speedMultiplier))
                    {
                        velVec = curLocVec.VectorDistanceTo(destVec);
                        velVec.Normalize();
                        velVec = velVec.Multiply(maxSpeed * throttle * speedMultiplier);
                    }
                    else
                    {
                        velVec = destVec.Subtract(curLocVec);
                    }

                    obProx["Velocity"].SetDataValue(velVec.ToVelocityValue());
                    //
                    // Update the object's location based on its velocity
                    //
                    newLocVec.X = curLocVec.X + (velVec.X * dTime);
                    newLocVec.Y = curLocVec.Y + (velVec.Y * dTime);
                    newLocVec.Z = curLocVec.Z + (velVec.Z * dTime);





                    // TODO: Do obstruction check here
                    /*
                    obstructionIntersect = FindObstructionBoundaryIntersection(curLocVec, newLocVec);
                    landIntersect = FindLandBoundaryIntersection(curLocVec, newLocVec);
                    if (obstructionIntersect != null)
                    {
                        curLocVec.Set(obstructionIntersect);
                        obProx["Location"].SetDataValue(curLocVec.ToLocationValue());
                        destVec.Set(curLocVec);
                        obProx["DestinationLocation"].SetDataValue(destVec.ToLocationValue());
                        distClient.PutEvent(SimUtility.BuildMoveDoneEvent(ref simModel, time, id));
                        dv = obProx["Throttle"].GetDataValue();
                        ((DoubleValue)dv).value = 0;
                        obProx["Throttle"].SetDataValue(dv);
                    }
                    else if (landIntersect != null && (obProx.GetObjectType() != "AirObject"))
                    {
                        curLocVec.Set(landIntersect);
                        obProx["Location"].SetDataValue(curLocVec.ToLocationValue());
                        destVec.Set(curLocVec);
                        obProx["DestinationLocation"].SetDataValue(destVec.ToLocationValue());
                        distClient.PutEvent(SimUtility.BuildMoveDoneEvent(ref simModel, time, id));
                        dv = obProx["Throttle"].GetDataValue();
                        ((DoubleValue)dv).value = 0;
                        obProx["Throttle"].SetDataValue(dv);
                    }
                    else
                    {
                        curLocVec.Set(newLocVec);
                        obProx["Location"].SetDataValue(curLocVec.ToLocationValue());
                    } */

                    bool stopMotion = false;
                    switch (obProx.GetObjectType())
                    {
                        case "SeaObject":
                            if (!IsOnSea(newLocVec))
                            {
                                stopMotion = true;
                                distClient.PutEvent(SimUtility.BuildSystemMessageEvent(ref simModel,
                                            time,
                                            ((StringValue)(obProx["OwnerID"].GetDataValue())).value,
                                            id + " has been blocked by land"));
                            }
                            break;
                        case "LandObject":
                            if (!IsOnLand(newLocVec))
                            {
                                stopMotion = true;
                                distClient.PutEvent(SimUtility.BuildSystemMessageEvent(ref simModel,
                                            time,
                                            ((StringValue)(obProx["OwnerID"].GetDataValue())).value,
                                            id + " has been blocked by sea"));
                            }
                            break;
                        default:
                            break;
                    }

                    if (IsObstructed(curLocVec, newLocVec,id))
                    {
                        stopMotion = true;
                        //distClient.PutEvent(SimUtility.BuildSystemMessageEvent(ref simModel,
                        //                    time,
                        //                    ((StringValue)(obProx["OwnerID"].GetDataValue())).value,
                        //                    id + " has been blocked by an obstruction"));
                    }

                    if (!stopMotion)
                    {
                        curLocVec.Set(newLocVec);
                        obProx["Location"].SetDataValue(curLocVec.ToLocationValue());
                        //Now that location has been updated, set in helper library:
                        ObjectDistances.UpdateObjectLocation(id, curLocVec);
                    }
                    else
                    {
                        obProx["Location"].SetDataValue(curLocVec.ToLocationValue());
                        //Now that location has been updated, set in helper library:
                        ObjectDistances.UpdateObjectLocation(id, curLocVec);
                        destVec.Set(curLocVec);
                        obProx["DestinationLocation"].SetDataValue(destVec.ToLocationValue());
                        distClient.PutEvent(SimUtility.BuildMoveDoneEvent(ref simModel, time, id, "Obstruction"));
                        distributor.viewProBackChannelEvents.Add(SimUtility.BuildMoveDoneEvent(ref simModel, time, id, "Obstruction"));
                        dv = obProx["Throttle"].GetDataValue();
                        ((DoubleValue)dv).value = 0;
                        obProx["Throttle"].SetDataValue(dv);
                        distClient.PutEvent(SimUtility.BuildSystemMessageEvent(ref simModel,
                                            time,
                                            ((StringValue)(obProx["OwnerID"].GetDataValue())).value,
                                            id + " was stopped by an obstruction"));
                    }

                }
                else // if the object has reached its destination and is not pursuing, send MoveDone
                {


                    velVec.Set(0, 0, 0);
                    newLocVec.Set(destVec);
                    obProx["Location"].SetDataValue(newLocVec.ToLocationValue());
                    //Now that location has been updated, set in helper library:
                    ObjectDistances.UpdateObjectLocation(id, newLocVec);
                    obProx["Velocity"].SetDataValue(velVec.ToVelocityValue());


                    if (!pursueStarted && throttle > 0)
                    {
                        /* TODO: Make sure MoveDone is being sent correctly.*/

                        distClient.PutEvent(SimUtility.BuildMoveDoneEvent(ref simModel, time, id, "ReachedDestination"));
                        distributor.viewProBackChannelEvents.Add(SimUtility.BuildMoveDoneEvent(ref simModel, time, id, "ReachedDestination"));
                        dv = obProx["Throttle"].GetDataValue();
                        ((DoubleValue)dv).value = 0;
                        obProx["Throttle"].SetDataValue(dv);

                        distClient.PutEvent(SimUtility.BuildSystemMessageEvent(ref simModel,
                                            time,
                                            ((StringValue)(obProx["OwnerID"].GetDataValue())).value,
                                            id + " has reached its destination"));
                    }



                }

                

                /* TODO: Ignore obstruction code for now */
                /*
                if (((StringValue)obProx["State"].GetDataValue()).value != "Dead" &&
                    ((obProx.GetObjectType() == "LandObject" && !IsOnLand(newLocVec)) ||
                    (obProx.GetObjectType() == "SeaObject" && !IsOnSea(newLocVec)) ||
                    IsObstructed(curLocVec,newLocVec) || IsInObstruction(newLocVec)))
                {
                    velVec.Set(0, 0, 0);
                    dv = obProx["Velocity"].GetDataValue();

                    obProx["Velocity"].SetDataValue(velVec.ToVelocityValue());
                    SimulationEvent done = SimulationEventFactory.BuildEvent(ref simModel, "MoveDone");
                    ((IntegerValue)done["Time"]).value = time;
                    ((StringValue)done["ObjectID"]).value = id;
                    distClient.PutEvent(done);
                    System.Console.WriteLine("Motion: object {0} stopped by land boundery", id);

                    dv = obProx["Throttle"].GetDataValue();
                    ((DoubleValue)dv).value = 0;
                    obProx["Throttle"].SetDataValue(dv);

                    if (((obProx.GetObjectType() == "LandObject" && !IsOnLand(curLocVec)) ||
                        obProx.GetObjectType() == "SeaObject" && !IsOnSea(curLocVec)) ||
                        IsInObstruction(curLocVec))
                    {
                        SimulationEvent dead = SimulationEventFactory.BuildEvent(ref simModel, "StateChange");
                        ((IntegerValue)dead["Time"]).value = time;
                        ((StringValue)dead["ObjectID"]).value = id;
                        ((StringValue)dead["NewState"]).value = "Dead";
                        distClient.PutEvent(dead);
                    }

                    return;
                }
                 * */

            }
        }