Exemple #1
0
        private void ChangeLocationType(Location location, LocationTypeChange change)
        {
            string prevName = location.Name;

            location.ChangeType(LocationType.List.Find(lt => lt.Identifier.Equals(change.ChangeToType, StringComparison.OrdinalIgnoreCase)));
            ChangeLocationTypeProjSpecific(location, prevName, change);
            location.ProximityTimer.Remove(change);
            location.TimeSinceLastTypeChange   = 0;
            location.PendingLocationTypeChange = null;
        }
Exemple #2
0
        public void Load(XElement element, bool showNotifications)
        {
            ClearAnimQueue();
            SetLocation(element.GetAttributeInt("currentlocation", 0));

            if (!Version.TryParse(element.GetAttributeString("version", ""), out _))
            {
                DebugConsole.ThrowError("Incompatible map save file, loading the game failed.");
                return;
            }

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "location":
                    string   locationType      = subElement.GetAttributeString("type", "");
                    Location location          = Locations[subElement.GetAttributeInt("i", 0)];
                    int      typeChangeTimer   = subElement.GetAttributeInt("changetimer", 0);
                    int      missionsCompleted = subElement.GetAttributeInt("missionscompleted", 0);

                    string       prevLocationName = location.Name;
                    LocationType prevLocationType = location.Type;
                    location.Discovered = true;
                    location.ChangeType(LocationType.List.Find(lt => lt.Identifier.ToLowerInvariant() == locationType.ToLowerInvariant()));
                    location.TypeChangeTimer   = typeChangeTimer;
                    location.MissionsCompleted = missionsCompleted;
                    if (showNotifications && prevLocationType != location.Type)
                    {
                        var change = prevLocationType.CanChangeTo.Find(c =>
                                                                       c.ChangeToType.ToLowerInvariant() == location.Type.Identifier.ToLowerInvariant());
                        if (change != null)
                        {
                            ChangeLocationType(location, prevLocationName, change);
                        }
                    }
                    break;

                case "connection":
                    int connectionIndex = subElement.GetAttributeInt("i", 0);
                    connections[connectionIndex].Passed = true;
                    break;
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Load the state of an existing map from xml (current state of locations, where the crew is now, etc).
        /// </summary>
        public void LoadState(XElement element, bool showNotifications)
        {
            ClearAnimQueue();
            SetLocation(element.GetAttributeInt("currentlocation", 0));

            if (!Version.TryParse(element.GetAttributeString("version", ""), out _))
            {
                DebugConsole.ThrowError("Incompatible map save file, loading the game failed.");
                return;
            }

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "location":
                    Location location = Locations[subElement.GetAttributeInt("i", 0)];
                    location.ProximityTimer.Clear();
                    for (int i = 0; i < location.Type.CanChangeTo.Count; i++)
                    {
                        location.ProximityTimer.Add(location.Type.CanChangeTo[i], subElement.GetAttributeInt("changetimer" + i, 0));
                    }
                    int locationTypeChangeIndex = subElement.GetAttributeInt("pendinglocationtypechange", -1);
                    if (locationTypeChangeIndex > 0 && locationTypeChangeIndex < location.Type.CanChangeTo.Count - 1)
                    {
                        location.PendingLocationTypeChange = new Pair <LocationTypeChange, int>(
                            location.Type.CanChangeTo[locationTypeChangeIndex],
                            subElement.GetAttributeInt("pendinglocationtypechangetimer", 0));
                    }
                    location.TimeSinceLastTypeChange = subElement.GetAttributeInt("timesincelasttypechange", 0);
                    location.Discovered = subElement.GetAttributeBool("discovered", false);
                    if (location.Discovered)
                    {
#if CLIENT
                        RemoveFogOfWar(location);
#endif
                        if (furthestDiscoveredLocation == null || location.MapPosition.X > furthestDiscoveredLocation.MapPosition.X)
                        {
                            furthestDiscoveredLocation = location;
                        }
                    }

                    string       locationType     = subElement.GetAttributeString("type", "");
                    string       prevLocationName = location.Name;
                    LocationType prevLocationType = location.Type;
                    LocationType newLocationType  = LocationType.List.Find(lt => lt.Identifier.Equals(locationType, StringComparison.OrdinalIgnoreCase)) ?? LocationType.List.First();
                    location.ChangeType(newLocationType);
                    if (showNotifications && prevLocationType != location.Type)
                    {
                        var change = prevLocationType.CanChangeTo.Find(c => c.ChangeToType.Equals(location.Type.Identifier, StringComparison.OrdinalIgnoreCase));
                        if (change != null)
                        {
                            ChangeLocationTypeProjSpecific(location, prevLocationName, change);
                            location.TimeSinceLastTypeChange = 0;
                        }
                    }

                    location.LoadStore(subElement);
                    location.LoadMissions(subElement);

                    break;

                case "connection":
                    int connectionIndex = subElement.GetAttributeInt("i", 0);
                    Connections[connectionIndex].Passed = subElement.GetAttributeBool("passed", false);
                    break;
                }
            }

            foreach (Location location in Locations)
            {
                location?.InstantiateLoadedMissions(this);
            }

            int currentLocationConnection = element.GetAttributeInt("currentlocationconnection", -1);
            if (currentLocationConnection >= 0)
            {
                SelectLocation(Connections[currentLocationConnection].OtherLocation(CurrentLocation));
            }
            else
            {
                //this should not be possible, you can't enter non-outpost locations (= natural formations)
                if (CurrentLocation != null && !CurrentLocation.Type.HasOutpost && SelectedConnection == null)
                {
                    DebugConsole.AddWarning($"Error while loading campaign map state. Submarine in a location with no outpost ({CurrentLocation.Name}). Loading the first adjacent connection...");
                    SelectLocation(CurrentLocation.Connections[0].OtherLocation(CurrentLocation));
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Load the state of an existing map from xml (current state of locations, where the crew is now, etc).
        /// </summary>
        public void LoadState(XElement element, bool showNotifications)
        {
            ClearAnimQueue();
            SetLocation(element.GetAttributeInt("currentlocation", 0));

            if (!Version.TryParse(element.GetAttributeString("version", ""), out _))
            {
                DebugConsole.ThrowError("Incompatible map save file, loading the game failed.");
                return;
            }

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "location":
                    Location location = Locations[subElement.GetAttributeInt("i", 0)];

                    location.TypeChangeTimer = subElement.GetAttributeInt("changetimer", 0);
                    location.Discovered      = subElement.GetAttributeBool("discovered", false);
                    if (location.Discovered)
                    {
#if CLIENT
                        RemoveFogOfWar(StartLocation);
#endif
                        if (furthestDiscoveredLocation == null || location.MapPosition.X > furthestDiscoveredLocation.MapPosition.X)
                        {
                            furthestDiscoveredLocation = location;
                        }
                    }


                    string       locationType     = subElement.GetAttributeString("type", "");
                    string       prevLocationName = location.Name;
                    LocationType prevLocationType = location.Type;
                    LocationType newLocationType  = LocationType.List.Find(lt => lt.Identifier.Equals(locationType, StringComparison.OrdinalIgnoreCase)) ?? LocationType.List.First();
                    location.ChangeType(newLocationType);
                    if (showNotifications && prevLocationType != location.Type)
                    {
                        var change = prevLocationType.CanChangeTo.Find(c => c.ChangeToType.Equals(location.Type.Identifier, StringComparison.OrdinalIgnoreCase));
                        if (change != null)
                        {
                            ChangeLocationType(location, prevLocationName, change);
                        }
                    }
                    location.LoadMissions(subElement);
                    break;

                case "connection":
                    int connectionIndex = subElement.GetAttributeInt("i", 0);
                    Connections[connectionIndex].Passed = subElement.GetAttributeBool("passed", false);
                    break;
                }
            }

            foreach (Location location in Locations)
            {
                location?.InstantiateLoadedMissions(this);
            }

            int currentLocationConnection = element.GetAttributeInt("currentlocationconnection", -1);
            if (currentLocationConnection >= 0)
            {
                SelectLocation(Connections[currentLocationConnection].OtherLocation(CurrentLocation));
            }
        }