Skip to content

Commit 2f6b331

Browse files
committed
Add a couple more tests around accessing BOOSTS
1 parent 1f73abf commit 2f6b331

File tree

1 file changed

+158
-1
lines changed

1 file changed

+158
-1
lines changed

dist/screeps-tests.ts

Lines changed: 158 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,8 +1020,165 @@ function resources(o: GenericStore): ResourceConstant[] {
10201020
EXTENSION_ENERGY_CAPACITY[Game.rooms.myRoom.controller!.level];
10211021

10221022
REACTIONS[Object.keys(creep.carry)[0]];
1023+
}
1024+
1025+
{
1026+
// Test the BOOSTS constant
1027+
1028+
// Can be used with a body part, returns a record of mineral -> boosted property -> level
1029+
const c = BOOSTS[creep.body[0].type];
1030+
1031+
// Can be used with all body part types, returns undefined
1032+
const undef = BOOSTS["claim"];
1033+
1034+
// Can still be iterated over
1035+
for (const bodyPart of Object.keys(BOOSTS) as BodyPartConstant[]) {
1036+
const boosts = BOOSTS[bodyPart];
1037+
for (const mineral of Object.keys(boosts) as MineralBoostConstant[]) {
1038+
const upgrades = boosts[mineral];
1039+
}
1040+
}
1041+
}
10231042

1024-
BOOSTS[creep.body[0].type];
1043+
{
1044+
// Boost estimation code lifted from Overmind
1045+
1046+
type HARVEST = "harvest";
1047+
type CONSTRUCT = "construct";
1048+
type DISMANTLE = "dismantle";
1049+
type UPGRADE = "upgrade";
1050+
const HARVEST: HARVEST = "harvest";
1051+
const CONSTRUCT: CONSTRUCT = "construct";
1052+
const DISMANTLE: DISMANTLE = "dismantle";
1053+
const UPGRADE: UPGRADE = "upgrade";
1054+
1055+
type BoostTier = "T1" | "T2" | "T3";
1056+
type BoostType = ATTACK | CARRY | RANGED_ATTACK | HEAL | MOVE | TOUGH | HARVEST | CONSTRUCT | DISMANTLE | UPGRADE;
1057+
1058+
const BOOST_TIERS: {
1059+
[boostType in BoostType]: {
1060+
[boostTier in BoostTier]: MineralBoostConstant;
1061+
};
1062+
} = {
1063+
attack: {
1064+
T1: "UH",
1065+
T2: "UH2O",
1066+
T3: "XUH2O",
1067+
},
1068+
carry: {
1069+
T1: "KH",
1070+
T2: "KH2O",
1071+
T3: "XKH2O",
1072+
},
1073+
ranged_attack: {
1074+
T1: "KO",
1075+
T2: "KHO2",
1076+
T3: "XKHO2",
1077+
},
1078+
heal: {
1079+
T1: "LO",
1080+
T2: "LHO2",
1081+
T3: "XLHO2",
1082+
},
1083+
move: {
1084+
T1: "ZO",
1085+
T2: "ZHO2",
1086+
T3: "XZHO2",
1087+
},
1088+
tough: {
1089+
T1: "GO",
1090+
T2: "GHO2",
1091+
T3: "XGHO2",
1092+
},
1093+
harvest: {
1094+
T1: "UO",
1095+
T2: "UHO2",
1096+
T3: "XUHO2",
1097+
},
1098+
construct: {
1099+
T1: "LH",
1100+
T2: "LH2O",
1101+
T3: "XLH2O",
1102+
},
1103+
dismantle: {
1104+
T1: "ZH",
1105+
T2: "ZH2O",
1106+
T3: "XZH2O",
1107+
},
1108+
upgrade: {
1109+
T1: "GH",
1110+
T2: "GH2O",
1111+
T3: "XGH2O",
1112+
},
1113+
};
1114+
1115+
const BoostTypeBodyparts: {
1116+
[boostType in BoostType]: BodyPartConstant;
1117+
} = {
1118+
[ATTACK]: ATTACK,
1119+
[CARRY]: CARRY,
1120+
[RANGED_ATTACK]: RANGED_ATTACK,
1121+
[HEAL]: HEAL,
1122+
[MOVE]: MOVE,
1123+
[TOUGH]: TOUGH,
1124+
[HARVEST]: WORK,
1125+
[CONSTRUCT]: WORK,
1126+
[DISMANTLE]: WORK,
1127+
[UPGRADE]: WORK,
1128+
};
1129+
1130+
const BoostTypeToBoostArray: {
1131+
[boostType in BoostType]: BoostModifier;
1132+
} = {
1133+
[ATTACK]: ATTACK,
1134+
[CARRY]: "capacity",
1135+
[RANGED_ATTACK]: "rangedAttack",
1136+
// [RANGED_MASS_ATTACK]: "rangedMassAttack",
1137+
[HEAL]: HEAL,
1138+
[MOVE]: "fatigue",
1139+
[TOUGH]: "damage",
1140+
[HARVEST]: "harvest",
1141+
[CONSTRUCT]: "build",
1142+
// [REPAIR]: "repair",
1143+
[DISMANTLE]: "dismantle",
1144+
[UPGRADE]: "upgradeController",
1145+
};
1146+
1147+
/**
1148+
*
1149+
* @param body
1150+
* @param type
1151+
* @param intendedBoosts
1152+
* @returns
1153+
*/
1154+
function getBodyPotential(body: BodyPartDefinition[], type: BoostType, intendedBoosts: MineralBoostConstant[] = []): number {
1155+
const bodyPart = BoostTypeBodyparts[type];
1156+
return body.reduce((sum, part) => {
1157+
if (part.hits === 0) {
1158+
return sum + 0;
1159+
}
1160+
if (part.type === bodyPart) {
1161+
let boost = part.boost;
1162+
if (!boost && intendedBoosts) {
1163+
boost = intendedBoosts.find(
1164+
(boost) => boost === BOOST_TIERS[type].T1 || boost === BOOST_TIERS[type].T2 || boost === BOOST_TIERS[type].T3,
1165+
);
1166+
}
1167+
if (!boost) {
1168+
return sum + 1;
1169+
}
1170+
1171+
const key = BoostTypeToBoostArray[type];
1172+
const partBoost = BOOSTS[bodyPart];
1173+
if (!partBoost || !(boost in partBoost) || !partBoost[boost] || !(key in partBoost[boost])) {
1174+
return sum + 0;
1175+
}
1176+
1177+
return partBoost[boost][key];
1178+
}
1179+
return sum + 0;
1180+
}, 0);
1181+
}
10251182
}
10261183

10271184
// Tombstones

0 commit comments

Comments
 (0)