public override ToolBase.ToolErrors CheckBuildPosition(bool test, bool visualize, bool overlay, bool autofix, ref NetTool.ControlPoint startPoint, ref NetTool.ControlPoint middlePoint, ref NetTool.ControlPoint endPoint, out BuildingInfo ownerBuilding, out Vector3 ownerPosition, out Vector3 ownerDirection, out int productionRate)
        {
            ToolBase.ToolErrors toolErrors = NetAIDetour.CheckBuildPosition(this, test, visualize, overlay, autofix, ref startPoint, ref middlePoint, ref endPoint, out ownerBuilding, out ownerPosition, out ownerDirection, out productionRate);
            Vector3             middlePos1;
            Vector3             middlePos2;

            NetSegment.CalculateMiddlePoints(startPoint.m_position, middlePoint.m_direction, endPoint.m_position, -endPoint.m_direction, true, true, out middlePos1, out middlePos2);
            Bezier2 bezier2;

            bezier2.a = VectorUtils.XZ(startPoint.m_position);
            bezier2.b = VectorUtils.XZ(middlePos1);
            bezier2.c = VectorUtils.XZ(middlePos2);
            bezier2.d = VectorUtils.XZ(endPoint.m_position);
            int      @int = Mathf.CeilToInt(Vector2.Distance(bezier2.a, bezier2.d) * 0.005f);
            Segment2 segment;

            segment.a = bezier2.a;
            for (int index = 1; index <= @int; ++index)
            {
                segment.b = bezier2.Position((float)index / (float)@int);
                //begin mod
                //end mod
                segment.a = segment.b;
            }
            return(toolErrors);
        }
Ejemplo n.º 2
0
        public static void Prefix(object __instance, ref bool __state)
        {
            if (IgnoreHelper.IsIgnored())
            {
                return;
            }

            TransportTool tool    = ReflectionHelper.GetAttr <TransportTool>(__instance, "$this");
            int           counter = ReflectionHelper.GetAttr <int>(__instance, "$PC");

            int mode         = ReflectionHelper.GetAttr <int>(tool, "m_mode");
            int expectedMode = ReflectionHelper.GetEnumValue(typeof(TransportTool).GetNestedType("Mode", ReflectionHelper.AllAccessFlags), "NewLine");

            ToolBase.ToolErrors m_errors = ReflectionHelper.GetAttr <ToolBase.ToolErrors>(tool, "m_errors");
            ushort m_lastEditLine        = ReflectionHelper.GetAttr <ushort>(tool, "m_lastEditLine");
            int    m_hoverStopIndex      = ReflectionHelper.GetAttr <int>(tool, "m_hoverStopIndex");
            int    m_building            = ReflectionHelper.GetAttr <int>(tool, "m_building");

            if (counter != 0 || m_errors != ToolBase.ToolErrors.None || mode != expectedMode || m_lastEditLine == 0 || m_hoverStopIndex == -1 || (m_building != 0 && m_hoverStopIndex == 0))
            {
                __state = false;
                return;
            }
            __state = true;

            ArrayHandler.StartCollecting();
            IgnoreHelper.StartIgnore("RemoveStop");
        }
Ejemplo n.º 3
0
        public override ToolBase.ToolErrors CheckBuildPosition(
            ushort relocateID,
            ref Vector3 position,
            ref float angle,
            float waterHeight,
            float elevation,
            ref Segment3 connectionSegment,
            out int productionRate,
            out int constructionCost)
        {
            ToolBase.ToolErrors toolErrors1 = ToolBase.ToolErrors.None;
            Vector3             pos;
            Vector3             dir;
            bool isQuay;

            if (this.m_info.m_placementMode == BuildingInfo.PlacementMode.Shoreline &&
                BuildingTool.SnapToCanal(position, out pos, out dir, out isQuay, 40f, false))
            {
                angle      = Mathf.Atan2(dir.x, -dir.z);
                pos       += dir * this.m_quayOffset;
                position.x = pos.x;
                position.z = pos.z;
                if (!isQuay)
                {
                    toolErrors1 |= ToolBase.ToolErrors.ShoreNotFound;
                }
            }

            ToolBase.ToolErrors toolErrors2 = toolErrors1 | base.CheckBuildPosition(relocateID, ref position, ref angle,
                                                                                    waterHeight, elevation, ref connectionSegment, out productionRate, out constructionCost);

            return(toolErrors2);
        }
Ejemplo n.º 4
0
        public static void Prefix(out CallState __state, object __instance)
        {
            __state = new CallState();

            if (IgnoreHelper.IsIgnored())
            {
                __state.run = false;
                return;
            }

            BuildingTool tool    = ReflectionHelper.GetAttr <BuildingTool>(__instance, "$this");
            int          counter = ReflectionHelper.GetAttr <int>(__instance, "$PC");

            ToolBase.ToolErrors ___m_placementErrors = ReflectionHelper.GetAttr <ToolBase.ToolErrors>(tool, "m_placementErrors");

            if (counter != 0 || ___m_placementErrors != ToolBase.ToolErrors.None)
            {
                __state.run = false;
                return;
            }

            __state.run      = true;
            __state.relocate = tool.m_relocate; // Save relocate state as it will be cleared at the end of the method

            IgnoreHelper.StartIgnore();
            ArrayHandler.StartCollecting();
        }
Ejemplo n.º 5
0
        public override void SimulationStep()
        {
            ToolBase.RaycastInput input = new ToolBase.RaycastInput(this.m_mouseRay, this.m_mouseRayLength);
            input.m_ignoreSegmentFlags = NetSegment.Flags.None;
            input.m_ignoreNodeFlags    = NetNode.Flags.None;
            ulong[] collidingSegments;
            ulong[] collidingBuildings;
            this.m_toolController.BeginColliding(out collidingSegments, out collidingBuildings);
            try
            {
                ToolBase.RaycastOutput output;
                if (this.m_mouseRayValid && ToolBase.RayCast(input, out output))
                {
                    float terrainHeight = TerrainManager.instance.SampleDetailHeight(output.m_hitPos);
                    output.m_hitPos.y = output.m_hitPos.y > terrainHeight ? output.m_hitPos.y : terrainHeight;
                    Randomizer r  = this.m_randomizer;
                    ushort     id = Singleton <PropManager> .instance.m_props.NextFreeItem(ref r);

                    this.m_mousePosition   = output.m_hitPos;
                    this.m_placementErrors = ToolErrors.None;
                }
                else
                {
                    this.m_placementErrors = ToolBase.ToolErrors.RaycastFailed;
                }
            }
            finally
            {
                this.m_toolController.EndColliding();
            }
        }
Ejemplo n.º 6
0
        private void UpgradePipes()
        {
            try
            {
                int totalCost            = 0;
                ToolBase.ToolErrors none = ToolBase.ToolErrors.None;
                int    num2 = this.UpgradeWaterToHeat(false, out totalCost, out none);
                string str  = "";
                if (none != ToolBase.ToolErrors.None)
                {
                    str = " Not enough money.";
                    this._upgradeResult.textColor = Color.red;
                }
                else
                {
                    this._upgradeResult.textColor = Color.green;
                }
                object[] objArray1 = new object[] { "Upgraded ", num2, " pipes.", str };
                this._upgradeResult.text = string.Concat(objArray1);
                Util.DebugPrint(this.name + Mod._version + " All pipes upgraded");
            }

            catch (Exception ex)
            {
                Util.LogException(ex);
            }
        }
Ejemplo n.º 7
0
        public override ToolBase.ToolErrors CheckBuildPosition(ushort relocateID, ref Vector3 position, ref float angle, float waterHeight, float elevation, ref Segment3 connectionSegment, out int productionRate, out int constructionCost)
        {
            if (this.m_transportLineInfo == null)
            {
                return(base.CheckBuildPosition(relocateID, ref position, ref angle, waterHeight, elevation, ref connectionSegment, out productionRate, out constructionCost));
            }
            ToolBase.ToolErrors toolErrors1 = ToolBase.ToolErrors.None;
            Vector3             pos;
            Vector3             dir;
            bool isQuay;

            if (this.m_info.m_placementMode == BuildingInfo.PlacementMode.Shoreline && BuildingTool.SnapToCanal(position, out pos, out dir, out isQuay, 40f, false))
            {
                angle      = Mathf.Atan2(dir.x, -dir.z);
                pos       += dir * this.m_quayOffset;
                position.x = pos.x;
                position.z = pos.z;
                if (!isQuay && !this.m_supportCanals)
                {
                    toolErrors1 |= ToolBase.ToolErrors.ShoreNotFound;
                }
            }
            ToolBase.ToolErrors toolErrors2 = toolErrors1 | base.CheckBuildPosition(relocateID, ref position, ref angle, waterHeight, elevation, ref connectionSegment, out productionRate, out constructionCost);
            //begin mod
            //end mod
            Vector3 position1 = Building.CalculatePosition(position, angle, this.m_connectionOffset);
            Vector3 position2 = position1;
            uint    laneID;
            byte    offset;

            if (ShipDockAI.FindConnectionPath(ref position2, out laneID, out offset))
            {
                position1.y         = position2.y;
                connectionSegment.a = position1;
                connectionSegment.b = position2;
                if (!Singleton <TerrainManager> .instance.HasWater(Segment2.XZ(connectionSegment), 50f, false))
                {
                    toolErrors2 |= ToolBase.ToolErrors.CannotConnect;
                }
            }
            else
            {
                toolErrors2 |= ToolBase.ToolErrors.CannotConnect;
            }
            GuideController properties = Singleton <GuideManager> .instance.m_properties;

            if (properties != null)
            {
                if ((toolErrors2 & ToolBase.ToolErrors.CannotConnect) != ToolBase.ToolErrors.None)
                {
                    Singleton <BuildingManager> .instance.m_harborPlacement.Activate(properties.m_harborPlacement);
                }
                else
                {
                    Singleton <BuildingManager> .instance.m_harborPlacement.Deactivate();
                }
            }
            return(toolErrors2);
        }
Ejemplo n.º 8
0
 protected override void OnEnable()
 {
     base.OnEnable();
     this.ToolCursor = this.m_buildCursor;
     this.m_toolController.ClearColliding();
     this.m_placementErrors = ToolBase.ToolErrors.Pending;
     this.m_toolController.SetBrush((Texture2D)null, Vector3.zero, 1f);
 }
