コード例 #1
0
        private static void FixSlopes(BuildingInfo info, int inx, TrackVehicleType vehicletype)
        {
            var path = info.m_paths[inx];
            var horizontalDistance = Vector3.Distance(new Vector3(path.m_nodes[0].x, path.m_nodes[0].y, path.m_nodes[0].z),
                                                      new Vector3(path.m_nodes[1].x, path.m_nodes[0].y, path.m_nodes[1].z)); //Math.Pow(Math.Pow(path.m_nodes[0].x - path.m_nodes[1].x, 2) + Math.Pow(path.m_nodes[0].x - path.m_nodes[1].x, 2), 0.5f);

            var verticalDistance = Math.Abs(path.m_nodes[0].y - path.m_nodes[1].y);

            if (path.m_netInfo.m_maxSlope < Math.Abs(verticalDistance / horizontalDistance))
            {
                Debug.Log("Triggered on " + info.name);
                Debug.Log("verticalDistance = " + verticalDistance);
                Debug.Log("horizontalDistance = " + horizontalDistance);
                Debug.Log("actual vs maxSlope = " + (float)Math.Abs(verticalDistance / horizontalDistance) + " vs " + path.m_netInfo.m_maxSlope);
                bool  isTargetVehicleTrackType = false;
                float slopeDist = ((float)Math.Abs(verticalDistance / horizontalDistance)) - path.m_netInfo.m_maxSlope;

                var     pathList      = new List <BuildingInfo.PathInfo>();
                Vector3 targetNode    = Vector3.zero;
                Vector3 otherNode     = Vector3.zero;
                Vector3 adjTargetNode = Vector3.zero;
                Debug.Log("Finding a mate for inx: " + inx + " called: " + info.m_paths[inx].m_netInfo.name);
                for (int i = 0; i < info.m_paths.Length; i++)
                {
                    if (info.m_paths[i]?.m_netInfo?.name == null)
                    {
                        continue;
                    }

                    if (targetNode != Vector3.zero)
                    {
                        break;
                    }

                    isTargetVehicleTrackType = false;
                    switch (vehicletype)
                    {
                    case TrackVehicleType.Train:
                        isTargetVehicleTrackType = info.m_paths[i].m_netInfo.IsTrainTrackAI();
                        break;

                    case TrackVehicleType.Metro:
                        isTargetVehicleTrackType = info.m_paths[i].m_netInfo.IsTrainTrackAIMetro();
                        break;
                    }
                    if (isTargetVehicleTrackType && i != inx)
                    {
                        Debug.Log("info to compare is " + info.m_paths[i].m_netInfo.name);
                        //if (info.m_paths[i].m_netInfo.name.Contains("Ground") ||
                        //    info.m_paths[i].m_netInfo.name == ModTrackNames.TRAIN_TRACK ||
                        //    info.m_paths[i].m_netInfo.name == ModTrackNames.TRAIN_STATION_TRACK_GROUND) ;
                        //{
                        for (int j = 0; j < info.m_paths[i].m_nodes.Length; j++)
                        {
                            var targetIndex = Array.IndexOf(path.m_nodes, info.m_paths[i].m_nodes[j]);
                            if (targetIndex > -1)
                            {
                                otherNode     = path.m_nodes[((targetIndex + 1) % 2)];
                                targetNode    = path.m_nodes[targetIndex];
                                adjTargetNode = otherNode + ((targetNode - otherNode) * (1 + slopeDist));
                                Debug.Log("targetNode/otherNode/adjTargetNode = " + targetNode.ToString() + "/" + otherNode.ToString() + "/" + adjTargetNode.ToString());
                                break;
                            }
                        }
                        //}
                    }
                }

                if (targetNode != Vector3.zero)
                {
                    Debug.Log("In the process of setting targetNode: " + targetNode.ToString() + " to adjTargetNode: " + adjTargetNode);
                    Vector3[] nodeArray = null;
                    var       findCount = 0; //debug stuff
                    for (int i = 0; i < info.m_paths.Length; i++)
                    {
                        isTargetVehicleTrackType = false;
                        switch (vehicletype)
                        {
                        case TrackVehicleType.Train:
                            isTargetVehicleTrackType = info.m_paths[i].m_netInfo.IsTrainTrackAI();
                            //groundName = ModTrackNames.TRAIN_TRACK;
                            break;

                        case TrackVehicleType.Metro:
                            isTargetVehicleTrackType = info.m_paths[i].m_netInfo.IsTrainTrackAIMetro();
                            //groundName = ModTrackNames.MOM_TRACK_GROUND + " NoBar";
                            break;
                        }

                        if (isTargetVehicleTrackType && i != inx)
                        {
                            for (int j = 0; j < info.m_paths[i].m_nodes.Length; j++)
                            {
                                if (info.m_paths[i].m_nodes[j] == targetNode)
                                {
                                    otherNode                = info.m_paths[i].m_nodes[((j + 1) % 2)];
                                    nodeArray                = new Vector3[2];
                                    nodeArray[j]             = adjTargetNode;
                                    nodeArray[((j + 1) % 2)] = otherNode;
                                    info.m_paths[i].m_nodes  = nodeArray;
                                    findCount++;
                                    break;
                                }
                            }
                        }
                    }

                    otherNode = Vector3.zero;
                    nodeArray = null;
                    for (int i = 0; i < path.m_nodes.Length; i++)
                    {
                        if (path.m_nodes[i] == targetNode)
                        {
                            nodeArray                = new Vector3[2];
                            otherNode                = path.m_nodes[((i + 1) % 2)];
                            nodeArray[i]             = adjTargetNode;
                            nodeArray[((i + 1) % 2)] = otherNode;
                            break;
                        }
                    }

                    if (nodeArray != null)
                    {
                        path.m_nodes = nodeArray;
                        Debug.Log("path at inx: " + inx + " has " + findCount + " adjoining path(s) linked at " + targetNode.ToString() + " which was moved to " + adjTargetNode.ToString());
                    }
                }
            }
        }
