Add the barracks and soldiers.

This commit is contained in:
Adrian 2024-11-07 10:12:29 +01:00
parent f427f4e2b6
commit 9639ff1368
6 changed files with 50 additions and 9 deletions

View File

@ -194,5 +194,29 @@ export default [
recruitmentTime: (V: VillageState, self: BuildingType) => 2 - 0.06 * self.level,
},
},
}
},
{
type: 'barracks',
name: 'Barracks',
cost: (level: number) => {
return {
wood: level * 100,
stone: level * 100,
iron: level * 100,
food: 0,
};
},
behavior: {
production: (V: VillageState, self: BuildingType) => {
const prod = getEmptyResources();
const intakePerMinute = Math.ceil(self.level / 3) * 3;
prod.food = -intakePerMinute;
return prod;
},
units: {
type: 'soldier',
recruitmentTime: (V: VillageState, self: BuildingType) => 1 - 0.03 * self.level,
},
},
},
];

View File

@ -13,4 +13,17 @@ export default [
foodIntakePerMinute: 2,
},
},
{
type: 'soldier',
name: 'Soldier',
cost: {
wood: 15,
stone: 5,
iron: 40,
food: 0,
},
behavior: {
foodIntakePerMinute: 1,
},
},
];

View File

@ -3,7 +3,7 @@
import showBuildingPanel from "../stores/showBuildingPanel";
import { getBuilding } from "../utils";
import village from "../village";
import UniversityPanel from "./UniversityPanel.svelte";
import BuildingRecruitment from "./BuildingRecruitment.svelte";
function close() {
showBuildingPanel.set(null);
@ -35,8 +35,8 @@
<div class="content">
{ #if building.level === 0 }
<p>Building in construction…</p>
{ :else if building.type === 'university' }
<UniversityPanel { building } />
{ :else if building.behavior.units }
<BuildingRecruitment { building } />
{ /if }
</div>
<div class="upgrade">

View File

@ -49,8 +49,8 @@
}
</script>
<div class="university">
<p>Create Philosophers</p>
<div class="recruitment">
<p>Recruit { unit.name }s</p>
<div class="cost">
<Cost { cost } duration={ timeToRecruit } />
</div>
@ -77,7 +77,7 @@
</div>
<style>
.university .cost {
.recruitment .cost {
margin: 1em;
}
</style>

View File

@ -4,6 +4,10 @@
$: currentUnits = Object.entries($village.units).map(([type, count]) => {
const unit = units.find(u => u.type === type);
if (!unit) {
throw new Error(`Unable to find unit: "${type}"`);
}
return {
...unit,
count,

View File

@ -39,7 +39,7 @@ export function getProduction(villageState: VillageState): ResourcesType {
.reduce(_reduceResources, production);
// Add units production and intake.
['philosopher'].forEach(type => {
['philosopher', 'soldier'].forEach(type => {
const unit = getUnitSource(type);
const unitCount = villageState.units[type] || 0;
@ -49,7 +49,7 @@ export function getProduction(villageState: VillageState): ResourcesType {
// Add culture production for Philosophers.
if (type === 'philosopher') {
const outputPerMinute = unit.behavior.culturePerMinute;
const outputPerMinute = unit.behavior.culturePerMinute || 0;
production.culture += outputPerMinute * unitCount;
}
});