The world of Screeps is not the safest place on earth. This article explains the means you have at your disposal to protect yourself from invasions.

Safe mode

When you start out in the game, you have Safe Mode turned on in your room. It means that no other creep will be able to use any methods in this room that can affect your creeps of objects (but you’ll still be able to defend against strangers). See more about that in the description of StructureController

https://docs.screeps.com/img/safe_mode.png

Safe mode lasts for 20,000 game ticks (approx. 20 hours depending on the tick duration). However, if the room controller has extra available activations, you can turn on safe mode again using the method StructureController.activateSafeMode:

Game.rooms.W1N1.controller.activateSafeMode()

A controller obtains one activation with each new level. Later, you can add more activations to your controller with the help of the ghodium resource using the method Creep.generateSafeMode.

Safe mode is a defense tactic of last resort, when everything else has failed. Besides, safe mode can be active only in one room per shard at the same time. For more robust defense you should use walls, ramparts, towers, and creep defenders.

Passive defense: walls

The most easy and trivial way to defend your room is to build the same walls that you may have noticed surrounding a novice zone during the initial grace period. There is a difference though: while the initial walls were right on doorways blocking outside creeps, your new walls may be built not closer than 2 squares to the room edges, and hostile creeps will still be able to enter the room and destroy your fortifications. This is why it's crucial not to just build, but also fortify your walls in such a way that it takes your opponents much time to destroy them.

https://docs.screeps.com/img/defense1.png

After a wall is built, its square has only 1 hit point. So if you want the wall to cause any trouble to the attackers for at least several hours (or even days), you should fortify it with the help of workers and the repair action. The maximum number of hits you can repair the wall to is 300,000,000 hits. If you spend much resources, such a wall can withstand attacks for many days. And it is just a single square, while you can build multiple rows of walls!

Passive defense: ramparts

However, walls have a considerable disadvantage: they block not only hostile creeps, but your own ones too. Building walls at exits will prevent your own expansion from your room.

This is why you have another passive defense means – ramparts. They behave like walls for hostile creeps by blocking their movements, while your creeps can freely pass through them. Furthermore, a creep on a rampart square is completely invulnerable to any kind of attack until the rampart is destroyed. Being protected, it can still attack opponents.

https://docs.screeps.com/img/defense2.png

In the same way as walls, ramparts are built with 1 hit point initially and need to be fortified to a needed level by workers afterwards. The maximum amount of rampart hits depends on the Room Controller level. See more about that in the article Control.

A rampart has another peculiarity: its superior defense abilities must be constantly maintained at a proper level. Every few ticks, a rampart loses a few hit points, so you should assign a worker to make sure that all your ramparts stand alert and don't wear off.

Active defense: towers

While well-designed passive defenses may withstand attacks for many days (for example, while you are offline and out of the game), they will inevitably fall sometime. This is why it's utterly important not to rely on fortifications alone but install defense systems to repel opponents when needed.