QTfrontend/campaign.cpp
changeset 14633 c9d2a5a9f6ba
parent 14462 4c743ef80b1b
child 15506 f315bb93db1f
equal deleted inserted replaced
14632:5132548cdb77 14633:c9d2a5a9f6ba
    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     if(progress>0 && unlockedMissions==0)
    60     // The CowardMode cheat unlocks all campaign missions,
       
    61     // but as "punishment", none of them will be marked as completed.
       
    62     // Added to make it easier to test campaigns.
       
    63     bool cheat = teamfile->value("Team/CowardMode", false).toBool();
       
    64     if(cheat)
       
    65     {
       
    66         return false;
       
    67     }
       
    68     else if(progress>0 && unlockedMissions==0)
    61     {
    69     {
    62         QSettings campfile("physfs://Missions/Campaign/" + campaignName + "/campaign.ini", QSettings::IniFormat, 0);
    70         QSettings campfile("physfs://Missions/Campaign/" + campaignName + "/campaign.ini", QSettings::IniFormat, 0);
    63         campfile.setIniCodec("UTF-8");
    71         campfile.setIniCodec("UTF-8");
    64         int totalMissions = campfile.value("MissionNum", 1).toInt();
    72         int totalMissions = campfile.value("MissionNum", 1).toInt();
    65         return (progress > (progress - missionInList)) || (progress >= totalMissions);
    73         return (progress > (progress - missionInList)) || (progress >= totalMissions);
    77 /** Returns true if the campaign has been won by the team */
    85 /** Returns true if the campaign has been won by the team */
    78 bool isCampWon(QString & campaignName, QString & teamName)
    86 bool isCampWon(QString & campaignName, QString & teamName)
    79 {
    87 {
    80     QSettings* teamfile = getCampTeamFile(campaignName, teamName);
    88     QSettings* teamfile = getCampTeamFile(campaignName, teamName);
    81     bool won = teamfile->value("Campaign " + campaignName + "/Won", false).toBool();
    89     bool won = teamfile->value("Campaign " + campaignName + "/Won", false).toBool();
    82     return won;
    90     bool cheat = teamfile->value("Team/CowardMode", false).toBool();
       
    91     return won && !cheat;
    83 }
    92 }
    84 
    93 
    85 QSettings* getCampMetaInfo()
    94 QSettings* getCampMetaInfo()
    86 {
    95 {
    87     DataManager & dataMgr = DataManager::instance();
    96     DataManager & dataMgr = DataManager::instance();
   116     QList<MissionInfo> missionInfoList;
   125     QList<MissionInfo> missionInfoList;
   117     QSettings* teamfile = getCampTeamFile(campaignName, teamName);
   126     QSettings* teamfile = getCampTeamFile(campaignName, teamName);
   118 
   127 
   119     int progress = teamfile->value("Campaign " + campaignName + "/Progress", 0).toInt();
   128     int progress = teamfile->value("Campaign " + campaignName + "/Progress", 0).toInt();
   120     int unlockedMissions = teamfile->value("Campaign " + campaignName + "/UnlockedMissions", 0).toInt();
   129     int unlockedMissions = teamfile->value("Campaign " + campaignName + "/UnlockedMissions", 0).toInt();
       
   130     bool cheat = teamfile->value("Team/CowardMode", false).toBool();
   121 
   131 
   122     QSettings campfile("physfs://Missions/Campaign/" + campaignName + "/campaign.ini", QSettings::IniFormat, 0);
   132     QSettings campfile("physfs://Missions/Campaign/" + campaignName + "/campaign.ini", QSettings::IniFormat, 0);
   123     campfile.setIniCodec("UTF-8");
   133     campfile.setIniCodec("UTF-8");
   124 
   134 
   125     QSettings* m_info = getCampMetaInfo();
   135     QSettings* m_info = getCampMetaInfo();
   126 
   136 
   127     if(progress >= 0 && unlockedMissions == 0)
   137     if(cheat)
       
   138     {
       
   139         progress = campfile.value("MissionNum", 1).toInt();
       
   140     }
       
   141     if((progress >= 0 && unlockedMissions == 0) || cheat)
   128     {
   142     {
   129         for(unsigned int i = progress + 1; i > 0; i--)
   143         for(unsigned int i = progress + 1; i > 0; i--)
   130         {
   144         {
   131             MissionInfo missionInfo;
   145             MissionInfo missionInfo;
   132             QString script = campfile.value(QString("Mission %1/Script").arg(i)).toString();
   146             QString script = campfile.value(QString("Mission %1/Script").arg(i)).toString();