Skip to content

Commit

Permalink
Merge pull request #75 from Fenyx4/mountains
Browse files Browse the repository at this point in the history
Mountains, rivers and forests oh my
  • Loading branch information
Fenyx4 authored Mar 14, 2021
2 parents c7f709e + fa5e7c2 commit 686e990
Show file tree
Hide file tree
Showing 15 changed files with 1,153 additions and 306 deletions.
1 change: 1 addition & 0 deletions U4DosRandomizer/IWorldMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public interface IWorldMap
void Load(string path, int v, Random random1, Random random2);
void Randomize(UltimaData ultimaData, Random random1, Random random2);
SixLabors.ImageSharp.Image ToImage();
SixLabors.ImageSharp.Image ToHeightMapImage();

public void Save(string path);

Expand Down
40 changes: 8 additions & 32 deletions U4DosRandomizer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,12 @@ private static void Randomize(int seed, string path, Flags flags)

IWorldMap worldMap = null;

//WorldMapGenerateMap.PrintWorldMapInfo(path);

if (flags.Overworld == 5)
{
worldMap = new WorldMapGenerateMap(spoilerLog);

}
else if (flags.Overworld == 1)
{
Expand Down Expand Up @@ -413,6 +416,11 @@ private static void Randomize(int seed, string path, Flags flags)
{
var image = worldMap.ToImage();
image.SaveAsPng($"worldMap-{seed}.png");
//image = worldMap.ToHeightMapImage();
//if (image != null)
//{
// image.SaveAsPng($"worldMap-hm-{seed}.png");
//}
}

spoilerWriter.Close();
Expand Down Expand Up @@ -490,38 +498,6 @@ private static void LogQuestItems(SpoilerLog spoilerLog, UltimaData ultimaData)

}

private static void PrintWorldMapInfo()
{
var world = new byte[256 * 256];
using (FileStream stream = new FileStream("ULT\\WORLD.MAP", FileMode.Open))
{
stream.Read(world, 0, 256 * 256);
}
var worldList = world.ToList();

worldList.Sort();

var worldTileCount = new Dictionary<byte, int>();
for (int i = 0; i < worldList.Count(); i++)
{
if (worldTileCount.ContainsKey(worldList[i]))
{
worldTileCount[worldList[i]] = worldTileCount[worldList[i]] + 1;
}
else
{
worldTileCount[worldList[i]] = 1;
}
}

foreach (var key in worldTileCount.Keys)
{
//var output = $"{shapes[key]}:".PadRight(31) + $" {worldTileCount[key]/(256.0*256.0)}";
var output = $"{{{key},{worldTileCount[key] / (256.0 * 256.0)}}}";
Console.WriteLine(output);
}
}

static public double Linear(double x, double x0, double x1, double y0, double y1)
{
if ((x1 - x0) == 0)
Expand Down
79 changes: 77 additions & 2 deletions U4DosRandomizer/River.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,82 @@ namespace U4DosRandomizer
{
public class River
{
public List<ITile> Path { get; internal set; }
public int Head { get; internal set; }
public RiverNode Tree { get; internal set; }
public Tuple<int, int> Direction { get; internal set; }

// Prints the n-ary tree level wise
public void LevelOrderTraversal(Action<RiverNode> actionOnNode)
{
if (Tree == null)
return;

// Standard level order traversal code
// using queue
Queue<RiverNode> q = new Queue<RiverNode>(); // Create a queue
q.Enqueue(Tree); // Enqueue root
while (q.Count != 0)
{
int n = q.Count;

// If this node has children
while (n > 0)
{
// Dequeue an item from queue
// and print it
RiverNode p = q.Peek();
q.Dequeue();
actionOnNode(p);

// Enqueue all children of
// the dequeued item
for (int i = 0; i < p.Children.Count; i++)
q.Enqueue(p.Children[i]);
n--;
}
}
}

public int AddBridges(WorldMapGenerateMap map, int minDepth, int maxDepth)
{
int bridgeCount = 0;
if (Tree == null)
{
return bridgeCount;
}

bridgeCount += AddBridges(Tree, map, minDepth, maxDepth);

return bridgeCount;
}

private int AddBridges(RiverNode node, WorldMapGenerateMap map, int minDepth, int maxDepth)
{
int bridgeCount = 0;
// Dont add it we aren't on shallow water (rare case of sailable river) or we are at the end of the river
if (node.Coordinate.GetTile() != TileInfo.Shallow_Water || node.Children.Count == 0)
{
return bridgeCount;
}

//if(node.depth > minDepth)
//{
// return bridgeCount;
//}

if (node.depth > minDepth && WorldMapGenerateMap.IsWalkableGround(map.GetCoordinate(node.Coordinate.X - 1, node.Coordinate.Y)) && WorldMapGenerateMap.IsWalkableGround(map.GetCoordinate(node.Coordinate.X + 1, node.Coordinate.Y)))
{
node.Coordinate.SetTile(TileInfo.Bridge);
bridgeCount++;
}
else
{
foreach (var child in node.Children)
{
bridgeCount += AddBridges(child, map, minDepth, maxDepth);
}
}

return bridgeCount;
}
}
}
14 changes: 14 additions & 0 deletions U4DosRandomizer/RiverNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace U4DosRandomizer
{
public class RiverNode
{
public ITile Coordinate { get; set; }
public RiverNode Parent { get; set; }
public List<RiverNode> Children { get; set; }
public int depth { get; set; }
}
}
Loading

0 comments on commit 686e990

Please sign in to comment.