Exemplo n.º 1
0
    public override void OnInspectorGUI()
    {
        if (!TerrainManager.HasValidTerrain())
        {
            GUILayout.Label("Create or load a map to continue...");
            return;
        }

        PathManager instance = (PathManager)target;

        GUILayout.Label("Path Creator", EditorStyles.boldLabel);

        GUILayout.Space(5f);

        Type = (PathType)EditorGUILayout.EnumPopup("Path Type", Type);

        if (GUILayout.Button("Create"))
        {
            RaycastHit rayHit;
            if (Physics.Raycast(SceneView.lastActiveSceneView.camera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 1.0f)), out rayHit, Mathf.Infinity, 1 << 8))
            {
                PathManager.CreatePath(Type, rayHit.point);
                Debug.Log(string.Concat("Create a new ", Type, " path at ", rayHit.point));
            }
            else
            {
                Debug.Log("Look at the terrain to create a path");
            }
        }
    }
Exemplo n.º 2
0
    public void ResetPath(Vector2 position)
    {
        //not actually random, just named so
        int rand = manager.ClosestPoint(new Vector2(transform.position.x, transform.position.z)).transform.GetSiblingIndex();

        path.Clear();

        path = manager.CreatePath(manager.transform.GetChild(rand).GetComponent <PathPoint>(), position);
    }
        protected override bool StartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vector3 startPos, Vector3 endPos, bool startBothWays, bool endBothWays, bool undergroundTarget)
        {
            if ((vehicleData.m_flags & (Vehicle.Flags.TransferToSource | Vehicle.Flags.GoingBack)) != 0)
            {
                return(this.StartPathFind(ExtendedVehicleType.CargoTruck, vehicleID, ref vehicleData, startPos, endPos, startBothWays, endBothWays, undergroundTarget, this.IsHeavyVehicle(), this.IgnoreBlocked(vehicleID, ref vehicleData)));
            }
            bool allowUnderground = (vehicleData.m_flags & (Vehicle.Flags.Underground | Vehicle.Flags.Transition)) != 0;

            PathUnit.Position startPosA;
            PathUnit.Position startPosB;
            float             num;
            float             num2;
            bool flag = PathManager.FindPathPosition(startPos, ItemClass.Service.Road, NetInfo.LaneType.Vehicle | NetInfo.LaneType.TransportVehicle, VehicleInfo.VehicleType.Car, allowUnderground, false, 32f, out startPosA, out startPosB, out num, out num2);

            PathUnit.Position position;
            PathUnit.Position position2;
            float             num3;
            float             num4;

            if (PathManager.FindPathPosition(startPos, ItemClass.Service.PublicTransport, NetInfo.LaneType.Vehicle, VehicleInfo.VehicleType.Train | VehicleInfo.VehicleType.Ship, allowUnderground, false, 32f, out position, out position2, out num3, out num4))
            {
                if (!flag || num3 < num)
                {
                    startPosA = position;
                    startPosB = position2;
                    num       = num3;
                    num2      = num4;
                }
                flag = true;
            }
            PathUnit.Position endPosA;
            PathUnit.Position endPosB;
            float             num5;
            float             num6;
            bool flag2 = PathManager.FindPathPosition(endPos, ItemClass.Service.Road, NetInfo.LaneType.Vehicle | NetInfo.LaneType.TransportVehicle, VehicleInfo.VehicleType.Car, undergroundTarget, false, 32f, out endPosA, out endPosB, out num5, out num6);

            PathUnit.Position position3;
            PathUnit.Position position4;
            float             num7;
            float             num8;

            if (PathManager.FindPathPosition(endPos, ItemClass.Service.PublicTransport, NetInfo.LaneType.Vehicle, VehicleInfo.VehicleType.Train | VehicleInfo.VehicleType.Ship, undergroundTarget, false, 32f, out position3, out position4, out num7, out num8))
            {
                if (!flag2 || num7 < num5)
                {
                    endPosA = position3;
                    endPosB = position4;
                    num5    = num7;
                    num6    = num8;
                }
                flag2 = true;
            }
            if (flag && flag2)
            {
                PathManager instance = Singleton <PathManager> .instance;
                if (!startBothWays || num < 10f)
                {
                    startPosB = default(PathUnit.Position);
                }
                if (!endBothWays || num5 < 10f)
                {
                    endPosB = default(PathUnit.Position);
                }
                NetInfo.LaneType        laneTypes    = NetInfo.LaneType.Vehicle | NetInfo.LaneType.CargoVehicle;
                VehicleInfo.VehicleType vehicleTypes = VehicleInfo.VehicleType.Car | VehicleInfo.VehicleType.Train | VehicleInfo.VehicleType.Ship;
                uint path;
                if (instance.CreatePath(ExtendedVehicleType.CargoTruck, out path, ref Singleton <SimulationManager> .instance.m_randomizer, Singleton <SimulationManager> .instance.m_currentBuildIndex, startPosA, startPosB, endPosA, endPosB, laneTypes, vehicleTypes, 20000f, this.IsHeavyVehicle(), this.IgnoreBlocked(vehicleID, ref vehicleData), false, false))
                {
                    if (vehicleData.m_path != 0u)
                    {
                        instance.ReleasePath(vehicleData.m_path);
                    }
                    vehicleData.m_path   = path;
                    vehicleData.m_flags |= Vehicle.Flags.WaitingPath;
                    return(true);
                }
            }
            return(false);
        }
        public static bool CreatePath(this PathManager pm, ExtendedVehicleType extendedVehicleType, out uint unit, ref Randomizer randomizer, uint buildIndex, PathUnit.Position startPosA, PathUnit.Position startPosB, PathUnit.Position endPosA, PathUnit.Position endPosB, PathUnit.Position vehiclePosition, NetInfo.LaneType laneTypes, VehicleInfo.VehicleType vehicleTypes, float maxLength, bool isHeavyVehicle, bool ignoreBlocked, bool stablePath, bool skipQueue, bool randomParking)
        {
            if (ExtendedPathManager.PathFindFacades == null)
            {
                // Redirections are not installed correctly, fallbacking on the default code
                return(pm.CreatePath(
                           out unit,
                           ref randomizer,
                           buildIndex,
                           startPosA,
                           startPosB,
                           endPosA,
                           endPosB,
                           vehiclePosition,
                           laneTypes,
                           vehicleTypes,
                           maxLength,
                           isHeavyVehicle,
                           ignoreBlocked,
                           stablePath,
                           skipQueue,
                           randomParking));
            }

            while (!Monitor.TryEnter(pm.m_bufferLock, SimulationManager.SYNCHRONIZE_TIMEOUT))
            {
            }
            uint num;

            try
            {
                if (!pm.m_pathUnits.CreateItem(out num, ref randomizer))
                {
                    unit = 0u;
                    bool result = false;
                    return(result);
                }
                pm.m_pathUnitCount = (int)(pm.m_pathUnits.ItemCount() - 1u);
            }
            finally
            {
                Monitor.Exit(pm.m_bufferLock);
            }
            unit = num;
            pm.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_simulationFlags = 1;
            if (isHeavyVehicle)
            {
                PathUnit[] expr_92_cp_0 = pm.m_pathUnits.m_buffer;
                UIntPtr    expr_92_cp_1 = (UIntPtr)unit;
                expr_92_cp_0[(int)expr_92_cp_1].m_simulationFlags = (byte)(expr_92_cp_0[(int)expr_92_cp_1].m_simulationFlags | 16);
            }
            if (ignoreBlocked)
            {
                PathUnit[] expr_BB_cp_0 = pm.m_pathUnits.m_buffer;
                UIntPtr    expr_BB_cp_1 = (UIntPtr)unit;
                expr_BB_cp_0[(int)expr_BB_cp_1].m_simulationFlags = (byte)(expr_BB_cp_0[(int)expr_BB_cp_1].m_simulationFlags | 32);
            }
            if (stablePath)
            {
                PathUnit[] expr_E4_cp_0 = pm.m_pathUnits.m_buffer;
                UIntPtr    expr_E4_cp_1 = (UIntPtr)unit;
                expr_E4_cp_0[(int)expr_E4_cp_1].m_simulationFlags = (byte)(expr_E4_cp_0[(int)expr_E4_cp_1].m_simulationFlags | 64);
            }
            pm.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_pathFindFlags  = 0;
            pm.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_buildIndex     = buildIndex;
            pm.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_position00     = startPosA;
            pm.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_position01     = endPosA;
            pm.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_position02     = startPosB;
            pm.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_position03     = endPosB;
            pm.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_position11     = vehiclePosition;
            pm.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_nextPathUnit   = 0u;
            pm.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_laneTypes      = (byte)laneTypes;
            pm.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_vehicleTypes   = (byte)vehicleTypes;
            pm.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_length         = maxLength;
            pm.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_positionCount  = 20;
            pm.m_pathUnits.m_buffer[(int)((UIntPtr)unit)].m_referenceCount = 1;
            int num2 = 10000000;
            ExtendedPathFindFacade pathFindFacade = null;

            for (int i = 0; i < ExtendedPathManager.PathFindFacades.Length; i++)
            {
                ExtendedPathFindFacade pathFind2 = ExtendedPathManager.PathFindFacades[i];
                if (pathFind2.IsAvailable && pathFind2.m_queuedPathFindCount < num2)
                {
                    num2           = pathFind2.m_queuedPathFindCount;
                    pathFindFacade = pathFind2;
                }
            }
            if (pathFindFacade != null && pathFindFacade.CalculatePath(unit, skipQueue, extendedVehicleType))
            {
                return(true);
            }
            pm.ReleasePath(unit);
            return(false);
        }
 public static bool CreatePath(this PathManager pm, ExtendedVehicleType extendedVehicleType, out uint unit, ref Randomizer randomizer, uint buildIndex, PathUnit.Position startPosA, PathUnit.Position startPosB, PathUnit.Position endPosA, PathUnit.Position endPosB, NetInfo.LaneType laneTypes, VehicleInfo.VehicleType vehicleTypes, float maxLength, bool isHeavyVehicle, bool ignoreBlocked, bool stablePath, bool skipQueue)
 {
     return(pm.CreatePath(extendedVehicleType, out unit, ref randomizer, buildIndex, startPosA, startPosB, endPosA, endPosB, default(PathUnit.Position), laneTypes, vehicleTypes, maxLength, isHeavyVehicle, ignoreBlocked, stablePath, skipQueue, false));
 }
        //// TO DEBUG
        //[RedirectFrom(typeof(PathManager))]
        //public static bool CreatePath(
        //    out uint unit,
        //    ref Randomizer randomizer,
        //    uint buildIndex,
        //    PathUnit.Position startPosA,
        //    PathUnit.Position startPosB,
        //    PathUnit.Position endPosA,
        //    PathUnit.Position endPosB,
        //    PathUnit.Position vehiclePosition,
        //    NetInfo.LaneType laneTypes,
        //    VehicleInfo.VehicleType vehicleTypes,
        //    float maxLength,
        //    bool isHeavyVehicle,
        //    bool ignoreBlocked,
        //    bool stablePath,
        //    bool skipQueue)
        //{
        //    throw new Exception("CreatePath has been called, please implement redirection to custom method");
        //}

        public static bool CreatePath(this PathManager pm, ExtendedVehicleType extendedVehicleType, out uint unit, ref Randomizer randomizer, uint buildIndex, PathUnit.Position startPos, PathUnit.Position endPos, NetInfo.LaneType laneTypes, VehicleInfo.VehicleType vehicleTypes, float maxLength)
        {
            PathUnit.Position position = default(PathUnit.Position);
            return(pm.CreatePath(extendedVehicleType, out unit, ref randomizer, buildIndex, startPos, position, endPos, position, position, laneTypes, vehicleTypes, maxLength, false, false, false, false, false));
        }