Ejemplo n.º 9
0
 public override ToolBase.ToolErrors CheckBuildPosition(bool test, bool visualize, bool overlay, bool autofix, ref NetTool.ControlPoint startPoint, ref NetTool.ControlPoint middlePoint, ref NetTool.ControlPoint endPoint, out BuildingInfo ownerBuilding, out Vector3 ownerPosition, out Vector3 ownerDirection, out int productionRate)
 {
     ToolBase.ToolErrors toolErrors = base.CheckBuildPosition(test, visualize, overlay, autofix, ref startPoint, ref middlePoint, ref endPoint, out ownerBuilding, out ownerPosition, out ownerDirection, out productionRate);
     if (test)
     {
         NetManager instance = Singleton <NetManager> .instance;
         ushort     num      = middlePoint.m_segment;
         if ((int)startPoint.m_segment == (int)num || (int)endPoint.m_segment == (int)num)
         {
             num = (ushort)0;
         }
         //if ((int)num != 0 && (Singleton<NetManager>.instance.m_segments.m_buffer[(int)num].m_flags & NetSegment.Flags.Collapsed) == NetSegment.Flags.None)
         //{
         //    NetInfo info = instance.m_segments.m_buffer[(int)num].Info;
         //    if (this.m_connectedInfo == info)
         //        toolErrors |= ToolBase.ToolErrors.CannotUpgrade;
         //    if (this.m_elevatedInfo == info)
         //        toolErrors |= ToolBase.ToolErrors.CannotUpgrade;
         //    if (this.m_bridgeInfo == info)
         //        toolErrors |= ToolBase.ToolErrors.CannotUpgrade;
         //    if (this.m_tunnelInfo == info)
         //        toolErrors |= ToolBase.ToolErrors.CannotUpgrade;
         //    if (this.m_slopeInfo == info)
         //        toolErrors |= ToolBase.ToolErrors.CannotUpgrade;
         //}
         if ((int)startPoint.m_node != 0)
         {
             for (int index = 0; index < 8; ++index)
             {
                 ushort segment = instance.m_nodes.m_buffer[(int)startPoint.m_node].GetSegment(index);
                 if ((int)segment != 0 && (instance.m_segments.m_buffer[(int)segment].Info.m_vehicleTypes & VehicleInfo.VehicleType.Tram) != VehicleInfo.VehicleType.None)
                 {
                     toolErrors |= ToolBase.ToolErrors.CannotCrossTrack;
                 }
             }
         }
         else if ((int)startPoint.m_segment != 0 && (instance.m_segments.m_buffer[(int)startPoint.m_segment].Info.m_vehicleTypes & VehicleInfo.VehicleType.Tram) != VehicleInfo.VehicleType.None)
         {
             toolErrors |= ToolBase.ToolErrors.CannotCrossTrack;
         }
         if ((int)endPoint.m_node != 0)
         {
             for (int index = 0; index < 8; ++index)
             {
                 ushort segment = instance.m_nodes.m_buffer[(int)endPoint.m_node].GetSegment(index);
                 if ((int)segment != 0 && (instance.m_segments.m_buffer[(int)segment].Info.m_vehicleTypes & VehicleInfo.VehicleType.Tram) != VehicleInfo.VehicleType.None)
                 {
                     toolErrors |= ToolBase.ToolErrors.CannotCrossTrack;
                 }
             }
         }
         else if ((int)endPoint.m_segment != 0 && (instance.m_segments.m_buffer[(int)endPoint.m_segment].Info.m_vehicleTypes & VehicleInfo.VehicleType.Tram) != VehicleInfo.VehicleType.None)
         {
             toolErrors |= ToolBase.ToolErrors.CannotCrossTrack;
         }
     }
     return(toolErrors);
 }
Ejemplo n.º 10
0
 private IEnumerator ReleaseSegment(ushort segment)
 {
     ToolBase.ToolErrors errors = ToolErrors.None;
     ;
     if (CheckSegment(segment, ref errors))
     {
         NetManager.instance.ReleaseSegment(segment, false);
     }
     yield return(null);
 }
Ejemplo n.º 11
0
 public override ToolBase.ToolErrors CheckBuildPosition(bool test, bool visualize, bool overlay, bool autofix, ref NetTool.ControlPoint startPoint, ref NetTool.ControlPoint middlePoint, ref NetTool.ControlPoint endPoint, out BuildingInfo ownerBuilding, out Vector3 ownerPosition, out Vector3 ownerDirection, out int productionRate)
 {
     ToolBase.ToolErrors toolErrors = base.CheckBuildPosition(test, visualize, overlay, autofix, ref startPoint, ref middlePoint, ref endPoint, out ownerBuilding, out ownerPosition, out ownerDirection, out productionRate);
     if (test)
     {
         if (this.m_enableZoning && !Singleton <ZoneManager> .instance.CheckLimits())
         {
             toolErrors |= ToolBase.ToolErrors.TooManyObjects;
         }
     }
     return(toolErrors);
 }
Ejemplo n.º 12
0
 protected override void OnDisable()
 {
     base.OnDisable();
     this.ToolCursor = (CursorInfo)null;
     this.m_toolController.SetBrush((Texture2D)null, Vector3.zero, 1f);
     this.m_mouseLeftDown   = false;
     this.m_mouseRightDown  = false;
     this.m_placementErrors = ToolBase.ToolErrors.Pending;
     this.m_mouseRayValid   = false;
     if (this.angleDialog != null)
     {
         this.angleDialog.Hide();
     }
 }
        public override NetInfo GetInfo(float minElevation, float maxElevation, float length, bool incoming, bool outgoing, bool curved,
                                        bool enableDouble, ref ToolBase.ToolErrors errors)
        {
            if (incoming || outgoing)
            {
                int incoming1;
                int outgoing1;
                Singleton <BuildingManager> .instance.CalculateOutsideConnectionCount(this.m_info.m_class.m_service, this.m_info.m_class.m_subService, out incoming1, out outgoing1);

                if (incoming && incoming1 >= 4 || outgoing && outgoing1 >= 4)
                {
                    errors = errors | ToolBase.ToolErrors.TooManyConnections;
                }
                if (this.m_connectedElevatedInfo != null && (double)maxElevation > 8.0)
                {
                    return(this.m_connectedElevatedInfo);
                }
                if (this.m_connectedInfo != null)
                {
                    return(this.m_connectedInfo);
                }
            }
            if ((double)maxElevation > (double)byte.MaxValue)
            {
                errors = errors | ToolBase.ToolErrors.HeightTooHigh;
            }
            //begin mod
            if (this.m_tunnelInfo != null && (double)maxElevation < -8.0)
            {
                return(this.m_tunnelInfo);
            }
            if (this.m_slopeInfo != null && (double)minElevation < -8.0)
            {
                return(this.m_slopeInfo);
            }
            //end mod
            if (this.m_bridgeInfo != null && (double)maxElevation > 25.0 && ((double)length > 45.0 && !curved) && (enableDouble || !this.m_bridgeInfo.m_netAI.RequireDoubleSegments()))
            {
                return(this.m_bridgeInfo);
            }
            if (this.m_elevatedInfo != null && (double)maxElevation > 0.100000001490116)
            {
                return(this.m_elevatedInfo);
            }
            if ((double)maxElevation > 8.0)
            {
                errors = errors | ToolBase.ToolErrors.HeightTooHigh;
            }
            return(this.m_info);
        }
Ejemplo n.º 14
0
        private int UpgradeWaterToHeat(bool test, out int totalCost, out ToolBase.ToolErrors errors)
        {
            int num = 0;

            totalCost = 0;
            errors    = ToolBase.ToolErrors.None;
            NetInfo info = PrefabCollection <NetInfo> .FindLoaded("Heating Pipe");

            if (info == null)
            {
                //Debug.Log("Couldn't find Heating Pipe, aborting.");
                Util.Log("Couldn't find Heating Pipe, aborting.");
                return(num);
            }
            NetSegment[] buffer = Singleton <NetManager> .instance.m_segments.m_buffer;
            for (int i = 0; i < buffer.Length; i++)
            {
                NetSegment segment = buffer[i];
                if (((segment.Info != null) && (segment.Info.category == "WaterServices")) && (segment.m_flags != NetSegment.Flags.None))
                {
                    NetTool.ControlPoint point;
                    NetTool.ControlPoint point2;
                    NetTool.ControlPoint point3;
                    this.GetSegmentControlPoints(i, out point, out point2, out point3);
                    bool   visualize      = false;
                    bool   autoFix        = true;
                    bool   needMoney      = true;
                    bool   invert         = false;
                    ushort node           = 0;
                    ushort num4           = 0;
                    int    cost           = 0;
                    int    productionRate = 0;
                    errors = NetTool.CreateNode(info, point, point2, point3, NetTool.m_nodePositionsSimulation, 0x3e8, test, visualize, autoFix, needMoney, invert, false, 0, out node, out num4, out cost, out productionRate);
                    if ((errors == ToolBase.ToolErrors.None) | test)
                    {
                        num++;
                        totalCost += cost;
                    }
                    else if ((errors & ToolBase.ToolErrors.NotEnoughMoney) != ToolBase.ToolErrors.None)
                    {
                        return(num);
                    }
                }
            }
            return(num);
        }
Ejemplo n.º 15
0
        private void CalculateUpgrade()
        {
            int totalCost = 0;

            ToolBase.ToolErrors none = ToolBase.ToolErrors.None;
            int num2 = this.UpgradeWaterToHeat(true, out totalCost, out none);

            this._upgradeCost.text = (totalCost * 0.01f).ToString(ColossalFramework.Globalization.Locale.Get("MONEY_FORMAT"), LocaleManager.cultureInfo);
            if (Singleton <EconomyManager> .instance.PeekResource(EconomyManager.Resource.Construction, totalCost) != totalCost)
            {
                this._upgradeCost.textColor = Color.red;
            }
            else
            {
                this._upgradeCost.textColor = Color.green;
            }
            this._pipeCount.text = num2.ToString();
        }
Ejemplo n.º 16
0
        public override ToolBase.ToolErrors CheckBuildPosition(ushort relocateID, ref Vector3 position, ref float angle, float waterHeight, float elevation, ref Segment3 connectionSegment, out int productionRate, out int constructionCost)
        {
            if (Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt))
            {
                if (this.m_info.m_placementMode != this.m_placementModeAlt)
                {
                    this.m_info.m_placementMode = this.m_placementModeAlt;
                }
            }
            else if (this.m_info.m_placementMode != this.m_placementMode)
            {
                this.m_info.m_placementMode = this.m_placementMode;
            }

            ToolBase.ToolErrors toolErrors = base.CheckBuildPosition(relocateID, ref position, ref angle, waterHeight, elevation, ref connectionSegment, out productionRate, out constructionCost);


            return(toolErrors);
        }
Ejemplo n.º 17
0
        public override void SimulationStep()
        {
            if (this.m_prefab == null)
            {
                this.m_wasPrefab = (PropInfo)null;
                this.m_propInfo  = (PropInfo)null;
            }
            else
            {
                if (this.m_propInfo == null || this.m_wasPrefab != this.m_prefab)
                {
                    this.m_wasPrefab = this.m_prefab;
                    Randomizer r = this.m_randomizer;
                    this.m_propInfo = (Singleton <ToolManager> .instance.m_properties.m_mode & ItemClass.Availability.AssetEditor) == ItemClass.Availability.None ? this.m_prefab.GetVariation(ref r) : this.m_prefab;
                    m_randomizer    = this.m_randomizer;
                }
                ToolBase.RaycastInput input = new ToolBase.RaycastInput(this.m_mouseRay, this.m_mouseRayLength);
                //begin mod
                input.m_ignoreBuildingFlags = Building.Flags.None;
                input.m_ignoreNodeFlags     = NetNode.Flags.None;
                input.m_ignoreSegmentFlags  = NetSegment.Flags.None;
                input.m_buildingService     = new RaycastService(ItemClass.Service.None, ItemClass.SubService.None, ItemClass.Layer.Default);
                input.m_netService          = new RaycastService(ItemClass.Service.None, ItemClass.SubService.None, ItemClass.Layer.Default);
                input.m_netService2         = new RaycastService(ItemClass.Service.None, ItemClass.SubService.None, ItemClass.Layer.Default);
                //end mod
                ulong[] collidingSegments;
                ulong[] collidingBuildings;
                this.m_toolController.BeginColliding(out collidingSegments, out collidingBuildings);
                try
                {
                    ToolBase.RaycastOutput output;
                    if (this.m_mouseRayValid && ToolBase.RayCast(input, out output))
                    {
                        if (this.m_mode == PropTool.Mode.Brush)
                        {
                            this.m_mousePosition   = output.m_hitPos;
                            this.m_placementErrors = !Singleton <PropManager> .instance.CheckLimits()
                                ? ToolBase.ToolErrors.TooManyObjects
                                : ToolBase.ToolErrors.Pending;

                            if (this.m_mouseLeftDown == this.m_mouseRightDown)
                            {
                                return;
                            }
                            this.ApplyBrush();
                        }
                        else
                        {
                            if (this.m_mode != PropTool.Mode.Single)
                            {
                                return;
                            }
                            //begin mod
                            //end mod
                            Randomizer r  = this.m_randomizer;
                            ushort     id = Singleton <PropManager> .instance.m_props.NextFreeItem(ref r);

                            ToolBase.ToolErrors toolErrors = PropTool.CheckPlacementErrors(this.m_propInfo,
                                                                                           output.m_hitPos, /*output.m_currentEditObject*/ false, id, collidingSegments,
                                                                                           collidingBuildings);
                            if ((Singleton <ToolManager> .instance.m_properties.m_mode & ItemClass.Availability.Game) !=
                                ItemClass.Availability.None)
                            {
                                int constructionCost = this.m_propInfo.GetConstructionCost();
                                if (constructionCost != 0 &&
                                    constructionCost !=
                                    Singleton <EconomyManager> .instance.PeekResource(
                                        EconomyManager.Resource.Construction, constructionCost))
                                {
                                    toolErrors |= ToolBase.ToolErrors.NotEnoughMoney;
                                }
                            }
                            if (!Singleton <PropManager> .instance.CheckLimits())
                            {
                                toolErrors |= ToolBase.ToolErrors.TooManyObjects;
                            }
                            this.m_mousePosition   = output.m_hitPos;
                            this.m_placementErrors = toolErrors;
                            //begin mod
                            //end mod
                        }
                    }
                    else
                    {
                        this.m_placementErrors = ToolBase.ToolErrors.RaycastFailed;
                    }
                }
                finally
                {
                    this.m_toolController.EndColliding();
                }
            }
        }
