Skip to content
Permalink
Browse files

feat(runtime): enable constructing roads and ramparts on top of terra…

…in walls
  • Loading branch information...
artch committed Aug 20, 2018
1 parent 76a355b commit ee5c9f96ac5a4a2aefc2fab0763355806c85f46d
@@ -31,7 +31,8 @@ module.exports = function(object, intent, {roomObjects, roomTerrain, bulk, roomC
return;
}

if(target.structureType != 'extractor' && utils.checkTerrain(roomTerrain, target.x, target.y, C.TERRAIN_MASK_WALL)) {
if(target.structureType != 'extractor' && target.structureType != 'road' && target.structureType != 'rampart' &&
utils.checkTerrain(roomTerrain, target.x, target.y, C.TERRAIN_MASK_WALL)) {
return;
}

@@ -139,6 +140,10 @@ module.exports = function(object, intent, {roomObjects, roomTerrain, bulk, roomC
utils.checkTerrain(roomTerrain, target.x, target.y, C.TERRAIN_MASK_SWAMP)) {
hits *= C.CONSTRUCTION_COST_ROAD_SWAMP_RATIO;
}
if(_.any(roomObjects, {x: target.x, y: target.y, type: 'wall'}) ||
utils.checkTerrain(roomTerrain, target.x, target.y, C.TERRAIN_MASK_WALL)) {
hits *= C.CONSTRUCTION_COST_ROAD_WALL_RATIO;
}
_.extend(newObject, {
hits,
hitsMax: hits
@@ -9,13 +9,28 @@ var _ = require('lodash'),
roomTerrain;

function checkObstacleAtXY(x,y,object, roomIsInSafeMode) {
var hasObstacle = false, hasRoad = false;
_.forEach(roomObjects, (i) => {
if (i.x != x || i.y != y) {
return;
}
if (i.type == 'creep' && !objects[i._id] && (!roomIsInSafeMode || roomIsInSafeMode != object.user || roomIsInSafeMode == object.user && object.user == i.user) ||
i.type != 'creep' && _.contains(C.OBSTACLE_OBJECT_TYPES, i.type) ||
i.type == 'rampart' && !i.isPublic && i.user != object.user ||
i.type == 'constructionSite' && i.user == object.user && _.contains(C.OBSTACLE_OBJECT_TYPES,
i.structureType)) {
hasObstacle = true;
return false;
}
if(i.type == 'road') {
hasRoad = true;
}
});
if(hasObstacle) {
return true;
}
return utils.checkTerrain(roomTerrain, x, y, C.TERRAIN_MASK_WALL) && !hasRoad;

return _.any(roomObjects, (i) => i.x == x && i.y == y &&
(i.type == 'creep' && !objects[i._id] && (!roomIsInSafeMode || roomIsInSafeMode != object.user || roomIsInSafeMode == object.user && object.user == i.user) ||
i.type != 'creep' && _.contains(C.OBSTACLE_OBJECT_TYPES, i.type) ||
i.type == 'rampart' && !i.isPublic && i.user != object.user ||
i.type == 'constructionSite' && i.user == object.user && _.contains(C.OBSTACLE_OBJECT_TYPES, i.structureType) ))
|| utils.checkTerrain(roomTerrain, x, y, C.TERRAIN_MASK_WALL);
}

function calcResourcesWeight(creep) {
@@ -13,6 +13,10 @@ module.exports = function(object, {roomObjects, roomTerrain, bulk, gameTime}) {
utils.checkTerrain(roomTerrain, object.x, object.y, C.TERRAIN_MASK_SWAMP)) {
decayAmount *= C.CONSTRUCTION_COST_ROAD_SWAMP_RATIO;
}
if(_.any(roomObjects, (i) => i.x == object.x && i.y == object.y && i.type == 'wall') ||
utils.checkTerrain(roomTerrain, object.x, object.y, C.TERRAIN_MASK_WALL)) {
decayAmount *= C.CONSTRUCTION_COST_ROAD_WALL_RATIO;
}
object.hits -= decayAmount;
if(object.hits <= 0) {
bulk.remove(object._id);
@@ -34,10 +34,15 @@ module.exports = function(userId, intent, {roomObjects, roomTerrain, bulk, roomC

var progressTotal = C.CONSTRUCTION_COST[intent.structureType];

if(intent.structureType == 'road' &&
(_.any(roomObjects, {x: intent.x, y: intent.y, type: 'swamp'}) ||
utils.checkTerrain(roomTerrain, intent.x, intent.y, C.TERRAIN_MASK_SWAMP))) {
progressTotal *= C.CONSTRUCTION_COST_ROAD_SWAMP_RATIO;
if(intent.structureType == 'road') {
if(_.any(roomObjects, {x: intent.x, y: intent.y, type: 'swamp'}) ||
utils.checkTerrain(roomTerrain, intent.x, intent.y, C.TERRAIN_MASK_SWAMP)) {
progressTotal *= C.CONSTRUCTION_COST_ROAD_SWAMP_RATIO;
}
if(_.any(roomObjects, {x: intent.x, y: intent.y, type: 'wall'}) ||
utils.checkTerrain(roomTerrain, intent.x, intent.y, C.TERRAIN_MASK_WALL)) {
progressTotal *= C.CONSTRUCTION_COST_ROAD_WALL_RATIO;
}
}

if(config.ptr) {
@@ -155,7 +155,8 @@ exports.checkConstructionSite = function(objects, structureType, x, y) {
if(structureType == 'extractor') {
return true;
}
if(exports.checkTerrain(objects, x, y, C.TERRAIN_MASK_WALL)) {
if(structureType != 'road' && structureType != 'rampart' &&
exports.checkTerrain(objects, x, y, C.TERRAIN_MASK_WALL)) {
return false;
}
return true;
@@ -172,7 +173,8 @@ exports.checkConstructionSite = function(objects, structureType, x, y) {
if(structureType == 'extractor') {
return true;
}
if(objects[y][x] & C.TERRAIN_MASK_WALL) {
if(structureType != 'road' && structureType != 'rampart' &&
objects[y][x] & C.TERRAIN_MASK_WALL) {
return false;
}
return true;

0 comments on commit ee5c9f9

Please sign in to comment.
You can’t perform that action at this time.