diff --git a/src/data/buildings.ts b/src/data/buildings.ts index 27fbe75..f00b359 100644 --- a/src/data/buildings.ts +++ b/src/data/buildings.ts @@ -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, + }, + }, + }, ]; diff --git a/src/data/units.ts b/src/data/units.ts index 49e996c..47f4450 100644 --- a/src/data/units.ts +++ b/src/data/units.ts @@ -13,4 +13,17 @@ export default [ foodIntakePerMinute: 2, }, }, + { + type: 'soldier', + name: 'Soldier', + cost: { + wood: 15, + stone: 5, + iron: 40, + food: 0, + }, + behavior: { + foodIntakePerMinute: 1, + }, + }, ]; diff --git a/src/hud/BuildingPanel.svelte b/src/hud/BuildingPanel.svelte index 9018b59..297e144 100644 --- a/src/hud/BuildingPanel.svelte +++ b/src/hud/BuildingPanel.svelte @@ -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 @@
{ #if building.level === 0 }

Building in construction…

- { :else if building.type === 'university' } - + { :else if building.behavior.units } + { /if }
diff --git a/src/hud/UniversityPanel.svelte b/src/hud/BuildingRecruitment.svelte similarity index 96% rename from src/hud/UniversityPanel.svelte rename to src/hud/BuildingRecruitment.svelte index b557699..74a5cdb 100644 --- a/src/hud/UniversityPanel.svelte +++ b/src/hud/BuildingRecruitment.svelte @@ -49,8 +49,8 @@ } -
-

Create Philosophers

+
+

Recruit { unit.name }s

@@ -77,7 +77,7 @@
diff --git a/src/hud/Units.svelte b/src/hud/Units.svelte index f21bec6..9ac07e7 100644 --- a/src/hud/Units.svelte +++ b/src/hud/Units.svelte @@ -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, diff --git a/src/utils.ts b/src/utils.ts index e25d368..eb93360 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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; } });