Ejemplo n.º 18
0
        public static void Prefix(Vector3 ___m_hitPosition, bool ___m_fixedPlatform, int ___m_hoverStopIndex, int ___m_hoverSegmentIndex, int ___m_mode, ToolBase.ToolErrors ___m_errors, ushort ___m_tempLine, out DataStore __state)
        {
            __state = new DataStore();

            if (IgnoreHelper.IsIgnored())
            {
                return;
            }

            TransportHandler.TrackSimulationStep = true;
            TransportHandler.TrackTempLine       = ___m_tempLine;
            TransportHandler.DidUpdatePaths      = false;
            TransportHandler.DidUpdateLinesNow   = false;

            // Save current values for comparison
            __state.hitPos       = ___m_hitPosition;
            __state.fixedP       = ___m_fixedPlatform;
            __state.hoverStop    = ___m_hoverStopIndex;
            __state.hoverSegment = ___m_hoverSegmentIndex;
            __state.mode         = ___m_mode;
            __state.errors       = ___m_errors;
        }
Ejemplo n.º 19
0
        public override NetInfo GetInfo(float elevation, float length, bool incoming, bool outgoing, bool curved, bool enableDouble, ref ToolBase.ToolErrors errors)
        {
            if (incoming || outgoing)
            {
                int num;
                int num2;
                Singleton <BuildingManager> .instance.CalculateOutsideConnectionCount(this.m_info.m_class.m_service, this.m_info.m_class.m_subService, out num, out num2);

                if ((incoming && num >= 4) || (outgoing && num2 >= 4))
                {
                    errors |= ToolBase.ToolErrors.TooManyConnections;
                }
            }
            if (this.m_invisible)
            {
                return(this.m_info);
            }
            if (elevation > 255f)
            {
                errors |= ToolBase.ToolErrors.HeightTooHigh;
            }
            if (this.m_bridgeInfo != null && elevation > 25f && length > 45f && !curved && (enableDouble || !this.m_bridgeInfo.m_netAI.RequireDoubleSegments()))
            {
                return(this.m_bridgeInfo);
            }
            if (this.m_elevatedInfo != null && elevation > 2f)
            {
                return(this.m_elevatedInfo);
            }
            if (elevation > 4f)
            {
                errors |= ToolBase.ToolErrors.HeightTooHigh;
            }
            return(this.m_info);
        }
Ejemplo n.º 20
0
        void _OnBeforeSimulationTick()
        {
            if (toolMode == ToolMode.None)
            {
                return;
            }

            if (!mouseDown)
            {
                dragging = false;
                prevBuiltSegmentIndex = 0;
            }

            if (buildTool != null)
            {
                buildTool.isHoveringSegment = false;
                buildTool.toolMode          = toolMode;
                buildTool.ToolCursor        = netTool.m_upgradeCursor;
            }

            if (!mouseRayValid)
            {
                return;
            }

            ToolBase.RaycastInput raycastInput = new ToolBase.RaycastInput(mouseRay, mouseRayLength);
            raycastInput.m_netService         = raycastService;
            raycastInput.m_ignoreTerrain      = true;
            raycastInput.m_ignoreNodeFlags    = NetNode.Flags.All;
            raycastInput.m_ignoreSegmentFlags = NetSegment.Flags.Untouchable;

            ToolBase.RaycastOutput raycastOutput;
            if (BuildTool118.RayCast(raycastInput, out raycastOutput))
            {
                int segmentIndex = raycastOutput.m_netSegment;
                if (segmentIndex != 0)
                {
                    NetManager net           = Singleton <NetManager> .instance;
                    NetInfo    newRoadPrefab = null;

                    NetTool.ControlPoint startPoint;
                    NetTool.ControlPoint middlePoint;
                    NetTool.ControlPoint endPoint;

                    GetSegmentControlPoints(segmentIndex, out startPoint, out middlePoint, out endPoint);

                    ushort node;
                    ushort outSegment;
                    int    cost;
                    int    productionRate;
                    // Check for out-of-area error and initialized collide arrays for visualization
                    ToolBase.ToolErrors errors = NetTool.CreateNode(net.m_segments.m_buffer[segmentIndex].Info,
                                                                    startPoint, middlePoint, endPoint, NetTool.m_nodePositionsSimulation, 1000,
                                                                    true, false, true, false, false, false, (ushort)0, out node, out outSegment, out cost, out productionRate);

                    if ((errors & ToolBase.ToolErrors.OutOfArea) != 0)
                    {
                        toolError = ToolError.OutOfArea;
                    }
                    else
                    {
                        if (mouseDown)
                        {
                            HandleMouseDrag(ref raycastOutput, ref toolError, false, ref newRoadPrefab, ref segmentIndex);

                            if (segmentIndex == prevBuiltSegmentIndex)
                            {
                                toolError = ToolError.AlreadyBuilt;
                            }
                        }
                        else
                        {
                            HandleMouseDrag(ref raycastOutput, ref toolError, true, ref newRoadPrefab, ref segmentIndex);
                        }
                    }

                    if (buildTool != null)
                    {
                        buildTool.segment           = net.m_segments.m_buffer[segmentIndex];
                        buildTool.segmentIndex      = segmentIndex;
                        buildTool.isHoveringSegment = toolError != ToolError.Unknown;
                        if (newRoadPrefab != null)
                        {
                            buildTool.newPrefab = newRoadPrefab;
                        }
                        GetSegmentControlPoints(segmentIndex, out buildTool.startPoint, out buildTool.middlePoint, out buildTool.endPoint);
                    }
                }
            }

            if (buildTool != null)
            {
                buildTool.toolError = toolError;
            }
        }
Ejemplo n.º 21
0
 private void setErrors(ToolBase.ToolErrors value)
 {
     m_errors.SetValue(this, value);
 }
Ejemplo n.º 22
0
 public override NetInfo GetInfo(float minElevation, float maxElevation, float length, bool incoming, bool outgoing, bool curved, bool enableDouble, ref ToolBase.ToolErrors errors)
 {
     if (this.m_invisible)
     {
         return(this.m_info);
     }
     if ((double)maxElevation > (double)byte.MaxValue)
     {
         errors = errors | ToolBase.ToolErrors.HeightTooHigh;
     }
     //begin mod
     if (this.m_tunnelInfo != null && (double)maxElevation < -8.0)
     {
         return(this.m_tunnelInfo);
     }
     if (this.m_slopeInfo != null && (double)minElevation < -8.0)
     {
         return(this.m_slopeInfo);
     }
     //end mod
     if (this.m_bridgeInfo != null && (double)maxElevation > 25.0 && ((double)length > 45.0 && !curved) && (enableDouble || !this.m_bridgeInfo.m_netAI.RequireDoubleSegments()))
     {
         return(this.m_bridgeInfo);
     }
     if (this.m_elevatedInfo != null && (double)maxElevation > 0.100000001490116)
     {
         return(this.m_elevatedInfo);
     }
     if ((double)maxElevation > 4.0)
     {
         errors = errors | ToolBase.ToolErrors.HeightTooHigh;
     }
     return(this.m_info);
 }
 public override NetInfo GetInfo(float minElevation, float maxElevation, float length, bool incoming, bool outgoing, bool curved, bool enableDouble, ref ToolBase.ToolErrors errors)
 {
     //begin mod
     //end mod
     return(this.m_info);
 }
