Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ For pull requests, we use [GitConsensus](https://www.gitconsensus.com/) to allow
|TS| [Creep intent tracker.ts](/src/misc/TypeScript/Creep%20intent%20tracker.ts) |unfleshedone|intent tracker implementation|
|TS| [moving.average.ts](/src/misc/TypeScript/moving.average.ts) |unsleshedone|moving average implementation|
|TS| [Typescript roomScan.ts](/src/misc/TypeScript/Typescript%20roomScan.ts) |crzytrane|room scanner?|
|TS| [Typescript openingRampartsForAllies.ts](/src/misc/TypeScript/openingRampartsForAllies.ts) |Robalian|A function for opening ramparts for allied creeps moving through a room|
|| [migrate room to sim.md](/src/misc/migrate%20room%20to%20sim.md) |semperrabbit|how to migrate room to sim|
|| [screeps body calculator.md](/src/misc/screeps%20body%20calculator.md) |nitroevil|link to creep calculator|
|KT| [DistanceTransform](src/misc/Kotlin/DistanceTransform/) |Vipo|Algoritm for finding open areas in rooms|
Expand Down
60 changes: 60 additions & 0 deletions src/misc/TypeScript/openingRampartsForAllies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const ALLIES = new Set([
"ally 1",
"ally_2"
]);
const offsetX = [0, 0, 1, 1, 1, 0, -1, -1, -1];
const offsetY = [0, -1, -1, 0, 1, 1, 1, 0, -1];
// roomName, rampartIds
let rampartsToClose: Record<string, string[]> = {};
/**
* opens ramparts around creeps of whitelisted players
*
* as long as allies ignore your ramparts when pathfinding
* their creeps should have no problem going through your room
*/
export function letAlliesIn(room: Room) {
// init rampartsToClose for this room
if (!rampartsToClose[room.name]) {
rampartsToClose[room.name] = room.find(FIND_MY_STRUCTURES)
.filter(r => r.structureType === STRUCTURE_RAMPART && r.isPublic)
.map(r => r.id);
}
let alliesInRoom = room.find(FIND_HOSTILE_CREEPS).filter(c => ALLIES.has(c.owner.username));
// close ramparts and remove them from a list
rampartsToClose[room.name] = rampartsToClose[room.name].filter(rampartId => {
let r = Game.getObjectById<StructureRampart>(rampartId);
if (!r || !r.isPublic)
return false;
const anyAllyNearRamp = alliesInRoom.some(ally => ally.pos.isNearTo(r.pos) && !ally.pos.isEqualTo(r.pos));
if (anyAllyNearRamp)
return true;
r.setPublic(false);
return true;
});
let rampartCount = _.sum(room.find(FIND_MY_STRUCTURES), s => s.structureType === STRUCTURE_RAMPART ? 1 : 0);
if (alliesInRoom.length === 0 || rampartCount === 0)
return;
// might be a good idea
//if (isUnderAttack(room))
// return;
//
for (let ally of alliesInRoom) {
for (let dir = TOP; dir <= TOP_LEFT; ++dir) {
let x = ally.pos.x + offsetX[dir];
let y = ally.pos.y + offsetY[dir];
if (x < 0 || x > 49 || y < 0 || y > 49)
continue;
let rampartAtPos = room.lookForAt(LOOK_STRUCTURES, x, y).find(s => s.structureType === STRUCTURE_RAMPART) as StructureRampart;
if (rampartAtPos && rampartAtPos.my && !rampartAtPos.isPublic) {
rampartAtPos.setPublic(true);
rampartsToClose[room.name].push(rampartAtPos.id);
}
}
}
}