QTfrontend/team.cpp
author unc0rr
Mon, 26 Nov 2012 00:09:54 +0400
branchflibqtfrontend
changeset 8126 5bfa1b2025d6
parent 8106 861d145b270e
parent 8098 4efee370e2de
child 8128 ebef2de30c18
permissions -rw-r--r--
Merge from default to have recent fixes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     1
/*
1066
1f1b3686a2b0 Update copyright headers a bit
unc0rr
parents: 607
diff changeset
     2
 * Hedgewars, a free turn based strategy game
6952
7f70f37bbf08 license header year range adjustments
sheepluva
parents: 6700
diff changeset
     3
 * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     4
 *
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     8
 *
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    12
 * GNU General Public License for more details.
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    13
 *
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    14
 * You should have received a copy of the GNU General Public License
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    15
 * along with this program; if not, write to the Free Software
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    17
 */
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    18
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    19
#include <QFile>
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    20
#include <QTextStream>
471
e1eb64ba5e9c Small cleanup, faster compilation as a result
unc0rr
parents: 468
diff changeset
    21
#include <QStringList>
e1eb64ba5e9c Small cleanup, faster compilation as a result
unc0rr
parents: 468
diff changeset
    22
#include <QLineEdit>
2874
3c7c2bf1ba38 A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents: 2833
diff changeset
    23
#include <QCryptographicHash>
3333
560e2766c445 Frontend:
smxx
parents: 3236
diff changeset
    24
#include <QSettings>
7130
fcab1fd02bc6 - Allow switching colors with mouse wheel
unc0rr
parents: 6953
diff changeset
    25
#include <QStandardItemModel>
8100
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents: 7955
diff changeset
    26
#include <QDebug>
5252
ded882439548 file association for mac!
koda
parents: 5204
diff changeset
    27
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    28
#include "team.h"
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    29
#include "hwform.h"
7258
722e8a0d89dc - Move colorsModel to appropriate place
unc0rr
parents: 7254
diff changeset
    30