Ejemplo n.º 24
0
        private static ToolBase.ToolErrors CheckNodeHeights(NetInfo info, FastList <NetTool.NodePosition> nodeBuffer)
        {
            bool flag  = info.m_netAI.BuildUnderground();
            bool flag2 = flag || info.m_netAI.SupportUnderground();

            if (info.m_netAI.LinearMiddleHeight())
            {
                if (nodeBuffer.m_size >= 3)
                {
                    Vector2 b  = VectorUtils.XZ(nodeBuffer.m_buffer[0].m_position);
                    Vector2 b2 = VectorUtils.XZ(nodeBuffer.m_buffer[nodeBuffer.m_size - 1].m_position);
                    float   y  = nodeBuffer.m_buffer[0].m_position.y;
                    float   y2 = nodeBuffer.m_buffer[nodeBuffer.m_size - 1].m_position.y;
                    for (int i = 1; i < nodeBuffer.m_size - 1; i++)
                    {
                        NetTool.NodePosition nodePosition = nodeBuffer.m_buffer[i];
                        float num  = Vector2.Distance(VectorUtils.XZ(nodePosition.m_position), b);
                        float num2 = Vector2.Distance(VectorUtils.XZ(nodePosition.m_position), b2);
                        nodePosition.m_position.y = Mathf.Lerp(y, y2, num / Mathf.Max(1f, num + num2));
                        nodeBuffer.m_buffer[i]    = nodePosition;
                    }
                }

                return(ToolBase.ToolErrors.None);
            }
            else
            {
                bool flag3 = false;
                for (int j = 1; j < nodeBuffer.m_size; j++)
                {
                    NetTool.NodePosition nodePosition2 = nodeBuffer.m_buffer[j - 1];
                    NetTool.NodePosition nodePosition3 = nodeBuffer.m_buffer[j];
                    float num4 = VectorUtils.LengthXZ(nodePosition3.m_position - nodePosition2.m_position);
                    float num5 = num4 * info.m_maxSlope;
                    nodePosition3.m_minY = Mathf.Max(nodePosition3.m_minY, nodePosition2.m_minY - num5);
                    nodePosition3.m_maxY = Mathf.Min(nodePosition3.m_maxY, nodePosition2.m_maxY + num5);
                    if (!flag2)
                    {
                        nodePosition3.m_terrainHeight = Mathf.Min(nodePosition3.m_terrainHeight, nodePosition3.m_position.y + 7.98f);
                        nodePosition3.m_minY          = Mathf.Max(nodePosition3.m_minY, nodePosition3.m_terrainHeight - 7.99f);
                    }
                    nodeBuffer.m_buffer[j] = nodePosition3;
                }
                for (int k = nodeBuffer.m_size - 2; k >= 0; k--)
                {
                    NetTool.NodePosition nodePosition4 = nodeBuffer.m_buffer[k + 1];
                    NetTool.NodePosition nodePosition5 = nodeBuffer.m_buffer[k];
                    float num6 = VectorUtils.LengthXZ(nodePosition5.m_position - nodePosition4.m_position);
                    float num7 = num6 * info.m_maxSlope;
                    nodePosition5.m_minY   = Mathf.Max(nodePosition5.m_minY, nodePosition4.m_minY - num7);
                    nodePosition5.m_maxY   = Mathf.Min(nodePosition5.m_maxY, nodePosition4.m_maxY + num7);
                    nodeBuffer.m_buffer[k] = nodePosition5;
                }
                for (int l = 0; l < nodeBuffer.m_size; l++)
                {
                    NetTool.NodePosition nodePosition6 = nodeBuffer.m_buffer[l];
                    if (nodePosition6.m_minY > nodePosition6.m_maxY)
                    {
                        return(ToolBase.ToolErrors.None); /*SlopeTooSteep;*/
                    }
                    if (nodePosition6.m_position.y > nodePosition6.m_maxY)
                    {
                        nodePosition6.m_position.y = nodePosition6.m_maxY;
                        if (!flag && nodePosition6.m_elevation >= -8f)
                        {
                            nodePosition6.m_minY = nodePosition6.m_maxY;
                        }
                        flag3 = true;
                    }
                    else if (nodePosition6.m_position.y < nodePosition6.m_minY)
                    {
                        nodePosition6.m_position.y = nodePosition6.m_minY;
                        if (flag || nodePosition6.m_elevation < -8f)
                        {
                            nodePosition6.m_maxY = nodePosition6.m_minY;
                        }
                        flag3 = true;
                    }
                    nodeBuffer.m_buffer[l] = nodePosition6;
                }
                if (nodeBuffer.m_size << 1 == 0)
                {
                    return(ToolBase.ToolErrors.None); /*SlopeTooSteep;*/
                }
                if (!flag3)
                {
                    for (int m = 1; m < nodeBuffer.m_size - 1; m++)
                    {
                        NetTool.NodePosition nodePosition7 = nodeBuffer.m_buffer[m - 1];
                        NetTool.NodePosition nodePosition8 = nodeBuffer.m_buffer[m];
                        float num8 = VectorUtils.LengthXZ(nodePosition8.m_position - nodePosition7.m_position);
                        float num9 = num8 * info.m_maxSlope;
                        if (flag || nodePosition8.m_elevation < -8f)
                        {
                            if (nodePosition8.m_position.y > nodePosition7.m_position.y + num9)
                            {
                                nodePosition8.m_position.y = nodePosition7.m_position.y + num9;
                            }
                        }
                        else if (nodePosition8.m_position.y < nodePosition7.m_position.y - num9)
                        {
                            nodePosition8.m_position.y = nodePosition7.m_position.y - num9;
                        }
                        nodeBuffer.m_buffer[m] = nodePosition8;
                    }
                    for (int n = nodeBuffer.m_size - 2; n > 0; n--)
                    {
                        NetTool.NodePosition nodePosition9  = nodeBuffer.m_buffer[n + 1];
                        NetTool.NodePosition nodePosition10 = nodeBuffer.m_buffer[n];
                        float num10 = VectorUtils.LengthXZ(nodePosition10.m_position - nodePosition9.m_position);
                        float num11 = num10 * info.m_maxSlope;
                        if (flag || nodePosition10.m_elevation < -8f)
                        {
                            if (nodePosition10.m_position.y > nodePosition9.m_position.y + num11)
                            {
                                nodePosition10.m_position.y = nodePosition9.m_position.y + num11;
                            }
                        }
                        else if (nodePosition10.m_position.y < nodePosition9.m_position.y - num11)
                        {
                            nodePosition10.m_position.y = nodePosition9.m_position.y - num11;
                        }
                        nodeBuffer.m_buffer[n] = nodePosition10;
                    }
                    int num12;
                    int num13;
                    info.m_netAI.GetElevationLimits(out num12, out num13);
                    if (num13 > num12 && !flag)
                    {
                        int num15;
                        for (int num14 = 0; num14 < nodeBuffer.m_size - 1; num14 = num15)
                        {
                            NetTool.NodePosition nodePosition11 = nodeBuffer.m_buffer[num14];
                            num15 = num14 + 1;
                            float num16 = 0f;
                            bool  flag4 = nodeBuffer.m_buffer[num15].m_position.y >= nodeBuffer.m_buffer[num15].m_terrainHeight + 8f;
                            bool  flag5 = nodeBuffer.m_buffer[num15].m_position.y <= nodeBuffer.m_buffer[num15].m_terrainHeight - 8f;
                            if (!flag2)
                            {
                                flag5 = false;
                            }
                            if (flag4 || flag5)
                            {
                                while (num15 < nodeBuffer.m_size)
                                {
                                    NetTool.NodePosition nodePosition12 = nodeBuffer.m_buffer[num15];
                                    num16 += VectorUtils.LengthXZ(nodePosition12.m_position - nodePosition11.m_position);
                                    if (flag4 && nodePosition12.m_position.y < nodePosition12.m_terrainHeight + 8f)
                                    {
                                        break;
                                    }
                                    if (flag5 && nodePosition12.m_position.y > nodePosition12.m_terrainHeight - 8f)
                                    {
                                        break;
                                    }
                                    nodePosition11 = nodePosition12;
                                    if (num15 == nodeBuffer.m_size - 1)
                                    {
                                        break;
                                    }
                                    num15++;
                                }
                            }
                            float y3 = nodeBuffer.m_buffer[num14].m_position.y;
                            float y4 = nodeBuffer.m_buffer[num15].m_position.y;
                            nodePosition11 = nodeBuffer.m_buffer[num14];
                            float num17 = 0f;
                            num16 = Mathf.Max(1f, num16);
                            for (int num18 = num14 + 1; num18 < num15; num18++)
                            {
                                NetTool.NodePosition nodePosition13 = nodeBuffer.m_buffer[num18];
                                num17 += VectorUtils.LengthXZ(nodePosition13.m_position - nodePosition11.m_position);
                                if (flag5)
                                {
                                    nodePosition13.m_position.y = Mathf.Min(nodePosition13.m_position.y, Mathf.Lerp(y3, y4, num17 / num16));
                                }
                                else
                                {
                                    nodePosition13.m_position.y = Mathf.Max(nodePosition13.m_position.y, Mathf.Lerp(y3, y4, num17 / num16));
                                }
                                nodeBuffer.m_buffer[num18] = nodePosition13;
                                nodePosition11             = nodePosition13;
                            }
                        }
                    }
                }
                ToolBase.ToolErrors toolErrors = ToolBase.ToolErrors.None;
                for (int num19 = 1; num19 < nodeBuffer.m_size - 1; num19++)
                {
                    NetTool.NodePosition nodePosition14 = nodeBuffer.m_buffer[num19 - 1];
                    NetTool.NodePosition nodePosition15 = nodeBuffer.m_buffer[num19 + 1];
                    NetTool.NodePosition nodePosition16 = nodeBuffer.m_buffer[num19];

                    /*if (flag)
                     * {
                     *  if (nodePosition16.m_terrainHeight < nodePosition16.m_position.y)
                     *  {
                     *      toolErrors |= ToolBase.ToolErrors.SlopeTooSteep;
                     *  }
                     * }*
                     * else if (nodePosition16.m_elevation < -8f)
                     * {
                     *  if (nodePosition16.m_terrainHeight <= nodePosition16.m_position.y + 8f)
                     *  {
                     *      toolErrors |= ToolBase.ToolErrors.SlopeTooSteep;
                     *  }
                     * }
                     * else if (!flag2 && nodePosition16.m_terrainHeight > nodePosition16.m_position.y + 8f)
                     * {
                     *  toolErrors |= ToolBase.ToolErrors.SlopeTooSteep;
                     * }*/
                    nodePosition16.m_direction.y = VectorUtils.NormalizeXZ(nodePosition15.m_position - nodePosition14.m_position).y;
                    nodeBuffer.m_buffer[num19]   = nodePosition16;
                }
                return(toolErrors);
            }
        }
        public override void SimulationStep()
        {
            BuildingInfo info;
            int          relocating;

            this.GetPrefabInfo(out info, out relocating);
            if (info == null)
            {
                return;
            }
            ulong[] collidingSegments;
            ulong[] collidingBuildings;
            this.m_toolController.BeginColliding(out collidingSegments, out collidingBuildings);
            try
            {
                ToolBase.RaycastOutput output;
                if (m_mouseRayValid && ToolBase.RayCast(new ToolBase.RaycastInput(this.m_mouseRay, this.m_mouseRayLength), out output))
                {
                    Vector3             vector3_1          = output.m_hitPos;
                    float               num1               = this.m_mouseAngle;
                    bool                flag               = (Singleton <ToolManager> .instance.m_properties.m_mode & ItemClass.Availability.Game) != ItemClass.Availability.None;
                    float               waterHeight        = 0.0f;
                    Segment3            connectionSegment1 = new Segment3();
                    float               elevation          = this.GetElevation(info);
                    int                 productionRate1;
                    int                 constructionCost1;
                    ToolBase.ToolErrors toolErrors1;
                    if (info.m_placementMode == BuildingInfo.PlacementMode.Roadside)
                    {
                        ToolBase.ToolErrors toolErrors2 = ToolBase.ToolErrors.GridNotFound;
                        float       num2     = output.m_hitPos.x - 8f;
                        float       num3     = output.m_hitPos.z - 8f;
                        float       num4     = output.m_hitPos.x + 8f;
                        float       num5     = output.m_hitPos.z + 8f;
                        ZoneManager instance = Singleton <ZoneManager> .instance;
                        float       minD     = 8f;
                        float       min2     = 1000000f;
                        //begin mod
                        int num6 = Mathf.Max((int)(((double)num2 - 46.0) / 64.0 + FakeZoneManager.HALFGRID), 0);
                        int num7 = Mathf.Max((int)(((double)num3 - 46.0) / 64.0 + FakeZoneManager.HALFGRID), 0);
                        int num8 = Mathf.Min((int)(((double)num4 + 46.0) / 64.0 + FakeZoneManager.HALFGRID), FakeZoneManager.GRIDSIZE - 1);
                        int num9 = Mathf.Min((int)(((double)num5 + 46.0) / 64.0 + FakeZoneManager.HALFGRID), FakeZoneManager.GRIDSIZE - 1);
                        //end mod
                        this.m_tempZoneBuffer.Clear();
                        if (relocating != 0)
                        {
                            this.GetAllZoneBlocks((ushort)relocating, this.m_tempZoneBuffer);
                        }
                        for (int index1 = num7; index1 <= num9; ++index1)
                        {
                            for (int index2 = num6; index2 <= num8; ++index2)
                            {
                                //begin mod
                                ushort nextGridBlock = instance.m_zoneGrid[index1 * FakeZoneManager.GRIDSIZE + index2];
                                //end mod
                                int num10 = 0;
                                while ((int)nextGridBlock != 0)
                                {
                                    if (!this.m_tempZoneBuffer.Contains(nextGridBlock))
                                    {
                                        Vector3 position = instance.m_blocks.m_buffer[(int)nextGridBlock].m_position;
                                        if ((double)Mathf.Max(Mathf.Max(num2 - 46f - position.x, num3 - 46f - position.z), Mathf.Max((float)((double)position.x - (double)num4 - 46.0), (float)((double)position.z - (double)num5 - 46.0))) < 0.0)
                                        {
                                            this.FindClosestZone(info, nextGridBlock, output.m_hitPos, ref minD, ref min2, ref vector3_1, ref num1);
                                        }
                                    }
                                    nextGridBlock = instance.m_blocks.m_buffer[(int)nextGridBlock].m_nextGridBlock;
                                    if (++num10 >= 49152)
                                    {
                                        CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + System.Environment.StackTrace);

                                        break;
                                    }
                                }
                            }
                        }
                        if ((double)minD < 8.0)
                        {
                            int offset;
                            if (Singleton <ZoneManager> .instance.CheckSpace(vector3_1, num1, info.m_cellWidth, info.m_cellLength, out offset))
                            {
                                float minY;
                                float maxY;
                                float buildingY;
                                Building.SampleBuildingHeight(vector3_1, num1, info.m_cellWidth, info.m_cellLength, info, out minY, out maxY, out buildingY);
                                Vector3 pos = vector3_1;
                                pos.y = buildingY;
                                ToolBase.ToolErrors toolErrors3 = BuildingTool.CheckSpace(info, info.m_placementMode, relocating, pos, minY, buildingY + info.m_collisionHeight, num1, info.m_cellWidth, info.m_cellLength, true, collidingSegments, collidingBuildings);
                                if ((double)maxY - (double)minY > (double)info.m_maxHeightOffset)
                                {
                                    toolErrors3 |= ToolBase.ToolErrors.SlopeTooSteep;
                                }
                                if (toolErrors3 == ToolBase.ToolErrors.None)
                                {
                                    vector3_1.y = buildingY;
                                }
                                toolErrors2 = toolErrors3;
                            }
                            else if (offset < 0)
                            {
                                Vector3 vector3_2 = new Vector3(Mathf.Cos(num1), 0.0f, Mathf.Sin(num1)) * 8f;
                                int     num10     = info.m_cellWidth >> 1;
                                for (int index = 1; index <= num10; ++index)
                                {
                                    Vector3 vector3_3 = vector3_1 - vector3_2 * (float)index;
                                    if (Singleton <ZoneManager> .instance.CheckSpace(vector3_3, num1, info.m_cellWidth, info.m_cellLength, out offset))
                                    {
                                        float minY;
                                        float maxY;
                                        float buildingY;
                                        Building.SampleBuildingHeight(vector3_3, num1, info.m_cellWidth, info.m_cellLength, info, out minY, out maxY, out buildingY);
                                        Vector3 pos = vector3_3;
                                        pos.y = buildingY;
                                        ToolBase.ToolErrors toolErrors3 = BuildingTool.CheckSpace(info, info.m_placementMode, relocating, pos, minY, buildingY + info.m_collisionHeight, num1, info.m_cellWidth, info.m_cellLength, true, collidingSegments, collidingBuildings);
                                        if ((double)maxY - (double)minY > (double)info.m_maxHeightOffset)
                                        {
                                            toolErrors3 |= ToolBase.ToolErrors.SlopeTooSteep;
                                        }
                                        if (toolErrors3 == ToolBase.ToolErrors.None)
                                        {
                                            vector3_3.y = buildingY;
                                            vector3_1   = vector3_3;
                                        }
                                        toolErrors2 = toolErrors3;
                                        break;
                                    }
                                }
                            }
                            else if (offset > 0)
                            {
                                Vector3 vector3_2 = new Vector3(Mathf.Cos(num1), 0.0f, Mathf.Sin(num1)) * 8f;
                                int     num10     = info.m_cellWidth >> 1;
                                for (int index = 1; index <= num10; ++index)
                                {
                                    Vector3 vector3_3 = vector3_1 + vector3_2 * (float)index;
                                    if (Singleton <ZoneManager> .instance.CheckSpace(vector3_3, num1, info.m_cellWidth, info.m_cellLength, out offset))
                                    {
                                        float minY;
                                        float maxY;
                                        float buildingY;
                                        Building.SampleBuildingHeight(vector3_3, num1, info.m_cellWidth, info.m_cellLength, info, out minY, out maxY, out buildingY);
                                        Vector3 pos = vector3_3;
                                        pos.y = buildingY;
                                        ToolBase.ToolErrors toolErrors3 = BuildingTool.CheckSpace(info, info.m_placementMode, relocating, pos, minY, buildingY + info.m_collisionHeight, num1, info.m_cellWidth, info.m_cellLength, true, collidingSegments, collidingBuildings);
                                        if ((double)maxY - (double)minY > (double)info.m_maxHeightOffset)
                                        {
                                            toolErrors3 |= ToolBase.ToolErrors.SlopeTooSteep;
                                        }
                                        if (toolErrors3 == ToolBase.ToolErrors.None)
                                        {
                                            vector3_3.y = buildingY;
                                            vector3_1   = vector3_3;
                                        }
                                        toolErrors2 = toolErrors3;
                                        break;
                                    }
                                }
                            }
                            if (toolErrors2 != ToolBase.ToolErrors.None)
                            {
                                float minY;
                                float maxY;
                                float buildingY;
                                Building.SampleBuildingHeight(vector3_1, num1, info.m_cellWidth, info.m_cellLength, info, out minY, out maxY, out buildingY);
                                Vector3 pos = vector3_1;
                                pos.y = buildingY;
                                this.m_toolController.ResetColliding();
                                toolErrors2 = BuildingTool.CheckSpace(info, info.m_placementMode, relocating, pos, minY, buildingY + info.m_collisionHeight, num1, info.m_cellWidth, info.m_cellLength, true, collidingSegments, collidingBuildings);
                                if ((double)maxY - (double)minY > (double)info.m_maxHeightOffset)
                                {
                                    toolErrors2 |= ToolBase.ToolErrors.SlopeTooSteep;
                                }
                                vector3_1.y = buildingY;
                            }
                        }
                        toolErrors1 = toolErrors2 | info.m_buildingAI.CheckBuildPosition((ushort)relocating, ref vector3_1, ref num1, waterHeight, elevation, ref connectionSegment1, out productionRate1, out constructionCost1);
                    }
                    else if (info.m_placementMode == BuildingInfo.PlacementMode.Shoreline || info.m_placementMode == BuildingInfo.PlacementMode.ShorelineOrGround)
                    {
                        Vector3 pos;
                        Vector3 dir;
                        bool    isQuay;
                        bool    canal = BuildingTool.SnapToCanal(vector3_1, out pos, out dir, out isQuay, 40f, false);
                        Vector3 position;
                        Vector3 direction;
                        bool    shorePos = Singleton <TerrainManager> .instance.GetShorePos(pos, 50f, out position, out direction, out waterHeight);

                        if (canal)
                        {
                            vector3_1 = pos;
                            num1      = Mathf.Atan2(dir.x, -dir.z);
                            float buildWaterHeight = Mathf.Max(0.0f, pos.y);
                            float minY1;
                            float maxY;
                            float buildingY;
                            Building.SampleBuildingHeight(vector3_1, num1, info.m_cellWidth, info.m_cellLength, info, out minY1, out maxY, out buildingY, ref buildWaterHeight);
                            float minY2 = minY1 - 20f;
                            float num2  = Mathf.Max(vector3_1.y, buildingY);
                            float y     = vector3_1.y;
                            vector3_1.y = num2;
                            toolErrors1 = info.m_buildingAI.CheckBuildPosition((ushort)relocating, ref vector3_1, ref num1, waterHeight, elevation, ref connectionSegment1, out productionRate1, out constructionCost1) | BuildingTool.CheckSpace(info, BuildingInfo.PlacementMode.Shoreline, relocating, vector3_1, minY2, num2 + info.m_collisionHeight, num1, info.m_cellWidth, info.m_cellLength, true, collidingSegments, collidingBuildings);
                            if ((double)y - (double)minY2 > 128.0)
                            {
                                toolErrors1 |= ToolBase.ToolErrors.HeightTooHigh;
                            }
                        }
                        else if (shorePos)
                        {
                            vector3_1 = position;
                            if (Singleton <TerrainManager> .instance.GetShorePos(vector3_1, 50f, out position, out direction, out waterHeight))
                            {
                                position += direction.normalized * info.m_placementOffset;
                                vector3_1 = position;
                                num1      = Mathf.Atan2(direction.x, -direction.z);
                                float minY;
                                float maxY;
                                float buildingY;
                                Building.SampleBuildingHeight(vector3_1, num1, info.m_cellWidth, info.m_cellLength, info, out minY, out maxY, out buildingY);
                                minY = Mathf.Min(waterHeight, minY);
                                float num2 = Mathf.Max(vector3_1.y, buildingY);
                                float y    = vector3_1.y;
                                vector3_1.y = num2;
                                toolErrors1 = info.m_buildingAI.CheckBuildPosition((ushort)relocating, ref vector3_1, ref num1, waterHeight, elevation, ref connectionSegment1, out productionRate1, out constructionCost1) | BuildingTool.CheckSpace(info, BuildingInfo.PlacementMode.Shoreline, relocating, vector3_1, minY, num2 + info.m_collisionHeight, num1, info.m_cellWidth, info.m_cellLength, true, collidingSegments, collidingBuildings);
                                if ((double)y - (double)waterHeight > 128.0)
                                {
                                    toolErrors1 |= ToolBase.ToolErrors.HeightTooHigh;
                                }
                                if ((double)num2 <= (double)waterHeight)
                                {
                                    toolErrors1 = toolErrors1 & ~(ToolBase.ToolErrors.HeightTooHigh | ToolBase.ToolErrors.CannotConnect | ToolBase.ToolErrors.CannotBuildOnWater) | ToolBase.ToolErrors.ShoreNotFound;
                                }
                            }
                            else
                            {
                                toolErrors1 = info.m_buildingAI.CheckBuildPosition((ushort)relocating, ref vector3_1, ref num1, waterHeight, elevation, ref connectionSegment1, out productionRate1, out constructionCost1) & ~(ToolBase.ToolErrors.HeightTooHigh | ToolBase.ToolErrors.CannotConnect | ToolBase.ToolErrors.CannotBuildOnWater) | ToolBase.ToolErrors.ShoreNotFound;
                            }
                        }
                        else if (info.m_placementMode == BuildingInfo.PlacementMode.ShorelineOrGround)
                        {
                            Quaternion quaternion = Quaternion.AngleAxis(this.m_angle, Vector3.down);
                            vector3_1 -= quaternion * info.m_centerOffset;
                            num1       = this.m_angle * ((float)System.Math.PI / 180f);
                            float minY;
                            float maxY;
                            float buildingY;
                            Building.SampleBuildingHeight(vector3_1, num1, info.m_cellWidth, info.m_cellLength, info, out minY, out maxY, out buildingY);
                            vector3_1.y = buildingY;
                            toolErrors1 = info.m_buildingAI.CheckBuildPosition((ushort)relocating, ref vector3_1, ref num1, waterHeight, elevation, ref connectionSegment1, out productionRate1, out constructionCost1) | BuildingTool.CheckSpace(info, BuildingInfo.PlacementMode.OnGround, relocating, vector3_1, minY, buildingY + info.m_collisionHeight, num1, info.m_cellWidth, info.m_cellLength, true, collidingSegments, collidingBuildings);
                            if ((toolErrors1 & ToolBase.ToolErrors.CannotBuildOnWater) == ToolBase.ToolErrors.None && (double)maxY - (double)minY > (double)info.m_maxHeightOffset)
                            {
                                toolErrors1 |= ToolBase.ToolErrors.SlopeTooSteep;
                            }
                        }
                        else
                        {
                            toolErrors1 = info.m_buildingAI.CheckBuildPosition((ushort)relocating, ref vector3_1, ref num1, waterHeight, elevation, ref connectionSegment1, out productionRate1, out constructionCost1) & ~(ToolBase.ToolErrors.HeightTooHigh | ToolBase.ToolErrors.CannotConnect | ToolBase.ToolErrors.CannotBuildOnWater) | ToolBase.ToolErrors.ShoreNotFound;
                        }
                    }
                    else if (info.m_placementMode == BuildingInfo.PlacementMode.PathsideOrGround)
                    {
                        Vector3 pos;
                        Vector3 dir;
                        if (BuildingTool.SnapToPath(vector3_1, out pos, out dir, (float)Mathf.Min(info.m_cellWidth, info.m_cellLength) * 3.9f, info.m_hasPedestrianPaths))
                        {
                            vector3_1 = pos - dir * (float)info.m_cellLength * 4f;
                            num1      = Mathf.Atan2(-dir.x, dir.z);
                            float minY;
                            float maxY;
                            float buildingY;
                            Building.SampleBuildingHeight(vector3_1, num1, info.m_cellWidth, info.m_cellLength, info, out minY, out maxY, out buildingY);
                            toolErrors1 = info.m_buildingAI.CheckBuildPosition((ushort)relocating, ref vector3_1, ref num1, waterHeight, elevation, ref connectionSegment1, out productionRate1, out constructionCost1) | BuildingTool.CheckSpace(info, BuildingInfo.PlacementMode.PathsideOrGround, relocating, vector3_1, minY, vector3_1.y + info.m_collisionHeight, num1, info.m_cellWidth, info.m_cellLength, true, collidingSegments, collidingBuildings);
                            if ((double)maxY - (double)minY > (double)info.m_maxHeightOffset)
                            {
                                toolErrors1 |= ToolBase.ToolErrors.SlopeTooSteep;
                            }
                        }
                        else
                        {
                            Quaternion quaternion = Quaternion.AngleAxis(this.m_angle, Vector3.down);
                            vector3_1 -= quaternion * info.m_centerOffset;
                            num1       = this.m_angle * ((float)System.Math.PI / 180f);
                            float minY;
                            float maxY;
                            float buildingY;
                            Building.SampleBuildingHeight(vector3_1, num1, info.m_cellWidth, info.m_cellLength, info, out minY, out maxY, out buildingY);
                            vector3_1.y = buildingY;
                            toolErrors1 = info.m_buildingAI.CheckBuildPosition((ushort)relocating, ref vector3_1, ref num1, waterHeight, elevation, ref connectionSegment1, out productionRate1, out constructionCost1) | BuildingTool.CheckSpace(info, BuildingInfo.PlacementMode.OnGround, relocating, vector3_1, minY, buildingY + info.m_collisionHeight, num1, info.m_cellWidth, info.m_cellLength, true, collidingSegments, collidingBuildings);
                            if ((double)maxY - (double)minY > (double)info.m_maxHeightOffset)
                            {
                                toolErrors1 |= ToolBase.ToolErrors.SlopeTooSteep;
                            }
                        }
                    }
                    else if (info.m_placementMode == BuildingInfo.PlacementMode.OnSurface || info.m_placementMode == BuildingInfo.PlacementMode.OnTerrain)
                    {
                        Quaternion quaternion = Quaternion.AngleAxis(this.m_angle, Vector3.down);
                        vector3_1 -= quaternion * info.m_centerOffset;
                        num1       = this.m_angle * ((float)System.Math.PI / 180f);
                        float minY;
                        float maxY;
                        float buildingY;
                        Building.SampleBuildingHeight(vector3_1, num1, info.m_cellWidth, info.m_cellLength, info, out minY, out maxY, out buildingY);
                        vector3_1.y = buildingY;
                        toolErrors1 = info.m_buildingAI.CheckBuildPosition((ushort)relocating, ref vector3_1, ref num1, waterHeight, elevation, ref connectionSegment1, out productionRate1, out constructionCost1) | BuildingTool.CheckSpace(info, info.m_placementMode, relocating, vector3_1, minY, buildingY + info.m_collisionHeight, num1, info.m_cellWidth, info.m_cellLength, true, collidingSegments, collidingBuildings);
                    }
                    else if (info.m_placementMode == BuildingInfo.PlacementMode.OnGround)
                    {
                        Quaternion quaternion = Quaternion.AngleAxis(this.m_angle, Vector3.down);
                        vector3_1 -= quaternion * info.m_centerOffset;
                        num1       = this.m_angle * ((float)System.Math.PI / 180f);
                        float minY;
                        float maxY;
                        float buildingY;
                        Building.SampleBuildingHeight(vector3_1, num1, info.m_cellWidth, info.m_cellLength, info, out minY, out maxY, out buildingY);
                        vector3_1.y = buildingY;
                        toolErrors1 = info.m_buildingAI.CheckBuildPosition((ushort)relocating, ref vector3_1, ref num1, waterHeight, elevation, ref connectionSegment1, out productionRate1, out constructionCost1) | BuildingTool.CheckSpace(info, info.m_placementMode, relocating, vector3_1, minY, buildingY + info.m_collisionHeight, num1, info.m_cellWidth, info.m_cellLength, true, collidingSegments, collidingBuildings);
                        if ((double)maxY - (double)minY > (double)info.m_maxHeightOffset)
                        {
                            toolErrors1 |= ToolBase.ToolErrors.SlopeTooSteep;
                        }
                    }
                    else if (info.m_placementMode == BuildingInfo.PlacementMode.OnWater)
                    {
                        Quaternion quaternion = Quaternion.AngleAxis(this.m_angle, Vector3.down);
                        vector3_1 -= quaternion * info.m_centerOffset;
                        num1       = this.m_angle * ((float)System.Math.PI / 180f);
                        float minY;
                        float maxY;
                        float buildingY;
                        Building.SampleBuildingHeight(vector3_1, num1, info.m_cellWidth, info.m_cellLength, info, out minY, out maxY, out buildingY);
                        vector3_1.y = buildingY;
                        toolErrors1 = info.m_buildingAI.CheckBuildPosition((ushort)relocating, ref vector3_1, ref num1, waterHeight, elevation, ref connectionSegment1, out productionRate1, out constructionCost1) | BuildingTool.CheckSpace(info, info.m_placementMode, relocating, vector3_1, minY, buildingY + info.m_collisionHeight, num1, info.m_cellWidth, info.m_cellLength, true, collidingSegments, collidingBuildings);
                    }
                    else
                    {
                        toolErrors1 = ToolBase.ToolErrors.Pending | info.m_buildingAI.CheckBuildPosition((ushort)relocating, ref vector3_1, ref num1, waterHeight, elevation, ref connectionSegment1, out productionRate1, out constructionCost1);
                    }
                    if (info.m_subBuildings != null && info.m_subBuildings.Length != 0)
                    {
                        Matrix4x4 matrix4x4 = new Matrix4x4();
                        matrix4x4.SetTRS(vector3_1, Quaternion.AngleAxis(num1 * 57.29578f, Vector3.down), Vector3.one);
                        for (int index = 0; index < info.m_subBuildings.Length; ++index)
                        {
                            BuildingInfo buildingInfo       = info.m_subBuildings[index].m_buildingInfo;
                            Vector3      position           = matrix4x4.MultiplyPoint(info.m_subBuildings[index].m_position);
                            float        angle              = info.m_subBuildings[index].m_angle * ((float)System.Math.PI / 180f) + num1;
                            Segment3     connectionSegment2 = new Segment3();
                            int          productionRate2;
                            int          constructionCost2;
                            toolErrors1       |= buildingInfo.m_buildingAI.CheckBuildPosition((ushort)relocating, ref position, ref angle, waterHeight, elevation, ref connectionSegment2, out productionRate2, out constructionCost2);
                            constructionCost1 += constructionCost2;
                            if ((productionRate2 & 268435456) != 0)
                            {
                                connectionSegment1 = connectionSegment2;
                                productionRate1    = productionRate2 & 268435455;
                            }
                        }
                    }
                    if (flag && Singleton <EconomyManager> .instance.PeekResource(EconomyManager.Resource.Construction, constructionCost1) != constructionCost1)
                    {
                        toolErrors1 |= ToolBase.ToolErrors.NotEnoughMoney;
                    }
                    if (!Singleton <BuildingManager> .instance.CheckLimits())
                    {
                        toolErrors1 |= ToolBase.ToolErrors.TooManyObjects;
                    }
                    if ((Singleton <ToolManager> .instance.m_properties.m_mode & ItemClass.Availability.AssetEditor) != ItemClass.Availability.None && (UnityEngine.Object) this.m_toolController.m_editPrefabInfo != (UnityEngine.Object)null)
                    {
                        BuildingInfo editPrefabInfo = this.m_toolController.m_editPrefabInfo as BuildingInfo;
                        if ((UnityEngine.Object)editPrefabInfo != (UnityEngine.Object)null && (UnityEngine.Object)editPrefabInfo.m_buildingAI != (UnityEngine.Object)null && !(editPrefabInfo.m_buildingAI is IntersectionAI))
                        {
                            toolErrors1 = ToolBase.ToolErrors.None;
                        }
                    }
                    this.m_mousePosition    = vector3_1;
                    m_mouseAngle            = (Singleton <ToolManager> .instance.m_properties.m_mode & ItemClass.Availability.AssetEditor) != ItemClass.Availability.None ? this.m_angle * ((float)System.Math.PI / 180f) : num1;
                    m_connectionSegment     = connectionSegment1;
                    this.m_productionRate   = productionRate1;
                    this.m_constructionCost = constructionCost1;
                    this.m_placementErrors  = toolErrors1;
                }
                else
                {
                    this.m_placementErrors   = ToolBase.ToolErrors.RaycastFailed;
                    this.m_connectionSegment = new Segment3();
                }
            }
            finally
            {
                this.m_toolController.EndColliding();
            }
        }
