Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Sub-shapes within Rooms #48

Open
Baaleos opened this issue Nov 18, 2019 · 1 comment
Open

Suggestion: Sub-shapes within Rooms #48

Baaleos opened this issue Nov 18, 2019 · 1 comment

Comments

@Baaleos
Copy link

Baaleos commented Nov 18, 2019

This is a specific idea that would be useful to my game project - but figured it might be re-usable.

In my game I am working on - each room type will have a specific amount of 'slots' where furniture/devices/interact-able objects can go.

At the moment I don't have anything in place to visualise the slots - but I imagine it would be a case of drawing a series of smaller squares inside a room - ideally adjacent to the walls.

The image would then be visualised with a series of grey outlined boxes inside the room shape.
In my game - players could then choose to put objects / devices / technology into those slots.

  • While this specific use case is specific to my game.
    Another person might want this feature so they could create table-top dungeon-esq maps that display traps within the room.

Eg: A player who does not have detect trap - gets the original map - minus the trap outlines, but when they 'detect' the trap - the dungeon master reveals the map that has the traps visible.

@OndrejNepozitek
Copy link
Owner

Hey! Thanks for the suggestion.

If I understand your suggestion correctly, these sub-shapes would not change the outline of the rooms, so they would not change the behaviour of the layouting algorithm. If this is the case, it's probably not a good idea to add these sub-shapes to the algorithm itself because it would slow it down.

It would be probably better to implement this as a postprocessing step on the output of the algorithm. I added (release 1.0.6, master branch) a simple extension method to the IRoom interface that should help you do this. It could be done as follows:

  • Create classic room descriptions for room types
  • Define your slots for each room type e.g. as lists of IntVector2and create a mapping from room types to these lists of slots
  • Run the algorithm, it produces a position and a room shape for each node in the input graph
  • Take the generated layout, go through each room
    • find associated slots
    • the room may have been transformed (e.g. rotated and moved) - so you have to transform all the slots - there is a TransformPointToNewPosition extension method on the IRoom interface and you should use it on all your slots
    • now you have the slot positions of a given room in the final layout

I also implemented an integration test that should demonstrate how it could be done (here):

// Create a rectangular room shape
// Move it away from (0, 0) so that we can properly test the functionality
var rectangleShape = GridPolygon.GetRectangle(10, 4) + new IntVector2(10, 10);

// Create points to be transformed
// These could be for example traps, spawn points, etc.
// We use points of the rectangle here because it is easy to check that the transformation is correct.
var pointsToTransform = rectangleShape.GetPoints();

var mapDescription = new MapDescription<int>();

// Create simple graph with 2 vertices and 1 edge
mapDescription.AddRoom(0);
mapDescription.AddRoom(1);
mapDescription.AddPassage(0, 1);

// Add the rectangle shape
mapDescription.AddRoomShapes(new RoomDescription(rectangleShape, new OverlapMode(1, 0)));

var layoutGenerator = LayoutGeneratorFactory.GetDefaultChainBasedGenerator<int>();
var layout = layoutGenerator.GetLayouts(mapDescription, 1)[0];

foreach (var room in layout.Rooms)
{
    // The points were chosen to be the points of the polygon, so after transforming them, they should
    // be equal to the room.Shape + room.Position points
    var transformedPoints = pointsToTransform.Select(x => room.TransformPointToNewPosition(x));
    var expectedPoints = (room.Shape + room.Position).GetPoints();

    Assert.That(transformedPoints, Is.EquivalentTo(expectedPoints));
}

Is this a solution to your problem/suggestion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants