Fix final mission of Progress-based campaigns (like ACF) not being recognized as finished
authorWuzzy <almikes@aol.com>
Wed, 04 May 2016 04:32:31 +0200
changeset 11959 62be63822a96
parent 11958 c8457c7f10f4
child 11960 d72a177dbaea
Fix final mission of Progress-based campaigns (like ACF) not being recognized as finished
QTfrontend/campaign.cpp
share/hedgewars/Data/Missions/Campaign/A_Classic_Fairytale/enemy.lua
share/hedgewars/Data/Missions/Campaign/A_Classic_Fairytale/epil.lua
--- a/QTfrontend/campaign.cpp	Wed May 04 04:07:12 2016 +0200
+++ b/QTfrontend/campaign.cpp	Wed May 04 04:32:31 2016 +0200
@@ -55,11 +55,12 @@
 bool isMissionWon(QString & campaignName, int missionInList, QString & teamName)
 {
     QSettings* teamfile = getCampTeamFile(campaignName, teamName);
+    int won = teamfile->value("Campaign " + campaignName + "/Won", false).toBool();
     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);
+        return (progress > (progress - missionInList)) || won;
     }
     else if(unlockedMissions>0)
     {
@@ -114,16 +115,18 @@
         for(unsigned int i=progress+1;i>0;i--)
         {
             MissionInfo missionInfo;
-            missionInfo.name = campfile.value(QString("Mission %1/Name").arg(i)).toString();
             QString script = campfile.value(QString("Mission %1/Script").arg(i)).toString();
-            missionInfo.script = script;
-            missionInfo.description = m_info.value(campaignName+"-"+ script.replace(QString(".lua"),QString("")) + ".desc",
+            if(!script.isNull()) {
+                missionInfo.name = campfile.value(QString("Mission %1/Name").arg(i)).toString();
+                missionInfo.script = script;
+                missionInfo.description = m_info.value(campaignName+"-"+ script.replace(QString(".lua"),QString("")) + ".desc",
                                             QObject::tr("No description available")).toString();
-            QString image = campfile.value(QString("Mission %1/Script").arg(i)).toString().replace(QString(".lua"),QString(".png"));
-            missionInfo.image = ":/res/campaign/"+campaignName+"/"+image;
-            if (!QFile::exists(missionInfo.image))
-                missionInfo.image = ":/res/CampaignDefault.png";
-            missionInfoList.append(missionInfo);
+                QString image = campfile.value(QString("Mission %1/Script").arg(i)).toString().replace(QString(".lua"),QString(".png"));
+                missionInfo.image = ":/res/campaign/"+campaignName+"/"+image;
+                if (!QFile::exists(missionInfo.image))
+                    missionInfo.image = ":/res/CampaignDefault.png";
+                missionInfoList.append(missionInfo);
+            }
         }
     }
     else if(unlockedMissions>0)
--- a/share/hedgewars/Data/Missions/Campaign/A_Classic_Fairytale/enemy.lua	Wed May 04 04:07:12 2016 +0200
+++ b/share/hedgewars/Data/Missions/Campaign/A_Classic_Fairytale/enemy.lua	Wed May 04 04:32:31 2016 +0200
@@ -403,7 +403,6 @@
   if progress and progress<9 then
     SaveCampaignVar("Progress", "9")
   end
-  SaveCampaignVar("Won", "true")
   DismissTeam(loc("011101001"))
   TurnTimeLeft = 0
 end
--- a/share/hedgewars/Data/Missions/Campaign/A_Classic_Fairytale/epil.lua	Wed May 04 04:07:12 2016 +0200
+++ b/share/hedgewars/Data/Missions/Campaign/A_Classic_Fairytale/epil.lua	Wed May 04 04:32:31 2016 +0200
@@ -83,6 +83,7 @@
   AddNewEvent(CheckCrateTaken, {}, DoCrateTaken, {}, 1)
   TurnTimeLeft = 0
   ShowMission("Epilogue", "That's all folks!", "You have successfully finished the campaign!|If you wish to replay, there are other possible endings, too!|You can practice moving around and using utilities in this mission.|However, it will never end!", 1, 0)
+  SaveCampaignVar("Won", "true")
 end
 
 ---------------------------Events-------------------------------------