Ejemplo n.º 26
0
        public override void SimulationStep()
        {
            TransportInfo prefab = this.m_prefab;

            if (prefab == null)
            {
                return;
            }
            ToolBase.ToolErrors toolErrors = ToolBase.ToolErrors.None;
            switch (this.m_mode)
            {
            case CustomTransportTool.Mode.NewLine:
            {
                Vector3 vector;
                ushort  num;
                int     hoverStopIndex;
                int     hoverSegmentIndex;
                if ((Singleton <TransportManager> .instance as CustomTransportManager).RayCast(this.m_mouseRay, this.m_mouseRayLength, out vector, out num, out hoverStopIndex, out hoverSegmentIndex))
                {
                    TransportInfo info = Singleton <TransportManager> .instance.m_lines.m_buffer[(int)num].Info;
                    bool          flag = info == prefab;
                    if (flag)
                    {
                        flag = this.EnsureTempLine(prefab, num, -2, -2, vector, false);
                    }
                    if (flag)
                    {
                        this.m_hitPosition       = vector;
                        this.m_fixedPlatform     = false;
                        this.m_hoverStopIndex    = hoverStopIndex;
                        this.m_hoverSegmentIndex = hoverSegmentIndex;
                        if (this.m_hoverSegmentIndex != -1 && !Singleton <NetManager> .instance.CheckLimits())
                        {
                            toolErrors |= ToolBase.ToolErrors.TooManyObjects;
                        }
                    }
                    else
                    {
                        this.EnsureTempLine(prefab, 0, -2, -2, Vector3.zero, false);
                        this.m_hoverStopIndex    = -1;
                        this.m_hoverSegmentIndex = -1;
                        toolErrors |= ToolBase.ToolErrors.RaycastFailed;
                    }
                }
                else
                {
                    ToolBase.RaycastOutput raycastOutput;
                    bool flag2 = ToolBase.RayCast(new ToolBase.RaycastInput(this.m_mouseRay, this.m_mouseRayLength)
                        {
                            m_buildingService     = new ToolBase.RaycastService(prefab.m_stationService, prefab.m_stationSubService, prefab.m_stationLayer),
                            m_netService          = new ToolBase.RaycastService(prefab.m_netService, prefab.m_netSubService, prefab.m_netLayer),
                            m_ignoreTerrain       = true,
                            m_ignoreSegmentFlags  = (prefab.m_netService == ItemClass.Service.None) ? NetSegment.Flags.All : NetSegment.Flags.None,
                            m_ignoreBuildingFlags = (prefab.m_stationService == ItemClass.Service.None) ? Building.Flags.All : Building.Flags.None
                        }, out raycastOutput);
                    bool fixedPlatform = false;
                    if (flag2)
                    {
                        flag2 = this.GetStopPosition(prefab, raycastOutput.m_netSegment, raycastOutput.m_building, 0, ref raycastOutput.m_hitPos, out fixedPlatform);
                    }
                    if (flag2)
                    {
                        flag2 = this.CanAddStop(prefab, 0, -1, raycastOutput.m_hitPos);
                    }
                    if (flag2)
                    {
                        flag2 = this.EnsureTempLine(prefab, 0, -2, -1, raycastOutput.m_hitPos, fixedPlatform);
                    }
                    if (flag2)
                    {
                        this.m_hitPosition       = raycastOutput.m_hitPos;
                        this.m_fixedPlatform     = fixedPlatform;
                        this.m_hoverStopIndex    = -1;
                        this.m_hoverSegmentIndex = -1;
                        if (!Singleton <NetManager> .instance.CheckLimits())
                        {
                            toolErrors |= ToolBase.ToolErrors.TooManyObjects;
                        }
                        if (!Singleton <TransportManager> .instance.CheckLimits())
                        {
                            toolErrors |= ToolBase.ToolErrors.TooManyObjects;
                        }
                    }
                    else
                    {
                        this.EnsureTempLine(prefab, 0, -2, -2, Vector3.zero, fixedPlatform);
                        this.m_hoverStopIndex    = -1;
                        this.m_hoverSegmentIndex = -1;
                        toolErrors |= ToolBase.ToolErrors.RaycastFailed;
                    }
                }
                break;
            }

            case CustomTransportTool.Mode.AddStops:
                if (this.m_line == 0)
                {
                    this.m_mode = CustomTransportTool.Mode.NewLine;
                    toolErrors |= ToolBase.ToolErrors.RaycastFailed;
                }
                else
                {
                    ToolBase.RaycastOutput raycastOutput2;
                    bool flag3 = ToolBase.RayCast(new ToolBase.RaycastInput(this.m_mouseRay, this.m_mouseRayLength)
                    {
                        m_buildingService     = new ToolBase.RaycastService(prefab.m_stationService, prefab.m_stationSubService, prefab.m_stationLayer),
                        m_netService          = new ToolBase.RaycastService(prefab.m_netService, prefab.m_netSubService, prefab.m_netLayer),
                        m_ignoreTerrain       = true,
                        m_ignoreSegmentFlags  = (prefab.m_netService == ItemClass.Service.None) ? NetSegment.Flags.All : NetSegment.Flags.None,
                        m_ignoreBuildingFlags = (prefab.m_stationService == ItemClass.Service.None) ? Building.Flags.All : Building.Flags.None
                    }, out raycastOutput2);
                    bool fixedPlatform2 = false;
                    if (flag3)
                    {
                        ushort firstStop = 0;
                        if (this.m_line != 0)
                        {
                            TransportManager instance = Singleton <TransportManager> .instance;
                            if (!instance.m_lines.m_buffer[(int)this.m_line].Complete)
                            {
                                firstStop = instance.m_lines.m_buffer[(int)this.m_line].m_stops;
                            }
                        }
                        flag3 = this.GetStopPosition(prefab, raycastOutput2.m_netSegment, raycastOutput2.m_building, firstStop, ref raycastOutput2.m_hitPos, out fixedPlatform2);
                    }
                    if (flag3)
                    {
                        flag3 = this.CanAddStop(prefab, this.m_line, -1, raycastOutput2.m_hitPos);
                    }
                    if (flag3)
                    {
                        flag3 = this.EnsureTempLine(prefab, this.m_line, -2, -1, raycastOutput2.m_hitPos, fixedPlatform2);
                    }
                    if (flag3)
                    {
                        this.m_hitPosition   = raycastOutput2.m_hitPos;
                        this.m_fixedPlatform = fixedPlatform2;
                        if (!Singleton <NetManager> .instance.CheckLimits())
                        {
                            toolErrors |= ToolBase.ToolErrors.TooManyObjects;
                        }
                    }
                    else
                    {
                        this.EnsureTempLine(prefab, this.m_line, -2, -2, Vector3.zero, fixedPlatform2);
                        toolErrors |= ToolBase.ToolErrors.RaycastFailed;
                    }
                }
                break;

            case CustomTransportTool.Mode.MoveStops:
                if (this.m_line == 0)
                {
                    this.m_mode = CustomTransportTool.Mode.NewLine;
                    toolErrors |= ToolBase.ToolErrors.RaycastFailed;
                }
                else
                {
                    ToolBase.RaycastOutput raycastOutput3;
                    bool flag4 = ToolBase.RayCast(new ToolBase.RaycastInput(this.m_mouseRay, this.m_mouseRayLength)
                    {
                        m_buildingService     = new ToolBase.RaycastService(prefab.m_stationService, prefab.m_stationSubService, prefab.m_stationLayer),
                        m_netService          = new ToolBase.RaycastService(prefab.m_netService, prefab.m_netSubService, prefab.m_netLayer),
                        m_ignoreTerrain       = true,
                        m_ignoreSegmentFlags  = (prefab.m_netService == ItemClass.Service.None) ? NetSegment.Flags.All : NetSegment.Flags.None,
                        m_ignoreBuildingFlags = (prefab.m_stationService == ItemClass.Service.None) ? Building.Flags.All : Building.Flags.None
                    }, out raycastOutput3);
                    bool fixedPlatform3 = false;
                    if (flag4)
                    {
                        flag4 = this.GetStopPosition(prefab, raycastOutput3.m_netSegment, raycastOutput3.m_building, 0, ref raycastOutput3.m_hitPos, out fixedPlatform3);
                    }
                    if (this.m_hoverStopIndex != -1)
                    {
                        if (flag4)
                        {
                            flag4 = this.CanMoveStop(prefab, this.m_line, this.m_hoverStopIndex, raycastOutput3.m_hitPos);
                        }
                        if (flag4)
                        {
                            flag4 = this.EnsureTempLine(prefab, this.m_line, this.m_hoverStopIndex, -2, raycastOutput3.m_hitPos, fixedPlatform3);
                        }
                    }
                    else if (this.m_hoverSegmentIndex != -1)
                    {
                        if (flag4)
                        {
                            flag4 = this.CanAddStop(prefab, this.m_line, this.m_hoverSegmentIndex + 1, raycastOutput3.m_hitPos);
                        }
                        if (flag4)
                        {
                            flag4 = this.EnsureTempLine(prefab, this.m_line, -2, this.m_hoverSegmentIndex + 1, raycastOutput3.m_hitPos, fixedPlatform3);
                        }
                    }
                    if (flag4)
                    {
                        this.m_hitPosition   = raycastOutput3.m_hitPos;
                        this.m_fixedPlatform = fixedPlatform3;
                        if (this.m_hoverSegmentIndex != -1 && !Singleton <NetManager> .instance.CheckLimits())
                        {
                            toolErrors |= ToolBase.ToolErrors.TooManyObjects;
                        }
                    }
                    else
                    {
                        this.EnsureTempLine(prefab, this.m_line, -2, -2, Vector3.zero, fixedPlatform3);
                        toolErrors |= ToolBase.ToolErrors.RaycastFailed;
                    }
                }
                break;

            default:
                toolErrors |= ToolBase.ToolErrors.RaycastFailed;
                break;
            }
            this.m_errors = toolErrors;
        }
