feat: Prevent placing entities on water and improve land generation

This commit is contained in:
Kacper Kostka (aider)
2025-04-02 12:14:34 +02:00
parent cde5301c2b
commit 3fa8a695b3
6 changed files with 113 additions and 13 deletions

17
ai.js
View File

@@ -648,8 +648,21 @@ function deliverFruitTask(cit) {
}
function plantFruitTreeTask(cit) {
let px = cit.x + randInt(-50, 50);
let py = cit.y + randInt(-50, 50);
// Try to find a valid land position nearby
let px, py;
let attempts = 0;
do {
px = cit.x + randInt(-50, 50);
py = cit.y + randInt(-50, 50);
attempts++;
// Give up after too many attempts and find a new task
if (attempts > 20) {
cit.task = null;
cit.target = null;
return;
}
} while (!isValidPlacement(px, py));
moveToward(cit, px, py, 0.4);
if(distance(cit.x, cit.y, px, py) < 10) {
if(cit.carryingFruit >= FRUIT_PLANT_COST) {