-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: tower effectiveness at range * fix: supply the tower power in the function
- Loading branch information
1 parent
9a01ad6
commit ad42ed7
Showing
5 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export function towerEffectivenessAtRange( | ||
range: number, | ||
max: number, | ||
): number { | ||
if (range <= TOWER_OPTIMAL_RANGE) { | ||
return max; | ||
} | ||
if (range >= TOWER_FALLOFF_RANGE) { | ||
return max * (1 - TOWER_FALLOFF); | ||
} | ||
|
||
const towerFalloffPerTile = TOWER_FALLOFF / (TOWER_FALLOFF_RANGE - TOWER_OPTIMAL_RANGE); | ||
|
||
return max * (1 - (range - TOWER_OPTIMAL_RANGE) * towerFalloffPerTile); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"name": "@open-screeps/tower-effectiveness-at-range", | ||
"version": "0.0.0-development", | ||
"description": "Calculate the effectiveness of tower actions at the given range", | ||
"main": "index.js", | ||
"scripts": { | ||
"lint": "tslint -p ./tsconfig.json", | ||
"test": "tsc && nyc ava", | ||
"prepare": "npm test", | ||
"release": "semantic-release -e semantic-release-monorepo" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/postcrafter/open-screeps.git" | ||
}, | ||
"files": [ | ||
"index.{d.ts,js,js.map}" | ||
], | ||
"keywords": [ | ||
"screeps", | ||
"open-screeps" | ||
], | ||
"author": "Adam Laycock <[email protected]>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/postcrafter/open-screeps/issues" | ||
}, | ||
"homepage": "https://github.com/postcrafter/open-screeps/src/tower-effectiveness-at-range#readme", | ||
"dependencies": { | ||
"@types/screeps": "^0.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^0.24.0", | ||
"condition-circle": "^2.0.1", | ||
"nyc": "^11.3.0", | ||
"semantic-release": "^11.0.2", | ||
"semantic-release-monorepo": "^4.0.0", | ||
"tslint": "^5.9.1", | ||
"tslint-config-airbnb": "^5.4.2", | ||
"typescript": "^2.6.2" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"release": { | ||
"verifyConditions": "condition-circle" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# tower-effectiveness-at-range | ||
> Calculate the effectiveness of tower actions at the given range | ||
## Install | ||
```sh | ||
$ npm install @open-screeps/tower-effectiveness-at-range | ||
``` | ||
|
||
## Usage | ||
```typescript | ||
import { towerEffectivenessAtRange } from '@open-screeps/tower-effectiveness-at-range'; | ||
|
||
let damage = towerEffectivenessAtRange(creep.pos.getRangeTo(tower)); | ||
|
||
let heal = towerEffectivenessAtRange(creep.pos.getRangeTo(tower), 'heal'); | ||
|
||
let repair = towerEffectivenessAtRange(container.pos.getRangeTo(tower), 'repair'); | ||
``` | ||
|
||
## Related | ||
|
||
## License | ||
[MIT](../../license.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import ava from 'ava'; | ||
|
||
import { towerEffectivenessAtRange } from './index'; | ||
|
||
declare const global: any; | ||
|
||
global.TOWER_HITS = 3000; | ||
global.TOWER_CAPACITY = 1000; | ||
global.TOWER_ENERGY_COST = 10; | ||
global.TOWER_POWER_ATTACK = 600; | ||
global.TOWER_POWER_HEAL = 400; | ||
global.TOWER_POWER_REPAIR = 800; | ||
global.TOWER_OPTIMAL_RANGE = 5; | ||
global.TOWER_FALLOFF_RANGE = 20; | ||
global.TOWER_FALLOFF = 0.75; | ||
|
||
ava('Should calculate the tower effectiveness for the given ranges', (t) => { | ||
t.is(towerEffectivenessAtRange(2, TOWER_POWER_ATTACK), 600); | ||
t.is(towerEffectivenessAtRange(21, TOWER_POWER_ATTACK), 150); | ||
t.is(towerEffectivenessAtRange(10, TOWER_POWER_ATTACK), 450); | ||
t.is(towerEffectivenessAtRange(15, TOWER_POWER_ATTACK), 300); | ||
t.is(towerEffectivenessAtRange(2, TOWER_POWER_HEAL), 400); | ||
t.is(towerEffectivenessAtRange(2, TOWER_POWER_REPAIR), 800); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json" | ||
} |