Ejemplo n.º 27
0
 public override void SimulationStep()
 {
     TransportInfo prefab = this.m_prefab;
     if (prefab == null)
     {
         return;
     }
     ToolBase.ToolErrors toolErrors = ToolBase.ToolErrors.None;
     switch (this.m_mode)
     {
         case CustomTransportTool.Mode.NewLine:
             {
                 Vector3 vector;
                 ushort num;
                 int hoverStopIndex;
                 int hoverSegmentIndex;
                 if ((Singleton<TransportManager>.instance as CustomTransportManager).RayCast(this.m_mouseRay, this.m_mouseRayLength, out vector, out num, out hoverStopIndex, out hoverSegmentIndex))
                 {
                     TransportInfo info = Singleton<TransportManager>.instance.m_lines.m_buffer[(int)num].Info;
                     bool flag = info == prefab;
                     if (flag)
                     {
                         flag = this.EnsureTempLine(prefab, num, -2, -2, vector, false);
                     }
                     if (flag)
                     {
                         this.m_hitPosition = vector;
                         this.m_fixedPlatform = false;
                         this.m_hoverStopIndex = hoverStopIndex;
                         this.m_hoverSegmentIndex = hoverSegmentIndex;
                         if (this.m_hoverSegmentIndex != -1 && !Singleton<NetManager>.instance.CheckLimits())
                         {
                             toolErrors |= ToolBase.ToolErrors.TooManyObjects;
                         }
                     }
                     else
                     {
                         this.EnsureTempLine(prefab, 0, -2, -2, Vector3.zero, false);
                         this.m_hoverStopIndex = -1;
                         this.m_hoverSegmentIndex = -1;
                         toolErrors |= ToolBase.ToolErrors.RaycastFailed;
                     }
                 }
                 else
                 {
                     ToolBase.RaycastOutput raycastOutput;
                     bool flag2 = ToolBase.RayCast(new ToolBase.RaycastInput(this.m_mouseRay, this.m_mouseRayLength)
                     {
                         m_buildingService = new ToolBase.RaycastService(prefab.m_stationService, prefab.m_stationSubService, prefab.m_stationLayer),
                         m_netService = new ToolBase.RaycastService(prefab.m_netService, prefab.m_netSubService, prefab.m_netLayer),
                         m_ignoreTerrain = true,
                         m_ignoreSegmentFlags = (prefab.m_netService == ItemClass.Service.None) ? NetSegment.Flags.All : NetSegment.Flags.None,
                         m_ignoreBuildingFlags = (prefab.m_stationService == ItemClass.Service.None) ? Building.Flags.All : Building.Flags.None
                     }, out raycastOutput);
                     bool fixedPlatform = false;
                     if (flag2)
                     {
                         flag2 = this.GetStopPosition(prefab, raycastOutput.m_netSegment, raycastOutput.m_building, 0, ref raycastOutput.m_hitPos, out fixedPlatform);
                     }
                     if (flag2)
                     {
                         flag2 = this.CanAddStop(prefab, 0, -1, raycastOutput.m_hitPos);
                     }
                     if (flag2)
                     {
                         flag2 = this.EnsureTempLine(prefab, 0, -2, -1, raycastOutput.m_hitPos, fixedPlatform);
                     }
                     if (flag2)
                     {
                         this.m_hitPosition = raycastOutput.m_hitPos;
                         this.m_fixedPlatform = fixedPlatform;
                         this.m_hoverStopIndex = -1;
                         this.m_hoverSegmentIndex = -1;
                         if (!Singleton<NetManager>.instance.CheckLimits())
                         {
                             toolErrors |= ToolBase.ToolErrors.TooManyObjects;
                         }
                         if (!Singleton<TransportManager>.instance.CheckLimits())
                         {
                             toolErrors |= ToolBase.ToolErrors.TooManyObjects;
                         }
                     }
                     else
                     {
                         this.EnsureTempLine(prefab, 0, -2, -2, Vector3.zero, fixedPlatform);
                         this.m_hoverStopIndex = -1;
                         this.m_hoverSegmentIndex = -1;
                         toolErrors |= ToolBase.ToolErrors.RaycastFailed;
                     }
                 }
                 break;
             }
         case CustomTransportTool.Mode.AddStops:
             if (this.m_line == 0)
             {
                 this.m_mode = CustomTransportTool.Mode.NewLine;
                 toolErrors |= ToolBase.ToolErrors.RaycastFailed;
             }
             else
             {
                 ToolBase.RaycastOutput raycastOutput2;
                 bool flag3 = ToolBase.RayCast(new ToolBase.RaycastInput(this.m_mouseRay, this.m_mouseRayLength)
                 {
                     m_buildingService = new ToolBase.RaycastService(prefab.m_stationService, prefab.m_stationSubService, prefab.m_stationLayer),
                     m_netService = new ToolBase.RaycastService(prefab.m_netService, prefab.m_netSubService, prefab.m_netLayer),
                     m_ignoreTerrain = true,
                     m_ignoreSegmentFlags = (prefab.m_netService == ItemClass.Service.None) ? NetSegment.Flags.All : NetSegment.Flags.None,
                     m_ignoreBuildingFlags = (prefab.m_stationService == ItemClass.Service.None) ? Building.Flags.All : Building.Flags.None
                 }, out raycastOutput2);
                 bool fixedPlatform2 = false;
                 if (flag3)
                 {
                     ushort firstStop = 0;
                     if (this.m_line != 0)
                     {
                         TransportManager instance = Singleton<TransportManager>.instance;
                         if (!instance.m_lines.m_buffer[(int)this.m_line].Complete)
                         {
                             firstStop = instance.m_lines.m_buffer[(int)this.m_line].m_stops;
                         }
                     }
                     flag3 = this.GetStopPosition(prefab, raycastOutput2.m_netSegment, raycastOutput2.m_building, firstStop, ref raycastOutput2.m_hitPos, out fixedPlatform2);
                 }
                 if (flag3)
                 {
                     flag3 = this.CanAddStop(prefab, this.m_line, -1, raycastOutput2.m_hitPos);
                 }
                 if (flag3)
                 {
                     flag3 = this.EnsureTempLine(prefab, this.m_line, -2, -1, raycastOutput2.m_hitPos, fixedPlatform2);
                 }
                 if (flag3)
                 {
                     this.m_hitPosition = raycastOutput2.m_hitPos;
                     this.m_fixedPlatform = fixedPlatform2;
                     if (!Singleton<NetManager>.instance.CheckLimits())
                     {
                         toolErrors |= ToolBase.ToolErrors.TooManyObjects;
                     }
                 }
                 else
                 {
                     this.EnsureTempLine(prefab, this.m_line, -2, -2, Vector3.zero, fixedPlatform2);
                     toolErrors |= ToolBase.ToolErrors.RaycastFailed;
                 }
             }
             break;
         case CustomTransportTool.Mode.MoveStops:
             if (this.m_line == 0)
             {
                 this.m_mode = CustomTransportTool.Mode.NewLine;
                 toolErrors |= ToolBase.ToolErrors.RaycastFailed;
             }
             else
             {
                 ToolBase.RaycastOutput raycastOutput3;
                 bool flag4 = ToolBase.RayCast(new ToolBase.RaycastInput(this.m_mouseRay, this.m_mouseRayLength)
                 {
                     m_buildingService = new ToolBase.RaycastService(prefab.m_stationService, prefab.m_stationSubService, prefab.m_stationLayer),
                     m_netService = new ToolBase.RaycastService(prefab.m_netService, prefab.m_netSubService, prefab.m_netLayer),
                     m_ignoreTerrain = true,
                     m_ignoreSegmentFlags = (prefab.m_netService == ItemClass.Service.None) ? NetSegment.Flags.All : NetSegment.Flags.None,
                     m_ignoreBuildingFlags = (prefab.m_stationService == ItemClass.Service.None) ? Building.Flags.All : Building.Flags.None
                 }, out raycastOutput3);
                 bool fixedPlatform3 = false;
                 if (flag4)
                 {
                     flag4 = this.GetStopPosition(prefab, raycastOutput3.m_netSegment, raycastOutput3.m_building, 0, ref raycastOutput3.m_hitPos, out fixedPlatform3);
                 }
                 if (this.m_hoverStopIndex != -1)
                 {
                     if (flag4)
                     {
                         flag4 = this.CanMoveStop(prefab, this.m_line, this.m_hoverStopIndex, raycastOutput3.m_hitPos);
                     }
                     if (flag4)
                     {
                         flag4 = this.EnsureTempLine(prefab, this.m_line, this.m_hoverStopIndex, -2, raycastOutput3.m_hitPos, fixedPlatform3);
                     }
                 }
                 else if (this.m_hoverSegmentIndex != -1)
                 {
                     if (flag4)
                     {
                         flag4 = this.CanAddStop(prefab, this.m_line, this.m_hoverSegmentIndex + 1, raycastOutput3.m_hitPos);
                     }
                     if (flag4)
                     {
                         flag4 = this.EnsureTempLine(prefab, this.m_line, -2, this.m_hoverSegmentIndex + 1, raycastOutput3.m_hitPos, fixedPlatform3);
                     }
                 }
                 if (flag4)
                 {
                     this.m_hitPosition = raycastOutput3.m_hitPos;
                     this.m_fixedPlatform = fixedPlatform3;
                     if (this.m_hoverSegmentIndex != -1 && !Singleton<NetManager>.instance.CheckLimits())
                     {
                         toolErrors |= ToolBase.ToolErrors.TooManyObjects;
                     }
                 }
                 else
                 {
                     this.EnsureTempLine(prefab, this.m_line, -2, -2, Vector3.zero, fixedPlatform3);
                     toolErrors |= ToolBase.ToolErrors.RaycastFailed;
                 }
             }
             break;
         default:
             toolErrors |= ToolBase.ToolErrors.RaycastFailed;
             break;
     }
     this.m_errors = toolErrors;
 }
