UNPKG

@screeps/engine

Version:

This is a module for Screeps standalone server. See [main repository](https://github.com/screeps/screeps) for more info.

31 lines (26 loc) 1.08 kB
var _ = require('lodash'), utils = require('../../../utils'), driver = utils.getDriver(), C = driver.constants; module.exports = function(object, roomObjects, roomTerrain, bulk, bulkUsers, roomController, gameTime) { if(!object || object.type != 'road') return; if(!object.nextDecayTime || gameTime >= object.nextDecayTime-1) { var decayAmount = C.ROAD_DECAY_AMOUNT; if(_.any(roomObjects, (i) => i.x == object.x && i.y == object.y && i.type == 'swamp') || utils.checkTerrain(roomTerrain, object.x, object.y, C.TERRAIN_MASK_SWAMP)) { decayAmount *= C.CONSTRUCTION_COST_ROAD_SWAMP_RATIO; } object.hits -= decayAmount; if(object.hits <= 0) { bulk.remove(object._id); delete roomObjects[object._id]; } else { object.nextDecayTime = gameTime + C.ROAD_DECAY_TIME; bulk.update(object, { hits: object.hits, nextDecayTime: object.nextDecayTime }); } } };