예제 #1
0
        public override bool OnPortalStop(Sim sim)
        {
            try
            {
                AncientPortal targetPortal = null;
                if (!sTargetPortals.TryGetValue(sim, out targetPortal))
                {
                    sim.PlayRouteFailure(mPortal);
                    return(false);
                }

                mSMC.SetActor("portal", targetPortal);

                Slot    slotName       = targetPortal.GetRoutingSlots()[0x0];
                Vector3 positionOfSlot = targetPortal.GetPositionOfSlot(slotName);
                Vector3 forwardOfSlot  = targetPortal.GetForwardOfSlot(slotName);
                sim.SetPosition(positionOfSlot);
                sim.SetForward(forwardOfSlot);

                targetPortal.DisableFootprint(AncientPortal.CatchABeam.FootprintPlacementHash);

                mSMC.RequestState("x", "Exit");

                if (SimTypes.IsSelectable(sim))
                {
                    for (int i = 0x0; i < AncientPortal.CatchABeam.kPotentialTravelBuffs.Length; i++)
                    {
                        if (RandomUtil.RandomChance(AncientPortal.CatchABeam.kChanceForEachBuff))
                        {
                            sim.BuffManager.AddElement(AncientPortal.CatchABeam.kPotentialTravelBuffs[i], Origin.FromAncientPortal);
                        }
                    }
                }

                targetPortal.RemoveFromUseList(sim);

                if (targetPortal.LotCurrent.IsResidentialLot && !sim.IsGreetedOnLot(targetPortal.LotCurrent))
                {
                    sim.GreetSimOnLot(targetPortal.LotCurrent);
                }

                if (mSMC != null)
                {
                    mSMC.Dispose();
                    mSMC = null;
                }

                mCurrentlyRoutingSim = null;

                return(true);
            }
            catch (ResetException)
            {
                throw;
            }
            catch (Exception e)
            {
                Common.Exception(sim, Owner, e);
                return(false);
            }
            finally
            {
                if (mCurrentlyRoutingSim != null)
                {
                    mCurrentlyRoutingSim.SetHiddenFlags(HiddenFlags.Nothing);
                }
            }
        }
        private static void Reroute(Route r, AncientPortal closest, AncientPortal destination)
        {
            Sim target = r.Follower.Target as Sim;
            Vector3 currentStartPoint = r.GetCurrentStartPoint();
            float distanceRemaining = r.GetDistanceRemaining();

            Common.StringBuilder msg = new Common.StringBuilder();

            msg.Append("AncientPortal Reroute: " + target.FullName);

            Route routeToPortal = target.CreateRoute();
            routeToPortal.SetOption(Route.RouteOption.EnableSubwayPlanning, false);
            routeToPortal.SetOption2(Route.RouteOption2.EnableHoverTrainPlanning, false);
            routeToPortal.SetOption(Route.RouteOption.EnablePlanningAsCar, r.GetOption(Route.RouteOption.EnablePlanningAsCar));
            routeToPortal.SetOption(Route.RouteOption.PlanUsingStroller, r.GetOption(Route.RouteOption.PlanUsingStroller));
            routeToPortal.SetOption(Route.RouteOption.ReplanUsingStroller, r.GetOption(Route.RouteOption.ReplanUsingStroller));
            routeToPortal.SetOption(Route.RouteOption.BeginAsStroller, r.GetOption(Route.RouteOption.BeginAsStroller));

            Vector3 slotPosition = closest.GetSlotPosition(closest.GetRoutingSlots()[0]);
            Vector3 slotFoward = closest.GetForwardOfSlot(closest.GetRoutingSlots()[0]);

            Vector3 farPosition = new Vector3(slotPosition);
            farPosition.x -= slotFoward.x / 4f;
            farPosition.y -= slotFoward.y / 4f;

            RoutePlanResult result = routeToPortal.PlanToPoint(farPosition);

            msg.Append(Common.NewLine + "Result: " + result);

            if (result.Succeeded())
            {
                msg.Append(Common.NewLine + "D" + Common.NewLine + Routes.RouteToString(routeToPortal));

                Route portalRoute = target.CreateRoute();
                portalRoute.SetOption(Route.RouteOption.EnableSubwayPlanning, false);
                portalRoute.SetOption2(Route.RouteOption2.EnableHoverTrainPlanning, false);
                portalRoute.SetOption(Route.RouteOption.EnablePlanningAsCar, r.GetOption(Route.RouteOption.EnablePlanningAsCar));
                portalRoute.SetOption(Route.RouteOption.PlanUsingStroller, r.GetOption(Route.RouteOption.PlanUsingStroller));
                portalRoute.SetOption(Route.RouteOption.ReplanUsingStroller, r.GetOption(Route.RouteOption.ReplanUsingStroller));
                portalRoute.SetOption(Route.RouteOption.BeginAsStroller, r.GetOption(Route.RouteOption.BeginAsStroller));

                result = portalRoute.PlanToPointFromPoint(slotPosition, farPosition);

                msg.Append(Common.NewLine + "Result: " + result);

                if (result.Succeeded())
                {
                    PathData portalData = new PathData();
                    portalData.PathType = PathType.PortalPath;
                    portalData.ObjectId = closest.ObjectId;
                    portalData.PortalStartPos = slotPosition;

                    portalRoute.SetPathData(ref portalData);

                    msg.Append(Common.NewLine + "A" + Common.NewLine + Routes.RouteToString(portalRoute));

                    slotPosition = destination.GetSlotPosition(destination.GetRoutingSlots()[0]);

                    r.SetOption(Route.RouteOption.EnableSubwayPlanning, false);
                    if (!r.ReplanFromPoint(slotPosition).Succeeded())
                    {
                        r.ReplanFromPoint(currentStartPoint);
                    }
                    else if ((routeToPortal.GetDistanceRemaining() + r.GetDistanceRemaining()) < (distanceRemaining + SimRoutingComponent.kDistanceMustSaveInOrderToUseSubway))
                    {
                        AncientPortalComponent.AddTargetPortal(target, destination);

                        msg.Append(Common.NewLine + "B" + Common.NewLine + Routes.RouteToString(r));

                        r.InsertRouteSubPathsAtIndex(0x0, portalRoute);
                        r.InsertRouteSubPathsAtIndex(0x0, routeToPortal);

                        msg.Append(Common.NewLine + "C" + Common.NewLine + Routes.RouteToString(r));

                        r.SetOption(Route.RouteOption.EnableSubwayPlanning, true);
                    }
                    else
                    {
                        r.ReplanFromPoint(currentStartPoint);
                    }
                }
            }

            Common.DebugNotify(msg, target);
            Common.DebugWriteLog(msg);
        }
