Git Product home page Git Product logo

Comments (3)

stwe avatar stwe commented on August 17, 2024

The behavior is the expected behavior based on the current implementation - so no bug. However, I have to admit that it could be better and is not optimal. Maybe it's not comfortable. Let me explain how this is implemented.

In the example map in rotation DEG0 we have the following initial situation:

c = coast
b = bakery
f = fishing hut

     0   1   2   3   4   5   6   7
   ---------------------------------
0  | c | c | c | c | c | c | c | c |
   ---------------------------------
1  | c |   |   |   |   |   |   | c |
   ---------------------------------
2  | c |   |   |   |   | b | b | c |
   ---------------------------------
3  | c |   |   |   |   | b | b | c |
   ---------------------------------
4  | c |   |   |   |   |   |   | c |
   ---------------------------------
5  | c |   |   |   |   |   |   | c |
   ---------------------------------
6  | c |   |   |   |   |   |   | c |
   ---------------------------------
7  | c |   |   |   |   |   |   | c |
   ---------------------------------
8  | c |   |   |   |   |   |   | c |
   ---------------------------------
9  | c |   |   |   |   |   |   | c |
   ---------------------------------
10 | c |   |   |   |   |   |   | c |
   ---------------------------------
11 | c | f | c | c | c | c | c | c |
   ---------------------------------

Now, if we want to put a 2x2 sized building (for example) on the map, we have to keep in mind:

  • do not build on the coast or off the map
  • do not "overwrite" the existing buildings

There are, of course, buildings that have other peculiarities. But that's not the topic for now.

A 2x2 building has its own coordinate system xy in the range 0 to 1. In the example above it looks like this:

     0            1         2         3         4         5        6         7
   --------------------------------------------------------------------------------
0  |    c    |    c    |    c    |    c    |    c    |    c   |    c    |    c    |
   --------------------------------------------------------------------------------
1  |    c    |         |         |         |         |        |         |    c    |
   --------------------------------------------------------------------------------
2  |    c    |         |         |         |         | (0, 0) | (1, 0)  |    c    |
   --------------------------------------------------------------------------------
3  |    c    |         |         |         |         | (0, 1) | (1, 1)  |    c    |
   --------------------------------------------------------------------------------
4  |    c    |         |         |         |         |        |         |    c    |
   --------------------------------------------------------------------------------

// ...

Bakery:
World Space (5, 2) - Object Space (0, 0)
World Space (6, 2) - Object Space (1, 0)
World Space (5, 3) - Object Space (0, 1)
World Space (6, 3) - Object Space (1, 1)

If you now click anywhere in the world with the mouse, this is the starting position for checking whether the building can be built. For this, each position of the object space is added to the starting position of the world.

https://github.com/stwe/MDCII/blob/main/src/world/World.cpp#L714
https://github.com/stwe/MDCII/blob/main/src/world/World.cpp#L736
https://github.com/stwe/MDCII/blob/main/src/world/World.cpp#L419

for (auto y{ 0 }; y < t_building.size.h; ++y)
{
    for (auto x{ 0 }; x < t_building.size.w; ++x)
    {
        auto rp{ world::rotate_position(x, y, t_building.size.h, t_building.size.w, t_buildingRotation) };
        if (t_buildingRotation == world::Rotation::DEG0 || t_buildingRotation == world::Rotation::DEG180)
        {
            rp = world::rotate_position(x, y, t_building.size.w, t_building.size.h, t_buildingRotation);
        }

        if (!IsPositionInWorld(t_x + rp.x, t_y + rp.y))
        {
            return true;
        }
    }
}

The strange behavior mentioned here can result from the fact that the object space is always iterated at (0, 0) -> (1,1). If the building cannot be built like this, we should perhaps iterate through the loop differently. If that doesn't work either, return false.

Back to the example above. In the following map all positions are marked with an "x", from which no 2x2 building can be built.

     0   1   2   3   4   5   6   7
   ---------------------------------
0  | x | x | x | x | x | x | x | x |
   ---------------------------------
1  | x |   |   |   | x | x | x | x |
   ---------------------------------
2  | x |   |   |   | x | x | x | x |
   ---------------------------------
3  | x |   |   |   | x | x | x | x |
   ---------------------------------
4  | x |   |   |   |   |   | x | x |
   ---------------------------------
5  | x |   |   |   |   |   | x | x |
   ---------------------------------
6  | x |   |   |   |   |   | x | x |
   ---------------------------------
7  | x |   |   |   |   |   | x | x |
   ---------------------------------
8  | x |   |   |   |   |   | x | x |
   ---------------------------------
9  | x |   |   |   |   |   | x | x |
   ---------------------------------
10 | x | x | x | x | x | x | x | x |
   ---------------------------------
11 | x | x | x | x | x | x | x | x |
   ---------------------------------

E.g. it would be correct to be able to build a building by clicking on (4, 1), (4, 2) or (4, 3).

from mdcii.

siredmar avatar siredmar commented on August 17, 2024

I don't know if this is a new issue or just shows the same symptoms: The cursor has different offsets for different buildings when placing them.
image
Also i noticed, that placing the fisher hut and the warehouse coast cannot be placed on the shore. I guess this is simply not implemented yet.

from mdcii.

stwe avatar stwe commented on August 17, 2024

see 5052856

from mdcii.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.