コード例 #2
0
        public static void SetTrackVehicleType(this BuildingInfo info, int inx, TrackVehicleType vehicleType)
        {
            var path = info.GetPaths()[inx];

            switch (vehicleType)
            {
            case TrackVehicleType.Default:
                if ((path.m_finalNetInfo.IsElevatedSidePlatformTrainStationTrack() || path.m_finalNetInfo.IsGroundSinglePlatformTrainStationTrack()) && (path.m_netInfo.IsElevatedSidePlatformMetroStationTrack() || path.m_netInfo.IsGroundSinglePlatformMetroStationTrack()) ||
                    (path.m_finalNetInfo.IsElevatedSidePlatformMetroStationTrack() || path.m_finalNetInfo.IsGroundSinglePlatformMetroStationTrack()) && (path.m_netInfo.IsElevatedSidePlatformTrainStationTrack() || path.m_netInfo.IsGroundSinglePlatformTrainStationTrack()))
                {
                    InvertPath(path);
                }
                path.AssignNetInfo(path.m_netInfo);
                break;

            case TrackVehicleType.Train:
                if (path.m_finalNetInfo.IsAbovegroundMetroStationTrack())
                {
                    if (path.m_finalNetInfo.IsElevatedSidePlatformMetroStationTrack())
                    {
                        path.AssignNetInfo(ModTrackNames.TRAIN_STATION_TRACK_ELEVA, false);     //somehow expand this for the other types
                    }
                    else if (path.m_finalNetInfo.IsSunkenSidePlatformMetroStationTrack())
                    {
                        path.AssignNetInfo(ModTrackNames.TRAIN_STATION_TRACK_SUNKEN, false);
                    }
                    else if (path.m_finalNetInfo.IsGroundSidePlatformMetroStationTrack())
                    {
                        path.AssignNetInfo(ModTrackNames.TRAIN_STATION_TRACK_GROUND, false);
                    }
                    else if (path.m_finalNetInfo.IsElevatedSinglePlatformMetroStationTrack())
                    {
                        InvertPath(path);
                        path.AssignNetInfo(ModTrackNames.TRAIN_STATION_TRACK_ELEVATED_SMALL, false);
                    }
                    else if (path.m_finalNetInfo.IsGroundSinglePlatformMetroStationTrack())
                    {
                        InvertPath(path);
                        path.AssignNetInfo(ModTrackNames.TRAIN_STATION_TRACK_GROUND_SMALL, false);
                    }
                    else if (path.m_finalNetInfo.IsElevatedIslandPlatformMetroStationTrack())
                    {
                        path.AssignNetInfo(ModTrackNames.TRAIN_STATION_TRACK_ELEVATED_ISLAND, false);
                    }
                    else if (path.m_finalNetInfo.IsGroundIslandPlatformMetroStationTrack())
                    {
                        path.AssignNetInfo(ModTrackNames.TRAIN_STATION_TRACK_GROUND_ISLAND, false);
                    }
                    else if (path.m_finalNetInfo.IsElevatedLargeSidePlatformMetroStationTrack())
                    {
                        path.AssignNetInfo(ModTrackNames.TRAIN_STATION_TRACK_ELEVATED_LARGE, false);
                    }
                    else if (path.m_finalNetInfo.IsGroundLargeSidePlatformMetroStationTrack())
                    {
                        path.AssignNetInfo(ModTrackNames.TRAIN_STATION_TRACK_GROUND_LARGE, false);
                    }
                    else if (path.m_finalNetInfo.IsElevatedDualIslandPlatformMetroStationTrack())
                    {
                        path.AssignNetInfo(ModTrackNames.TRAIN_STATION_TRACK_ELEVATED_LARGE_DUALISLAND, false);
                    }
                    else if (path.m_finalNetInfo.IsGroundDualIslandPlatformMetroStationTrack())
                    {
                        path.AssignNetInfo(ModTrackNames.TRAIN_STATION_TRACK_GROUND_LARGE_DUALISLAND, false);
                    }
                }
                else if (path.m_finalNetInfo.IsMetroTrack())
                {
                    if (path.m_finalNetInfo)
                    {
                        path.AssignNetInfo(ModTrackNames.GetTrackAnalogName(path.m_finalNetInfo.name), false);
                    }
                    //FixSlopes(info, inx, vehicleType);
                }
                break;

            case TrackVehicleType.Metro:
                if (path.m_finalNetInfo.IsAbovegroundTrainStationTrack())
                {
                    if (path.m_finalNetInfo.IsElevatedSidePlatformTrainStationTrack())
                    {
                        path.AssignNetInfo(ModTrackNames.MOM_STATION_TRACK_ELEVATED, false);
                    }
                    else if (path.m_finalNetInfo.IsSunkenSidePlatformTrainStationTrack())
                    {
                        path.AssignNetInfo(ModTrackNames.MOM_STATION_TRACK_SUNKEN, false);
                    }
                    else if (path.m_finalNetInfo.IsGroundSidePlatformTrainStationTrack())
                    {
                        path.AssignNetInfo(ModTrackNames.MOM_STATION_TRACK_GROUND, false);
                    }
                    else if (path.m_finalNetInfo.IsElevatedSinglePlatformTrainStationTrack())
                    {
                        InvertPath(path);
                        path.AssignNetInfo(ModTrackNames.MOM_STATION_TRACK_ELEVATED_SMALL, false);
                    }
                    else if (path.m_finalNetInfo.IsGroundSinglePlatformTrainStationTrack())
                    {
                        InvertPath(path);
                        path.AssignNetInfo(ModTrackNames.MOM_STATION_TRACK_GROUND_SMALL, false);
                    }
                    else if (path.m_finalNetInfo.IsElevatedIslandPlatformTrainStationTrack())
                    {
                        path.AssignNetInfo(ModTrackNames.MOM_STATION_TRACK_ELEVATED_ISLAND, false);
                    }
                    else if (path.m_finalNetInfo.IsGroundIslandPlatformTrainStationTrack())
                    {
                        path.AssignNetInfo(ModTrackNames.MOM_STATION_TRACK_GROUND_ISLAND, false);
                    }
                    else if (path.m_finalNetInfo.IsElevatedLargeSidePlatformTrainStationTrack())
                    {
                        path.AssignNetInfo(ModTrackNames.MOM_STATION_TRACK_ELEVATED_LARGE, false);
                    }
                    else if (path.m_finalNetInfo.IsGroundLargeSidePlatformTrainStationTrack())
                    {
                        path.AssignNetInfo(ModTrackNames.MOM_STATION_TRACK_GROUND_LARGE, false);
                    }
                    else if (path.m_finalNetInfo.IsElevatedDualIslandPlatformTrainStationTrack())
                    {
                        path.AssignNetInfo(ModTrackNames.MOM_STATION_TRACK_ELEVATED_LARGE_DUALISLAND, false);
                    }
                    else if (path.m_finalNetInfo.IsGroundDualIslandPlatformTrainStationTrack())
                    {
                        path.AssignNetInfo(ModTrackNames.MOM_STATION_TRACK_GROUND_LARGE_DUALISLAND, false);
                    }
                }
                else if (path.m_finalNetInfo.IsTrainTrack())
                {
                    path.AssignNetInfo(ModTrackNames.GetTrackAnalogName(path.m_finalNetInfo.name), false);
                    //FixSlopes(info, inx, vehicleType);
                }
                break;
            }
        }