/// <summary>
        /// Play bulldoze sound (if enabled) for specified building.
        /// </summary>
        /// <param name="target">The building being destroyed.</param>
        protected void PlayBulldozeSound(Building target)
        {
            EffectInfo effect = BuildingManager.instance.m_properties.m_bulldozeEffect;

            if (effect == null)
            {
                return;                            //effect is disabled.
            }
            Log("Triggering bulldoze effect...");

            //var nullAudioGroup = new AudioGroup(0,
            //	new SavedFloat("Bulldoze",
            //		Settings.gameSettingsFile, 0, false));
            var instance  = new InstanceID();
            var spawnArea = new EffectInfo.SpawnArea(
                //Compute where the sound should come from in the world.
                Matrix4x4.TRS(
                    Building.CalculateMeshPosition(target.Info,
                                                   target.m_position, target.m_angle, target.m_length),
                    Building.CalculateMeshRotation(target.m_angle),
                    Vector3.one),
                target.Info.m_lodMeshData);

            EffectManager.instance.DispatchEffect(effect, instance, spawnArea,
                                                  Vector3.zero, 0.0f, 1f,
                                                  AudioManager.instance.EffectGroup);
            //nullAudioGroup);
            Log("Triggered bulldoze effect.");
        }
        protected void StartUpgrading(ushort buildingID, ref Building buildingData)
        {
            buildingData.m_frame0.m_constructState = (byte)0;
            buildingData.m_frame1.m_constructState = (byte)0;
            buildingData.m_frame2.m_constructState = (byte)0;
            buildingData.m_frame3.m_constructState = (byte)0;
            Building.Flags flags = (buildingData.m_flags | Building.Flags.Upgrading) & ~Building.Flags.Completed & ~Building.Flags.LevelUpEducation & ~Building.Flags.LevelUpLandValue;
            buildingData.m_flags = flags;
            BuildingManager instance1 = Singleton <BuildingManager> .instance;

            instance1.UpdateBuildingRenderer(buildingID, true);
            EffectInfo effect = instance1.m_properties.m_levelupEffect;

            if (effect != null)
            {
                InstanceID instance2 = new InstanceID();
                instance2.Building = buildingID;
                Vector3    meshPosition;
                Quaternion meshRotation;
                buildingData.CalculateMeshPosition(out meshPosition, out meshRotation);
                EffectInfo.SpawnArea spawnArea = new EffectInfo.SpawnArea(Matrix4x4.TRS(meshPosition, meshRotation, Vector3.one), this.m_info.m_lodMeshData);
                Singleton <EffectManager> .instance.DispatchEffect(effect, instance2, spawnArea, Vector3.zero, 0.0f, 1f, instance1.m_audioGroup);
            }
            Vector3 position = buildingData.m_position;

            position.y += this.m_info.m_size.y;
            Singleton <NotificationManager> .instance.AddEvent(NotificationEvent.Type.LevelUp, position, 1f);

            ++Singleton <SimulationManager> .instance.m_currentBuildIndex;
        }
        protected void StartUpgrading(ushort buildingID, ref Building buildingData)
        {
            Debug.LogFormat("StartUpgrading called: {0}", buildingData.Info.name);

            buildingData.m_frame0.m_constructState = 0;
            buildingData.m_frame1.m_constructState = 0;
            buildingData.m_frame2.m_constructState = 0;
            buildingData.m_frame3.m_constructState = 0;
            Building.Flags flags = buildingData.m_flags;
            flags |= Building.Flags.Upgrading;
            flags &= ~Building.Flags.Completed;
            flags &= ~Building.Flags.LevelUpEducation;
            flags &= ~Building.Flags.LevelUpLandValue;
            buildingData.m_flags = flags;
            BuildingManager instance = Singleton<BuildingManager>.instance;
            instance.UpdateBuildingRenderer(buildingID, true);
            EffectInfo levelupEffect = instance.m_properties.m_levelupEffect;
            if (levelupEffect != null)
            {
                InstanceID instance2 = default(InstanceID);
                instance2.Building = buildingID;
                Vector3 pos;
                Quaternion q;
                buildingData.CalculateMeshPosition(out pos, out q);
                Matrix4x4 matrix = Matrix4x4.TRS(pos, q, Vector3.one);
                EffectInfo.SpawnArea spawnArea = new EffectInfo.SpawnArea(matrix, buildingData.Info.m_lodMeshData);
                Singleton<EffectManager>.instance.DispatchEffect(levelupEffect, instance2, spawnArea, Vector3.zero, 0f, 1f, instance.m_audioGroup);
            }
            Vector3 position = buildingData.m_position;
            position.y += buildingData.Info.m_size.y;
            Singleton<NotificationManager>.instance.AddEvent(NotificationEvent.Type.LevelUp, position, 1f);
            Singleton<SimulationManager>.instance.m_currentBuildIndex += 1u;
        }
        public static void DispatchPlacementEffect(Vector3 pos, bool bulldozing)
        {
            EffectInfo effect = !bulldozing ? Singleton <PropManager> .instance.m_properties.m_placementEffect : Singleton <PropManager> .instance.m_properties.m_bulldozeEffect;

            if (effect == null)
            {
                return;
            }
            InstanceID instance = new InstanceID();

            EffectInfo.SpawnArea spawnArea = new EffectInfo.SpawnArea(pos, Vector3.up, 1f);
            Singleton <EffectManager> .instance.DispatchEffect(effect, instance, spawnArea, Vector3.zero, 0.0f, 1f, Singleton <AudioManager> .instance.DefaultGroup);
        }
        public static void DispatchAutobulldozeEffect(BuildingInfo info, Vector3 pos, float angle, int length)
        {
            EffectInfo effect = Singleton <BuildingManager> .instance.m_properties.m_bulldozeEffect;

            if (effect == null)
            {
                return;
            }
            InstanceID instance = new InstanceID();

            EffectInfo.SpawnArea spawnArea = new EffectInfo.SpawnArea(Matrix4x4.TRS(Building.CalculateMeshPosition(info, pos, angle, length), Building.CalculateMeshRotation(angle), Vector3.one), info.m_lodMeshData);
            Singleton <EffectManager> .instance.DispatchEffect(effect, instance, spawnArea, Vector3.zero, 0.0f, 1f, nullAudioGroup);
        }
Beispiel #6
0
        internal static void DispatchAutobulldozeEffect(this Building building, ref ushort buildingId, AudioGroup nullAudioGroup)
        {
            var effect = Singleton <BuildingManager> .instance.m_properties.m_bulldozeEffect;

            if (effect == null)
            {
                return;
            }
            var instance = new InstanceID();
            var matrix   = Matrix4x4.TRS(
                Building.CalculateMeshPosition(building.Info, building.m_position, building.m_angle, building.Length),
                Building.CalculateMeshRotation(building.m_angle), Vector3.one);

            EffectInfo.SpawnArea spawnArea;
            var collapsed = (building.m_flags & Building.Flags.Collapsed) != Building.Flags.None;

            if (collapsed)
            {
                var collapsedInfo = (BuildingInfoBase)building.Info.m_collapsedInfo;
                if (!(collapsedInfo != null))
                {
                    return;
                }
                var num = new Randomizer(buildingId).Int32(4U);
                if ((1 << num & building.Info.m_collapsedRotations) == 0)
                {
                    num = num + 1 & 3;
                }
                var x1 = building.Width * 4f;
                var z1 = building.Length * 4f;
                var localMeshOffset = Building.CalculateLocalMeshOffset(building.Info, building.Length);
                var vector31        = Vector3.Max(building.Info.m_generatedInfo.m_min - new Vector3(4f, 0.0f, 4f + localMeshOffset), new Vector3(-x1, 0.0f, -z1));
                var vector32        = Vector3.Min(building.Info.m_generatedInfo.m_max + new Vector3(4f, 0.0f, 4f - localMeshOffset), new Vector3(x1, 0.0f, z1));
                var vector33        = (vector31 + vector32) * 0.5f;
                var vector34        = vector32 - vector31;
                var x2        = ((num & 1) != 0 ? vector34.z : vector34.x) / Mathf.Max(1f, collapsedInfo.m_generatedInfo.m_size.x);
                var z2        = ((num & 1) != 0 ? vector34.x : vector34.z) / Mathf.Max(1f, collapsedInfo.m_generatedInfo.m_size.z);
                var q         = Quaternion.AngleAxis(num * 90f, Vector3.down);
                var matrix4X4 = Matrix4x4.TRS(new Vector3(vector33.x, 0.0f, vector33.z + localMeshOffset), q, new Vector3(x2, 1f, z2));

                spawnArea = new EffectInfo.SpawnArea(matrix * matrix4X4, collapsedInfo.m_lodMeshData);
            }
            else
            {
                spawnArea = new EffectInfo.SpawnArea(matrix, building.Info.m_lodMeshData);
            }
            Singleton <EffectManager> .instance.DispatchEffect(effect, instance, spawnArea, Vector3.zero, 0.0f, 1f, nullAudioGroup);
        }
