1 //Copyright Paul Reiche, Fred Ford. 1992-2002
2 
3 /*
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18 
19 #ifndef UQM_ENCOUNT_H_
20 #define UQM_ENCOUNT_H_
21 
22 typedef struct brief_ship_info BRIEF_SHIP_INFO;
23 typedef struct encounter ENCOUNTER;
24 
25 // XXX: temporary, for CONVERSATION
26 #include "commglue.h"
27 #include "displist.h"
28 #include "libs/gfxlib.h"
29 #include "planets/planets.h"
30 #include "element.h"
31 #include "races.h"
32 
33 #if defined(__cplusplus)
34 extern "C" {
35 #endif
36 
37 
38 typedef HLINK HENCOUNTER;
39 
40 #define MAX_HYPER_SHIPS 7
41 
42 // ENCOUNTER.flags
43 // XXX: Currently, the flags are combined with num_ships into a single BYTE
44 //   in the savegames: num_ships occupy the low nibble and flags the high one.
45 //   Bits 4 and 5 are available for more flags in the savegames,
46 //   and bits 0-3 available in the game but will not be saved.
47 #define ONE_SHOT_ENCOUNTER (1 << 7)
48 #define ENCOUNTER_REFORMING (1 << 6)
49 #define ENCOUNTER_SHIPS_MASK  0x0f
50 #define ENCOUNTER_FLAGS_MASK  0xf0
51 
52 struct brief_ship_info
53 {
54 	// The only field actually used right now is crew_level
55 	BYTE race_id;
56 	COUNT crew_level;
57 	COUNT max_crew;
58 	BYTE max_energy;
59 
60 };
61 
62 struct encounter
63 {
64 	// LINK elements; must be first
65 	HENCOUNTER pred, succ;
66 
67 	HELEMENT hElement;
68 
69 	SIZE transition_state;
70 	POINT origin;
71 	COUNT radius;
72 	BYTE race_id;
73 	BYTE num_ships;
74 	BYTE flags;
75 			// See ENCOUNTER.flags above
76 	POINT loc_pt;
77 
78 	BRIEF_SHIP_INFO ShipList[MAX_HYPER_SHIPS];
79 			// Only the crew_level member is currently used
80 
81 	SDWORD log_x, log_y;
82 };
83 
84 #define AllocEncounter() AllocLink (&GLOBAL (encounter_q))
85 #define PutEncounter(h) PutQueue (&GLOBAL (encounter_q), h)
86 #define InsertEncounter(h,i) InsertQueue (&GLOBAL (encounter_q), h, i)
87 #define GetHeadEncounter() GetHeadLink (&GLOBAL (encounter_q))
88 #define GetTailEncounter() GetTailLink (&GLOBAL (encounter_q))
89 #define LockEncounter(h,ppe) (*(ppe) = (ENCOUNTER*)LockLink (&GLOBAL (encounter_q), h))
90 #define UnlockEncounter(h) UnlockLink (&GLOBAL (encounter_q), h)
91 #define RemoveEncounter(h) RemoveQueue (&GLOBAL (encounter_q), h)
92 #define FreeEncounter(h) FreeLink (&GLOBAL (encounter_q), h)
93 #define GetPredEncounter(l) _GetPredLink (l)
94 #define GetSuccEncounter(l) _GetSuccLink (l)
95 
96 enum
97 {
98 	HAIL = 0,
99 	ATTACK
100 };
101 
102 extern void EncounterBattle (void);
103 extern void BuildBattle (COUNT which_player);
104 extern COUNT InitEncounter (void);
105 extern COUNT UninitEncounter (void);
106 extern BOOLEAN FleetIsInfinite (COUNT playerNr);
107 extern void UpdateShipFragCrew (STARSHIP *);
108 
109 // Last race the player battled with, or -1 if no battle took place.
110 // Set to -1 by some funcs to inhibit IP groups from intercepting
111 // the flagship.
112 extern SIZE EncounterRace;
113 extern BYTE EncounterGroup;
114 
115 #if defined(__cplusplus)
116 }
117 #endif
118 
119 #endif /* UQM_ENCOUNT_H_ */
120