Skip to content

Commit

Permalink
Merge branch 'screepers:master' into flexible-memory
Browse files Browse the repository at this point in the history
  • Loading branch information
Jomik authored Dec 22, 2023
2 parents 71d9d43 + 9d727de commit 7f3680a
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 11 deletions.
46 changes: 41 additions & 5 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ declare const PWR_OPERATE_FACTORY: PWR_OPERATE_FACTORY;
declare const EFFECT_INVULNERABILITY: EFFECT_INVULNERABILITY;
declare const EFFECT_COLLAPSE_TIMER: EFFECT_COLLAPSE_TIMER;

declare const INVADER_CORE_HITS: 1000000;
declare const INVADER_CORE_HITS: 100000;
declare const INVADER_CORE_CREEP_SPAWN_TIME: {
0: 0;
1: 0;
Expand All @@ -852,11 +852,24 @@ declare const INVADER_CORE_CREEP_SPAWN_TIME: {
4: 2;
5: 1;
};
declare const INVADER_CORE_EXPAND_TIME: 15000;
declare const INVADER_CORE_CONTROLLER_POWER: 100;
declare const INVADER_CORE_EXPAND_TIME: {
1: 4000;
2: 3500;
3: 3000;
4: 2500;
5: 2000;
};
declare const INVADER_CORE_CONTROLLER_POWER: 2;
declare const INVADER_CORE_CONTROLLER_DOWNGRADE: 5000;
declare const STRONGHOLD_RAMPART_HITS: { 0: 0; 1: 50000; 2: 200000; 3: 500000; 4: 1000000; 5: 2000000 };
declare const STRONGHOLD_DECAY_TICKS: 150000;
declare const STRONGHOLD_RAMPART_HITS: {
0: 0;
1: 100000;
2: 200000;
3: 500000;
4: 1000000;
5: 2000000;
};
declare const STRONGHOLD_DECAY_TICKS: 75000;

declare const POWER_INFO: {
[powerID: number]: {
Expand Down Expand Up @@ -2019,7 +2032,9 @@ declare namespace Tag {
private [OpaqueTagSymbol]: T;
}
}

type Id<T extends _HasId> = string & Tag.OpaqueTag<T>;

type fromId<T> = T extends Id<infer R> ? R : never;
/**
* `InterShardMemory` object provides an interface for communicating between shards.
Expand Down Expand Up @@ -4040,6 +4055,27 @@ interface RoomTerrain {
* @return number Number of terrain mask like: TERRAIN_MASK_SWAMP | TERRAIN_MASK_WALL
*/
get(x: number, y: number): 0 | TERRAIN_MASK_WALL | TERRAIN_MASK_SWAMP;
/**
* Get copy of underlying static terrain buffer.
* @param destinationArray (optional) A typed array view in which terrain will be copied to.
* @throws {RangeError} if `destinationArray` is provided, it must have a length of at least 2500 (`50*50`).
* @return Copy of underlying room terrain as a new typed array of size 2500.
*/
getRawBuffer<
T extends
| Int8Array
| Uint8Array
| Int16Array
| Uint16Array
| Int32Array
| Uint32Array
| Uint8ClampedArray
| Float32Array
| Float64Array,
>(
destinationArray: T,
): T;
getRawBuffer(): Uint8Array;
}

interface RoomTerrainConstructor extends _Constructor<RoomTerrain> {
Expand Down
27 changes: 26 additions & 1 deletion dist/screeps-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,10 @@ function resources(o: GenericStore): ResourceConstant[] {

const myTerrain = room.getTerrain();

const otherTerrain = new Room.Terrain("E2S7");

const anotherTerrain = Game.map.getRoomTerrain("W2N5");

const ret = myTerrain.get(5, 5);
if (ret === 0) {
/*plain*/
Expand All @@ -1161,7 +1165,28 @@ function resources(o: GenericStore): ResourceConstant[] {
/*wall*/
}

const enemyTerrain = new Room.Terrain("W2N5");
const myRawTerrain = myTerrain.getRawBuffer();

const otherRawTerrain = otherTerrain.getRawBuffer(new Int8Array(2500));

const anotherRawTerrain = anotherTerrain.getRawBuffer(new Uint16Array(2500));

for (const rawTerrain of [myRawTerrain, otherRawTerrain, anotherRawTerrain]) {
for (let y = 0; y < 50; y++) {
for (let x = 0; x < 50; x++) {
const code = rawTerrain[y * 50 + x];
if (code === 0) {
/*plain*/
}
if (code & TERRAIN_MASK_SWAMP) {
/*swamp*/
}
if (code & TERRAIN_MASK_WALL) {
/*wall*/
}
}
}
}
}

// Creep.body
Expand Down
23 changes: 18 additions & 5 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ declare const PWR_OPERATE_FACTORY: PWR_OPERATE_FACTORY;
declare const EFFECT_INVULNERABILITY: EFFECT_INVULNERABILITY;
declare const EFFECT_COLLAPSE_TIMER: EFFECT_COLLAPSE_TIMER;

declare const INVADER_CORE_HITS: 1000000;
declare const INVADER_CORE_HITS: 100000;
declare const INVADER_CORE_CREEP_SPAWN_TIME: {
0: 0;
1: 0;
Expand All @@ -837,11 +837,24 @@ declare const INVADER_CORE_CREEP_SPAWN_TIME: {
4: 2;
5: 1;
};
declare const INVADER_CORE_EXPAND_TIME: 15000;
declare const INVADER_CORE_CONTROLLER_POWER: 100;
declare const INVADER_CORE_EXPAND_TIME: {
1: 4000;
2: 3500;
3: 3000;
4: 2500;
5: 2000;
};
declare const INVADER_CORE_CONTROLLER_POWER: 2;
declare const INVADER_CORE_CONTROLLER_DOWNGRADE: 5000;
declare const STRONGHOLD_RAMPART_HITS: { 0: 0; 1: 50000; 2: 200000; 3: 500000; 4: 1000000; 5: 2000000 };
declare const STRONGHOLD_DECAY_TICKS: 150000;
declare const STRONGHOLD_RAMPART_HITS: {
0: 0;
1: 100000;
2: 200000;
3: 500000;
4: 1000000;
5: 2000000;
};
declare const STRONGHOLD_DECAY_TICKS: 75000;

declare const POWER_INFO: {
[powerID: number]: {
Expand Down
2 changes: 2 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,5 +433,7 @@ declare namespace Tag {
private [OpaqueTagSymbol]: T;
}
}

type Id<T extends _HasId> = string & Tag.OpaqueTag<T>;

type fromId<T> = T extends Id<infer R> ? R : never;
21 changes: 21 additions & 0 deletions src/room-terrain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@ interface RoomTerrain {
* @return number Number of terrain mask like: TERRAIN_MASK_SWAMP | TERRAIN_MASK_WALL
*/
get(x: number, y: number): 0 | TERRAIN_MASK_WALL | TERRAIN_MASK_SWAMP;
/**
* Get copy of underlying static terrain buffer.
* @param destinationArray (optional) A typed array view in which terrain will be copied to.
* @throws {RangeError} if `destinationArray` is provided, it must have a length of at least 2500 (`50*50`).
* @return Copy of underlying room terrain as a new typed array of size 2500.
*/
getRawBuffer<
T extends
| Int8Array
| Uint8Array
| Int16Array
| Uint16Array
| Int32Array
| Uint32Array
| Uint8ClampedArray
| Float32Array
| Float64Array,
>(
destinationArray: T,
): T;
getRawBuffer(): Uint8Array;
}

interface RoomTerrainConstructor extends _Constructor<RoomTerrain> {
Expand Down

0 comments on commit 7f3680a

Please sign in to comment.