feat: Prevent placing entities on water and improve land generation
This commit is contained in:
17
ai.js
17
ai.js
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user