Comments (3)
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.
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.
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.
see 5052856
from mdcii.
Related Issues (20)
- Refactor the MapTile HOT 1
- Render animations HOT 1
- Add culling
- ClangFormat file HOT 5
- Google Test is missing HOT 2
- Conan execute error on Manjaro Linux HOT 1
- Image failed to load at path: resources/atlas/sgfx/0.png HOT 2
- Proposal versioning HOT 5
- Cod-Reader writes wrong gfx values in the json HOT 6
- If the building width != building height, the rotated building will be shown incorrectly.
- AtlasCreator usage Readme
- Placement and rotation of water-related buildings and farms selection
- Buildings are partially rendered with black borders on the side. HOT 1
- Bug: Mouse picker has x,y offset after zooming out and in again
- The world cannot be rotated when the world is resized.
- Mouse and keyboard events broken - reworked ImGui IO mouse/keyboard input API
- Build without conan HOT 1
- Add buildings only possible in DEG0
- Grammar for COD/GAD/INC files HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mdcii.