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

View File

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

View File

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

View File

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