Beispiel #7
0
        public override void RenderEffect(InstanceID id, EffectInfo.SpawnArea area, Vector3 velocity, float acceleration, float magnitude, float timeOffset, float timeDelta, RenderManager.CameraInfo cameraInfo)
        {
            Vector3 point = area.m_matrix.MultiplyPoint(Vector3.zero);

            if (cameraInfo.CheckRenderDistance(point, this.m_maxVisibilityDistance) && cameraInfo.Intersect(point, 100f))
            {
                Vector3 vector  = new Vector3(100000f, 100000f, 100000f);
                Vector3 vector2 = new Vector3(-100000f, -100000f, -100000f);

                magnitude = Mathf.Min(magnitude, this.m_minMagnitude + velocity.magnitude * this.m_magnitudeSpeedMultiplier + acceleration * this.m_magnitudeAccelerationMultiplier);
                float particlesPerSquare = timeDelta * magnitude * 0.01f;

                velocity = velocity * m_velocityMultiplier;

                EmitParticles(id, area.m_matrix, area.m_positions, velocity, particlesPerSquare, 100, ref vector, ref vector2);
            }
        }
 protected override void ArrivingToDestination(ushort vehicleID, ref Vehicle vehicleData)
 {
     base.ArrivingToDestination(vehicleID, ref vehicleData);
     if (this.m_arriveEffect == null)
     {
         return;
     }
     if ((vehicleData.m_flags & Vehicle.Flags.GoingBack) != ~(Vehicle.Flags.Created | Vehicle.Flags.Deleted | Vehicle.Flags.Spawned | Vehicle.Flags.Inverted | Vehicle.Flags.TransferToTarget | Vehicle.Flags.TransferToSource | Vehicle.Flags.Emergency1 | Vehicle.Flags.Emergency2 | Vehicle.Flags.WaitingPath | Vehicle.Flags.Stopped | Vehicle.Flags.Leaving | Vehicle.Flags.Arriving | Vehicle.Flags.Reversed | Vehicle.Flags.TakingOff | Vehicle.Flags.Flying | Vehicle.Flags.Landing | Vehicle.Flags.WaitingSpace | Vehicle.Flags.WaitingCargo | Vehicle.Flags.GoingBack | Vehicle.Flags.WaitingTarget | Vehicle.Flags.Importing | Vehicle.Flags.Exporting | Vehicle.Flags.Parking | Vehicle.Flags.CustomName | Vehicle.Flags.OnGravel | Vehicle.Flags.WaitingLoading | Vehicle.Flags.Congestion | Vehicle.Flags.DummyTraffic | Vehicle.Flags.Underground | Vehicle.Flags.Transition | Vehicle.Flags.InsideBuilding | Vehicle.Flags.LeftHandDrive))
     {
         if ((int)vehicleData.m_sourceBuilding == 0)
         {
             return;
         }
         Vector3    position = Singleton <BuildingManager> .instance.m_buildings.m_buffer[(int)vehicleData.m_sourceBuilding].m_position;
         InstanceID instance = new InstanceID();
         instance.Building = vehicleData.m_sourceBuilding;
         EffectInfo.SpawnArea spawnArea = new EffectInfo.SpawnArea(position, Vector3.up, 0.0f);
         Singleton <EffectManager> .instance.DispatchEffect(this.m_arriveEffect, instance, spawnArea, Vector3.zero, 0.0f, 1f, Singleton <BuildingManager> .instance.m_audioGroup);
     }
     else if ((vehicleData.m_flags & Vehicle.Flags.DummyTraffic) != ~(Vehicle.Flags.Created | Vehicle.Flags.Deleted | Vehicle.Flags.Spawned | Vehicle.Flags.Inverted | Vehicle.Flags.TransferToTarget | Vehicle.Flags.TransferToSource | Vehicle.Flags.Emergency1 | Vehicle.Flags.Emergency2 | Vehicle.Flags.WaitingPath | Vehicle.Flags.Stopped | Vehicle.Flags.Leaving | Vehicle.Flags.Arriving | Vehicle.Flags.Reversed | Vehicle.Flags.TakingOff | Vehicle.Flags.Flying | Vehicle.Flags.Landing | Vehicle.Flags.WaitingSpace | Vehicle.Flags.WaitingCargo | Vehicle.Flags.GoingBack | Vehicle.Flags.WaitingTarget | Vehicle.Flags.Importing | Vehicle.Flags.Exporting | Vehicle.Flags.Parking | Vehicle.Flags.CustomName | Vehicle.Flags.OnGravel | Vehicle.Flags.WaitingLoading | Vehicle.Flags.Congestion | Vehicle.Flags.DummyTraffic | Vehicle.Flags.Underground | Vehicle.Flags.Transition | Vehicle.Flags.InsideBuilding | Vehicle.Flags.LeftHandDrive))
     {
         if ((int)vehicleData.m_targetBuilding == 0)
         {
             return;
         }
         Vector3    position = Singleton <BuildingManager> .instance.m_buildings.m_buffer[(int)vehicleData.m_targetBuilding].m_position;
         InstanceID instance = new InstanceID();
         instance.Building = vehicleData.m_targetBuilding;
         EffectInfo.SpawnArea spawnArea = new EffectInfo.SpawnArea(position, Vector3.up, 0.0f);
         Singleton <EffectManager> .instance.DispatchEffect(this.m_arriveEffect, instance, spawnArea, Vector3.zero, 0.0f, 1f, Singleton <BuildingManager> .instance.m_audioGroup);
     }
     else
     {
         if ((int)vehicleData.m_targetBuilding == 0)
         {
             return;
         }
         Vector3    position = Singleton <NetManager> .instance.m_nodes.m_buffer[(int)vehicleData.m_targetBuilding].m_position;
         InstanceID instance = new InstanceID();
         instance.NetNode = vehicleData.m_targetBuilding;
         EffectInfo.SpawnArea spawnArea = new EffectInfo.SpawnArea(position, Vector3.up, 0.0f);
         Singleton <EffectManager> .instance.DispatchEffect(this.m_arriveEffect, instance, spawnArea, Vector3.zero, 0.0f, 1f, Singleton <BuildingManager> .instance.m_audioGroup);
     }
 }
