QTfrontend/campaign.cpp
author Periklis Ntanasis <pntanasis@gmail.com>
Fri, 28 Jun 2013 02:38:56 +0300
branchspacecampaign
changeset 9272 6fa30e491b37
parent 9219 0a4b6bb69f99
child 9275 3df990e2ee0e
permissions -rw-r--r--
changes in campaign page - not tested wip
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
9080
9b42757d7e71 bump copyright year for Andrey entries
unc0rr
parents: 9001
diff changeset
     3
 * Copyright (c) 2004-2013 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
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
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"
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    21
#include <QSettings>
9272
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    22
#include <QHash>
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    23
#include <QDebug>
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    24
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    25
QStringList getCampMissionList(QString & campaign)
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    26
{
8049
133e22b5c410 Get rid of DataManager::findFileForRead
unc0rr
parents: 7794
diff changeset
    27
    QSettings campfile("physfs://Missions/Campaign/" + campaign + "/campaign.ini", QSettings::IniFormat, 0);
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    28
    campfile.setIniCodec("UTF-8");
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    29
    unsigned int mNum = campfile.value("MissionNum", 0).toInt();
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8049
diff changeset
    30
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    31
    QStringList missionList;
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    32
    for (unsigned int i = 0; i < mNum; i++)
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    33
    {
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    34
      missionList += campfile.value(QString("Mission %1/Name").arg(i + 1)).toString();
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    35
    }
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    36
    return missionList;
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    37
}
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8049
diff changeset
    38
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    39
unsigned int getCampProgress(QString & teamName, QString & campName)
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    40
{
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    41
    QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + teamName + ".hwt", QSettings::IniFormat, 0);
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    42
    teamfile.setIniCodec("UTF-8");
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    43
    return teamfile.value("Campaign " + campName + "/Progress", 0).toInt();
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    44
}
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    45
9272
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    46
QHash<QString,QString> getUnlockedMissions2(QString & campaignName, QString & teamName)
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    47
{
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    48
	QHash<QString,QString> hash;
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    49
	QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + teamName + ".hwt", QSettings::IniFormat, 0);
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    50
    teamfile.setIniCodec("UTF-8");
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    51
    unsigned int progress = teamfile.value("Campaign " + campaignName + "/Progress", 0).toInt();
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    52
    qDebug("HERE is progress : %d",progress);
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    53
    unsigned int unlockedMissions = teamfile.value("Campaign " + campaignName + "/UnlockedMissions", 0).toInt();
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    54
    qDebug("HERE is unlocked missions : %d",unlockedMissions);
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    55
    
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    56
    QSettings campfile("physfs://Missions/Campaign/" + campaignName + "/campaign.ini", QSettings::IniFormat, 0);
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    57
    campfile.setIniCodec("UTF-8");
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    58
    unsigned int missionsNumber = campfile.value("MissionNum", 0).toInt();
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    59
    qDebug("HERE is number of missions : %d",missionsNumber);  
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    60
    
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    61
    if(progress>0)
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    62
    {
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    63
		for(unsigned int i=1;i<=missionsNumber;i++)
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    64
		{
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    65
			hash[getCampaignScript(campaignName,i)] = campfile.value(QString("Mission %1/Name").arg(i)).toString();
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    66
		}
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    67
	} 
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    68
	else if(unlockedMissions>0)
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    69
	{
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    70
		for(unsigned int i=1;i<=unlockedMissions;i++)
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    71
		{
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    72
			int missionNumber = teamfile.value("Campaign " + campaignName + "/Mission"+i, -1).toInt();
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    73
			hash[getCampaignScript(campaignName,missionNumber)] = campfile.value(QString("Mission %1/Name").arg(missionNumber)).toString();
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    74
		}
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    75
	}
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    76
	return hash;
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    77
}
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    78
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    79
QStringList getUnlockedMissions(QString & teamName, QString & campName)
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    80
{
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    81
	QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + teamName + ".hwt", QSettings::IniFormat, 0);
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    82
    teamfile.setIniCodec("UTF-8");
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    83
    unsigned int mNum = teamfile.value("UnlockedMissions", 0).toInt();
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    84
    
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    85
    QStringList missionList;
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    86
    for (unsigned int i = 0; i < mNum; i++)
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    87
    {
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    88
      missionList += teamfile.value(QString("Mission%1").arg(i + 1)).toString();
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    89
    }
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    90
    return missionList;
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    91
}
6fa30e491b37 changes in campaign page - not tested wip
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9219
diff changeset
    92
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    93
QString getCampaignScript(QString campaign, unsigned int mNum)
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    94
{
8049
133e22b5c410 Get rid of DataManager::findFileForRead
unc0rr
parents: 7794
diff changeset
    95
    QSettings campfile("physfs://Missions/Campaign/" + campaign + "/campaign.ini", QSettings::IniFormat, 0);
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    96
    campfile.setIniCodec("UTF-8");
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    97
    return campfile.value(QString("Mission %1/Script").arg(mNum)).toString();
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents:
diff changeset
    98
}
9182
f92e205bc167 issue 562, image and description for the campaign page
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9080
diff changeset
    99
f92e205bc167 issue 562, image and description for the campaign page
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9080
diff changeset
   100
QString getCampaignImage(QString campaign, unsigned int mNum)
f92e205bc167 issue 562, image and description for the campaign page
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9080
diff changeset
   101
{
9219
0a4b6bb69f99 bring windows fixes from main repo
koda
parents: 9182
diff changeset
   102
    return getCampaignScript(campaign,mNum).replace(QString(".lua"),QString(".png"));
9182
f92e205bc167 issue 562, image and description for the campaign page
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9080
diff changeset
   103
}
f92e205bc167 issue 562, image and description for the campaign page
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9080
diff changeset
   104
9219
0a4b6bb69f99 bring windows fixes from main repo
koda
parents: 9182
diff changeset
   105
QString getCampaignMissionName(QString campaign, unsigned int mNum)
9182
f92e205bc167 issue 562, image and description for the campaign page
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9080
diff changeset
   106
{
9219
0a4b6bb69f99 bring windows fixes from main repo
koda
parents: 9182
diff changeset
   107
    return getCampaignScript(campaign,mNum).replace(QString(".lua"),QString(""));
9182
f92e205bc167 issue 562, image and description for the campaign page
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9080
diff changeset
   108
}
f92e205bc167 issue 562, image and description for the campaign page
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9080
diff changeset
   109