@chronodivide/game-api 0.35.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,164 @@
1
+ # Changelog
2
+
3
+ # 0.35.0
4
+
5
+ - Update game engine version to 0.42
6
+
7
+ # 0.34.0
8
+
9
+ - Update game engine version to 0.41
10
+
11
+ # 0.33.0
12
+
13
+ - Update game engine version to 0.40
14
+
15
+ # 0.32.0
16
+
17
+ - Update game engine version to 0.39
18
+
19
+ # 0.31.0
20
+
21
+ - Update game engine version to 0.38
22
+
23
+ # 0.30.0
24
+
25
+ - Update game engine version to 0.37
26
+
27
+ # 0.29.0
28
+
29
+ - Update game engine version to 0.36
30
+
31
+ # 0.28.0
32
+
33
+ - Update game engine version to 0.35
34
+
35
+ # 0.27.0
36
+
37
+ - Update game engine version to 0.34
38
+
39
+ # 0.26.0
40
+
41
+ - Update game engine version to 0.33
42
+
43
+ # 0.25.0
44
+
45
+ - Add `gameApi.rulesApi`
46
+ - Add `UnitData.isWarpedOut`, `UnitData.mindControlledBy` and `UnitData.tntTimer`
47
+
48
+ # 0.24.0
49
+
50
+ - Update game engine version to 0.32
51
+
52
+ # 0.23.0
53
+
54
+ - Update game engine version to 0.31
55
+
56
+ # 0.22.0
57
+
58
+ - Update game engine version to 0.30
59
+
60
+ # 0.21.0
61
+
62
+ - Update game engine version to 0.29
63
+
64
+ # 0.20.0
65
+
66
+ - Update game engine version to 0.28
67
+
68
+ ## 0.19.0
69
+
70
+ - Update game engine version to 0.27
71
+
72
+ ## 0.18.0
73
+
74
+ - Update game engine version to 0.26
75
+
76
+ ## 0.17.0
77
+
78
+ - Update game engine version to 0.25
79
+
80
+ ## 0.16.0
81
+
82
+ - Update game engine version to 0.24
83
+
84
+ ## 0.15.0
85
+
86
+ - Add `gameApi.getAllSuperWeaponData` and `actionApi.activateSuperWeapon`
87
+ - Update game engine version to 0.19
88
+
89
+ ## 0.14.0
90
+
91
+ - **BREAKING**: Replace `gameInstanceApi.getTickMillis` and `gameApi.getTickMillis` with `getTickRate`
92
+ - **BREAKING**: Remove `gameApi.getSpeedMultiplier`
93
+ - **BREAKING**: When constructing a `Bot` instance or an `Agent` object, `country` must now be the country name from rules.ini (e.g. "Americans")
94
+
95
+ ## 0.13.0
96
+
97
+ - **BREAKING**: `gameApi.canPlaceBuilding` and `actionsApi.placeBuilding` now use the normalized (screen top) tile as parameter instead of center tile
98
+ - Update game engine version to 0.18
99
+
100
+ ## 0.12.0
101
+
102
+ - Add `gameInstanceApi.getCurrentTick`, `gameInstanceApi.getTickMillis` and `gameInstanceApi.getPlayerStats`
103
+
104
+ ## 0.11.0
105
+
106
+ - **BREAKING**: Remove `gameApi.actions`, `gameApi.getActions` and `gameApi.getProduction`
107
+ - **BREAKING**: Rename `gameApi.map` to `gameApi.mapApi`
108
+ - **BREAKING**: Rename `Bot.actions` to `Bot.actionsApi` and `Bot.production` to `Bot.productionApi`
109
+ - **BREAKING**: Move gameApi methods that where unrelated to game state into a separate `GameInstanceApi`, only accessible top-level via `cdapi.createGame`. `Bot` instances will no longer have implicit access to these methods. Game state is now available only within the `Bot` class.
110
+ - **BREAKING**: Consolidate `gameApi.waitForTick` and `game.tick` into a single `game.update` method
111
+ - Add `Bot.gameApi`
112
+
113
+ ## 0.10.0
114
+
115
+ - **BREAKING**: The `agents` option for `cdapi.createGame` must now contain `Bot` class instances for non-human players
116
+ - Bot code is now added by extending the base `Bot` class and overriding the `onGameStart`, `onGameTick` and `onGameEvent` methods. The `actions` and `production` properties provide access to scoped `actionsApi` and `productionApi` respectively.
117
+ - `mapApi.getTilesInRect` now properly filters out tiles which are outside the map boundaries
118
+ - Add `mapApi.getAllTilesResourceData` and `mapApi.getTileResourceData`
119
+ - Add `gameApi.getAllTerrainObjects`
120
+
121
+ ## Version 0.9.0
122
+
123
+ - Add `onBridge` optional argument to `actionsApi#orderUnits`
124
+ - Add `mapApi#hasBridgeOnTile` and `mapApi#hasHighBridgeOnTile` methods
125
+ - Add `gameApi.generateRandom` and `gameApi.generateRandomInt` methods
126
+ - **BREAKING**: `PlayerData.startLocation` now returns the start coords instead of the index into the startingLocations array
127
+ - **BREAKING**: `PlayerData.country` is now a `Country` object instead of the country name string
128
+ - **BREAKING**: `UnitData.owner` now returns the player name instead of the player index
129
+ - **BREAKING**: `PlayerData.isLowPower` is replaced by a `power` property which also includes the total power and drain
130
+ - Add doc-blocks to most API methods and interface properties
131
+
132
+ ## Version 0.8.1
133
+
134
+ - Add `gameApi.getBuildingPlacementData`
135
+ - Add `gameApi.getPlayers`
136
+ - Add `gameApi.getArtIni`
137
+
138
+ ## Version 0.8.0
139
+
140
+ - Add `gameApi.getActions`
141
+ - Add online mode
142
+
143
+ ## Version 0.7.4
144
+
145
+ - Add `gameApi.getSpeedMultiplier`
146
+ - Add `actionsApi.quitGame`
147
+ - Fix replays when actions are issued for multiple agents
148
+
149
+ ## Version 0.7.3
150
+
151
+ - Fix fatal error caused by a [Webpack compilation bug](https://github.com/webpack/webpack/pull/15246)
152
+ - Update game engine to version 0.17
153
+
154
+ ## Version 0.7.2
155
+
156
+ - Use the original game *.mix archives instead of the custom JSON files
157
+
158
+ ## Version 0.7.1
159
+
160
+ - Fix errors caused by special characters in replay file names
161
+
162
+ ## Version 0.7.0
163
+
164
+ - Initial version (game engine version 0.7)
package/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # Chrono Divide Game API
2
+
3
+ This is a TypeScript/JavaScript API and development sandbox for the [Chrono Divide](https://chronodivide.com) game engine. It can be used to develop and test AI bots by running the game headless, in an isolated command-line environment. The API can create offline games between computer-controlled agents, or even online games, played in real-time versus human opponents.
4
+
5
+ ## Prerequisites
6
+
7
+ * NodeJS 14+
8
+ * TypeScript 4.3.5+ (optional)
9
+ * MIX files from an original RA2 installation
10
+
11
+ ## Installation
12
+
13
+ ```
14
+ npm install @chronodivide/game-api
15
+ ```
16
+
17
+ ## Basic Usage
18
+
19
+ The following code example creates an offline game, between two AI agents, runs the simulation until the game ends, then saves the game replay and exits.
20
+
21
+ The bot implementation is not provided.
22
+
23
+ ```ts
24
+ import { cdapi, OrderType, ApiEventType, Bot, GameApi, ApiEvent } from "@chronodivide/game-api";
25
+
26
+ class ExampleBot extends Bot {}
27
+
28
+ async function main() {
29
+ const mapName = "mp03t4.map";
30
+
31
+ // Replace MIX_DIR with your original RA2 installation folder
32
+ await cdapi.init(process.env.MIX_DIR || "./");
33
+
34
+ const game = await cdapi.createGame({
35
+ agents: [
36
+ new ExampleBot("AgentRed", "Americans"),
37
+ new ExampleBot("AgentBlue", "French")
38
+ ],
39
+ buildOffAlly: false,
40
+ cratesAppear: false,
41
+ credits: 10000,
42
+ gameMode: cdapi.getAvailableGameModes(mapName)[0],
43
+ gameSpeed: 5,
44
+ mapName,
45
+ mcvRepacks: true,
46
+ shortGame: true,
47
+ superWeapons: false,
48
+ unitCount: 10
49
+ });
50
+
51
+ while (!game.isFinished()) {
52
+ await game.update();
53
+ }
54
+
55
+ game.saveReplay();
56
+ game.dispose();
57
+ }
58
+
59
+ main().catch(e => {
60
+ console.error(e);
61
+ process.exit(1);
62
+ });
63
+ ```
64
+
65
+ ## Online Games
66
+
67
+ Online games between an AI and a human opponent are also possible, but require a Chrono Divide server URL to connect to. Online games can be created with minimal changes to the `createGame` function from the previous example:
68
+
69
+ ```ts
70
+ const game = await cdapi.createGame({
71
+ online: true,
72
+ serverUrl: process.env.SERVER_URL!,
73
+ clientUrl: process.env.CLIENT_URL!,
74
+ agents: [
75
+ new ExampleBot(`Agent${String(Date.now()).substr(-6)}`, "Americans"),
76
+ { name: `Human${String(Date.now()).substr(-6)}`, country: "French" }
77
+ ],
78
+
79
+ buildOffAlly: false,
80
+ cratesAppear: false,
81
+ credits: 10000,
82
+ gameMode: cdapi.getAvailableGameModes(mapName)[0],
83
+ gameSpeed: 5,
84
+ mapName,
85
+ mcvRepacks: true,
86
+ shortGame: true,
87
+ superWeapons: false,
88
+ unitCount: 10
89
+ });
90
+ ```
91
+
92
+ ## API Reference
93
+
94
+ Please refer to the [TypeScript definitions](./dist/index.d.ts).