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