#include "DataManager.h"
314
83773ccf4f09 client/server net pre-alpha
displacer
parents: 312
diff changeset
    31
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    32
HWTeam::HWTeam(const QString & teamname, QObject *parent) :
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    33
    QObject(parent)
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    34
{
8106
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
    35
    QList<QByteArray> baList;
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
    36
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    37
    flib_team team;
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    38
    bzero(&team, sizeof(team));
8106
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
    39
    baList << teamname.toUtf8();
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
    40
    team.name = baList.last().data();
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    41
    team.grave = "Statue";
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    42
    team.fort = "Plane";
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    43
    team.voicepack = "Default";
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    44
    team.flag = "hedgewars";
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    45
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
    46
    for (int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2879
diff changeset
    47
    {
8106
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
    48
        baList << QLineEdit::tr("hedgehog %1").arg(i+1).toUtf8();
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
    49
        team.hogs[i].name = baList.last().data();
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    50
        team.hogs[i].hat = "NoHat";
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2879
diff changeset
    51
    }
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    52
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    53
    m_oldTeamName = teamname;
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    54
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    55
    QVector<flib_binding> binds(BINDS_NUMBER);
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2879
diff changeset
    56
    for(int i = 0; i < BINDS_NUMBER; i++)
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2879
diff changeset
    57
    {
8106
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
    58
        baList << cbinds[i].action.toUtf8();
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
    59
        binds[i].action = baList.last().data();
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
    60
        baList << cbinds[i].strbind.toUtf8();
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
    61
        binds[i].binding = baList.last().data();
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2879
diff changeset
    62
    }
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    63
    team.bindings = binds.data();
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    64
    team.bindingCount = binds.size();
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    65
8106
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
    66
    m_team = flib_team_copy(&team);
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    67
8106
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
    68
    m_team->remoteDriven = false;
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
    69
    m_team->hogsInGame = 4;
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    70
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    71
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    72
HWTeam::HWTeam(const QStringList& strLst, QObject *parent) :
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    73
    QObject(parent)
314
83773ccf4f09 client/server net pre-alpha
displacer
parents: 312
diff changeset
    74
{
8106
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
    75
    QList<QByteArray> baList;
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
    76
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2879
diff changeset
    77
    // net teams are configured from QStringList
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2879
diff changeset
    78
    if(strLst.size() != 23) throw HWTeamConstructException();
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    79
    flib_team team;
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    80
    bzero(&team, sizeof(team));
314
83773ccf4f09 client/server net pre-alpha
displacer
parents: 312
diff changeset
    81
8106
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
    82
    for(int i = 0; i < 6; ++i)
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
    83
        baList << strLst[i].toUtf8();
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
    84
    team.name = baList[0].data();
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    85
    m_oldTeamName = strLst[0];
8106
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
    86
    team.grave = baList[1].data();
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
    87
    team.fort = baList[2].data();
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
    88
    team.voicepack = baList[3].data();
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
    89
    team.flag = baList[4].data();
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
    90
    team.ownerName = baList[5].data();
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    91
    int difficulty = strLst[6].toUInt();
314
83773ccf4f09 client/server net pre-alpha
displacer
parents: 312
diff changeset
    92
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
    93
    for (int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2879
diff changeset
    94
    {
8106
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
    95
        baList << strLst[i * 2 + 7].toUtf8();
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
    96
        team.hogs[i].name = baList.last().data();
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    97
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    98
        QString hat = strLst[i * 2 + 8];
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    99
        if (hat.isEmpty())
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   100
            team.hogs[i].hat = "NoHat";
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   101
        else
8106
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
   102
        {
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
   103
            baList << hat.toUtf8();
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
   104
            team.hogs[i].hat = baList.last().data();
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
   105
        }
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   106
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   107
        team.hogs[i].difficulty = difficulty;
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2879
diff changeset
   108
    }
1840
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   109
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   110
    m_oldTeamName = strLst[0];
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents: 1840
diff changeset
   111
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   112
    QVector<flib_binding> binds(BINDS_NUMBER);
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2879
diff changeset
   113
    for(int i = 0; i < BINDS_NUMBER; i++)
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2879
diff changeset
   114
    {
8106
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
   115
        baList << cbinds[i].action.toUtf8();
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
   116
        binds[i].action = baList.last().data();
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
   117
        baList << cbinds[i].strbind.toUtf8();
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
   118
        binds[i].binding = baList.last().data();
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2879
diff changeset
   119
    }
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   120
    team.bindings = binds.data();
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   121
    team.bindingCount = binds.size();
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   122
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   123
    m_team = flib_team_copy(&team);
8106
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
   124
    m_team->remoteDriven = true;
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
   125
    m_team->hogsInGame = 4;
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   126
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   127
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   128
6223
cc3eb9b7230f It doesn't make much sense to make checks like 'if(game)' if you never set game to 0. Using smart pointers instead. Does it fix segfaults? Probably.
unc0rr
parents: 6060
diff changeset
   129
HWTeam::HWTeam(const HWTeam & other) :
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   130
    QObject(other.parent())
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   131
    , m_oldTeamName(other.m_oldTeamName)
8100
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents: 7955
diff changeset
   132
    , m_team(flib_team_copy(other.m_team))
6223
cc3eb9b7230f It doesn't make much sense to make checks like 'if(game)' if you never set game to 0. Using smart pointers instead. Does it fix segfaults? Probably.
unc0rr
parents: 6060
diff changeset
   133
{
8106
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
   134
    m_team->hogsInGame = other.m_team->hogsInGame;
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
   135
    m_team->remoteDriven = other.m_team->remoteDriven;
6223
cc3eb9b7230f It doesn't make much sense to make checks like 'if(game)' if you never set game to 0. Using smart pointers instead. Does it fix segfaults? Probably.
unc0rr
parents: 6060
diff changeset
   136
}
cc3eb9b7230f It doesn't make much sense to make checks like 'if(game)' if you never set game to 0. Using smart pointers instead. Does it fix segfaults? Probably.
unc0rr
parents: 6060
diff changeset
   137
cc3eb9b7230f It doesn't make much sense to make checks like 'if(game)' if you never set game to 0. Using smart pointers instead. Does it fix segfaults? Probably.
unc0rr
parents: 6060
diff changeset
   138
HWTeam & HWTeam::operator = (const HWTeam & other)
cc3eb9b7230f It doesn't make much sense to make checks like 'if(game)' if you never set game to 0. Using smart pointers instead. Does it fix segfaults? Probably.
unc0rr
parents: 6060
diff changeset
   139
{
6225
505643d4c23d disconnect when going back from lobby page (regression fix)
sheepluva
parents: 6223
diff changeset
   140
    if(this != &other)
505643d4c23d disconnect when going back from lobby page (regression fix)
sheepluva
parents: 6223
diff changeset
   141
    {
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   142
        m_oldTeamName = other.m_oldTeamName;
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   143
        m_team = flib_team_copy(other.m_team);
8106
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
   144
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
   145
        m_team->hogsInGame = other.m_team->hogsInGame;
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
   146
        m_team->remoteDriven = other.m_team->remoteDriven;
6225
505643d4c23d disconnect when going back from lobby page (regression fix)
sheepluva
parents: 6223
diff changeset
   147
    }
6223
cc3eb9b7230f It doesn't make much sense to make checks like 'if(game)' if you never set game to 0. Using smart pointers instead. Does it fix segfaults? Probably.
unc0rr
parents: 6060
diff changeset
   148
6225
505643d4c23d disconnect when going back from lobby page (regression fix)
sheepluva
parents: 6223
diff changeset
   149
    return *this;
6223
cc3eb9b7230f It doesn't make much sense to make checks like 'if(game)' if you never set game to 0. Using smart pointers instead. Does it fix segfaults? Probably.
unc0rr
parents: 6060
diff changeset
   150
}
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   151
8100
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents: 7955
diff changeset
   152
HWTeam::~HWTeam()
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents: 7955
diff changeset
   153
{
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents: 7955
diff changeset
   154
    if(m_team)
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents: 7955
diff changeset
   155
        flib_team_destroy(m_team);
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents: 7955
diff changeset
   156
}
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents: 7955
diff changeset
   157
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   158
bool HWTeam::loadFromFile()
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   159
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   160
    QString name = QString::fromUtf8(m_team->name);
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   161
8100
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents: 7955
diff changeset
   162
    if(m_team)
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents: 7955
diff changeset
   163
        flib_team_destroy(m_team);
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents: 7955
diff changeset
   164
8126
5bfa1b2025d6 Merge from default to have recent fixes
unc0rr
parents: 8106 8098
diff changeset
   165
    m_team = flib_team_from_ini(QString("/Teams/%1.hwt").arg(name).toUtf8().data());
8100
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents: 7955
diff changeset
   166
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents: 7955
diff changeset
   167
    return m_team != NULL;
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   168
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   169
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   170
bool HWTeam::fileExists()
3381
f8800c44b3de Engine:
smxx
parents: 3359
diff changeset
   171
{
8126
5bfa1b2025d6 Merge from default to have recent fixes
unc0rr
parents: 8106 8098
diff changeset
   172
    QFile f(QString("physfs://Teams/%1.hwt").arg(name()));
3381
f8800c44b3de Engine:
smxx
parents: 3359
diff changeset
   173
    return f.exists();
f8800c44b3de Engine:
smxx
parents: 3359
diff changeset
   174
}
f8800c44b3de Engine:
smxx
parents: 3359
diff changeset
   175
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   176
bool HWTeam::deleteFile()
3159
e5eff81d7635 Frontend:
smxx
parents: 2948
diff changeset
   177
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   178
    if(m_team->remoteDriven)
3159
e5eff81d7635 Frontend:
smxx
parents: 2948
diff changeset
   179
        return false;
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   180
8126
5bfa1b2025d6 Merge from default to have recent fixes
unc0rr
parents: 8106 8098
diff changeset
   181
    QFile cfgfile(QString("physfs://Teams/%1.hwt").arg(name()));
3159
e5eff81d7635 Frontend:
smxx
parents: 2948
diff changeset
   182
    cfgfile.remove();
e5eff81d7635 Frontend:
smxx
parents: 2948
diff changeset
   183
    return true;
e5eff81d7635 Frontend:
smxx
parents: 2948
diff changeset
   184
}
e5eff81d7635 Frontend:
smxx
parents: 2948
diff changeset
   185
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   186
bool HWTeam::saveToFile()
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   187
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   188
    if (m_oldTeamName != name())
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2879
diff changeset
   189
    {
8126
5bfa1b2025d6 Merge from default to have recent fixes
unc0rr
parents: 8106 8098
diff changeset
   190
        QFile cfgfile(QString("physfs://Teams/%1.hwt").arg(m_oldTeamName));
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2879
diff changeset
   191
        cfgfile.remove();
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   192
        m_oldTeamName = name();
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2879
diff changeset
   193
    }
8098
4efee370e2de - Fix saving .ini files
unc0rr
parents: 7955
diff changeset
   194
8126
5bfa1b2025d6 Merge from default to have recent fixes
unc0rr
parents: 8106 8098
diff changeset
   195
    return flib_team_to_ini(QString("physfs://Teams/%1.hwt").arg(name()).toUtf8(), m_team) == 0;
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   196
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   197
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   198
352
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
   199
bool HWTeam::isNetTeam() const
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
   200
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   201
    return m_team->remoteDriven;
352
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
   202
}
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
   203
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
   204
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   205
bool HWTeam::operator==(const HWTeam& t1) const
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   206
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   207
    return qstrcmp(m_team->name, t1.m_team->name) == 0;
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   208
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   209
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   210
bool HWTeam::operator<(const HWTeam& t1) const
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   211
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   212
    return qstrcmp(m_team->name, t1.m_team->name) < 0; // if names are equal - test if it is net team
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   213
}
1840
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   214
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   215
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   216
//// Methods for member inspection+modification ////
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   217
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   218
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   219
// name
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   220
QString HWTeam::name() const
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   221
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   222
    return QString::fromUtf8(m_team->name);
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   223
}
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   224
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   225
void HWTeam::setName(const QString & name)
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   226
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   227
    free(m_team->name);
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   228
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   229
    m_team->name = qstrdup(name.toUtf8().constData());
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   230
}
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   231
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   232
QString HWTeam::hedgehogName(int index) const
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   233
{
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   234
    return QString::fromUtf8(m_team->hogs[index].name);
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   235
}
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   236
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   237
QString HWTeam::hedgehogHat(int index) const
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   238
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   239
    return QString::fromUtf8(m_team->hogs[index].hat);
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   240
}
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   241
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   242
void HWTeam::setHedgehogName(int index, const QString & name)
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   243
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   244
    free(m_team->hogs[index].name);
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   245
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   246
    m_team->hogs[index].name = qstrdup(name.toUtf8().constData());
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   247
}
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   248
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   249
void HWTeam::setHedgehogHat(int index, const QString & hat)
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   250
{
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   251
    free(m_team->hogs[index].hat);
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   252
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   253
    m_team->hogs[index].hat = qstrdup(hat.toUtf8().constData());
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   254
}
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   255
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   256
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   257
// owner
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   258
QString HWTeam::owner() const
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   259
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   260
    return QString::fromUtf8(m_team->ownerName);
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   261
}
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   262
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   263
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   264
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   265
// difficulty
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   266
unsigned int HWTeam::difficulty() const
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   267
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   268
    return m_team->hogs[0].difficulty;
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   269
}
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   270
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   271
void HWTeam::setDifficulty(unsigned int level)
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   272
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   273
    for(int i = 0; i < HEDGEHOGS_PER_TEAM; ++i)
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   274
        m_team->hogs[i].difficulty = level;
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   275
}
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   276
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   277
// color
7130
fcab1fd02bc6 - Allow switching colors with mouse wheel
unc0rr
parents: 6953
diff changeset
   278
