project_files/frontlib/model/team.h
author unc0rr
Sat, 16 Dec 2017 22:58:28 +0100
changeset 12858 a9d105dc5c95
parent 10017 de822cd3df3a
permissions -rw-r--r--
Improve this code a bit more
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
     1
/*
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
     2
 * Hedgewars, a free turn based strategy game
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
     3
 * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
     4
 *
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
     5
 * This program is free software; you can redistribute it and/or
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
     6
 * modify it under the terms of the GNU General Public License
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
     7
 * as published by the Free Software Foundation; either version 2
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
     8
 * of the License, or (at your option) any later version.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
     9
 *
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    13
 * GNU General Public License for more details.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    14
 *
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    15
 * You should have received a copy of the GNU General Public License
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    16
 * along with this program; if not, write to the Free Software
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    18
 */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    19
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    20
/**
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    21
 * This file defines a data structure for a hedgewars team.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    22
 *
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    23
 * Teams are used in several different contexts in Hedgewars, and some of these require
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    24
 * extra information about teams. For example, the weaponset is important
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    25
 * to the engine, but not for ini reading/writing, and with the team statistics it is the
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    26
 * other way around. To keep things simple, the data structure can hold all information
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    27
 * used in any context. On the downside, that means we can't use static typing to ensure
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    28
 * that team information is "complete" for a particular purpose.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    29
 */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    30
#ifndef TEAM_H_
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    31
#define TEAM_H_
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    32
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    33
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    34
#include "weapon.h"
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    35
#include "../hwconsts.h"
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    36
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    37
#include <stdbool.h>
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    38
#include <stdint.h>
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    39
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    40
#define TEAM_DEFAULT_HEALTH 100
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    41
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    42
/**
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    43
 * Struct representing a single keybinding.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    44
 */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    45
typedef struct {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    46
    char *action;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    47
    char *binding;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    48
} flib_binding;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    49
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    50
typedef struct {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    51
    char *name;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    52
    char *hat;          //!< e.g. hair_yellow; References a .png file in Data/Graphics/Hats
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    53
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    54
    //! Statistics. They are irrelevant for the engine or server,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    55
    //! but provided for ini reading/writing by the frontend.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    56
    int rounds;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    57
    int kills;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    58
    int deaths;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    59
    int suicides;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    60
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    61
    int difficulty;     //!< 0 = human, 1 = most difficult bot ... 5 = least difficult bot (somewhat counterintuitive)
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    62
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    63
    //! Transient setting used in game setup
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    64
    int initialHealth;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    65
    flib_weaponset *weaponset;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    66
} flib_hog;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    67
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    68
typedef struct {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    69
    flib_hog hogs[HEDGEHOGS_PER_TEAM];
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    70
    char *name;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    71
    char *grave;        //!< e.g. "Bone"; References a .png file in Data/Graphics/Graves
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    72
    char *fort;         //!< e.g. "Castle"; References a series of files in Data/Forts
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    73
    char *voicepack;    //!< e.g. "Classic"; References a directory in Data/Sounds/voices
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    74
    char *flag;         //!< e.g. "hedgewars"; References a .png file in Data/Graphics/Flags
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    75
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    76
    flib_binding *bindings;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    77
    int bindingCount;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    78
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    79
    //! Statistics. They are irrelevant for the engine or server,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    80
    //! but provided for ini reading/writing by the frontend.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    81
    int rounds;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    82
    int wins;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    83
    int campaignProgress;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    84
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    85
    //! Transient settings used in game setup
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    86
    int colorIndex;     //!< Index into a color table
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    87
    int hogsInGame;     //!< The number of hogs that will actually play
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    88
    bool remoteDriven;  //!< true for non-local teams in a network game
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    89
    char *ownerName;    //!< Username of the owner of a team in a network game
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    90
} flib_team;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    91
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    92
/**
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    93
 * Free all memory associated with the team
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    94
 */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    95
void flib_team_destroy(flib_team *team);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    96
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    97
/**
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    98
 * Loads a team, returns NULL on error. Destroy this team using flib_team_destroy.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
    99
 * This will not fill in the fields marked as "transient" in the structs above.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   100
 */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   101
flib_team *flib_team_from_ini(const char *filename);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   102
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   103
/**
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   104
 * Write the team to an ini file. Attempts to retain extra ini settings
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   105
 * that were already present. Note that not all fields of a team struct
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   106
 * are stored in the ini, some are only used intermittently to store
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   107
 * information about a team in the context of a game.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   108
 *
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   109
 * The flib_team can handle "difficulty" on a per-hog basis, but it
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   110
 * is only written per-team in the team file. The difficulty of the
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   111
 * first hog is used for the entire team when writing.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   112
 */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   113
int flib_team_to_ini(const char *filename, const flib_team *team);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   114
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   115
/**
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   116
 * Set the same weaponset for every hog in the team
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   117
 */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   118
int flib_team_set_weaponset(flib_team *team, const flib_weaponset *set);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   119
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   120
/**
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   121
 * Set the same initial health for every hog.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   122
 */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   123
void flib_team_set_health(flib_team *team, int health);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   124
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   125
/**
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   126
 * Create a deep copy of a team. Returns NULL on failure.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   127
 */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   128
flib_team *flib_team_copy(const flib_team *team);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   129
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   130
#endif /* TEAM_H_ */