summaryrefslogtreecommitdiff
path: root/src/uqm/supermelee/meleesetup.h
blob: 0097d920bb41f6e2a99962228f60f36a24de305e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef MELEESETUP_H
#define MELEESETUP_H

typedef struct MeleeTeam MeleeTeam;
typedef struct MeleeSetup MeleeSetup;

#ifdef MELEESETUP_INTERNAL
#	define MELEETEAM_INTERNAL
#endif  /* MELEESETUP_INTERNAL */

#include "libs/compiler.h"

typedef COUNT FleetShipIndex;

#include "libs/uio.h"
#include "melee.h"
#include "meleeship.h"

#if defined(__cplusplus)
extern "C" {
#endif

#ifdef MELEETEAM_INTERNAL
struct MeleeTeam
{
	MeleeShip ships[MELEE_FLEET_SIZE];
	char name[MAX_TEAM_CHARS + 1 + 24];
			/* The +1 is for the terminating \0; the +24 is in case some
			 * default name in starcon.txt is unknowingly mangled. */
			// XXX: SvdB: Why would it be mangled? Why don't we just reject
			//            it if it is? Is this so that we have some space
			//            for multibyte UTF-8 chars?
};
#endif  /* MELEETEAM_INTERNAL */

#ifdef MELEESETUP_INTERNAL
struct MeleeSetup
{
	MeleeTeam teams[NUM_SIDES];
	COUNT fleetValue[NUM_SIDES];
#ifdef NETPLAY
	MeleeTeam sentTeams[NUM_SIDES];
			// The last sent (parts of) teams.
			// Used in the Update protocol. See doc/devel/netplay/protocol
			// XXX: this may actually be deallocated when the battle starts.
	bool haveSentTeamName[NUM_SIDES];
			// Whether we have sent a team name this 'turn'.
			// Used in the Update protocol. See doc/devel/netplay/protocol
			// (also for the term 'turn').
#endif
};

#endif  /* MELEESETUP_INTERNAL */

extern const size_t MeleeTeam_serialSize;

void MeleeTeam_init (MeleeTeam *team);
void MeleeTeam_uninit (MeleeTeam *team);
MeleeTeam *MeleeTeam_new (void);
void MeleeTeam_delete (MeleeTeam *team);
#ifdef NETPLAY
void MeleeSetup_resetSentTeams (MeleeSetup *setup);
#endif  /* NETPLAY */
int MeleeTeam_serialize (const MeleeTeam *team, uio_Stream *stream);
int MeleeTeam_deserialize (MeleeTeam *team, uio_Stream *stream);
COUNT MeleeTeam_getValue (const MeleeTeam *team);
MeleeShip MeleeTeam_getShip (const MeleeTeam *team, FleetShipIndex slotNr);
void MeleeTeam_setShip (MeleeTeam *team, FleetShipIndex slotNr,
		MeleeShip ship);
const MeleeShip *MeleeTeam_getFleet (const MeleeTeam *team);
const char *MeleeTeam_getTeamName (const MeleeTeam *team);
void MeleeTeam_setName (MeleeTeam *team, const char *name);
void MeleeTeam_copy (MeleeTeam *copy, const MeleeTeam *original);
#if 0
bool MeleeTeam_isEqual (const MeleeTeam *team1, const MeleeTeam *team2);
#endif

#ifdef NETPLAY
MeleeShip MeleeSetup_getSentShip (const MeleeSetup *setup, size_t teamNr,
		FleetShipIndex slotNr);
const char *MeleeSetup_getSentTeamName (const MeleeSetup *setup,
		size_t teamNr);
bool MeleeSetup_setSentShip (MeleeSetup *setup, size_t teamNr,
		FleetShipIndex slotNr, MeleeShip ship);
bool MeleeSetup_setSentTeamName (MeleeSetup *setup, size_t teamNr,
		const char *name);
#if 0
bool MeleeSetup_isTeamSent (MeleeSetup *setup, size_t teamNr);
#endif
#endif  /* NETPLAY */

MeleeSetup *MeleeSetup_new (void);
void MeleeSetup_delete (MeleeSetup *setup);

bool MeleeSetup_setShip (MeleeSetup *setup, size_t teamNr,
		FleetShipIndex slotNr, MeleeShip ship);
MeleeShip MeleeSetup_getShip (const MeleeSetup *setup, size_t teamNr,
		FleetShipIndex slotNr);
bool MeleeSetup_setFleet (MeleeSetup *setup, size_t teamNr,
		const MeleeShip *fleet);
const MeleeShip *MeleeSetup_getFleet (const MeleeSetup *setup, size_t teamNr);
bool MeleeSetup_setTeamName (MeleeSetup *setup, size_t teamNr,
		const char *name);
const char *MeleeSetup_getTeamName (const MeleeSetup *setup,
		size_t teamNr);
COUNT MeleeSetup_getFleetValue (const MeleeSetup *setup, size_t teamNr);
int MeleeSetup_deserializeTeam (MeleeSetup *setup, size_t teamNr,
		uio_Stream *stream);
int MeleeSetup_serializeTeam (const MeleeSetup *setup, size_t teamNr,
		uio_Stream *stream);


void MeleeState_setShip (MELEE_STATE *pMS, size_t teamNr,
		FleetShipIndex slotNr, MeleeShip ship);
void MeleeState_setFleet (MELEE_STATE *pMS, size_t teamNr,
		const MeleeShip *fleet);
void MeleeState_setTeamName (MELEE_STATE *pMS, size_t teamNr,
		const char *name);
void MeleeState_setTeam (MELEE_STATE *pMS, size_t teamNr,
		const MeleeTeam *team);

#if defined(__cplusplus)
}
#endif

#endif  /* MELEESETUP_H */