Skip to content

Commit

Permalink
merged changes from OuadII
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszkot committed Jan 27, 2024
1 parent 17b1106 commit 65f5888
Show file tree
Hide file tree
Showing 201 changed files with 8,306 additions and 3,189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ public DungeonPresenter(IDrawingEngine drawingEngine, int left = 0, int top = 0)
this.left = left;
drawingEngine.CursorVisible = false;
}


public void Print(Tile tile, PrintInfo pi)
{
var color = ConsoleColor.White;
var symbol = ' ';
if (tile != null)
{
if (pi.CustomDrawer != null)
{
pi.CustomDrawer(tile, drawingEngine);
return;
}
color = tile.Color;
if (pi.PrintNodeIndexes)
{
Expand All @@ -35,6 +41,10 @@ public void Print(Tile tile, PrintInfo pi)
if (tile.Revealed)
{
symbol = tile.Symbol;
if (pi.SymbolToDraw!=null)
{
symbol = pi.SymbolToDraw(tile);
}
}
}
drawingEngine.ForegroundColor = color;
Expand Down
11 changes: 8 additions & 3 deletions Assets/Scripts/Common/Dlls/Dungeons/ASCIIDisplay/Screen.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Dungeons.ASCIIDisplay.Presenters;
using Dungeons.TileContainers;
using Dungeons.Tiles;
using System;
using System.Collections.Generic;
using System.Linq;

Expand All @@ -16,7 +17,11 @@ public class Screen
public int DungeonY { get; set; }

public DungeonPresenter DungeonPresenter { get; set; }
public PrintInfo PrintInfo { get => printInfo; set => printInfo = value; }
public PrintInfo PrintInfo
{
get => printInfo;
set => printInfo = value;
}
public Dictionary<string, ListPresenter> Lists { get => lists; set => lists = value; }
public List<Item> ASCIIItems = new List<Item>();

Expand Down Expand Up @@ -57,7 +62,7 @@ private void RedrawTiles<T>(List<T> tiles) where T : Tile
protected virtual void CreateLists()
{
Lists = new Dictionary<string, ListPresenter>();
var usage = new ListPresenter(UsageListName, OriginX+55, OriginY, 30);
var usage = new ListPresenter(UsageListName, OriginX+75, OriginY, 30);
var list = new List<ListItem>();
list.Add(new ListItem("R - reload"));
list.Add(new ListItem("D - toggle node_indexes/symbols"));
Expand Down Expand Up @@ -104,7 +109,7 @@ public virtual void Redraw(DungeonNode dungeon)
DungeonPresenter.Redraw(dungeon, PrintInfo);
DrawingEngine.SetCursorPosition(0, 0);
}

private void RedrawItems()
{
ASCIIItems.ForEach(i =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System;
using System.Linq;
using System.Reflection;
#pragma warning disable 8603
#pragma warning disable 8602

namespace Dungeons.Core
{
Expand Down
3 changes: 2 additions & 1 deletion Assets/Scripts/Common/Dlls/Dungeons/Core/RandHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;

#pragma warning disable 8603
#pragma warning disable 8602

namespace Dungeons.Core
{
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Common/Dlls/Dungeons/CorridorNodeLayouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ private void CreateSecretRoom(DungeonNode level, List<DungeonNode> mazeNodes, ID
var node = dungeonGenerator.CreateDungeonNodeInstance();
node.Secret = true;

var he = 9;
var wi = 9;
var he = 8;
var wi = 8;

var entr = RandHelper.GetRandomDouble() > 0.5f ? EntranceSide.Bottom : EntranceSide.Top;

Expand Down
1 change: 0 additions & 1 deletion Assets/Scripts/Common/Dlls/Dungeons/DefaultNodeLayouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ protected virtual void LayoutNodes(DungeonNode level, List<DungeonNode> mazeNode
if (!currentNode.Secret)
lastNonSecretNode = currentNode;


bool shallBreak = currentNodeIndex == mazeNodes.Count - 1;
AppendNodeInfo infoNext = new AppendNodeInfo();

Expand Down
34 changes: 30 additions & 4 deletions Assets/Scripts/Common/Dlls/Dungeons/DungeonGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected virtual DungeonNode CreateNode(int w, int h, GenerationInfo gi, int no
DungeonNode dungeon = CreateDungeonNodeInstance();

dungeon.ChildIslandCreated += Dungeon_ChildIslandCreated;

Check warning on line 106 in Assets/Scripts/Common/Dlls/Dungeons/DungeonGenerator.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Nullability of reference types in type of parameter 'sender' of 'void DungeonGenerator.Dungeon_ChildIslandCreated(object sender, ChildIslandCreationInfo e)' doesn't match the target delegate 'EventHandler<ChildIslandCreationInfo>' (possibly because of nullability attributes).
if (dungeonLayouterKind == DungeonLayouterKind.Corridor && nodeIndex == (int)RoomPlacement.Center)
if (dungeonLayouterKind == Dungeons.DungeonLayouterKind.Corridor && nodeIndex == (int)RoomPlacement.Center)
{
w = GenerationInfo.MaxRoomSideSize;
h = GenerationInfo.MaxRoomSideSize;
Expand Down Expand Up @@ -150,7 +150,7 @@ protected virtual List<DungeonNode> CreateDungeonNodes(GenerationInfo info = nul

if (!this.info.PreventSecretRoomGeneration)
{
if (this.dungeonLayouterKind == DungeonLayouterKind.Default)
if (this.dungeonLayouterKind == Dungeons.DungeonLayouterKind.Default)
{
if (this.info.SecretRoomIndex >= 0)
secretRoomIndex = this.info.SecretRoomIndex;
Expand Down Expand Up @@ -232,12 +232,38 @@ public virtual DungeonLevel Generate(int levelIndex, GenerationInfo info = null,
return level;
}

static List<DungeonLayouterKind> everDungeonLayouterKinds = new List<DungeonLayouterKind>();
static DungeonLayouterKind recentDungeonLayouterKind;

protected virtual DungeonLayouterKind CalcLayouterKind()
{
DungeonLayouterKind lk;

lk = GenerateDungeonLayouterKind();
if (lk == recentDungeonLayouterKind)//help luck
{
lk = GenerateDungeonLayouterKind();
}
if (everDungeonLayouterKinds.Count == 1 && lk == everDungeonLayouterKinds[0])
{
lk = lk == DungeonLayouterKind.Corridor ? DungeonLayouterKind.Default : DungeonLayouterKind.Corridor;
}

if (!everDungeonLayouterKinds.Contains(lk))
everDungeonLayouterKinds.Add(lk);

recentDungeonLayouterKind = lk;
return lk;
}

static DungeonLayouterKind GenerateDungeonLayouterKind()
{
DungeonLayouterKind lk;
if (RandHelper.GetRandomDouble() > 0.5f)
return DungeonLayouterKind.Corridor;
lk = DungeonLayouterKind.Corridor;
else
return DungeonLayouterKind.Default;
lk = DungeonLayouterKind.Default;
return lk;
}

protected virtual void CreateDynamicTiles(List<Dungeons.TileContainers.DungeonNode> mazeNodes)
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Common/Dlls/Dungeons/Dungeons.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NoWarn>1701;1702;8604;8629;8602;8618;8625;8600;8601;8603;8622;8765</NoWarn>
<NoWarn>1701;1702;8604;8629;8602;8618;8625;8600;8601</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<NoWarn>1701;1702;8604;8629;8602;8618;8625;8600;8601;8603;8622;8765</NoWarn>
<NoWarn>1701;1702;8604;8629;8602;8618;8625;8600;8601</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions Assets/Scripts/Common/Dlls/Dungeons/GenerationInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Drawing;
#pragma warning disable 8603
#pragma warning disable 8602

namespace Dungeons
{
Expand All @@ -20,7 +21,7 @@ public class GenerationInfo : ICloneable
public bool GenerateDecorations { get; set; } = true;
public bool GenerateInterior { get; set; } = true;

public DungeonLayouterKind ForcedDungeonLayouterKind { get; set; }//= DungeonLayouterKind.Default;
public DungeonLayouterKind ForcedDungeonLayouterKind { get; set; }// = DungeonLayouterKind.Corridor;
/// <summary>
/// Normally true, can be set to false for issue testing purposes
/// </summary>
Expand All @@ -42,7 +43,7 @@ public class GenerationInfo : ICloneable

public bool FirstNodeSmaller = false;
public const int MinRoomSideSize = 16;//14 is too small - child island would not be created!
public const int MaxRoomSideSize = 20;
public const int MaxRoomSideSize = 24;
public Size MinNodeSize = new Size(MinRoomSideSize, MinRoomSideSize);
public Size MaxNodeSize = new Size(MaxRoomSideSize, MaxRoomSideSize);
public Size ForcedChilldIslandSize = new Size(0, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public void SetSideWalls()

if (sideCounter < 3)
{
dungeonNode.Container.GetInstance<ILogger>().LogError("sideCounter < 3 = "+ sideCounter + " side: " + side.Key + " NodeInd: "+ dungeonNode);
//dungeonNode.Container.GetInstance<ILogger>().LogError("sideCounter < 3 = "+ sideCounter + " side: " + side.Key + " NodeInd: "+ dungeonNode);
}
}
}
Expand Down
63 changes: 41 additions & 22 deletions Assets/Scripts/Common/Dlls/Dungeons/TileContainers/DungeonNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
using System.Drawing;
using System.Linq;
using System.Xml.Serialization;
using Dungeons.ASCIIDisplay;


#pragma warning disable 8603
namespace Dungeons
{
Expand All @@ -31,6 +34,9 @@ public class PrintInfo
public bool PrintNodeIndexes = false;
public int OriginX { get; set; }
public int OriginY { get; set; }

public Func<Tile, char> SymbolToDraw;
public Action<Tile, IDrawingEngine > CustomDrawer;
}


Expand Down Expand Up @@ -188,6 +194,21 @@ public bool GetHiddenTilesAlreadyAdded(string key)
return hiddenTilesAlreadyAdded[key];
}

protected virtual bool ShallEnsureCorrectY(Dungeons.Tiles.Tile tile)
{
return false;
}

public Dungeons.Tiles.Tile EnsureCorrectY(Dungeons.Tiles.Tile tile)
{
var maxY = Height - 1;
if (tile.point.Y >= maxY)
{
tile = GetEmptyTiles().Where(i => i.point.Y < maxY).ToList().FirstOrDefault();
}

return tile;
}
public void SetAlreadyAdded(string key, bool alreadyAdded)
{
hiddenTilesAlreadyAdded[key] = alreadyAdded;
Expand Down Expand Up @@ -267,26 +288,14 @@ internal List<IDoor> GenerateLayoutDoors(EntranceSide side, int nextNodeIndex, b
List<Wall> wall = sides[side];
if (secret)
{
var count = sides[side].Count;
var diff = GenerationInfo.MaxRoomSideSize - GenerationInfo.MinRoomSideSize;
int counter = 0;
bool added = false;
while (counter < 100)
{
counter++;
var index = Enumerable.Range(diff, (count - diff*2)-2).ToList().GetRandomElem();
//var allowed = AreDoorAllowedToPutOn(wall[index]);
//if (!allowed)
//{
// continue;
//}
var door = CreateDoor(wall[index], side) as IDoor;
door.Secret = true;
res.Add(door);
added = true;
break;
}
DebugHelper.Assert(added);
var wallSize = sides[side].Count;
var index = wallSize / 2;
var moveBy = (int)RandHelper.GetRandomFloatInRange(0,4);
index += moveBy * RandHelper.GetRandomFloat() > 0.5f ? 1 : -1;
var door = CreateDoor(wall[index], side) as IDoor;
door.Secret = true;
res.Add(door);

return res;
}

Expand Down Expand Up @@ -470,6 +479,8 @@ public void SetTilesNodeIndex()

public Tile GetNeighborTile(Tile tile, TileNeighborhood neighborhood)
{
if(tile == null)
return null;
var pt = GetNeighborPoint(tile, neighborhood);
return GetTile(pt);
}
Expand Down Expand Up @@ -549,7 +560,8 @@ public virtual List<Tile> GetEmptyTiles
return emptyTiles;
}

public Tile GetRandomEmptyTile(EmptyCheckContext emptyCheckContext, GenerationConstraints constraints = null, bool canBeNextToDoors = true, int? nodeIndex = null)
public Tile GetRandomEmptyTile(EmptyCheckContext emptyCheckContext, GenerationConstraints constraints = null,
bool canBeNextToDoors = true, int? nodeIndex = null)
{
var emptyTiles = GetEmptyTiles(constraints, canBeNextToDoors, emptyCheckContext : emptyCheckContext);

Expand Down Expand Up @@ -1047,7 +1059,7 @@ bool AreDoorAllowedToPutOn(Tile tile)
return true;

var neibs = GetNeighborTiles(tile);
var forbid = neibs.Where(i => i is Wall).Count() >= 3 || neibs.Where(i => i == null).Any();
var forbid = neibs.Count < 4 || neibs.Where(i => i is Wall).Count() >= 3 || neibs.Where(i => i == null).Any();
return !forbid;
}

Expand Down Expand Up @@ -1322,11 +1334,18 @@ public virtual List<Tile> GetAllTiles()
#nullable enable
public virtual Tile? SetTileAtRandomPosition(Tile tile, bool matchNodeIndex = true, EmptyCheckContext emptyCheckContext = EmptyCheckContext.Unset)
{

var node = matchNodeIndex == true ? (int?)NodeIndex : null;
var empty = this.GetRandomEmptyTile(emptyCheckContext, nodeIndex: node);

if (empty == null)
return null;

if (ShallEnsureCorrectY(tile))
{
empty = EnsureCorrectY(empty);
}

var set = SetTile(tile, empty.point);

return set ? tile : null;
Expand Down
Loading

0 comments on commit 65f5888

Please sign in to comment.