commit 54545ffe
Add lake spawn command
Changed files
| M | src/saland/Game.cpp before |
| M | src/saland/GameConsoleCommand.cpp before |
| M | src/saland/GameRegion.cpp before |
| M | src/saland/GameRegion.hpp before |
| M | src/saland/globals.hpp before |
diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp
index e284dec..6f6d060 100644
--- a/src/saland/Game.cpp
+++ b/src/saland/Game.cpp
@@ -880,6 +880,14 @@ void Game::Update() {
reset_region = false;
}
HandleSpawnCommand(data->gameRegion, data->human.get());
+ if (globalData.pendingSpawnLake) {
+ // Convert mouse position from pixels to tile coordinates
+ int tile_x = data->world_mouse_x / 32;
+ int tile_y = data->world_mouse_y / 32;
+ data->gameRegion.CreateLake(data->gameRegion.world, tile_x, tile_y);
+ data->gameRegion.world.init_physics(data->gameRegion.physicsBox);
+ globalData.pendingSpawnLake = false;
+ }
if (data->consoleActive && data->console && !data->console->IsActive()) {
data->consoleActive = false;
}
diff --git a/src/saland/GameConsoleCommand.cpp b/src/saland/GameConsoleCommand.cpp
index 9d8b455..c899559 100644
--- a/src/saland/GameConsoleCommand.cpp
+++ b/src/saland/GameConsoleCommand.cpp
@@ -202,7 +202,6 @@ struct ConsoleCommandSpawn : public ConsoleCommand {
if (args.size() < 3) {
throw std::runtime_error("Must be called like: spawn MONSTER_RACE COUNT [--aggressive|--fleeing]");
}
-
std::string race = args[1];
int count = 1;
try {
@@ -213,7 +212,6 @@ struct ConsoleCommandSpawn : public ConsoleCommand {
error_msg += args[2] + "\" into an integer";
throw std::runtime_error(error_msg);
}
-
if (count <= 0 || count > 100) {
throw std::runtime_error("Count must be between 1 and 100");
}
@@ -248,12 +246,28 @@ struct ConsoleCommandSpawn : public ConsoleCommand {
}
};
+struct ConsoleCommandSpawnLake : public ConsoleCommand {
+ virtual std::string getCommand() const override {
+ return "spawn_lake";
+ }
+
+ virtual std::string run(const std::vector<std::string>&) override {
+ globalData.pendingSpawnLake = true;
+ return "Lake will spawn at mouse position";
+ }
+
+ virtual std::string helpMessage() const override {
+ return "Spawns a lake at the current mouse position";
+ }
+};
+
static ConsoleCommandGiveItem cc_give_item;
static ConsoleCommandItem cc_item;
static ConsoleCommandQuit cc_quit;
static ConsoleCommandConfig cc_config;
static DrawOverlayConsoleCommand docc;
static ConsoleCommandSpawn cc_spawn;
+static ConsoleCommandSpawnLake cc_spawn_lake;
void GameConsoleCommandRegister() {
RegisterCommand(&cc_give_item);
@@ -262,4 +276,5 @@ void GameConsoleCommandRegister() {
RegisterCommand(&cc_config);
RegisterCommand(&docc);
RegisterCommand(&cc_spawn);
+ RegisterCommand(&cc_spawn_lake);
}
\ No newline at end of file
diff --git a/src/saland/GameRegion.cpp b/src/saland/GameRegion.cpp
index a9e32b7..048825e 100644
--- a/src/saland/GameRegion.cpp
+++ b/src/saland/GameRegion.cpp
@@ -154,8 +154,8 @@ static std::string GetRegionType(int region_x, int region_y) {
return "default";
}
-const int LAKE_WIDTH = 20; // width of the lake pattern
-const int LAKE_HEIGHT = 20; // height of the lake pattern
+const int LAKE_WIDTH = 10; // width of the lake pattern
+const int LAKE_HEIGHT = 10; // height of the lake pattern
const int LAKE_SIZE = 40; // maximum size of the lake
const int LAKE_MIN_SIZE = 8;
@@ -254,6 +254,12 @@ 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));
+ CreateLake(world, x, y);
+}
+
+void GameRegion::CreateLake(World& world, int tile_x, int tile_y)
+{
+ // Add a small lake at specified location
const auto &pattern = generateLakePattern();
for (size_t i = 0; i < LAKE_WIDTH; ++i)
{
@@ -265,8 +271,8 @@ void GameRegion::CreateLake(World& world)
}
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);
+ sago::tiled::setTileOnLayerNumber(world.tm, layer_number, tile_x + i, tile_y + j, tile);
+ liqudHandler["water"].updateFirstTile(world.tm, tile_x + i, tile_y + j);
}
}
}
diff --git a/src/saland/GameRegion.hpp b/src/saland/GameRegion.hpp
index b215dcb..322d5c6 100644
--- a/src/saland/GameRegion.hpp
+++ b/src/saland/GameRegion.hpp
@@ -67,6 +67,7 @@ public:
void SpawnPrefab(const Prefab& prefab, int destX, int destY);
void ProcessRegionFirstTimeEnter(World& world);
void CreateLake(World& world);
+ void CreateLake(World& world, int tile_x, int tile_y);
void ProcessRegionEnter(World& world);
private:
int region_x = 0;
diff --git a/src/saland/globals.hpp b/src/saland/globals.hpp
index 14e2edf..75cc468 100644
--- a/src/saland/globals.hpp
+++ b/src/saland/globals.hpp
@@ -70,6 +70,7 @@ struct GlobalData {
sago::SagoLogicalResize logicalResize;
SpawnCommand pendingSpawnCommand;
+ bool pendingSpawnLake = false;
};
extern GlobalData globalData;
@@ -79,4 +80,3 @@ void PlayerSave();
void PlayerLoad();
#endif /* GLOBALS_HPP */
-