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