QTfrontend/campaign.cpp
changeset 15506 f315bb93db1f
parent 14633 c9d2a5a9f6ba
equal deleted inserted replaced
15505:d94c42c174a1 15506:f315bb93db1f
    55 bool isCampMissionWon(QString & campaignName, int missionInList, QString & teamName)
    55 bool isCampMissionWon(QString & campaignName, int missionInList, QString & teamName)
    56 {
    56 {
    57     QSettings* teamfile = getCampTeamFile(campaignName, teamName);
    57     QSettings* teamfile = getCampTeamFile(campaignName, teamName);
    58     int progress = teamfile->value("Campaign " + campaignName + "/Progress", 0).toInt();
    58     int progress = teamfile->value("Campaign " + campaignName + "/Progress", 0).toInt();
    59     int unlockedMissions = teamfile->value("Campaign " + campaignName + "/UnlockedMissions", 0).toInt();
    59     int unlockedMissions = teamfile->value("Campaign " + campaignName + "/UnlockedMissions", 0).toInt();
    60     // The CowardMode cheat unlocks all campaign missions,
    60     QSettings campfile("physfs://Missions/Campaign/" + campaignName + "/campaign.ini", QSettings::IniFormat, 0);
    61     // but as "punishment", none of them will be marked as completed.
    61     campfile.setIniCodec("UTF-8");
       
    62     int totalMissions = campfile.value("MissionNum", 1).toInt();
       
    63     // The CowardMode cheat unlocks all campaign missions.
    62     // Added to make it easier to test campaigns.
    64     // Added to make it easier to test campaigns.
    63     bool cheat = teamfile->value("Team/CowardMode", false).toBool();
    65     bool cheat = teamfile->value("Team/CowardMode", false).toBool();
    64     if(cheat)
    66     if(progress>0 && unlockedMissions==0)
    65     {
    67     {
    66         return false;
    68         int maxMission;
    67     }
    69         if(cheat)
    68     else if(progress>0 && unlockedMissions==0)
    70             maxMission = totalMissions - (missionInList + 1);
    69     {
    71         else
    70         QSettings campfile("physfs://Missions/Campaign/" + campaignName + "/campaign.ini", QSettings::IniFormat, 0);
    72             maxMission = progress - missionInList;
    71         campfile.setIniCodec("UTF-8");
    73         return (progress > maxMission) || (progress >= totalMissions);
    72         int totalMissions = campfile.value("MissionNum", 1).toInt();
       
    73         return (progress > (progress - missionInList)) || (progress >= totalMissions);
       
    74     }
    74     }
    75     else if(unlockedMissions>0)
    75     else if(unlockedMissions>0)
    76     {
    76     {
    77         int fileMissionId = missionInList + 1;
    77         int fileMissionId = missionInList + 1;
    78         int actualMissionId = teamfile->value(QString("Campaign %1/Mission%2").arg(campaignName, QString::number(fileMissionId)), false).toInt();
    78         int actualMissionId;
       
    79         if(cheat)
       
    80             actualMissionId = totalMissions - missionInList;
       
    81         else
       
    82             actualMissionId = teamfile->value(QString("Campaign %1/Mission%2").arg(campaignName, QString::number(fileMissionId)), false).toInt();
    79         return teamfile->value(QString("Campaign %1/Mission%2Won").arg(campaignName, QString::number(actualMissionId)), false).toBool();
    83         return teamfile->value(QString("Campaign %1/Mission%2Won").arg(campaignName, QString::number(actualMissionId)), false).toBool();
    80     }
    84     }
    81     else
    85     else
    82         return false;
    86         return false;
    83 }
    87 }
    85 /** Returns true if the campaign has been won by the team */
    89 /** Returns true if the campaign has been won by the team */
    86 bool isCampWon(QString & campaignName, QString & teamName)
    90 bool isCampWon(QString & campaignName, QString & teamName)
    87 {
    91 {
    88     QSettings* teamfile = getCampTeamFile(campaignName, teamName);
    92     QSettings* teamfile = getCampTeamFile(campaignName, teamName);
    89     bool won = teamfile->value("Campaign " + campaignName + "/Won", false).toBool();
    93     bool won = teamfile->value("Campaign " + campaignName + "/Won", false).toBool();
    90     bool cheat = teamfile->value("Team/CowardMode", false).toBool();
    94     return won;
    91     return won && !cheat;
       
    92 }
    95 }
    93 
    96 
    94 QSettings* getCampMetaInfo()
    97 QSettings* getCampMetaInfo()
    95 {
    98 {
    96     DataManager & dataMgr = DataManager::instance();
    99     DataManager & dataMgr = DataManager::instance();