1 /*
2  *  This program is free software; you can redistribute it and/or modify
3  *  it under the terms of the GNU General Public License as published by
4  *  the Free Software Foundation; either version 2 of the License, or
5  *  (at your option) any later version.
6  *
7  *  This program is distributed in the hope that it will be useful,
8  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *  GNU General Public License for more details.
11  *
12  *  You should have received a copy of the GNU General Public License
13  *  along with this program; if not, write to the Free Software
14  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  */
16 
17 #ifndef MELEESETUP_H
18 #define MELEESETUP_H
19 
20 typedef struct MeleeTeam MeleeTeam;
21 typedef struct MeleeSetup MeleeSetup;
22 
23 #ifdef MELEESETUP_INTERNAL
24 #	define MELEETEAM_INTERNAL
25 #endif  /* MELEESETUP_INTERNAL */
26 
27 #include "libs/compiler.h"
28 
29 typedef COUNT FleetShipIndex;
30 
31 #include "libs/uio.h"
32 #include "melee.h"
33 #include "meleeship.h"
34 
35 #if defined(__cplusplus)
36 extern "C" {
37 #endif
38 
39 #ifdef MELEETEAM_INTERNAL
40 struct MeleeTeam
41 {
42 	MeleeShip ships[MELEE_FLEET_SIZE];
43 	char name[MAX_TEAM_CHARS + 1 + 24];
44 			/* The +1 is for the terminating \0; the +24 is in case some
45 			 * default name in starcon.txt is unknowingly mangled. */
46 			// XXX: SvdB: Why would it be mangled? Why don't we just reject
47 			//            it if it is? Is this so that we have some space
48 			//            for multibyte UTF-8 chars?
49 };
50 #endif  /* MELEETEAM_INTERNAL */
51 
52 #ifdef MELEESETUP_INTERNAL
53 struct MeleeSetup
54 {
55 	MeleeTeam teams[NUM_SIDES];
56 	COUNT fleetValue[NUM_SIDES];
57 #ifdef NETPLAY
58 	MeleeTeam sentTeams[NUM_SIDES];
59 			// The last sent (parts of) teams.
60 			// Used in the Update protocol. See doc/devel/netplay/protocol
61 			// XXX: this may actually be deallocated when the battle starts.
62 	bool haveSentTeamName[NUM_SIDES];
63 			// Whether we have sent a team name this 'turn'.
64 			// Used in the Update protocol. See doc/devel/netplay/protocol
65 			// (also for the term 'turn').
66 #endif
67 };
68 
69 #endif  /* MELEESETUP_INTERNAL */
70 
71 extern const size_t MeleeTeam_serialSize;
72 
73 void MeleeTeam_init (MeleeTeam *team);
74 void MeleeTeam_uninit (MeleeTeam *team);
75 MeleeTeam *MeleeTeam_new (void);
76 void MeleeTeam_delete (MeleeTeam *team);
77 #ifdef NETPLAY
78 void MeleeSetup_resetSentTeams (MeleeSetup *setup);
79 #endif  /* NETPLAY */
80 int MeleeTeam_serialize (const MeleeTeam *team, uio_Stream *stream);
81 int MeleeTeam_deserialize (MeleeTeam *team, uio_Stream *stream);
82 COUNT MeleeTeam_getValue (const MeleeTeam *team);
83 MeleeShip MeleeTeam_getShip (const MeleeTeam *team, FleetShipIndex slotNr);
84 void MeleeTeam_setShip (MeleeTeam *team, FleetShipIndex slotNr,
85 		MeleeShip ship);
86 const MeleeShip *MeleeTeam_getFleet (const MeleeTeam *team);
87 const char *MeleeTeam_getTeamName (const MeleeTeam *team);
88 void MeleeTeam_setName (MeleeTeam *team, const char *name);
89 void MeleeTeam_copy (MeleeTeam *copy, const MeleeTeam *original);
90 #if 0
91 bool MeleeTeam_isEqual (const MeleeTeam *team1, const MeleeTeam *team2);
92 #endif
93 
94 #ifdef NETPLAY
95 MeleeShip MeleeSetup_getSentShip (const MeleeSetup *setup, size_t teamNr,
96 		FleetShipIndex slotNr);
97 const char *MeleeSetup_getSentTeamName (const MeleeSetup *setup,
98 		size_t teamNr);
99 bool MeleeSetup_setSentShip (MeleeSetup *setup, size_t teamNr,
100 		FleetShipIndex slotNr, MeleeShip ship);
101 bool MeleeSetup_setSentTeamName (MeleeSetup *setup, size_t teamNr,
102 		const char *name);
103 #if 0
104 bool MeleeSetup_isTeamSent (MeleeSetup *setup, size_t teamNr);
105 #endif
106 #endif  /* NETPLAY */
107 
108 MeleeSetup *MeleeSetup_new (void);
109 void MeleeSetup_delete (MeleeSetup *setup);
110 
111 bool MeleeSetup_setShip (MeleeSetup *setup, size_t teamNr,
112 		FleetShipIndex slotNr, MeleeShip ship);
113 MeleeShip MeleeSetup_getShip (const MeleeSetup *setup, size_t teamNr,
114 		FleetShipIndex slotNr);
115 bool MeleeSetup_setFleet (MeleeSetup *setup, size_t teamNr,
116 		const MeleeShip *fleet);
117 const MeleeShip *MeleeSetup_getFleet (const MeleeSetup *setup, size_t teamNr);
118 bool MeleeSetup_setTeamName (MeleeSetup *setup, size_t teamNr,
119 		const char *name);
120 const char *MeleeSetup_getTeamName (const MeleeSetup *setup,
121 		size_t teamNr);
122 COUNT MeleeSetup_getFleetValue (const MeleeSetup *setup, size_t teamNr);
123 int MeleeSetup_deserializeTeam (MeleeSetup *setup, size_t teamNr,
124 		uio_Stream *stream);
125 int MeleeSetup_serializeTeam (const MeleeSetup *setup, size_t teamNr,
126 		uio_Stream *stream);
127 
128 
129 void MeleeState_setShip (MELEE_STATE *pMS, size_t teamNr,
130 		FleetShipIndex slotNr, MeleeShip ship);
131 void MeleeState_setFleet (MELEE_STATE *pMS, size_t teamNr,
132 		const MeleeShip *fleet);
133 void MeleeState_setTeamName (MELEE_STATE *pMS, size_t teamNr,
134 		const char *name);
135 void MeleeState_setTeam (MELEE_STATE *pMS, size_t teamNr,
136 		const MeleeTeam *team);
137 
138 #if defined(__cplusplus)
139 }
140 #endif
141 
142 #endif  /* MELEESETUP_H */
143 
144