Skip to content

Commit 5cfa531

Browse files
RiftLurkerLeo Friedrichs
authored andcommitted
Use RANGE_* constants
1 parent 7df5e3f commit 5cfa531

29 files changed

+55
-55
lines changed

src/game/creeps.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
310310
if(!target.energy) {
311311
return C.ERR_NOT_ENOUGH_RESOURCES;
312312
}
313-
if(!target.pos.isNearTo(this.pos)) {
313+
if(!target.pos.inRangeTo(this.pos, C.RANGE_HARVEST_SOURCE)) {
314314
return C.ERR_NOT_IN_RANGE;
315315
}
316316
if(this.room.controller && (
@@ -325,7 +325,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
325325
if(!target.mineralAmount) {
326326
return C.ERR_NOT_ENOUGH_RESOURCES;
327327
}
328-
if(!target.pos.isNearTo(this.pos)) {
328+
if(!target.pos.inRangeTo(this.pos, C.RANGE_HARVEST_MINERAL)) {
329329
return C.ERR_NOT_IN_RANGE;
330330
}
331331
var extractor = _.find(target.pos.lookFor('structure'), {structureType: C.STRUCTURE_EXTRACTOR});
@@ -433,7 +433,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
433433
}
434434
}
435435

436-
if(!target.pos.isNearTo(this.pos)) {
436+
if(!target.pos.inRangeTo(this.pos, C.RANGE_TRANSFER)) {
437437
return C.ERR_NOT_IN_RANGE;
438438
}
439439
if(!data(this.id)[resourceType]) {
@@ -574,7 +574,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
574574
}
575575
}
576576

577-
if(!target.pos.isNearTo(this.pos)) {
577+
if(!target.pos.inRangeTo(this.pos, C.RANGE_WITHDRAW)) {
578578
return C.ERR_NOT_IN_RANGE;
579579
}
580580

@@ -646,7 +646,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
646646
if(utils.calcResources(this.carry) >= this.carryCapacity) {
647647
return C.ERR_FULL;
648648
}
649-
if(!target.pos.isNearTo(this.pos)) {
649+
if(!target.pos.inRangeTo(this.pos, C.RANGE_PICKUP)) {
650650
return C.ERR_NOT_IN_RANGE;
651651
}
652652

@@ -678,7 +678,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
678678
register.assertTargetObject(target);
679679
return C.ERR_INVALID_TARGET;
680680
}
681-
if(!target.pos.isNearTo(this.pos)) {
681+
if(!target.pos.inRangeTo(this.pos, C.RANGE_ATTACK)) {
682682
return C.ERR_NOT_IN_RANGE;
683683
}
684684

@@ -706,7 +706,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
706706
register.assertTargetObject(target);
707707
return C.ERR_INVALID_TARGET;
708708
}
709-
if(!this.pos.inRangeTo(target, 3)) {
709+
if(!this.pos.inRangeTo(target, C.RANGE_RANGED_ATTACK)) {
710710
return C.ERR_NOT_IN_RANGE;
711711
}
712712

@@ -750,7 +750,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
750750
register.assertTargetObject(target);
751751
return C.ERR_INVALID_TARGET;
752752
}
753-
if(!target.pos.isNearTo(this.pos)) {
753+
if(!target.pos.inRangeTo(this.pos, C.RANGE_HEAL)) {
754754
return C.ERR_NOT_IN_RANGE;
755755
}
756756
if(this.room.controller && !this.room.controller.my && this.room.controller.safeMode) {
@@ -808,7 +808,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
808808
register.assertTargetObject(target);
809809
return C.ERR_INVALID_TARGET;
810810
}
811-
if(!this.pos.inRangeTo(target, 3)) {
811+
if(!this.pos.inRangeTo(target, C.RANGE_REPAIR)) {
812812
return C.ERR_NOT_IN_RANGE;
813813
}
814814

@@ -835,7 +835,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
835835
register.assertTargetObject(target);
836836
return C.ERR_INVALID_TARGET;
837837
}
838-
if(!this.pos.inRangeTo(target, 3)) {
838+
if(!this.pos.inRangeTo(target, C.RANGE_BUILD)) {
839839
return C.ERR_NOT_IN_RANGE;
840840
}
841841
if(_.contains(['spawn','extension','constructedWall'], target.structureType) &&
@@ -906,7 +906,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
906906
if(this.getActiveBodyparts(C.CLAIM) == 0) {
907907
return C.ERR_NO_BODYPART;
908908
}
909-
if(!target.pos.isNearTo(this.pos)) {
909+
if(!target.pos.inRangeTo(this.pos, C.RANGE_CLAIM_CONTROLLER)) {
910910
return C.ERR_NOT_IN_RANGE;
911911
}
912912
if(target.structureType != 'controller') {
@@ -942,7 +942,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
942942
if(this.getActiveBodyparts(C.CLAIM) < 5) {
943943
return C.ERR_NO_BODYPART;
944944
}
945-
if(!target.pos.isNearTo(this.pos)) {
945+
if(!target.pos.inRangeTo(this.pos, C.RANGE_ATTACK_CONTROLLER)) {
946946
return C.ERR_NOT_IN_RANGE;
947947
}
948948
if(!target.owner && !target.reservation) {
@@ -977,7 +977,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
977977
if(target.upgradeBlocked && target.upgradeBlocked > 0) {
978978
return C.ERR_INVALID_TARGET;
979979
}
980-
if(!target.pos.inRangeTo(this.pos, 3)) {
980+
if(!target.pos.inRangeTo(this.pos, C.RANGE_UPGRADE_CONTROLLER)) {
981981
return C.ERR_NOT_IN_RANGE;
982982
}
983983
if(!target.my) {
@@ -1004,7 +1004,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
10041004
register.assertTargetObject(target);
10051005
return C.ERR_INVALID_TARGET;
10061006
}
1007-
if(!target.pos.isNearTo(this.pos)) {
1007+
if(!target.pos.inRangeTo(this.pos, C.RANGE_RESERVE_CONTROLLER)) {
10081008
return C.ERR_NOT_IN_RANGE;
10091009
}
10101010
if(target.structureType != 'controller') {
@@ -1070,7 +1070,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
10701070
register.assertTargetObject(target);
10711071
return C.ERR_INVALID_TARGET;
10721072
}
1073-
if(!target.pos.isNearTo(this.pos)) {
1073+
if(!target.pos.inRangeTo(this.pos, C.RANGE_DISMANTLE)) {
10741074
return C.ERR_NOT_IN_RANGE;
10751075
}
10761076
if(this.room.controller && !this.room.controller.my && this.room.controller.safeMode) {
@@ -1096,7 +1096,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
10961096
register.assertTargetObject(target);
10971097
return C.ERR_INVALID_TARGET;
10981098
}
1099-
if(!target.pos.isNearTo(this.pos)) {
1099+
if(!target.pos.inRangeTo(this.pos, C.RANGE_GENERATE_SAFEMODE)) {
11001100
return C.ERR_NOT_IN_RANGE;
11011101
}
11021102

@@ -1114,7 +1114,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
11141114
register.assertTargetObject(target);
11151115
return C.ERR_INVALID_TARGET;
11161116
}
1117-
if(!target.pos.isNearTo(this.pos)) {
1117+
if(!target.pos.inRangeTo(this.pos, C.RANGE_SIGN_CONTROLLER)) {
11181118
return C.ERR_NOT_IN_RANGE;
11191119
}
11201120
if(target.structureType != 'controller') {

src/game/structures.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function _transfer(target, resourceType, amount) {
5252
if (data(target.id).energyCapacity && (!amount || utils.calcResources(data(target.id)) + amount > data(target.id).energyCapacity)) {
5353
return C.ERR_FULL;
5454
}
55-
if (!target.pos.isNearTo(this.pos)) {
55+
if (!target.pos.inRangeTo(this.pos, C.RANGE_TRANSFER)) {
5656
return C.ERR_NOT_IN_RANGE;
5757
}
5858

@@ -89,7 +89,7 @@ function _transferEnergy(target, amount) {
8989
if(data(target.id).energyCapacity && (!amount || utils.calcResources(data(target.id)) + amount > data(target.id).energyCapacity)) {
9090
return C.ERR_FULL;
9191
}
92-
if(!target.pos.isNearTo(this.pos)) {
92+
if(!target.pos.inRangeTo(this.pos, C.RANGE_TRANSFER)) {
9393
return C.ERR_NOT_IN_RANGE;
9494
}
9595

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

@@ -431,7 +431,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
431431
register.assertTargetObject(lab2);
432432
return C.ERR_INVALID_TARGET;
433433
}
434-
if(this.pos.getRangeTo(lab1) > 2 || this.pos.getRangeTo(lab2) > 2) {
434+
if(this.pos.getRangeTo(lab1) > C.RANGE_RUN_REACTION || this.pos.getRangeTo(lab2) > C.RANGE_RUN_REACTION) {
435435
return C.ERR_NOT_IN_RANGE;
436436
}
437437
if(this.mineralAmount > this.mineralCapacity - C.LAB_REACTION_AMOUNT) {
@@ -460,7 +460,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
460460
register.assertTargetObject(target);
461461
return C.ERR_INVALID_TARGET;
462462
}
463-
if(!this.pos.isNearTo(target)) {
463+
if(!this.pos.inRangeTo(target, C.RANGE_BOOST_CREEP)) {
464464
return C.ERR_NOT_IN_RANGE;
465465
}
466466
if(data(this.id).energy < C.LAB_BOOST_ENERGY) {
@@ -531,7 +531,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
531531
return C.ERR_RCL_NOT_ENOUGH;
532532
}
533533
}
534-
if ((target instanceof globals.Creep) && !this.pos.isNearTo(target)) {
534+
if ((target instanceof globals.Creep) && !this.pos.inRangeTo(target, C.RANGE_TRANSFER)) {
535535
return C.ERR_NOT_IN_RANGE;
536536
}
537537
if (!data(this.id).energy) {
@@ -1092,7 +1092,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
10921092
if(data(target.id).energy == data(target.id).energyCapacity) {
10931093
return C.ERR_FULL;
10941094
}
1095-
if(!target.pos.isNearTo(this.pos)) {
1095+
if(!target.pos.inRangeTo(this.pos, C.RANGE_TRANSFER)) {
10961096
return C.ERR_NOT_IN_RANGE;
10971097
}
10981098

@@ -1144,7 +1144,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
11441144
if(!target.my) {
11451145
return C.ERR_NOT_OWNER;
11461146
}
1147-
if(!target.pos.isNearTo(this.pos)) {
1147+
if(!target.pos.inRangeTo(this.pos, C.RANGE_RENEW_CREEP)) {
11481148
return C.ERR_NOT_IN_RANGE;
11491149
}
11501150
if(this.spawning) {
@@ -1176,7 +1176,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
11761176
if(!target.my) {
11771177
return C.ERR_NOT_OWNER;
11781178
}
1179-
if(!target.pos.isNearTo(this.pos)) {
1179+
if(!target.pos.inRangeTo(this.pos, C.RANGE_RECYCLE_CREEP)) {
11801180
return C.ERR_NOT_IN_RANGE;
11811181
}
11821182

src/processor/intents/creeps/attack.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = function(object, intent, roomObjects, roomTerrain, bulk, bulkUs
1616
if(!target || target == object) {
1717
return;
1818
}
19-
if(Math.abs(target.x - object.x) > 1 || Math.abs(target.y - object.y) > 1) {
19+
if(Math.abs(target.x - object.x) > C.RANGE_ATTACK || Math.abs(target.y - object.y) > C.RANGE_ATTACK) {
2020
return;
2121
}
2222
if(target.type == 'creep' && target.spawning) {

src/processor/intents/creeps/attackController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = function(object, intent, roomObjects, roomTerrain, bulk, bulkUs
1616
if(!target || target.type != 'controller') {
1717
return;
1818
}
19-
if(Math.abs(target.x - object.x) > 1 || Math.abs(target.y - object.y) > 1) {
19+
if(Math.abs(target.x - object.x) > C.RANGE_ATTACK_CONTROLLER || Math.abs(target.y - object.y) > C.RANGE_ATTACK_CONTROLLER) {
2020
return;
2121
}
2222
if(!target.user && !target.reservation) {

src/processor/intents/creeps/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = function(object, intent, roomObjects, roomTerrain, bulk, bulkUs
2020
!C.CONSTRUCTION_COST[target.structureType]) {
2121
return;
2222
}
23-
if(Math.abs(target.x - object.x) > 3 || Math.abs(target.y - object.y) > 3) {
23+
if(Math.abs(target.x - object.x) > C.RANGE_BUILD || Math.abs(target.y - object.y) > C.RANGE_BUILD) {
2424
return;
2525
}
2626
if(_.any(roomObjects, {x: target.x, y: target.y, type: target.structureType})) {

src/processor/intents/creeps/claimController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = function(object, intent, roomObjects, roomTerrain, bulk, bulkUs
1616
if(!target || target.type != 'controller') {
1717
return;
1818
}
19-
if(Math.abs(target.x - object.x) > 1 || Math.abs(target.y - object.y) > 1) {
19+
if(Math.abs(target.x - object.x) > C.RANGE_CLAIM_CONTROLLER || Math.abs(target.y - object.y) > C.RANGE_CLAIM_CONTROLLER) {
2020
return;
2121
}
2222
if(target.bindUser && object.user != target.bindUser) {

src/processor/intents/creeps/dismantle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = function(object, intent, roomObjects, roomTerrain, bulk, bulkUs
1616
if(!target || !C.CONSTRUCTION_COST[target.type]) {
1717
return;
1818
}
19-
if(Math.abs(target.x - object.x) > 1 || Math.abs(target.y - object.y) > 1) {
19+
if(Math.abs(target.x - object.x) > C.RANGE_DISMANTLE || Math.abs(target.y - object.y) > C.RANGE_DISMANTLE) {
2020
return;
2121
}
2222
if(roomController && roomController.user != object.user && roomController.safeMode > gameTime) {

src/processor/intents/creeps/generateSafeMode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = function(object, intent, roomObjects, roomTerrain, bulk, bulkUs
1313
if(!target || target.type != 'controller') {
1414
return;
1515
}
16-
if(Math.abs(target.x - object.x) > 1 || Math.abs(target.y - object.y) > 1) {
16+
if(Math.abs(target.x - object.x) > C.RANGE_GENERATE_SAFEMODE || Math.abs(target.y - object.y) > C.RANGE_GENERATE_SAFEMODE) {
1717
return;
1818
}
1919
if(!(object[C.RESOURCE_GHODIUM] >= C.SAFE_MODE_COST)) {

src/processor/intents/creeps/harvest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = function(object, intent, roomObjects, roomTerrain, bulk, bulkUs
1616
if(!target) {
1717
return;
1818
}
19-
if(Math.abs(target.x - object.x) > 1 || Math.abs(target.y - object.y) > 1) {
19+
if(Math.abs(target.x - object.x) > C.RANGE_HARVEST || Math.abs(target.y - object.y) > C.RANGE_HARVEST) {
2020
return;
2121
}
2222

src/processor/intents/creeps/heal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = function(object, intent, roomObjects, roomTerrain, bulk, bulkUs
1616
if(!target || target.type != 'creep' || target.spawning || target.hits >= target.hitsMax) {
1717
return;
1818
}
19-
if(Math.abs(target.x - object.x) > 1 || Math.abs(target.y - object.y) > 1) {
19+
if(Math.abs(target.x - object.x) > C.RANGE_HEAL || Math.abs(target.y - object.y) > C.RANGE_HEAL) {
2020
return;
2121
}
2222
if(roomController && roomController.user != object.user && roomController.safeMode > gameTime) {

0 commit comments

Comments
 (0)