Beispiel #1
0
        public static bool Prefix(ref bool __result, ref 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, bool ignoreFlooded, bool combustionEngine, bool ignoreCost)
        {
            PathCreationArgs args = default;
            VehicleInfo      info = null;

            if (VehicleID != 0)
            {
                // CreatePath called for customized AI
                Vehicle[]   vehicleBuffer = VehicleManager.instance.m_vehicles.m_buffer;
                ref Vehicle vehicleData   = ref vehicleBuffer[VehicleID];

                args.vehicleId      = VehicleID;
                args.extPathType    = ExtPathType;
                args.extVehicleType = ExtVehicleType;
                args.spawned        = vehicleData.m_flags.IsFlagSet(Vehicle.Flags.Spawned);
                args.skipQueue      = skipQueue;

                if (vehicleData.Info.m_vehicleAI is ShipAI)
                {
                    args.skipQueue = false;
                }
            }
Beispiel #2
0
        public bool CustomCreatePath(out uint unit,
                                     ref Randomizer randomizer,
                                     PathCreationArgs args)
        {
            uint pathUnitId;

            try {
                Monitor.Enter(m_bufferLock);

                int numIters = 0;
                while (true)
                {
                    // NON-STOCK CODE
                    ++numIters;

                    if (!m_pathUnits.CreateItem(out pathUnitId, ref randomizer))
                    {
                        unit = 0u;
                        return(false);
                    }

                    m_pathUnits.m_buffer[pathUnitId].m_simulationFlags = 1;
                    m_pathUnits.m_buffer[pathUnitId].m_referenceCount  = 1;
                    m_pathUnits.m_buffer[pathUnitId].m_nextPathUnit    = 0u;

                    // NON-STOCK CODE START
                    if (QueueItems[pathUnitId].queued)
                    {
                        ReleasePath(pathUnitId);

                        if (numIters > 10)
                        {
                            unit = 0u;
                            return(false);
                        }

                        continue;
                    }

                    break;
                }

                QueueItems[pathUnitId].vehicleType = args.extVehicleType;
                QueueItems[pathUnitId].vehicleId   = args.vehicleId;
                QueueItems[pathUnitId].pathType    = args.extPathType;
                QueueItems[pathUnitId].spawned     = args.spawned;
                QueueItems[pathUnitId].queued      = true;
                // NON-STOCK CODE END

                m_pathUnitCount = (int)(m_pathUnits.ItemCount() - 1u);
            }
            finally {
                Monitor.Exit(m_bufferLock);
            }

            unit = pathUnitId;

            if (args.isHeavyVehicle)
            {
                m_pathUnits.m_buffer[unit].m_simulationFlags |= PathUnit.FLAG_IS_HEAVY;
            }

            if (args.ignoreBlocked || args.ignoreFlooded)
            {
                m_pathUnits.m_buffer[unit].m_simulationFlags |= PathUnit.FLAG_IGNORE_BLOCKED;
            }

            if (args.stablePath)
            {
                m_pathUnits.m_buffer[unit].m_simulationFlags |= PathUnit.FLAG_STABLE_PATH;
            }

            if (args.randomParking)
            {
                m_pathUnits.m_buffer[unit].m_simulationFlags |= PathUnit.FLAG_RANDOM_PARKING;
            }

            if (args.ignoreFlooded)
            {
                m_pathUnits.m_buffer[unit].m_simulationFlags |= PathUnit.FLAG_IGNORE_FLOODED;
            }

            if (args.hasCombustionEngine)
            {
                m_pathUnits.m_buffer[unit].m_simulationFlags |= PathUnit.FLAG_COMBUSTION;
            }

            if (args.ignoreCosts)
            {
                m_pathUnits.m_buffer[unit].m_simulationFlags |= PathUnit.FLAG_IGNORE_COST;
            }

            m_pathUnits.m_buffer[unit].m_pathFindFlags = 0;
            m_pathUnits.m_buffer[unit].m_buildIndex    = args.buildIndex;
            m_pathUnits.m_buffer[unit].m_position00    = args.startPosA;
            m_pathUnits.m_buffer[unit].m_position01    = args.endPosA;
            m_pathUnits.m_buffer[unit].m_position02    = args.startPosB;
            m_pathUnits.m_buffer[unit].m_position03    = args.endPosB;
            m_pathUnits.m_buffer[unit].m_position11    = args.vehiclePosition;
            m_pathUnits.m_buffer[unit].m_laneTypes     = (byte)args.laneTypes;
            m_pathUnits.m_buffer[unit].m_vehicleTypes  = (ushort)args.vehicleTypes;
            m_pathUnits.m_buffer[unit].m_length        = args.maxLength;
            m_pathUnits.m_buffer[unit].m_positionCount = 20;

            int            minQueued = 10000000;
            CustomPathFind pathFind  = null;

#if QUEUEDSTATS
            TotalQueuedPathFinds = 0;
#endif
            foreach (CustomPathFind pathFindCandidate in _replacementPathFinds)
            {
#if QUEUEDSTATS
                TotalQueuedPathFinds += (uint)pathFindCandidate.m_queuedPathFindCount;
#endif
                if (!pathFindCandidate.IsAvailable ||
                    pathFindCandidate.m_queuedPathFindCount >= minQueued)
                {
                    continue;
                }

                minQueued = pathFindCandidate.m_queuedPathFindCount;
                pathFind  = pathFindCandidate;
            }

#if PF_DIJKSTRA
            if (pathFind != null && pathFind.CalculatePath(unit, args.skipQueue))
            {
                return(true);
            }
#else
            if (pathFind != null && pathFind.ExtCalculatePath(unit, args.skipQueue))
            {
                return(true);
            }
#endif

            // NON-STOCK CODE START
            try {
                Monitor.Enter(m_bufferLock);

                QueueItems[pathUnitId].queued = false;
                // NON-STOCK CODE END
                ReleasePath(unit);

                // NON-STOCK CODE START
                m_pathUnitCount = (int)(m_pathUnits.ItemCount() - 1u);
            }
            finally {
                Monitor.Exit(m_bufferLock);
            }

            // NON-STOCK CODE END
            return(false);
        }
        public bool CreatePath(out uint unit, ref Randomizer randomizer, PathCreationArgs args)
        {
            uint pathUnitId;

            try {
                Monitor.Enter(this.m_bufferLock);

                int numIters = 0;
                while (true)                   // NON-STOCK CODE
                {
                    ++numIters;

                    if (!this.m_pathUnits.CreateItem(out pathUnitId, ref randomizer))
                    {
                        unit = 0u;
                        return(false);
                    }

                    this.m_pathUnits.m_buffer[pathUnitId].m_simulationFlags = 1;
                    this.m_pathUnits.m_buffer[pathUnitId].m_referenceCount  = 1;
                    this.m_pathUnits.m_buffer[pathUnitId].m_nextPathUnit    = 0u;

                    // NON-STOCK CODE START
                    if (queueItems[pathUnitId].queued)
                    {
                        ReleasePath(pathUnitId);

                        if (numIters > 10)
                        {
                            unit = 0u;
                            return(false);
                        }

                        continue;
                    }
                    break;
                }

                queueItems[pathUnitId].vehicleType = args.extVehicleType;
                queueItems[pathUnitId].vehicleId   = args.vehicleId;
                queueItems[pathUnitId].pathType    = args.extPathType;
                queueItems[pathUnitId].queued      = true;
                // NON-STOCK CODE END

                this.m_pathUnitCount = (int)(this.m_pathUnits.ItemCount() - 1u);
            } finally {
                Monitor.Exit(this.m_bufferLock);
            }
            unit = pathUnitId;

            if (args.isHeavyVehicle)
            {
                this.m_pathUnits.m_buffer[unit].m_simulationFlags |= 16;
            }
            if (args.ignoreBlocked || args.ignoreFlooded)
            {
                this.m_pathUnits.m_buffer[unit].m_simulationFlags |= 32;
            }
            if (args.stablePath)
            {
                this.m_pathUnits.m_buffer[unit].m_simulationFlags |= 64;
            }
            if (args.randomParking)
            {
                this.m_pathUnits.m_buffer[unit].m_simulationFlags |= 2;
            }
            if (args.hasCombustionEngine)
            {
                this.m_pathUnits.m_buffer[unit].m_simulationFlags |= 4;
            }
            if (args.ignoreCosts)
            {
                this.m_pathUnits.m_buffer[unit].m_simulationFlags |= 8;
            }
            this.m_pathUnits.m_buffer[unit].m_pathFindFlags = 0;
            this.m_pathUnits.m_buffer[unit].m_buildIndex    = args.buildIndex;
            this.m_pathUnits.m_buffer[unit].m_position00    = args.startPosA;
            this.m_pathUnits.m_buffer[unit].m_position01    = args.endPosA;
            this.m_pathUnits.m_buffer[unit].m_position02    = args.startPosB;
            this.m_pathUnits.m_buffer[unit].m_position03    = args.endPosB;
            this.m_pathUnits.m_buffer[unit].m_position11    = args.vehiclePosition;
            this.m_pathUnits.m_buffer[unit].m_laneTypes     = (byte)args.laneTypes;
            this.m_pathUnits.m_buffer[unit].m_vehicleTypes  = (ushort)args.vehicleTypes;
            this.m_pathUnits.m_buffer[unit].m_length        = args.maxLength;
            this.m_pathUnits.m_buffer[unit].m_positionCount = 20;
            int minQueued = 10000000;

#if PF2
            CustomPathFind2 pathFind = null;
#else
            CustomPathFind pathFind = null;
#endif

#if QUEUEDSTATS
            TotalQueuedPathFinds = 0;
#endif
            for (int i = 0; i < _replacementPathFinds.Length; ++i)
            {
#if PF2
                CustomPathFind2 pathFindCandidate = _replacementPathFinds[i];
#else
                CustomPathFind pathFindCandidate = _replacementPathFinds[i];
#endif

#if QUEUEDSTATS
                TotalQueuedPathFinds += (uint)pathFindCandidate.m_queuedPathFindCount;
#endif
                if (pathFindCandidate.IsAvailable &&
                    pathFindCandidate.m_queuedPathFindCount < minQueued)
                {
                    minQueued = pathFindCandidate.m_queuedPathFindCount;
                    pathFind  = pathFindCandidate;
                }
            }

#if PF2
            if (pathFind != null && pathFind.CalculatePath(unit, args.skipQueue))
            {
                return(true);
            }
#else
            if (pathFind != null && pathFind.ExtCalculatePath(unit, args.skipQueue))
            {
                return(true);
            }
#endif

            // NON-STOCK CODE START
            try {
                Monitor.Enter(this.m_bufferLock);

                queueItems[pathUnitId].queued = false;
                // NON-STOCK CODE END
                this.ReleasePath(unit);

                // NON-STOCK CODE START
                this.m_pathUnitCount = (int)(this.m_pathUnits.ItemCount() - 1u);
            } finally {
                Monitor.Exit(this.m_bufferLock);
            }
            // NON-STOCK CODE END
            return(false);
        }