Skip to content

Commit

Permalink
Use RANGE_* constants
Browse files Browse the repository at this point in the history
  • Loading branch information
RiftLurker authored and Leo Friedrichs committed Feb 3, 2017
1 parent 7df5e3f commit 5cfa531
Show file tree
Hide file tree
Showing 29 changed files with 55 additions and 55 deletions.
34 changes: 17 additions & 17 deletions src/game/creeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
if(!target.energy) {
return C.ERR_NOT_ENOUGH_RESOURCES;
}
if(!target.pos.isNearTo(this.pos)) {
if(!target.pos.inRangeTo(this.pos, C.RANGE_HARVEST_SOURCE)) {
return C.ERR_NOT_IN_RANGE;
}
if(this.room.controller && (
Expand All @@ -325,7 +325,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
if(!target.mineralAmount) {
return C.ERR_NOT_ENOUGH_RESOURCES;
}
if(!target.pos.isNearTo(this.pos)) {
if(!target.pos.inRangeTo(this.pos, C.RANGE_HARVEST_MINERAL)) {
return C.ERR_NOT_IN_RANGE;
}
var extractor = _.find(target.pos.lookFor('structure'), {structureType: C.STRUCTURE_EXTRACTOR});
Expand Down Expand Up @@ -433,7 +433,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
}
}

if(!target.pos.isNearTo(this.pos)) {
if(!target.pos.inRangeTo(this.pos, C.RANGE_TRANSFER)) {
return C.ERR_NOT_IN_RANGE;
}
if(!data(this.id)[resourceType]) {
Expand Down Expand Up @@ -574,7 +574,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
}
}

if(!target.pos.isNearTo(this.pos)) {
if(!target.pos.inRangeTo(this.pos, C.RANGE_WITHDRAW)) {
return C.ERR_NOT_IN_RANGE;
}

Expand Down Expand Up @@ -646,7 +646,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
if(utils.calcResources(this.carry) >= this.carryCapacity) {
return C.ERR_FULL;
}
if(!target.pos.isNearTo(this.pos)) {
if(!target.pos.inRangeTo(this.pos, C.RANGE_PICKUP)) {
return C.ERR_NOT_IN_RANGE;
}

Expand Down Expand Up @@ -678,7 +678,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
register.assertTargetObject(target);
return C.ERR_INVALID_TARGET;
}
if(!target.pos.isNearTo(this.pos)) {
if(!target.pos.inRangeTo(this.pos, C.RANGE_ATTACK)) {
return C.ERR_NOT_IN_RANGE;
}

Expand Down Expand Up @@ -706,7 +706,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
register.assertTargetObject(target);
return C.ERR_INVALID_TARGET;
}
if(!this.pos.inRangeTo(target, 3)) {
if(!this.pos.inRangeTo(target, C.RANGE_RANGED_ATTACK)) {
return C.ERR_NOT_IN_RANGE;
}

Expand Down Expand Up @@ -750,7 +750,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
register.assertTargetObject(target);
return C.ERR_INVALID_TARGET;
}
if(!target.pos.isNearTo(this.pos)) {
if(!target.pos.inRangeTo(this.pos, C.RANGE_HEAL)) {
return C.ERR_NOT_IN_RANGE;
}
if(this.room.controller && !this.room.controller.my && this.room.controller.safeMode) {
Expand Down Expand Up @@ -808,7 +808,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
register.assertTargetObject(target);
return C.ERR_INVALID_TARGET;
}
if(!this.pos.inRangeTo(target, 3)) {
if(!this.pos.inRangeTo(target, C.RANGE_REPAIR)) {
return C.ERR_NOT_IN_RANGE;
}

Expand All @@ -835,7 +835,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
register.assertTargetObject(target);
return C.ERR_INVALID_TARGET;
}
if(!this.pos.inRangeTo(target, 3)) {
if(!this.pos.inRangeTo(target, C.RANGE_BUILD)) {
return C.ERR_NOT_IN_RANGE;
}
if(_.contains(['spawn','extension','constructedWall'], target.structureType) &&
Expand Down Expand Up @@ -906,7 +906,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
if(this.getActiveBodyparts(C.CLAIM) == 0) {
return C.ERR_NO_BODYPART;
}
if(!target.pos.isNearTo(this.pos)) {
if(!target.pos.inRangeTo(this.pos, C.RANGE_CLAIM_CONTROLLER)) {
return C.ERR_NOT_IN_RANGE;
}
if(target.structureType != 'controller') {
Expand Down Expand Up @@ -942,7 +942,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
if(this.getActiveBodyparts(C.CLAIM) < 5) {
return C.ERR_NO_BODYPART;
}
if(!target.pos.isNearTo(this.pos)) {
if(!target.pos.inRangeTo(this.pos, C.RANGE_ATTACK_CONTROLLER)) {
return C.ERR_NOT_IN_RANGE;
}
if(!target.owner && !target.reservation) {
Expand Down Expand Up @@ -977,7 +977,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
if(target.upgradeBlocked && target.upgradeBlocked > 0) {
return C.ERR_INVALID_TARGET;
}
if(!target.pos.inRangeTo(this.pos, 3)) {
if(!target.pos.inRangeTo(this.pos, C.RANGE_UPGRADE_CONTROLLER)) {
return C.ERR_NOT_IN_RANGE;
}
if(!target.my) {
Expand All @@ -1004,7 +1004,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
register.assertTargetObject(target);
return C.ERR_INVALID_TARGET;
}
if(!target.pos.isNearTo(this.pos)) {
if(!target.pos.inRangeTo(this.pos, C.RANGE_RESERVE_CONTROLLER)) {
return C.ERR_NOT_IN_RANGE;
}
if(target.structureType != 'controller') {
Expand Down Expand Up @@ -1070,7 +1070,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
register.assertTargetObject(target);
return C.ERR_INVALID_TARGET;
}
if(!target.pos.isNearTo(this.pos)) {
if(!target.pos.inRangeTo(this.pos, C.RANGE_DISMANTLE)) {
return C.ERR_NOT_IN_RANGE;
}
if(this.room.controller && !this.room.controller.my && this.room.controller.safeMode) {
Expand All @@ -1096,7 +1096,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
register.assertTargetObject(target);
return C.ERR_INVALID_TARGET;
}
if(!target.pos.isNearTo(this.pos)) {
if(!target.pos.inRangeTo(this.pos, C.RANGE_GENERATE_SAFEMODE)) {
return C.ERR_NOT_IN_RANGE;
}

Expand All @@ -1114,7 +1114,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
register.assertTargetObject(target);
return C.ERR_INVALID_TARGET;
}
if(!target.pos.isNearTo(this.pos)) {
if(!target.pos.inRangeTo(this.pos, C.RANGE_SIGN_CONTROLLER)) {
return C.ERR_NOT_IN_RANGE;
}
if(target.structureType != 'controller') {
Expand Down
18 changes: 9 additions & 9 deletions src/game/structures.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function _transfer(target, resourceType, amount) {
if (data(target.id).energyCapacity && (!amount || utils.calcResources(data(target.id)) + amount > data(target.id).energyCapacity)) {
return C.ERR_FULL;
}
if (!target.pos.isNearTo(this.pos)) {
if (!target.pos.inRangeTo(this.pos, C.RANGE_TRANSFER)) {
return C.ERR_NOT_IN_RANGE;
}

Expand Down Expand Up @@ -89,7 +89,7 @@ function _transferEnergy(target, amount) {
if(data(target.id).energyCapacity && (!amount || utils.calcResources(data(target.id)) + amount > data(target.id).energyCapacity)) {
return C.ERR_FULL;
}
if(!target.pos.isNearTo(this.pos)) {
if(!target.pos.inRangeTo(this.pos, C.RANGE_TRANSFER)) {
return C.ERR_NOT_IN_RANGE;
}

Expand Down Expand Up @@ -403,7 +403,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
if (data(target.id).energyCapacity && (!amount || utils.calcResources(data(target.id)) + amount > data(target.id).energyCapacity)) {
return C.ERR_FULL;
}
if (!target.pos.isNearTo(this.pos)) {
if (!target.pos.inRangeTo(this.pos, C.RANGE_TRANSFER)) {
return C.ERR_NOT_IN_RANGE;
}

Expand Down Expand Up @@ -431,7 +431,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
register.assertTargetObject(lab2);
return C.ERR_INVALID_TARGET;
}
if(this.pos.getRangeTo(lab1) > 2 || this.pos.getRangeTo(lab2) > 2) {
if(this.pos.getRangeTo(lab1) > C.RANGE_RUN_REACTION || this.pos.getRangeTo(lab2) > C.RANGE_RUN_REACTION) {
return C.ERR_NOT_IN_RANGE;
}
if(this.mineralAmount > this.mineralCapacity - C.LAB_REACTION_AMOUNT) {
Expand Down Expand Up @@ -460,7 +460,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
register.assertTargetObject(target);
return C.ERR_INVALID_TARGET;
}
if(!this.pos.isNearTo(target)) {
if(!this.pos.inRangeTo(target, C.RANGE_BOOST_CREEP)) {
return C.ERR_NOT_IN_RANGE;
}
if(data(this.id).energy < C.LAB_BOOST_ENERGY) {
Expand Down Expand Up @@ -531,7 +531,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
return C.ERR_RCL_NOT_ENOUGH;
}
}
if ((target instanceof globals.Creep) && !this.pos.isNearTo(target)) {
if ((target instanceof globals.Creep) && !this.pos.inRangeTo(target, C.RANGE_TRANSFER)) {
return C.ERR_NOT_IN_RANGE;
}
if (!data(this.id).energy) {
Expand Down Expand Up @@ -1092,7 +1092,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
if(data(target.id).energy == data(target.id).energyCapacity) {
return C.ERR_FULL;
}
if(!target.pos.isNearTo(this.pos)) {
if(!target.pos.inRangeTo(this.pos, C.RANGE_TRANSFER)) {
return C.ERR_NOT_IN_RANGE;
}

Expand Down Expand Up @@ -1144,7 +1144,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
if(!target.my) {
return C.ERR_NOT_OWNER;
}
if(!target.pos.isNearTo(this.pos)) {
if(!target.pos.inRangeTo(this.pos, C.RANGE_RENEW_CREEP)) {
return C.ERR_NOT_IN_RANGE;
}
if(this.spawning) {
Expand Down Expand Up @@ -1176,7 +1176,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
if(!target.my) {
return C.ERR_NOT_OWNER;
}
if(!target.pos.isNearTo(this.pos)) {
if(!target.pos.inRangeTo(this.pos, C.RANGE_RECYCLE_CREEP)) {
return C.ERR_NOT_IN_RANGE;
}

Expand Down
2 changes: 1 addition & 1 deletion src/processor/intents/creeps/attack.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function(object, intent, roomObjects, roomTerrain, bulk, bulkUs
if(!target || target == object) {
return;
}
if(Math.abs(target.x - object.x) > 1 || Math.abs(target.y - object.y) > 1) {
if(Math.abs(target.x - object.x) > C.RANGE_ATTACK || Math.abs(target.y - object.y) > C.RANGE_ATTACK) {
return;
}
if(target.type == 'creep' && target.spawning) {
Expand Down
2 changes: 1 addition & 1 deletion src/processor/intents/creeps/attackController.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function(object, intent, roomObjects, roomTerrain, bulk, bulkUs
if(!target || target.type != 'controller') {
return;
}
if(Math.abs(target.x - object.x) > 1 || Math.abs(target.y - object.y) > 1) {
if(Math.abs(target.x - object.x) > C.RANGE_ATTACK_CONTROLLER || Math.abs(target.y - object.y) > C.RANGE_ATTACK_CONTROLLER) {
return;
}
if(!target.user && !target.reservation) {
Expand Down
2 changes: 1 addition & 1 deletion src/processor/intents/creeps/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = function(object, intent, roomObjects, roomTerrain, bulk, bulkUs
!C.CONSTRUCTION_COST[target.structureType]) {
return;
}
if(Math.abs(target.x - object.x) > 3 || Math.abs(target.y - object.y) > 3) {
if(Math.abs(target.x - object.x) > C.RANGE_BUILD || Math.abs(target.y - object.y) > C.RANGE_BUILD) {
return;
}
if(_.any(roomObjects, {x: target.x, y: target.y, type: target.structureType})) {
Expand Down
2 changes: 1 addition & 1 deletion src/processor/intents/creeps/claimController.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function(object, intent, roomObjects, roomTerrain, bulk, bulkUs
if(!target || target.type != 'controller') {
return;
}
if(Math.abs(target.x - object.x) > 1 || Math.abs(target.y - object.y) > 1) {
if(Math.abs(target.x - object.x) > C.RANGE_CLAIM_CONTROLLER || Math.abs(target.y - object.y) > C.RANGE_CLAIM_CONTROLLER) {
return;
}
if(target.bindUser && object.user != target.bindUser) {
Expand Down
2 changes: 1 addition & 1 deletion src/processor/intents/creeps/dismantle.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function(object, intent, roomObjects, roomTerrain, bulk, bulkUs
if(!target || !C.CONSTRUCTION_COST[target.type]) {
return;
}
if(Math.abs(target.x - object.x) > 1 || Math.abs(target.y - object.y) > 1) {
if(Math.abs(target.x - object.x) > C.RANGE_DISMANTLE || Math.abs(target.y - object.y) > C.RANGE_DISMANTLE) {
return;
}
if(roomController && roomController.user != object.user && roomController.safeMode > gameTime) {
Expand Down
2 changes: 1 addition & 1 deletion src/processor/intents/creeps/generateSafeMode.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = function(object, intent, roomObjects, roomTerrain, bulk, bulkUs
if(!target || target.type != 'controller') {
return;
}
if(Math.abs(target.x - object.x) > 1 || Math.abs(target.y - object.y) > 1) {
if(Math.abs(target.x - object.x) > C.RANGE_GENERATE_SAFEMODE || Math.abs(target.y - object.y) > C.RANGE_GENERATE_SAFEMODE) {
return;
}
if(!(object[C.RESOURCE_GHODIUM] >= C.SAFE_MODE_COST)) {
Expand Down
2 changes: 1 addition & 1 deletion src/processor/intents/creeps/harvest.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function(object, intent, roomObjects, roomTerrain, bulk, bulkUs
if(!target) {
return;
}
if(Math.abs(target.x - object.x) > 1 || Math.abs(target.y - object.y) > 1) {
if(Math.abs(target.x - object.x) > C.RANGE_HARVEST || Math.abs(target.y - object.y) > C.RANGE_HARVEST) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/processor/intents/creeps/heal.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function(object, intent, roomObjects, roomTerrain, bulk, bulkUs
if(!target || target.type != 'creep' || target.spawning || target.hits >= target.hitsMax) {
return;
}
if(Math.abs(target.x - object.x) > 1 || Math.abs(target.y - object.y) > 1) {
if(Math.abs(target.x - object.x) > C.RANGE_HEAL || Math.abs(target.y - object.y) > C.RANGE_HEAL) {
return;
}
if(roomController && roomController.user != object.user && roomController.safeMode > gameTime) {
Expand Down
2 changes: 1 addition & 1 deletion src/processor/intents/creeps/pickup.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = function(object, intent, roomObjects, roomTerrain, bulk) {
if(!target || target.type != 'energy') {
return;
}
if(Math.abs(target.x - object.x) > 1 || Math.abs(target.y - object.y) > 1) {
if(Math.abs(target.x - object.x) > C.RANGE_PICKUP || Math.abs(target.y - object.y) > C.RANGE_PICKUP) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/processor/intents/creeps/rangedAttack.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function(object, intent, roomObjects, roomTerrain, bulk, bulkUs
if(!target || target == object) {
return;
}
if(Math.abs(target.x - object.x) > 3 || Math.abs(target.y - object.y) > 3) {
if(Math.abs(target.x - object.x) > C.RANGE_RANGED_ATTACK || Math.abs(target.y - object.y) > C.RANGE_RANGED_ATTACK) {
return;
}
if(target.type == 'creep' && target.spawning) {
Expand Down
2 changes: 1 addition & 1 deletion src/processor/intents/creeps/rangedHeal.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function(object, intent, roomObjects, roomTerrain, bulk, bulkUs
if(!target || target.type != 'creep' || target.spawning || target.hits >= target.hitsMax) {
return;
}
if(Math.abs(target.x - object.x) > 3 || Math.abs(target.y - object.y) > 3) {
if(Math.abs(target.x - object.x) > C.RANGE_RANGED_HEAL || Math.abs(target.y - object.y) > C.RANGE_RANGED_HEAL) {
return;
}
if(roomController && roomController.user != object.user && roomController.safeMode > gameTime) {
Expand Down
4 changes: 2 additions & 2 deletions src/processor/intents/creeps/rangedMassAttack.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ module.exports = function(object, intent, roomObjects, roomTerrain, bulk, bulkUs

var targets = _.filter(roomObjects, (i) => {
return (!_.isUndefined(i.user) || i.type == 'powerBank') && i.user != object.user &&
i.x >= object.x - 3 && i.x <= object.x + 3 &&
i.y >= object.y - 3 && i.y <= object.y + 3;
i.x >= object.x - C.RANGE_RANGED_MASS_ATTACK && i.x <= object.x + C.RANGE_RANGED_MASS_ATTACK &&
i.y >= object.y - C.RANGE_RANGED_MASS_ATTACK && i.y <= object.y + C.RANGE_RANGED_MASS_ATTACK;
});

var distanceRate = {1: 1, 2: 0.4, 3: 0.1};
Expand Down
2 changes: 1 addition & 1 deletion src/processor/intents/creeps/repair.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function(object, intent, roomObjects, roomTerrain, bulk, bulkUs
if(!target || !C.CONSTRUCTION_COST[target.type] || target.hits >= target.hitsMax) {
return;
}
if(Math.abs(target.x - object.x) > 3 || Math.abs(target.y - object.y) > 3) {
if(Math.abs(target.x - object.x) > C.RANGE_REPAIR || Math.abs(target.y - object.y) > C.RANGE_REPAIR) {
return;
}
if(!target.hitsMax) {
Expand Down
2 changes: 1 addition & 1 deletion src/processor/intents/creeps/reserveController.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function(object, intent, roomObjects, roomTerrain, bulk, bulkUs
if(!target || target.type != 'controller') {
return;
}
if(Math.abs(target.x - object.x) > 1 || Math.abs(target.y - object.y) > 1) {
if(Math.abs(target.x - object.x) > C.RANGE_RESERVE_CONTROLLER || Math.abs(target.y - object.y) > C.RANGE_RESERVE_CONTROLLER) {
return;
}
if(target.user || target.reservation && target.reservation.user != object.user) {
Expand Down
2 changes: 1 addition & 1 deletion src/processor/intents/creeps/signController.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function(object, intent, roomObjects, roomTerrain, bulk, bulkUs
if(!target || target.type != 'controller') {
return;
}
if(Math.abs(target.x - object.x) > 1 || Math.abs(target.y - object.y) > 1) {
if(Math.abs(target.x - object.x) > C.RANGE_SIGN_CONTROLLER || Math.abs(target.y - object.y) > C.RANGE_SIGN_CONTROLLER) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/processor/intents/creeps/transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = function(object, intent, roomObjects, roomTerrain, bulk, bulkUs
if(!target) {
return;
}
if(Math.abs(target.x - object.x) > 1 || Math.abs(target.y - object.y) > 1) {
if(Math.abs(target.x - object.x) > C.RANGE_TRANSFER || Math.abs(target.y - object.y) > C.RANGE_TRANSFER) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/processor/intents/creeps/upgradeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = function(object, intent, roomObjects, roomTerrain, bulk, bulkUs
if(!target || target.type != 'controller') {
return;
}
if(Math.abs(target.x - object.x) > 3 || Math.abs(target.y - object.y) > 3) {
if(Math.abs(target.x - object.x) > C.RANGE_UPGRADE_CONTROLLER || Math.abs(target.y - object.y) > C.RANGE_UPGRADE_CONTROLLER) {
return;
}
if(target.level == 0 || target.user != object.user) {
Expand Down
2 changes: 1 addition & 1 deletion src/processor/intents/creeps/withdraw.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = function(object, intent, roomObjects, roomTerrain, bulk, bulkUs
if(object.user != target.user && _.any(roomObjects, i => i.type == C.STRUCTURE_RAMPART && i.user != object.user && !i.isPublic && i.x == target.x && i.y == target.y)) {
return;
}
if(Math.abs(target.x - object.x) > 1 || Math.abs(target.y - object.y) > 1) {
if(Math.abs(target.x - object.x) > C.RANGE_WITHDRAW || Math.abs(target.y - object.y) > C.RANGE_WITHDRAW) {
return;
}

Expand Down
Loading

0 comments on commit 5cfa531

Please sign in to comment.