Show culture production.
This commit is contained in:
parent
e14cb045f7
commit
33eb732162
@ -31,6 +31,7 @@
|
|||||||
<div>
|
<div>
|
||||||
<img src="/img/icons/culture.png" alt="Culture" />
|
<img src="/img/icons/culture.png" alt="Culture" />
|
||||||
{ Math.floor($village.resources.culture) }
|
{ Math.floor($village.resources.culture) }
|
||||||
|
({ production.culture >= 0 ? '+' : '' }{ production.culture })
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -76,12 +76,6 @@ export default function update(timestamp: number) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Make philosophers produce culture.
|
|
||||||
const philosopher = getUnitSource('philosopher');
|
|
||||||
const outputPerMinute = philosopher.behavior.culturePerMinute;
|
|
||||||
const outputPerMilisecond = outputPerMinute / 60.0 / 1000.0;
|
|
||||||
V.resources.culture += outputPerMilisecond * delta * (V.units.philosopher || 0);
|
|
||||||
|
|
||||||
// Check if the game is won.
|
// Check if the game is won.
|
||||||
if (V.resources.culture >= 2000) {
|
if (V.resources.culture >= 2000) {
|
||||||
V.victory = true;
|
V.victory = true;
|
||||||
|
20
src/utils.ts
20
src/utils.ts
@ -1,29 +1,31 @@
|
|||||||
import units from "./data/units";
|
import units from "./data/units";
|
||||||
import type { BuildingType, CostType, ProductionType } from "./types";
|
import type { BuildingType, CostType, ProductionType, ResourcesType } from "./types";
|
||||||
import type { VillageState } from "./village";
|
import type { VillageState } from "./village";
|
||||||
|
|
||||||
|
|
||||||
function _reduceResources(acc: ProductionType, item: ProductionType): ProductionType {
|
function _reduceResources(acc: ResourcesType, item: ResourcesType): ResourcesType {
|
||||||
return {
|
return {
|
||||||
wood: acc.wood + item.wood,
|
wood: acc.wood + item.wood,
|
||||||
stone: acc.stone + item.stone,
|
stone: acc.stone + item.stone,
|
||||||
iron: acc.iron + item.iron,
|
iron: acc.iron + item.iron,
|
||||||
food: acc.food + item.food,
|
food: acc.food + item.food,
|
||||||
|
culture: acc.culture + item.culture,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function getEmptyResources(): ProductionType {
|
export function getEmptyResources(): ResourcesType {
|
||||||
return {
|
return {
|
||||||
wood: 0,
|
wood: 0,
|
||||||
stone: 0,
|
stone: 0,
|
||||||
iron: 0,
|
iron: 0,
|
||||||
food: 0,
|
food: 0,
|
||||||
|
culture: 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function getProduction(villageState: VillageState): ProductionType {
|
export function getProduction(villageState: VillageState): ResourcesType {
|
||||||
let production = getEmptyResources();
|
let production = getEmptyResources();
|
||||||
|
|
||||||
// Add buildings production and intake.
|
// Add buildings production and intake.
|
||||||
@ -36,12 +38,20 @@ export function getProduction(villageState: VillageState): ProductionType {
|
|||||||
})
|
})
|
||||||
.reduce(_reduceResources, production);
|
.reduce(_reduceResources, production);
|
||||||
|
|
||||||
// Add units intake.
|
// Add units production and intake.
|
||||||
['philosopher'].forEach(type => {
|
['philosopher'].forEach(type => {
|
||||||
const unit = getUnitSource(type);
|
const unit = getUnitSource(type);
|
||||||
const unitCount = villageState.units[type] || 0;
|
const unitCount = villageState.units[type] || 0;
|
||||||
|
|
||||||
|
// Add food intake.
|
||||||
const intakePerMinute = unit.behavior.foodIntakePerMinute * unitCount;
|
const intakePerMinute = unit.behavior.foodIntakePerMinute * unitCount;
|
||||||
production.food -= intakePerMinute;
|
production.food -= intakePerMinute;
|
||||||
|
|
||||||
|
// Add culture production for Philosophers.
|
||||||
|
if (type === 'philosopher') {
|
||||||
|
const outputPerMinute = unit.behavior.culturePerMinute;
|
||||||
|
production.culture += outputPerMinute * unitCount;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return production;
|
return production;
|
||||||
|
Loading…
Reference in New Issue
Block a user