// TMainScreen.Client() branches that show what happens on the map // (Term.pas): cShowUnitChanged/CityChanged/AfterMove/AfterAttack, // cShowMoving/cShowCapturing, cShowAttacking and cRefreshDebugMap. #include "Term.MainScreen.h" #include "Cevo/CevoScreenTools.h" #include "Cevo/CevoTexture.h" #include "Global.h" #include "Messg.h" #include "Sound.h" #include namespace Cevo { namespace Term { namespace { constexpr int MoveTime = 300; constexpr int WaitAfterShowMove = 32; bool option(ClientTools::SaveOption so) { return ClientTools::hasSaveOption(optionChecked, so); } } // namespace void MainScreen::clientShow(int command, int newPlayer, void *data) { using ClientTools::me; using ClientTools::myCity; using ClientTools::myMap; using ClientTools::myModel; using ClientTools::myRO; const int lx = ClientTools::g.lx; const bool movieFast = gameMode == cMovie && m_movieSpeed == 4; const auto intData = [data] { return *static_cast(data); }; CurrentMoveInfo &info = m_currentMoveInfo; if (command == cRefreshDebugMap) { if (intData() == m_mainMap->pDebugMap) { m_mapValid = false; mainOffscreenPaint(); updateNow(); } return; } if (command == cShowUnitChanged || command == cShowCityChanged || command == cShowAfterMove || command == cShowAfterAttack) { if (!((m_idle && newPlayer == me) || (!m_idle && !m_skipped)) || movieFast) return; Q_ASSERT(newPlayer == me); if (!m_idle || gameMode == cMovie) QCoreApplication::processEvents(); if (command == cShowCityChanged) { if (m_idle) info.doShow = true; else if (info.isAlly) info.doShow = !option(ClientTools::soAlNoMoves); else info.doShow = !option(ClientTools::soEnNoMoves); } else if (command == cShowUnitChanged) { if (m_idle) info.doShow = !option(ClientTools::soEffectiveMovesOnly); else if (info.isAlly) info.doShow = !(option(ClientTools::soAlNoMoves) || option(ClientTools::soAlEffectiveMovesOnly)); else info.doShow = !(option(ClientTools::soEnNoMoves) || option(ClientTools::soEnAttacks)); } // else keep doShow from cShowMove/cShowAttack if (info.doShow) { if (command == cShowCityChanged) m_mapValid = false; focusOnLoc(intData(), flImmUpdate); if (command == cShowAfterMove) paintLoc(intData(), info.afterMovePaintRadius); // show discovered areas else paintLoc(intData(), 1); if (command == cShowAfterAttack && info.afterAttackExpeller >= 0) { MessgEx::soundMessageEx(Tribes::tribe[static_cast(info.afterAttackExpeller)]->tPhrase( QStringLiteral("EXPEL")), QString()); info.afterAttackExpeller = -1; updateNow(); // remove message box from screen } else if (!m_idle) { if (command == cShowCityChanged) QThread::msleep(static_cast(MoveTime * WaitAfterShowMove / 16)); else if (command == cShowUnitChanged && (myMap[intData()] & fUnit) != 0) QThread::msleep(static_cast(MoveTime * WaitAfterShowMove / 32)); } } else { m_mapValid = false; } return; } auto &showMove = *static_cast(data); if (command == cShowMoving || command == cShowCapturing) { if (!((m_idle && newPlayer == me) || (!m_idle && !m_skipped && showMove.emix != 0xFFFF)) || movieFast) return; Q_ASSERT(newPlayer == me); if (!m_idle || gameMode == cMovie) QCoreApplication::processEvents(); info.doShow = false; if (!m_idle && !Tribes::tribe[static_cast(showMove.Owner)]->modelPictureAt(showMove.mix).hGr) initEnemyModel(showMove.emix); const int toLoc = ClientTools::dLoc(showMove.FromLoc, showMove.dx, showMove.dy); int animationSpeed = 16; int showMoveDomain = dGround; bool isAlpine = false; const auto movieSpeedAnimation = [this]() { if (m_movieSpeed == 3) return 4; if (m_movieSpeed == 2) return 8; return 16; }; if (m_idle) { // own unit -- make discovered land visible Q_ASSERT(showMove.Owner == me); // no foreign moves during my turn! info.doShow = !option(ClientTools::soEffectiveMovesOnly) || command == cShowCapturing; if (info.doShow) { if (gameMode == cMovie) animationSpeed = movieSpeedAnimation(); else if (option(ClientTools::soVeryFastMoves)) animationSpeed = 4; else if (option(ClientTools::soFastMoves)) animationSpeed = 8; else animationSpeed = 16; const TModel &model = myModel[showMove.mix]; if (model.Kind == mkDiplomat || model.Domain == dAir || model.Cap[mcRadar] + model.Cap[mcCarrier] + model.Cap[mcAcademy] > 0 || (myMap[toLoc] & fTerrain) == static_cast(fMountains) || (myMap[toLoc] & fTerImp) == static_cast(tiFort) || (myMap[toLoc] & fTerImp) == static_cast(tiBase)) info.afterMovePaintRadius = 2; else info.afterMovePaintRadius = 1; if (myRO->Wonder[woShinkansen].EffectiveOwner == me && model.Domain == dGround && (myMap[showMove.FromLoc] & (fRR | fCity)) != 0 && (myMap[toLoc] & (fRR | fCity)) != 0 && (showMove.Flags & umPlaneUnloading) == 0) animationSpeed = 4; showMoveDomain = model.Domain; isAlpine = model.Cap[mcAlpine] > 0; } } else { info.isAlly = myRO->Treaty[showMove.Owner] == trAlliance; if (gameMode == cMovie) info.doShow = true; else if (info.isAlly) info.doShow = !option(ClientTools::soAlNoMoves) && !(option(ClientTools::soAlEffectiveMovesOnly) && command != cShowCapturing); else info.doShow = !option(ClientTools::soEnNoMoves) && !(option(ClientTools::soEnAttacks) && command != cShowCapturing); if (info.doShow) { const TModelInfo &emodel = (*myRO->EnemyModel)[showMove.emix]; if (command == cShowCapturing) { // show capture message QString cityName; if ((myMap[toLoc] & fOwned) != 0) { // own city, search int cix = myRO->nCity - 1; while (cix >= 0 && myCity[cix].Loc != toLoc) --cix; cityName = Tribes::cityName(myCity[cix].ID); } else { // foreign city, search int ecix = myRO->nEnemyCity - 1; while (ecix >= 0 && (*myRO->EnemyCity)[ecix].Loc != toLoc) --ecix; cityName = Tribes::cityName((*myRO->EnemyCity)[ecix].ID); } MessgEx::tribeMessage(showMove.Owner, Tribes::tribe[static_cast(showMove.Owner)]->tPhrase( QStringLiteral("CAPTURE")).arg(cityName), QString()); updateNow(); // remove message box from screen } if (info.isAlly) { // allied unit -- make discovered land visible animationSpeed = option(ClientTools::soAlFastMoves) ? 8 : 16; if (emodel.Kind == mkDiplomat || emodel.Domain == dAir || emodel.ATrans_Fuel > 0 || (emodel.Cap & ((1u << (mcRadar - mcFirstNonCap)) | (1u << (mcAcademy - mcFirstNonCap)))) != 0 || (myMap[toLoc] & fTerrain) == static_cast(fMountains) || (myMap[toLoc] & fTerImp) == static_cast(tiFort) || (myMap[toLoc] & fTerImp) == static_cast(tiBase)) info.afterMovePaintRadius = 2; else info.afterMovePaintRadius = 1; } else { animationSpeed = option(ClientTools::soEnFastMoves) ? 8 : 16; info.afterMovePaintRadius = 0; // enemy unit, nothing discovered } if (gameMode == cMovie) animationSpeed = movieSpeedAnimation(); showMoveDomain = emodel.Domain; isAlpine = (emodel.Cap & (1u << (mcAlpine - mcFirstNonCap))) != 0; } } if (info.doShow) { using Sound::play; const int flags = showMove.Flags; if (command == cShowCapturing) play(QStringLiteral("MOVE_CAPTURE")); else if (showMove.EndHealth <= 0) play(QStringLiteral("MOVE_DIE")); else if (flags & umSpyMission) play(QStringLiteral("MOVE_COVERT")); else if (flags & umShipLoading) play(showMoveDomain == dAir ? QStringLiteral("MOVE_PLANELANDING") : QStringLiteral("MOVE_LOAD")); else if (flags & umPlaneLoading) play(QStringLiteral("MOVE_LOAD")); else if (flags & umShipUnloading) play(showMoveDomain == dAir ? QStringLiteral("MOVE_PLANESTART") : QStringLiteral("MOVE_UNLOAD")); else if (flags & umPlaneUnloading) play((myMap[showMove.FromLoc] & fCity) == 0 && (myMap[showMove.FromLoc] & fTerImp) != static_cast(tiBase) ? QStringLiteral("MOVE_PARACHUTE") : QStringLiteral("MOVE_UNLOAD")); else if (showMoveDomain == dGround && !isAlpine && (myMap[toLoc] & fTerrain) == static_cast(fMountains) && ((myMap[showMove.FromLoc] & (fRoad | fRR | fCity)) == 0 || (myMap[toLoc] & (fRoad | fRR | fCity)) == 0)) play(QStringLiteral("MOVE_MOUNTAIN")); focusOnLoc(showMove.FromLoc, flImmUpdate); paintLocBeforeMove(showMove.FromLoc); if (command == cShowCapturing) moveOnScreen(showMove, 1, 32, 32); else moveOnScreen(showMove, 1, animationSpeed, animationSpeed); } else { m_mapValid = false; } Q_UNUSED(lx); return; } if (command == cShowAttacking) { if (!((m_idle && newPlayer == me) || (!m_idle && !m_skipped && showMove.emix != 0xFFFF)) || movieFast) return; Q_ASSERT(newPlayer == me); if (!m_idle || gameMode == cMovie) QCoreApplication::processEvents(); info.afterAttackExpeller = -1; info.doShow = false; if (m_idle) { info.doShow = true; // own unit -- always show attacks } else { info.isAlly = myRO->Treaty[showMove.Owner] == trAlliance; info.doShow = info.isAlly ? !option(ClientTools::soAlNoMoves) : !option(ClientTools::soEnNoMoves); } if (!info.doShow) { m_mapValid = false; return; } const int toLoc = ClientTools::dLoc(showMove.FromLoc, showMove.dx, showMove.dy); if (!Tribes::tribe[static_cast(showMove.Owner)]->modelPictureAt(showMove.mix).hGr) initEnemyModel(showMove.emix); if ((myMap[toLoc] & (fCity | fUnit | fOwned)) == static_cast(fCity | fOwned)) { // tell about bombardment int cix = myRO->nCity - 1; while (cix >= 0 && myCity[cix].Loc != toLoc) --cix; if ((myCity[cix].Status & csToldBombard) == 0) { if (!supervising) myCity[cix].Status |= csToldBombard; MessgEx::soundMessageEx(Tribes::tribe[static_cast(showMove.Owner)]->tPhrase( QStringLiteral("BOMBARD")).arg(Tribes::cityName(myCity[cix].ID)), QString()); updateNow(); // remove message box from screen } } else if (showMove.Flags & umExpelling) { info.afterAttackExpeller = showMove.Owner; } if (showMove.Flags & umExpelling) { Sound::play(QStringLiteral("MOVE_EXPEL")); } else if (showMove.Owner == me) { TModelInfo mi{}; MakeModelInfo(me, showMove.mix, myModel[showMove.mix], mi); Sound::play(attackSound(Tribes::modelCode(mi))); } else { Sound::play(attackSound(Tribes::modelCode((*myRO->EnemyModel)[showMove.emix]))); } focusOnLoc(showMove.FromLoc, flImmUpdate); // before combat m_mainMap->attackBegin(showMove); if ((myMap[toLoc] & fCity) != 0) paintLoc(toLoc); paintLoc(showMove.FromLoc); moveOnScreen(showMove, 1, 9, 16); moveOnScreen(showMove, 17, 12, 32); moveOnScreen(showMove, 7, 11, 16); // after combat m_mainMap->attackEffect(showMove); paintLoc(toLoc); if (showMove.EndHealth > 0) { showMove.Health = showMove.EndHealth; moveOnScreen(showMove, 10, 0, 16); } else if (!m_idle) { QThread::msleep(static_cast(MoveTime / 2)); } m_mainMap->attackEnd(); } } } // namespace Term } // namespace Cevo