Skip to content

Commit

Permalink
2.1 (#7)
Browse files Browse the repository at this point in the history
* don't stockpile resources if you're not a boost producing room

* add automated nuking

* tweak threat level cutoffs

* add a notification for MAD nukes

* tweak expansion room rating

* Fix threat detection

* Fix threat detection

* Fix threat detection

* Tweak when low power mode happens

* add a pixel buffer setting and fix resource balancing

* tweak low power triggers

* hopefully fix safemode

* add a low priority response to unarmed visitors

* beefy drones > a bunch of small ones

* fix fillers not spawning correctly

* tweak when factories operate

* remove randomness from structure cache

* remove redundant function

* tweak the sk check

* fix sk hostile listing

* praise rooms are a thing again

* commodity cleanup

* power healer pairing

* simplify remote hauler drop off

* make sure it's sitting in the right spot pre container

* add a check for energy rich rooms

* tweak sk response

* tweak sk response

* tweak hauler deliveries

* tweak hauler deliveries

* HOTFIX: Fix "this" error

* Fix storing extensions

* Fix edge case where response requests don't get cleared

* spawning border patrol already has a desto

* tweak how remote haulers pick destos

* add a check to the canIWin function

* tweak auto nuking

* tweak remote mining

* tweak hauler priorities

* fix source and mineral boosting

* tweak randomness

* Prettier

* Prettier

* Prettier

* Prettier

* prettier

* prettier

* prettier

* Revert "prettier"

This reverts commit 321f777.

* Revert "prettier"

This reverts commit 8012ab4.

* Revert "prettier"

This reverts commit bf6a6dd.

* Revert "Prettier"

This reverts commit 2620a37.

* Revert "Prettier"

This reverts commit 29ca2c8.

* Revert "Prettier"

This reverts commit cb300f1.

* Revert "Prettier"

This reverts commit 7cc9103.

* add a creep count cache

* tweak expansion scoring

* cpu saving tweaks

* cpu saving tweaks

* cpu saving tweaks

* only safemode for combat creeps

* add maintenance body

* add towing to a pos

* fix unreachable tower on template 5

* add a lab hub for layouts with no labs

* track source ranges for expansion considerations

* deliver to nearest room

* efficiency tweaks

* update ignore

* up default combat limit

* tweak room assist priority

* debug why expansion gets stuck

* remove bucket check for remote creep spawning

* tweak safemode

* fix invader core response

* fix invader core response

* op cleanup

* cpu saver

* cpu saver

* body tweak

* add map hud

* fix impassible to include creeps

* bugfix for sale term

* tweak when builders needed

* remove debug logging

* add a highway check for pathing when in a novice/respawn area

* cpu tweaks

* cleanup main.js

* move route/path cache to memory and fix cleanup

* move route/path cache to memory and fix cleanup

* global/config cleanup

* commodity tweak

* warfare tweaks

* cpu tasking 1.0

* cleanup config

* combat tweaks

* misc

* marauders should group up

* fix priorities

* cleanup memory entries

* fix startup

* clean mem entries

* misc cleanup

* misc cleanup

* code cleanup

* don't try to ranger unreachable rooms

* I don't remember all the changes.. but border patrol, basic pairing, energy tweaks, body tweaks

* new combat pair code

* spawn tweaks

* misc tweaks

* 2.0.4 final additions

* tweak room selection to avoid getting stuck

* tweak pair movement

* only 2 upgraders with link

* bug fixing

* bug fixing

* bug fixing

* add a claim check

* add a claim check

* add a claim check

* bug fixing

* bug fixing

* seasonal changes

* Bug fixing

* Bug fixing

* harvs will still fill containers if they dont have enough outlet links

* work on getting creep count down

* work on getting creep count down

* work on getting creep count down

* work on getting creep count down

* Bug fixing

* Bug fixing

* seasonal bug fixing

* seasonal bug fixing

* seasonal bug fixing

* seasonal bug fixing

* seasonal bug fixing

* seasonal bug fixing

* seasonal bug fixing

* seasonal bug fixing

* seasonal bug fixing

* seasonal bug fixing

* swc fixing

* swc fixing

* swc fixing

* swc fixing

* swc fixing

* swc fixing

* swc fixing

* season fixing

* season fixing
  • Loading branch information
shibdib authored Mar 20, 2021
1 parent 4fd4ef5 commit 26592f0
Show file tree
Hide file tree
Showing 75 changed files with 4,453 additions and 3,303 deletions.
12 changes: 7 additions & 5 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ module.exports = function (grunt) {

grunt.loadNpmTasks('grunt-screeps');

if (host !== 'mmo') {
if (host !== 'mmo' && !options.token) {
let port = 21025;
if (options.port) port = options.port;
grunt.initConfig({
screeps: {
options: {
server: {
host: options.host,
port: 21025,
port: port,
http: true
},
email: options.email,
Expand All @@ -28,10 +30,10 @@ module.exports = function (grunt) {
grunt.initConfig({
screeps: {
options: {
email: options.email,
password: options.password,
token: options.token,
branch: options.branch,
ptr: options.ptr
ptr: options.ptr,
season: options.season
},
dist: {
src: ['src/*.js']
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
"version": "0.0.1",
"dependencies": {
"grunt": "latest",
"grunt-screeps": "latest",
"nodejs": "latest",
"screeps-api": "latest"
"screeps-api": "^1.13.0"
},
"devDependencies": {
"grunt-screeps": "github:psy3727/grunt-screeps#season-updates"
}
}
40 changes: 0 additions & 40 deletions src/callback.js

This file was deleted.

7 changes: 3 additions & 4 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
global.COMBAT_SERVER = []; // Insert the Game.shard.name of servers you'd like to declare everyone hostile
global.HOSTILES = []; // Manually set players as hostile
global.MANUAL_FRIENDS = []; // Manually set players as friends (overrides COMBAT_SERVER)
global.RAMPART_ACCESS = false // Allow friends and allies access thru ramparts
global.NAP_ALLIANCE = []; // Do not attack members of this alliance
global.HOLD_SECTOR = false; // Attack rooms in sectors you have rooms (ignores local sphere)
global.ATTACK_LOCALS = true; // Attacks targets within range of the next entry
global.LOCAL_SPHERE = 2; // Range that rooms consider local via linear distance
global.NEW_SPAWN_DENIAL = true; // Crush new spawns immediately
Expand All @@ -28,9 +30,6 @@ global.EXPLORED_ROOM_SIGNS = ["Automated Exploration Occurred Here", "Just sayin
global.ATTACK_ROOM_SIGNS = ["~~ALL YOUR BASE BELONG TO ME~~"];
global.EXPLORER_SPAM = ['HI', 'Hello', 'Beep', 'Boop', 'Aloha', 'Shibby!'];

// Attack limits (Too high and your CPU is screwed, hard coded for non subs)
global.COMBAT_LIMIT = 3;

// Wall and rampart target amounts
global.BARRIER_TARGET_HIT_POINTS = {
1: 1000,
Expand All @@ -52,7 +51,7 @@ global.BUY_THESE_BOOSTS = [RESOURCE_GHODIUM_ACID, RESOURCE_KEANIUM_ALKALIDE, RES
global.PIXEL_BUFFER = 500; // Sell any pixels above this amount
global.BUY_ENERGY = true; // If true it will buy energy at anything below the baseline energy price if a room isn't considered in surplus
global.CREDIT_BUFFER = 10000; // Stay above
global.ENERGY_AMOUNT = (TERMINAL_CAPACITY * 0.1 + STORAGE_CAPACITY * 0.025); // Aim for this amount in a room
global.ENERGY_AMOUNT = (TERMINAL_CAPACITY * 0.1 + STORAGE_CAPACITY * 0.1); // Aim for this amount in a room
global.FACTORY_CUTOFF = ENERGY_AMOUNT * 0.5; // Amount needed for a factory to be active
global.MINERAL_TRADE_AMOUNT = (TERMINAL_CAPACITY * 0.015 + STORAGE_CAPACITY * 0.015); // Hold this much of a mineral before selling
global.BOOST_TRADE_AMOUNT = (TERMINAL_CAPACITY * 0.01 + STORAGE_CAPACITY * 0.01); // Hold this much of a mineral before selling
Expand Down
139 changes: 123 additions & 16 deletions src/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let globals = function () {
try {
require(Game.shard.name);
console.log('Loaded config for ' + Game.shard.name);
if (_.includes(COMBAT_SERVER, Game.shard.name)) console.log('Combat Server Mode Active - All Players Considered Hostile');
} catch (e) {
try {
require(Memory.customConfig);
Expand All @@ -27,7 +28,7 @@ let globals = function () {
global.DESIRED_LOGGING_LEVEL = 4; //Set level 1-5 (5 being most info)
global.STATUS_COOLDOWN = 180; // Seconds between console status reports
global.ROOM_ABANDON_THRESHOLD = 7250; // If bucket is consistently below this, abandon your lowest room
global.SIGN_CLEANER = true; // Clean room signs away with explorers
global.SIGN_CLEANER = false; // Clean room signs away with explorers

// Energy income breakdown
global.ROOM_ENERGY_ALLOTMENT = {
Expand All @@ -39,15 +40,15 @@ let globals = function () {
};

// Pathfinder Cache Sizes
global.PATH_CACHE_SIZE = 1500;
global.ROUTE_CACHE_SIZE = 100;
global.PATH_CACHE_SIZE = 1000;
global.ROUTE_CACHE_SIZE = 200;

// Reaction
global.TIER_3_BOOSTS = [RESOURCE_CATALYZED_GHODIUM_ALKALIDE, RESOURCE_CATALYZED_GHODIUM_ACID, RESOURCE_CATALYZED_ZYNTHIUM_ACID, RESOURCE_CATALYZED_UTRIUM_ACID, RESOURCE_CATALYZED_LEMERGIUM_ALKALIDE, RESOURCE_CATALYZED_KEANIUM_ALKALIDE, RESOURCE_CATALYZED_KEANIUM_ACID, RESOURCE_CATALYZED_LEMERGIUM_ACID, RESOURCE_CATALYZED_UTRIUM_ALKALIDE, RESOURCE_CATALYZED_ZYNTHIUM_ALKALIDE];
global.TIER_2_BOOSTS = [RESOURCE_GHODIUM_ALKALIDE, RESOURCE_GHODIUM_ACID, RESOURCE_ZYNTHIUM_ACID, RESOURCE_ZYNTHIUM_ALKALIDE, RESOURCE_LEMERGIUM_ALKALIDE, RESOURCE_LEMERGIUM_ACID, RESOURCE_KEANIUM_ACID, RESOURCE_KEANIUM_ALKALIDE, RESOURCE_UTRIUM_ALKALIDE, RESOURCE_UTRIUM_ACID];
global.TIER_1_BOOSTS = [RESOURCE_GHODIUM_HYDRIDE, RESOURCE_GHODIUM_OXIDE, RESOURCE_ZYNTHIUM_HYDRIDE, RESOURCE_ZYNTHIUM_OXIDE, RESOURCE_LEMERGIUM_OXIDE, RESOURCE_LEMERGIUM_HYDRIDE, RESOURCE_KEANIUM_OXIDE, RESOURCE_KEANIUM_HYDRIDE, RESOURCE_UTRIUM_HYDRIDE, RESOURCE_UTRIUM_OXIDE];
global.BASE_COMPOUNDS = [RESOURCE_GHODIUM, RESOURCE_ZYNTHIUM_KEANITE, RESOURCE_UTRIUM_LEMERGITE, RESOURCE_HYDROXIDE];
global.BASE_MINERALS = [RESOURCE_HYDROGEN, RESOURCE_OXYGEN, RESOURCE_UTRIUM, RESOURCE_LEMERGIUM, RESOURCE_KEANIUM, RESOURCE_ZYNTHIUM, RESOURCE_CATALYST, RESOURCE_GHODIUM];
global.BASE_COMPOUNDS = [RESOURCE_GHODIUM, RESOURCE_ZYNTHIUM_KEANITE, RESOURCE_UTRIUM_LEMERGITE, RESOURCE_HYDROXIDE, RESOURCE_GHODIUM];
global.BASE_MINERALS = [RESOURCE_HYDROGEN, RESOURCE_OXYGEN, RESOURCE_UTRIUM, RESOURCE_LEMERGIUM, RESOURCE_KEANIUM, RESOURCE_ZYNTHIUM, RESOURCE_CATALYST];
global.ALL_BOOSTS = _.union(TIER_3_BOOSTS, TIER_2_BOOSTS, TIER_1_BOOSTS, BASE_COMPOUNDS);

// Commodities
Expand All @@ -64,25 +65,24 @@ let globals = function () {

global.PRIORITIES = {
// Harvesters
stationaryHarvester: 2,
// Workers=
drone: 3,
waller: 3,
upgrader: 4,
stationaryHarvester: 1,
// Workers
drone: 2,
waller: 6,
upgrader: 3,
mineralHarvester: 7,
repairer: 7,
// Haulers
hauler: 1,
miscHauler: 3,
miscHauler: 2,
// Remotes
remoteHarvester: 4,
remoteHauler: 3,
remoteHarvester: 5,
remoteHauler: 4,
remoteUpgrader: 7,
roadBuilder: 6,
assistPioneer: 3,
fuelTruck: 7,
reserver: 4,
borderPatrol: 3,
reserver: 6,
// Power
Power: 6,
// SK
Expand All @@ -103,7 +103,7 @@ let globals = function () {

global.SPAWN = {
0: {
stationaryHarvester: [WORK, WORK, CARRY, MOVE],
stationaryHarvester: [WORK, WORK, MOVE],
drone: [MOVE, MOVE, CARRY, WORK],
maintenance: [MOVE, MOVE, CARRY, WORK],
waller: [MOVE, MOVE, CARRY, WORK],
Expand All @@ -126,13 +126,15 @@ let globals = function () {
global.CREEP_CPU_ARRAY = {};
global.ROOM_CPU_ARRAY = {};
global.CREEP_ROLE_CPU_ARRAY = {};
global.CREEP_ROLE_CPU = {};
global.ROOM_TASK_CPU_ARRAY = {};
global.ROOM_ENERGY_INCOME_ARRAY = {};
global.ROOM_ENERGY_PER_TICK = {};
global.TASK_CPU_ARRAY = {};
global.ROOM_CREEP_CPU_OBJECT = {};
global.ROOM_SOURCE_SPACE = {};
global.ROOM_CONTROLLER_SPACE = {};
global.VISUAL_CACHE = {};

global.ICONS = {
[STRUCTURE_CONTROLLER]: "\uD83C\uDFF0"
Expand Down Expand Up @@ -220,6 +222,8 @@ let globals = function () {
, courier: "\ud83d\ude90"
, power: "\u26a1"
, medical: "\u2695"
, eye: "\ud83d\udc40"
, santa: "\ud83c\udf85"
};

global.UNIT_COST = (body) => _.sum(body, p => BODYPART_COST[p.type || p]);
Expand Down Expand Up @@ -298,6 +302,17 @@ let globals = function () {
[RESOURCE_UTRIUM_LEMERGITE]: [RESOURCE_UTRIUM, RESOURCE_LEMERGIUM]
};

global.TOWER_POWER_FROM_RANGE = function (dist, power) {
if (dist <= TOWER_OPTIMAL_RANGE) {
return power
}
if (dist >= TOWER_FALLOFF_RANGE) {
return power * (1 - TOWER_FALLOFF);
}
let towerFalloffPerTile = TOWER_FALLOFF / (TOWER_FALLOFF_RANGE - TOWER_OPTIMAL_RANGE)
return Math.round(power * (1 - (dist - TOWER_OPTIMAL_RANGE) * towerFalloffPerTile))
}

// Boost Uses
global.BOOST_USE = {
'attack': [RESOURCE_CATALYZED_UTRIUM_ACID, RESOURCE_UTRIUM_ACID, RESOURCE_UTRIUM_HYDRIDE],
Expand Down Expand Up @@ -461,6 +476,15 @@ let globals = function () {
return array;
};

global.getResourceTotal = function (resource) {
let amount = 0;
for (let roomName of Memory.myRooms) {
let room = Game.rooms[roomName];
amount += room.store(resource);
}
return amount;
}

global.getLevel = function (room) {
let energy = room.energyCapacityAvailable;
let energyLevel = 0;
Expand Down Expand Up @@ -528,6 +552,89 @@ let globals = function () {
global.TEN_CPU = Game.cpu.limit === 20 || Game.shard.name === 'shard3';

global.log = new Log();

global.sameSectorCheck = function (roomA, roomB) {
let [EW, NS] = roomA.match(/\d+/g);
let roomAEWInt = EW.toString()[0];
let roomANSInt = NS.toString()[0];
let [EW2, NS2] = roomB.match(/\d+/g);
let roomBEWInt = EW2.toString()[0];
let roomBNSInt = NS2.toString()[0];
return roomAEWInt === roomBEWInt && roomANSInt === roomBNSInt;
}

global.floodFill = function (roomName) {

const room = Game.rooms[roomName];

const walls = room.find(FIND_STRUCTURES, {
filter: structure => [STRUCTURE_WALL, STRUCTURE_RAMPART].includes(structure.structureType)
}
);

const terrain = new Room.Terrain(roomName);

const startTime = Game.cpu.getUsed();

const matrix = new PathFinder.CostMatrix();

walls.forEach(wall => {
matrix.set(wall.pos.x, wall.pos.y, 255);
});

const queue = [];
for (let i = 0; i < 49; i++) {
if (terrain.get(i, 0) !== TERRAIN_MASK_WALL) {
matrix.set(i, 0, 1);
queue.push([i, 0]);
}
if (terrain.get(i, 49) !== TERRAIN_MASK_WALL) {
matrix.set(i, 49, 1);
queue.push([i, 49]);
}
if (terrain.get(0, i) !== TERRAIN_MASK_WALL) {
matrix.set(0, i, 1);
queue.push([0, i]);
}
if (terrain.get(49, i) !== TERRAIN_MASK_WALL) {
matrix.set(49, i, 1);
queue.push([49, i]);
}
}

while (queue.length > 0) {
const length = queue.length;
for (let i = 0; i < length; i++) {
const [x, y] = queue[i];

for (let dx = x - 1; dx <= x + 1; dx++) {
for (let dy = y - 1; dy <= y + 1; dy++) {
if (
dx > 0 && dx < 49 && dy > 0 && dy < 49 &&
matrix.get(dx, dy) === 0 &&
(terrain.get(dx, dy) & TERRAIN_MASK_WALL) === 0
) {
matrix.set(dx, dy, 1);
queue.push([dx, dy]);
}
}
}
}
queue.splice(0, length);
}

console.log('cpu used:', Game.cpu.getUsed() - startTime);

const visual = new RoomVisual(roomName);
for (let x = 1; x < 49; x++) {
for (let y = 1; y < 49; y++) {
if (matrix.get(x, y) === 1) {
visual.circle();
visual.circle(x, y, {radius: 0.2, fill: 'white', opacity: 0.6});
}
}
}
};
};

module.exports = globals;
Loading

0 comments on commit 26592f0

Please sign in to comment.