diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp index e9b3fba..b4f21ba 100644 --- a/src/saland/Game.cpp +++ b/src/saland/Game.cpp @@ -44,6 +44,7 @@ https://github.com/sago007/saland #include #include #include +#include #include #include "console/Console.hpp" #include "GameConsoleCommand.hpp" @@ -811,6 +812,25 @@ void Game::Update() { SetLengthToOne(projectile->directionX, projectile->directionY); projectile->fired_by = data->human; data->gameRegion.placeables.push_back(projectile); + + // Make nearby enemies aggressive with 60% probability + static std::random_device rd; + static std::mt19937 gen(rd()); + static std::uniform_real_distribution<> dis(0.0, 1.0); + const float aggroRadius = 200.0f; + const float aggroChance = 0.6f; + + for (auto& placeable : data->gameRegion.placeables) { + std::shared_ptr monster = std::dynamic_pointer_cast(placeable); + if (monster) { + float dx = monster->X - data->human->X; + float dy = monster->Y - data->human->Y; + float distance = std::sqrt(dx * dx + dy * dy); + if (distance <= aggroRadius && dis(gen) < aggroChance) { + monster->aiState = Monster::State::Aggressive; + } + } + } } } if (data->spell_holder->slot_spell.at(data->spell_holder->slot_selected).name == "spell_watershot") {