-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix typing of creep.body[n].boost
to use mineral boosts
#257
Open
tiennou
wants to merge
2
commits into
screepers:master
Choose a base branch
from
tiennou:fix/mineral-boosts
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -1030,8 +1030,165 @@ function resources(o: GenericStore): ResourceConstant[] { | |
EXTENSION_ENERGY_CAPACITY[Game.rooms.myRoom.controller!.level]; | ||
|
||
REACTIONS[Object.keys(creep.carry)[0]]; | ||
} | ||
|
||
{ | ||
// Test the BOOSTS constant | ||
|
||
// Can be used with a body part, returns a record of mineral -> boosted property -> level | ||
const c = BOOSTS[creep.body[0].type]; | ||
|
||
// Can be used with all body part types, returns undefined | ||
const undef = BOOSTS["claim"]; | ||
|
||
// Can still be iterated over | ||
for (const bodyPart of Object.keys(BOOSTS) as BodyPartConstant[]) { | ||
const boosts = BOOSTS[bodyPart]; | ||
for (const mineral of Object.keys(boosts) as MineralBoostConstant[]) { | ||
const upgrades = boosts[mineral]; | ||
} | ||
} | ||
} | ||
|
||
BOOSTS[creep.body[0].type]; | ||
{ | ||
// Boost estimation code lifted from Overmind | ||
|
||
type HARVEST = "harvest"; | ||
type CONSTRUCT = "construct"; | ||
type DISMANTLE = "dismantle"; | ||
type UPGRADE = "upgrade"; | ||
const HARVEST: HARVEST = "harvest"; | ||
const CONSTRUCT: CONSTRUCT = "construct"; | ||
const DISMANTLE: DISMANTLE = "dismantle"; | ||
const UPGRADE: UPGRADE = "upgrade"; | ||
|
||
type BoostTier = "T1" | "T2" | "T3"; | ||
type BoostType = ATTACK | CARRY | RANGED_ATTACK | HEAL | MOVE | TOUGH | HARVEST | CONSTRUCT | DISMANTLE | UPGRADE; | ||
|
||
const BOOST_TIERS: { | ||
[boostType in BoostType]: { | ||
[boostTier in BoostTier]: MineralBoostConstant; | ||
}; | ||
} = { | ||
attack: { | ||
T1: "UH", | ||
T2: "UH2O", | ||
T3: "XUH2O", | ||
}, | ||
carry: { | ||
T1: "KH", | ||
T2: "KH2O", | ||
T3: "XKH2O", | ||
}, | ||
ranged_attack: { | ||
T1: "KO", | ||
T2: "KHO2", | ||
T3: "XKHO2", | ||
}, | ||
heal: { | ||
T1: "LO", | ||
T2: "LHO2", | ||
T3: "XLHO2", | ||
}, | ||
move: { | ||
T1: "ZO", | ||
T2: "ZHO2", | ||
T3: "XZHO2", | ||
}, | ||
tough: { | ||
T1: "GO", | ||
T2: "GHO2", | ||
T3: "XGHO2", | ||
}, | ||
harvest: { | ||
T1: "UO", | ||
T2: "UHO2", | ||
T3: "XUHO2", | ||
}, | ||
construct: { | ||
T1: "LH", | ||
T2: "LH2O", | ||
T3: "XLH2O", | ||
}, | ||
dismantle: { | ||
T1: "ZH", | ||
T2: "ZH2O", | ||
T3: "XZH2O", | ||
}, | ||
upgrade: { | ||
T1: "GH", | ||
T2: "GH2O", | ||
T3: "XGH2O", | ||
}, | ||
}; | ||
|
||
const BoostTypeBodyparts: { | ||
[boostType in BoostType]: BodyPartConstant; | ||
} = { | ||
[ATTACK]: ATTACK, | ||
[CARRY]: CARRY, | ||
[RANGED_ATTACK]: RANGED_ATTACK, | ||
[HEAL]: HEAL, | ||
[MOVE]: MOVE, | ||
[TOUGH]: TOUGH, | ||
[HARVEST]: WORK, | ||
[CONSTRUCT]: WORK, | ||
[DISMANTLE]: WORK, | ||
[UPGRADE]: WORK, | ||
}; | ||
|
||
const BoostTypeToBoostArray: { | ||
[boostType in BoostType]: BoostModifier; | ||
} = { | ||
[ATTACK]: ATTACK, | ||
[CARRY]: "capacity", | ||
[RANGED_ATTACK]: "rangedAttack", | ||
// [RANGED_MASS_ATTACK]: "rangedMassAttack", | ||
[HEAL]: HEAL, | ||
[MOVE]: "fatigue", | ||
[TOUGH]: "damage", | ||
[HARVEST]: "harvest", | ||
[CONSTRUCT]: "build", | ||
// [REPAIR]: "repair", | ||
[DISMANTLE]: "dismantle", | ||
[UPGRADE]: "upgradeController", | ||
}; | ||
|
||
/** | ||
* | ||
* @param body | ||
* @param type | ||
* @param intendedBoosts | ||
* @returns | ||
*/ | ||
function getBodyPotential(body: BodyPartDefinition[], type: BoostType, intendedBoosts: MineralBoostConstant[] = []): number { | ||
const bodyPart = BoostTypeBodyparts[type]; | ||
return body.reduce((sum, part) => { | ||
if (part.hits === 0) { | ||
return sum + 0; | ||
} | ||
if (part.type === bodyPart) { | ||
let boost = part.boost; | ||
if (!boost && intendedBoosts) { | ||
boost = intendedBoosts.find( | ||
(boost) => boost === BOOST_TIERS[type].T1 || boost === BOOST_TIERS[type].T2 || boost === BOOST_TIERS[type].T3, | ||
); | ||
} | ||
if (!boost) { | ||
return sum + 1; | ||
} | ||
|
||
const key = BoostTypeToBoostArray[type]; | ||
const partBoost = BOOSTS[bodyPart]; | ||
if (!partBoost || !(boost in partBoost) || !partBoost[boost] || !(key in partBoost[boost])) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of the
|
||
return sum + 0; | ||
} | ||
|
||
return partBoost[boost][key]; | ||
} | ||
return sum + 0; | ||
}, 0); | ||
} | ||
} | ||
|
||
// Tombstones | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without the fixes, this fails with