1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell
5  * or otherwise commercially exploit the source or things you created based on the
6  * source.
7  *
8 */
9 
10 
11 
12 #ifndef _HUD_SQUADMSG
13 #define _HUD_SQUADMSG
14 
15 #include "hud/hud.h"
16 #include "network/multi.h"
17 
18 #define SM_MODE_TYPE_SELECT			1		//am I going to message a ship or a wing
19 #define SM_MODE_SHIP_SELECT			2		//choosing actual ship
20 #define SM_MODE_WING_SELECT			3		//choosing actual wing
21 #define SM_MODE_SHIP_COMMAND			4		//which command to send to a ship
22 #define SM_MODE_WING_COMMAND			5		//which command to send to a wing
23 #define SM_MODE_REINFORCEMENTS		6		//call for reinforcements
24 #define SM_MODE_REPAIR_REARM			7		//repair/rearm player ship
25 #define SM_MODE_REPAIR_REARM_ABORT	8		//abort repair/rearm of player ship
26 #define SM_MODE_ALL_FIGHTERS			9		//message all fighters/bombers
27 
28 // define for trapping messages send to "all fighters"
29 #define MESSAGE_ALL_FIGHTERS		-999
30 
31 class object;
32 
33 // defines for messages that can be sent from the player.  Defined at bitfields so that we can enable
34 // and disable messages on a message by message basis
35 
36 #define NUM_COMM_ORDER_ITEMS		16
37 
38 #define ATTACK_TARGET_ITEM			(1<<0)
39 #define DISABLE_TARGET_ITEM			(1<<1)
40 #define DISARM_TARGET_ITEM			(1<<2)
41 #define PROTECT_TARGET_ITEM			(1<<3)
42 #define IGNORE_TARGET_ITEM			(1<<4)
43 #define FORMATION_ITEM				(1<<5)
44 #define COVER_ME_ITEM				(1<<6)
45 #define ENGAGE_ENEMY_ITEM			(1<<7)
46 #define CAPTURE_TARGET_ITEM			(1<<8)
47 
48 // the next are for the support ship only
49 #define REARM_REPAIR_ME_ITEM		(1<<9)
50 #define ABORT_REARM_REPAIR_ITEM		(1<<10)
51 #define STAY_NEAR_ME_ITEM			(1<<11)
52 #define STAY_NEAR_TARGET_ITEM		(1<<12)
53 #define KEEP_SAFE_DIST_ITEM			(1<<13)
54 
55 // next item for all ships again -- to try to preserve relative order within the message menu
56 #define DEPART_ITEM					(1<<14)
57 
58 // out of order, but it was this way in the original source
59 #define DISABLE_SUBSYSTEM_ITEM		(1<<15)
60 
61 // used for Message box gauge
62 #define NUM_MBOX_FRAMES		3
63 
64 // data structure to hold character string of commands for comm menu
65 typedef struct comm_order {
66 	SCP_string name;
67 	int item;
68 } comm_order;
69 
70 typedef struct sexp_com_order{
71 	const char *name;
72 	int xstring;
73 	int item;
74 }sexp_com_order;
75 
76 extern comm_order Comm_orders[];
77 extern sexp_com_order Sexp_comm_orders[];
78 
79 // following defines are the set of possible commands that can be given to a ship.  A mission designer
80 // might not allow some messages
81 
82 //WMC - Formerly FIGHTER_MESSAGES
83 #define DEFAULT_MESSAGES	(ATTACK_TARGET_ITEM | DISABLE_TARGET_ITEM | DISARM_TARGET_ITEM | PROTECT_TARGET_ITEM | IGNORE_TARGET_ITEM | FORMATION_ITEM | COVER_ME_ITEM | ENGAGE_ENEMY_ITEM | DEPART_ITEM | DISABLE_SUBSYSTEM_ITEM)
84 /*
85 #define BOMBER_MESSAGES		FIGHTER_MESSAGES			// bombers can do the same things as fighters
86 
87 #define TRANSPORT_MESSAGES	(ATTACK_TARGET_ITEM | CAPTURE_TARGET_ITEM | DEPART_ITEM )
88 #define FREIGHTER_MESSAGES	TRANSPORT_MESSAGES		// freighters can do the same things as transports
89 
90 #define CRUISER_MESSAGES	(ATTACK_TARGET_ITEM | DEPART_ITEM)
91 
92 #define CAPITAL_MESSAGES	(DEPART_ITEM)				// can't order capitals to do much!!!!
93 
94 #define SUPERCAP_MESSAGES	(0)							// supercaps ignore you :p
95 
96 #define SUPPORT_MESSAGES	(REARM_REPAIR_ME_ITEM | ABORT_REARM_REPAIR_ITEM | STAY_NEAR_ME_ITEM | STAY_NEAR_TARGET_ITEM | KEEP_SAFE_DIST_ITEM | DEPART_ITEM )
97 */
98 // these messages require an active target.  They are also the set of messages
99 // which cannot be given to a ship when the target is on the same team, or the target
100 // is not a ship.
101 #define ENEMY_TARGET_MESSAGES		(ATTACK_TARGET_ITEM | DISABLE_TARGET_ITEM | DISARM_TARGET_ITEM | IGNORE_TARGET_ITEM | STAY_NEAR_TARGET_ITEM | CAPTURE_TARGET_ITEM | DISABLE_SUBSYSTEM_ITEM )
102 #define FRIENDLY_TARGET_MESSAGES	(PROTECT_TARGET_ITEM)
103 
104 #define TARGET_MESSAGES	(ENEMY_TARGET_MESSAGES | FRIENDLY_TARGET_MESSAGES)
105 
106 
107 
108 typedef struct squadmsg_history {
109 	int order_to;			// ship/wing that received the order
110 	int order;				// order that the ship/wing received (see defines above)
111 	int target;				// target of the order
112 	int order_from;			// ship that sent the order
113 	int special_index;		// any extra data the order might need (subsystem names for instance)
114 	fix order_time;			// when this order was sent (or received by the server in multiplayer)
squadmsg_historysquadmsg_history115 	squadmsg_history(): order_to(-1), order(-1), target(-1), order_from(-1), special_index(-1), order_time(0) {}
116 } squadmsg_history;
117 
118 extern SCP_vector<squadmsg_history> Squadmsg_history;
119 
120 /*
121 #define SQUADMSG_HISTORY_MAX 160
122 
123 typedef struct squadmsg_history {
124 	int ship;  // ship that received the order
125 	int order;  // order that the ship received (see defines above)
126 	int target;  // ship that is the target of the order
127 
128 	squadmsg_history(): ship(-1), order(-1), target(-1) {};
129 } squadmsg_history;
130 
131 
132 extern int squadmsg_history_index;
133 extern squadmsg_history Squadmsg_history[SQUADMSG_HISTORY_MAX];
134 */
135 
136 extern int Multi_squad_msg_local;
137 extern int Multi_squad_msg_targ;
138 
139 extern void hud_init_squadmsg();
140 extern void hud_init_comm_orders();
141 extern void hud_squadmsg_toggle();						// toggles the state of messaging mode
142 extern void hud_squadmsg_shortcut( int command );	// use of a shortcut key
143 extern int hud_squadmsg_hotkey_select( int k );	// a hotkey was hit -- maybe send a message to those ship(s)
144 extern void hud_squadmsg_save_keys( int do_scroll = 0 );					// saves into local area keys which need to be saved/restored when in messaging mode
145 extern int hud_squadmsg_do_frame();
146 extern int hud_query_order_issued(const char *to, const char *order_name, const char *target = nullptr, int timestamp = 0, const char *from = nullptr, const char *special_index = nullptr);
147 extern int hud_squadmsg_read_key( int k );			// called from high level keyboard code
148 
149 extern void hud_squadmsg_repair_rearm( int toggle_state, object *obj = NULL );
150 extern void hud_squadmsg_repair_rearm_abort( int toggle_state, object *obj = NULL );
151 extern void hud_squadmsg_rearm_shortcut();
152 
153 
154 #define SQUADMSG_HISTORY_NO_UPDATE		0
155 #define SQUADMSG_HISTORY_UPDATE			1
156 #define SQUADMSG_HISTORY_ADD_ENTRY		2
157 
158 extern int hud_squadmsg_send_ship_command( int shipnum, int command, int send_message, int update_history = SQUADMSG_HISTORY_ADD_ENTRY, int player_num = -1 );
159 extern int hud_squadmsg_send_wing_command( int wingnum, int command, int send_message, int update_history = SQUADMSG_HISTORY_ADD_ENTRY, int player_num = -1 );
160 extern void hud_squadmsg_send_to_all_fighters( int command, int player_num = -1 );
161 extern void hud_squadmsg_call_reinforcement(int reinforcement_num, int player_num = -1);
162 
163 extern int hud_squadmsg_reinforcements_available(int team);
164 
165 void hud_enemymsg_toggle();						// debug function to allow messaging of enemies
166 
167 // Added for voicer implementation
168 void hud_squadmsg_do_mode( int mode );
169 
170 class HudGaugeSquadMessage: public HudGauge
171 {
172 protected:
173 	hud_frames Mbox_gauge[NUM_MBOX_FRAMES];
174 
175 	int Header_offsets[2];
176 	int Item_start_offsets[2];
177 	int Middle_frame_start_offset_y;
178 	int bottom_bg_offset;
179 	int Item_h;
180 	int Item_offset_x;
181 
182 	int Pgup_offsets[2];
183 	int Pgdn_offsets[2];
184 
185 	int flash_timer[2];
186 	bool flash_flag;
187 public:
188 	HudGaugeSquadMessage();
189 	void initBitmaps(char *fname_top, char *fname_middle, char *fname_bottom);
190 	void initHeaderOffsets(int x, int y);
191 	void initItemStartOffsets(int x, int y);
192 	void initMiddleFrameStartOffsetY(int y);
193 	void initBottomBgOffset(int offset);
194 	void initItemHeight(int h);
195 	void initItemOffsetX(int x);
196 	void initPgUpOffsets(int x, int y);
197 	void initPgDnOffsets(int x, int y);
198 
199 	void render(float frametime) override;
200 	bool canRender() override;
201 	void pageIn() override;
202 	void initialize() override;
203 	void startFlashPageScroll(int duration = 1400);
204 	bool maybeFlashPageScroll(bool flash_fast = false);
205 };
206 
207 #endif
208