Skip to content

Commit 7f3680a

Browse files
authored
Merge branch 'screepers:master' into flexible-memory
2 parents 71d9d43 + 9d727de commit 7f3680a

File tree

5 files changed

+108
-11
lines changed

5 files changed

+108
-11
lines changed

dist/index.d.ts

+41-5
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ declare const PWR_OPERATE_FACTORY: PWR_OPERATE_FACTORY;
843843
declare const EFFECT_INVULNERABILITY: EFFECT_INVULNERABILITY;
844844
declare const EFFECT_COLLAPSE_TIMER: EFFECT_COLLAPSE_TIMER;
845845

846-
declare const INVADER_CORE_HITS: 1000000;
846+
declare const INVADER_CORE_HITS: 100000;
847847
declare const INVADER_CORE_CREEP_SPAWN_TIME: {
848848
0: 0;
849849
1: 0;
@@ -852,11 +852,24 @@ declare const INVADER_CORE_CREEP_SPAWN_TIME: {
852852
4: 2;
853853
5: 1;
854854
};
855-
declare const INVADER_CORE_EXPAND_TIME: 15000;
856-
declare const INVADER_CORE_CONTROLLER_POWER: 100;
855+
declare const INVADER_CORE_EXPAND_TIME: {
856+
1: 4000;
857+
2: 3500;
858+
3: 3000;
859+
4: 2500;
860+
5: 2000;
861+
};
862+
declare const INVADER_CORE_CONTROLLER_POWER: 2;
857863
declare const INVADER_CORE_CONTROLLER_DOWNGRADE: 5000;
858-
declare const STRONGHOLD_RAMPART_HITS: { 0: 0; 1: 50000; 2: 200000; 3: 500000; 4: 1000000; 5: 2000000 };
859-
declare const STRONGHOLD_DECAY_TICKS: 150000;
864+
declare const STRONGHOLD_RAMPART_HITS: {
865+
0: 0;
866+
1: 100000;
867+
2: 200000;
868+
3: 500000;
869+
4: 1000000;
870+
5: 2000000;
871+
};
872+
declare const STRONGHOLD_DECAY_TICKS: 75000;
860873

861874
declare const POWER_INFO: {
862875
[powerID: number]: {
@@ -2019,7 +2032,9 @@ declare namespace Tag {
20192032
private [OpaqueTagSymbol]: T;
20202033
}
20212034
}
2035+
20222036
type Id<T extends _HasId> = string & Tag.OpaqueTag<T>;
2037+
20232038
type fromId<T> = T extends Id<infer R> ? R : never;
20242039
/**
20252040
* `InterShardMemory` object provides an interface for communicating between shards.
@@ -4040,6 +4055,27 @@ interface RoomTerrain {
40404055
* @return number Number of terrain mask like: TERRAIN_MASK_SWAMP | TERRAIN_MASK_WALL
40414056
*/
40424057
get(x: number, y: number): 0 | TERRAIN_MASK_WALL | TERRAIN_MASK_SWAMP;
4058+
/**
4059+
* Get copy of underlying static terrain buffer.
4060+
* @param destinationArray (optional) A typed array view in which terrain will be copied to.
4061+
* @throws {RangeError} if `destinationArray` is provided, it must have a length of at least 2500 (`50*50`).
4062+
* @return Copy of underlying room terrain as a new typed array of size 2500.
4063+
*/
4064+
getRawBuffer<
4065+
T extends
4066+
| Int8Array
4067+
| Uint8Array
4068+
| Int16Array
4069+
| Uint16Array
4070+
| Int32Array
4071+
| Uint32Array
4072+
| Uint8ClampedArray
4073+
| Float32Array
4074+
| Float64Array,
4075+
>(
4076+
destinationArray: T,
4077+
): T;
4078+
getRawBuffer(): Uint8Array;
40434079
}
40444080

40454081
interface RoomTerrainConstructor extends _Constructor<RoomTerrain> {

dist/screeps-tests.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,10 @@ function resources(o: GenericStore): ResourceConstant[] {
11501150

11511151
const myTerrain = room.getTerrain();
11521152

1153+
const otherTerrain = new Room.Terrain("E2S7");
1154+
1155+
const anotherTerrain = Game.map.getRoomTerrain("W2N5");
1156+
11531157
const ret = myTerrain.get(5, 5);
11541158
if (ret === 0) {
11551159
/*plain*/
@@ -1161,7 +1165,28 @@ function resources(o: GenericStore): ResourceConstant[] {
11611165
/*wall*/
11621166
}
11631167

1164-
const enemyTerrain = new Room.Terrain("W2N5");
1168+
const myRawTerrain = myTerrain.getRawBuffer();
1169+
1170+
const otherRawTerrain = otherTerrain.getRawBuffer(new Int8Array(2500));
1171+
1172+
const anotherRawTerrain = anotherTerrain.getRawBuffer(new Uint16Array(2500));
1173+
1174+
for (const rawTerrain of [myRawTerrain, otherRawTerrain, anotherRawTerrain]) {
1175+
for (let y = 0; y < 50; y++) {
1176+
for (let x = 0; x < 50; x++) {
1177+
const code = rawTerrain[y * 50 + x];
1178+
if (code === 0) {
1179+
/*plain*/
1180+
}
1181+
if (code & TERRAIN_MASK_SWAMP) {
1182+
/*swamp*/
1183+
}
1184+
if (code & TERRAIN_MASK_WALL) {
1185+
/*wall*/
1186+
}
1187+
}
1188+
}
1189+
}
11651190
}
11661191

11671192
// Creep.body

src/constants.ts

+18-5
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ declare const PWR_OPERATE_FACTORY: PWR_OPERATE_FACTORY;
828828
declare const EFFECT_INVULNERABILITY: EFFECT_INVULNERABILITY;
829829
declare const EFFECT_COLLAPSE_TIMER: EFFECT_COLLAPSE_TIMER;
830830

831-
declare const INVADER_CORE_HITS: 1000000;
831+
declare const INVADER_CORE_HITS: 100000;
832832
declare const INVADER_CORE_CREEP_SPAWN_TIME: {
833833
0: 0;
834834
1: 0;
@@ -837,11 +837,24 @@ declare const INVADER_CORE_CREEP_SPAWN_TIME: {
837837
4: 2;
838838
5: 1;
839839
};
840-
declare const INVADER_CORE_EXPAND_TIME: 15000;
841-
declare const INVADER_CORE_CONTROLLER_POWER: 100;
840+
declare const INVADER_CORE_EXPAND_TIME: {
841+
1: 4000;
842+
2: 3500;
843+
3: 3000;
844+
4: 2500;
845+
5: 2000;
846+
};
847+
declare const INVADER_CORE_CONTROLLER_POWER: 2;
842848
declare const INVADER_CORE_CONTROLLER_DOWNGRADE: 5000;
843-
declare const STRONGHOLD_RAMPART_HITS: { 0: 0; 1: 50000; 2: 200000; 3: 500000; 4: 1000000; 5: 2000000 };
844-
declare const STRONGHOLD_DECAY_TICKS: 150000;
849+
declare const STRONGHOLD_RAMPART_HITS: {
850+
0: 0;
851+
1: 100000;
852+
2: 200000;
853+
3: 500000;
854+
4: 1000000;
855+
5: 2000000;
856+
};
857+
declare const STRONGHOLD_DECAY_TICKS: 75000;
845858

846859
declare const POWER_INFO: {
847860
[powerID: number]: {

src/helpers.ts

+2
Original file line numberDiff line numberDiff line change
@@ -433,5 +433,7 @@ declare namespace Tag {
433433
private [OpaqueTagSymbol]: T;
434434
}
435435
}
436+
436437
type Id<T extends _HasId> = string & Tag.OpaqueTag<T>;
438+
437439
type fromId<T> = T extends Id<infer R> ? R : never;

src/room-terrain.ts

+21
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,27 @@ interface RoomTerrain {
99
* @return number Number of terrain mask like: TERRAIN_MASK_SWAMP | TERRAIN_MASK_WALL
1010
*/
1111
get(x: number, y: number): 0 | TERRAIN_MASK_WALL | TERRAIN_MASK_SWAMP;
12+
/**
13+
* Get copy of underlying static terrain buffer.
14+
* @param destinationArray (optional) A typed array view in which terrain will be copied to.
15+
* @throws {RangeError} if `destinationArray` is provided, it must have a length of at least 2500 (`50*50`).
16+
* @return Copy of underlying room terrain as a new typed array of size 2500.
17+
*/
18+
getRawBuffer<
19+
T extends
20+
| Int8Array
21+
| Uint8Array
22+
| Int16Array
23+
| Uint16Array
24+
| Int32Array
25+
| Uint32Array
26+
| Uint8ClampedArray
27+
| Float32Array
28+
| Float64Array,
29+
>(
30+
destinationArray: T,
31+
): T;
32+
getRawBuffer(): Uint8Array;
1233
}
1334

1435
interface RoomTerrainConstructor extends _Constructor<RoomTerrain> {

0 commit comments

Comments
 (0)