fix: if two build buttons, move second to basics

This commit is contained in:
pavanvo 2022-08-12 04:09:03 +04:00 committed by Rampoina
parent f1e4a1bf83
commit f2b8d76383
1 changed files with 22 additions and 9 deletions

View File

@ -1238,10 +1238,12 @@ void UnitType::computeFirstCtOfClass() {
} }
void UnitType::sortCommandTypes(CommandTypes cts){ void UnitType::sortCommandTypes(CommandTypes cts){
try{
CommandTypes ctBuf(cts); CommandTypes ctBuf(cts);
CommandTypes ctCores; CommandTypes ctCores;
CommandTypes ctBasics = {NULL,NULL,NULL,NULL}; CommandTypes ctBasics = {NULL,NULL,NULL,NULL};
vector<int> basicNulls = {0,1,2,3};
CommandTypes ctMorphs; CommandTypes ctMorphs;
CommandTypes ctAttack; CommandTypes ctAttack;
@ -1259,6 +1261,7 @@ void UnitType::sortCommandTypes(CommandTypes cts){
CommandTypeFilter(ctBuf, ctAttack, ccAttack); CommandTypeFilter(ctBuf, ctAttack, ccAttack);
if(ctAttack.size() > 0) { if(ctAttack.size() > 0) {
ctBasics[0] = ctAttack[0];// first attack to basics ctBasics[0] = ctAttack[0];// first attack to basics
basicNulls.erase(basicNulls.begin());
ctAttack.erase(ctAttack.begin());// another to cores ctAttack.erase(ctAttack.begin());// another to cores
ctCores.insert(ctCores.end(), ctAttack.begin(), ctAttack.end()); ctCores.insert(ctCores.end(), ctAttack.begin(), ctAttack.end());
} }
@ -1273,11 +1276,12 @@ void UnitType::sortCommandTypes(CommandTypes cts){
auto ccPos = CommandHelper::getBasicPos(cc); auto ccPos = CommandHelper::getBasicPos(cc);
ctBasics[ccPos] = ctBuf[i]; ctBasics[ccPos] = ctBuf[i];
ctBuf.erase(ctBuf.begin() + i); ctBuf.erase(ctBuf.begin() + i);
basicNulls.erase(std::remove(basicNulls.begin(), basicNulls.end(), ccPos), basicNulls.end());
} }
} }
} }
// //Cores //Cores
CommandTypeFilter(ctBuf, ctCores, ccProduce); CommandTypeFilter(ctBuf, ctCores, ccProduce);
CommandTypeFilter(ctBuf, ctCores, ccUpgrade); CommandTypeFilter(ctBuf, ctCores, ccUpgrade);
CommandTypeFilter(ctBuf, ctCores, ccSwitchTeam); CommandTypeFilter(ctBuf, ctCores, ccSwitchTeam);
@ -1286,19 +1290,28 @@ void UnitType::sortCommandTypes(CommandTypes cts){
//Build //Build
CommandTypeFilter(ctBuf, ctBuild, ccBuild);// Build position always 4 in cores CommandTypeFilter(ctBuf, ctBuild, ccBuild);// Build position always 4 in cores
if(ctCores.size() == 4) {/*do nothing*/ } int nullCount = 4 - ctCores.size() - ctBuild.size();
else if(ctCores.size() < 4) { for(int i=0; i<nullCount; i++){
int nullCount = 4 - ctCores.size(); ctCores.push_back(NULL);
for(int i=0; i<nullCount; i++){ }
ctCores.push_back(NULL); if(ctBuild.size() > 0) {
} if(nullCount < 0) {//magic
if(ctBuild.size() > 0){ int buildToBasics = -nullCount;// if we cant push all builds to cores
ctCores[3] = ctBuild[0]; int until = (int)ctBuild.size() - buildToBasics;
for(int i = (int)ctBuild.size(); i --> until; ) {// we push it to basics
ctBasics[basicNulls[i - until]] = ctBuild[i];
ctBuild.erase(ctBuild.begin() + i);
basicNulls.erase(basicNulls.begin() + i - until);
}
} }
ctCores.insert(ctCores.end(), ctBuild.begin(), ctBuild.end());
} }
commandTypesSorted.insert(commandTypesSorted.end(), ctCores.begin(), ctCores.end()); commandTypesSorted.insert(commandTypesSorted.end(), ctCores.begin(), ctCores.end());
commandTypesSorted.insert(commandTypesSorted.end(), ctBasics.begin(), ctBasics.end()); commandTypesSorted.insert(commandTypesSorted.end(), ctBasics.begin(), ctBasics.end());
commandTypesSorted.insert(commandTypesSorted.end(), ctMorphs.begin(), ctMorphs.end()); commandTypesSorted.insert(commandTypesSorted.end(), ctMorphs.begin(), ctMorphs.end());
} catch(exception &ex){
}
} }
void UnitType::CommandTypeFilter(CommandTypes &input, CommandTypes &output, CommandClass cc){ void UnitType::CommandTypeFilter(CommandTypes &input, CommandTypes &output, CommandClass cc){