diff --git a/cockatrice/src/game/phase.cpp b/cockatrice/src/game/phase.cpp index 32c9060ee..7fb1700a5 100644 --- a/cockatrice/src/game/phase.cpp +++ b/cockatrice/src/game/phase.cpp @@ -22,6 +22,28 @@ Phase Phases::getPhase(int phase) } } +int Phases::getLastSubphase(int phase) +{ + if (0 <= phase && phase < Phases::phaseTypesCount) { + return subPhasesEnd[phase]; + } else { + return phase; + } +} + +QVector getSubPhasesEnd() +{ + QVector array(Phases::phaseTypesCount); + for (int phaseEnd = Phases::phaseTypesCount - 1; phaseEnd >= 0;) { + int subPhase = phaseEnd; + for (; subPhase >= 0 && Phases::phases[phaseEnd].color == Phases::phases[subPhase].color; --subPhase) { + array[subPhase] = phaseEnd; + } + phaseEnd = subPhase; + } + return array; +} + const Phase Phases::unknownPhase(QT_TRANSLATE_NOOP("Phase", "Unknown Phase"), "black", "unknown_phase"); const Phase Phases::phases[Phases::phaseTypesCount] = { {QT_TRANSLATE_NOOP("Phase", "Untap"), "green", "untap_step"}, @@ -35,3 +57,4 @@ const Phase Phases::phases[Phases::phaseTypesCount] = { {QT_TRANSLATE_NOOP("Phase", "End of Combat"), "red", "end_combat"}, {QT_TRANSLATE_NOOP("Phase", "Second Main"), "blue", "main_2"}, {QT_TRANSLATE_NOOP("Phase", "End/Cleanup"), "green", "end_step"}}; +const QVector Phases::subPhasesEnd = getSubPhasesEnd(); diff --git a/cockatrice/src/game/phase.h b/cockatrice/src/game/phase.h index 6e451161e..2e712932f 100644 --- a/cockatrice/src/game/phase.h +++ b/cockatrice/src/game/phase.h @@ -28,8 +28,10 @@ struct Phases const static int phaseTypesCount = 11; const static Phase unknownPhase; const static Phase phases[phaseTypesCount]; + const static QVector subPhasesEnd; static Phase getPhase(int); + static int getLastSubphase(int phase); }; #endif // PHASE_H