screeps
Screeps AI
Functional screeps AI.
Instructions
Startup
- Place your spawn in a large open area. Name it 0, for example, if the room is called E12N14, the spawn should be E12N140. The spawn should have 6 open squares on each side (13 by 13 square with spawn in the middle).
Claiming and Attacking (see "New City" section below and "Attacking" section below)
TLDR flag other rooms to "claim" (claim room), "plan" (build base at flag location), "break" (break buildings). Use the PlaceFlag() function from the console.
Features
- Cities will use market to trade for minerals and sell excess resources for credits.
- Cities use labs to make max power boosts for military and upgraders from minerals.
- Cities mine power for power creeps.
- Cities mine commodities and will attempt to create high level products with available factories and sell them.
- All structures and roads are placed automatically
- New rooms will be claimed automatically (private server only)
- AI optomized for Shard 3 (low CPU)
Current Roles
Core Roles
- Builder - build buildings from constructions sites, repair roads/walls
- Remote Miner - source of energy. mine energy sources in the room or neighboring rooms
- Runner - bring energy from miners to base
- Transporter - redistribute energy in base. load extensions, spawns, towers, factory, labs, and nuker
- Upgrader - upgrade base level
- Ferry - miscellaneous task operator. tasks include; lab work, factory, terminal management etc.
Military
- Breaker - destroys enemy buildings. Pair with healer.
- Medic - heals other military units
- Quad - ranged group of 4 units. units heal each other and focus attacks.
- Defender - Defend against enemy invaders.
- Harasser - Ranged attacking unit for cheap damage to enemy remote miners and protecting highways
- Robber - takes resources from enemy rooms
Other
- Claimer - claim rooms for new cities
- Deposit Miner - mine deposits in nearby highway rooms
- Mineral Miner - mine mineral source in the room
- Power Creep - boost other creeps/resources/structures in a room
- Power Miner - mine power in nearby highway rooms
- Spawn Builder - build initial buildings in a new city
- Scout - scout nearby rooms
- Unclaimer - attack enemy controllers
Flagging targets
The PlaceFlag function can be used from the console to flag a target with a flag.
For example: PlaceFlag("claim", 25, 25, "E9N32")
Flag Types:
- claim - claim a room
- plan - create a layout for a structures in a new room
- break - send a breaker to a room to destroy structures
- quadRally - send a quad to a room to destroy and creeps
If a flag requires a city name to be part of its name, this specifies the city that will send the creeps.
For example: a flag named E11N140break
will send a breaker from E11N140. A city's name will always be the room name with a '0' added to the end. For flags that require a city name, we will use a '-' to convey that. So in the example above, the flag would referred to as -break
.
New City
How to build a new city (not the first spawn)
- Find an empty room within 10-15 squares of a current room (must be greater than rcl 4).
- Open the room. Place a
claim
flag anywhere in the room. - Place a
plan
flag in the room as well. Theplan
flag will be placed in the top left corner of your base, so carefully find a 13 by 13 area in the room and place the flag in the top left corner of that area. You're done! Everything after this point is automated.
How a new city develops after flags are placed
- Wait ~500 ticks for the
claim
flag to be recognized and processed. The closest room (greater than rcl 4) will create claimers to claim the room and spawnBuilders to build the spawn & get the room started. - The
plan
flag will be replaced with construction sites for core buildings in the room after the room has been claimed.
Other flag info
There are some automated roles that currently run off of flagging mechanisms. These include the Power Miner, Deposit Miner, and Harasser. You do not need to interact with their respective flags (-powerMine
, -deposit
, -harass
) for them to operate successfully.
More useful functions
DeployQuad(targetRoom)
deploy a quad to target room (must be a roomName)SpawnQuad(city, boosted)
spawn a quad from specified city. If boosted is true, the city will attempt to make the quad boostedSpawnBreaker(city, boosted)
spawn a breaker from specified city. If boosted is true, the city will attempt to make the breaker boostedSpawnRole(role, city, boosted)
spawn any role from specified city. If boosted is true, the city will attempt to make the creep boosted
Best Practices for making changes
- Make new paths in memory for new usecases. For example Memory.attacks.xxxx instead of Memory.xxxx. Easier to change and clean up this way.
- Cache things in Cache.xxx if we can afford to lose them. This saves cpu from memory lookups on each tick.
- Always store room names/ids instead of the objects. Saving an object causes bugs because the internal fields within the object will be incorrect over time. For example creep.store values will change in game, but not in the copy you have stored. Names/Ids also take less memory.
- Store new routines in seperate files.
- Add new files to
profiler-prep.js
so we profile them. - Make sure changes pass
npm test
checks, eslint and mocha tests, to minimize sloppy bugs