Beispiel #9
0
        protected override void OnLeftClick()
        {
            LogUtils.DoLog("OnLeftClick");
            if (m_hoverSegment > 0 && (SegmentBuffer[m_hoverSegment].m_flags & NetSegment.Flags.Untouchable) != 0)
            {
                LogUtils.DoLog("Touching!");
                var id = new InstanceID
                {
                    NetSegment = m_hoverSegment
                };

                Singleton <NetManager> .instance.m_segments.m_buffer[m_hoverSegment].m_flags &= ~NetSegment.Flags.Untouchable;

                EffectInfo effectInfo = Singleton <NetManager> .instance.m_properties.m_placementEffect;

                var spawnArea = new EffectInfo.SpawnArea(new Vector3(), new Vector3(), 0);
                Singleton <EffectManager> .instance.DispatchEffect(effectInfo, id, spawnArea, Vector3.zero, 0f, 1f, Singleton <AudioManager> .instance.DefaultGroup, 0u, true);

                LogUtils.DoLog("Touched!");
            }
        }
        // Simply copied from the original code, just deleted the code for focusing the launch site.
        protected override void BeginEvent(ushort eventID, ref EventData data)
        {
            if ((data.m_flags & EventData.Flags.Ready) == EventData.Flags.None)
            {
                data.m_flags = ((data.m_flags & ~EventData.Flags.Preparing) | EventData.Flags.Ready);
                return;
            }
            data.m_flags |= EventData.Flags.Success;
            base.BeginEvent(eventID, ref data);
            data.m_startFrame  = Singleton <SimulationManager> .instance.m_currentFrameIndex;
            data.m_expireFrame = CalculateExpireFrame(data.m_startFrame);
            VehicleManager instance = Singleton <VehicleManager> .instance;

            FindVehicles(eventID, ref data, out ushort crawler, out ushort rocket);
            if (crawler != 0)
            {
                VehicleInfo info = instance.m_vehicles.m_buffer[crawler].Info;
                info.m_vehicleAI.SetTarget(crawler, ref instance.m_vehicles.m_buffer[crawler], 0);
            }
            if (rocket != 0)
            {
                ushort leadingVehicle = instance.m_vehicles.m_buffer[rocket].m_leadingVehicle;
                if (leadingVehicle != 0)
                {
                    instance.m_vehicles.m_buffer[leadingVehicle].m_trailingVehicle = 0;
                    instance.m_vehicles.m_buffer[rocket].m_leadingVehicle          = 0;
                }
                VehicleInfo info2 = instance.m_vehicles.m_buffer[rocket].Info;
                info2.m_vehicleAI.SetTarget(rocket, ref instance.m_vehicles.m_buffer[rocket], 0);
            }
            if ((object)m_launchAlarmEffect != null && data.m_building != 0)
            {
                InstanceID instance2 = default(InstanceID);
                instance2.Event = eventID;
                Vector3 position = Singleton <BuildingManager> .instance.m_buildings.m_buffer[data.m_building].CalculatePosition(m_rocketLaunchPosition);
                EffectInfo.SpawnArea spawnArea = new EffectInfo.SpawnArea(position, Vector3.up, 10f);
                Singleton <EffectManager> .instance.DispatchEffect(m_launchAlarmEffect, instance2, spawnArea, Vector3.zero, 0f, 1f, Singleton <AudioManager> .instance.DefaultGroup);
            }
        }
        private static void ApplyZoning(ZoneTool z)
        {
            Vector3 m_startPosition = (Vector3)z.GetType().GetField("m_startPosition", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(z);
            Vector3 m_mousePosition = (Vector3)z.GetType().GetField("m_mousePosition", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(z);
            Vector3 m_startDirection = (Vector3)z.GetType().GetField("m_startDirection", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(z);

            Vector2 vector2_1 = VectorUtils.XZ(m_startPosition);
            Vector2 vector2_2 = VectorUtils.XZ(m_mousePosition);
            Vector2 vector2_3 = VectorUtils.XZ(m_startDirection);
            Vector2 vector2_4 = new Vector2(vector2_3.y, -vector2_3.x);
            float num1 = Mathf.Round((float)((((double)vector2_2.x - (double)vector2_1.x) * (double)vector2_3.x + ((double)vector2_2.y - (double)vector2_1.y) * (double)vector2_3.y) * 0.125)) * 8f;
            float num2 = Mathf.Round((float)((((double)vector2_2.x - (double)vector2_1.x) * (double)vector2_4.x + ((double)vector2_2.y - (double)vector2_1.y) * (double)vector2_4.y) * 0.125)) * 8f;
            float num3 = (double)num1 < 0.0 ? -4f : 4f;
            float num4 = (double)num2 < 0.0 ? -4f : 4f;
            Quad2 quad2 = new Quad2();
            quad2.a = vector2_1 - vector2_3 * num3 - vector2_4 * num4;
            quad2.b = vector2_1 - vector2_3 * num3 + vector2_4 * (num2 + num4);
            quad2.c = vector2_1 + vector2_3 * (num1 + num3) + vector2_4 * (num2 + num4);
            quad2.d = vector2_1 + vector2_3 * (num1 + num3) - vector2_4 * num4;
            if ((double)num3 == (double)num4)
            {
                Vector2 vector2_5 = quad2.b;
                quad2.b = quad2.d;
                quad2.d = vector2_5;
            }
            Vector2 vector2_6 = quad2.Min();
            Vector2 vector2_7 = quad2.Max();
            int num5 = Mathf.Max((int)((vector2_6.x - 46f) / 64f + FakeZoneManager.HALFGRID), 0);
            int num6 = Mathf.Max((int)((vector2_6.y - 46f) / 64f + FakeZoneManager.HALFGRID), 0);
            int num7 = Mathf.Min((int)((vector2_7.x + 46f) / 64f + FakeZoneManager.HALFGRID), FakeZoneManager.GRIDSIZE - 1);
            int num8 = Mathf.Min((int)((vector2_7.y + 46f) / 64f + FakeZoneManager.HALFGRID), FakeZoneManager.GRIDSIZE - 1);
            var instance1 = ZoneManager.instance;
            bool flag = false;
            for (int index1 = num6; index1 <= num8; ++index1)
            {
                for (int index2 = num5; index2 <= num7; ++index2)
                {
                    ushort blockIndex = FakeZoneManager.zoneGrid[index1 * FakeZoneManager.GRIDSIZE + index2];
                    int num9 = 0;
                    while ((int)blockIndex != 0)
                    {
                        Vector3 vector3 = instance1.m_blocks.m_buffer[(int)blockIndex].m_position;
                        if ((double)Mathf.Max(Mathf.Max(vector2_6.x - 46f - vector3.x, vector2_6.y - 46f - vector3.z), Mathf.Max((float)((double)vector3.x - (double)vector2_7.x - 46.0), (float)((double)vector3.z - (double)vector2_7.y - 46.0))) < 0.0 && ApplyZoning(z, blockIndex, ref instance1.m_blocks.m_buffer[(int)blockIndex], quad2))
                            flag = true;
                        blockIndex = instance1.m_blocks.m_buffer[(int)blockIndex].m_nextGridBlock;
                        if (++num9 >= 32768)
                        {
                            CODebugBase<LogChannel>.Error(LogChannel.Core, "Invalid list detected!\n" + System.Environment.StackTrace);
                            break;
                        }
                    }
                }
            }
            if (!flag)
                return;
            bool m_zoning = (bool)z.GetType().GetField("m_validPosition", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(z);
            if (m_zoning)
                z.GetType().GetMethod("UsedZone", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(z, new object[] { z.m_zone });
            EffectInfo effect = instance1.m_properties.m_fillEffect;
            if (effect == null)
                return;
            InstanceID instance2 = new InstanceID();
            EffectInfo.SpawnArea spawnArea = new EffectInfo.SpawnArea((Vector3)((vector2_1 + vector2_2) * 0.5f), Vector3.up, 1f);
            Singleton<EffectManager>.instance.DispatchEffect(effect, instance2, spawnArea, Vector3.zero, 0.0f, 1f, Singleton<AudioManager>.instance.DefaultGroup);
        }
        private static void ApplyFill(ZoneTool z)
        {
            bool m_validPosition = (bool)z.GetType().GetField("m_validPosition", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(z);
            if (!m_validPosition)
                return;

            Vector3 position = (Vector3)z.GetType().GetField("m_mousePosition", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(z);
            Vector3 direction = (Vector3)z.GetType().GetField("m_mouseDirection", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(z);
            float angle = Mathf.Atan2(-direction.x, direction.z);
            float num1 = position.x - 256f;
            float num2 = position.z - 256f;
            float num3 = position.x + 256f;
            float num4 = position.z + 256f;
            int num5 = Mathf.Max((int)((num1 - 46f) / 64f + FakeZoneManager.HALFGRID), 0);
            int num6 = Mathf.Max((int)((num2 - 46f) / 64f + FakeZoneManager.HALFGRID), 0);
            int num7 = Mathf.Min((int)((num3 + 46f) / 64f + FakeZoneManager.HALFGRID), FakeZoneManager.GRIDSIZE - 1);
            int num8 = Mathf.Min((int)((num4 + 46f) / 64f + FakeZoneManager.HALFGRID), FakeZoneManager.GRIDSIZE - 1);
            ZoneManager instance1 = Singleton<ZoneManager>.instance;
            bool flag = false;
            for (int index1 = num6; index1 <= num8; ++index1)
            {
                for (int index2 = num5; index2 <= num7; ++index2)
                {
                    ushort blockIndex = FakeZoneManager.zoneGrid[index1 * FakeZoneManager.GRIDSIZE + index2];
                    int num9 = 0;
                    while ((int)blockIndex != 0)
                    {
                        Vector3 vector3 = instance1.m_blocks.m_buffer[(int)blockIndex].m_position;
                        if ((double)Mathf.Max(Mathf.Max(num1 - 46f - vector3.x, num2 - 46f - vector3.z), Mathf.Max((float)((double)vector3.x - (double)num3 - 46.0), (float)((double)vector3.z - (double)num4 - 46.0))) < 0.0 && ApplyFillBuffer(z, position, direction, angle, blockIndex, ref instance1.m_blocks.m_buffer[(int)blockIndex]))
                            flag = true;
                        blockIndex = instance1.m_blocks.m_buffer[(int)blockIndex].m_nextGridBlock;
                        if (++num9 >= 32768)
                        {
                            CODebugBase<LogChannel>.Error(LogChannel.Core, "Invalid list detected!\n" + System.Environment.StackTrace);
                            break;
                        }
                    }
                }
            }
            if (!flag)
                return;

            bool m_zoning = (bool)z.GetType().GetField("m_validPosition", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(z);
            if (m_zoning)
                z.GetType().GetMethod("UsedZone", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(z, new object[] { z.m_zone });
            EffectInfo effect = instance1.m_properties.m_fillEffect;
            if (effect == null)
                return;
            InstanceID instance2 = new InstanceID();
            EffectInfo.SpawnArea spawnArea = new EffectInfo.SpawnArea(position, Vector3.up, 1f);
            Singleton<EffectManager>.instance.DispatchEffect(effect, instance2, spawnArea, Vector3.zero, 0.0f, 1f, Singleton<AudioManager>.instance.DefaultGroup);
        }
Beispiel #13
0
        public static bool DestroyBuilding(ushort index)
        {
            Building building = buildManager.m_buildings.m_buffer[index];

            if (building.m_flags == Building.Flags.None)
            {
                return(false);
            }
//			Debug.Log("Building flags are: " + build.m_flags);

            BuildingInfo info = building.Info;

            // We don't care about burning buildings
//			if (info.m_buildingAI.CheckBulldozing(index, ref build) != ToolBase.ToolErrors.None) {
//				Debug.Log(info.m_buildingAI.CheckBulldozing(index, ref build).ToString());
//				return false;
//			}

            // For now we're gonna remove just buildings. Later we'll remove everything :B
            if (info.m_placementStyle != ItemClass.Placement.Automatic)
            {
//				Debug.Log(info.m_class.ToString());
                return(false);
            }

            int amount = info.m_buildingAI.GetRefundAmount(index, ref building);

            if (amount != 0)
            {
                Singleton <EconomyManager> .instance.AddResource(EconomyManager.Resource.RefundAmount, amount, info.m_class);
            }

            Vector3 position = building.m_position;
            float   angle    = building.m_angle;
            int     length   = building.m_length;

            buildManager.ReleaseBuilding(index);

            EffectInfo effect = Singleton <BuildingManager> .instance.m_properties.m_bulldozeEffect;

            if (effect == null)
            {
                return(false);
            }

            var instance  = new InstanceID();
            var spawnArea = new EffectInfo.SpawnArea(
                Matrix4x4.TRS(
                    Building.CalculateMeshPosition(info, position, angle, length),
                    Building.CalculateMeshRotation(angle),
                    Vector3.one
                    ),
                info.m_lodMeshData
                );

            Singleton <EffectManager> .instance.DispatchEffect(effect, instance, spawnArea, Vector3.zero, 0.0f, 1f, nullAudioGroup);

//			var name = new InstanceID();
//			Debug.Log("Current building name is " + buildManager.GetBuildingName(index, name));
            Debug.Log("Building should be destroyed now...");

            return(true);
        }
        public override void SimulationStep(ushort instanceID, ref CitizenInstance citizenData, ref CitizenInstance.Frame frameData, bool lodPhysics)
        {
            float sqrMagnitude1 = frameData.m_velocity.sqrMagnitude;

            if ((double)sqrMagnitude1 > 0.00999999977648258)
            {
                frameData.m_position += frameData.m_velocity * 0.5f;
            }
            Vector3 vector3_1     = (Vector3)citizenData.m_targetPos - frameData.m_position;
            float   sqrMagnitude2 = vector3_1.sqrMagnitude;
            float   num1          = Mathf.Max(sqrMagnitude1 * 3f, 6f);

            if ((double)sqrMagnitude2 < (double)num1 && Singleton <SimulationManager> .instance.m_randomizer.Int32(20U) == 0 && (int)citizenData.m_targetBuilding != 0)
            {
                BuildingManager       instance = Singleton <BuildingManager> .instance;
                Vector3               position;
                Vector3               target;
                Vector2               direction;
                CitizenInstance.Flags specialFlags;
                instance.m_buildings.m_buffer[(int)citizenData.m_targetBuilding].Info.m_buildingAI.CalculateUnspawnPosition(citizenData.m_targetBuilding, ref instance.m_buildings.m_buffer[(int)citizenData.m_targetBuilding], ref Singleton <SimulationManager> .instance.m_randomizer, this.m_info, instanceID, out position, out target, out direction, out specialFlags);
                position.y = Singleton <TerrainManager> .instance.SampleDetailHeight(position);

                citizenData.m_targetPos = (Vector4)position;
                vector3_1     = (Vector3)citizenData.m_targetPos - frameData.m_position;
                sqrMagnitude2 = vector3_1.sqrMagnitude;
            }
            float a = this.m_info.m_walkSpeed;
            float b = 2f;

            if ((double)sqrMagnitude2 < 4.0)
            {
                vector3_1 = Vector3.zero;
            }
            else
            {
                float num2 = Mathf.Sqrt(sqrMagnitude2);
                //begin mod
                if (isFreeAnimal(citizenData))
                {
                    float   maxLength = Mathf.Min(a, Mathf.Sqrt(num2 * b));
                    float   num3_     = Mathf.Max(1f, 0.5f * sqrMagnitude1 / b);
                    float   num4      = Mathf.Max(8f, 0.5f * sqrMagnitude1 / b + maxLength);
                    Vector3 position  = frameData.m_position + vector3_1 * (num3_ / num2);
                    var     stubAi    = new WildlifeAI {
                        m_info = this.m_info
                    };

                    if (WildlifeAIDetour.IsFreePosition(stubAi, frameData.m_position + vector3_1 * (num4 / num2)))
                    {
                        vector3_1 = Quaternion.Inverse(frameData.m_rotation) * vector3_1;
                        if ((double)vector3_1.z < (double)Mathf.Abs(vector3_1.x) * 1.70000004768372)
                        {
                            vector3_1.x = (double)vector3_1.x < 0.0 ? Mathf.Min(-1f, vector3_1.x) : Mathf.Max(1f, vector3_1.x);
                            vector3_1.z = Mathf.Abs(vector3_1.x) * 1.7f;
                            maxLength   = Mathf.Min(1.5f, num2 * 0.1f);
                        }
                        vector3_1 = Vector3.ClampMagnitude(frameData.m_rotation * vector3_1, maxLength);
                    }
                    else if (WildlifeAIDetour.IsFreePosition(stubAi, position))
                    {
                        citizenData.m_targetPos = (Vector4)position;
                        vector3_1 = Vector3.zero;
                    }
                    else if (WildlifeAIDetour.IsFreePosition(stubAi, frameData.m_position))
                    {
                        citizenData.m_targetPos = (Vector4)frameData.m_position;
                        vector3_1 = Vector3.zero;
                    }
                    else
                    {
                        citizenData.Unspawn(instanceID);
                        return;
                    }
                }
                else
                {
                    //end mod
                    float maxLength = Mathf.Min(a, num2 * 0.5f);
                    vector3_1 = Quaternion.Inverse(frameData.m_rotation) * vector3_1;
                    if ((double)vector3_1.z < (double)Mathf.Abs(vector3_1.x) * 5.0)
                    {
                        vector3_1.x = (double)vector3_1.x < 0.0 ? Mathf.Min(-1f, vector3_1.x) : Mathf.Max(1f, vector3_1.x);
                        vector3_1.z = Mathf.Abs(vector3_1.x) * 5f;
                        maxLength   = Mathf.Min(0.5f, num2 * 0.1f);
                    }
                    vector3_1 = Vector3.ClampMagnitude(frameData.m_rotation * vector3_1, maxLength);
                    //begin mod
                }
                //end mod
            }
            Vector3 vector3_2 = vector3_1 - frameData.m_velocity;
            float   magnitude = vector3_2.magnitude;
            Vector3 vector3_3 = vector3_2 * (b / Mathf.Max(magnitude, b));

            frameData.m_velocity     += vector3_3;
            citizenData.m_targetPos.y = Singleton <TerrainManager> .instance.SampleDetailHeight(frameData.m_position + frameData.m_velocity);

            frameData.m_velocity.y = citizenData.m_targetPos.y - frameData.m_position.y;
            float sqrMagnitude3 = frameData.m_velocity.sqrMagnitude;

            if ((double)sqrMagnitude3 > 0.00999999977648258)
            {
                Vector3 forward = frameData.m_velocity;
                if (!lodPhysics)
                {
                    Vector3 pushAmount  = Vector3.zero;
                    float   pushDivider = 0.0f;
                    //begin mod
                    this.CheckCollisions(instanceID, ref citizenData, frameData.m_position, frameData.m_position + frameData.m_velocity, isFreeAnimal(citizenData) ? (ushort)0 : citizenData.m_targetBuilding, ref pushAmount, ref pushDivider);
                    //end mod
                    if ((double)pushDivider > 0.00999999977648258)
                    {
                        pushAmount           *= 1f / pushDivider;
                        pushAmount            = Vector3.ClampMagnitude(pushAmount, Mathf.Sqrt(sqrMagnitude3) * 0.5f);
                        frameData.m_velocity += pushAmount;
                        forward += pushAmount * 0.25f;
                    }
                }
                frameData.m_position += frameData.m_velocity * 0.5f;
                if ((double)forward.sqrMagnitude > 0.00999999977648258)
                {
                    frameData.m_rotation = Quaternion.LookRotation(forward);
                }
            }
            if (this.m_randomEffect == null || Singleton <SimulationManager> .instance.m_randomizer.Int32(40U) != 0)
            {
                return;
            }
            InstanceID instance1 = new InstanceID();

            instance1.CitizenInstance = instanceID;
            EffectInfo.SpawnArea spawnArea = new EffectInfo.SpawnArea(frameData.m_position, Vector3.up, 0.0f);
            float num3 = 3.75f;

            Singleton <EffectManager> .instance.DispatchEffect(this.m_randomEffect, instance1, spawnArea, frameData.m_velocity *num3, 0.0f, 1f, Singleton <CitizenManager> .instance.m_audioGroup);
        }
        // Run before the original method. Skip the original one if the vehicle is a cable car
        public static bool Prefix(RenderManager.CameraInfo cameraInfo, VehicleInfo info, Vector3 position, ref Quaternion rotation, Vector3 swayPosition, Vector4 lightState, Vector4 tyrePosition, Vector3 velocity, float acceleration, Color color, Vehicle.Flags flags, int variationMask, InstanceID id, bool underground, bool overground)
        {
            // if the vehicle is not a cable car, skip and use the original method
            if ((int)info.m_vehicleType != 0x1000)
            {
                return(true);
            }

            // limit rotation along the x and z axes for all meshes except submesh1
            // submesh1 would rotate in the original way(along with the cable)
            Quaternion originalRotation = rotation;

            rotation.x = 0.0f;
            rotation.z = 0.0f;

            // change how cable cars sway
            // so they don't move up and down on the cables as if they're ships moving in sea waves
            swayPosition.y = 0.0f;

            if ((cameraInfo.m_layerMask & (1 << info.m_prefabDataLayer)) == 0)
            {
                // return false to skip the original method
                return(false);
            }
            Vector3 scale = Vector3.one;

            if ((flags & Vehicle.Flags.Inverted) != 0)
            {
                scale = new Vector3(-1f, 1f, -1f);
                Vector4 vector = lightState;
                lightState.x = vector.y;
                lightState.y = vector.x;
                lightState.z = vector.w;
                lightState.w = vector.z;
            }

            info.m_vehicleAI.RenderExtraStuff(id.Vehicle, ref Singleton <VehicleManager> .instance.m_vehicles.m_buffer[id.Vehicle], cameraInfo, id, position, rotation, tyrePosition, lightState, scale, swayPosition, underground, overground);

            if (cameraInfo.CheckRenderDistance(position, info.m_lodRenderDistance))
            {
                VehicleManager instance           = Singleton <VehicleManager> .instance;
                Matrix4x4      bodyMatrix         = info.m_vehicleAI.CalculateBodyMatrix(flags, ref position, ref rotation, ref scale, ref swayPosition);
                Matrix4x4      originalBodyMatrix = info.m_vehicleAI.CalculateBodyMatrix(flags, ref position, ref originalRotation, ref scale, ref swayPosition);
                Matrix4x4      value = info.m_vehicleAI.CalculateTyreMatrix(flags, ref position, ref rotation, ref scale, ref bodyMatrix);
                if (Singleton <InfoManager> .instance.CurrentMode == InfoManager.InfoMode.None)
                {
                    RenderGroup.MeshData effectMeshData = info.m_vehicleAI.GetEffectMeshData();
                    EffectInfo.SpawnArea area           = new EffectInfo.SpawnArea(bodyMatrix, effectMeshData, info.m_generatedInfo.m_tyres, info.m_lightPositions);
                    if (info.m_effects != null)
                    {
                        for (int i = 0; i < info.m_effects.Length; i++)
                        {
                            VehicleInfo.Effect effect = info.m_effects[i];
                            if (((effect.m_vehicleFlagsRequired | effect.m_vehicleFlagsForbidden) & flags) == effect.m_vehicleFlagsRequired && effect.m_parkedFlagsRequired == VehicleParked.Flags.None)
                            {
                                effect.m_effect.RenderEffect(id, area, velocity, acceleration, 1f, -1f, Singleton <SimulationManager> .instance.m_simulationTimeDelta, cameraInfo);
                            }
                        }
                    }
                }
                if ((flags & Vehicle.Flags.Inverted) != 0)
                {
                    tyrePosition.x = 0f - tyrePosition.x;
                    tyrePosition.y = 0f - tyrePosition.y;
                }
                MaterialPropertyBlock materialBlock = instance.m_materialBlock;
                materialBlock.Clear();
                materialBlock.SetMatrix(instance.ID_TyreMatrix, value);
                materialBlock.SetVector(instance.ID_TyrePosition, tyrePosition);
                materialBlock.SetVector(instance.ID_LightState, lightState);
                bool flag = Singleton <ToolManager> .instance.m_properties.m_mode == ItemClass.Availability.AssetEditor;
                if (!flag)
                {
                    materialBlock.SetColor(instance.ID_Color, color);
                }
                bool flag2 = true;
                if (flag)
                {
                    flag2 = BuildingDecoration.IsMainMeshRendered();
                }
                if (info.m_subMeshes != null)
                {
                    for (int j = 0; j < info.m_subMeshes.Length; j++)
                    {
                        VehicleInfo.MeshInfo meshInfo = info.m_subMeshes[j];
                        VehicleInfoBase      subInfo  = meshInfo.m_subInfo;
                        if ((!flag && ((meshInfo.m_vehicleFlagsRequired | meshInfo.m_vehicleFlagsForbidden) & flags) == meshInfo.m_vehicleFlagsRequired && (meshInfo.m_variationMask & variationMask) == 0 && meshInfo.m_parkedFlagsRequired == VehicleParked.Flags.None) || (flag && BuildingDecoration.IsSubMeshRendered(subInfo)))
                        {
                            if (!(subInfo != null))
                            {
                                continue;
                            }
                            instance.m_drawCallData.m_defaultCalls++;
                            if (underground)
                            {
                                if (subInfo.m_undergroundMaterial == null && subInfo.m_material != null)
                                {
                                    VehicleProperties properties = instance.m_properties;
                                    if (properties != null)
                                    {
                                        subInfo.m_undergroundMaterial = new Material(properties.m_undergroundShader);
                                        subInfo.m_undergroundMaterial.CopyPropertiesFromMaterial(subInfo.m_material);
                                    }
                                }
                                subInfo.m_undergroundMaterial.SetVectorArray(instance.ID_TyreLocation, subInfo.m_generatedInfo.m_tyres);
                                if (j == 1)
                                {
                                    Graphics.DrawMesh(subInfo.m_mesh, originalBodyMatrix, subInfo.m_undergroundMaterial, instance.m_undergroundLayer, null, 0, materialBlock);
                                }
                                else
                                {
                                    Graphics.DrawMesh(subInfo.m_mesh, bodyMatrix, subInfo.m_undergroundMaterial, instance.m_undergroundLayer, null, 0, materialBlock);
                                }
                            }
                            if (overground)
                            {
                                subInfo.m_material.SetVectorArray(instance.ID_TyreLocation, subInfo.m_generatedInfo.m_tyres);
                                if (j == 1)
                                {
                                    Graphics.DrawMesh(subInfo.m_mesh, originalBodyMatrix, subInfo.m_material, info.m_prefabDataLayer, null, 0, materialBlock);
                                }
                                else
                                {
                                    Graphics.DrawMesh(subInfo.m_mesh, bodyMatrix, subInfo.m_material, info.m_prefabDataLayer, null, 0, materialBlock);
                                }
                            }
                        }
                        else if (subInfo == null)
                        {
                            flag2 = false;
                        }
                    }
                }
                if (!flag2)
                {
                    // return false to skip the original method
                    return(false);
                }
                instance.m_drawCallData.m_defaultCalls++;
                if (underground)
                {
                    if (info.m_undergroundMaterial == null && info.m_material != null)
                    {
                        VehicleProperties properties2 = instance.m_properties;
                        if (properties2 != null)
                        {
                            info.m_undergroundMaterial = new Material(properties2.m_undergroundShader);
                            info.m_undergroundMaterial.CopyPropertiesFromMaterial(info.m_material);
                        }
                    }
                    info.m_undergroundMaterial.SetVectorArray(instance.ID_TyreLocation, info.m_generatedInfo.m_tyres);
                    Graphics.DrawMesh(info.m_mesh, bodyMatrix, info.m_undergroundMaterial, instance.m_undergroundLayer, null, 0, materialBlock);
                }
                if (overground)
                {
                    info.m_material.SetVectorArray(instance.ID_TyreLocation, info.m_generatedInfo.m_tyres);
                    Graphics.DrawMesh(info.m_mesh, bodyMatrix, info.m_material, info.m_prefabDataLayer, null, 0, materialBlock);
                }
                // return false to skip the original method
                return(false);
            }
            Matrix4x4 bodyMatrix2         = info.m_vehicleAI.CalculateBodyMatrix(flags, ref position, ref rotation, ref scale, ref swayPosition);
            Matrix4x4 originalBodyMatrix2 = info.m_vehicleAI.CalculateBodyMatrix(flags, ref position, ref originalRotation, ref scale, ref swayPosition);

            if (Singleton <ToolManager> .instance.m_properties.m_mode == ItemClass.Availability.AssetEditor)
            {
                Matrix4x4             value2         = info.m_vehicleAI.CalculateTyreMatrix(flags, ref position, ref rotation, ref scale, ref bodyMatrix2);
                VehicleManager        instance2      = Singleton <VehicleManager> .instance;
                MaterialPropertyBlock materialBlock2 = instance2.m_materialBlock;
                materialBlock2.Clear();
                materialBlock2.SetMatrix(instance2.ID_TyreMatrix, value2);
                materialBlock2.SetVector(instance2.ID_TyrePosition, tyrePosition);
                materialBlock2.SetVector(instance2.ID_LightState, lightState);
                Mesh     mesh     = null;
                Material material = null;
                if (info.m_lodObject != null)
                {
                    MeshFilter component = info.m_lodObject.GetComponent <MeshFilter>();
                    if (component != null)
                    {
                        mesh = component.sharedMesh;
                    }
                    Renderer component2 = info.m_lodObject.GetComponent <Renderer>();
                    if (component2 != null)
                    {
                        material = component2.sharedMaterial;
                    }
                }
                if (mesh != null && material != null)
                {
                    materialBlock2.SetVectorArray(instance2.ID_TyreLocation, info.m_generatedInfo.m_tyres);
                    Graphics.DrawMesh(mesh, bodyMatrix2, material, info.m_prefabDataLayer, null, 0, materialBlock2);
                }
            }
            else if (Singleton <InfoManager> .instance.CurrentMode == InfoManager.InfoMode.None)
            {
                RenderGroup.MeshData effectMeshData2 = info.m_vehicleAI.GetEffectMeshData();
                EffectInfo.SpawnArea area2           = new EffectInfo.SpawnArea(bodyMatrix2, effectMeshData2, info.m_generatedInfo.m_tyres, info.m_lightPositions);
                if (info.m_effects != null)
                {
                    for (int k = 0; k < info.m_effects.Length; k++)
                    {
                        VehicleInfo.Effect effect2 = info.m_effects[k];
                        if (((effect2.m_vehicleFlagsRequired | effect2.m_vehicleFlagsForbidden) & flags) == effect2.m_vehicleFlagsRequired && effect2.m_parkedFlagsRequired == VehicleParked.Flags.None)
                        {
                            effect2.m_effect.RenderEffect(id, area2, velocity, acceleration, 1f, -1f, Singleton <SimulationManager> .instance.m_simulationTimeDelta, cameraInfo);
                        }
                    }
                }
            }
            bool flag3 = true;

            if (info.m_subMeshes != null)
            {
                for (int l = 0; l < info.m_subMeshes.Length; l++)
                {
                    VehicleInfo.MeshInfo meshInfo2 = info.m_subMeshes[l];
                    VehicleInfoBase      subInfo2  = meshInfo2.m_subInfo;
                    if (((meshInfo2.m_vehicleFlagsRequired | meshInfo2.m_vehicleFlagsForbidden) & flags) == meshInfo2.m_vehicleFlagsRequired && (meshInfo2.m_variationMask & variationMask) == 0 && meshInfo2.m_parkedFlagsRequired == VehicleParked.Flags.None)
                    {
                        if (!(subInfo2 != null))
                        {
                            continue;
                        }
                        if (underground)
                        {
                            if (l == 1)
                            {
                                subInfo2.m_undergroundLodTransforms[subInfo2.m_undergroundLodCount] = originalBodyMatrix2;
                            }
                            else
                            {
                                subInfo2.m_undergroundLodTransforms[subInfo2.m_undergroundLodCount] = bodyMatrix2;
                            }

                            subInfo2.m_undergroundLodLightStates[subInfo2.m_undergroundLodCount] = lightState;
                            subInfo2.m_undergroundLodColors[subInfo2.m_undergroundLodCount]      = color.linear;
                            subInfo2.m_undergroundLodMin = Vector3.Min(subInfo2.m_undergroundLodMin, position);
                            subInfo2.m_undergroundLodMax = Vector3.Max(subInfo2.m_undergroundLodMax, position);
                            if (++subInfo2.m_undergroundLodCount == subInfo2.m_undergroundLodTransforms.Length)
                            {
                                Vehicle.RenderUndergroundLod(cameraInfo, subInfo2);
                            }
                        }
                        if (overground)
                        {
                            if (l == 1)
                            {
                                subInfo2.m_lodTransforms[subInfo2.m_lodCount] = originalBodyMatrix2;
                            }
                            else
                            {
                                subInfo2.m_lodTransforms[subInfo2.m_lodCount] = bodyMatrix2;
                            }
                            subInfo2.m_lodLightStates[subInfo2.m_lodCount] = lightState;
                            subInfo2.m_lodColors[subInfo2.m_lodCount]      = color.linear;
                            subInfo2.m_lodMin = Vector3.Min(subInfo2.m_lodMin, position);
                            subInfo2.m_lodMax = Vector3.Max(subInfo2.m_lodMax, position);
                            if (++subInfo2.m_lodCount == subInfo2.m_lodTransforms.Length)
                            {
                                Vehicle.RenderLod(cameraInfo, subInfo2);
                            }
                        }
                    }
                    else if (subInfo2 == null)
                    {
                        flag3 = false;
                    }
                }
            }
            if (!flag3)
            {
                return(false);
            }
            if (underground)
            {
                info.m_undergroundLodTransforms[info.m_undergroundLodCount]  = bodyMatrix2;
                info.m_undergroundLodLightStates[info.m_undergroundLodCount] = lightState;
                info.m_undergroundLodColors[info.m_undergroundLodCount]      = color.linear;
                info.m_undergroundLodMin = Vector3.Min(info.m_undergroundLodMin, position);
                info.m_undergroundLodMax = Vector3.Max(info.m_undergroundLodMax, position);
                if (++info.m_undergroundLodCount == info.m_undergroundLodTransforms.Length)
                {
                    Vehicle.RenderUndergroundLod(cameraInfo, info);
                }
            }
            if (overground)
            {
                info.m_lodTransforms[info.m_lodCount]  = bodyMatrix2;
                info.m_lodLightStates[info.m_lodCount] = lightState;
                info.m_lodColors[info.m_lodCount]      = color.linear;
                info.m_lodMin = Vector3.Min(info.m_lodMin, position);
                info.m_lodMax = Vector3.Max(info.m_lodMax, position);
                if (++info.m_lodCount == info.m_lodTransforms.Length)
                {
                    Vehicle.RenderLod(cameraInfo, info);
                }
            }
            // return false to skip the original method
            return(false);
        }
Beispiel #16
0
        private static void ApplyZoning(ZoneTool z)
        {
            Vector3 m_startPosition  = (Vector3)z.GetType().GetField("m_startPosition", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(z);
            Vector3 m_mousePosition  = (Vector3)z.GetType().GetField("m_mousePosition", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(z);
            Vector3 m_startDirection = (Vector3)z.GetType().GetField("m_startDirection", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(z);

            Vector2 vector2_1 = VectorUtils.XZ(m_startPosition);
            Vector2 vector2_2 = VectorUtils.XZ(m_mousePosition);
            Vector2 vector2_3 = VectorUtils.XZ(m_startDirection);
            Vector2 vector2_4 = new Vector2(vector2_3.y, -vector2_3.x);
            float   num1      = Mathf.Round((float)((((double)vector2_2.x - (double)vector2_1.x) * (double)vector2_3.x + ((double)vector2_2.y - (double)vector2_1.y) * (double)vector2_3.y) * 0.125)) * 8f;
            float   num2      = Mathf.Round((float)((((double)vector2_2.x - (double)vector2_1.x) * (double)vector2_4.x + ((double)vector2_2.y - (double)vector2_1.y) * (double)vector2_4.y) * 0.125)) * 8f;
            float   num3      = (double)num1 < 0.0 ? -4f : 4f;
            float   num4      = (double)num2 < 0.0 ? -4f : 4f;
            Quad2   quad2     = new Quad2();

            quad2.a = vector2_1 - vector2_3 * num3 - vector2_4 * num4;
            quad2.b = vector2_1 - vector2_3 * num3 + vector2_4 * (num2 + num4);
            quad2.c = vector2_1 + vector2_3 * (num1 + num3) + vector2_4 * (num2 + num4);
            quad2.d = vector2_1 + vector2_3 * (num1 + num3) - vector2_4 * num4;
            if ((double)num3 == (double)num4)
            {
                Vector2 vector2_5 = quad2.b;
                quad2.b = quad2.d;
                quad2.d = vector2_5;
            }
            Vector2 vector2_6 = quad2.Min();
            Vector2 vector2_7 = quad2.Max();
            int     num5      = Mathf.Max((int)((vector2_6.x - 46f) / 64f + FakeZoneManager.HALFGRID), 0);
            int     num6      = Mathf.Max((int)((vector2_6.y - 46f) / 64f + FakeZoneManager.HALFGRID), 0);
            int     num7      = Mathf.Min((int)((vector2_7.x + 46f) / 64f + FakeZoneManager.HALFGRID), FakeZoneManager.GRIDSIZE - 1);
            int     num8      = Mathf.Min((int)((vector2_7.y + 46f) / 64f + FakeZoneManager.HALFGRID), FakeZoneManager.GRIDSIZE - 1);
            var     instance1 = ZoneManager.instance;
            bool    flag      = false;

            for (int index1 = num6; index1 <= num8; ++index1)
            {
                for (int index2 = num5; index2 <= num7; ++index2)
                {
                    ushort blockIndex = instance1.m_zoneGrid[index1 * FakeZoneManager.GRIDSIZE + index2];
                    int    num9       = 0;
                    while ((int)blockIndex != 0)
                    {
                        Vector3 vector3 = instance1.m_blocks.m_buffer[(int)blockIndex].m_position;
                        if ((double)Mathf.Max(Mathf.Max(vector2_6.x - 46f - vector3.x, vector2_6.y - 46f - vector3.z), Mathf.Max((float)((double)vector3.x - (double)vector2_7.x - 46.0), (float)((double)vector3.z - (double)vector2_7.y - 46.0))) < 0.0 && ApplyZoning(z, blockIndex, ref instance1.m_blocks.m_buffer[(int)blockIndex], quad2))
                        {
                            flag = true;
                        }
                        blockIndex = instance1.m_blocks.m_buffer[(int)blockIndex].m_nextGridBlock;
                        if (++num9 >= ZoneManager.MAX_BLOCK_COUNT)
                        {
                            CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + System.Environment.StackTrace);

                            break;
                        }
                    }
                }
            }
            if (!flag)
            {
                return;
            }
            bool m_zoning = (bool)z.GetType().GetField("m_validPosition", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(z);

            if (m_zoning)
            {
                UsedZone(z, z.m_zone);
            }
            EffectInfo effect = instance1.m_properties.m_fillEffect;

            if (effect == null)
            {
                return;
            }
            InstanceID instance2 = new InstanceID();

            EffectInfo.SpawnArea spawnArea = new EffectInfo.SpawnArea((Vector3)((vector2_1 + vector2_2) * 0.5f), Vector3.up, 1f);
            Singleton <EffectManager> .instance.DispatchEffect(effect, instance2, spawnArea, Vector3.zero, 0.0f, 1f, Singleton <AudioManager> .instance.DefaultGroup);
        }
Beispiel #17
0
        private static void ApplyFill(ZoneTool z)
        {
            bool m_validPosition = (bool)z.GetType().GetField("m_validPosition", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(z);

            if (!m_validPosition)
            {
                return;
            }

            Vector3     position  = (Vector3)z.GetType().GetField("m_mousePosition", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(z);
            Vector3     direction = (Vector3)z.GetType().GetField("m_mouseDirection", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(z);
            float       angle     = Mathf.Atan2(-direction.x, direction.z);
            float       num1      = position.x - 256f;
            float       num2      = position.z - 256f;
            float       num3      = position.x + 256f;
            float       num4      = position.z + 256f;
            int         num5      = Mathf.Max((int)((num1 - 46f) / 64f + FakeZoneManager.HALFGRID), 0);
            int         num6      = Mathf.Max((int)((num2 - 46f) / 64f + FakeZoneManager.HALFGRID), 0);
            int         num7      = Mathf.Min((int)((num3 + 46f) / 64f + FakeZoneManager.HALFGRID), FakeZoneManager.GRIDSIZE - 1);
            int         num8      = Mathf.Min((int)((num4 + 46f) / 64f + FakeZoneManager.HALFGRID), FakeZoneManager.GRIDSIZE - 1);
            ZoneManager instance1 = Singleton <ZoneManager> .instance;
            bool        flag      = false;

            for (int index1 = num6; index1 <= num8; ++index1)
            {
                for (int index2 = num5; index2 <= num7; ++index2)
                {
                    ushort blockIndex = instance1.m_zoneGrid[index1 * FakeZoneManager.GRIDSIZE + index2];
                    int    num9       = 0;
                    while ((int)blockIndex != 0)
                    {
                        Vector3 vector3 = instance1.m_blocks.m_buffer[(int)blockIndex].m_position;
                        if ((double)Mathf.Max(Mathf.Max(num1 - 46f - vector3.x, num2 - 46f - vector3.z), Mathf.Max((float)((double)vector3.x - (double)num3 - 46.0), (float)((double)vector3.z - (double)num4 - 46.0))) < 0.0 && ApplyFillBuffer(z, position, direction, angle, blockIndex, ref instance1.m_blocks.m_buffer[(int)blockIndex]))
                        {
                            flag = true;
                        }
                        blockIndex = instance1.m_blocks.m_buffer[(int)blockIndex].m_nextGridBlock;
                        if (++num9 >= ZoneManager.MAX_BLOCK_COUNT)
                        {
                            CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + System.Environment.StackTrace);

                            break;
                        }
                    }
                }
            }
            if (!flag)
            {
                return;
            }

            bool m_zoning = (bool)z.GetType().GetField("m_validPosition", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(z);

            if (m_zoning)
            {
                UsedZone(z, z.m_zone);
            }
            EffectInfo effect = instance1.m_properties.m_fillEffect;

            if (effect == null)
            {
                return;
            }
            InstanceID instance2 = new InstanceID();

            EffectInfo.SpawnArea spawnArea = new EffectInfo.SpawnArea(position, Vector3.up, 1f);
            Singleton <EffectManager> .instance.DispatchEffect(effect, instance2, spawnArea, Vector3.zero, 0.0f, 1f, Singleton <AudioManager> .instance.DefaultGroup);
        }
Beispiel #18
0
        public override void SimulationStep(ushort instanceID, ref CitizenInstance citizenData, ref CitizenInstance.Frame frameData, bool lodPhysics)
        {
            if (IsCagedAnimal(citizenData))
            {
                SimulationStepCaged(instanceID, ref citizenData, ref frameData, lodPhysics);
                return;
            }
            else if (LivestockAIDetour.isFreeAnimal(citizenData))
            {
                SimulationStepWild(instanceID, ref citizenData, ref frameData, lodPhysics);
                return;
            }

            float sqrMagnitude1 = frameData.m_velocity.sqrMagnitude;

            if ((double)sqrMagnitude1 > 0.00999999977648258)
            {
                frameData.m_position += frameData.m_velocity * 0.5f;
            }
            CitizenInstance.Flags flags1 = CitizenInstance.Flags.None;
            if ((int)citizenData.m_targetBuilding != 0)
            {
                CitizenManager        instance = Singleton <CitizenManager> .instance;
                CitizenInstance.Flags flags2   = instance.m_instances.m_buffer[(int)citizenData.m_targetBuilding].m_flags;
                if ((flags2 & CitizenInstance.Flags.Character) != CitizenInstance.Flags.None)
                {
                    Randomizer            randomizer    = new Randomizer((int)instanceID);
                    CitizenInstance.Frame lastFrameData = instance.m_instances.m_buffer[(int)citizenData.m_targetBuilding].GetLastFrameData();
                    Vector3 vector3 = lastFrameData.m_rotation * new Vector3(0.5f, 0.0f, 0.0f);
                    if (randomizer.Int32(2U) == 0)
                    {
                        vector3 = -vector3;
                    }
                    Vector4 vector4 = instance.m_instances.m_buffer[(int)citizenData.m_targetBuilding].m_targetPos + (Vector4)vector3;
                    if ((double)Vector3.SqrMagnitude(lastFrameData.m_position - frameData.m_position) > 10000.0)
                    {
                        citizenData.m_targetBuilding = (ushort)0;
                    }
                    else
                    {
                        flags1 = flags2 & (CitizenInstance.Flags.Underground | CitizenInstance.Flags.InsideBuilding | CitizenInstance.Flags.Transition);
                        citizenData.m_targetPos = vector4;
                    }
                }
                else
                {
                    citizenData.m_targetBuilding = (ushort)0;
                }
            }
            citizenData.m_flags = citizenData.m_flags & ~(CitizenInstance.Flags.Underground | CitizenInstance.Flags.InsideBuilding | CitizenInstance.Flags.Transition) | flags1;
            Vector3 v = (Vector3)citizenData.m_targetPos - frameData.m_position;
            float   f = lodPhysics || (double)citizenData.m_targetPos.w <= 1.0 / 1000.0 ? v.sqrMagnitude : VectorUtils.LengthSqrXZ(v);
            float   a = this.m_info.m_walkSpeed;
            float   b = 2f;

            if ((double)f < 1.0)
            {
                v = Vector3.zero;
            }
            else
            {
                float num       = Mathf.Sqrt(f);
                float maxLength = Mathf.Min(a, num * 0.75f);
                v = Quaternion.Inverse(frameData.m_rotation) * v;
                if ((double)v.z < (double)Mathf.Abs(v.x))
                {
                    v.x       = (double)v.x < 0.0 ? Mathf.Min(-1f, v.x) : Mathf.Max(1f, v.x);
                    v.z       = Mathf.Abs(v.x);
                    maxLength = Mathf.Min(0.5f, num * 0.1f);
                }
                v = Vector3.ClampMagnitude(frameData.m_rotation * v, maxLength);
            }
            Vector3 vector3_1 = v - frameData.m_velocity;
            float   magnitude = vector3_1.magnitude;
            Vector3 vector3_2 = vector3_1 * (b / Mathf.Max(magnitude, b));

            frameData.m_velocity += vector3_2;
            float  sqrMagnitude2 = frameData.m_velocity.sqrMagnitude;
            bool   flag          = !lodPhysics && (double)citizenData.m_targetPos.w > 1.0 / 1000.0 && ((double)sqrMagnitude2 > 0.00999999977648258 || (double)sqrMagnitude1 > 0.00999999977648258);
            ushort buildingID    = !flag ? (ushort)0 : Singleton <BuildingManager> .instance.GetWalkingBuilding(frameData.m_position + frameData.m_velocity * 0.5f);

            if ((double)sqrMagnitude2 > 0.00999999977648258)
            {
                Vector3 forward = frameData.m_velocity;
                if (!lodPhysics)
                {
                    Vector3 pushAmount  = Vector3.zero;
                    float   pushDivider = 0.0f;
                    this.CheckCollisions(instanceID, ref citizenData, frameData.m_position, frameData.m_position + frameData.m_velocity, buildingID, ref pushAmount, ref pushDivider);
                    if ((double)pushDivider > 0.00999999977648258)
                    {
                        pushAmount           *= 1f / pushDivider;
                        pushAmount            = Vector3.ClampMagnitude(pushAmount, Mathf.Sqrt(sqrMagnitude2) * 0.5f);
                        frameData.m_velocity += pushAmount;
                        forward += pushAmount * 0.25f;
                    }
                }
                frameData.m_position += frameData.m_velocity * 0.5f;
                if ((double)forward.sqrMagnitude > 0.00999999977648258)
                {
                    frameData.m_rotation = Quaternion.LookRotation(forward);
                }
            }
            if (flag)
            {
                Vector3 worldPos      = frameData.m_position;
                float   terrainHeight = Singleton <TerrainManager> .instance.SampleDetailHeight(worldPos);

                if ((int)buildingID != 0)
                {
                    float num = Singleton <BuildingManager> .instance.m_buildings.m_buffer[(int)buildingID].SampleWalkingHeight(worldPos, terrainHeight);
                    worldPos.y             = worldPos.y + (num - worldPos.y) * Mathf.Min(1f, citizenData.m_targetPos.w * 4f);
                    frameData.m_position.y = worldPos.y;
                }
                else if ((double)Mathf.Abs(terrainHeight - worldPos.y) < 2.0)
                {
                    worldPos.y             = worldPos.y + (terrainHeight - worldPos.y) * Mathf.Min(1f, citizenData.m_targetPos.w * 4f);
                    frameData.m_position.y = worldPos.y;
                }
            }
            frameData.m_underground    = (citizenData.m_flags & CitizenInstance.Flags.Underground) != CitizenInstance.Flags.None;
            frameData.m_insideBuilding = (citizenData.m_flags & CitizenInstance.Flags.InsideBuilding) != CitizenInstance.Flags.None;
            frameData.m_transition     = (citizenData.m_flags & CitizenInstance.Flags.Transition) != CitizenInstance.Flags.None;
            var mRandomEffect = ((PetAI)Convert.ChangeType(this, typeof(PetAI))).m_randomEffect;

            if (mRandomEffect == null || Singleton <SimulationManager> .instance.m_randomizer.Int32(40U) != 0)
            {
                return;
            }
            InstanceID instance1 = new InstanceID();

            instance1.CitizenInstance = instanceID;
            EffectInfo.SpawnArea spawnArea = new EffectInfo.SpawnArea(frameData.m_position, Vector3.up, 0.0f);
            float num1 = 3.75f;

            Singleton <EffectManager> .instance.DispatchEffect(mRandomEffect, instance1, spawnArea, frameData.m_velocity *num1, 0.0f, 1f, Singleton <CitizenManager> .instance.m_audioGroup);
        }
Beispiel #19
0
        public void SimulationStepCaged(ushort instanceID, ref CitizenInstance citizenData, ref CitizenInstance.Frame frameData, bool lodPhysics)
        {
            float sqrMagnitude1 = frameData.m_velocity.sqrMagnitude;

            if ((double)sqrMagnitude1 > 0.00999999977648258)
            {
                frameData.m_position += frameData.m_velocity * 0.5f;
            }
            Vector3 vector3_1     = (Vector3)citizenData.m_targetPos - frameData.m_position;
            float   sqrMagnitude2 = vector3_1.sqrMagnitude;
            float   num1          = Mathf.Max(sqrMagnitude1 * 3f, 6f);

            if ((double)sqrMagnitude2 < (double)num1 && Singleton <SimulationManager> .instance.m_randomizer.Int32(20U) == 0 && (int)citizenData.m_targetBuilding != 0)
            {
                BuildingManager       instance = Singleton <BuildingManager> .instance;
                Vector3               position;
                Vector3               target;
                Vector2               direction;
                CitizenInstance.Flags specialFlags;
                instance.m_buildings.m_buffer[(int)citizenData.m_targetBuilding].Info.m_buildingAI.CalculateUnspawnPosition(citizenData.m_targetBuilding, ref instance.m_buildings.m_buffer[(int)citizenData.m_targetBuilding], ref Singleton <SimulationManager> .instance.m_randomizer, this.m_info, instanceID, out position, out target, out direction, out specialFlags);
                position.y = Singleton <TerrainManager> .instance.SampleDetailHeight(position);

                citizenData.m_targetPos = (Vector4)position;
                vector3_1     = (Vector3)citizenData.m_targetPos - frameData.m_position;
                sqrMagnitude2 = vector3_1.sqrMagnitude;
            }
            float a = this.m_info.m_walkSpeed;
            float b = 2f;

            if ((double)sqrMagnitude2 < 4.0)
            {
                vector3_1 = Vector3.zero;
            }
            else
            {
                float num2      = Mathf.Sqrt(sqrMagnitude2);
                float maxLength = Mathf.Min(a, num2 * 0.5f);
                vector3_1 = Quaternion.Inverse(frameData.m_rotation) * vector3_1;
                if ((double)vector3_1.z < (double)Mathf.Abs(vector3_1.x) * 5.0)
                {
                    vector3_1.x = (double)vector3_1.x < 0.0 ? Mathf.Min(-1f, vector3_1.x) : Mathf.Max(1f, vector3_1.x);
                    vector3_1.z = Mathf.Abs(vector3_1.x) * 5f;
                    maxLength   = Mathf.Min(0.5f, num2 * 0.1f);
                }
                vector3_1 = Vector3.ClampMagnitude(frameData.m_rotation * vector3_1, maxLength);
            }
            Vector3 vector3_2 = vector3_1 - frameData.m_velocity;
            float   magnitude = vector3_2.magnitude;
            Vector3 vector3_3 = vector3_2 * (b / Mathf.Max(magnitude, b));

            frameData.m_velocity     += vector3_3;
            citizenData.m_targetPos.y = Singleton <TerrainManager> .instance.SampleDetailHeight(frameData.m_position + frameData.m_velocity);

            frameData.m_velocity.y = citizenData.m_targetPos.y - frameData.m_position.y;
            float sqrMagnitude3 = frameData.m_velocity.sqrMagnitude;

            if ((double)sqrMagnitude3 > 0.00999999977648258)
            {
                Vector3 forward = frameData.m_velocity;
                if (!lodPhysics)
                {
                    Vector3 pushAmount  = Vector3.zero;
                    float   pushDivider = 0.0f;
                    this.CheckCollisions(instanceID, ref citizenData, frameData.m_position, frameData.m_position + frameData.m_velocity, citizenData.m_targetBuilding, ref pushAmount, ref pushDivider);
                    if ((double)pushDivider > 0.00999999977648258)
                    {
                        pushAmount           *= 1f / pushDivider;
                        pushAmount            = Vector3.ClampMagnitude(pushAmount, Mathf.Sqrt(sqrMagnitude3) * 0.5f);
                        frameData.m_velocity += pushAmount;
                        forward += pushAmount * 0.25f;
                    }
                }
                frameData.m_position += frameData.m_velocity * 0.5f;
                if ((double)forward.sqrMagnitude > 0.00999999977648258)
                {
                    frameData.m_rotation = Quaternion.LookRotation(forward);
                }
            }
            var m_randomEffect = ((PetAI)Convert.ChangeType(this, typeof(PetAI))).m_randomEffect;

            if (m_randomEffect == null || Singleton <SimulationManager> .instance.m_randomizer.Int32(40U) != 0)
            {
                return;
            }
            InstanceID instance1 = new InstanceID();

            instance1.CitizenInstance = instanceID;
            EffectInfo.SpawnArea spawnArea = new EffectInfo.SpawnArea(frameData.m_position, Vector3.up, 0.0f);
            float num3 = 3.75f;

            Singleton <EffectManager> .instance.DispatchEffect(m_randomEffect, instance1, spawnArea, frameData.m_velocity *num3, 0.0f, 1f, Singleton <CitizenManager> .instance.m_audioGroup);
        }
Beispiel #20
0
        public override void SimulationStep(ushort eventID, ref EventData data)
        {
            //begin mod
            var crawlerVehicle = Configuration.Get(eventID).Crawler;
            var rocketVehicle  = Configuration.Get(eventID).Rocket;
            //end mod
            VehicleManager  instance1 = Singleton <VehicleManager> .instance;
            BuildingManager instance2 = Singleton <BuildingManager> .instance;
            EventManager    instance3 = Singleton <EventManager> .instance;
            ushort          vehicleID1;
            ushort          vehicleID2;

            this.FindVehicles(eventID, ref data, out vehicleID1, out vehicleID2);
            bool flag1 = false;

            if ((data.m_flags & (EventData.Flags.Active | EventData.Flags.Expired | EventData.Flags.Completed | EventData.Flags.Disorganizing | EventData.Flags.Cancelled)) == EventData.Flags.None)
            {
                if ((data.m_flags & EventData.Flags.Ready) == EventData.Flags.None && this.m_resourceConsumption != 0)
                {
                    int num1 = (int)data.m_popularityDelta * 10;
                    int num2 = Mathf.Clamp(num1 / this.m_resourceConsumption, 0, 256);
                    data.m_startFrame  += (uint)(256 - num2);
                    data.m_expireFrame += (uint)(256 - num2);
                    int num3 = num1 - num2 * this.m_resourceConsumption;
                    data.m_popularityDelta = (short)Mathf.Clamp(num3 / 10, 0, (int)short.MaxValue);
                    int  num4 = 0;
                    uint currentFrameIndex = Singleton <SimulationManager> .instance.m_currentFrameIndex;
                    if (data.m_startFrame > currentFrameIndex)
                    {
                        num4 = ((int)data.m_startFrame - (int)currentFrameIndex) * this.m_resourceConsumption;
                    }
                    if ((int)data.m_building != 0 && num4 > num3)
                    {
                        int    num5       = 100000;
                        ushort vehicleID3 = instance2.m_buildings.m_buffer[(int)data.m_building].m_guestVehicles;
                        int    num6       = 0;
                        while ((int)vehicleID3 != 0)
                        {
                            switch ((TransferManager.TransferReason)instance1.m_vehicles.m_buffer[(int)vehicleID3].m_transferType)
                            {
                            case TransferManager.TransferReason.Coal:
                            case TransferManager.TransferReason.Petrol:
                                int size;
                                int max;
                                instance1.m_vehicles.m_buffer[(int)vehicleID3].Info.m_vehicleAI.GetSize(vehicleID3, ref instance1.m_vehicles.m_buffer[(int)vehicleID3], out size, out max);
                                num3 += Mathf.Min(size, max);
                                break;
                            }
                            vehicleID3 = instance1.m_vehicles.m_buffer[(int)vehicleID3].m_nextGuestVehicle;
                            if (++num6 > 16384)
                            {
                                CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + System.Environment.StackTrace);

                                break;
                            }
                        }
                        if (num3 <= num5 - 8000)
                        {
                            Singleton <TransferManager> .instance.AddIncomingOffer((data.m_flags & EventData.Flags.Preparing) == EventData.Flags.None?TransferManager.TransferReason.Coal : TransferManager.TransferReason.Petrol, new TransferManager.TransferOffer()
                            {
                                Priority = Mathf.Max(1, (num5 - num3) * 8 / num5),
                                Building = data.m_building,
                                Position = instance2.m_buildings.m_buffer[(int)data.m_building].m_position,
                                Amount   = 1,
                                Active   = false
                            });
                        }
                        if (num3 < 16000)
                        {
                            flag1 = true;
                        }
                    }
                }
                if ((data.m_flags & (EventData.Flags.Preparing | EventData.Flags.Ready)) != EventData.Flags.None && (int)data.m_building != 0)
                {
                    if ((int)vehicleID1 == 0 && crawlerVehicle != null)
                    {
                        Vector3 position = instance2.m_buildings.m_buffer[(int)data.m_building].CalculatePosition(this.m_rocketSpawnPosition);
                        if (instance1.CreateVehicle(out vehicleID1, ref Singleton <SimulationManager> .instance.m_randomizer, crawlerVehicle, position, TransferManager.TransferReason.None, false, false))
                        {
                            crawlerVehicle.m_vehicleAI.SetSource(vehicleID1, ref instance1.m_vehicles.m_buffer[(int)vehicleID1], data.m_building);
                            crawlerVehicle.m_vehicleAI.SetTarget(vehicleID1, ref instance1.m_vehicles.m_buffer[(int)vehicleID1], data.m_building);
                        }
                    }
                    if ((int)vehicleID1 != 0 && (int)vehicleID2 == 0 && rocketVehicle != null)
                    {
                        Vector3 position = instance2.m_buildings.m_buffer[(int)data.m_building].CalculatePosition(this.m_rocketSpawnPosition);
                        if (instance1.CreateVehicle(out vehicleID2, ref Singleton <SimulationManager> .instance.m_randomizer, rocketVehicle, position, TransferManager.TransferReason.None, false, false))
                        {
                            rocketVehicle.m_vehicleAI.SetSource(vehicleID2, ref instance1.m_vehicles.m_buffer[(int)vehicleID2], data.m_building);
                            rocketVehicle.m_vehicleAI.SetTarget(vehicleID2, ref instance1.m_vehicles.m_buffer[(int)vehicleID2], data.m_building);
                            ushort lastVehicle = instance1.m_vehicles.m_buffer[(int)vehicleID1].GetLastVehicle(vehicleID1);
                            if ((int)lastVehicle != 0)
                            {
                                instance1.m_vehicles.m_buffer[(int)vehicleID2].m_leadingVehicle   = lastVehicle;
                                instance1.m_vehicles.m_buffer[(int)lastVehicle].m_trailingVehicle = vehicleID2;
                            }
                        }
                    }
                }
            }
            if ((int)data.m_building != 0)
            {
                ushort num = instance2.m_buildings.m_buffer[(int)data.m_building].m_eventIndex;
                if ((int)num == (int)eventID)
                {
                    Notification.Problem problems = instance2.m_buildings.m_buffer[(int)data.m_building].m_problems;
                    Notification.Problem problem  = Notification.RemoveProblems(problems, Notification.Problem.NoResources);
                    if (flag1)
                    {
                        instance2.m_buildings.m_buffer[(int)data.m_building].m_incomingProblemTimer = (byte)Mathf.Min((int)byte.MaxValue, (int)instance2.m_buildings.m_buffer[(int)data.m_building].m_incomingProblemTimer + 1);
                        if ((int)instance2.m_buildings.m_buffer[(int)data.m_building].m_incomingProblemTimer >= 4)
                        {
                            problem = Notification.AddProblems(problem, Notification.Problem.NoResources);
                        }
                    }
                    else
                    {
                        instance2.m_buildings.m_buffer[(int)data.m_building].m_incomingProblemTimer = (byte)0;
                    }
                    if (problem != problems)
                    {
                        instance2.m_buildings.m_buffer[(int)data.m_building].m_problems = problem;
                        Singleton <BuildingManager> .instance.UpdateNotifications(data.m_building, problems, problem);
                    }
                    GuideController properties = Singleton <GuideManager> .instance.m_properties;
                    if (properties != null)
                    {
                        Singleton <BuildingManager> .instance.m_rocketLaunchSite.Activate(properties.m_rocketLaunchSite, data.m_building);
                    }
                }
                if ((int)num != 0 && (instance3.m_events.m_buffer[(int)num].m_flags & (EventData.Flags.Preparing | EventData.Flags.Active | EventData.Flags.Completed | EventData.Flags.Cancelled | EventData.Flags.Ready)) == EventData.Flags.None)
                {
                    num = instance3.m_events.m_buffer[(int)num].m_nextBuildingEvent;
                }
                bool flag2 = false;
                if ((int)vehicleID1 != 0 && crawlerVehicle != null)
                {
                    Vector3 position          = instance2.m_buildings.m_buffer[(int)data.m_building].CalculatePosition(this.m_doorPosition);
                    Vector3 lastFramePosition = instance1.m_vehicles.m_buffer[(int)vehicleID1].GetLastFramePosition();
                    Vector3 targetPos0        = (Vector3)instance1.m_vehicles.m_buffer[(int)vehicleID1].m_targetPos0;
                    Vector3 b = lastFramePosition + Vector3.ClampMagnitude(targetPos0 - lastFramePosition, crawlerVehicle.m_maxSpeed * 16f);
                    flag2 = (double)Vector3.Distance(position, b) < 40.0;
                }
                if (flag2)
                {
                    if ((data.m_flags & EventData.Flags.Loading) == EventData.Flags.None)
                    {
                        data.m_flags |= EventData.Flags.Loading;
                        if (this.m_doorOpenEffect != null && (int)num == (int)eventID)
                        {
                            InstanceID instance4 = new InstanceID();
                            instance4.Event = eventID;
                            EffectInfo.SpawnArea spawnArea = new EffectInfo.SpawnArea(Singleton <BuildingManager> .instance.m_buildings.m_buffer[(int)data.m_building].CalculatePosition(this.m_doorPosition), Vector3.up, 10f);
                            Singleton <EffectManager> .instance.DispatchEffect(this.m_doorOpenEffect, instance4, spawnArea, Vector3.zero, 0.0f, 1f, Singleton <AudioManager> .instance.DefaultGroup);
                        }
                    }
                }
                else if ((data.m_flags & EventData.Flags.Loading) != EventData.Flags.None)
                {
                    data.m_flags &= ~EventData.Flags.Loading;
                    if (this.m_doorCloseEffect != null && (int)num == (int)eventID)
                    {
                        InstanceID instance4 = new InstanceID();
                        instance4.Event = eventID;
                        EffectInfo.SpawnArea spawnArea = new EffectInfo.SpawnArea(Singleton <BuildingManager> .instance.m_buildings.m_buffer[(int)data.m_building].CalculatePosition(this.m_doorPosition), Vector3.up, 10f);
                        Singleton <EffectManager> .instance.DispatchEffect(this.m_doorCloseEffect, instance4, spawnArea, Vector3.zero, 0.0f, 1f, Singleton <AudioManager> .instance.DefaultGroup);
                    }
                }
            }
            base.SimulationStep(eventID, ref data);
        }
 private void DispatchAutobulldozeEffect(BuildingInfo info, ref Vector3 pos, ref float angle, int length)
 {
     EffectInfo mBulldozeEffect = this._buildingManager.m_properties.m_bulldozeEffect;
     if (mBulldozeEffect == null)
     {
         return;
     }
     InstanceID instanceID = new InstanceID();
     EffectInfo.SpawnArea spawnArea = new EffectInfo.SpawnArea(Matrix4x4.TRS(Building.CalculateMeshPosition(info, pos, angle, length), Building.CalculateMeshRotation(angle), Vector3.one), info.m_lodMeshData);
     this._effectManager.DispatchEffect(mBulldozeEffect, instanceID, spawnArea, Vector3.zero, 0f, 1f, this._nullAudioGroup);
 }