(ef1d7a5a2) Campaign fix: clear missions from locations that change their type, and all adjacent locations. Caused missions to still be available when they logically shouldn't be (e.g. a transport mission from an uninhabited location to another) and syncing issues in multiplayer.

This commit is contained in:
Joonas Rikkonen
2019-03-25 19:52:08 +02:00
parent d98f0efd66
commit 7c9d0aac03
6 changed files with 19 additions and 25 deletions
@@ -962,8 +962,6 @@ namespace Barotrauma
} }
} }
} }
element.Value = lines[i];
i++;
} }
}, isCheat: false)); }, isCheat: false));
#endif #endif
@@ -332,8 +332,7 @@ namespace Barotrauma.Networking
} }
} }
//too many events for one packet if (client.NeedsMidRoundSync)
if (eventsToSync.Count > 200)
{ {
msg.Write((byte)ServerNetObject.ENTITY_EVENT_INITIAL); msg.Write((byte)ServerNetObject.ENTITY_EVENT_INITIAL);
msg.Write(client.UnreceivedEntityEventCount); msg.Write(client.UnreceivedEntityEventCount);
@@ -341,8 +340,7 @@ namespace Barotrauma.Networking
Write(msg, eventsToSync, out sentEvents, client); Write(msg, eventsToSync, out sentEvents, client);
} }
else
foreach (NetEntityEvent entityEvent in sentEvents)
{ {
msg.Write((byte)ServerNetObject.ENTITY_EVENT); msg.Write((byte)ServerNetObject.ENTITY_EVENT);
Write(msg, eventsToSync, out sentEvents, client); Write(msg, eventsToSync, out sentEvents, client);
@@ -353,7 +351,6 @@ namespace Barotrauma.Networking
(entityEvent as ServerEntityEvent).Sent = true; (entityEvent as ServerEntityEvent).Sent = true;
client.EntityEventLastSent[entityEvent.ID] = NetTime.Now; client.EntityEventLastSent[entityEvent.ID] = NetTime.Now;
} }
sentEvents = eventsToSync;
} }
/// <summary> /// <summary>
@@ -806,7 +806,6 @@ namespace Barotrauma
if (closestBody.UserData is Structure wall && wall.Submarine != null) if (closestBody.UserData is Structure wall && wall.Submarine != null)
{ {
int sectionIndex = wall.FindSectionIndex(ConvertUnits.ToDisplayUnits(Submarine.LastPickedPosition)); int sectionIndex = wall.FindSectionIndex(ConvertUnits.ToDisplayUnits(Submarine.LastPickedPosition));
int passableHoleCount = GetMinimumPassableHoleCount();
float sectionDamage = wall.SectionDamage(sectionIndex); float sectionDamage = wall.SectionDamage(sectionIndex);
for (int i = sectionIndex - 2; i <= sectionIndex + 2; i++) for (int i = sectionIndex - 2; i <= sectionIndex + 2; i++)
@@ -1127,7 +1126,7 @@ namespace Barotrauma
valueModifier = isOutdoor ? 1 : 0; valueModifier = isOutdoor ? 1 : 0;
valueModifier *= isOpen ? 5 : 1; valueModifier *= isOpen ? 5 : 1;
} }
for (int i = 0; i < s.Sections.Length; i++) else
{ {
valueModifier = isOutdoor ? 0 : 1; valueModifier = isOutdoor ? 0 : 1;
valueModifier *= isOpen ? 0 : 1; valueModifier *= isOpen ? 0 : 1;
@@ -103,12 +103,6 @@ namespace Barotrauma
if (missionType == MissionType.Random) if (missionType == MissionType.Random)
{ {
allowedMissions.AddRange(MissionPrefab.List); allowedMissions.AddRange(MissionPrefab.List);
#if SERVER
if (GameMain.Server != null)
{
allowedMissions.RemoveAll(mission => !GameMain.Server.ServerSettings.AllowedRandomMissionTypes.Contains(mission.type));
}
#endif
} }
else if (missionType == MissionType.None) else if (missionType == MissionType.None)
{ {
@@ -125,8 +119,8 @@ namespace Barotrauma
allowedMissions.RemoveAll(m => !m.IsAllowed(locations[0], locations[1])); allowedMissions.RemoveAll(m => !m.IsAllowed(locations[0], locations[1]));
} }
float probabilitySum = allowedMissions.Sum(m => m.Commonness); int probabilitySum = allowedMissions.Sum(m => m.Commonness);
float randomNumber = (float)rand.NextDouble() * probabilitySum; int randomNumber = rand.NextInt32() % probabilitySum;
foreach (MissionPrefab missionPrefab in allowedMissions) foreach (MissionPrefab missionPrefab in allowedMissions)
{ {
if (randomNumber <= missionPrefab.Commonness) if (randomNumber <= missionPrefab.Commonness)
@@ -1286,11 +1286,7 @@ namespace Barotrauma
LastSentSignalRecipients.Clear(); LastSentSignalRecipients.Clear();
if (connections == null) return; if (connections == null) return;
public List<T> GetConnectedComponentsRecursive<T>(Connection c) where T : ItemComponent stepsTaken++;
{
List<T> connectedComponents = new List<T>();
List<Item> alreadySearched = new List<Item>() { this };
GetConnectedComponentsRecursive(c, alreadySearched, connectedComponents);
if (!connections.TryGetValue(connectionName, out Connection c)) return; if (!connections.TryGetValue(connectionName, out Connection c)) return;
@@ -33,7 +33,7 @@ namespace Barotrauma
get get
{ {
CheckMissionCompleted(); CheckMissionCompleted();
for (int i = availableMissions.Count; i < Connections.Count * 2; i++) for (int i = availableMissions.Count; i < Connections.Count * 2; i++)
{ {
int seed = (ToolBox.StringToInt(BaseName) + MissionsCompleted * 10 + i) % int.MaxValue; int seed = (ToolBox.StringToInt(BaseName) + MissionsCompleted * 10 + i) % int.MaxValue;
@@ -47,7 +47,7 @@ namespace Barotrauma
if (availableMissions.Any(m => m.Prefab == mission.Prefab)) { continue; } if (availableMissions.Any(m => m.Prefab == mission.Prefab)) { continue; }
if (GameSettings.VerboseLogging && mission != null) if (GameSettings.VerboseLogging && mission != null)
{ {
DebugConsole.NewMessage("Generated a new mission for a location connection (seed: " + seed.ToString("X") + ", type: " + mission.Name + ")", Color.White); DebugConsole.NewMessage("Generated a new mission for a location (location: " + Name + ", seed: " + seed.ToString("X") + ", missions completed: " + MissionsCompleted + ", type: " + mission.Name + ")", Color.White);
} }
availableMissions.Add(mission); availableMissions.Add(mission);
} }
@@ -100,7 +100,16 @@ namespace Barotrauma
public void ChangeType(LocationType newType) public void ChangeType(LocationType newType)
{ {
if (newType == Type) return; if (newType == Type) { return; }
//clear missions from this and adjacent locations (they may be invalid now)
availableMissions.Clear();
foreach (LocationConnection connection in Connections)
{
connection.OtherLocation(this)?.availableMissions.Clear();
}
DebugConsole.Log("Location " + baseName + " changed it's type from " + Type + " to " + newType);
Type = newType; Type = newType;
Name = Type.NameFormats[nameFormatIndex % Type.NameFormats.Count].Replace("[name]", baseName); Name = Type.NameFormats[nameFormatIndex % Type.NameFormats.Count].Replace("[name]", baseName);
@@ -112,6 +121,7 @@ namespace Barotrauma
{ {
if (mission.Completed) if (mission.Completed)
{ {
DebugConsole.Log("Mission \"" + mission.Name + "\" completed in \"" + Name + "\".");
MissionsCompleted++; MissionsCompleted++;
} }
} }