Skip to content

Commit

Permalink
Added Zematus#310
Browse files Browse the repository at this point in the history
New button "Restart World" in the main menu deletes basically everything (I dont know if I am missing something) and the user returns to mode selection. The button cannot be pressed in editor mode. Saving and loading work and the simulation seems to work seemlessly fine after resetting. Had to change UnsetNeighborProminencesFromGroup() in PolityProminence so all groups could be deleted at once
  • Loading branch information
Denormos committed Aug 30, 2023
1 parent d065b12 commit 5324452
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 1 deletion.
Binary file modified Assets/Prefabs/UI/MainMenuDialogPanel.prefab
Binary file not shown.
12 changes: 12 additions & 0 deletions Assets/Scripts/2D/GuiManagerScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1695,6 +1695,18 @@ private void RegenerateWorld(GenerationType type)
_regenMapOverlayTexture = true;
}

public void ResetWorld()
{
Manager.ResetWorld();

MainMenuDialogPanelScript.SetVisible(false);
//AddPopulationDialogScript.SetVisible(true);
_hasToSetInitialPopulation = true;
/* OpenModeSelectionDialogRequested.Invoke();
InterruptSimulation(true); */
OpenModeSelectionDialog();
}

private void GenerateWorld(bool randomSeed = true, int seed = 0, bool useHeightmap = false)
{
if (randomSeed)
Expand Down
5 changes: 5 additions & 0 deletions Assets/Scripts/WorldEngine/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,11 @@ public static void GenerateNewWorldAsync(int seed, Texture2D heightmap = null, P
});
}

public static void ResetWorld()
{
CurrentWorld.ResetWorld();
}

public static void RegenerateWorld(GenerationType type)
{
WorldIsReady = false;
Expand Down
2 changes: 2 additions & 0 deletions Assets/Scripts/WorldEngine/Polities/Polity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ public void Destroy()
World.AddGroupToPostUpdate_AfterPolityUpdate(group);
}

Territory = null;

Info.Polity = null;

StillPresent = false;
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/WorldEngine/Polities/PolityProminence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ private void UnsetNeighborProminencesFromGroup(CellGroup group)
{
foreach (PolityProminence p in group.GetPolityProminences())
{
if (p == this)
if (p == this||!NeighborProminences.Contains(p))
{
continue;
}
Expand Down
80 changes: 80 additions & 0 deletions Assets/Scripts/WorldEngine/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3249,6 +3249,84 @@ public void ModifyCellLayerData(TerrainCell cell, float valueOffset, string laye
Manager.ActiveEditorBrushAction.AddCellAfterModification(cell);
}

public void ResetWorld(){
CurrentDate = 0;
int sizeX = Width;
int sizeY = Height;

List<Territory> _territoriesToRemove = new List<Territory>();

for (int i = 0; i < sizeX; i++)
{
for (int j = 0; j < sizeY; j++)
{
if (TerrainCells[i][j].Group!=null)
{
AddGroupToRemove(TerrainCells[i][j].Group);
}

Territory EncompassingTerritory = TerrainCells[i][j].EncompassingTerritory;

if (EncompassingTerritory != null)
{
if (!_territoriesToRemove.Contains(EncompassingTerritory))
{
_territoriesToRemove.Add(EncompassingTerritory);
}
EncompassingTerritory.SetCellToRemove(TerrainCells[i][j]);
EncompassingTerritory.RemoveCells();
}
}
}

foreach (var t in _territoriesToRemove)
{
t.RemoveCells();
}

RemoveGroups();

//Regions have to be removed after the territories
for (int i = 0; i < sizeX; i++)
{
for (int j = 0; j < sizeY; j++)
{
if (TerrainCells[i][j].Region != null)
{
TerrainCells[i][j].Region = null;
}
}
}

foreach (Polity p in GetActivePolities())
{
AddPolityToRemove(p);
}

RemovePolities();

//Not sure if all of this is necessary or if theres something missing:
_factionsToUpdate.Clear();
_factionsToRemove.Clear();
_politiesToUpdate.Clear();

_languages.Clear();
LanguageCount = 0;
_regionInfos.Clear();
RegionCount = 0;
_polityInfos.Clear();
PolityCount = 0;
_factionInfos.Clear();
FactionCount = 0;

CulturalKnowledgeInfoList.Clear();
_culturalKnowledgeIdList.Clear();
ExistingDiscoveries.Clear();
ExistingDiscoveryIds.Clear();
_eventMessageIds.Clear();
_eventMessagesToShow.Clear();
}

private void GenerateTerrainAltitude()
{
int sizeX = Width;
Expand Down Expand Up @@ -5008,4 +5086,6 @@ private float CalculateTemperature(float value)

return temperature;
}


}
Binary file modified Assets/WorldView.unity
Binary file not shown.
4 changes: 4 additions & 0 deletions random worlds notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ group: The "group" of people inhabiting a cell
culture: A groups skills, knowledge, discoveries, activities and preferences are part of their culture

agents: clan leaders

Polity: state

Territory: Area of a polity

0 comments on commit 5324452

Please sign in to comment.