Kill units when food is negative.
This commit is contained in:
parent
33eb732162
commit
4768e22a39
@ -1,6 +1,6 @@
|
||||
import { produce } from 'immer';
|
||||
|
||||
import { getBuilding, getProduction, getStorage, getUnitSource } from './utils';
|
||||
import { getBuilding, getProduction, getStorage, getUnitSource, shuffle } from './utils';
|
||||
import village, { type VillageState } from "./village";
|
||||
import type { ProductionType } from './types';
|
||||
|
||||
@ -43,6 +43,14 @@ export default function update(timestamp: number) {
|
||||
V.resources[resource] += outputPerMilisecond * delta;
|
||||
});
|
||||
|
||||
// Kill units if food is negative.
|
||||
if (V.resources.food < 0) {
|
||||
// Choose a unit type at random.
|
||||
const type = shuffle(Object.keys(V.units).filter(t => V.units[t] > 0))[0];
|
||||
// Kill one unit of that type.
|
||||
V.units[type]--;
|
||||
}
|
||||
|
||||
// Make sure resources do not overflow.
|
||||
Object.keys(productionPerMinute).forEach((key) => {
|
||||
const resource = key as keyof ProductionType;
|
||||
|
@ -111,7 +111,7 @@ function getInitialState() {
|
||||
}
|
||||
const newBuilding = createBuilding(type);
|
||||
newBuilding.tile = new Hex(x, y);
|
||||
newBuilding.level = 10; // DEBUG
|
||||
newBuilding.level = newBuilding.type === 'field' ? 1 : 10;
|
||||
state.outsideTiles[y][x] = newBuilding.id;
|
||||
state.buildings.push(newBuilding);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user