git repos / saland

commit faf7c749

Poul Sander · 2026-01-17 13:12
faf7c74907bc00ee47a12b9900f91f9c4a6ed34a patch · browse files
parent f2cbe5a056fdb7166d3f6edd33cbf80286638f8c

Extract the CreateLake function

Changed files

M src/saland/GameRegion.cpp before
M src/saland/GameRegion.hpp before
diff --git a/src/saland/GameRegion.cpp b/src/saland/GameRegion.cpp index 6fec626..a9e32b7 100644 --- a/src/saland/GameRegion.cpp +++ b/src/saland/GameRegion.cpp
@@ -240,28 +240,37 @@ static std::vector<std::vector<int>> generateLakePattern() {
return pattern;
}
+
void GameRegion::ProcessRegionFirstTimeEnter(World& world) {
if (world.tm.properties["type"].value == "forrest") {
{
- // Add a small lake
- int x = (rand()%(world.tm.width-LAKE_WIDTH));
- int y = (rand()%(world.tm.height-LAKE_HEIGHT));
- const auto& pattern = generateLakePattern();
- for (size_t i=0; i < LAKE_WIDTH; ++i) {
- for (size_t j=0; j < LAKE_HEIGHT; ++j) {
- if (pattern[i][j] == 0) {
- continue;
- }
- int layer_number = world.blockingLayer;
- uint32_t tile = 28;
- sago::tiled::setTileOnLayerNumber(world.tm, layer_number, x+i, y+j, tile);
- liqudHandler["water"].updateFirstTile(world.tm, x+i, y+j);
- }
- }
- }
+ CreateLake(world);
+ }
}
}
+void GameRegion::CreateLake(World& world)
+{
+ // Add a small lake
+ int x = (rand() % (world.tm.width - LAKE_WIDTH));
+ int y = (rand() % (world.tm.height - LAKE_HEIGHT));
+ const auto &pattern = generateLakePattern();
+ for (size_t i = 0; i < LAKE_WIDTH; ++i)
+ {
+ for (size_t j = 0; j < LAKE_HEIGHT; ++j)
+ {
+ if (pattern[i][j] == 0)
+ {
+ continue;
+ }
+ int layer_number = world.blockingLayer;
+ uint32_t tile = 28;
+ sago::tiled::setTileOnLayerNumber(world.tm, layer_number, x + i, y + j, tile);
+ liqudHandler["water"].updateFirstTile(world.tm, x + i, y + j);
+ }
+ }
+}
+
void GameRegion::ProcessRegionEnter(World& world) {
if (world.tm.properties["type"].value == "forrest") {
std::cout << "Forrest (or start) region\n";
diff --git a/src/saland/GameRegion.hpp b/src/saland/GameRegion.hpp index 0919617..b215dcb 100644 --- a/src/saland/GameRegion.hpp +++ b/src/saland/GameRegion.hpp
@@ -66,6 +66,7 @@ public:
void SpawnItem(const ItemDef& def, float destX, float destY) ;
void SpawnPrefab(const Prefab& prefab, int destX, int destY);
void ProcessRegionFirstTimeEnter(World& world);
+ void CreateLake(World& world);
void ProcessRegionEnter(World& world);
private:
int region_x = 0;