QTfrontend/campaign.cpp
changeset 11956 b05db9ca6e1c
parent 11953 6da9bb4b3449
child 11959 62be63822a96
--- a/QTfrontend/campaign.cpp	Wed May 04 00:14:41 2016 +0200
+++ b/QTfrontend/campaign.cpp	Wed May 04 02:10:59 2016 +0200
@@ -46,6 +46,32 @@
     return teamfile;
 }
 
+/**
+    Returns true if the specified mission has been completed
+    campaignName: Name of the campaign in question
+    missionInList: QComboBox index of the mission as selected in the mission widget
+    teamName: Name of the playing team
+*/
+bool isMissionWon(QString & campaignName, int missionInList, QString & teamName)
+{
+    QSettings* teamfile = getCampTeamFile(campaignName, teamName);
+    int progress = teamfile->value("Campaign " + campaignName + "/Progress", 0).toInt();
+    int unlockedMissions = teamfile->value("Campaign " + campaignName + "/UnlockedMissions", 0).toInt();
+    if(progress>0 and unlockedMissions==0)
+    {
+        return progress > (progress - missionInList);
+    }
+    else if(unlockedMissions>0)
+    {
+        int fileMissionId = missionInList + 1;
+        int actualMissionId = teamfile->value(QString("Campaign %1/Mission%2").arg(campaignName, QString::number(fileMissionId)), false).toInt();
+        return teamfile->value(QString("Campaign %1/Mission%2Won").arg(campaignName, QString::number(actualMissionId)), false).toBool();
+    }
+    else
+        return false;
+}
+
+/** Returns true if the campaign has been won by the team */
 bool isCampWon(QString & campaignName, QString & teamName)
 {
     QSettings* teamfile = getCampTeamFile(campaignName, teamName);