예제 #3
0
        public override bool OnPortalStart(Sim sim)
        {
            try
            {
                if ((mCurrentlyRoutingSim != null) && (mCurrentlyRoutingSim.HasBeenDestroyed))
                {
                    if (mSMC != null)
                    {
                        mSMC.Dispose();
                        mSMC = null;
                    }
                }

                mCurrentlyRoutingSim = sim;

                if (mSMC != null)
                {
                    sim.PlayRouteFailure(mPortal);
                    return(false);
                }

                AncientPortal targetPortal = null;
                if (!sTargetPortals.TryGetValue(sim, out targetPortal))
                {
                    sim.PlayRouteFailure(mPortal);
                    return(false);
                }

                if (targetPortal == mPortal)
                {
                    return(false);
                }

                mPortal.AddToUseList(sim);

                sim.SimRoutingComponent.OnRouteActionsFinished -= OnPortalApproachCancelledAndFinished;
                sim.SetExitReasonsInterruptForMultiPortalRoute();
                sim.SimRoutingComponent.StartIgnoringObstacles();

                targetPortal.AddToUseList(sim);

                targetPortal.EnableFootprint(AncientPortal.CatchABeam.FootprintPlacementHash);
                targetPortal.PushSimsFromFootprint(AncientPortal.CatchABeam.FootprintPlacementHash, sim, null, false);

                Vector3 slotFoward = mPortal.GetForwardOfSlot(mPortal.GetRoutingSlots()[0]);

                sim.SetForward(slotFoward);

                mSMC = StateMachineClient.Acquire(sim, "AncientPortal", AnimationPriority.kAPDefault);
                mSMC.SetActor("x", sim);
                mSMC.SetActor("portal", mPortal);
                mSMC.EnterState("x", "Enter");
                mSMC.EnterState("portal", "Enter");

                mSMC.AddOneShotScriptEventHandler(0x65, HideSim);
                mSMC.AddOneShotScriptEventHandler(0x66, ShowSim);

                mSMC.RequestState("x", "InsidePortal");

                mPortal.RemoveFromUseList(sim);

                return(true);
            }
            catch (ResetException)
            {
                if (mCurrentlyRoutingSim != null)
                {
                    mCurrentlyRoutingSim.SetHiddenFlags(HiddenFlags.Nothing);
                }

                throw;
            }
            catch (Exception e)
            {
                if (mCurrentlyRoutingSim != null)
                {
                    mCurrentlyRoutingSim.SetHiddenFlags(HiddenFlags.Nothing);
                }

                Common.Exception(sim, Owner, e);
                return(false);
            }
        }
