git repos / saland

commit e5644f6b

Poul Sander · 2025-12-28 09:33
e5644f6b2c5b65ac9dde7e11f44c2de07561f7ca patch · browse files
parent fe8b32a69d503efc1a6c7337cbf97e0c37553a18

Add a propability that enemies becomes aggroed

Changed files

M src/saland/Game.cpp before
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 <cmath>
#include <condition_variable>
#include <memory>
+#include <random>
#include <sstream>
#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> monster = std::dynamic_pointer_cast<Monster>(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") {