Skip to content

Commit

Permalink
feat(runtime): enable constructing roads and ramparts on top of terra…
Browse files Browse the repository at this point in the history
…in walls
  • Loading branch information
artch committed Aug 20, 2018
1 parent 76a355b commit ee5c9f9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 13 deletions.
7 changes: 6 additions & 1 deletion src/processor/intents/creeps/build.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ module.exports = function(object, intent, {roomObjects, roomTerrain, bulk, roomC
return; 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; return;
} }


Expand Down Expand Up @@ -139,6 +140,10 @@ module.exports = function(object, intent, {roomObjects, roomTerrain, bulk, roomC
utils.checkTerrain(roomTerrain, target.x, target.y, C.TERRAIN_MASK_SWAMP)) { utils.checkTerrain(roomTerrain, target.x, target.y, C.TERRAIN_MASK_SWAMP)) {
hits *= C.CONSTRUCTION_COST_ROAD_SWAMP_RATIO; 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, { _.extend(newObject, {
hits, hits,
hitsMax: hits hitsMax: hits
Expand Down
27 changes: 21 additions & 6 deletions src/processor/intents/movement.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,13 +9,28 @@ var _ = require('lodash'),
roomTerrain; roomTerrain;


function checkObstacleAtXY(x,y,object, roomIsInSafeMode) { 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) { function calcResourcesWeight(creep) {
Expand Down
4 changes: 4 additions & 0 deletions src/processor/intents/roads/tick.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ module.exports = function(object, {roomObjects, roomTerrain, bulk, gameTime}) {
utils.checkTerrain(roomTerrain, object.x, object.y, C.TERRAIN_MASK_SWAMP)) { utils.checkTerrain(roomTerrain, object.x, object.y, C.TERRAIN_MASK_SWAMP)) {
decayAmount *= C.CONSTRUCTION_COST_ROAD_SWAMP_RATIO; 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; object.hits -= decayAmount;
if(object.hits <= 0) { if(object.hits <= 0) {
bulk.remove(object._id); bulk.remove(object._id);
Expand Down
13 changes: 9 additions & 4 deletions src/processor/intents/room/create-construction-site.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -34,10 +34,15 @@ module.exports = function(userId, intent, {roomObjects, roomTerrain, bulk, roomC


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


if(intent.structureType == 'road' && if(intent.structureType == 'road') {
(_.any(roomObjects, {x: intent.x, y: intent.y, type: 'swamp'}) || if(_.any(roomObjects, {x: intent.x, y: intent.y, type: 'swamp'}) ||
utils.checkTerrain(roomTerrain, intent.x, intent.y, C.TERRAIN_MASK_SWAMP))) { utils.checkTerrain(roomTerrain, intent.x, intent.y, C.TERRAIN_MASK_SWAMP)) {
progressTotal *= C.CONSTRUCTION_COST_ROAD_SWAMP_RATIO; 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) { if(config.ptr) {
Expand Down
6 changes: 4 additions & 2 deletions src/utils.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ exports.checkConstructionSite = function(objects, structureType, x, y) {
if(structureType == 'extractor') { if(structureType == 'extractor') {
return true; 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 false;
} }
return true; return true;
Expand All @@ -172,7 +173,8 @@ exports.checkConstructionSite = function(objects, structureType, x, y) {
if(structureType == 'extractor') { if(structureType == 'extractor') {
return true; 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 false;
} }
return true; return true;
Expand Down

0 comments on commit ee5c9f9

Please sign in to comment.