feat: Enhance wolf reproduction and movement mechanics
This commit is contained in:
parent
74f1c1eac1
commit
8bc13472aa
25
ai.js
25
ai.js
@ -6,8 +6,8 @@ const WOLF_HUNGER_INCREMENT = 0.01;
|
||||
const WOLF_DAMAGE = 10;
|
||||
const WOLF_ATTACK_RANGE = 15;
|
||||
const WOLF_ATTACK_COOLDOWN = 100;
|
||||
const WOLF_REPRO_CHANCE = 0.0002;
|
||||
const WOLF_REPRO_COOLDOWN = 5000;
|
||||
const WOLF_REPRO_CHANCE = 0.00008; // Much lower than rabbits
|
||||
const WOLF_REPRO_COOLDOWN = 8000; // Longer cooldown than rabbits
|
||||
|
||||
/**********************************************************************
|
||||
* CITIZEN AI
|
||||
@ -71,7 +71,7 @@ function updateWolf(w) {
|
||||
// First try to find rabbits
|
||||
let rabbit = findNearestAnimalOfType(w, "Rabbit");
|
||||
if(rabbit && distance(w.x, w.y, rabbit.x, rabbit.y) < 200) {
|
||||
moveToward(w, rabbit.x, rabbit.y, 0.5);
|
||||
moveToward(w, rabbit.x, rabbit.y, WOLF_SPEED);
|
||||
|
||||
// Attack if close enough and cooldown is ready
|
||||
if(distance(w.x, w.y, rabbit.x, rabbit.y) < WOLF_ATTACK_RANGE && w.attackCooldown <= 0) {
|
||||
@ -93,7 +93,7 @@ function updateWolf(w) {
|
||||
if(!nearbySoldier) {
|
||||
let citizen = citizens.find(c => distance(w.x, w.y, c.x, c.y) < 150);
|
||||
if(citizen) {
|
||||
moveToward(w, citizen.x, citizen.y, 0.45);
|
||||
moveToward(w, citizen.x, citizen.y, WOLF_SPEED);
|
||||
|
||||
// Attack if close enough and cooldown is ready
|
||||
if(distance(w.x, w.y, citizen.x, citizen.y) < WOLF_ATTACK_RANGE && w.attackCooldown <= 0) {
|
||||
@ -117,16 +117,21 @@ function updateWolf(w) {
|
||||
}
|
||||
} else {
|
||||
// Run away from soldier
|
||||
moveAway(w, nearbySoldier.x, nearbySoldier.y, 0.5);
|
||||
moveAway(w, nearbySoldier.x, nearbySoldier.y, WOLF_SPEED);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Reproduce
|
||||
if(w.hunger < 30 && w.reproductionCooldown <= 0) {
|
||||
if(Math.random() < WOLF_REPRO_CHANCE) {
|
||||
spawnBabyAnimal("Wolf", w.x, w.y);
|
||||
w.reproductionCooldown = WOLF_REPRO_COOLDOWN;
|
||||
// Reproduce - wolves need to be well-fed and have low hunger to reproduce
|
||||
if(w.hunger < 20 && w.reproductionCooldown <= 0) {
|
||||
// Find another wolf nearby for mating
|
||||
let nearbyWolf = findNearestAnimalOfType(w, "Wolf");
|
||||
if(nearbyWolf && nearbyWolf !== w && distance(w.x, w.y, nearbyWolf.x, nearbyWolf.y) < 50) {
|
||||
if(Math.random() < WOLF_REPRO_CHANCE) {
|
||||
spawnBabyAnimal("Wolf", w.x, w.y);
|
||||
w.reproductionCooldown = WOLF_REPRO_COOLDOWN;
|
||||
logAction("A wolf pack has grown - a new wolf pup was born!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
1
game.js
1
game.js
@ -91,6 +91,7 @@ const STARTING_WOLVES = 3;
|
||||
const RABBIT_HUNGER_INCREMENT = 0.003;
|
||||
const RABBIT_REPRO_COOLDOWN = 3000;
|
||||
const RABBIT_REPRO_CHANCE = 0.0005;
|
||||
const WOLF_SPEED = 0.7; // Faster than rabbits
|
||||
|
||||
/**********************************************************************
|
||||
* INIT WORLD
|
||||
|
Loading…
x
Reference in New Issue
Block a user