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