int HWTeam::color() const
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   279
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   280
    return m_team->colorIndex;
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   281
}
7130
fcab1fd02bc6 - Allow switching colors with mouse wheel
unc0rr
parents: 6953
diff changeset
   282
fcab1fd02bc6 - Allow switching colors with mouse wheel
unc0rr
parents: 6953
diff changeset
   283
QColor HWTeam::qcolor() const
fcab1fd02bc6 - Allow switching colors with mouse wheel
unc0rr
parents: 6953
diff changeset
   284
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   285
    return DataManager::instance().colorsModel()->item(m_team->colorIndex)->data().value<QColor>();
7130
fcab1fd02bc6 - Allow switching colors with mouse wheel
unc0rr
parents: 6953
diff changeset
   286
}
fcab1fd02bc6 - Allow switching colors with mouse wheel
unc0rr
parents: 6953
diff changeset
   287
fcab1fd02bc6 - Allow switching colors with mouse wheel
unc0rr
parents: 6953
diff changeset
   288
void HWTeam::setColor(int color)
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   289
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   290
    m_team->colorIndex = color % DataManager::instance().colorsModel()->rowCount();
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   291
}
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   292
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   293
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   294
// binds
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   295
QString HWTeam::keyBind(unsigned int idx) const
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   296
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   297
    return QString::fromUtf8(m_team->bindings[idx].binding);
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   298
}
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   299
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   300
void HWTeam::bindKey(unsigned int idx, const QString & key)
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   301
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   302
    free(m_team->bindings[idx].binding);
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   303
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   304
    m_team->bindings[idx].binding = qstrdup(key.toUtf8().constData());
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   305
}
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   306
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   307
// flag
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   308
void HWTeam::setFlag(const QString & flag)
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   309
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   310
    free(m_team->flag);
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   311
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   312
    m_team->flag = strdup(flag.toUtf8().constData());
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   313
}
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   314
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   315
QString HWTeam::flag() const
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   316
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   317
    return QString::fromUtf8(m_team->flag);
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   318
}
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   319
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   320
// fort
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   321
void HWTeam::setFort(const QString & fort)
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   322
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   323
    free(m_team->fort);
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   324
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   325
    m_team->fort = strdup(fort.toUtf8().constData());
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   326
}
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   327
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   328
QString HWTeam::fort() const
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   329
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   330
    return QString::fromUtf8(m_team->fort);
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   331
}
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   332
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   333
// grave
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   334
void HWTeam::setGrave(const QString & grave)
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   335
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   336
    free(m_team->grave);
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   337
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   338
    m_team->grave = strdup(grave.toUtf8().constData());
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   339
}
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   340
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   341
QString HWTeam::grave() const
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   342
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   343
    return QString::fromUtf8(m_team->grave);
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   344
}
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   345
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   346
// voicepack - getter/setter
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   347
void HWTeam::setVoicepack(const QString & voicepack)
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   348
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   349
    free(m_team->voicepack);
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   350
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   351
    m_team->voicepack = strdup(voicepack.toUtf8().constData());
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   352
}
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   353
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   354
QString HWTeam::voicepack() const
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   355
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   356
    return QString::fromUtf8(m_team->voicepack);
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   357
}
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   358
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   359
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   360
// campaignProgress - getter
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   361
unsigned int HWTeam::campaignProgress() const
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   362
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   363
    return m_team->campaignProgress;
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   364
}
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   365
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   366
// amount of hedgehogs
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   367
unsigned char HWTeam::numHedgehogs() const
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   368
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   369
    return m_team->hogsInGame;
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   370
}
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   371
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   372
void HWTeam::setNumHedgehogs(unsigned char num)
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   373
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   374
    m_team->hogsInGame = num;
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   375
}
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   376
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5907
diff changeset
   377
// rounds+wins - incrementors
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   378
void HWTeam::incRounds()
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   379
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   380
    m_team->rounds++;
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   381
}
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   382
void HWTeam::incWins()
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   383
{
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   384
    m_team->wins++;
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
   385
}
8106
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
   386
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
   387
flib_team * HWTeam::toFlibTeam()
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
   388
{
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
   389
    return m_team;
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
   390
}