The DEFEND intent will be set if there was a hostile minion in the room in the last 10 ticks. For now, we’ll use our existing TerritoryIntents. This particularly includes remote Franchises - Salesmen can stay put and maintain their containers, but Accountants should not try to travel past hostile minions - but also includes scouting or acquiring new offices.Įventually we may need a more full-fledged DEFCON status. When a room is under attack, operations outside the defensive perimeter should be suspended. ATTACK parts make more sense here than ranged attack because they force hostile minions to stand back from the ramparts if the hostile minion has RANGED_ATTACK, this will limit the damage they can do to the ramparts, so our Engineers can out-repair them, keeping them at bay indefinitely. They’ll travel to the empty rampart nearest to the target invader and attack it from cover. For now we’ll make it simple and spawn Guards with an equal number of move/attack parts. Our ramparts will stall attackers to give us time to spawn defenders. So far, so good but how do we deal with those minions? We need active defenders. If the target is within three squares of an exit, or if the healing will outpace our damage, the towers will ignore it. For each hostile target, we’ll calculate the damage our towers can do then we’ll calculate the healing that target can receive from itself or nearby allies, and subtract it.
So our tower code needs to be intelligent. The same goes for minions with enough healing (or boosts) to tank those attacks directly. Repeat until the towers are drained, and then the rest of the army can charge in without fear. If your tower code blindly attacks every hostile minion, an enemy can sit on the border, take a hit, and then blink back to the other room for healing. Towers are the first line of defense, but without safeguards they can be exploited to drain your room’s energy. We should push the ramparts out three squares from our existing structures. If our room is under attack, the refillers need to get from the spawn (outside the perimeter) to the extensions (inside the perimeter), and they are vulnerable to hostiles.Īlso, the perimeter is too close to our structures: creeps with Ranged Attack can target structures behind the ramparts. Everything inside the perimeter is protected, but we rely on refiller minions to manage the energy levels in our extensions. That’s a start, but there are some issues with this layout. Here’s an example of drawing a perimeter around our extensions field and headquarters: I elected to take a shortcut and use the min-cut implementation by Saruss, Chobobobo, and Shibdib in screepers-snippets.
It may also include a layer of protective walls around the controller: an attacker needs to be adjacent, but your own minions can upgrade from afar, so it’s a simple protection against controller attacks. This could look like ramparts covering a bunker, a min-cut generated perimeter, or both. The purpose of walls and ramparts is to protect your core facilities until your active defenses can destroy invaders. The official Screeps docs have an introduction to defense which highlights two different modalities: passive (walls and ramparts) and active (towers and creeps). DefenseĬlausewitz’s first principle is “make your own base secure.” As a reminder, here’s what our base plan looks like. You may implement them - or implement countermeasures - as you please. However, I will discuss many of the tactics, strategies, and other considerations here openly. To that end, I’ll be separating most of my combat code into a new closed-source package, leaving the rest of the codebase open-source. There is a taboo against providing combat code, and depending who you ask, even against discussing combat in too much detail. If you ask nicely (by submitting a PR) you can be added to the Grey Company whitelist. If you want the risk posed by other players, that’s what MMO or other public servers are for. If you want to avoid combat so you can focus on your economy, that’s fine that’s what private servers are for. Let’s talk about my philosophy of Screeps combat for just a moment. Here’s the GitHub repo if you’d like to follow along. The article below describes the AI in its current state: I’m still expanding and refining my codebase.