Skip to content

Commit

Permalink
Support X/Y position periods for autotile "alt-id"s (#3158)
Browse files Browse the repository at this point in the history
Autotile "alt-id"s now support the "period-x" and "period-y" properties, which contain 2 unsigned integer values: first is the divider and second is the desired remainder after dividing the X/Y position of the tile, relative to its tilemap. If the desired remainder is matched, the condition is passed.

NOTE: For an "alt-id" to be chosen, all of its conditions ("period", random "weight") must be met.

This PR takes advantage of these new position periods to achieve proper castle autotiling with line tiles.
  • Loading branch information
Vankata453 authored Dec 27, 2024
1 parent 2cdc407 commit c21910d
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 50 deletions.
162 changes: 128 additions & 34 deletions data/images/autotiles.satc
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,19 @@
;; V
;; Contains :
;; The alternative id : (id 123456)
;; The X/Y period : (period-x 2 1) / (period-y 2 0)
;; Both contain 2 unsigned integer values: first is the divider and second is
;; the desired remainder after dividing the X/Y position of the tile, relative
;; to its tilemap.
;; The weight : (weight 0.2)
;; The weight is the odds of this tile to happen. 0 is never, 1 is always.
;; The autotile's default ID's odds of occuring are (1 - sum of all weights).
;; Ideally, the sum of all weights for an autotile should be below 1. If it
;; is 1, the the regular ID for that autotile will never occur. If it is
;; greater than 1, then certains alt ID's might never occur either.
;;
;; NOTE: For an "alt-id" to be chosen, all of its conditions ("period", random "weight") must be met.
;;
;; ===== MASK INFO =====
;;
;; The mask is 8 characters and represent which tiles around it is solid.
Expand Down Expand Up @@ -6365,7 +6371,6 @@
(solid #t)
(mask "*0****0*")
)

)

