Compare commits
No commits in common. "22adaeb7002b5f301f85856567135839f829b112" and "854ac99f526133e58c25a0c651489d1eecfa2367" have entirely different histories.
22adaeb700
...
854ac99f52
88
ai.js
88
ai.js
@ -263,9 +263,6 @@ function assignNewTask(cit) {
|
|||||||
case "Soldier":
|
case "Soldier":
|
||||||
soldierTasks(cit);
|
soldierTasks(cit);
|
||||||
break;
|
break;
|
||||||
case "Planner":
|
|
||||||
plannerTasks(cit);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
cit.task = null;
|
cit.task = null;
|
||||||
cit.target = null;
|
cit.target = null;
|
||||||
@ -388,94 +385,9 @@ function soldierTasks(cit) {
|
|||||||
builderTasks(cit);
|
builderTasks(cit);
|
||||||
}
|
}
|
||||||
|
|
||||||
function plannerTasks(cit) {
|
|
||||||
// Randomly place buildings with no planning
|
|
||||||
if(Math.random() < 0.05) {
|
|
||||||
cit.task = "planBuilding";
|
|
||||||
cit.target = null;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Just wander around when not placing buildings
|
|
||||||
cit.task = null;
|
|
||||||
cit.target = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* NEW TASK HANDLERS
|
* NEW TASK HANDLERS
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
function planBuildingTask(cit) {
|
|
||||||
// Choose a completely random building type
|
|
||||||
const buildingTypes = ["House", "Road", "Market", "Hospital", "School"];
|
|
||||||
const buildingType = buildingTypes[Math.floor(Math.random() * buildingTypes.length)];
|
|
||||||
|
|
||||||
// Set cost based on building type
|
|
||||||
let buildingCost = 0;
|
|
||||||
switch (buildingType) {
|
|
||||||
case "House": buildingCost = COST_HOUSE; break;
|
|
||||||
case "Road": buildingCost = COST_ROAD; break;
|
|
||||||
case "Market": buildingCost = COST_MARKET; break;
|
|
||||||
case "Hospital": buildingCost = COST_HOSPITAL; break;
|
|
||||||
case "School": buildingCost = COST_SCHOOL; break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if we can afford it
|
|
||||||
if (money < buildingCost) {
|
|
||||||
cit.task = null;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Choose a completely random location
|
|
||||||
let randomX, randomY;
|
|
||||||
let attempts = 0;
|
|
||||||
|
|
||||||
// Just try random locations until we find one that's not water
|
|
||||||
do {
|
|
||||||
randomX = randInt(-1500, 1500);
|
|
||||||
randomY = randInt(-1500, 1500);
|
|
||||||
attempts++;
|
|
||||||
if (attempts > 20) {
|
|
||||||
// Give up after too many attempts
|
|
||||||
cit.task = null;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} while (!isValidPlacement(randomX, randomY));
|
|
||||||
|
|
||||||
// Place the building at the random location
|
|
||||||
addMoney(-buildingCost, `Planner: ${buildingType}`);
|
|
||||||
|
|
||||||
let newBuilding;
|
|
||||||
switch (buildingType) {
|
|
||||||
case "House":
|
|
||||||
newBuilding = createHouseSite(randomX, randomY);
|
|
||||||
break;
|
|
||||||
case "Road":
|
|
||||||
// Just make a random road segment
|
|
||||||
newBuilding = createRoadSite(
|
|
||||||
randomX,
|
|
||||||
randomY,
|
|
||||||
randomX + randInt(-100, 100),
|
|
||||||
randomY + randInt(-100, 100)
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
case "Market":
|
|
||||||
newBuilding = createMarketSite(randomX, randomY);
|
|
||||||
break;
|
|
||||||
case "Hospital":
|
|
||||||
newBuilding = createHospitalSite(randomX, randomY);
|
|
||||||
break;
|
|
||||||
case "School":
|
|
||||||
newBuilding = createSchoolSite(randomX, randomY);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
buildings.push(newBuilding);
|
|
||||||
logAction(`${cit.name} [Planner] randomly placed a ${buildingType} at (${Math.floor(randomX)}, ${Math.floor(randomY)})`);
|
|
||||||
|
|
||||||
cit.task = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function huntWolfTask(cit) {
|
function huntWolfTask(cit) {
|
||||||
let wolf = cit.target;
|
let wolf = cit.target;
|
||||||
if(!wolf || wolf.dead) {
|
if(!wolf || wolf.dead) {
|
||||||
|
16
events.js
16
events.js
@ -96,11 +96,6 @@ function setupBuyButtons() {
|
|||||||
logAction("Click on map to place a new Soldier citizen.");
|
logAction("Click on map to place a new Soldier citizen.");
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById('buyPlannerBtn').addEventListener('click', () => {
|
|
||||||
purchaseMode = "Planner";
|
|
||||||
logAction("Click on map to place a new Planner citizen.");
|
|
||||||
});
|
|
||||||
|
|
||||||
document.getElementById('buyMarketBtn').addEventListener('click', () => {
|
document.getElementById('buyMarketBtn').addEventListener('click', () => {
|
||||||
purchaseMode = "Market";
|
purchaseMode = "Market";
|
||||||
logAction("Click on map to place a Market site.");
|
logAction("Click on map to place a Market site.");
|
||||||
@ -400,17 +395,6 @@ function setupCanvasClick() {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "Planner":
|
|
||||||
if(money >= COST_PLANNER) {
|
|
||||||
addMoney(-COST_PLANNER, "Buy Planner");
|
|
||||||
let c = createCitizen(randomName(), worldX, worldY, "Planner");
|
|
||||||
citizens.push(c);
|
|
||||||
logAction(`Purchased new Planner @(${Math.floor(worldX)},${Math.floor(worldY)})`);
|
|
||||||
} else {
|
|
||||||
logAction("Not enough money to buy Planner!");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "Spawner":
|
case "Spawner":
|
||||||
if(money >= COST_SPAWNER) {
|
if(money >= COST_SPAWNER) {
|
||||||
addMoney(-COST_SPAWNER, "Buy Spawner");
|
addMoney(-COST_SPAWNER, "Buy Spawner");
|
||||||
|
54
game.js
54
game.js
@ -36,7 +36,6 @@ const COST_SCHOOL = 450;
|
|||||||
const COST_SPAWNER = 500;
|
const COST_SPAWNER = 500;
|
||||||
const COST_TREE = 50;
|
const COST_TREE = 50;
|
||||||
const COST_SOLDIER = 250;
|
const COST_SOLDIER = 250;
|
||||||
const COST_PLANNER = 1000;
|
|
||||||
|
|
||||||
// Terrain costs
|
// Terrain costs
|
||||||
const COST_WATER = 20;
|
const COST_WATER = 20;
|
||||||
@ -91,51 +90,19 @@ const SCHOOL_WOOD_REQUIRED = 65;
|
|||||||
const SCHOOL_BUILD_RATE = 0.12;
|
const SCHOOL_BUILD_RATE = 0.12;
|
||||||
|
|
||||||
// Professions
|
// Professions
|
||||||
const PROFESSIONS = ["Farmer", "Builder", "Merchant", "Doctor", "Teacher", "Soldier", "Planner"];
|
const PROFESSIONS = ["Farmer", "Builder", "Merchant", "Doctor", "Teacher", "Soldier"];
|
||||||
|
|
||||||
// Animals
|
// Animals
|
||||||
const STARTING_RABBITS = 10;
|
const STARTING_RABBITS = 10;
|
||||||
const STARTING_WOLVES = 5;
|
const STARTING_WOLVES = 3;
|
||||||
const RABBIT_HUNGER_INCREMENT = 0.003;
|
const RABBIT_HUNGER_INCREMENT = 0.003;
|
||||||
const RABBIT_REPRO_COOLDOWN = 5000;
|
const RABBIT_REPRO_COOLDOWN = 3000;
|
||||||
const RABBIT_REPRO_CHANCE = 0.0002;
|
const RABBIT_REPRO_CHANCE = 0.0005;
|
||||||
const WOLF_SPEED = 0.7; // Faster than rabbits
|
const WOLF_SPEED = 0.7; // Faster than rabbits
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* INIT WORLD
|
* INIT WORLD
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
// Function to spawn wolves at the corners of the map
|
|
||||||
function spawnWolvesAtCorners() {
|
|
||||||
const corners = [
|
|
||||||
{ x: -1800, y: -1800 },
|
|
||||||
{ x: -1800, y: 1800 },
|
|
||||||
{ x: 1800, y: -1800 },
|
|
||||||
{ x: 1800, y: 1800 }
|
|
||||||
];
|
|
||||||
|
|
||||||
corners.forEach(corner => {
|
|
||||||
// Try to find valid placement near the corner
|
|
||||||
let x, y;
|
|
||||||
let attempts = 0;
|
|
||||||
do {
|
|
||||||
x = corner.x + randInt(-100, 100);
|
|
||||||
y = corner.y + randInt(-100, 100);
|
|
||||||
attempts++;
|
|
||||||
// Give up after too many attempts
|
|
||||||
if (attempts > 20) break;
|
|
||||||
} while (!isValidPlacement(x, y));
|
|
||||||
|
|
||||||
// If we found a valid spot, spawn 3 wolves there
|
|
||||||
if (attempts <= 20) {
|
|
||||||
for (let i = 0; i < 3; i++) {
|
|
||||||
const wolf = createAnimal("Wolf", x + randInt(-50, 50), y + randInt(-50, 50));
|
|
||||||
animals.push(wolf);
|
|
||||||
}
|
|
||||||
logAction(`A pack of wolves has appeared near (${Math.floor(x)}, ${Math.floor(y)})!`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function initWorld() {
|
function initWorld() {
|
||||||
// Normal trees - only on land
|
// Normal trees - only on land
|
||||||
for(let i=0; i<15; i++) {
|
for(let i=0; i<15; i++) {
|
||||||
@ -186,19 +153,6 @@ function initWorld() {
|
|||||||
animals.push(createAnimal("Wolf", x, y));
|
animals.push(createAnimal("Wolf", x, y));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spawn wolves at the corners of the map
|
|
||||||
spawnWolvesAtCorners();
|
|
||||||
|
|
||||||
// Spawn additional wolves in random locations
|
|
||||||
for(let i=0; i<5; i++) {
|
|
||||||
let x, y;
|
|
||||||
do {
|
|
||||||
x = randInt(-1500,1500);
|
|
||||||
y = randInt(-1500,1500);
|
|
||||||
} while (!isValidPlacement(x, y));
|
|
||||||
animals.push(createAnimal("Wolf", x, y));
|
|
||||||
}
|
|
||||||
|
|
||||||
requestAnimationFrame(update);
|
requestAnimationFrame(update);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +194,6 @@
|
|||||||
<button class="menu-button" id="buyDoctorBtn">Buy Doctor ($200)</button>
|
<button class="menu-button" id="buyDoctorBtn">Buy Doctor ($200)</button>
|
||||||
<button class="menu-button" id="buyTeacherBtn">Buy Teacher ($180)</button>
|
<button class="menu-button" id="buyTeacherBtn">Buy Teacher ($180)</button>
|
||||||
<button class="menu-button" id="buySoldierBtn">Buy Soldier ($250)</button>
|
<button class="menu-button" id="buySoldierBtn">Buy Soldier ($250)</button>
|
||||||
<button class="menu-button" id="buyPlannerBtn">Buy Planner ($1000)</button>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="menu-category">
|
<div class="menu-category">
|
||||||
|
@ -372,7 +372,6 @@ function drawCitizen(c) {
|
|||||||
case "Doctor": icon = "💉"; break;
|
case "Doctor": icon = "💉"; break;
|
||||||
case "Teacher": icon = "📚"; break;
|
case "Teacher": icon = "📚"; break;
|
||||||
case "Soldier": icon = "⚔️"; break;
|
case "Soldier": icon = "⚔️"; break;
|
||||||
case "Planner": icon = "🏗️"; break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.fillStyle = "#000";
|
ctx.fillStyle = "#000";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user