/// <summary>
        /// Gets the district for a building.
        /// </summary>
        /// <param name="buildingId">The building identifier.</param>
        /// <returns>
        /// The district.
        /// </returns>
        public static byte GetDistrict(ushort buildingId)
        {
            try
            {
                Building[] buildings = Singleton <BuildingManager> .instance.m_buildings.m_buffer;
                if (buildings[buildingId].Info == null || (buildings[buildingId].m_flags & Building.Flags.Created) != Building.Flags.Created)
                {
                    return(0);
                }

                return(DistrictHelper.GetDistrict(buildings[buildingId].m_position));
            }
            catch
            {
                return(0);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <param name="vehicle">The vehicle.</param>
        /// <param name="vehicles">The vehicles.</param>
        /// <param name="buildings">The buildings.</param>
        /// <param name="getHead">if set to <c>true</c> get header instead of data.</param>
        /// <returns>
        /// A <see cref="System.String" /> that represents this instance.
        /// </returns>
        private static string InfoString(StuckVehicleInfo vehicle, Vehicle[] vehicles, Building[] buildings, bool getHead)
        {
            Log.InfoList info = new Log.InfoList();

            List <string> status   = null;
            List <string> dispatch = null;
            string        ai       = null;

            if (!getHead)
            {
                if (vehicles == null)
                {
                    vehicles = Singleton <VehicleManager> .instance.m_vehicles.m_buffer;
                }

                if (buildings == null)
                {
                    buildings = Singleton <BuildingManager> .instance.m_buildings.m_buffer;
                }

                status = new List <string>(1);
                if (vehicle.isStuck)
                {
                    status.Add("Stuck");
                }
                if (vehicle.isBroken)
                {
                    status.Add("Broken");
                }
                if (vehicle.isLost)
                {
                    status.Add("Lost");
                }
                if (vehicle.isConfused)
                {
                    status.Add("Confused");
                }
                if (vehicle.isFlagged)
                {
                    status.Add("Flagged");
                }
                if (status.Count == 0)
                {
                    status.Add("Checking");
                }

                dispatch = new List <string>(2);
                if (IsDispatchersResponsibility(vehicle.dispatcherType))
                {
                    dispatch.Add("IsResponsible");
                }
                if (vehicle.dispatcherType != Dispatcher.DispatcherTypes.None)
                {
                    dispatch.Add(vehicle.dispatcherType.ToString());
                }

                try
                {
                    if (vehicles[vehicle.VehicleId].Info != null)
                    {
                        if (vehicles[vehicle.VehicleId].Info.m_vehicleAI != null)
                        {
                            ai = vehicles[vehicle.VehicleId].Info.m_vehicleAI.GetType().ToString();
                        }
                    }
                }
                catch { }
            }

            if (getHead)
            {
                info.Add("<Status>", "<Status>");
                info.Add("<Vehicle>", "<VehicleId>", "[VehicleName]", "[VehicleAI]", "[ExtraInfo]");
            }
            else
            {
                info.Add("Status", status);
                info.Add("Vehicle", vehicle.VehicleId, vehicle.VehicleName, ai, vehicle.ExtraInfo);
            }

            if (getHead)
            {
                info.Add("[Dispatch]", "[Responsibility]", "[DispatcherType]");
            }
            else if (dispatch.Count > 0)
            {
                info.Add("Dispatch", dispatch);
            }

            if (getHead)
            {
                info.Add("[Confused]", "<ConfusedForSeconds>", "<ConfusedForFrames>");
            }
            else if (vehicle.confusedSinceFrame > 0 || vehicle.confusedSinceTime > 0.0)
            {
                info.Add("Confused", vehicle.ConfusedForSeconds, vehicle.ConfusedForFrames);
            }

            if (getHead)
            {
                info.Add("[Flagged]", "<FlaggedForSeconds>", "<FlaggedForFrames>", "[Flags]", "[Position]");
            }
            else if (vehicle.checkFlagSinceFrame > 0 || vehicle.checkFlagSinceTime > 0.0)
            {
                info.Add("Flagged", vehicle.CheckFlaggedForSeconds, vehicle.CheckFlaggedForFrames, vehicle.checkFlags, vehicle.checkFlagPosition);
            }

            if (getHead)
            {
                info.Add("[Lost]", "<LostForSeconds>", "<LostForFrames>", "[LostReason]");
            }
            else if (vehicle.lostSinceFrame > 0 || vehicle.lostSinceTime > 0.0)
            {
                info.Add("Lost", vehicle.LostForSeconds, vehicle.LostForFrames, vehicle.lostReason);
            }

            if (getHead)
            {
                info.Add("[District]", "<districtId>", "[DistrictName]");
            }
            else if (vehicle.checkFlagSinceFrame > 0 || vehicle.checkFlagSinceTime > 0.0)
            {
                try
                {
                    byte districtId = DistrictHelper.GetDistrict(vehicle.checkFlagPosition);
                    if (districtId != 0)
                    {
                        info.Add("District", districtId, DistrictHelper.GetDistrictName(districtId));
                    }
                }
                catch { }
            }

            if (getHead)
            {
                InfoStringInfoForBuilding(null, null, null, true, 0, "SourceBuilding", info);
                InfoStringInfoForBuilding(null, null, null, true, 0, "TargetBuilding", info);
            }
            else
            {
                try
                {
                    InfoStringInfoForBuilding(vehicle, vehicles, buildings, false, vehicles[vehicle.VehicleId].m_sourceBuilding, "SourceBuilding", info);
                    InfoStringInfoForBuilding(vehicle, vehicles, buildings, false, vehicles[vehicle.VehicleId].m_targetBuilding, "TargetBuilding", info);
                }
                catch { }
            }

            if (getHead)
            {
                info.Add("[Handling]", "<HandledForFrames>", "<HandlingErrors>");
            }
            else if (vehicle.handlingErrors > 0 || vehicle.lastHandledStamp > 0)
            {
                info.Add("Handling", (vehicle.lastHandledStamp > 0 && vehicle.lastHandledStamp < Global.CurrentFrame) ? Global.CurrentFrame - vehicle.lastHandledStamp : 0, vehicle.handlingErrors);
            }

            return(info.ToString());
        }