(autotileset
Expand All @@ -6377,7 +6382,13 @@
(id 4566)
(alt-id
(id 4565)
(weight -1)
(period-x 2 0)
(period-y 2 0)
)
(alt-id
(id 4565)
(period-x 2 1)
(period-y 2 1)
)
(solid #t)
(mask "11111111")
Expand All @@ -6389,16 +6400,20 @@

(mask "01011*0*")
(mask "*0*11010")


)

;; LEFT
(autotile
(id 4564)
(alt-id
(id 4557)
(weight -1)
(period-x 2 0)
(period-y 2 0)
)
(alt-id
(id 4557)
(period-x 2 1)
(period-y 2 1)
)
(solid #t)
(mask "*1101*11")
Expand All @@ -6415,7 +6430,13 @@
(id 4567)
(alt-id
(id 4558)
(weight -1)
(period-x 2 0)
(period-y 2 0)
)
(alt-id
(id 4558)
(period-x 2 1)
(period-y 2 1)
)
(solid #t)
(mask "11*1011*")
Expand All @@ -6441,15 +6462,20 @@
(solid #t)
(mask "*0*01*11")
(mask "01001*11")

)

;; TOP CENTER
(autotile
(id 4569)
(alt-id
(id 4555)
(weight -1)
(period-x 2 0)
(period-y 2 0)
)
(alt-id
(id 4555)
(period-x 2 1)
(period-y 2 1)
)
(alt-id
(id 4554)
Expand Down Expand Up @@ -6494,15 +6520,13 @@
(id 4580)
(alt-id
(id 4577)
(weight -1)
(period-x 2 0)
(period-y 2 0)
)
(alt-id
(id 4579)
(weight -1)
)
(alt-id
(id 4576)
(weight -1)
(id 4577)
(period-x 2 1)
(period-y 2 1)
)
(solid #t)
(mask "11111*0*")
Expand Down Expand Up @@ -6530,7 +6554,13 @@
(id 4592)
(alt-id
(id 4570)
(weight -1)
(period-x 2 0)
(period-y 2 0)
)
(alt-id
(id 4570)
(period-x 2 1)
(period-y 2 1)
)
(solid #t)
(mask "11111110")
Expand All @@ -6555,7 +6585,13 @@
(id 4593)
(alt-id
(id 4571)
(weight -1)
(period-x 2 0)
(period-y 2 0)
)
(alt-id
(id 4571)
(period-x 2 1)
(period-y 2 1)
)
(solid #t)
(mask "11111011")
Expand All @@ -6580,7 +6616,13 @@
(id 4581)
(alt-id
(id 4559)
(weight -1)
(period-x 2 0)
(period-y 2 0)
)
(alt-id
(id 4559)
(period-x 2 1)
(period-y 2 1)
)
(solid #t)
(mask "11011111")
Expand All @@ -6605,7 +6647,13 @@
(id 4582)
(alt-id
(id 4560)
(weight -1)
(period-x 2 0)
(period-y 2 0)
)
(alt-id
(id 4560)
(period-x 2 1)
(period-y 2 1)
)
(solid #t)
(mask "01111111")
Expand Down Expand Up @@ -6760,7 +6808,13 @@
(id 4480)
(alt-id
(id 4479)
(weight -1)
(period-x 2 0)
(period-y 2 0)
)
(alt-id
(id 4479)
(period-x 2 1)
(period-y 2 1)
)
(solid #t)
(mask "11111111")
Expand All @@ -6781,7 +6835,13 @@
(id 4478)
(alt-id
(id 4467)
(weight -1)
(period-x 2 0)
(period-y 2 0)
)
(alt-id
(id 4467)
(period-x 2 1)
(period-y 2 1)
)
(solid #t)
(mask "*1101*11")
Expand All @@ -6798,7 +6858,13 @@
(id 4481)
(alt-id
(id 4468)
(weight -1)
(period-x 2 0)
(period-y 2 0)
)
(alt-id
(id 4468)
(period-x 2 1)
(period-y 2 1)
)
(solid #t)
(mask "11*1011*")
Expand Down Expand Up @@ -6832,15 +6898,13 @@
(id 4483)
(alt-id
(id 4465)
(weight -1)
(period-x 2 0)
(period-y 2 0)
)
(alt-id
(id 4482)
(weight -1)
)
(alt-id
(id 4464)
(weight -1)
(id 4465)
(period-x 2 1)
(period-y 2 1)
)
(solid #t)
(mask "*0*11111")
Expand Down Expand Up @@ -6877,7 +6941,13 @@
(id 4498)
(alt-id
(id 4495)
(weight -1)
(period-x 2 0)
(period-y 2 0)
)
(alt-id
(id 4495)
(period-x 2 1)
(period-y 2 1)
)
(alt-id
(id 4497)
Expand Down Expand Up @@ -6913,7 +6983,13 @@
(id 4514)
(alt-id
(id 4484)
(weight -1)
(period-x 2 0)
(period-y 2 0)
)
(alt-id
(id 4484)
(period-x 2 1)
(period-y 2 1)
)
(solid #t)
(mask "11111110")
Expand All @@ -6938,7 +7014,13 @@
(id 4515)
(alt-id
(id 4485)
(weight -1)
(period-x 2 0)
(period-y 2 0)
)
(alt-id
(id 4485)
(period-x 2 1)
(period-y 2 1)
)
(solid #t)
(mask "11111011")
Expand All @@ -6963,7 +7045,13 @@
(id 4499)
(alt-id
(id 4469)
(weight -1)
(period-x 2 0)
(period-y 2 0)
)
(alt-id
(id 4469)
(period-x 2 1)
(period-y 2 1)
)
(solid #t)
(mask "11011111")
Expand All @@ -6988,7 +7076,13 @@
(id 4500)
(alt-id
(id 4470)
(weight -1)
(period-x 2 0)
(period-y 2 0)
)
(alt-id
(id 4470)
(period-x 2 1)
(period-y 2 1)
)
(solid #t)
(mask "01111111")
Expand Down
21 changes: 16 additions & 5 deletions src/supertux/autotile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ AutotileMask::matches(uint8_t mask, bool center) const

// Autotile.

Autotile::Autotile(uint32_t tile_id, const std::vector<std::pair<uint32_t, float>>& alt_tiles, const std::vector<AutotileMask>& masks, bool solid) :
Autotile::Autotile(uint32_t tile_id, const std::vector<std::pair<uint32_t, AltConditions>>& alt_tiles, const std::vector<AutotileMask>& masks, bool solid) :
m_tile_id(tile_id),
m_alt_tiles(alt_tiles),
m_masks(std::move(masks)),
Expand All @@ -62,7 +62,7 @@ Autotile::pick_tile(int x, int y) const
{
// Needed? Not needed?
// Could avoid pointless computation.
if (m_alt_tiles.size() == 0)
if (m_alt_tiles.empty())
return m_tile_id;

// srand() and rand() are inconsistent across platforms (Windows)
Expand All @@ -77,11 +77,22 @@ Autotile::pick_tile(int x, int y) const

for (const auto& pair : m_alt_tiles)
{
rnd_val -= pair.second;
if (rnd_val <= 0)
const AltConditions& cond = pair.second;
if (cond.weight <= 0.f && cond.period_x.first == 0 && cond.period_y.first == 0)
continue;

if (cond.period_x.first != 0 && x % cond.period_x.first != cond.period_x.second)
continue;
if (cond.period_y.first != 0 && y % cond.period_y.first != cond.period_y.second)
continue;
if (cond.weight > 0.f)
{
return pair.first;
rnd_val -= cond.weight;
if (rnd_val > 0.f)
continue;
}

return pair.first;
}

return m_tile_id;
Expand Down
Loading

0 comments on commit c21910d

Please sign in to comment.