@civ-clone/base-city-lifecycle 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +2 -0
- package/.github/workflows/build-on-push.yml +39 -0
- package/.prettierrc +4 -0
- package/LICENSE +21 -0
- package/README.md +42 -2
- package/lib/assignWorkers.d.ts +114 -0
- package/lib/assignWorkers.js +184 -0
- package/lib/assignWorkers.js.map +1 -0
- package/lib/assignWorkers.ts +372 -0
- package/lib/canBeWorked.d.ts +28 -0
- package/lib/canBeWorked.js +27 -0
- package/lib/canBeWorked.js.map +1 -0
- package/lib/canBeWorked.ts +43 -0
- package/lib/captured.d.ts +12 -0
- package/lib/captured.js +30 -0
- package/lib/captured.js.map +1 -0
- package/lib/captured.ts +31 -0
- package/lib/claimName.d.ts +12 -0
- package/lib/claimName.js +9 -0
- package/lib/claimName.js.map +1 -0
- package/lib/claimName.ts +13 -0
- package/lib/created.d.ts +41 -0
- package/lib/created.js +52 -0
- package/lib/created.js.map +1 -0
- package/lib/created.ts +110 -0
- package/lib/destroyed.d.ts +23 -0
- package/lib/destroyed.js +29 -0
- package/lib/destroyed.js.map +1 -0
- package/lib/destroyed.ts +39 -0
- package/lib/events.d.ts +39 -0
- package/lib/events.js +33 -0
- package/lib/events.js.map +1 -0
- package/lib/events.ts +51 -0
- package/lib/famine.d.ts +41 -0
- package/lib/famine.js +44 -0
- package/lib/famine.js.map +1 -0
- package/lib/famine.ts +68 -0
- package/lib/foodStorage.d.ts +21 -0
- package/lib/foodStorage.js +27 -0
- package/lib/foodStorage.js.map +1 -0
- package/lib/foodStorage.ts +30 -0
- package/lib/occupiedTiles.d.ts +39 -0
- package/lib/occupiedTiles.js +50 -0
- package/lib/occupiedTiles.js.map +1 -0
- package/lib/occupiedTiles.ts +84 -0
- package/lib/playerActions.d.ts +72 -0
- package/lib/playerActions.js +68 -0
- package/lib/playerActions.js.map +1 -0
- package/lib/playerActions.ts +114 -0
- package/lib/processYield.d.ts +30 -0
- package/lib/processYield.js +54 -0
- package/lib/processYield.js.map +1 -0
- package/lib/processYield.ts +82 -0
- package/lib/unsupported.d.ts +6 -0
- package/lib/unsupported.js +9 -0
- package/lib/unsupported.js.map +1 -0
- package/lib/unsupported.ts +8 -0
- package/package.json +45 -4
- package/tests/base-city-lifecycle.test.ts +536 -0
- package/tests/r3b.test.ts +341 -0
- package/tsconfig.json +16 -0
package/lib/created.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.workCityTile = exports.registerCityGrowth = exports.registerCityBuild = void 0;
|
|
4
|
+
const AvailableSpecialistRegistry_1 = require("@civ-clone/core-city/AvailableSpecialistRegistry");
|
|
5
|
+
const CityGrowthRegistry_1 = require("@civ-clone/core-city-growth/CityGrowthRegistry");
|
|
6
|
+
const PlayerWorldRegistry_1 = require("@civ-clone/core-player-world/PlayerWorldRegistry");
|
|
7
|
+
const RuleRegistry_1 = require("@civ-clone/core-rule/RuleRegistry");
|
|
8
|
+
const SpecialistRegistry_1 = require("@civ-clone/core-city/SpecialistRegistry");
|
|
9
|
+
const WorkedTileRegistry_1 = require("@civ-clone/core-city/WorkedTileRegistry");
|
|
10
|
+
const CityBuild_1 = require("@civ-clone/core-city-build/CityBuild");
|
|
11
|
+
const CityGrowth_1 = require("@civ-clone/core-city-growth/CityGrowth");
|
|
12
|
+
const TileReassigned_1 = require("@civ-clone/core-city/Rules/TileReassigned");
|
|
13
|
+
const WorkedTile_1 = require("@civ-clone/core-city/WorkedTile");
|
|
14
|
+
const assignWorkers_1 = require("./assignWorkers");
|
|
15
|
+
/**
|
|
16
|
+
* Gives a new city its build, whose first item is asked for as a new city's (civ-clone/web-renderer#716).
|
|
17
|
+
*/
|
|
18
|
+
const registerCityBuild = (city, cityBuildRegistry, availableBuildItemsRegistry, ruleRegistry = RuleRegistry_1.instance) => {
|
|
19
|
+
const cityBuild = new CityBuild_1.default(city, availableBuildItemsRegistry, ruleRegistry);
|
|
20
|
+
cityBuild.setCleared('created');
|
|
21
|
+
cityBuildRegistry.register(cityBuild);
|
|
22
|
+
return cityBuild;
|
|
23
|
+
};
|
|
24
|
+
exports.registerCityBuild = registerCityBuild;
|
|
25
|
+
/**
|
|
26
|
+
* Gives a new city its growth: its size and food store.
|
|
27
|
+
*/
|
|
28
|
+
const registerCityGrowth = (city, cityGrowthRegistry = CityGrowthRegistry_1.instance, ruleRegistry = RuleRegistry_1.instance) => {
|
|
29
|
+
const cityGrowth = new CityGrowth_1.default(city, ruleRegistry);
|
|
30
|
+
cityGrowthRegistry.register(cityGrowth);
|
|
31
|
+
return cityGrowth;
|
|
32
|
+
};
|
|
33
|
+
exports.registerCityGrowth = registerCityGrowth;
|
|
34
|
+
/**
|
|
35
|
+
* A new city works its own centre, taking it from any city that worked it, which its `TileReassigned` rules then let
|
|
36
|
+
* choose another, and puts its citizens to work.
|
|
37
|
+
*/
|
|
38
|
+
const workCityTile = (city, ruleRegistry = RuleRegistry_1.instance, playerWorldRegistry = PlayerWorldRegistry_1.instance, cityGrowthRegistry = CityGrowthRegistry_1.instance, workedTileRegistry = WorkedTileRegistry_1.instance, specialistRegistry = SpecialistRegistry_1.instance, availableSpecialistRegistry = AvailableSpecialistRegistry_1.instance) => {
|
|
39
|
+
const existingWorkedTile = workedTileRegistry.getByTile(city.tile());
|
|
40
|
+
if (existingWorkedTile !== null) {
|
|
41
|
+
workedTileRegistry.unregister(existingWorkedTile);
|
|
42
|
+
}
|
|
43
|
+
workedTileRegistry.register(new WorkedTile_1.default(city.tile(), city));
|
|
44
|
+
// Give the existing City the chance to reassign its worker before...
|
|
45
|
+
if (existingWorkedTile !== null) {
|
|
46
|
+
ruleRegistry.process(TileReassigned_1.default, existingWorkedTile.city(), existingWorkedTile.tile());
|
|
47
|
+
}
|
|
48
|
+
// ...assigning the remaining workers.
|
|
49
|
+
(0, assignWorkers_1.default)(city, playerWorldRegistry, cityGrowthRegistry, workedTileRegistry, specialistRegistry, availableSpecialistRegistry);
|
|
50
|
+
};
|
|
51
|
+
exports.workCityTile = workCityTile;
|
|
52
|
+
//# sourceMappingURL=created.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"created.js","sourceRoot":"","sources":["created.ts"],"names":[],"mappings":";;;AAAA,kGAG0D;AAC1D,uFAGwD;AACxD,0FAG0D;AAC1D,oEAG2C;AAC3C,gFAGiD;AACjD,gFAGiD;AAGjD,oEAA6D;AAE7D,uEAAgE;AAChE,8EAAuE;AACvE,gEAAyD;AACzD,mDAA4C;AAE5C;;GAEG;AACI,MAAM,iBAAiB,GAAG,CAC/B,IAAU,EACV,iBAAoC,EACpC,2BAA4D,EAC5D,eAA6B,uBAAoB,EACtC,EAAE;IACb,MAAM,SAAS,GAAG,IAAI,mBAAS,CAC7B,IAAI,EACJ,2BAA2B,EAC3B,YAAY,CACb,CAAC;IAEF,SAAS,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IAEhC,iBAAiB,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAEtC,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAjBW,QAAA,iBAAiB,qBAiB5B;AAEF;;GAEG;AACI,MAAM,kBAAkB,GAAG,CAChC,IAAU,EACV,qBAAyC,6BAA0B,EACnE,eAA6B,uBAAoB,EACrC,EAAE;IACd,MAAM,UAAU,GAAG,IAAI,oBAAU,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IAEtD,kBAAkB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAExC,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAVW,QAAA,kBAAkB,sBAU7B;AAEF;;;GAGG;AACI,MAAM,YAAY,GAAG,CAC1B,IAAU,EACV,eAA6B,uBAAoB,EACjD,sBAA2C,8BAA2B,EACtE,qBAAyC,6BAA0B,EACnE,qBAAyC,6BAA0B,EACnE,qBAAyC,6BAA0B,EACnE,8BAA2D,sCAAmC,EACxF,EAAE;IACR,MAAM,kBAAkB,GAAG,kBAAkB,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAErE,IAAI,kBAAkB,KAAK,IAAI,EAAE;QAC/B,kBAAkB,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC;KACnD;IAED,kBAAkB,CAAC,QAAQ,CAAC,IAAI,oBAAU,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC;IAE/D,qEAAqE;IACrE,IAAI,kBAAkB,KAAK,IAAI,EAAE;QAC/B,YAAY,CAAC,OAAO,CAClB,wBAAc,EACd,kBAAkB,CAAC,IAAI,EAAE,EACzB,kBAAkB,CAAC,IAAI,EAAE,CAC1B,CAAC;KACH;IAED,sCAAsC;IACtC,IAAA,uBAAa,EACX,IAAI,EACJ,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,2BAA2B,CAC5B,CAAC;AACJ,CAAC,CAAC;AAnCW,QAAA,YAAY,gBAmCvB"}
|
package/lib/created.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AvailableSpecialistRegistry,
|
|
3
|
+
instance as availableSpecialistRegistryInstance,
|
|
4
|
+
} from '@civ-clone/core-city/AvailableSpecialistRegistry';
|
|
5
|
+
import {
|
|
6
|
+
CityGrowthRegistry,
|
|
7
|
+
instance as cityGrowthRegistryInstance,
|
|
8
|
+
} from '@civ-clone/core-city-growth/CityGrowthRegistry';
|
|
9
|
+
import {
|
|
10
|
+
PlayerWorldRegistry,
|
|
11
|
+
instance as playerWorldRegistryInstance,
|
|
12
|
+
} from '@civ-clone/core-player-world/PlayerWorldRegistry';
|
|
13
|
+
import {
|
|
14
|
+
RuleRegistry,
|
|
15
|
+
instance as ruleRegistryInstance,
|
|
16
|
+
} from '@civ-clone/core-rule/RuleRegistry';
|
|
17
|
+
import {
|
|
18
|
+
SpecialistRegistry,
|
|
19
|
+
instance as specialistRegistryInstance,
|
|
20
|
+
} from '@civ-clone/core-city/SpecialistRegistry';
|
|
21
|
+
import {
|
|
22
|
+
WorkedTileRegistry,
|
|
23
|
+
instance as workedTileRegistryInstance,
|
|
24
|
+
} from '@civ-clone/core-city/WorkedTileRegistry';
|
|
25
|
+
import { AvailableCityBuildItemsRegistry } from '@civ-clone/core-city-build/AvailableCityBuildItemsRegistry';
|
|
26
|
+
import City from '@civ-clone/core-city/City';
|
|
27
|
+
import CityBuild from '@civ-clone/core-city-build/CityBuild';
|
|
28
|
+
import { CityBuildRegistry } from '@civ-clone/core-city-build/CityBuildRegistry';
|
|
29
|
+
import CityGrowth from '@civ-clone/core-city-growth/CityGrowth';
|
|
30
|
+
import TileReassigned from '@civ-clone/core-city/Rules/TileReassigned';
|
|
31
|
+
import WorkedTile from '@civ-clone/core-city/WorkedTile';
|
|
32
|
+
import assignWorkers from './assignWorkers';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Gives a new city its build, whose first item is asked for as a new city's (civ-clone/web-renderer#716).
|
|
36
|
+
*/
|
|
37
|
+
export const registerCityBuild = (
|
|
38
|
+
city: City,
|
|
39
|
+
cityBuildRegistry: CityBuildRegistry,
|
|
40
|
+
availableBuildItemsRegistry: AvailableCityBuildItemsRegistry,
|
|
41
|
+
ruleRegistry: RuleRegistry = ruleRegistryInstance
|
|
42
|
+
): CityBuild => {
|
|
43
|
+
const cityBuild = new CityBuild(
|
|
44
|
+
city,
|
|
45
|
+
availableBuildItemsRegistry,
|
|
46
|
+
ruleRegistry
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
cityBuild.setCleared('created');
|
|
50
|
+
|
|
51
|
+
cityBuildRegistry.register(cityBuild);
|
|
52
|
+
|
|
53
|
+
return cityBuild;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Gives a new city its growth: its size and food store.
|
|
58
|
+
*/
|
|
59
|
+
export const registerCityGrowth = (
|
|
60
|
+
city: City,
|
|
61
|
+
cityGrowthRegistry: CityGrowthRegistry = cityGrowthRegistryInstance,
|
|
62
|
+
ruleRegistry: RuleRegistry = ruleRegistryInstance
|
|
63
|
+
): CityGrowth => {
|
|
64
|
+
const cityGrowth = new CityGrowth(city, ruleRegistry);
|
|
65
|
+
|
|
66
|
+
cityGrowthRegistry.register(cityGrowth);
|
|
67
|
+
|
|
68
|
+
return cityGrowth;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* A new city works its own centre, taking it from any city that worked it, which its `TileReassigned` rules then let
|
|
73
|
+
* choose another, and puts its citizens to work.
|
|
74
|
+
*/
|
|
75
|
+
export const workCityTile = (
|
|
76
|
+
city: City,
|
|
77
|
+
ruleRegistry: RuleRegistry = ruleRegistryInstance,
|
|
78
|
+
playerWorldRegistry: PlayerWorldRegistry = playerWorldRegistryInstance,
|
|
79
|
+
cityGrowthRegistry: CityGrowthRegistry = cityGrowthRegistryInstance,
|
|
80
|
+
workedTileRegistry: WorkedTileRegistry = workedTileRegistryInstance,
|
|
81
|
+
specialistRegistry: SpecialistRegistry = specialistRegistryInstance,
|
|
82
|
+
availableSpecialistRegistry: AvailableSpecialistRegistry = availableSpecialistRegistryInstance
|
|
83
|
+
): void => {
|
|
84
|
+
const existingWorkedTile = workedTileRegistry.getByTile(city.tile());
|
|
85
|
+
|
|
86
|
+
if (existingWorkedTile !== null) {
|
|
87
|
+
workedTileRegistry.unregister(existingWorkedTile);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
workedTileRegistry.register(new WorkedTile(city.tile(), city));
|
|
91
|
+
|
|
92
|
+
// Give the existing City the chance to reassign its worker before...
|
|
93
|
+
if (existingWorkedTile !== null) {
|
|
94
|
+
ruleRegistry.process(
|
|
95
|
+
TileReassigned,
|
|
96
|
+
existingWorkedTile.city(),
|
|
97
|
+
existingWorkedTile.tile()
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// ...assigning the remaining workers.
|
|
102
|
+
assignWorkers(
|
|
103
|
+
city,
|
|
104
|
+
playerWorldRegistry,
|
|
105
|
+
cityGrowthRegistry,
|
|
106
|
+
workedTileRegistry,
|
|
107
|
+
specialistRegistry,
|
|
108
|
+
availableSpecialistRegistry
|
|
109
|
+
);
|
|
110
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SpecialistRegistry } from '@civ-clone/core-city/SpecialistRegistry';
|
|
2
|
+
import City from '@civ-clone/core-city/City';
|
|
3
|
+
import Unit from '@civ-clone/core-unit/Unit';
|
|
4
|
+
import { WorkedTileRegistry } from '@civ-clone/core-city/WorkedTileRegistry';
|
|
5
|
+
/**
|
|
6
|
+
* Destroys each of `units` (a city's own, say) that isn't destroyed already: when the city was its player's last, the
|
|
7
|
+
* first unit to go defeats the player, which destroys the rest (civ-clone/web-renderer#600).
|
|
8
|
+
*/
|
|
9
|
+
export declare const destroyUnits: (units: Unit[]) => void;
|
|
10
|
+
/**
|
|
11
|
+
* The tiles a city that's gone worked are free for another to work.
|
|
12
|
+
*/
|
|
13
|
+
export declare const releaseWorkedTiles: (
|
|
14
|
+
city: City,
|
|
15
|
+
workedTileRegistry: WorkedTileRegistry
|
|
16
|
+
) => void;
|
|
17
|
+
/**
|
|
18
|
+
* A city that's gone has no specialists.
|
|
19
|
+
*/
|
|
20
|
+
export declare const releaseSpecialists: (
|
|
21
|
+
city: City,
|
|
22
|
+
specialistRegistry: SpecialistRegistry
|
|
23
|
+
) => void;
|
package/lib/destroyed.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.releaseSpecialists = exports.releaseWorkedTiles = exports.destroyUnits = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Destroys each of `units` (a city's own, say) that isn't destroyed already: when the city was its player's last, the
|
|
6
|
+
* first unit to go defeats the player, which destroys the rest (civ-clone/web-renderer#600).
|
|
7
|
+
*/
|
|
8
|
+
const destroyUnits = (units) => units.forEach((unit) => {
|
|
9
|
+
if (unit.destroyed()) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
unit.destroy();
|
|
13
|
+
});
|
|
14
|
+
exports.destroyUnits = destroyUnits;
|
|
15
|
+
/**
|
|
16
|
+
* The tiles a city that's gone worked are free for another to work.
|
|
17
|
+
*/
|
|
18
|
+
const releaseWorkedTiles = (city, workedTileRegistry) => workedTileRegistry
|
|
19
|
+
.getByCity(city)
|
|
20
|
+
.forEach((workedTile) => workedTileRegistry.unregister(workedTile));
|
|
21
|
+
exports.releaseWorkedTiles = releaseWorkedTiles;
|
|
22
|
+
/**
|
|
23
|
+
* A city that's gone has no specialists.
|
|
24
|
+
*/
|
|
25
|
+
const releaseSpecialists = (city, specialistRegistry) => specialistRegistry
|
|
26
|
+
.getByCity(city)
|
|
27
|
+
.forEach((specialist) => specialistRegistry.unregister(specialist));
|
|
28
|
+
exports.releaseSpecialists = releaseSpecialists;
|
|
29
|
+
//# sourceMappingURL=destroyed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"destroyed.js","sourceRoot":"","sources":["destroyed.ts"],"names":[],"mappings":";;;AAKA;;;GAGG;AACI,MAAM,YAAY,GAAG,CAAC,KAAa,EAAQ,EAAE,CAClD,KAAK,CAAC,OAAO,CAAC,CAAC,IAAU,EAAQ,EAAE;IACjC,IAAI,IAAI,CAAC,SAAS,EAAE,EAAE;QACpB,OAAO;KACR;IAED,IAAI,CAAC,OAAO,EAAE,CAAC;AACjB,CAAC,CAAC,CAAC;AAPQ,QAAA,YAAY,gBAOpB;AAEL;;GAEG;AACI,MAAM,kBAAkB,GAAG,CAChC,IAAU,EACV,kBAAsC,EAChC,EAAE,CACR,kBAAkB;KACf,SAAS,CAAC,IAAI,CAAC;KACf,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,kBAAkB,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC;AAN3D,QAAA,kBAAkB,sBAMyC;AAExE;;GAEG;AACI,MAAM,kBAAkB,GAAG,CAChC,IAAU,EACV,kBAAsC,EAChC,EAAE,CACR,kBAAkB;KACf,SAAS,CAAC,IAAI,CAAC;KACf,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,kBAAkB,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC;AAN3D,QAAA,kBAAkB,sBAMyC"}
|
package/lib/destroyed.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { SpecialistRegistry } from '@civ-clone/core-city/SpecialistRegistry';
|
|
2
|
+
import City from '@civ-clone/core-city/City';
|
|
3
|
+
import Unit from '@civ-clone/core-unit/Unit';
|
|
4
|
+
import { WorkedTileRegistry } from '@civ-clone/core-city/WorkedTileRegistry';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Destroys each of `units` (a city's own, say) that isn't destroyed already: when the city was its player's last, the
|
|
8
|
+
* first unit to go defeats the player, which destroys the rest (civ-clone/web-renderer#600).
|
|
9
|
+
*/
|
|
10
|
+
export const destroyUnits = (units: Unit[]): void =>
|
|
11
|
+
units.forEach((unit: Unit): void => {
|
|
12
|
+
if (unit.destroyed()) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
unit.destroy();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The tiles a city that's gone worked are free for another to work.
|
|
21
|
+
*/
|
|
22
|
+
export const releaseWorkedTiles = (
|
|
23
|
+
city: City,
|
|
24
|
+
workedTileRegistry: WorkedTileRegistry
|
|
25
|
+
): void =>
|
|
26
|
+
workedTileRegistry
|
|
27
|
+
.getByCity(city)
|
|
28
|
+
.forEach((workedTile) => workedTileRegistry.unregister(workedTile));
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A city that's gone has no specialists.
|
|
32
|
+
*/
|
|
33
|
+
export const releaseSpecialists = (
|
|
34
|
+
city: City,
|
|
35
|
+
specialistRegistry: SpecialistRegistry
|
|
36
|
+
): void =>
|
|
37
|
+
specialistRegistry
|
|
38
|
+
.getByCity(city)
|
|
39
|
+
.forEach((specialist) => specialistRegistry.unregister(specialist));
|
package/lib/events.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { IBuildable as Buildable } from '@civ-clone/core-city-build/Buildable';
|
|
2
|
+
import City from '@civ-clone/core-city/City';
|
|
3
|
+
import CityBuild from '@civ-clone/core-city-build/CityBuild';
|
|
4
|
+
import { Engine } from '@civ-clone/core-engine/Engine';
|
|
5
|
+
import Tile from '@civ-clone/core-world/Tile';
|
|
6
|
+
/**
|
|
7
|
+
* Tells clients that `city` now works `tile`, so they can redraw it and show who works it.
|
|
8
|
+
*/
|
|
9
|
+
export declare const emitTileWorked: (
|
|
10
|
+
city: City,
|
|
11
|
+
tile: Tile,
|
|
12
|
+
engine: Engine
|
|
13
|
+
) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Tells clients that `city` no longer works `tile`, so they can redraw it.
|
|
16
|
+
*/
|
|
17
|
+
export declare const emitTileReleased: (
|
|
18
|
+
city: City,
|
|
19
|
+
tile: Tile,
|
|
20
|
+
engine: Engine
|
|
21
|
+
) => void;
|
|
22
|
+
/**
|
|
23
|
+
* Tells clients that `cityBuild`'s `item` is paid for but held back, with the ids of the `Hold` rules holding it (`null`
|
|
24
|
+
* for a rule without one), for a client to word.
|
|
25
|
+
*/
|
|
26
|
+
export declare const emitBuildingHeld: (
|
|
27
|
+
cityBuild: CityBuild,
|
|
28
|
+
item: Buildable,
|
|
29
|
+
held: (string | null)[],
|
|
30
|
+
engine: Engine
|
|
31
|
+
) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Tells clients that `cityBuild` has built `built`.
|
|
34
|
+
*/
|
|
35
|
+
export declare const emitBuildingComplete: (
|
|
36
|
+
cityBuild: CityBuild,
|
|
37
|
+
built: unknown,
|
|
38
|
+
engine: Engine
|
|
39
|
+
) => void;
|
package/lib/events.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.emitBuildingComplete = exports.emitBuildingHeld = exports.emitTileReleased = exports.emitTileWorked = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Tells clients that `city` now works `tile`, so they can redraw it and show who works it.
|
|
6
|
+
*/
|
|
7
|
+
const emitTileWorked = (city, tile, engine) => {
|
|
8
|
+
engine.emit('city:tile-worked', city, tile);
|
|
9
|
+
};
|
|
10
|
+
exports.emitTileWorked = emitTileWorked;
|
|
11
|
+
/**
|
|
12
|
+
* Tells clients that `city` no longer works `tile`, so they can redraw it.
|
|
13
|
+
*/
|
|
14
|
+
const emitTileReleased = (city, tile, engine) => {
|
|
15
|
+
engine.emit('city:tile-released', city, tile);
|
|
16
|
+
};
|
|
17
|
+
exports.emitTileReleased = emitTileReleased;
|
|
18
|
+
/**
|
|
19
|
+
* Tells clients that `cityBuild`'s `item` is paid for but held back, with the ids of the `Hold` rules holding it (`null`
|
|
20
|
+
* for a rule without one), for a client to word.
|
|
21
|
+
*/
|
|
22
|
+
const emitBuildingHeld = (cityBuild, item, held, engine) => {
|
|
23
|
+
engine.emit('city:building-held', cityBuild, item, held);
|
|
24
|
+
};
|
|
25
|
+
exports.emitBuildingHeld = emitBuildingHeld;
|
|
26
|
+
/**
|
|
27
|
+
* Tells clients that `cityBuild` has built `built`.
|
|
28
|
+
*/
|
|
29
|
+
const emitBuildingComplete = (cityBuild, built, engine) => {
|
|
30
|
+
engine.emit('city:building-complete', cityBuild, built);
|
|
31
|
+
};
|
|
32
|
+
exports.emitBuildingComplete = emitBuildingComplete;
|
|
33
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["events.ts"],"names":[],"mappings":";;;AAMA;;GAEG;AACI,MAAM,cAAc,GAAG,CAC5B,IAAU,EACV,IAAU,EACV,MAAc,EACR,EAAE;IACR,MAAM,CAAC,IAAI,CAAC,kBAAkB,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAC9C,CAAC,CAAC;AANW,QAAA,cAAc,kBAMzB;AAEF;;GAEG;AACI,MAAM,gBAAgB,GAAG,CAC9B,IAAU,EACV,IAAU,EACV,MAAc,EACR,EAAE;IACR,MAAM,CAAC,IAAI,CAAC,oBAAoB,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAChD,CAAC,CAAC;AANW,QAAA,gBAAgB,oBAM3B;AAEF;;;GAGG;AACI,MAAM,gBAAgB,GAAG,CAC9B,SAAoB,EACpB,IAAe,EACf,IAAuB,EACvB,MAAc,EACR,EAAE;IACR,MAAM,CAAC,IAAI,CAAC,oBAAoB,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAC3D,CAAC,CAAC;AAPW,QAAA,gBAAgB,oBAO3B;AAEF;;GAEG;AACI,MAAM,oBAAoB,GAAG,CAClC,SAAoB,EACpB,KAAc,EACd,MAAc,EACR,EAAE;IACR,MAAM,CAAC,IAAI,CAAC,wBAAwB,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;AAC1D,CAAC,CAAC;AANW,QAAA,oBAAoB,wBAM/B"}
|
package/lib/events.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { IBuildable as Buildable } from '@civ-clone/core-city-build/Buildable';
|
|
2
|
+
import City from '@civ-clone/core-city/City';
|
|
3
|
+
import CityBuild from '@civ-clone/core-city-build/CityBuild';
|
|
4
|
+
import { Engine } from '@civ-clone/core-engine/Engine';
|
|
5
|
+
import Tile from '@civ-clone/core-world/Tile';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Tells clients that `city` now works `tile`, so they can redraw it and show who works it.
|
|
9
|
+
*/
|
|
10
|
+
export const emitTileWorked = (
|
|
11
|
+
city: City,
|
|
12
|
+
tile: Tile,
|
|
13
|
+
engine: Engine
|
|
14
|
+
): void => {
|
|
15
|
+
engine.emit('city:tile-worked', city, tile);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Tells clients that `city` no longer works `tile`, so they can redraw it.
|
|
20
|
+
*/
|
|
21
|
+
export const emitTileReleased = (
|
|
22
|
+
city: City,
|
|
23
|
+
tile: Tile,
|
|
24
|
+
engine: Engine
|
|
25
|
+
): void => {
|
|
26
|
+
engine.emit('city:tile-released', city, tile);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Tells clients that `cityBuild`'s `item` is paid for but held back, with the ids of the `Hold` rules holding it (`null`
|
|
31
|
+
* for a rule without one), for a client to word.
|
|
32
|
+
*/
|
|
33
|
+
export const emitBuildingHeld = (
|
|
34
|
+
cityBuild: CityBuild,
|
|
35
|
+
item: Buildable,
|
|
36
|
+
held: (string | null)[],
|
|
37
|
+
engine: Engine
|
|
38
|
+
): void => {
|
|
39
|
+
engine.emit('city:building-held', cityBuild, item, held);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Tells clients that `cityBuild` has built `built`.
|
|
44
|
+
*/
|
|
45
|
+
export const emitBuildingComplete = (
|
|
46
|
+
cityBuild: CityBuild,
|
|
47
|
+
built: unknown,
|
|
48
|
+
engine: Engine
|
|
49
|
+
): void => {
|
|
50
|
+
engine.emit('city:building-complete', cityBuild, built);
|
|
51
|
+
};
|
package/lib/famine.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import CityGrowth from '@civ-clone/core-city-growth/CityGrowth';
|
|
2
|
+
import { Engine } from '@civ-clone/core-engine/Engine';
|
|
3
|
+
import Unit from '@civ-clone/core-unit/Unit';
|
|
4
|
+
import Yield from '@civ-clone/core-yield/Yield';
|
|
5
|
+
/**
|
|
6
|
+
* A yield a city pays for one of its units, which knows that unit (or `null`).
|
|
7
|
+
*/
|
|
8
|
+
export type UnitYieldType = abstract new (...args: any[]) => Yield & {
|
|
9
|
+
unit(): Unit | null;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* The first unit `cityGrowth`'s city feeds, as a `FoodSupportType` yield, in the order of the city's yields (the order
|
|
13
|
+
* its units were built), or `null`.
|
|
14
|
+
*/
|
|
15
|
+
export declare const foodSupportedUnit: (
|
|
16
|
+
cityGrowth: CityGrowth,
|
|
17
|
+
FoodSupportType: UnitYieldType
|
|
18
|
+
) => Unit | null;
|
|
19
|
+
/**
|
|
20
|
+
* Tells clients that `cityGrowth`'s city has run out of food, with the unit it will lose for it, when there is one.
|
|
21
|
+
*/
|
|
22
|
+
export declare const emitFoodStorageExhausted: (
|
|
23
|
+
cityGrowth: CityGrowth,
|
|
24
|
+
unit: Unit | null,
|
|
25
|
+
engine: Engine
|
|
26
|
+
) => void;
|
|
27
|
+
/**
|
|
28
|
+
* The city loses the first unit it feeds (see `foodSupportedUnit`), which must exist.
|
|
29
|
+
*/
|
|
30
|
+
export declare const loseFoodSupportedUnit: (
|
|
31
|
+
cityGrowth: CityGrowth,
|
|
32
|
+
FoodSupportType: UnitYieldType
|
|
33
|
+
) => void;
|
|
34
|
+
/**
|
|
35
|
+
* The city shrinks, because its food ran out.
|
|
36
|
+
*/
|
|
37
|
+
export declare const shrinkFromFamine: (cityGrowth: CityGrowth) => void;
|
|
38
|
+
/**
|
|
39
|
+
* The city's food store is emptied.
|
|
40
|
+
*/
|
|
41
|
+
export declare const emptyFoodStore: (cityGrowth: CityGrowth) => void;
|
package/lib/famine.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.emptyFoodStore = exports.shrinkFromFamine = exports.loseFoodSupportedUnit = exports.emitFoodStorageExhausted = exports.foodSupportedUnit = void 0;
|
|
4
|
+
const FoodExhausted_1 = require("@civ-clone/core-city-growth/Rules/FoodExhausted");
|
|
5
|
+
/**
|
|
6
|
+
* The first unit `cityGrowth`'s city feeds, as a `FoodSupportType` yield, in the order of the city's yields (the order
|
|
7
|
+
* its units were built), or `null`.
|
|
8
|
+
*/
|
|
9
|
+
const foodSupportedUnit = (cityGrowth, FoodSupportType) => {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
return (_b = (_a = cityGrowth
|
|
12
|
+
.city()
|
|
13
|
+
.yields()
|
|
14
|
+
.find((cityYield) => cityYield instanceof FoodSupportType &&
|
|
15
|
+
cityYield.unit() !== null)) === null || _a === void 0 ? void 0 : _a.unit()) !== null && _b !== void 0 ? _b : null;
|
|
16
|
+
};
|
|
17
|
+
exports.foodSupportedUnit = foodSupportedUnit;
|
|
18
|
+
/**
|
|
19
|
+
* Tells clients that `cityGrowth`'s city has run out of food, with the unit it will lose for it, when there is one.
|
|
20
|
+
*/
|
|
21
|
+
const emitFoodStorageExhausted = (cityGrowth, unit, engine) => {
|
|
22
|
+
if (unit === null) {
|
|
23
|
+
engine.emit('city:food-storage-exhausted', cityGrowth.city());
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
engine.emit('city:food-storage-exhausted', cityGrowth.city(), unit);
|
|
27
|
+
};
|
|
28
|
+
exports.emitFoodStorageExhausted = emitFoodStorageExhausted;
|
|
29
|
+
/**
|
|
30
|
+
* The city loses the first unit it feeds (see `foodSupportedUnit`), which must exist.
|
|
31
|
+
*/
|
|
32
|
+
const loseFoodSupportedUnit = (cityGrowth, FoodSupportType) => (0, exports.foodSupportedUnit)(cityGrowth, FoodSupportType).destroy();
|
|
33
|
+
exports.loseFoodSupportedUnit = loseFoodSupportedUnit;
|
|
34
|
+
/**
|
|
35
|
+
* The city shrinks, because its food ran out.
|
|
36
|
+
*/
|
|
37
|
+
const shrinkFromFamine = (cityGrowth) => cityGrowth.shrink(FoodExhausted_1.default);
|
|
38
|
+
exports.shrinkFromFamine = shrinkFromFamine;
|
|
39
|
+
/**
|
|
40
|
+
* The city's food store is emptied.
|
|
41
|
+
*/
|
|
42
|
+
const emptyFoodStore = (cityGrowth) => cityGrowth.empty();
|
|
43
|
+
exports.emptyFoodStore = emptyFoodStore;
|
|
44
|
+
//# sourceMappingURL=famine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"famine.js","sourceRoot":"","sources":["famine.ts"],"names":[],"mappings":";;;AAEA,mFAA4E;AAW5E;;;GAGG;AACI,MAAM,iBAAiB,GAAG,CAC/B,UAAsB,EACtB,eAA8B,EACjB,EAAE;;IACf,OAAA,MAAA,MACE,UAAU;SACP,IAAI,EAAE;SACN,MAAM,EAAE;SACR,IAAI,CACH,CAAC,SAAgB,EAAW,EAAE,CAC5B,SAAS,YAAY,eAAe;QACnC,SAAyC,CAAC,IAAI,EAAE,KAAK,IAAI,CAEjE,0CAAE,IAAI,EAAE,mCAAI,IAAI,CAAA;CAAA,CAAC;AAbP,QAAA,iBAAiB,qBAaV;AAEpB;;GAEG;AACI,MAAM,wBAAwB,GAAG,CACtC,UAAsB,EACtB,IAAiB,EACjB,MAAc,EACR,EAAE;IACR,IAAI,IAAI,KAAK,IAAI,EAAE;QACjB,MAAM,CAAC,IAAI,CAAC,6BAA6B,EAAE,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;QAE9D,OAAO;KACR;IAED,MAAM,CAAC,IAAI,CAAC,6BAA6B,EAAE,UAAU,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;AACtE,CAAC,CAAC;AAZW,QAAA,wBAAwB,4BAYnC;AAEF;;GAEG;AACI,MAAM,qBAAqB,GAAG,CACnC,UAAsB,EACtB,eAA8B,EACxB,EAAE,CAAC,IAAA,yBAAiB,EAAC,UAAU,EAAE,eAAe,CAAE,CAAC,OAAO,EAAE,CAAC;AAHxD,QAAA,qBAAqB,yBAGmC;AAErE;;GAEG;AACI,MAAM,gBAAgB,GAAG,CAAC,UAAsB,EAAQ,EAAE,CAC/D,UAAU,CAAC,MAAM,CAAC,uBAAa,CAAC,CAAC;AADtB,QAAA,gBAAgB,oBACM;AAEnC;;GAEG;AACI,MAAM,cAAc,GAAG,CAAC,UAAsB,EAAQ,EAAE,CAC7D,UAAU,CAAC,KAAK,EAAE,CAAC;AADR,QAAA,cAAc,kBACN"}
|
package/lib/famine.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import CityGrowth from '@civ-clone/core-city-growth/CityGrowth';
|
|
2
|
+
import { Engine } from '@civ-clone/core-engine/Engine';
|
|
3
|
+
import FoodExhausted from '@civ-clone/core-city-growth/Rules/FoodExhausted';
|
|
4
|
+
import Unit from '@civ-clone/core-unit/Unit';
|
|
5
|
+
import Yield from '@civ-clone/core-yield/Yield';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A yield a city pays for one of its units, which knows that unit (or `null`).
|
|
9
|
+
*/
|
|
10
|
+
export type UnitYieldType = abstract new (...args: any[]) => Yield & {
|
|
11
|
+
unit(): Unit | null;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The first unit `cityGrowth`'s city feeds, as a `FoodSupportType` yield, in the order of the city's yields (the order
|
|
16
|
+
* its units were built), or `null`.
|
|
17
|
+
*/
|
|
18
|
+
export const foodSupportedUnit = (
|
|
19
|
+
cityGrowth: CityGrowth,
|
|
20
|
+
FoodSupportType: UnitYieldType
|
|
21
|
+
): Unit | null =>
|
|
22
|
+
(
|
|
23
|
+
cityGrowth
|
|
24
|
+
.city()
|
|
25
|
+
.yields()
|
|
26
|
+
.find(
|
|
27
|
+
(cityYield: Yield): boolean =>
|
|
28
|
+
cityYield instanceof FoodSupportType &&
|
|
29
|
+
(cityYield as InstanceType<UnitYieldType>).unit() !== null
|
|
30
|
+
) as InstanceType<UnitYieldType> | undefined
|
|
31
|
+
)?.unit() ?? null;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Tells clients that `cityGrowth`'s city has run out of food, with the unit it will lose for it, when there is one.
|
|
35
|
+
*/
|
|
36
|
+
export const emitFoodStorageExhausted = (
|
|
37
|
+
cityGrowth: CityGrowth,
|
|
38
|
+
unit: Unit | null,
|
|
39
|
+
engine: Engine
|
|
40
|
+
): void => {
|
|
41
|
+
if (unit === null) {
|
|
42
|
+
engine.emit('city:food-storage-exhausted', cityGrowth.city());
|
|
43
|
+
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
engine.emit('city:food-storage-exhausted', cityGrowth.city(), unit);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The city loses the first unit it feeds (see `foodSupportedUnit`), which must exist.
|
|
52
|
+
*/
|
|
53
|
+
export const loseFoodSupportedUnit = (
|
|
54
|
+
cityGrowth: CityGrowth,
|
|
55
|
+
FoodSupportType: UnitYieldType
|
|
56
|
+
): void => foodSupportedUnit(cityGrowth, FoodSupportType)!.destroy();
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The city shrinks, because its food ran out.
|
|
60
|
+
*/
|
|
61
|
+
export const shrinkFromFamine = (cityGrowth: CityGrowth): void =>
|
|
62
|
+
cityGrowth.shrink(FoodExhausted);
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The city's food store is emptied.
|
|
66
|
+
*/
|
|
67
|
+
export const emptyFoodStore = (cityGrowth: CityGrowth): void =>
|
|
68
|
+
cityGrowth.empty();
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import CityGrowth from '@civ-clone/core-city-growth/CityGrowth';
|
|
2
|
+
import { RuleRegistry } from '@civ-clone/core-rule/RuleRegistry';
|
|
3
|
+
/**
|
|
4
|
+
* Whether a city's food store holds enough for it to grow.
|
|
5
|
+
*/
|
|
6
|
+
export declare const hasFoodToGrow: (cityGrowth: CityGrowth) => boolean;
|
|
7
|
+
/**
|
|
8
|
+
* The city grows.
|
|
9
|
+
*/
|
|
10
|
+
export declare const grow: (cityGrowth: CityGrowth) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Whether a city's food store has run out: it is below 0 once the turn's food is added.
|
|
13
|
+
*/
|
|
14
|
+
export declare const isFoodExhausted: (cityGrowth: CityGrowth) => boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The city's food has run out: its `FoodExhausted` rules decide what that costs it.
|
|
17
|
+
*/
|
|
18
|
+
export declare const exhaustFood: (
|
|
19
|
+
cityGrowth: CityGrowth,
|
|
20
|
+
ruleRegistry: RuleRegistry
|
|
21
|
+
) => void;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.exhaustFood = exports.isFoodExhausted = exports.grow = exports.hasFoodToGrow = void 0;
|
|
4
|
+
const FoodExhausted_1 = require("@civ-clone/core-city-growth/Rules/FoodExhausted");
|
|
5
|
+
/**
|
|
6
|
+
* Whether a city's food store holds enough for it to grow.
|
|
7
|
+
*/
|
|
8
|
+
const hasFoodToGrow = (cityGrowth) => cityGrowth.progress().value() >= cityGrowth.cost().value();
|
|
9
|
+
exports.hasFoodToGrow = hasFoodToGrow;
|
|
10
|
+
/**
|
|
11
|
+
* The city grows.
|
|
12
|
+
*/
|
|
13
|
+
const grow = (cityGrowth) => cityGrowth.grow();
|
|
14
|
+
exports.grow = grow;
|
|
15
|
+
/**
|
|
16
|
+
* Whether a city's food store has run out: it is below 0 once the turn's food is added.
|
|
17
|
+
*/
|
|
18
|
+
const isFoodExhausted = (cityGrowth) => cityGrowth.progress().value() < 0;
|
|
19
|
+
exports.isFoodExhausted = isFoodExhausted;
|
|
20
|
+
/**
|
|
21
|
+
* The city's food has run out: its `FoodExhausted` rules decide what that costs it.
|
|
22
|
+
*/
|
|
23
|
+
const exhaustFood = (cityGrowth, ruleRegistry) => {
|
|
24
|
+
ruleRegistry.process(FoodExhausted_1.default, cityGrowth);
|
|
25
|
+
};
|
|
26
|
+
exports.exhaustFood = exhaustFood;
|
|
27
|
+
//# sourceMappingURL=foodStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"foodStorage.js","sourceRoot":"","sources":["foodStorage.ts"],"names":[],"mappings":";;;AACA,mFAA4E;AAG5E;;GAEG;AACI,MAAM,aAAa,GAAG,CAAC,UAAsB,EAAW,EAAE,CAC/D,UAAU,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,UAAU,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC;AADhD,QAAA,aAAa,iBACmC;AAE7D;;GAEG;AACI,MAAM,IAAI,GAAG,CAAC,UAAsB,EAAQ,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;AAA3D,QAAA,IAAI,QAAuD;AAExE;;GAEG;AACI,MAAM,eAAe,GAAG,CAAC,UAAsB,EAAW,EAAE,CACjE,UAAU,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AADvB,QAAA,eAAe,mBACQ;AAEpC;;GAEG;AACI,MAAM,WAAW,GAAG,CACzB,UAAsB,EACtB,YAA0B,EACpB,EAAE;IACR,YAAY,CAAC,OAAO,CAAC,uBAAa,EAAE,UAAU,CAAC,CAAC;AAClD,CAAC,CAAC;AALW,QAAA,WAAW,eAKtB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import CityGrowth from '@civ-clone/core-city-growth/CityGrowth';
|
|
2
|
+
import FoodExhausted from '@civ-clone/core-city-growth/Rules/FoodExhausted';
|
|
3
|
+
import { RuleRegistry } from '@civ-clone/core-rule/RuleRegistry';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Whether a city's food store holds enough for it to grow.
|
|
7
|
+
*/
|
|
8
|
+
export const hasFoodToGrow = (cityGrowth: CityGrowth): boolean =>
|
|
9
|
+
cityGrowth.progress().value() >= cityGrowth.cost().value();
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The city grows.
|
|
13
|
+
*/
|
|
14
|
+
export const grow = (cityGrowth: CityGrowth): void => cityGrowth.grow();
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Whether a city's food store has run out: it is below 0 once the turn's food is added.
|
|
18
|
+
*/
|
|
19
|
+
export const isFoodExhausted = (cityGrowth: CityGrowth): boolean =>
|
|
20
|
+
cityGrowth.progress().value() < 0;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The city's food has run out: its `FoodExhausted` rules decide what that costs it.
|
|
24
|
+
*/
|
|
25
|
+
export const exhaustFood = (
|
|
26
|
+
cityGrowth: CityGrowth,
|
|
27
|
+
ruleRegistry: RuleRegistry
|
|
28
|
+
): void => {
|
|
29
|
+
ruleRegistry.process(FoodExhausted, cityGrowth);
|
|
30
|
+
};
|