Ejemplo n.º 28
0
        public virtual void OnAfterSimulationTick()
        {
            if (m_buildingTool == null)
            {
                return;
            }

            // Removes HeightTooHigh & TooShort errors
            if (m_buildingTool.enabled)
            {
                ToolBase.ToolErrors errors = (ToolBase.ToolErrors)m_placementErrorsField.GetValue(m_buildingTool);
                if ((errors & ToolBase.ToolErrors.HeightTooHigh) == ToolBase.ToolErrors.HeightTooHigh)
                {
                    errors = errors & ~ToolBase.ToolErrors.HeightTooHigh;
                    m_placementErrorsField.SetValue(m_buildingTool, errors);
                }

                if ((errors & ToolBase.ToolErrors.TooShort) == ToolBase.ToolErrors.TooShort)
                {
                    errors = errors & ~ToolBase.ToolErrors.TooShort;
                    m_placementErrorsField.SetValue(m_buildingTool, errors);
                }
            }

            // Resume fixes
            if (m_fixNodesCount != 0 || m_fixTunnelsCount != 0)
            {
                RoadPrefab prefab = RoadPrefab.GetPrefab(m_current);
                if (prefab != null)
                {
                    prefab.Restore(false);
                }

                if (m_fixTunnelsCount != 0)
                {
                    FixTunnels();
                }
                if (m_fixNodesCount != 0)
                {
                    FixNodes();
                }

                if (prefab != null)
                {
                    prefab.Update(false);
                }
            }

            if (!isActive && !m_bulldozeTool.enabled)
            {
                return;
            }

            // Check if segment have been created/deleted/updated
            if (m_segmentCount != NetManager.instance.m_segmentCount || (bool)m_upgradingField.GetValue(m_netTool))
            {
                m_segmentCount = NetManager.instance.m_segmentCount;

                RoadPrefab prefab = RoadPrefab.GetPrefab(m_current);
                if (prefab != null)
                {
                    prefab.Restore(false);
                }

                m_fixTunnelsCount = 0;
                m_fixNodesCount   = 0;

                FixTunnels();
                FixNodes();

                if (prefab != null)
                {
                    prefab.Update(straightSlope);
                }
            }

            if (!isActive)
            {
                return;
            }

            // Fix first control point elevation
            int count = (int)m_controlPointCountField.GetValue(m_netTool);

            if (count != m_controlPointCount && m_controlPointCount == 0 && count == 1)
            {
                if (FixControlPoint(0))
                {
                    m_elevation = Mathf.RoundToInt(Mathf.RoundToInt(m_controlPoints[0].m_elevation / elevationStep) * elevationStep * 256f / 12f);
                    UpdateElevation();
                    if (m_toolOptionButton != null)
                    {
                        m_toolOptionButton.UpdateInfo();
                    }
                }
            }
            // Fix last control point elevation
            else if (count == ((m_netTool.m_mode == NetTool.Mode.Curved || m_netTool.m_mode == NetTool.Mode.Freeform) ? 2 : 1))
            {
                FixControlPoint(count);
            }
            m_controlPointCount = count;
        }
