QTfrontend/campaign.cpp
author alfadur
Thu, 09 Jul 2020 00:45:27 +0300
changeset 15712 b496233ac26d
parent 15506 f315bb93db1f
permissions -rw-r--r--
make sentries reload after being hit
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
     1
/*
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 10108
diff changeset
     3
 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
     4
 *
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
     8
 *
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    12
 * GNU General Public License for more details.
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    13
 *
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 10017
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    17
 */
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    18
9000
af202eff659c remove about 45 useless #include statements from campain.* - copypasta ftw, eh? :p
sheepluva
parents: 8434
diff changeset
    19
#include "campaign.h"
af202eff659c remove about 45 useless #include statements from campain.* - copypasta ftw, eh? :p
sheepluva
parents: 8434
diff changeset
    20
#include "hwconsts.h"
9278
33a30ce9782f this seems to works, still wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9275
diff changeset
    21
#include "DataManager.h"
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    22
#include <QSettings>
9278
33a30ce9782f this seems to works, still wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9275
diff changeset
    23
#include <QObject>
9292
187ce630dddc y! code clean up :)
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9290
diff changeset
    24
#include <QLocale>
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8049
diff changeset
    25
11948
6da9bb4b3449 Show check marks for campaigns with Won=true
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    26
QSettings* getCampTeamFile(QString & campaignName, QString & teamName)
9294
f9b31c3efd35 added deafult image if not one available in campaign
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9292
diff changeset
    27
{
11948
6da9bb4b3449 Show check marks for campaigns with Won=true
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    28
    QSettings* teamfile = new QSettings(cfgdir->absolutePath() + "/Teams/" + teamName + ".hwt", QSettings::IniFormat, 0);
6da9bb4b3449 Show check marks for campaigns with Won=true
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    29
    teamfile->setIniCodec("UTF-8");
9821
7501208fd025 check if save from old campaign name scheme exists and if so rename it to use _ instead of spaces -see issue 722
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9308
diff changeset
    30
    // if entry not found check if there is written without _
7501208fd025 check if save from old campaign name scheme exists and if so rename it to use _ instead of spaces -see issue 722
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9308
diff changeset
    31
    // if then is found rename it to use _
7501208fd025 check if save from old campaign name scheme exists and if so rename it to use _ instead of spaces -see issue 722
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9308
diff changeset
    32
    QString spaceCampName = campaignName;
7501208fd025 check if save from old campaign name scheme exists and if so rename it to use _ instead of spaces -see issue 722
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9308
diff changeset
    33
    spaceCampName = spaceCampName.replace(QString("_"),QString(" "));
13910
6c8d4e140f27 fix frontend compatibility issues
alfadur
parents: 13811
diff changeset
    34
    if (!teamfile->childGroups().contains("Campaign " + campaignName) &&
11948
6da9bb4b3449 Show check marks for campaigns with Won=true
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    35
            teamfile->childGroups().contains("Campaign " + spaceCampName)){
6da9bb4b3449 Show check marks for campaigns with Won=true
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    36
        teamfile->beginGroup("Campaign " + spaceCampName);
6da9bb4b3449 Show check marks for campaigns with Won=true
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    37
        QStringList keys = teamfile->childKeys();
6da9bb4b3449 Show check marks for campaigns with Won=true
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    38
        teamfile->endGroup();
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
    39
        for (int i=0;i<keys.size();i++) {
11948
6da9bb4b3449 Show check marks for campaigns with Won=true
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    40
            QVariant value = teamfile->value("Campaign " + spaceCampName + "/" + keys[i]);
6da9bb4b3449 Show check marks for campaigns with Won=true
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    41
            teamfile->setValue("Campaign " + campaignName + "/" + keys[i], value);
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
    42
        }
11948
6da9bb4b3449 Show check marks for campaigns with Won=true
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    43
        teamfile->remove("Campaign " + spaceCampName);
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
    44
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
    45
11948
6da9bb4b3449 Show check marks for campaigns with Won=true
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    46
    return teamfile;
6da9bb4b3449 Show check marks for campaigns with Won=true
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    47
}
6da9bb4b3449 Show check marks for campaigns with Won=true
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    48
11951
b05db9ca6e1c Add support for storing and displaying success of campaign missions
Wuzzy <almikes@aol.com>
parents: 11948
diff changeset
    49
/**
b05db9ca6e1c Add support for storing and displaying success of campaign missions
Wuzzy <almikes@aol.com>
parents: 11948
diff changeset
    50
    Returns true if the specified mission has been completed
b05db9ca6e1c Add support for storing and displaying success of campaign missions
Wuzzy <almikes@aol.com>
parents: 11948
diff changeset
    51
    campaignName: Name of the campaign in question
b05db9ca6e1c Add support for storing and displaying success of campaign missions
Wuzzy <almikes@aol.com>
parents: 11948
diff changeset
    52
    missionInList: QComboBox index of the mission as selected in the mission widget
b05db9ca6e1c Add support for storing and displaying success of campaign missions
Wuzzy <almikes@aol.com>
parents: 11948
diff changeset
    53
    teamName: Name of the playing team
b05db9ca6e1c Add support for storing and displaying success of campaign missions
Wuzzy <almikes@aol.com>
parents: 11948
diff changeset
    54
*/
14462
4c743ef80b1b Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents: 13910
diff changeset
    55
bool isCampMissionWon(QString & campaignName, int missionInList, QString & teamName)
11951
b05db9ca6e1c Add support for storing and displaying success of campaign missions
Wuzzy <almikes@aol.com>
parents: 11948
diff changeset
    56
{
b05db9ca6e1c Add support for storing and displaying success of campaign missions
Wuzzy <almikes@aol.com>
parents: 11948
diff changeset
    57
    QSettings* teamfile = getCampTeamFile(campaignName, teamName);
b05db9ca6e1c Add support for storing and displaying success of campaign missions
Wuzzy <almikes@aol.com>
parents: 11948
diff changeset
    58
    int progress = teamfile->value("Campaign " + campaignName + "/Progress", 0).toInt();
b05db9ca6e1c Add support for storing and displaying success of campaign missions
Wuzzy <almikes@aol.com>
parents: 11948
diff changeset
    59
    int unlockedMissions = teamfile->value("Campaign " + campaignName + "/UnlockedMissions", 0).toInt();
15506
f315bb93db1f CowardMode: Display checkmarks in missions list
Wuzzy <Wuzzy2@mail.ru>
parents: 14633
diff changeset
    60
    QSettings campfile("physfs://Missions/Campaign/" + campaignName + "/campaign.ini", QSettings::IniFormat, 0);
f315bb93db1f CowardMode: Display checkmarks in missions list
Wuzzy <Wuzzy2@mail.ru>
parents: 14633
diff changeset
    61
    campfile.setIniCodec("UTF-8");
f315bb93db1f CowardMode: Display checkmarks in missions list
Wuzzy <Wuzzy2@mail.ru>
parents: 14633
diff changeset
    62
    int totalMissions = campfile.value("MissionNum", 1).toInt();
f315bb93db1f CowardMode: Display checkmarks in missions list
Wuzzy <Wuzzy2@mail.ru>
parents: 14633
diff changeset
    63
    // The CowardMode cheat unlocks all campaign missions.
14633
c9d2a5a9f6ba Add CowardMode team setting
Wuzzy <Wuzzy2@mail.ru>
parents: 14462
diff changeset
    64
    // Added to make it easier to test campaigns.
c9d2a5a9f6ba Add CowardMode team setting
Wuzzy <Wuzzy2@mail.ru>
parents: 14462
diff changeset
    65
    bool cheat = teamfile->value("Team/CowardMode", false).toBool();
15506
f315bb93db1f CowardMode: Display checkmarks in missions list
Wuzzy <Wuzzy2@mail.ru>
parents: 14633
diff changeset
    66
    if(progress>0 && unlockedMissions==0)
14633
c9d2a5a9f6ba Add CowardMode team setting
Wuzzy <Wuzzy2@mail.ru>
parents: 14462
diff changeset
    67
    {
15506
f315bb93db1f CowardMode: Display checkmarks in missions list
Wuzzy <Wuzzy2@mail.ru>
parents: 14633
diff changeset
    68
        int maxMission;
f315bb93db1f CowardMode: Display checkmarks in missions list
Wuzzy <Wuzzy2@mail.ru>
parents: 14633
diff changeset
    69
        if(cheat)
f315bb93db1f CowardMode: Display checkmarks in missions list
Wuzzy <Wuzzy2@mail.ru>
parents: 14633
diff changeset
    70
            maxMission = totalMissions - (missionInList + 1);
f315bb93db1f CowardMode: Display checkmarks in missions list
Wuzzy <Wuzzy2@mail.ru>
parents: 14633
diff changeset
    71
        else
f315bb93db1f CowardMode: Display checkmarks in missions list
Wuzzy <Wuzzy2@mail.ru>
parents: 14633
diff changeset
    72
            maxMission = progress - missionInList;
f315bb93db1f CowardMode: Display checkmarks in missions list
Wuzzy <Wuzzy2@mail.ru>
parents: 14633
diff changeset
    73
        return (progress > maxMission) || (progress >= totalMissions);
11951
b05db9ca6e1c Add support for storing and displaying success of campaign missions
Wuzzy <almikes@aol.com>
parents: 11948
diff changeset
    74
    }
b05db9ca6e1c Add support for storing and displaying success of campaign missions
Wuzzy <almikes@aol.com>
parents: 11948
diff changeset
    75
    else if(unlockedMissions>0)
b05db9ca6e1c Add support for storing and displaying success of campaign missions
Wuzzy <almikes@aol.com>
parents: 11948
diff changeset
    76
    {
b05db9ca6e1c Add support for storing and displaying success of campaign missions
Wuzzy <almikes@aol.com>
parents: 11948
diff changeset
    77
        int fileMissionId = missionInList + 1;
15506
f315bb93db1f CowardMode: Display checkmarks in missions list
Wuzzy <Wuzzy2@mail.ru>
parents: 14633
diff changeset
    78
        int actualMissionId;
f315bb93db1f CowardMode: Display checkmarks in missions list
Wuzzy <Wuzzy2@mail.ru>
parents: 14633
diff changeset
    79
        if(cheat)
f315bb93db1f CowardMode: Display checkmarks in missions list
Wuzzy <Wuzzy2@mail.ru>
parents: 14633
diff changeset
    80
            actualMissionId = totalMissions - missionInList;
f315bb93db1f CowardMode: Display checkmarks in missions list
Wuzzy <Wuzzy2@mail.ru>
parents: 14633
diff changeset
    81
        else
f315bb93db1f CowardMode: Display checkmarks in missions list
Wuzzy <Wuzzy2@mail.ru>
parents: 14633
diff changeset
    82
            actualMissionId = teamfile->value(QString("Campaign %1/Mission%2").arg(campaignName, QString::number(fileMissionId)), false).toInt();
11951
b05db9ca6e1c Add support for storing and displaying success of campaign missions
Wuzzy <almikes@aol.com>
parents: 11948
diff changeset
    83
        return teamfile->value(QString("Campaign %1/Mission%2Won").arg(campaignName, QString::number(actualMissionId)), false).toBool();
b05db9ca6e1c Add support for storing and displaying success of campaign missions
Wuzzy <almikes@aol.com>
parents: 11948
diff changeset
    84
    }
b05db9ca6e1c Add support for storing and displaying success of campaign missions
Wuzzy <almikes@aol.com>
parents: 11948
diff changeset
    85
    else
b05db9ca6e1c Add support for storing and displaying success of campaign missions
Wuzzy <almikes@aol.com>
parents: 11948
diff changeset
    86
        return false;
b05db9ca6e1c Add support for storing and displaying success of campaign missions
Wuzzy <almikes@aol.com>
parents: 11948
diff changeset
    87
}
b05db9ca6e1c Add support for storing and displaying success of campaign missions
Wuzzy <almikes@aol.com>
parents: 11948
diff changeset
    88
b05db9ca6e1c Add support for storing and displaying success of campaign missions
Wuzzy <almikes@aol.com>
parents: 11948
diff changeset
    89
/** Returns true if the campaign has been won by the team */
11948
6da9bb4b3449 Show check marks for campaigns with Won=true
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    90
bool isCampWon(QString & campaignName, QString & teamName)
6da9bb4b3449 Show check marks for campaigns with Won=true
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    91
{
6da9bb4b3449 Show check marks for campaigns with Won=true
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    92
    QSettings* teamfile = getCampTeamFile(campaignName, teamName);
6da9bb4b3449 Show check marks for campaigns with Won=true
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    93
    bool won = teamfile->value("Campaign " + campaignName + "/Won", false).toBool();
15506
f315bb93db1f CowardMode: Display checkmarks in missions list
Wuzzy <Wuzzy2@mail.ru>
parents: 14633
diff changeset
    94
    return won;
11948
6da9bb4b3449 Show check marks for campaigns with Won=true
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    95
}
6da9bb4b3449 Show check marks for campaigns with Won=true
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    96
11957
1201fc039e24 Make campaign names translatable
Wuzzy <almikes@aol.com>
parents: 11956
diff changeset
    97
QSettings* getCampMetaInfo()
1201fc039e24 Make campaign names translatable
Wuzzy <almikes@aol.com>
parents: 11956
diff changeset
    98
{
1201fc039e24 Make campaign names translatable
Wuzzy <almikes@aol.com>
parents: 11956
diff changeset
    99
    DataManager & dataMgr = DataManager::instance();
1201fc039e24 Make campaign names translatable
Wuzzy <almikes@aol.com>
parents: 11956
diff changeset
   100
    // get locale
1201fc039e24 Make campaign names translatable
Wuzzy <almikes@aol.com>
parents: 11956
diff changeset
   101
    QSettings settings(dataMgr.settingsFileName(),
1201fc039e24 Make campaign names translatable
Wuzzy <almikes@aol.com>
parents: 11956
diff changeset
   102
    QSettings::IniFormat);
13274
e381f5260b45 Change how locale is loaded in frontend, and fix some bugs
Wuzzy <Wuzzy2@mail.ru>
parents: 12305
diff changeset
   103
    QString loc = QLocale().name();
11957
1201fc039e24 Make campaign names translatable
Wuzzy <almikes@aol.com>
parents: 11956
diff changeset
   104
    QString campaignDescFile = QString("physfs://Locale/campaigns_" + loc + ".txt");
1201fc039e24 Make campaign names translatable
Wuzzy <almikes@aol.com>
parents: 11956
diff changeset
   105
    // if file is non-existant try with language only
1201fc039e24 Make campaign names translatable
Wuzzy <almikes@aol.com>
parents: 11956
diff changeset
   106
    if (!QFile::exists(campaignDescFile))
1201fc039e24 Make campaign names translatable
Wuzzy <almikes@aol.com>
parents: 11956
diff changeset
   107
    campaignDescFile = QString("physfs://Locale/campaigns_" + loc.remove(QRegExp("_.*$")) + ".txt");
1201fc039e24 Make campaign names translatable
Wuzzy <almikes@aol.com>
parents: 11956
diff changeset
   108
1201fc039e24 Make campaign names translatable
Wuzzy <almikes@aol.com>
parents: 11956
diff changeset
   109
    // fallback if file for current locale is non-existant
1201fc039e24 Make campaign names translatable
Wuzzy <almikes@aol.com>
parents: 11956
diff changeset
   110
    if (!QFile::exists(campaignDescFile))
1201fc039e24 Make campaign names translatable
Wuzzy <almikes@aol.com>
parents: 11956
diff changeset
   111
        campaignDescFile = QString("physfs://Locale/campaigns_en.txt");
1201fc039e24 Make campaign names translatable
Wuzzy <almikes@aol.com>
parents: 11956
diff changeset
   112
1201fc039e24 Make campaign names translatable
Wuzzy <almikes@aol.com>
parents: 11956
diff changeset
   113
    QSettings* m_info = new QSettings(campaignDescFile, QSettings::IniFormat, 0);
1201fc039e24 Make campaign names translatable
Wuzzy <almikes@aol.com>
parents: 11956
diff changeset
   114
    m_info->setIniCodec("UTF-8");
1201fc039e24 Make campaign names translatable
Wuzzy <almikes@aol.com>
parents: 11956
diff changeset
   115
1201fc039e24 Make campaign names translatable
Wuzzy <almikes@aol.com>
parents: 11956
diff changeset
   116
    return m_info;
1201fc039e24 Make campaign names translatable
Wuzzy <almikes@aol.com>
parents: 11956
diff changeset
   117
}
1201fc039e24 Make campaign names translatable
Wuzzy <almikes@aol.com>
parents: 11956
diff changeset
   118
1201fc039e24 Make campaign names translatable
Wuzzy <almikes@aol.com>
parents: 11956
diff changeset
   119
/** Returns the localized campaign name */
12305
d3a52e51efd4 fix campaign missions not showing up for me
sheepluva
parents: 11958
diff changeset
   120
QString getRealCampName(const QString & campaignName)
11957
1201fc039e24 Make campaign names translatable
Wuzzy <almikes@aol.com>
parents: 11956
diff changeset
   121
{
12305
d3a52e51efd4 fix campaign missions not showing up for me
sheepluva
parents: 11958
diff changeset
   122
    QString campaignNameSpaces = QString(campaignName).replace(QString("_"), QString(" "));
d3a52e51efd4 fix campaign missions not showing up for me
sheepluva
parents: 11958
diff changeset
   123
    return getCampMetaInfo()->value(campaignName+".name", campaignNameSpaces).toString();
11957
1201fc039e24 Make campaign names translatable
Wuzzy <almikes@aol.com>
parents: 11956
diff changeset
   124
}
1201fc039e24 Make campaign names translatable
Wuzzy <almikes@aol.com>
parents: 11956
diff changeset
   125
11948
6da9bb4b3449 Show check marks for campaigns with Won=true
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   126
QList<MissionInfo> getCampMissionList(QString & campaignName, QString & teamName)
6da9bb4b3449 Show check marks for campaigns with Won=true
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   127
{
6da9bb4b3449 Show check marks for campaigns with Won=true
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   128
    QList<MissionInfo> missionInfoList;
6da9bb4b3449 Show check marks for campaigns with Won=true
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   129
    QSettings* teamfile = getCampTeamFile(campaignName, teamName);
6da9bb4b3449 Show check marks for campaigns with Won=true
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   130
6da9bb4b3449 Show check marks for campaigns with Won=true
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   131
    int progress = teamfile->value("Campaign " + campaignName + "/Progress", 0).toInt();
6da9bb4b3449 Show check marks for campaigns with Won=true
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   132
    int unlockedMissions = teamfile->value("Campaign " + campaignName + "/UnlockedMissions", 0).toInt();
14633
c9d2a5a9f6ba Add CowardMode team setting
Wuzzy <Wuzzy2@mail.ru>
parents: 14462
diff changeset
   133
    bool cheat = teamfile->value("Team/CowardMode", false).toBool();
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
   134
9290
478aa681e702 this seems to work ok, but I have to clean up the code
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9286
diff changeset
   135
    QSettings campfile("physfs://Missions/Campaign/" + campaignName + "/campaign.ini", QSettings::IniFormat, 0);
478aa681e702 this seems to work ok, but I have to clean up the code
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9286
diff changeset
   136
    campfile.setIniCodec("UTF-8");
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
   137
11957
1201fc039e24 Make campaign names translatable
Wuzzy <almikes@aol.com>
parents: 11956
diff changeset
   138
    QSettings* m_info = getCampMetaInfo();
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
   139
14633
c9d2a5a9f6ba Add CowardMode team setting
Wuzzy <Wuzzy2@mail.ru>
parents: 14462
diff changeset
   140
    if(cheat)
c9d2a5a9f6ba Add CowardMode team setting
Wuzzy <Wuzzy2@mail.ru>
parents: 14462
diff changeset
   141
    {
c9d2a5a9f6ba Add CowardMode team setting
Wuzzy <Wuzzy2@mail.ru>
parents: 14462
diff changeset
   142
        progress = campfile.value("MissionNum", 1).toInt();
c9d2a5a9f6ba Add CowardMode team setting
Wuzzy <Wuzzy2@mail.ru>
parents: 14462
diff changeset
   143
    }
c9d2a5a9f6ba Add CowardMode team setting
Wuzzy <Wuzzy2@mail.ru>
parents: 14462
diff changeset
   144
    if((progress >= 0 && unlockedMissions == 0) || cheat)
9290
478aa681e702 this seems to work ok, but I have to clean up the code
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9286
diff changeset
   145
    {
13910
6c8d4e140f27 fix frontend compatibility issues
alfadur
parents: 13811
diff changeset
   146
        for(unsigned int i = progress + 1; i > 0; i--)
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
   147
        {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
   148
            MissionInfo missionInfo;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
   149
            QString script = campfile.value(QString("Mission %1/Script").arg(i)).toString();
11954
62be63822a96 Fix final mission of Progress-based campaigns (like ACF) not being recognized as finished
Wuzzy <almikes@aol.com>
parents: 11951
diff changeset
   150
            if(!script.isNull()) {
11958
de66192866d3 Make campaign mission names translatable
Wuzzy <almikes@aol.com>
parents: 11957
diff changeset
   151
                missionInfo.script = script;
11954
62be63822a96 Fix final mission of Progress-based campaigns (like ACF) not being recognized as finished
Wuzzy <almikes@aol.com>
parents: 11951
diff changeset
   152
                missionInfo.name = campfile.value(QString("Mission %1/Name").arg(i)).toString();
11958
de66192866d3 Make campaign mission names translatable
Wuzzy <almikes@aol.com>
parents: 11957
diff changeset
   153
                QString scriptPrefix = campaignName+"-"+ script.replace(QString(".lua"),QString(""));
de66192866d3 Make campaign mission names translatable
Wuzzy <almikes@aol.com>
parents: 11957
diff changeset
   154
                missionInfo.realName = m_info->value(scriptPrefix+".name", missionInfo.name).toString();
de66192866d3 Make campaign mission names translatable
Wuzzy <almikes@aol.com>
parents: 11957
diff changeset
   155
                missionInfo.description = m_info->value(scriptPrefix + ".desc",
9290
478aa681e702 this seems to work ok, but I have to clean up the code
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9286
diff changeset
   156
                                            QObject::tr("No description available")).toString();
13811
e3fee73c51a0 Move campaign mission images to share/ instead of hardcoding them into frontend
Wuzzy <Wuzzy2@mail.ru>
parents: 13274
diff changeset
   157
                QString image = campfile.value(QString("Mission %1/Script").arg(i)).toString().replace(QString(".lua"),QString("@2x.png"));
e3fee73c51a0 Move campaign mission images to share/ instead of hardcoding them into frontend
Wuzzy <Wuzzy2@mail.ru>
parents: 13274
diff changeset
   158
                missionInfo.image = "physfs://Graphics/Missions/Campaign/"+campaignName+"/"+image;
11954
62be63822a96 Fix final mission of Progress-based campaigns (like ACF) not being recognized as finished
Wuzzy <almikes@aol.com>
parents: 11951
diff changeset
   159
                if (!QFile::exists(missionInfo.image))
62be63822a96 Fix final mission of Progress-based campaigns (like ACF) not being recognized as finished
Wuzzy <almikes@aol.com>
parents: 11951
diff changeset
   160
                    missionInfo.image = ":/res/CampaignDefault.png";
62be63822a96 Fix final mission of Progress-based campaigns (like ACF) not being recognized as finished
Wuzzy <almikes@aol.com>
parents: 11951
diff changeset
   161
                missionInfoList.append(missionInfo);
62be63822a96 Fix final mission of Progress-based campaigns (like ACF) not being recognized as finished
Wuzzy <almikes@aol.com>
parents: 11951
diff changeset
   162
            }
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
   163
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
   164
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
   165
    else if(unlockedMissions>0)
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
   166
    {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
   167
        for(int i=1;i<=unlockedMissions;i++)
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
   168
        {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
   169
            QString missionNum = QString("%1").arg(i);
11948
6da9bb4b3449 Show check marks for campaigns with Won=true
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   170
            int missionNumber = teamfile->value("Campaign " + campaignName + "/Mission"+missionNum, -1).toInt();
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
   171
            MissionInfo missionInfo;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
   172
            QString script = campfile.value(QString("Mission %1/Script").arg(missionNumber)).toString();
9308
4bddcc1a1450 merge and changed also spacecampaign name
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9294
diff changeset
   173
            missionInfo.script = script;
11958
de66192866d3 Make campaign mission names translatable
Wuzzy <almikes@aol.com>
parents: 11957
diff changeset
   174
            missionInfo.name = campfile.value(QString("Mission %1/Name").arg(missionNumber)).toString();
de66192866d3 Make campaign mission names translatable
Wuzzy <almikes@aol.com>
parents: 11957
diff changeset
   175
            QString scriptPrefix = campaignName+"-"+ script.replace(QString(".lua"),QString(""));
de66192866d3 Make campaign mission names translatable
Wuzzy <almikes@aol.com>
parents: 11957
diff changeset
   176
            missionInfo.realName = m_info->value(scriptPrefix+".name", missionInfo.name).toString();
de66192866d3 Make campaign mission names translatable
Wuzzy <almikes@aol.com>
parents: 11957
diff changeset
   177
            missionInfo.description = m_info->value(scriptPrefix + ".desc",
9290
478aa681e702 this seems to work ok, but I have to clean up the code
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9286
diff changeset
   178
                                            QObject::tr("No description available")).toString();
13811
e3fee73c51a0 Move campaign mission images to share/ instead of hardcoding them into frontend
Wuzzy <Wuzzy2@mail.ru>
parents: 13274
diff changeset
   179
            QString image = campfile.value(QString("Mission %1/Script").arg(missionNumber)).toString().replace(QString(".lua"),QString("@2x.png"));
e3fee73c51a0 Move campaign mission images to share/ instead of hardcoding them into frontend
Wuzzy <Wuzzy2@mail.ru>
parents: 13274
diff changeset
   180
            missionInfo.image = "physfs://Graphics/Missions/Campaign/"+campaignName+"/"+image;
9294
f9b31c3efd35 added deafult image if not one available in campaign
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9292
diff changeset
   181
            if (!QFile::exists(missionInfo.image))
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
   182
                missionInfo.image = ":/res/CampaignDefault.png";
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
   183
            missionInfoList.append(missionInfo);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
   184
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
   185
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
   186
    return missionInfoList;
9290
478aa681e702 this seems to work ok, but I have to clean up the code
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9286
diff changeset
   187
}