예제 #4
0
        private static void Reroute(Route r, AncientPortal closest, AncientPortal destination)
        {
            Sim     target            = r.Follower.Target as Sim;
            Vector3 currentStartPoint = r.GetCurrentStartPoint();
            float   distanceRemaining = r.GetDistanceRemaining();

            Common.StringBuilder msg = new Common.StringBuilder();

            msg.Append("AncientPortal Reroute: " + target.FullName);

            Route routeToPortal = target.CreateRoute();

            routeToPortal.SetOption(Route.RouteOption.EnableSubwayPlanning, false);
            routeToPortal.SetOption2(Route.RouteOption2.EnableHoverTrainPlanning, false);
            routeToPortal.SetOption(Route.RouteOption.EnablePlanningAsCar, r.GetOption(Route.RouteOption.EnablePlanningAsCar));
            routeToPortal.SetOption(Route.RouteOption.PlanUsingStroller, r.GetOption(Route.RouteOption.PlanUsingStroller));
            routeToPortal.SetOption(Route.RouteOption.ReplanUsingStroller, r.GetOption(Route.RouteOption.ReplanUsingStroller));
            routeToPortal.SetOption(Route.RouteOption.BeginAsStroller, r.GetOption(Route.RouteOption.BeginAsStroller));

            Vector3 slotPosition = closest.GetSlotPosition(closest.GetRoutingSlots()[0]);
            Vector3 slotFoward   = closest.GetForwardOfSlot(closest.GetRoutingSlots()[0]);

            Vector3 farPosition = new Vector3(slotPosition);

            farPosition.x -= slotFoward.x / 4f;
            farPosition.y -= slotFoward.y / 4f;

            RoutePlanResult result = routeToPortal.PlanToPoint(farPosition);

            msg.Append(Common.NewLine + "Result: " + result);

            if (result.Succeeded())
            {
                msg.Append(Common.NewLine + "D" + Common.NewLine + Routes.RouteToString(routeToPortal));

                Route portalRoute = target.CreateRoute();
                portalRoute.SetOption(Route.RouteOption.EnableSubwayPlanning, false);
                portalRoute.SetOption2(Route.RouteOption2.EnableHoverTrainPlanning, false);
                portalRoute.SetOption(Route.RouteOption.EnablePlanningAsCar, r.GetOption(Route.RouteOption.EnablePlanningAsCar));
                portalRoute.SetOption(Route.RouteOption.PlanUsingStroller, r.GetOption(Route.RouteOption.PlanUsingStroller));
                portalRoute.SetOption(Route.RouteOption.ReplanUsingStroller, r.GetOption(Route.RouteOption.ReplanUsingStroller));
                portalRoute.SetOption(Route.RouteOption.BeginAsStroller, r.GetOption(Route.RouteOption.BeginAsStroller));

                result = portalRoute.PlanToPointFromPoint(slotPosition, farPosition);

                msg.Append(Common.NewLine + "Result: " + result);

                if (result.Succeeded())
                {
                    PathData portalData = new PathData();
                    portalData.PathType       = PathType.PortalPath;
                    portalData.ObjectId       = closest.ObjectId;
                    portalData.PortalStartPos = slotPosition;

                    portalRoute.SetPathData(ref portalData);

                    msg.Append(Common.NewLine + "A" + Common.NewLine + Routes.RouteToString(portalRoute));

                    slotPosition = destination.GetSlotPosition(destination.GetRoutingSlots()[0]);

                    r.SetOption(Route.RouteOption.EnableSubwayPlanning, false);
                    if (!r.ReplanFromPoint(slotPosition).Succeeded())
                    {
                        r.ReplanFromPoint(currentStartPoint);
                    }
                    else if ((routeToPortal.GetDistanceRemaining() + r.GetDistanceRemaining()) < (distanceRemaining + SimRoutingComponent.kDistanceMustSaveInOrderToUseSubway))
                    {
                        AncientPortalComponent.AddTargetPortal(target, destination);

                        msg.Append(Common.NewLine + "B" + Common.NewLine + Routes.RouteToString(r));

                        r.InsertRouteSubPathsAtIndex(0x0, portalRoute);
                        r.InsertRouteSubPathsAtIndex(0x0, routeToPortal);

                        msg.Append(Common.NewLine + "C" + Common.NewLine + Routes.RouteToString(r));

                        r.SetOption(Route.RouteOption.EnableSubwayPlanning, true);
                    }
                    else
                    {
                        r.ReplanFromPoint(currentStartPoint);
                    }
                }
            }

            Common.DebugNotify(msg, target);
            Common.DebugWriteLog(msg);
        }