File tree Expand file tree Collapse file tree 5 files changed +113
-0
lines changed
src/tower-effectiveness-at-range Expand file tree Collapse file tree 5 files changed +113
-0
lines changed Original file line number Diff line number Diff line change
1
+ export function towerEffectivenessAtRange (
2
+ range : number ,
3
+ max : number ,
4
+ ) : number {
5
+ if ( range <= TOWER_OPTIMAL_RANGE ) {
6
+ return max ;
7
+ }
8
+ if ( range >= TOWER_FALLOFF_RANGE ) {
9
+ return max * ( 1 - TOWER_FALLOFF ) ;
10
+ }
11
+
12
+ const towerFalloffPerTile = TOWER_FALLOFF / ( TOWER_FALLOFF_RANGE - TOWER_OPTIMAL_RANGE ) ;
13
+
14
+ return max * ( 1 - ( range - TOWER_OPTIMAL_RANGE ) * towerFalloffPerTile ) ;
15
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " @open-screeps/tower-effectiveness-at-range" ,
3
+ "version" : " 0.0.0-development" ,
4
+ "description" : " Calculate the effectiveness of tower actions at the given range" ,
5
+ "main" : " index.js" ,
6
+ "scripts" : {
7
+ "lint" : " tslint -p ./tsconfig.json" ,
8
+ "test" : " tsc && nyc ava" ,
9
+ "prepare" : " npm test" ,
10
+ "release" : " semantic-release -e semantic-release-monorepo"
11
+ },
12
+ "repository" : {
13
+ "type" : " git" ,
14
+ "url" : " git+https://github.com/postcrafter/open-screeps.git"
15
+ },
16
+ "files" : [
17
+ " index.{d.ts,js,js.map}"
18
+ ],
19
+ "keywords" : [
20
+ " screeps" ,
21
+ " open-screeps"
22
+ ],
23
+ "author" : " Adam Laycock <adam@arcath.net>" ,
24
+ "license" : " MIT" ,
25
+ "bugs" : {
26
+ "url" : " https://github.com/postcrafter/open-screeps/issues"
27
+ },
28
+ "homepage" : " https://github.com/postcrafter/open-screeps/src/tower-effectiveness-at-range#readme" ,
29
+ "dependencies" : {
30
+ "@types/screeps" : " ^0.0.0"
31
+ },
32
+ "devDependencies" : {
33
+ "ava" : " ^0.24.0" ,
34
+ "condition-circle" : " ^2.0.1" ,
35
+ "nyc" : " ^11.3.0" ,
36
+ "semantic-release" : " ^11.0.2" ,
37
+ "semantic-release-monorepo" : " ^4.0.0" ,
38
+ "tslint" : " ^5.9.1" ,
39
+ "tslint-config-airbnb" : " ^5.4.2" ,
40
+ "typescript" : " ^2.6.2"
41
+ },
42
+ "publishConfig" : {
43
+ "access" : " public"
44
+ },
45
+ "release" : {
46
+ "verifyConditions" : " condition-circle"
47
+ }
48
+ }
Original file line number Diff line number Diff line change
1
+ # tower-effectiveness-at-range
2
+ > Calculate the effectiveness of tower actions at the given range
3
+
4
+ ## Install
5
+ ``` sh
6
+ $ npm install @open-screeps/tower-effectiveness-at-range
7
+ ```
8
+
9
+ ## Usage
10
+ ``` typescript
11
+ import { towerEffectivenessAtRange } from ' @open-screeps/tower-effectiveness-at-range' ;
12
+
13
+ let damage = towerEffectivenessAtRange (creep .pos .getRangeTo (tower ));
14
+
15
+ let heal = towerEffectivenessAtRange (creep .pos .getRangeTo (tower ), ' heal' );
16
+
17
+ let repair = towerEffectivenessAtRange (container .pos .getRangeTo (tower ), ' repair' );
18
+ ```
19
+
20
+ ## Related
21
+
22
+ ## License
23
+ [ MIT] ( ../../license.md )
Original file line number Diff line number Diff line change
1
+ import ava from 'ava' ;
2
+
3
+ import { towerEffectivenessAtRange } from './index' ;
4
+
5
+ declare const global : any ;
6
+
7
+ global . TOWER_HITS = 3000 ;
8
+ global . TOWER_CAPACITY = 1000 ;
9
+ global . TOWER_ENERGY_COST = 10 ;
10
+ global . TOWER_POWER_ATTACK = 600 ;
11
+ global . TOWER_POWER_HEAL = 400 ;
12
+ global . TOWER_POWER_REPAIR = 800 ;
13
+ global . TOWER_OPTIMAL_RANGE = 5 ;
14
+ global . TOWER_FALLOFF_RANGE = 20 ;
15
+ global . TOWER_FALLOFF = 0.75 ;
16
+
17
+ ava ( 'Should calculate the tower effectiveness for the given ranges' , ( t ) => {
18
+ t . is ( towerEffectivenessAtRange ( 2 , TOWER_POWER_ATTACK ) , 600 ) ;
19
+ t . is ( towerEffectivenessAtRange ( 21 , TOWER_POWER_ATTACK ) , 150 ) ;
20
+ t . is ( towerEffectivenessAtRange ( 10 , TOWER_POWER_ATTACK ) , 450 ) ;
21
+ t . is ( towerEffectivenessAtRange ( 15 , TOWER_POWER_ATTACK ) , 300 ) ;
22
+ t . is ( towerEffectivenessAtRange ( 2 , TOWER_POWER_HEAL ) , 400 ) ;
23
+ t . is ( towerEffectivenessAtRange ( 2 , TOWER_POWER_REPAIR ) , 800 ) ;
24
+ } ) ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "extends" : " ../../tsconfig.base.json"
3
+ }
You can’t perform that action at this time.
0 commit comments