Ejemplo n.º 29
0
        public static void Postfix(TransportInfo ___m_prefab, Vector3 ___m_hitPosition, bool ___m_fixedPlatform, int ___m_hoverStopIndex, int ___m_hoverSegmentIndex, int ___m_mode, ToolBase.ToolErrors ___m_errors, ref DataStore __state)
        {
            if (IgnoreHelper.IsIgnored())
            {
                return;
            }

            TransportHandler.TrackSimulationStep = false;

            // Only send when values have changed
            if (TransportHandler.DidUpdatePaths ||
                __state.hitPos != ___m_hitPosition || __state.fixedP != ___m_fixedPlatform ||
                __state.hoverStop != ___m_hoverStopIndex || __state.hoverSegment != ___m_hoverSegmentIndex ||
                __state.mode != ___m_mode || __state.errors != ___m_errors)
            {
                Command.SendToAll(new TransportLineSyncCommand()
                {
                    HitPosition       = ___m_hitPosition,
                    FixedPlatform     = ___m_fixedPlatform,
                    HoverStopIndex    = ___m_hoverStopIndex,
                    HoverSegmentIndex = ___m_hoverSegmentIndex,
                    Mode        = ___m_mode,
                    Errors      = ___m_errors,
                    UpdateLines = TransportHandler.DidUpdateLinesNow,
                    UpdatePaths = TransportHandler.DidUpdatePaths
                });

                TransportHandler.DidUpdateLinesNow = false;
                TransportHandler.DidUpdatePaths    = false;
            }
        }
Ejemplo n.º 30
0
 public override ToolBase.ToolErrors CheckBuildPosition(ushort relocateID, ref Vector3 position, ref float angle, float waterHeight, ref Segment3 connectionSegment, out int productionRate, out int constructionCost)
 {
     ToolBase.ToolErrors toolErrors = base.CheckBuildPosition(relocateID, ref position, ref angle, waterHeight, ref connectionSegment, out productionRate, out constructionCost);
     return(toolErrors);
 }
        public override ToolBase.ToolErrors CheckBuildPosition(bool test, bool visualize, bool overlay, bool autofix, ref NetTool.ControlPoint startPoint, ref NetTool.ControlPoint middlePoint, ref NetTool.ControlPoint endPoint, out BuildingInfo ownerBuilding, out Vector3 ownerPosition, out Vector3 ownerDirection, out int productionRate)
        {
            ToolBase.ToolErrors toolErrors = base.CheckBuildPosition(test, visualize, overlay, autofix, ref startPoint, ref middlePoint, ref endPoint, out ownerBuilding, out ownerPosition, out ownerDirection, out productionRate);
            NetManager          instance1  = Singleton <NetManager> .instance;
            TerrainManager      instance2  = Singleton <TerrainManager> .instance;

            if ((int)startPoint.m_node != 0)
            {
                NetInfo info = instance1.m_nodes.m_buffer[(int)startPoint.m_node].Info;
                if (info.m_class.m_subService != this.m_info.m_class.m_subService || info.m_class.m_level != this.m_info.m_class.m_level)
                {
                    toolErrors |= ToolBase.ToolErrors.InvalidShape;
                }
            }
            else if ((int)startPoint.m_segment != 0)
            {
                NetInfo info = instance1.m_segments.m_buffer[(int)startPoint.m_segment].Info;
                if (info.m_class.m_subService != this.m_info.m_class.m_subService || info.m_class.m_level != this.m_info.m_class.m_level)
                {
                    toolErrors |= ToolBase.ToolErrors.InvalidShape;
                }
            }
            if ((int)endPoint.m_node != 0)
            {
                NetInfo info = instance1.m_nodes.m_buffer[(int)endPoint.m_node].Info;
                if (info.m_class.m_subService != this.m_info.m_class.m_subService || info.m_class.m_level != this.m_info.m_class.m_level)
                {
                    toolErrors |= ToolBase.ToolErrors.InvalidShape;
                }
            }
            else if ((int)endPoint.m_segment != 0)
            {
                NetInfo info = instance1.m_segments.m_buffer[(int)endPoint.m_segment].Info;
                if (info.m_class.m_subService != this.m_info.m_class.m_subService || info.m_class.m_level != this.m_info.m_class.m_level)
                {
                    toolErrors |= ToolBase.ToolErrors.InvalidShape;
                }
            }
            Vector3 middlePos1;
            Vector3 middlePos2;

            NetSegment.CalculateMiddlePoints(startPoint.m_position, middlePoint.m_direction, endPoint.m_position, -endPoint.m_direction, true, true, out middlePos1, out middlePos2);
            Bezier2 bezier2;

            bezier2.a = VectorUtils.XZ(startPoint.m_position);
            bezier2.b = VectorUtils.XZ(middlePos1);
            bezier2.c = VectorUtils.XZ(middlePos2);
            bezier2.d = VectorUtils.XZ(endPoint.m_position);
            int      num = Mathf.CeilToInt(Vector2.Distance(bezier2.a, bezier2.d) * 0.005f) + 3;
            Segment2 segment;

            segment.a = bezier2.a;
            for (int index = 1; index <= num; ++index)
            {
                segment.b = bezier2.Position((float)index / (float)num);
                //begin mod
                //end mod
                segment.a = segment.b;
            }
            return(toolErrors);
        }