@civ-clone/base-unit-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.
Files changed (79) hide show
  1. package/.gitattributes +4 -0
  2. package/.github/workflows/build-on-push.yml +39 -0
  3. package/.prettierrc +4 -0
  4. package/LICENSE +21 -0
  5. package/README.md +61 -2
  6. package/lib/activate.d.ts +15 -0
  7. package/lib/activate.js +27 -0
  8. package/lib/activate.js.map +1 -0
  9. package/lib/activate.ts +47 -0
  10. package/lib/canStow.d.ts +8 -0
  11. package/lib/canStow.js +17 -0
  12. package/lib/canStow.js.map +1 -0
  13. package/lib/canStow.ts +25 -0
  14. package/lib/created.d.ts +9 -0
  15. package/lib/created.js +19 -0
  16. package/lib/created.js.map +1 -0
  17. package/lib/created.ts +24 -0
  18. package/lib/defeated.d.ts +25 -0
  19. package/lib/defeated.js +33 -0
  20. package/lib/defeated.js.map +1 -0
  21. package/lib/defeated.ts +55 -0
  22. package/lib/destroyed.d.ts +37 -0
  23. package/lib/destroyed.js +74 -0
  24. package/lib/destroyed.js.map +1 -0
  25. package/lib/destroyed.ts +106 -0
  26. package/lib/detonatedRules.d.ts +56 -0
  27. package/lib/detonatedRules.js +95 -0
  28. package/lib/detonatedRules.js.map +1 -0
  29. package/lib/detonatedRules.ts +196 -0
  30. package/lib/diplomatRules.d.ts +27 -0
  31. package/lib/diplomatRules.js +41 -0
  32. package/lib/diplomatRules.js.map +1 -0
  33. package/lib/diplomatRules.ts +83 -0
  34. package/lib/halted.d.ts +6 -0
  35. package/lib/halted.js +10 -0
  36. package/lib/halted.js.map +1 -0
  37. package/lib/halted.ts +11 -0
  38. package/lib/impassable.d.ts +8 -0
  39. package/lib/impassable.js +15 -0
  40. package/lib/impassable.js.map +1 -0
  41. package/lib/impassable.ts +19 -0
  42. package/lib/lifecycleRules.d.ts +118 -0
  43. package/lib/lifecycleRules.js +126 -0
  44. package/lib/lifecycleRules.js.map +1 -0
  45. package/lib/lifecycleRules.ts +378 -0
  46. package/lib/lostAtSea.d.ts +12 -0
  47. package/lib/lostAtSea.js +26 -0
  48. package/lib/lostAtSea.js.map +1 -0
  49. package/lib/lostAtSea.ts +37 -0
  50. package/lib/movedRules.d.ts +44 -0
  51. package/lib/movedRules.js +126 -0
  52. package/lib/movedRules.js.map +1 -0
  53. package/lib/movedRules.ts +300 -0
  54. package/lib/playerAction.d.ts +22 -0
  55. package/lib/playerAction.js +28 -0
  56. package/lib/playerAction.js.map +1 -0
  57. package/lib/playerAction.ts +64 -0
  58. package/lib/stowed.d.ts +2 -0
  59. package/lib/stowed.js +8 -0
  60. package/lib/stowed.js.map +1 -0
  61. package/lib/stowed.ts +6 -0
  62. package/lib/treatyPartner.d.ts +26 -0
  63. package/lib/treatyPartner.js +38 -0
  64. package/lib/treatyPartner.js.map +1 -0
  65. package/lib/treatyPartner.ts +78 -0
  66. package/lib/unsupported.d.ts +6 -0
  67. package/lib/unsupported.js +9 -0
  68. package/lib/unsupported.js.map +1 -0
  69. package/lib/unsupported.ts +10 -0
  70. package/lib/validateMove.d.ts +11 -0
  71. package/lib/validateMove.js +26 -0
  72. package/lib/validateMove.js.map +1 -0
  73. package/lib/validateMove.ts +36 -0
  74. package/package.json +61 -4
  75. package/tests/fixtures/civ1-unit-rules.json +89 -0
  76. package/tests/lifecycle.test.ts +657 -0
  77. package/tests/movedRules.test.ts +256 -0
  78. package/tests/rules.test.ts +434 -0
  79. package/tsconfig.json +16 -0
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.spendShort = exports.shortOfMovesFor = exports.spendMoves = exports.hasMovesFor = void 0;
4
+ const moveShortfall_1 = require("@civ-clone/base-unit-action-rules/lib/moveShortfall");
5
+ // What a ruleset's `ValidateMove` rules ask and do when `unit` makes a step costing `movementCost` moves.
6
+ // The unit has the moves the step costs.
7
+ const hasMovesFor = (unit, movementCost) => unit.moves().value() >= movementCost;
8
+ exports.hasMovesFor = hasMovesFor;
9
+ // Spends the moves the step costs. The step succeeds.
10
+ const spendMoves = (unit, movementCost) => {
11
+ unit.moves().subtract(movementCost);
12
+ return true;
13
+ };
14
+ exports.spendMoves = spendMoves;
15
+ // The unit is short of the moves the step costs.
16
+ const shortOfMovesFor = (unit, movementCost) => unit.moves().value() < movementCost;
17
+ exports.shortOfMovesFor = shortOfMovesFor;
18
+ // Spends all the unit's remaining moves on a step it is short of moves for, and says whether it gets there
19
+ // (`succeedsShort`, with `shortfallFactor` and a draw of `randomNumberGenerator`).
20
+ const spendShort = (shortfallFactor, randomNumberGenerator) => (unit, movementCost) => {
21
+ const remainingMoves = unit.moves().value();
22
+ unit.moves().set(0);
23
+ return (0, moveShortfall_1.succeedsShort)(remainingMoves, movementCost, shortfallFactor, randomNumberGenerator);
24
+ };
25
+ exports.spendShort = spendShort;
26
+ //# sourceMappingURL=validateMove.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validateMove.js","sourceRoot":"","sources":["validateMove.ts"],"names":[],"mappings":";;;AACA,uFAAoF;AAEpF,0GAA0G;AAE1G,yCAAyC;AAClC,MAAM,WAAW,GAAG,CAAC,IAAU,EAAE,YAAoB,EAAW,EAAE,CACvE,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,IAAI,YAAY,CAAC;AAD1B,QAAA,WAAW,eACe;AAEvC,sDAAsD;AAC/C,MAAM,UAAU,GAAG,CAAC,IAAU,EAAE,YAAoB,EAAW,EAAE;IACtE,IAAI,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;IAEpC,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAJW,QAAA,UAAU,cAIrB;AAEF,iDAAiD;AAC1C,MAAM,eAAe,GAAG,CAAC,IAAU,EAAE,YAAoB,EAAW,EAAE,CAC3E,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,GAAG,YAAY,CAAC;AADzB,QAAA,eAAe,mBACU;AAEtC,2GAA2G;AAC3G,oFAAoF;AAC7E,MAAM,UAAU,GACrB,CAAC,eAAuB,EAAE,qBAAmC,EAAE,EAAE,CACjE,CAAC,IAAU,EAAE,YAAoB,EAAW,EAAE;IAC5C,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,CAAC;IAE5C,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAEpB,OAAO,IAAA,6BAAa,EAClB,cAAc,EACd,YAAY,EACZ,eAAe,EACf,qBAAqB,CACtB,CAAC;AACJ,CAAC,CAAC;AAbS,QAAA,UAAU,cAanB"}
@@ -0,0 +1,36 @@
1
+ import Unit from '@civ-clone/core-unit/Unit';
2
+ import { succeedsShort } from '@civ-clone/base-unit-action-rules/lib/moveShortfall';
3
+
4
+ // What a ruleset's `ValidateMove` rules ask and do when `unit` makes a step costing `movementCost` moves.
5
+
6
+ // The unit has the moves the step costs.
7
+ export const hasMovesFor = (unit: Unit, movementCost: number): boolean =>
8
+ unit.moves().value() >= movementCost;
9
+
10
+ // Spends the moves the step costs. The step succeeds.
11
+ export const spendMoves = (unit: Unit, movementCost: number): boolean => {
12
+ unit.moves().subtract(movementCost);
13
+
14
+ return true;
15
+ };
16
+
17
+ // The unit is short of the moves the step costs.
18
+ export const shortOfMovesFor = (unit: Unit, movementCost: number): boolean =>
19
+ unit.moves().value() < movementCost;
20
+
21
+ // Spends all the unit's remaining moves on a step it is short of moves for, and says whether it gets there
22
+ // (`succeedsShort`, with `shortfallFactor` and a draw of `randomNumberGenerator`).
23
+ export const spendShort =
24
+ (shortfallFactor: number, randomNumberGenerator: () => number) =>
25
+ (unit: Unit, movementCost: number): boolean => {
26
+ const remainingMoves = unit.moves().value();
27
+
28
+ unit.moves().set(0);
29
+
30
+ return succeedsShort(
31
+ remainingMoves,
32
+ movementCost,
33
+ shortfallFactor,
34
+ randomNumberGenerator
35
+ );
36
+ };
package/package.json CHANGED
@@ -1,6 +1,63 @@
1
1
  {
2
2
  "name": "@civ-clone/base-unit-lifecycle",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Building blocks for a ruleset's unit lifecycle rules: what happens when a unit is created, activated, moved, stowed aboard a transport, halted, defeated, destroyed, lost at sea or left unsupported, and which of a player's units can take orders. The ruleset keeps its own rules, ids and order, and builds their criteria and effects from these.",
5
+ "repository": "git@github.com:civ-clone/base-unit-lifecycle.git",
6
+ "keywords": [
7
+ "typescript",
8
+ "civilization"
9
+ ],
10
+ "author": "dom111 <dom111@users.noreply.github.com>",
11
+ "license": "MIT",
12
+ "private": false,
13
+ "scripts": {
14
+ "build": "npm run ts:compile && npm run prettier:format",
15
+ "prettier:check": "prettier --config .prettierrc --check '**/*.ts'",
16
+ "prettier:format": "prettier --config .prettierrc '**/*.ts' --write",
17
+ "test": "ts-mocha ./tests/*.test.ts",
18
+ "ts:compile": "tsc --build tsconfig.json"
19
+ },
20
+ "devDependencies": {
21
+ "@types/chai": "^4.0.0",
22
+ "@types/mocha": "^10.0.0",
23
+ "@types/node": "^16.0.0",
24
+ "chai": "^4.0.0",
25
+ "mocha": "^10.0.0",
26
+ "prettier": "^2.8.8",
27
+ "ts-mocha": "^10.0.0",
28
+ "typescript": "^4.0.0"
29
+ },
30
+ "dependencies": {
31
+ "@civ-clone/base-unit-action-embark": "^0.1.0",
32
+ "@civ-clone/base-unit-action-establish-embassy": "^0.1.0",
33
+ "@civ-clone/base-unit-action-goto": "^0.1.9",
34
+ "@civ-clone/base-unit-action-investigate-city": "^0.1.0",
35
+ "@civ-clone/base-unit-action-meet-with-leader": "^0.1.0",
36
+ "@civ-clone/base-unit-action-nuclear-attack": "^0.1.0",
37
+ "@civ-clone/base-unit-action-rules": "^0.1.5",
38
+ "@civ-clone/base-unit-action-sleep": "^0.1.0",
39
+ "@civ-clone/base-unit-trait-attack-ends-turn": "^0.1.0",
40
+ "@civ-clone/base-unit-trait-carries": "^0.1.0",
41
+ "@civ-clone/base-unit-trait-coast-bound": "^0.1.0",
42
+ "@civ-clone/base-unit-trait-non-combatant": "^0.1.0",
43
+ "@civ-clone/base-unit-type-air": "^0.1.0",
44
+ "@civ-clone/base-unit-type-land": "^0.1.0",
45
+ "@civ-clone/base-unit-type-naval-transport": "^0.1.3",
46
+ "@civ-clone/core-city": "^0.1.19",
47
+ "@civ-clone/core-city-growth": "^0.1.6",
48
+ "@civ-clone/core-diplomacy": "^0.1.8",
49
+ "@civ-clone/core-engine": "^0.1.0",
50
+ "@civ-clone/core-player": "^0.1.0",
51
+ "@civ-clone/core-random": "^0.1.2",
52
+ "@civ-clone/core-rule": "^0.1.9",
53
+ "@civ-clone/core-terrain": "^0.1.0",
54
+ "@civ-clone/core-tile-improvement": "^0.1.6",
55
+ "@civ-clone/core-turn-based-game": "^0.1.10",
56
+ "@civ-clone/core-unit": "^0.1.31",
57
+ "@civ-clone/core-unit-improvement": "^0.1.0",
58
+ "@civ-clone/core-unit-transport": "^0.1.8",
59
+ "@civ-clone/core-world": "^0.1.0",
60
+ "@civ-clone/core-world-path": "^0.1.3",
61
+ "@civ-clone/library-diplomacy": "^0.1.4"
62
+ }
63
+ }
@@ -0,0 +1,89 @@
1
+ {
2
+ "Rules/Unit/activate": [
3
+ ["civ1-unit:unit/activate/has-moves", "Activate", 2000, 1],
4
+ ["civ1-unit:unit/activate/clear-busy", "Activate", 2000, 1],
5
+ ["civ1-unit:unit/activate/remove-improvement/Fortified", "Activate", 2000, 1]
6
+ ],
7
+ "Rules/Unit/canStow": [
8
+ ["civ1-unit:unit/can-stow/Land", "CanStow", 2000, 1],
9
+ ["civ1-unit:unit/can-stow/Air", "CanStow", 2000, 1]
10
+ ],
11
+ "Rules/Unit/created": [
12
+ ["civ1-unit:unit/created/register", "Created", 2000, 0],
13
+ ["civ1-unit:unit/created/apply-visibility", "Created", 2000, 0],
14
+ ["civ1-unit:unit/created/set-moves", "Created", 2000, 0],
15
+ ["civ1-unit:unit/created/emit", "Created", 2000, 0]
16
+ ],
17
+ "Rules/Unit/defeated": [
18
+ ["civ1-unit:unit/defeated/emit-and-destroy", "Defeated", 2000, 0],
19
+ ["civ1-unit:unit/defeated/destroy-stack", "Defeated", 2000, 3]
20
+ ],
21
+ "Rules/Unit/destroyed": [
22
+ ["civ1-unit:unit/destroyed/emit", "Destroyed", 2000, 0],
23
+ ["civ1-unit:unit/destroyed/count-loss", "Destroyed", 2000, 2],
24
+ ["civ1-unit:unit/destroyed/deactivate", "Destroyed", 2000, 0],
25
+ ["civ1-unit:unit/destroyed/remove-improvements", "Destroyed", 2000, 0],
26
+ ["civ1-unit:unit/destroyed/lose-cargo", "Destroyed", 2000, 1],
27
+ ["civ1-unit:unit/destroyed/leave-transport", "Destroyed", 2000, 1]
28
+ ],
29
+ "Rules/Unit/expectedMovementCost": [
30
+ ["civ1-unit:unit/expected-movement-cost/shortfall", "ExpectedMovementCost", 2000, 1]
31
+ ],
32
+ "Rules/Unit/halted": [
33
+ ["civ1-unit:unit/halted/emit", "Halted", 2000, 0]
34
+ ],
35
+ "Rules/Unit/impassable": [
36
+ ["civ1-unit:unit/impassable/treaty-partners-land", "Impassable", 2000, 2]
37
+ ],
38
+ "Rules/Unit/lostAtSea": [
39
+ ["civ1-unit:unit/lost-at-sea/emit", "LostAtSea", 2000, 0],
40
+ ["civ1-unit:unit/lost-at-sea/count-loss", "LostAtSea", 2000, 0],
41
+ ["civ1-unit:unit/lost-at-sea/destroy", "LostAtSea", 2000, 0]
42
+ ],
43
+ "Rules/Player/action": [
44
+ ["civ1-unit:player/action/active-units", "Action", 2000, 1],
45
+ ["civ1-unit:player/action/inactive-units", "Action", 2000, 1]
46
+ ],
47
+ "Rules/Unit/stowed": [
48
+ ["civ1-unit:unit/stowed/sleep", "Stowed", 2000, 0]
49
+ ],
50
+ "Rules/Unit/transferred": [
51
+ ["civ1-unit:unit/transferred/start-afresh", "Transferred", 2000, 0],
52
+ ["civ1-unit:unit/transferred/emit", "Transferred", 2000, 0]
53
+ ],
54
+ "Rules/Unit/unsupported": [
55
+ ["civ1-unit:unit/unsupported/emit", "Unsupported", 2000, 0]
56
+ ],
57
+ "Rules/Unit/validateMove": [
58
+ ["civ1-unit:unit/validate-move/enough-moves", "ValidateMove", 2000, 1],
59
+ ["civ1-unit:unit/validate-move/not-enough-moves", "ValidateMove", 2000, 1]
60
+ ],
61
+ "Rules/Unit/moved": [
62
+ ["civ1-unit:unit/moved/emit", "Moved", 2000, 0],
63
+ ["civ1-unit:unit/moved/apply-visibility", "Moved", 2000, 0],
64
+ ["civ1-unit:unit/moved/end-moves-when-exhausted", "Moved", 2000, 1],
65
+ ["civ1-unit:unit/moved/move-cargo", "Moved", 2000, 3],
66
+ ["civ1-unit:unit/moved/collect-aircraft", "Moved", 2000, 4],
67
+ ["civ1-unit:unit/moved/collect-sleeping", "Moved", 2000, 4],
68
+ ["civ1-unit:unit/moved/disembark", "Moved", 2000, 1],
69
+ ["civ1-unit:unit/moved/take-off", "Moved", 2000, 4],
70
+ ["civ1-unit:unit/moved/trireme-lost-at-sea", "Moved", 2000, 4],
71
+ ["civ1-unit:unit/moved/bomber/end-turn-after-attack", "Moved", 1000, 2],
72
+ ["civ1-unit:unit/moved/break-peace-treaty", "Moved", 2000, 1]
73
+ ],
74
+ "Rules/Unit/detonated": [
75
+ ["civ1-unit:unit/detonated/emit", "Detonated", 1000, 0],
76
+ ["civ1-unit:unit/detonated/destroy-units", "Detonated", 2000, 0],
77
+ ["civ1-unit:unit/detonated/halve-cities", "Detonated", 2500, 0],
78
+ ["civ1-unit:unit/detonated/fallout", "Detonated", 3000, 0]
79
+ ],
80
+ "Rules/Unit/diplomat": [
81
+ ["civ1-unit:unit/embassy-established/register", "EmbassyEstablished", 2000, 0],
82
+ ["civ1-unit:unit/city-investigated/emit", "CityInvestigated", 2000, 0],
83
+ ["civ1-unit:unit/leader-met/meet", "LeaderMet", 2000, 0],
84
+ ["civ1-unit:unit/technology-stolen/steal", "TechnologyStolen", 2000, 0],
85
+ ["civ1-unit:unit/city-sabotaged/sabotage", "CitySabotaged", 2000, 0],
86
+ ["civ1-unit:unit/revolt-incited/capture", "RevoltIncited", 2000, 0],
87
+ ["civ1-unit:unit/unit-bribed/transfer", "UnitBribed", 2000, 0]
88
+ ]
89
+ }