public void AddAncientPortal()
        {
            try
            {
                if (mPortal.GetRoutingSlots().Length == 0)
                {
                    return;
                }

                Vector3 startPos = Owner.GetPositionOfSlot(mPortal.GetRoutingSlots()[0]);
                Vector3 endPos   = mPortal.PositionOnFloor;

                CASAGSAvailabilityFlags ageFlags = CASAGSAvailabilityFlags.HumanYoungAdult | CASAGSAvailabilityFlags.HumanTeen | CASAGSAvailabilityFlags.HumanAdult | CASAGSAvailabilityFlags.HumanElder | CASAGSAvailabilityFlags.HumanChild | CASAGSAvailabilityFlags.Male | CASAGSAvailabilityFlags.Female | CASAGSAvailabilityFlags.LeftHanded | CASAGSAvailabilityFlags.RightHanded;

                //ageFlags |= CASAGSAvailabilityFlags.CatAdult | CASAGSAvailabilityFlags.CatElder | CASAGSAvailabilityFlags.DogAdult | CASAGSAvailabilityFlags.DogElder | CASAGSAvailabilityFlags.LittleDogAdult | CASAGSAvailabilityFlags.LittleDogElder;

                Route.AddPortal(Owner.ObjectId, startPos, endPos, 1f, PortalType.PortalTypeAnimateThrough, RoutePortalFlags.OneWayPortal, ageFlags);
                Route.AddPortal(Owner.ObjectId, endPos, startPos, 1f, PortalType.PortalTypeAnimateThrough, RoutePortalFlags.OneWayPortal, ageFlags);
            }
            catch (Exception e)
            {
                Common.Exception("AddAncientPortal", e);
            }
        }
        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);
        }
        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);
                }
            }
        }
Exemple #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);
        }