@@ -1030,8 +1030,165 @@ function resources(o: GenericStore): ResourceConstant[] {
10301030 EXTENSION_ENERGY_CAPACITY [ Game . rooms . myRoom . controller ! . level ] ;
10311031
10321032 REACTIONS [ Object . keys ( creep . carry ) [ 0 ] ] ;
1033+ }
1034+
1035+ {
1036+ // Test the BOOSTS constant
1037+
1038+ // Can be used with a body part, returns a record of mineral -> boosted property -> level
1039+ const c = BOOSTS [ creep . body [ 0 ] . type ] ;
1040+
1041+ // Can be used with all body part types, returns undefined
1042+ const undef = BOOSTS [ "claim" ] ;
1043+
1044+ // Can still be iterated over
1045+ for ( const bodyPart of Object . keys ( BOOSTS ) as BodyPartConstant [ ] ) {
1046+ const boosts = BOOSTS [ bodyPart ] ;
1047+ for ( const mineral of Object . keys ( boosts ) as MineralBoostConstant [ ] ) {
1048+ const upgrades = boosts [ mineral ] ;
1049+ }
1050+ }
1051+ }
10331052
1034- BOOSTS [ creep . body [ 0 ] . type ] ;
1053+ {
1054+ // Boost estimation code lifted from Overmind
1055+
1056+ type HARVEST = "harvest" ;
1057+ type CONSTRUCT = "construct" ;
1058+ type DISMANTLE = "dismantle" ;
1059+ type UPGRADE = "upgrade" ;
1060+ const HARVEST : HARVEST = "harvest" ;
1061+ const CONSTRUCT : CONSTRUCT = "construct" ;
1062+ const DISMANTLE : DISMANTLE = "dismantle" ;
1063+ const UPGRADE : UPGRADE = "upgrade" ;
1064+
1065+ type BoostTier = "T1" | "T2" | "T3" ;
1066+ type BoostType = ATTACK | CARRY | RANGED_ATTACK | HEAL | MOVE | TOUGH | HARVEST | CONSTRUCT | DISMANTLE | UPGRADE ;
1067+
1068+ const BOOST_TIERS : {
1069+ [ boostType in BoostType ] : {
1070+ [ boostTier in BoostTier ] : MineralBoostConstant ;
1071+ } ;
1072+ } = {
1073+ attack : {
1074+ T1 : "UH" ,
1075+ T2 : "UH2O" ,
1076+ T3 : "XUH2O" ,
1077+ } ,
1078+ carry : {
1079+ T1 : "KH" ,
1080+ T2 : "KH2O" ,
1081+ T3 : "XKH2O" ,
1082+ } ,
1083+ ranged_attack : {
1084+ T1 : "KO" ,
1085+ T2 : "KHO2" ,
1086+ T3 : "XKHO2" ,
1087+ } ,
1088+ heal : {
1089+ T1 : "LO" ,
1090+ T2 : "LHO2" ,
1091+ T3 : "XLHO2" ,
1092+ } ,
1093+ move : {
1094+ T1 : "ZO" ,
1095+ T2 : "ZHO2" ,
1096+ T3 : "XZHO2" ,
1097+ } ,
1098+ tough : {
1099+ T1 : "GO" ,
1100+ T2 : "GHO2" ,
1101+ T3 : "XGHO2" ,
1102+ } ,
1103+ harvest : {
1104+ T1 : "UO" ,
1105+ T2 : "UHO2" ,
1106+ T3 : "XUHO2" ,
1107+ } ,
1108+ construct : {
1109+ T1 : "LH" ,
1110+ T2 : "LH2O" ,
1111+ T3 : "XLH2O" ,
1112+ } ,
1113+ dismantle : {
1114+ T1 : "ZH" ,
1115+ T2 : "ZH2O" ,
1116+ T3 : "XZH2O" ,
1117+ } ,
1118+ upgrade : {
1119+ T1 : "GH" ,
1120+ T2 : "GH2O" ,
1121+ T3 : "XGH2O" ,
1122+ } ,
1123+ } ;
1124+
1125+ const BoostTypeBodyparts : {
1126+ [ boostType in BoostType ] : BodyPartConstant ;
1127+ } = {
1128+ [ ATTACK ] : ATTACK ,
1129+ [ CARRY ] : CARRY ,
1130+ [ RANGED_ATTACK ] : RANGED_ATTACK ,
1131+ [ HEAL ] : HEAL ,
1132+ [ MOVE ] : MOVE ,
1133+ [ TOUGH ] : TOUGH ,
1134+ [ HARVEST ] : WORK ,
1135+ [ CONSTRUCT ] : WORK ,
1136+ [ DISMANTLE ] : WORK ,
1137+ [ UPGRADE ] : WORK ,
1138+ } ;
1139+
1140+ const BoostTypeToBoostArray : {
1141+ [ boostType in BoostType ] : BoostModifier ;
1142+ } = {
1143+ [ ATTACK ] : ATTACK ,
1144+ [ CARRY ] : "capacity" ,
1145+ [ RANGED_ATTACK ] : "rangedAttack" ,
1146+ // [RANGED_MASS_ATTACK]: "rangedMassAttack",
1147+ [ HEAL ] : HEAL ,
1148+ [ MOVE ] : "fatigue" ,
1149+ [ TOUGH ] : "damage" ,
1150+ [ HARVEST ] : "harvest" ,
1151+ [ CONSTRUCT ] : "build" ,
1152+ // [REPAIR]: "repair",
1153+ [ DISMANTLE ] : "dismantle" ,
1154+ [ UPGRADE ] : "upgradeController" ,
1155+ } ;
1156+
1157+ /**
1158+ *
1159+ * @param body
1160+ * @param type
1161+ * @param intendedBoosts
1162+ * @returns
1163+ */
1164+ function getBodyPotential ( body : BodyPartDefinition [ ] , type : BoostType , intendedBoosts : MineralBoostConstant [ ] = [ ] ) : number {
1165+ const bodyPart = BoostTypeBodyparts [ type ] ;
1166+ return body . reduce ( ( sum , part ) => {
1167+ if ( part . hits === 0 ) {
1168+ return sum + 0 ;
1169+ }
1170+ if ( part . type === bodyPart ) {
1171+ let boost = part . boost ;
1172+ if ( ! boost && intendedBoosts ) {
1173+ boost = intendedBoosts . find (
1174+ ( boost ) => boost === BOOST_TIERS [ type ] . T1 || boost === BOOST_TIERS [ type ] . T2 || boost === BOOST_TIERS [ type ] . T3 ,
1175+ ) ;
1176+ }
1177+ if ( ! boost ) {
1178+ return sum + 1 ;
1179+ }
1180+
1181+ const key = BoostTypeToBoostArray [ type ] ;
1182+ const partBoost = BOOSTS [ bodyPart ] ;
1183+ if ( ! partBoost || ! ( boost in partBoost ) || ! partBoost [ boost ] || ! ( key in partBoost [ boost ] ) ) {
1184+ return sum + 0 ;
1185+ }
1186+
1187+ return partBoost [ boost ] [ key ] ;
1188+ }
1189+ return sum + 0 ;
1190+ } , 0 ) ;
1191+ }
10351192}
10361193
10371194// Tombstones
0 commit comments