2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
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
10 * $Logfile: /Freespace2/code/Hud/HUDsquadmsg.cpp $
15 * File to control sqaudmate messaging
18 * Revision 1.5 2005/08/12 08:52:32 taylor
19 * various GCC4 warning fixes
21 * Revision 1.4 2002/07/13 06:46:48 theoddone33
24 * Revision 1.3 2002/06/09 04:41:21 relnev
25 * added copyright header
27 * Revision 1.2 2002/05/07 03:16:45 theoddone33
28 * The Great Newline Fix
30 * Revision 1.1.1.1 2002/05/03 03:28:09 root
34 * 16 9/06/99 10:45a Andsager
35 * Add freighter to player override of protected status.
37 * 15 9/06/99 10:32a Andsager
38 * Allow attack of protected fighter, bomber, freighters, by player's
41 * 14 8/26/99 8:51p Dave
42 * Gave multiplayer TvT messaging a heavy dose of sanity. Cheat codes.
44 * 13 7/30/99 10:31p Dave
45 * Added comm menu to the configurable hud files.
47 * 12 7/09/99 5:54p Dave
48 * Seperated cruiser types into individual types. Added tons of new
49 * briefing icons. Campaign screen.
51 * 11 6/16/99 10:20a Dave
52 * Added send-message-list sexpression.
54 * 10 6/09/99 9:53a Andsager
55 * 1st pass at grey menu items when no ships/wings/fighters accepting
58 * 9 4/23/99 12:01p Johnson
61 * 8 4/16/99 5:54p Dave
62 * Support for on/off style "stream" weapons. Real early support for
63 * target-painting lasers.
65 * 7 3/30/99 5:40p Dave
66 * Fixed reinforcements for TvT in multiplayer.
68 * 6 3/28/99 5:58p Dave
69 * Added early demo code. Make objects move. Nice and framerate
70 * independant, but not much else. Don't use yet unless you're me :)
72 * 5 1/07/99 9:07a Jasen
75 * 4 12/28/98 3:17p Dave
76 * Support for multiple hud bitmap filenames for hi-res mode.
78 * 3 12/21/98 5:02p Dave
79 * Modified all hud elements to be multi-resolution friendly.
81 * 2 10/07/98 10:53a Dave
84 * 1 10/07/98 10:49a Dave
86 * 198 9/11/98 2:05p Allender
87 * make reinforcements work correctly in multiplayer games. There still
88 * may be a team vs team issue that I haven't thought of yet :-(
90 * 197 8/28/98 3:28p Dave
91 * EMP effect done. AI effects may need some tweaking as required.
93 * 196 8/25/98 1:48p Dave
94 * First rev of EMP effect. Player side stuff basically done. Next comes
97 * 195 6/30/98 2:17p Dave
98 * Revised object update system. Removed updates for all weapons. Put
99 * button info back into control info packet.
101 * 194 6/09/98 10:31a Hoffoss
102 * Created index numbers for all xstr() references. Any new xstr() stuff
103 * added from here on out should be added to the end if the list. The
104 * current list count can be found in FreeSpace.cpp (search for
107 * 193 5/26/98 11:54a Allender
108 * fix multiplayer problems and sexpression crash
110 * 192 5/24/98 4:27p Allender
111 * fix bug when determine who could message in multiplayer
113 * 191 5/23/98 2:34a Lawrance
114 * Fix problems with HUD squad messaging, don't save/restore bindings
116 * 190 5/22/98 12:41a Allender
117 * don't save/restore key presses in comm menu
119 * 189 5/21/98 9:38p Allender
120 * don't save/clear key bindings
122 * 188 5/21/98 3:32p Allender
123 * don't allow comm menu in observer mode
125 * 187 5/19/98 12:19p Mike
128 * 186 5/18/98 10:08a Lawrance
129 * increase MSG_KEY_EAT_TIME to 300ms
131 * 185 5/18/98 12:41a Allender
132 * fixed subsystem problems on clients (i.e. not reporting properly on
133 * damage indicator). Fixed ingame join problem with respawns. minor
136 * 184 5/13/98 5:08p Allender
137 * fix code in which sometimes wings wouldn't respond in multiplayer when
138 * doing a message all fighters
140 * 183 5/08/98 4:38p Allender
141 * always allow player ships to count when counting fighters for
142 * messaging. Terran command will now always issue the shooting at
145 * 182 5/08/98 2:11p Mike
146 * Add "/Repair Subsys" to "Rearm" option in Comm menu.
148 * 181 5/06/98 2:57p Allender
149 * always allow rearm ship to be called in
151 * 180 5/05/98 2:04a Mike
152 * Fix bug in support ship code.
154 * 179 5/05/98 1:41a Mike
155 * Improve support ship availability.
157 * 178 5/04/98 12:59a Allender
158 * players who are traitors shouldn't be allowed to rearm or use messaging
161 * 177 5/04/98 12:39a Allender
162 * make page up and page down only active when > 10 items on menu
164 * 176 4/29/98 10:56p Allender
165 * don't allow shortcuts in mutliplayer when player cannot message (except
168 * 175 4/23/98 10:06a Allender
169 * don't use the word "player" in event log for rearm event. Send
170 * shipname instead (players only)
172 * 174 4/23/98 9:15a Allender
173 * make rearm shortcut work for clients
175 * 173 4/23/98 1:49a Allender
176 * major rearm/repair fixes for multiplayer. Fixed respawning of AI ships
177 * to not respawn until 5 seconds after they die. Send escort information
180 * 172 4/22/98 4:59p Allender
181 * new multiplayer dead popup. big changes to the comm menu system for
182 * team vs. team. Start of debriefing stuff for team vs. team Make form
183 * on my wing work with individual ships who have high priority orders
185 * 171 4/21/98 12:15a Allender
186 * don't allow observers to use shortcut messaging keys
188 * 170 4/20/98 12:36a Mike
189 * Make team vs. team work when player is hostile. Several targeting
192 * 169 4/13/98 12:51p Allender
193 * made countermeasure succeed indicator work in multiplayer. Make rearm
194 * shortcut work more appropriately.
196 * 168 4/10/98 2:42p Johnson
197 * (from allender) when sending wing command, don't assert if ship to
198 * send message not found -- don't send message. Allow rearm message
199 * shortcut even if comm destroyed
201 * 167 4/10/98 2:39p Johnson
203 * 166 4/10/98 12:47p Allender
204 * changed working on replay popup. Don't reference repair in comm menu.
205 * Added Shift-R for repair me
207 * 165 4/09/98 12:35p Allender
208 * disallow messaging to departing wings and departing/dying ships
210 * 164 4/08/98 4:06p Allender
211 * make selection of wing Player team based, not TEAM_FRIENDLY.
213 * 163 4/07/98 5:30p Lawrance
214 * Player can't send/receive messages when comm is destroyed. Garble
215 * messages when comm is damaged.
217 * 162 4/07/98 1:53p Lawrance
218 * Fix uninitialized data bug.
220 * 161 4/06/98 12:11a Allender
221 * prevent the comm menu keys from being held over after menu goes away
223 * 160 4/05/98 3:06p Allender
224 * don't allow ships/wings to act on orders which they shouldn't receive
226 * 159 4/03/98 12:17a Allender
227 * new sexpression to detect departed or destroyed. optionally disallow
228 * support ships. Allow docking with escape pods
230 * 158 4/02/98 5:50p Dave
231 * Put in support for standard comm messages to get sent to netplayers as
232 * well as ai ships. Make critical button presses not get evaluated on the
239 #include "freespace.h"
245 #include "hudtarget.h"
247 #include "hudsquadmsg.h"
248 #include "controlsconfig.h"
251 #include "missionparse.h"
253 #include "linklist.h"
254 #include "missionlog.h"
255 #include "missionmessage.h"
256 #include "hudtarget.h"
259 #include "missionparse.h"
260 #include "multimsgs.h"
261 #include "multiutil.h"
263 #include "hudtargetbox.h"
264 #include "multi_pmsg.h"
265 #include "subsysdamage.h"
268 // defines for different modes in the squad messaging system
270 #define SM_MODE_TYPE_SELECT 1 //am I going to message a ship or a wing
271 #define SM_MODE_SHIP_SELECT 2 //choosing actual ship
272 #define SM_MODE_WING_SELECT 3 //choosing actual wing
273 #define SM_MODE_SHIP_COMMAND 4 //which command to send to a ship
274 #define SM_MODE_WING_COMMAND 5 //which command to send to a wing
275 #define SM_MODE_REINFORCEMENTS 6 //call for reinforcements
276 #define SM_MODE_REPAIR_REARM 7 //repair/rearm player ship
277 #define SM_MODE_REPAIR_REARM_ABORT 8 //abort repair/rearm of player ship
278 #define SM_MODE_ALL_FIGHTERS 9 //message all fighters/bombers
280 #define DEFAULT_MSG_TIMEOUT (8 * 1000) // number of seconds * 1000 to get milliseconds
281 #define MSG_KEY_EAT_TIME (300)
283 LOCAL int Squad_msg_mode; // current mode that the messaging system is in
284 LOCAL int Msg_key_used; // local variable which tells if the key being processed
285 // with the messaging system was actually used
286 LOCAL int Msg_key; // global which indicates which key was currently pressed
287 LOCAL int Msg_mode_timestamp;
288 LOCAL int Msg_instance; // variable which holds ship/wing instance to send the message to
289 LOCAL int Msg_shortcut_command; // holds command when using a shortcut key
290 LOCAL int Msg_target_objnum; // id of the current target of the player
291 LOCAL ship_subsys *Msg_targeted_subsys;// pointer to current subsystem which is targeted
293 LOCAL int Msg_enemies; // tells us whether or not to message enemy ships or friendlies
296 LOCAL int Msg_eat_key_timestamp; // used to temporarily "eat" keys
298 // defined to position the messaging box
299 int Mbox_item_h[GR_NUM_RESOLUTIONS] = {
303 int Mbox_item_xoffset[GR_NUM_RESOLUTIONS] = {
308 // top of the message box gauge
309 int Mbox_top_coords[GR_NUM_RESOLUTIONS][2] = {
318 int Mbox_bmap_coords[GR_NUM_RESOLUTIONS][2] = {
327 // squadmsg menu pgup and pgdn
328 int Menu_pgup_coords[GR_NUM_RESOLUTIONS][2] = {
336 int Menu_pgdn_coords[GR_NUM_RESOLUTIONS][2] = {
346 // following defines/vars are used to build menus that are used in messaging mode
348 typedef struct mmode_item {
349 int instance; // instance in Ships/Wings array of this menu item
350 int active; // active items are in bold text -- inactive items greyed out
351 char text[NAME_LENGTH]; // text to display on the menu
354 #define MAX_MENU_ITEMS 50 // max number of items in the menu
355 #define MAX_MENU_DISPLAY 10 // max number that can be displayed
357 mmode_item MsgItems[MAX_MENU_ITEMS];
358 int Num_menu_items = -1; // number of items for a message menu
359 int First_menu_item= -1; // index of first item in the menu
362 // following set of vars/defines are used to store/restore key bindings for keys that
363 // are used in messaging mode
365 // array to temporarily store key bindings that will be in use for the messaging
367 typedef struct key_store {
368 int option_num; // which element in the Control_config array is this
369 int id; // which id (1 or 2) is this key.
370 int key_value; // which key value to put there.
373 #define MAX_KEYS_NO_SCROLL 10
374 #define MAX_KEYS_USED 12 // maximum number of keys used for the messaging system
376 key_store key_save[MAX_KEYS_USED]; // array to save the key information during messaging mode
377 int num_keys_saved = 0; // number of keys that are saved.
379 // next array is the array of MAX_KEYS_USED size which are the keys to use for messaging mode
381 int keys_used[] = { SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5, SDLK_6, SDLK_7, SDLK_8, SDLK_9, SDLK_0,
382 SDLK_PAGEUP, SDLK_PAGEDOWN };
387 // following are defines and character strings that are used as part of messaging mode
389 #define TYPE_SHIP_ITEM 0
390 #define TYPE_WING_ITEM 1
391 #define TYPE_ALL_FIGHTERS_ITEM 2
392 #define TYPE_REINFORCEMENT_ITEM 3
393 #define TYPE_REPAIR_REARM_ITEM 4
394 #define TYPE_REPAIR_REARM_ABORT_ITEM 5
396 #define NUM_TYPE_SELECT 6
398 const char *type_select_str(int n)
400 #if NUM_TYPE_SELECT != 6
401 #error type_select_Str is not up to date
406 return XSTR( "Ships", 293);
408 return XSTR( "Wings", 294);
409 case TYPE_ALL_FIGHTERS_ITEM:
410 return XSTR( "All Fighters", 295);
411 case TYPE_REINFORCEMENT_ITEM:
412 return XSTR( "Reinforcements", 296);
413 case TYPE_REPAIR_REARM_ITEM:
414 return XSTR( "Rearm/Repair Subsys", 297);
415 case TYPE_REPAIR_REARM_ABORT_ITEM:
416 return XSTR( "Abort Rearm", 298);
422 // data structure to hold character string of commands for comm menu
423 typedef struct comm_order {
424 int value; // used to match which command to display on the menu
427 // note: If you change this table at all, keep it in sync with version in IgnoreOrdersDlg.cpp
428 // Also make sure you update comm_order_menu_text below this.
429 // Also make sure you update MAX_SHIP_ORDERS in HUDsquadmsg.h
430 comm_order Comm_orders[MAX_SHIP_ORDERS] = {
431 { ATTACK_TARGET_ITEM },
432 { DISABLE_TARGET_ITEM },
433 { DISARM_TARGET_ITEM },
434 { DISABLE_SUBSYSTEM_ITEM },
435 { PROTECT_TARGET_ITEM },
436 { IGNORE_TARGET_ITEM },
439 { ENGAGE_ENEMY_ITEM },
440 { CAPTURE_TARGET_ITEM },
441 { REARM_REPAIR_ME_ITEM },
442 { ABORT_REARM_REPAIR_ITEM },
446 // Text to display on the menu
447 // Given an index into the Comm_orders array, return the text associated with it.
448 // MUST BE 1:1 with Comm_orders.
449 const char *comm_order_menu_text(int index)
452 case 0: return XSTR( "Destroy my target", 299); break;
453 case 1: return XSTR( "Disable my target", 300); break;
454 case 2: return XSTR( "Disarm my target", 301); break;
455 case 3: return XSTR( "Destroy subsystem", 302); break;
456 case 4: return XSTR( "Protect my target", 303); break;
457 case 5: return XSTR( "Ignore my target", 304); break;
458 case 6: return XSTR( "Form on my wing", 305); break;
459 case 7: return XSTR( "Cover me", 306); break;
460 case 8: return XSTR( "Engage enemy", 307); break;
461 case 9: return XSTR( "Capture my target", 308); break;
462 case 10: return XSTR( "Rearm me", 309); break;
463 case 11: return XSTR( "Abort rearm", 310); break;
464 case 12: return XSTR( "Depart", 311); break;
471 // Text to display on the messaging menu when using the shortcut keys
472 const char *comm_order_hotkey_text( int index )
476 for (i = 0; i < MAX_SHIP_ORDERS; i++ ) {
477 if ( Comm_orders[i].value == index )
478 return comm_order_menu_text(i);
485 // a define of who can receive message
486 #define CAN_MESSAGE (SIF_FIGHTER | SIF_BOMBER | SIF_CRUISER | SIF_FREIGHTER | SIF_TRANSPORT | SIF_CAPITAL | SIF_SUPPORT | SIF_SUPERCAP | SIF_DRYDOCK | SIF_GAS_MINER | SIF_AWACS | SIF_CORVETTE)
488 int squadmsg_history_index = 0;
489 squadmsg_history Squadmsg_history[SQUADMSG_HISTORY_MAX];
491 // used for Message box gauge
492 #define NUM_MBOX_FRAMES 3
494 static hud_frames Mbox_gauge[NUM_MBOX_FRAMES];
495 static int Mbox_frames_loaded = 0;
496 static const char *Mbox_fnames[GR_NUM_RESOLUTIONS][NUM_MBOX_FRAMES] =
500 "message1", // top part of menu
501 "message2", // middle part
502 "message3" // bottom part
505 "message1", // top part of menu
506 "message2", // middle part
507 "message3" // bottom part
512 static int Mbox_title_coord[GR_NUM_RESOLUTIONS][2] = {
520 static int Mbox_item_coord[GR_NUM_RESOLUTIONS][2] = {
529 // define for trapping messages send to "all fighters"
530 #define MESSAGE_ALL_FIGHTERS -999
532 // forward declarations
533 void hud_add_issued_order(const char *name, int order, const char *target);
534 int hud_squadmsg_is_target_order_valid(int order, int find_order, ai_info *aip = NULL );
535 int hud_squadmsg_ship_order_valid( int shipnum, int order );
537 // function to set up variables needed when messaging mode is started
538 void hud_squadmsg_start()
542 //if ( num_keys_saved < 0 ) // save the keys if they haven't been saved yet
543 hud_squadmsg_save_keys();
548 for (i=0; i<num_keys_saved; i++)
549 clear_key_binding ( (short) key_save[i].key_value ); // removes all mention of this key from Control_config
552 Num_menu_items = -1; // reset the menu items
554 Squad_msg_mode = SM_MODE_TYPE_SELECT; // start off at the base state
555 Msg_mode_timestamp = timestamp(DEFAULT_MSG_TIMEOUT); // initialize our timer to bogus value
556 Msg_shortcut_command = -1; // assume no shortcut key being used
557 Msg_target_objnum = Player_ai->target_objnum; // save the players target object number
558 Msg_targeted_subsys = Player_ai->targeted_subsys; // save the players currently targted subsystem
560 Msg_enemies = 0; // tells us if we are messaging enemy ships
563 snd_play( &Snds[SND_SQUADMSGING_ON] );
566 // functions which will restore all of the key binding stuff when messaging mode is done
567 void hud_squadmsg_end()
573 // move through all keys saved and restore their orignal values.
574 for ( i=0; i<num_keys_saved; i++ ) {
576 Control_config[ksp->option_num].key_id = (short) ksp->key_value;
580 if ( message_is_playing() == FALSE )
581 snd_play( &Snds[SND_SQUADMSGING_OFF] );
584 // function which returns true if there are fighters/bombers on the players team
586 int hud_squadmsg_count_fighters( )
593 // set up the team to compare for messaging. In debug versions, we will allow messaging to enemies
594 //team = TEAM_FRIENDLY;
595 team = Player_ship->team;
598 team = opposing_team_mask(Player_ship->team);
602 for ( objp = GET_FIRST(&obj_used_list); objp != END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp) ) {
603 if ( objp->type != OBJ_SHIP )
606 shipp = &Ships[objp->instance];
607 // check fighter is accepting orders
608 if (shipp->orders_accepted != 0) {
609 // be sure ship is on correct team, not the player, and is a fighter/bomber
610 if ( (shipp->team == team) && (objp != Player_obj) && (Ship_info[shipp->ship_info_index].flags & (SIF_FIGHTER | SIF_BOMBER)) ) {
620 // function which counts the number of ships available for messaging. Used to determine if
621 // we should grey out a menu or allow a shortcut command to apply. parameter "flag" is used
622 // to tell us whether or not we should add the ship to a menu item or not. We include the
623 // flag so that we don't have to have conditions for messaging ships/wings in two places.
624 int hud_squadmsg_count_ships( int add_to_menu )
631 // set up the team to compare for messaging. In debug versions, we will allow messaging to enemies
632 //team = TEAM_FRIENDLY;
633 team = Player_ship->team;
636 team = opposing_team_mask(Player_ship->team);
640 for ( so = GET_FIRST(&Ship_obj_list); so != END_OF_LIST(&Ship_obj_list); so = GET_NEXT(so) ) {
642 shipp = &Ships[Objects[so->objnum].instance];
643 Assert ( shipp->objnum != -1 );
645 // ships must be able to receive a message
646 if ( !(Ship_info[shipp->ship_info_index].flags & CAN_MESSAGE) )
649 // must be on the same team
650 if ( shipp->team != team )
653 // departing or dying ships cannot be on list
654 if ( shipp->flags & (SF_DEPARTING|SF_DYING) )
657 // MULTI - changed to allow messaging of netplayers
659 // cannot be my ship or an instructor
660 if ( (&Objects[so->objnum] == Player_obj) || is_instructor(&Objects[so->objnum]) )
663 // ship must be accepting ship type orders
664 if ( shipp->orders_accepted == 0)
667 // if it is a player ship, we must be in multiplayer
668 if ( (Objects[so->objnum].flags & OF_PLAYER_SHIP) && !(Game_mode & GM_MULTIPLAYER) )
671 // if a messaging shortcut, be sure this ship can process the order
672 if ( Msg_shortcut_command != -1 ) {
673 if ( !(shipp->orders_accepted & Msg_shortcut_command) )
675 else if ( !hud_squadmsg_ship_order_valid(Objects[so->objnum].instance, Msg_shortcut_command) )
681 Assert ( Num_menu_items < MAX_MENU_ITEMS );
682 strcpy( MsgItems[Num_menu_items].text, shipp->ship_name );
683 MsgItems[Num_menu_items].instance = SHIP_INDEX(shipp);
684 MsgItems[Num_menu_items].active = 1;
690 // if adding to the menu and we have > 10 items, then don't allow page up and page down to be used.
691 if ( add_to_menu && (Num_menu_items > MAX_MENU_DISPLAY) )
692 hud_squadmsg_save_keys(1);
696 // routine to return true if a wing should be put onto the messaging menu
697 int hud_squadmsg_wing_valid( wing *wingp, int team )
699 // int player_count, j;
701 // a couple of special cases to account for before adding to count (or to menu). The wing gone
702 // flags is firm indication to skip this particular wing. Also, skip if enemy wing
703 if ( (wingp->flags & WF_WING_GONE) || (wingp->current_count == 0) )
706 // departing wings don't get attention either
707 if ( wingp->flags & WF_WING_DEPARTING )
710 // sanity check on ship_index field -- if check is successful, then check the team.
711 Assert (wingp->ship_index[0] != -1 );
712 if ( Ships[wingp->ship_index[0]].team != team )
715 // if this wing is the players wing, and there is only one ship in the wing, then skip past it
716 if ( (Ships[Player_obj->instance].wingnum == WING_INDEX(wingp)) && (wingp->current_count == 1) )
719 // check if wing commander is accepting orders
720 if ( Ships[wingp->ship_index[0]].orders_accepted == 0)
723 // if doing a message shortcut is being used, be sure the wing can "accept" the command. Only need
724 // to look at the first ship in the wing.
725 if ( Msg_shortcut_command != -1 ) {
726 if ( !(Ships[wingp->ship_index[0]].orders_accepted & Msg_shortcut_command) )
729 // MULTI - changed to allow messaging of netplayers
730 // don't count wings where all ships are player ships
733 for ( j = 0; j < wingp->current_count; j++ ) {
734 if ( Objects[Ships[wingp->ship_index[j]].objnum].flags & OF_PLAYER_SHIP )
737 if ( player_count == wingp->current_count )
744 // function like above, except for wings
745 int hud_squadmsg_count_wings( int add_to_menu )
750 // set up the team to compare for messaging. In debug versions, we will allow messaging to enemies
751 //team = TEAM_FRIENDLY;
752 team = Player_ship->team;
755 team = opposing_team_mask(Player_ship->team);
760 // add the player starting wings first
761 for ( i = 0; i < MAX_STARTING_WINGS; i++ ) {
764 wingnum = Starting_wings[i];
768 if ( hud_squadmsg_wing_valid(&Wings[wingnum], team) ) {
771 Assert ( Num_menu_items < MAX_MENU_ITEMS );
772 strcpy( MsgItems[Num_menu_items].text, Wings[wingnum].name );
773 MsgItems[Num_menu_items].instance = wingnum;
774 MsgItems[Num_menu_items].active = 1;
780 for ( i = 0; i < num_wings; i++ ) {
781 // if this wing is a player starting wing, skip it since we added it above
782 for ( j = 0; j < MAX_STARTING_WINGS; j++ ) {
783 if ( i == Starting_wings[j] )
786 if ( j < MAX_STARTING_WINGS )
789 if ( hud_squadmsg_wing_valid(&Wings[i], team) ) {
792 Assert ( Num_menu_items < MAX_MENU_ITEMS );
793 strcpy( MsgItems[Num_menu_items].text, Wings[i].name );
794 MsgItems[Num_menu_items].instance = i;
795 MsgItems[Num_menu_items].active = 1;
804 // function to set the current submode in message mode -- also resets variables that
805 // should be reset inbetween submodes
806 void hud_squadmsg_do_mode( int mode )
808 Squad_msg_mode = mode;
813 void hud_squadmsg_page_down()
815 if ( (First_menu_item + MAX_MENU_DISPLAY) < Num_menu_items ) {
816 First_menu_item += MAX_MENU_DISPLAY;
817 Assert ( First_menu_item < Num_menu_items );
821 void hud_squadmsg_page_up()
823 if ( First_menu_item > 0 ) {
824 First_menu_item -= MAX_MENU_DISPLAY;
825 Assert (First_menu_item >= 0 );
829 int hud_squadmsg_get_total_keys()
833 num_keys_used = MAX_KEYS_NO_SCROLL;
834 if ( Num_menu_items > MAX_MENU_DISPLAY )
835 num_keys_used = MAX_KEYS_USED;
837 return num_keys_used;
840 // function called from high level keyboard read code to give the squadmsg code a key.
841 // return 1 is the key was used by the messaging code, 0 otherwise
842 int hud_squadmsg_read_key( int k )
844 int i, key_found, num_keys_used;
846 num_keys_used = hud_squadmsg_get_total_keys();
848 if ( !(Player->flags & PLAYER_FLAGS_MSG_MODE) ) {
849 // check to see if any messaging keys are still down for some length of time
850 // after messaging is over. Return true for a while.
851 if ( !timestamp_elapsed(Msg_eat_key_timestamp) ) {
852 for (i = 0; i < num_keys_used; i++ ) {
853 if ( key_pressed(keys_used[i]) )
862 for (i = 0; i < num_keys_used; i++ ) {
863 if ( k == keys_used[i] ) {
864 if ( key_down_count(k) ) {
869 if ( key_pressed(k) ) {
873 // key_down_count(k);
884 // function which reads the keyboard array and determines if a menu key has been hit
885 int hud_squadmsg_get_key()
887 int k, i, num_keys_used;
895 num_keys_used = hud_squadmsg_get_total_keys();
897 // if the emp effect is active, never accept keypresses
898 if(emp_active_local()){
902 for ( i = 0; i < num_keys_used; i++ ) {
903 if ( k == keys_used[i] ) {
904 Msg_key_used = 1; // this variable will extend the timer
906 // use a timestamp to prevent top level key code from possibly reprocessing this key
907 Msg_eat_key_timestamp = timestamp(MSG_KEY_EAT_TIME);
908 if ( k == SDLK_PAGEDOWN ) { // pageup and pagedown scroll the menu -- deal with these seperately!!
909 hud_squadmsg_page_down();
911 } else if ( k == SDLK_PAGEUP ) {
912 hud_squadmsg_page_up();
914 } else if ( k == SDLK_ESCAPE ) {
915 hud_squadmsg_toggle();
917 } else if ( (i < Num_menu_items) && (Squad_msg_mode == SM_MODE_REINFORCEMENTS) ) // return any key if selecting reinforcement
920 // play general fail sound if inactive item hit.
921 else if ( (i < Num_menu_items) && !(MsgItems[i].active) )
922 gamesnd_play_iface(SND_GENERAL_FAIL);
924 else if ( (i < Num_menu_items) && (MsgItems[i].active) ) // only return keys that are associated with menu items
928 Msg_key_used = 0; // if no #-key pressed for visible item, break and allow timer to
929 break; // to continue as if no key was pressed
937 // function which will essentially print out the contents of the current state of the messaging
938 // menu. Parameters will be a title. The menu items and the number of items will be
939 // in global vars since they don't get recomputed every frame.
940 void hud_squadmsg_display_menu( const char *title )
942 int bx, by, sx, sy, i, nitems, none_valid, messaging_allowed;
944 // hud_set_bright_color();
945 hud_set_gauge_color(HUD_MESSAGE_BOX, HUD_C_BRIGHT);
947 gr_string(Mbox_title_coord[gr_screen.res][0], Mbox_title_coord[gr_screen.res][1], title);
950 if ( Num_menu_items < MAX_MENU_DISPLAY )
951 nitems = Num_menu_items;
953 if ( First_menu_item == 0 ) // First_menu_item == 0 means first page of items
954 nitems = MAX_MENU_DISPLAY;
955 else if ( (Num_menu_items - First_menu_item) <= MAX_MENU_DISPLAY ) // check if remaining items fit on one page
956 nitems = Num_menu_items - First_menu_item;
958 nitems = MAX_MENU_DISPLAY;
962 sx = Mbox_item_coord[gr_screen.res][0];
963 sy = Mbox_item_coord[gr_screen.res][1];
964 bx = Mbox_bmap_coords[gr_screen.res][0]; // global x-offset where bitmap gets drawn
965 by = Mbox_bmap_coords[gr_screen.res][1]; // global y-offset where bitmap gets drawn
967 none_valid = 1; // variable to tell us whether all items in the menu are valid or not
969 // use another variable to tell us whether we can message or not.
970 messaging_allowed = 1;
971 if ( (Game_mode & GM_MULTIPLAYER) && !multi_can_message(Net_player) ){
972 messaging_allowed = 0;
975 for ( i = 0; i < nitems; i++ ) {
977 char *text = MsgItems[First_menu_item+i].text;
979 // blit the background
980 // hud_set_default_color();
981 hud_set_gauge_color(HUD_MESSAGE_BOX);
982 if ( Mbox_gauge[1].first_frame >= 0 ) {
983 GR_AABITMAP(Mbox_gauge[1].first_frame, bx, by);
985 by += Mbox_item_h[gr_screen.res];
987 // set the text color
988 if ( MsgItems[First_menu_item+i].active ) {
989 // hud_set_bright_color();
990 hud_set_gauge_color(HUD_MESSAGE_BOX, HUD_C_BRIGHT);
993 dim_index = min(5, HUD_color_alpha - 2);
994 if ( dim_index < 0 ) {
997 gr_set_color_fast(&HUD_color_defaults[dim_index]);
1000 hud_set_gauge_color(HUD_MESSAGE_BOX, HUD_C_DIM);
1003 // first do the number
1004 item_num = (i+1) % MAX_MENU_DISPLAY;
1005 emp_hud_printf(sx, sy, EG_SQ1 + i, NOX("%1d."), item_num );
1008 emp_hud_string(sx+Mbox_item_xoffset[gr_screen.res], sy, EG_SQ1 + i, text);
1010 sy += Mbox_item_h[gr_screen.res];
1012 // if we have at least one item active, then set the variable so we don't display any
1013 // message about no active items
1014 if ( MsgItems[First_menu_item+i].active )
1018 // maybe draw an extra line in to make room for [pgdn], or for the 'no active items'
1020 if ( !messaging_allowed || none_valid || ((First_menu_item + nitems) < Num_menu_items) || (Msg_shortcut_command != -1) ) {
1021 // blit the background
1022 // hud_set_default_color();
1023 hud_set_gauge_color(HUD_MESSAGE_BOX);
1024 if ( Mbox_gauge[1].first_frame >= 0 ) {
1026 GR_AABITMAP(Mbox_gauge[1].first_frame, bx, by);
1028 by += Mbox_item_h[gr_screen.res];
1031 // draw the bottom of the frame
1032 // hud_set_default_color();
1033 hud_set_gauge_color(HUD_MESSAGE_BOX);
1034 if ( Mbox_gauge[2].first_frame >= 0 ) {
1036 GR_AABITMAP(Mbox_gauge[2].first_frame, bx, by);
1039 // determine if we should put the text "[more]" at top or bottom to indicate you can page up or down
1040 hud_targetbox_start_flash(TBOX_FLASH_SQUADMSG);
1041 hud_targetbox_maybe_flash(TBOX_FLASH_SQUADMSG);
1042 if ( First_menu_item > 0 ) {
1043 gr_printf( Menu_pgup_coords[gr_screen.res][0], Menu_pgup_coords[gr_screen.res][1], XSTR( "[pgup]", 312) );
1046 if ( (First_menu_item + nitems) < Num_menu_items ) {
1047 gr_printf( Menu_pgdn_coords[gr_screen.res][0], Menu_pgdn_coords[gr_screen.res][1], XSTR( "[pgdn]", 313));
1050 if ( messaging_allowed ) {
1052 gr_printf( sx, by - Mbox_item_h[gr_screen.res] + 2, XSTR( "No valid items", 314));
1053 } else if ( !none_valid && (Msg_shortcut_command != -1) ){
1054 gr_printf( sx, by - Mbox_item_h[gr_screen.res] + 2, "%s", comm_order_hotkey_text(Msg_shortcut_command));
1057 // if this player is not allowed to message, then display message saying so
1058 gr_printf( sx, by - Mbox_item_h[gr_screen.res] + 2, XSTR( "Not allowed to message", 315));
1063 // function to return true or false if the given ship can rearm, or be repaired
1064 int hud_squadmsg_can_rearm( ship *shipp )
1066 // player ships which turns traitor cannot rearm
1067 if ( (shipp == Player_ship) && (Player_ship->team == TEAM_TRAITOR) )
1070 // 5/6/98 -- MWA Decided to always be able to call in support.
1074 // calls for repair/rearm of the player ship. Checks for the presense of the support
1075 // ship and does the appropriate action if found
1076 void hud_squadmsg_repair_rearm( int toggle_state, object *objp)
1081 int multi_player_num;
1083 // this is essentially a check for multiplayer server/client mode
1084 // in multiplayer mode, the server may have to issue this command when received from a client
1087 multi_player_num = -1;
1090 multi_player_num = multi_find_player_by_object(objp);
1091 Assert(multi_player_num != -1);
1094 // see if player is already scheduled on arriving support ship. If so, issues appripriate
1096 if ( is_support_allowed(tobj) ) {
1097 if ( mission_is_repair_scheduled( tobj ) ) {
1098 message_send_builtin_to_player( MESSAGE_REARM_ON_WAY, NULL, MESSAGE_PRIORITY_NORMAL, MESSAGE_TIME_SOON, 0, 0, multi_player_num, -1 );
1100 robjnum = hud_support_find_closest(OBJ_INDEX(tobj));
1101 if ( robjnum != -1 ) {
1102 message_send_builtin_to_player( MESSAGE_REARM_ON_WAY, &Ships[Objects[robjnum].instance], MESSAGE_PRIORITY_NORMAL, MESSAGE_TIME_SOON, 0, 0, multi_player_num, -1 );
1104 // request a rearm. Next function returns -1 if ship is warping in, objnum of repair ship otherwise
1105 robjnum = ai_issue_rearm_request( tobj );
1106 if ( robjnum != -1) {
1107 robjp = &Objects[robjnum];
1108 message_send_builtin_to_player( MESSAGE_ON_WAY, &Ships[robjp->instance], MESSAGE_PRIORITY_NORMAL, MESSAGE_TIME_SOON, 0, 0, multi_player_num, -1 );
1111 // if we are in this part of the if statment, a support ship has been warped in to
1112 // service us. Issue appropriate message
1113 message_send_builtin_to_player( MESSAGE_REARM_WARP, NULL, MESSAGE_PRIORITY_NORMAL, MESSAGE_TIME_SOON, 0, 0, multi_player_num, -1 );
1116 mission_log_add_entry(LOG_PLAYER_REARM, Ships[tobj->instance].ship_name, NULL);
1121 //if ( multi_player_num == -1 ) // only do the hud display if it is for me!
1122 // hud_support_view_start();
1125 hud_squadmsg_toggle(); // take us out of message mode
1128 // function which gets called from keyboard code to issues a shortcut command for rearming.
1129 void hud_squadmsg_rearm_shortcut()
1131 if ( !hud_squadmsg_can_rearm(Player_ship) )
1134 // multiplayer clients need to send this message to the server
1135 if ( MULTIPLAYER_CLIENT ) {
1136 send_player_order_packet(SQUAD_MSG_SHIP, 0, REARM_REPAIR_ME_ITEM);
1140 hud_squadmsg_repair_rearm(0);
1143 // code which is called when a player aborts his rearm request
1144 void hud_squadmsg_repair_rearm_abort( int toggle_state, object *obj)
1150 // this is essentially a check for multiplayer server/client mode
1151 // in multiplayer mode, the server may have to issue this command when received from a client
1157 // try to abort the request. We shoudln't be in this function unless we are actually
1158 // queued for repair. Send a message from support ship if the support ship is in the mission
1159 ai_abort_rearm_request( tobj );
1161 // move the next statements outside of the above if-statement. Seems like this place
1162 // is the right place, since we want to change state of the messaging system regardless
1163 // of what happened above.
1165 hud_squadmsg_toggle(); // take us out of message mode
1168 // returns 1 if an order is valid for a ship. Applies to things like departure when engines are blown, etc.
1169 int hud_squadmsg_ship_order_valid( int shipnum, int order )
1171 // disabled ships can't depart.
1172 if ( (order == DEPART_ITEM) && (Ships[shipnum].flags & SF_DISABLED) )
1178 // returns true or false if the Players target is valid for the given order
1179 // find_order is true when we need to search the comm_orders array for the order entry. We have
1180 // to do this action in some cases since all we know is the actual "value" of the order
1181 int hud_squadmsg_is_target_order_valid(int order, int find_order, ai_info *aip )
1183 int target_objnum, i;
1184 ship *shipp, *ordering_shipp;
1190 // find the comm_menu item for this command
1192 for (i = 0; i < MAX_SHIP_ORDERS; i++ ) {
1193 if ( Comm_orders[i].value == order )
1196 Assert( i < MAX_SHIP_ORDERS );
1200 // orders which don't operate on targets are always valid
1201 if ( !(Comm_orders[order].value & TARGET_MESSAGES) )
1204 target_objnum = aip->target_objnum;
1206 // order isn't valid if there is no player target
1207 if ( target_objnum == -1 ) {
1211 objp = &Objects[target_objnum];
1213 ordering_shipp = &Ships[aip->shipnum];
1215 // target isn't a ship, then return 0
1216 if ( (objp->type != OBJ_SHIP) && (objp->type != OBJ_WEAPON) )
1219 // if it's a weapon, then it needs to be a WIF_BOMB weapon. Only attack order valid, and only
1220 // valid on bombs not on the player's team
1221 if ( objp->type == OBJ_WEAPON ) {
1222 if ( (Comm_orders[order].value == ATTACK_TARGET_ITEM )
1223 && (Weapon_info[Weapons[objp->instance].weapon_info_index].wi_flags & WIF_BOMB)
1224 && (Weapons[objp->instance].team != ordering_shipp->team) )
1231 Assert( objp->type == OBJ_SHIP );
1233 shipp = &Ships[objp->instance];
1235 // if target is a navbouy, return 0
1236 if ( Ship_info[shipp->ship_info_index].flags & SIF_NAVBUOY ){
1240 // if we are messaging a ship, and that ship is our target, no target type orders are ever active
1241 if ( (Squad_msg_mode == SM_MODE_SHIP_COMMAND) && (target_objnum == Msg_instance) ){
1245 // if the order is a disable order or depart, and the ship is disabled, order isn't active
1246 if ( (Comm_orders[order].value == DISABLE_TARGET_ITEM) && (shipp->flags & SF_DISABLED) ){
1250 // same as above except for disabled.
1251 if ( (Comm_orders[order].value == DISARM_TARGET_ITEM) && ((shipp->subsys_info[SUBSYSTEM_TURRET].num > 0) && (shipp->subsys_info[SUBSYSTEM_TURRET].current_hits == 0.0f)) ){
1255 // if order is disable subsystem, and no subsystem targeted or no hits, then order not valid
1256 if ( (Comm_orders[order].value == DISABLE_SUBSYSTEM_ITEM) && ((aip->targeted_subsys == NULL) || (aip->targeted_subsys->current_hits <= 0.0f)) ){
1260 // check based on target's and player's team
1261 if ( (shipp->team == ordering_shipp->team) && (Comm_orders[order].value & FRIENDLY_TARGET_MESSAGES) ){
1263 } else if ( (shipp->team != ordering_shipp->team) && (Comm_orders[order].value & ENEMY_TARGET_MESSAGES) ){
1270 // function to send an order to all fighters/bombers.
1271 void hud_squadmsg_send_to_all_fighters( int command, int player_num )
1274 ship *shipp, *ordering_shipp;
1275 int i, send_message, to_everyone, do_ship;
1278 // quick short circuit here because of actually showing comm menu even though you cannot message.
1279 // just a safety net.
1280 if ( (Game_mode & GM_MULTIPLAYER) && (player_num != -1) ) {
1281 if ( !multi_can_message(&Net_players[player_num]) ) {
1286 // check for multiplayer mode
1287 if((Game_mode & GM_MULTIPLAYER) && !(Net_player->flags & NETINFO_FLAG_AM_MASTER)) {
1288 send_player_order_packet(SQUAD_MSG_ALL, 0, command);
1292 // to_everyone tells us whether the command should apply to all ships, or just to fighets/bombers.
1293 // when true, command goes to *all* friendlies.
1294 send_message = 1; // internal flag to dictate who sends message
1299 if ( player_num != -1 )
1300 aip = &Ai_info[Ships[Objects[Net_players[player_num].player->objnum].instance].ai_index];
1302 Assert( aip->shipnum != -1 );
1303 ordering_shipp = &Ships[aip->shipnum];
1305 if ( command == IGNORE_TARGET_ITEM ) {
1307 // if we were messaging a ship directly, set flag to send no messages. We will send one
1308 // specifically from the ship player is ordering
1309 if ( (Msg_instance != MESSAGE_ALL_FIGHTERS) && (Squad_msg_mode == SM_MODE_SHIP_COMMAND) ) {
1315 for ( i = 0; i < num_wings; i++ ) {
1318 if ( (Wings[i].flags & WF_WING_GONE) || (Wings[i].current_count == 0) )
1321 if ( Wings[i].flags & WF_WING_DEPARTING )
1324 // get the first ship on the wing list and look at it's team and then it's type
1325 shipnum = Wings[i].ship_index[0];
1326 Assert( shipnum != -1 );
1327 shipp = &Ships[shipnum];
1329 // can't message if not on players team
1330 if ( shipp->team != ordering_shipp->team )
1333 // can't message if ship not fighter/bomber if the command isn't to everyone.
1334 if ( !to_everyone && !(Ship_info[shipp->ship_info_index].flags & (SIF_FIGHTER | SIF_BOMBER)) )
1337 // don't send the command if the "wing" won't accept the command. We do this by looking at
1338 // the set of orders accepted for the first ship in the wing.
1339 if ( !(command & shipp->orders_accepted) )
1342 // send the command to the wing
1343 if ( Wings[i].current_count > 1 ) {
1344 if ( hud_squadmsg_send_wing_command(i, command, send_message, player_num) ) {
1350 // now find any friendly fighter/bomber ships not in wings
1351 for ( objp = GET_FIRST(&obj_used_list); objp != END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp) ) {
1352 if ( objp->type != OBJ_SHIP )
1355 // don't send messge to ships not on player's team, or that are in a wing.
1356 shipp = &Ships[objp->instance];
1357 if ( (shipp->team != ordering_shipp->team) || (shipp->wingnum != -1) )
1360 // don't send message to non fighter wings
1361 if ( !to_everyone && !(Ship_info[shipp->ship_info_index].flags & (SIF_FIGHTER | SIF_BOMBER)) )
1364 // skip departing/dying ships
1365 if ( shipp->flags & (SF_DEPARTING|SF_DYING) )
1368 // don't send command if ship won't accept if
1369 if ( !(command & shipp->orders_accepted) )
1372 if ( hud_squadmsg_send_ship_command(objp->instance, command, send_message, player_num) ) {
1377 // we might send the ship command again if we are ignoring a target, and the guy
1378 // we ordered directly is a ship -- we want the response to come directly from the
1381 Assert( Msg_instance != MESSAGE_ALL_FIGHTERS );
1382 hud_squadmsg_send_ship_command( Msg_instance, command, 1 );
1386 // Check if any enemy ships are in the mission
1387 int hud_squadmsg_enemies_present()
1392 for ( so = GET_FIRST(&Ship_obj_list); so != END_OF_LIST(&Ship_obj_list); so = GET_NEXT(so) ) {
1393 shipp = &Ships[Objects[so->objnum].instance];
1394 if ( shipp->team != Player_ship->team )
1401 #define OVERRIDE_PROTECT_SHIP_TYPE (SIF_FIGHTER|SIF_BOMBER|SIF_FREIGHTER|SIF_TRANSPORT)
1402 // function which sends a message to a specific ship. This routine can be called from one of two
1403 // places. Either after selecting a ship when using a hotkey, or after selecting a command when
1404 // using the entire messaging menu system
1406 // if local and addr are non-null, it means the function is being called by the (multiplayer) server in response to
1407 // a PLAYER_COMMAND_PACKET
1408 int hud_squadmsg_send_ship_command( int shipnum, int command, int send_message, int player_num )
1411 int ai_mode, ai_submode; // ai mode and submode needed for ship commands
1412 char *target_shipname; // ship number of possible targets
1414 int target_team, ship_team; // team id's for the ship getting message and any target the player has
1415 ship *ordering_shipp;
1417 // quick short circuit here because of actually showing comm menu even though you cannot message.
1418 // just a safety net.
1419 if ( (Game_mode & GM_MULTIPLAYER) && (player_num != -1) ) {
1420 if ( !multi_can_message(&Net_players[player_num]) ) {
1425 // check for multiplayer mode
1426 if((Game_mode & GM_MULTIPLAYER) && !(Net_player->flags & NETINFO_FLAG_AM_MASTER)){
1427 send_player_order_packet(SQUAD_MSG_SHIP, shipnum, command);
1431 ai_mode = AI_GOAL_NONE; // needs to be initialized
1432 ai_submode = -1234567;
1435 if ( player_num != -1 ){
1436 ainfo = &Ai_info[Ships[Objects[Net_players[player_num].player->objnum].instance].ai_index];
1439 Assert( ainfo->shipnum != -1 );
1440 ordering_shipp = &Ships[ainfo->shipnum];
1442 // a shortcut to save on repetitive coding. If the order is a 'target' order, make the default
1443 // mesage be "no target"
1444 message = MESSAGE_NOSIR;
1445 if ( (command & TARGET_MESSAGES) && (ainfo->target_objnum == -1) )
1446 message = MESSAGE_NO_TARGET;
1448 if ( hud_squadmsg_is_target_order_valid(command, 1, ainfo) ) {
1450 target_shipname = NULL;
1452 if ( ainfo->target_objnum != -1) {
1453 if ( Objects[ainfo->target_objnum].type == OBJ_SHIP ) {
1454 if ( ainfo->target_objnum != Ships[shipnum].objnum ) {
1455 target_shipname = Ships[Objects[ainfo->target_objnum].instance].ship_name; // I think this is right
1456 target_team = Ships[Objects[ainfo->target_objnum].instance].team;
1461 Assert ( ainfo->shipnum != -1 );
1462 ship_team = Ships[ainfo->shipnum].team; // team of the ship issuing the message
1464 switch ( command ) { // value of k matches the #defines for ship messages
1465 case ATTACK_TARGET_ITEM:
1466 if ( Objects[ainfo->target_objnum].type == OBJ_SHIP ) {
1467 Assert( target_shipname );
1468 Assert( ship_team != target_team );
1470 // Orders to override protect
1471 if (Ship_info[Ships[Objects[ainfo->target_objnum].instance].ship_info_index].flags & OVERRIDE_PROTECT_SHIP_TYPE) {
1472 Objects[ainfo->target_objnum].flags &= ~OF_PROTECTED;
1475 ai_mode = AI_GOAL_CHASE;
1476 ai_submode = SM_ATTACK;
1477 } else if ( Objects[ainfo->target_objnum].type == OBJ_WEAPON ) {
1478 ai_mode = AI_GOAL_CHASE_WEAPON;
1479 ai_submode = Objects[ainfo->target_objnum].instance; // store the instance of the weapon -- ai goals code will deal with it
1482 message = MESSAGE_ATTACK_TARGET;
1485 case DISABLE_TARGET_ITEM:
1486 Assert( target_shipname );
1487 Assert( ship_team != target_team );
1489 // Orders to override protect
1490 if (Ship_info[Ships[Objects[ainfo->target_objnum].instance].ship_info_index].flags & OVERRIDE_PROTECT_SHIP_TYPE) {
1491 Objects[ainfo->target_objnum].flags &= ~OF_PROTECTED;
1494 ai_mode = AI_GOAL_DISABLE_SHIP;
1495 ai_submode = -SUBSYSTEM_ENGINE;
1496 message = MESSAGE_DISABLE_TARGET;
1499 case DISARM_TARGET_ITEM:
1500 Assert( target_shipname );
1501 Assert( ship_team != target_team );
1503 // Orders to override protect
1504 if (Ship_info[Ships[Objects[ainfo->target_objnum].instance].ship_info_index].flags & OVERRIDE_PROTECT_SHIP_TYPE) {
1505 Objects[ainfo->target_objnum].flags &= ~OF_PROTECTED;
1508 ai_mode = AI_GOAL_DISARM_SHIP;
1509 ai_submode = -SUBSYSTEM_TURRET;
1510 message = MESSAGE_DISARM_TARGET;
1513 case DISABLE_SUBSYSTEM_ITEM:
1514 Assert( target_shipname );
1515 Assert( ship_team != target_team );
1516 Assert( ainfo->targeted_subsys != NULL );
1517 Assert( ainfo->targeted_subsys->current_hits > 0.0f);
1519 // Orders to override protect
1520 if (Ship_info[Ships[Objects[ainfo->target_objnum].instance].ship_info_index].flags & OVERRIDE_PROTECT_SHIP_TYPE) {
1521 Objects[ainfo->target_objnum].flags &= ~OF_PROTECTED;
1524 ai_mode = AI_GOAL_DESTROY_SUBSYSTEM;
1525 ai_submode = ship_get_subsys_index( &Ships[Objects[ainfo->target_objnum].instance], ainfo->targeted_subsys->system_info->subobj_name );
1526 message = MESSAGE_ATTACK_TARGET;
1529 case CAPTURE_TARGET_ITEM:
1530 Assert( target_shipname );
1531 Assert( ship_team != target_team );
1533 Assert(ainfo->target_objnum > -1);
1535 Objects[ainfo->target_objnum].flags |= OF_PROTECTED;
1537 ai_mode = AI_GOAL_DOCK;
1538 ai_submode = AIS_DOCK_0;
1539 message = MESSAGE_DOCK_YES;
1542 case PROTECT_TARGET_ITEM:
1544 // AL 31-3-98: Can't protect self... this can happen if all fighters
1545 // are told to protect another friendly ship
1546 if ( ainfo->target_objnum == Ships[shipnum].objnum ) {
1550 Assert( target_shipname );
1551 Assert( ship_team == target_team );
1553 ai_mode = AI_GOAL_GUARD;
1554 ai_submode = AIS_GUARD_PATROL;
1555 message = MESSAGE_YESSIR;
1558 case IGNORE_TARGET_ITEM:
1559 Assert( target_shipname );
1560 Assert( ship_team != target_team );
1562 ai_mode = AI_GOAL_IGNORE;
1564 message = MESSAGE_YESSIR;
1567 case FORMATION_ITEM:
1568 message = MESSAGE_YESSIR;
1569 target_shipname = ordering_shipp->ship_name;
1570 ai_mode = AI_GOAL_FORM_ON_WING;
1575 ai_mode = AI_GOAL_GUARD;
1576 ai_submode = AIS_GUARD_PATROL;
1577 target_shipname = ordering_shipp->ship_name;
1578 message = MESSAGE_YESSIR;
1581 case ENGAGE_ENEMY_ITEM:
1582 ai_mode = AI_GOAL_CHASE_ANY;
1583 ai_submode = SM_ATTACK;
1584 // if no enemies present, use the affirmative, instead of engaging enemies message
1585 if ( hud_squadmsg_enemies_present() )
1586 message = MESSAGE_YESSIR;
1588 message = MESSAGE_ENGAGE;
1589 target_shipname = NULL;
1593 ai_mode = AI_GOAL_WARP;
1595 message = MESSAGE_WARP_OUT;
1598 // the following are support ship options!!!
1599 case REARM_REPAIR_ME_ITEM:
1600 if((Game_mode & GM_MULTIPLAYER) && (Net_player->flags & NETINFO_FLAG_AM_MASTER) && (player_num != -1) ){
1601 hud_squadmsg_repair_rearm(0,&Objects[Net_players[player_num].player->objnum]);
1603 hud_squadmsg_repair_rearm(0); // note we return right away. repair/rearm code handles messaging, etc
1607 case ABORT_REARM_REPAIR_ITEM:
1608 if((Game_mode & GM_MULTIPLAYER) && (Net_player->flags & NETINFO_FLAG_AM_MASTER) && (player_num != -1) ){
1609 hud_squadmsg_repair_rearm_abort(0,&Objects[Net_players[player_num].player->objnum]);
1611 hud_squadmsg_repair_rearm_abort(0); // note we return right away. repair/rearm code handles messaging, etc
1615 case STAY_NEAR_ME_ITEM:
1616 case STAY_NEAR_TARGET_ITEM: // can't attack anything on same team
1618 // cannot stay near a hostile ship(?)
1619 if ( (command == STAY_NEAR_TARGET_ITEM) && (ship_team != target_team) )
1622 ai_mode = AI_GOAL_STAY_NEAR_SHIP;
1624 message = MESSAGE_YESSIR;
1625 if ( command == STAY_NEAR_ME_ITEM )
1626 target_shipname = ordering_shipp->ship_name;
1629 case KEEP_SAFE_DIST_ITEM:
1630 ai_mode = AI_GOAL_KEEP_SAFE_DISTANCE;
1632 message = MESSAGE_YESSIR;
1636 Int3(); // get Allender -- illegal message
1641 // handle case of messaging one ship. Deal with messaging all fighters next.
1642 if ( ai_mode != AI_GOAL_NONE ) {
1643 Assert(ai_submode != -1234567);
1644 ai_add_ship_goal_player( AIG_TYPE_PLAYER_SHIP, ai_mode, ai_submode, target_shipname, &Ai_info[Ships[shipnum].ai_index] );
1645 if( player_num == -1 )
1646 hud_add_issued_order(Ships[shipnum].ship_name, command, target_shipname);
1650 // if we're in multiplayer mode, and we're the server, determine if this virtual squadmate order should be
1651 // sent to other players in the game as an actual "order"
1652 if((Game_mode & GM_MULTIPLAYER) && (message != MESSAGE_NOSIR)){
1653 // if the multi_msg system processed and sent this order to a player, we should not play a response
1654 if(multi_msg_eval_ship_squadmsg(shipnum,command,ainfo,player_num)){
1659 // this is the _response_
1660 if ( send_message ){
1661 message_send_builtin_to_player( message, &Ships[shipnum], MESSAGE_PRIORITY_NORMAL, MESSAGE_TIME_ANYTIME, 0, 0, player_num, -1 );
1664 return send_message;
1667 // function to send a command to a wing. Like above function, called from one of two places
1669 // if local and addr are non-null, it means the function is being called by the (multiplayer) server in response to
1670 // a PLAYER_COMMAND_PACKET
1672 // returns whether or not a message was sent
1673 int hud_squadmsg_send_wing_command( int wingnum, int command, int send_message, int player_num )
1676 int ai_mode, ai_submode; // ai mode and submode needed for ship commands
1677 char *target_shipname; // ship number of possible targets
1678 int message_sent, message;
1679 int target_team, wing_team; // team for the wing and the player's target
1680 ship *ordering_shipp;
1682 // quick short circuit here because of actually showing comm menu even though you cannot message.
1683 // just a safety net.
1684 if ( (Game_mode & GM_MULTIPLAYER) && (player_num != -1) ) {
1685 if ( !multi_can_message(&Net_players[player_num]) ) {
1690 // check for multiplayer mode
1691 if((Game_mode & GM_MULTIPLAYER) && !(Net_player->flags & NETINFO_FLAG_AM_MASTER)){
1692 send_player_order_packet(SQUAD_MSG_WING, wingnum,command);
1696 ai_mode = AI_GOAL_NONE; // needs to be initialized
1697 ai_submode = -1234567;
1700 if ( player_num != -1 )
1701 ainfo = &Ai_info[Ships[Objects[Net_players[player_num].player->objnum].instance].ai_index];
1703 Assert( ainfo->shipnum != -1 );
1704 ordering_shipp = &Ships[ainfo->shipnum];
1706 // get the shipnum of the ship the player has targeted. Used in enough places to do this just
1707 // once. If the ship targeted is part of the wing that was messages -- bail out!!!
1709 // a shortcut to save on repetative coding
1710 message = MESSAGE_NOSIR;
1711 if ( (command & TARGET_MESSAGES) && (ainfo->target_objnum == -1) )
1712 message = MESSAGE_NO_TARGET;
1714 if ( hud_squadmsg_is_target_order_valid(command, 1, ainfo) ) {
1716 target_shipname = NULL;
1718 if ( ainfo->target_objnum != -1) {
1719 if ( Objects[ainfo->target_objnum].type == OBJ_SHIP ) {
1720 target_shipname = Ships[Objects[ainfo->target_objnum].instance].ship_name; // I think this is right
1721 target_team = Ships[Objects[ainfo->target_objnum].instance].team;
1725 Assert ( ainfo->shipnum != -1 );
1726 Assert ( (wingnum >= 0) && (wingnum < num_wings) );
1728 // get the team for the wing
1729 Assert ( Wings[wingnum].ship_index[0] != -1 );
1730 wing_team = Ships[Wings[wingnum].ship_index[0]].team;
1732 switch ( command ) { // value of k matches the #defines for ship messages
1733 case ATTACK_TARGET_ITEM:
1734 if ( Objects[ainfo->target_objnum].type == OBJ_SHIP ) {
1735 Assert( target_shipname );
1736 Assert( wing_team != target_team );
1737 if ( (Ships[Objects[ainfo->target_objnum].instance].wingnum != -1) && (Ships[Objects[ainfo->target_objnum].instance].wingnum == wingnum) ) {
1738 message = MESSAGE_NOSIR;
1739 ai_mode = AI_GOAL_NONE;
1741 ai_mode = AI_GOAL_CHASE;
1742 ai_submode = SM_ATTACK;
1743 message = MESSAGE_ATTACK_TARGET;
1745 } else if ( Objects[ainfo->target_objnum].type == OBJ_WEAPON ) {
1746 ai_mode = AI_GOAL_CHASE_WEAPON;
1747 ai_submode = Objects[ainfo->target_objnum].instance; // store the instance of the weapon -- ai goals code will deal with it
1748 message = MESSAGE_ATTACK_TARGET;
1754 case DISABLE_TARGET_ITEM:
1755 Assert( target_shipname );
1756 Assert( wing_team != target_team );
1758 ai_mode = AI_GOAL_DISABLE_SHIP;
1759 ai_submode = -SUBSYSTEM_ENGINE;
1760 message = MESSAGE_DISABLE_TARGET;
1763 case DISARM_TARGET_ITEM:
1764 Assert( target_shipname );
1765 Assert( wing_team != target_team );
1767 ai_mode = AI_GOAL_DISARM_SHIP;
1768 ai_submode = -SUBSYSTEM_TURRET;
1769 message = MESSAGE_DISARM_TARGET;
1772 case DISABLE_SUBSYSTEM_ITEM:
1773 Assert( target_shipname );
1774 Assert( wing_team != target_team );
1775 Assert( ainfo->targeted_subsys != NULL );
1776 Assert( ainfo->targeted_subsys->current_hits > 0.0f);
1778 ai_mode = AI_GOAL_DESTROY_SUBSYSTEM;
1779 ai_submode = ship_get_subsys_index( &Ships[Objects[ainfo->target_objnum].instance], ainfo->targeted_subsys->system_info->subobj_name );
1780 message = MESSAGE_ATTACK_TARGET;
1784 case PROTECT_TARGET_ITEM:
1785 Assert( target_shipname );
1786 Assert( wing_team == target_team );
1788 ai_mode = AI_GOAL_GUARD;
1789 ai_submode = AIS_GUARD_PATROL;
1790 message = MESSAGE_YESSIR;
1793 case IGNORE_TARGET_ITEM:
1794 Assert( target_shipname );
1795 Assert( wing_team != target_team );
1797 ai_mode = AI_GOAL_IGNORE;
1798 ai_submode = 0; // actually, a don't care.
1799 message = MESSAGE_YESSIR;
1802 case FORMATION_ITEM:
1803 message = MESSAGE_YESSIR;
1804 target_shipname = ordering_shipp->ship_name;
1805 ai_mode = AI_GOAL_FORM_ON_WING;
1810 ai_mode = AI_GOAL_GUARD;
1811 ai_submode = AIS_GUARD_PATROL;
1812 target_shipname = ordering_shipp->ship_name;
1813 message = MESSAGE_YESSIR;
1816 case ENGAGE_ENEMY_ITEM:
1817 ai_mode = AI_GOAL_CHASE_ANY;
1818 ai_submode = SM_ATTACK;
1819 if ( hud_squadmsg_enemies_present() )
1820 message = MESSAGE_YESSIR;
1822 message = MESSAGE_ENGAGE;
1823 target_shipname = NULL;
1827 ai_mode = AI_GOAL_WARP;
1829 message = MESSAGE_WARP_OUT;
1830 Wings[wingnum].flags |= WF_DEPARTURE_ORDERED;
1833 case REARM_REPAIR_ME_ITEM:
1834 case ABORT_REARM_REPAIR_ITEM:
1835 case STAY_NEAR_ME_ITEM:
1836 case STAY_NEAR_TARGET_ITEM:
1837 case KEEP_SAFE_DIST_ITEM:
1841 Int3(); // get Allender -- illegal message
1846 if ( ai_mode != AI_GOAL_NONE ) {
1847 Assert(ai_submode != -1234567);
1848 ai_add_wing_goal_player( AIG_TYPE_PLAYER_WING, ai_mode, ai_submode, target_shipname, wingnum );
1852 // if we're in multiplayer mode, and we're the server, determine if this virtual squadmate order should be
1853 // sent to other players in the game as an actual "order"
1854 if((Game_mode & GM_MULTIPLAYER) && (message != MESSAGE_NOSIR)){
1855 // if there's at least one ai ship which got the command, let the response come through
1856 if(multi_msg_eval_wing_squadmsg(wingnum,command,ainfo,player_num)){
1861 // this is the _response_
1863 if ( send_message ) {
1866 // get a random ship in the wing to send the message to the player
1867 ship_num = ship_get_random_ship_in_wing( wingnum, SHIP_GET_NO_PLAYERS );
1869 // in multiplayer, its possible that all ships in a wing are players. so we'll just send from a random ship
1871 ship_num = ship_get_random_ship_in_wing(wingnum);
1874 // only send message if ship is found. There appear to be cases where all ships
1875 // in a wing die in the same frame causing the wing to appear valid in the message
1876 // menu, but the get_random_ship* functions won't return dying ships.
1877 if ( ship_num != -1 ) {
1878 message_send_builtin_to_player( message, &Ships[ship_num], MESSAGE_PRIORITY_NORMAL, MESSAGE_TIME_ANYTIME, 0, 0, player_num, -1 );
1883 return message_sent;
1887 // return number of available reinforcements, 0 if none available
1888 int hud_squadmsg_reinforcements_available(int team)
1892 for (i = 0; i < Num_reinforcements; i++) {
1896 if ( Reinforcements[i].num_uses >= Reinforcements[i].uses ){
1901 if ( team != ship_get_reinforcement_team(i) ){
1905 // check the arrival cue sexpression of the ship/wing of this reinforcement. If known
1906 // false, it doesn't count either
1907 if ( (wingnum = wing_name_lookup(Reinforcements[i].name, 1)) != -1 ) {
1908 Assert ( Wings[wingnum].arrival_cue >= 0 );
1909 if ( Sexp_nodes[Wings[wingnum].arrival_cue].value == SEXP_KNOWN_FALSE ){
1915 p_objp = mission_parse_get_arrival_ship( Reinforcements[i].name );
1916 if ( p_objp != NULL ) {
1917 if ( Sexp_nodes[p_objp->arrival_cue].value == SEXP_KNOWN_FALSE ){
1921 Int3(); // allender says bogus! reinforcement should be here since it wasn't a wing!
1931 // function to put up window in upper right to allow for player to select the type
1932 // of entity to select for a message (i.e. a wing or a ship)
1933 void hud_squadmsg_type_select( )
1937 First_menu_item = 0;
1940 for (i=0; i<NUM_TYPE_SELECT; i++ ) {
1941 strcpy( MsgItems[i].text, type_select_str(i) );
1942 MsgItems[i].active = 1; // assume active
1944 Num_menu_items = NUM_TYPE_SELECT;
1947 // check to see if the players team is TEAM_TRAITOR. If so, then he is a "traitor", and will not
1948 // be able to do anything from this menu
1949 if ( Player_ship->team == TEAM_TRAITOR ) {
1950 for (i = 0; i < MAX_MENU_ITEMS; i++ )
1951 MsgItems[i].active = 0;
1955 // based on ship counts, wing counts, shortcut active, grey out possible menu choices
1956 if ( !hud_squadmsg_count_ships(0) )
1957 MsgItems[TYPE_SHIP_ITEM].active = 0;
1959 if ( !hud_squadmsg_count_wings(0) )
1960 MsgItems[TYPE_WING_ITEM].active = 0;
1962 // check to be sure that we have some fighters/bombers on the players team that we
1964 if ( !hud_squadmsg_count_fighters() ){
1965 MsgItems[TYPE_ALL_FIGHTERS_ITEM].active = 0;
1968 if ((Player_ship != NULL) && !hud_squadmsg_reinforcements_available(Player_ship->team)) {
1969 MsgItems[TYPE_REINFORCEMENT_ITEM].active = 0;
1972 MsgItems[TYPE_REPAIR_REARM_ITEM].active = 1; // this item will always be available (I think)
1973 MsgItems[TYPE_REPAIR_REARM_ABORT_ITEM].active = 0;
1976 // If the player ship communications are severely damaged, then the player
1977 // will only be able to call for repair/rearm ships
1979 // also, only allow support ship if this player is not allowed to messaage.
1980 if ( (hud_communications_state(Player_ship) != COMM_OK) || ((Game_mode & GM_MULTIPLAYER) && !multi_can_message(Net_player)) ) {
1981 for ( i = 0; i < MAX_MENU_ITEMS; i++ ){
1982 MsgItems[i].active = 0;
1985 MsgItems[TYPE_REPAIR_REARM_ITEM].active = 1;
1988 // check to see if the player is awaiting repair or being repaired. Active the abort and inactive the repair items
1989 // check to see if the player is scheduled to be repaired by incoming ship
1990 if ( Ai_info[Ships[Player_obj->instance].ai_index].ai_flags & (AIF_AWAITING_REPAIR | AIF_BEING_REPAIRED) ) {
1991 MsgItems[TYPE_REPAIR_REARM_ITEM].active = 0;
1992 MsgItems[TYPE_REPAIR_REARM_ABORT_ITEM].active = 1;
1993 } else if ( mission_is_repair_scheduled(Player_obj) ) {
1994 MsgItems[TYPE_REPAIR_REARM_ITEM].active = 0;
1995 MsgItems[TYPE_REPAIR_REARM_ABORT_ITEM].active = 1;
1998 // if no support available, can't call one in
1999 if ( !is_support_allowed(Player_obj) ) {
2000 MsgItems[TYPE_REPAIR_REARM_ITEM].active = 0;
2001 MsgItems[TYPE_REPAIR_REARM_ABORT_ITEM].active = 0;
2004 // de-activate the rearm/repair item if the player has a full load of missiles and
2005 // all subsystems at full strength. We will only check if this item hasn't been marked
2006 // inactive because of some other reason
2007 if ( MsgItems[TYPE_REPAIR_REARM_ITEM].active ) {
2009 if ( !hud_squadmsg_can_rearm(Player_ship) ){
2010 MsgItems[TYPE_REPAIR_REARM_ITEM].active = 0;
2014 // if using keyboard shortcut, these items are always inactive
2015 if ( Msg_shortcut_command != -1 ) {
2016 MsgItems[TYPE_REPAIR_REARM_ITEM].active = 0;
2017 MsgItems[TYPE_REINFORCEMENT_ITEM].active = 0;
2018 MsgItems[TYPE_REPAIR_REARM_ABORT_ITEM].active = 0;
2022 hud_squadmsg_display_menu( XSTR( "Message What", 316) );
2023 k = hud_squadmsg_get_key();
2024 if ( k != -1 ) { // when k != -1, we have a key that associates with menu item
2025 Assert ( k < Num_menu_items );
2026 if ( k == TYPE_SHIP_ITEM ){
2027 hud_squadmsg_do_mode( SM_MODE_SHIP_SELECT );
2028 } else if ( k == TYPE_WING_ITEM ) {
2029 hud_squadmsg_do_mode( SM_MODE_WING_SELECT );
2030 } else if ( k == TYPE_ALL_FIGHTERS_ITEM ) {
2031 hud_squadmsg_do_mode( SM_MODE_ALL_FIGHTERS );
2034 if ( Msg_shortcut_command == -1 ) {
2035 if ( k == TYPE_REINFORCEMENT_ITEM ) {
2036 hud_squadmsg_do_mode( SM_MODE_REINFORCEMENTS );
2037 player_set_next_all_alone_msg_timestamp();
2038 } else if ( k == TYPE_REPAIR_REARM_ITEM ){
2039 hud_squadmsg_do_mode( SM_MODE_REPAIR_REARM );
2040 } else if ( k == TYPE_REPAIR_REARM_ABORT_ITEM ) {
2041 hud_squadmsg_do_mode( SM_MODE_REPAIR_REARM_ABORT );
2047 // function to display a list of ships to send a command to
2048 void hud_squadmsg_ship_select()
2052 if ( Num_menu_items == -1 ) {
2054 hud_squadmsg_count_ships( 1 );
2057 hud_squadmsg_display_menu( XSTR( "Select Ship", 317) );
2058 k = hud_squadmsg_get_key();
2059 if ( k != -1 ) { // if true, we have selected a ship.
2060 if ( Msg_shortcut_command == -1 ) {
2061 Msg_instance = MsgItems[First_menu_item + k].instance; // store the instance id in a global
2062 hud_squadmsg_do_mode( SM_MODE_SHIP_COMMAND ); // and move to a new mode
2064 // we must convert the Msg_shortcut_command value to a value that the message
2065 // system normally uses to select a command. Since the menu
2066 Assert( Msg_shortcut_command != IGNORE_TARGET_ITEM );
2067 hud_squadmsg_send_ship_command( MsgItems[First_menu_item+k].instance, Msg_shortcut_command, 1 );
2068 hud_squadmsg_toggle();
2074 // function to display a list of ships to send a command to
2075 void hud_squadmsg_wing_select()
2079 if ( Num_menu_items == -1 ) {
2081 hud_squadmsg_count_wings( 1 );
2084 hud_squadmsg_display_menu( XSTR( "Select Wing", 318) );
2085 k = hud_squadmsg_get_key();
2086 if ( k != -1 ) { // if true, we have selected a ship.
2087 if ( Msg_shortcut_command == -1 ) { // do normal menu stuff when no hoykey active
2088 Msg_instance = MsgItems[First_menu_item + k].instance; // store the instance id in a global
2089 hud_squadmsg_do_mode( SM_MODE_WING_COMMAND ); // and move to a new mode
2091 Assert( Msg_shortcut_command != IGNORE_TARGET_ITEM );
2092 hud_squadmsg_send_wing_command( MsgItems[First_menu_item+k].instance, Msg_shortcut_command, 1 );
2093 hud_squadmsg_toggle();
2099 // code which gives an order to all fighters/bombers. If there is a message shortcut active, then
2100 // make that order apply to all fighters/bombers. Otherwise, move to the ship_command menu
2101 void hud_squadmsg_msg_all_fighters()
2103 if ( Msg_shortcut_command == -1 ) {
2104 Msg_instance = MESSAGE_ALL_FIGHTERS;
2105 hud_squadmsg_do_mode( SM_MODE_SHIP_COMMAND );
2107 hud_squadmsg_send_to_all_fighters( Msg_shortcut_command );
2108 hud_squadmsg_toggle();
2112 // called to actually bring in a reinforcement. For single player games, always gets called.
2113 // for multiplayer games, always called on the server side. Clients should never get here
2114 void hud_squadmsg_call_reinforcement(int reinforcement_num, int player_num)
2120 rp = &Reinforcements[reinforcement_num];
2122 // safety net mainly for multiplayer servers in case some odd data desync occurs between
2123 // server and clients
2124 if ( MULTIPLAYER_MASTER && (rp->num_uses == rp->uses) ) {
2128 // check to see if the reinforcement called was a wing.
2129 for (i = 0; i < num_wings; i++ ) {
2130 if ( !stricmp(rp->name, Wings[i].name) ) {
2131 // found a wingname. Call the parse function to create all the ships in this wing
2132 // we must set the arrival cue of the wing to true, otherwise, this won't work!!
2133 Wings[i].flags &= ~WF_REINFORCEMENT;
2134 Wings[i].flags |= WF_RESET_REINFORCEMENT;
2136 // set up the arrival delay. If it is 0, then make is some random number of seconds
2137 delay = rp->arrival_delay;
2139 delay = (int)(frand() * 3.0) + 3;
2140 Wings[i].arrival_delay = timestamp(delay * 1000);
2145 // if we found no wing name that matched the reinforcement name, then look for a ship
2147 if ( i == num_wings ) {
2148 p_objp = mission_parse_get_arrival_ship( rp->name );
2150 // by resetting the reinforcement flag, we will allow code which normally handles arrivals
2151 // to make this reinforcement arrive. Doing so keeps the data structures clean.
2152 p_objp->flags &= ~P_SF_REINFORCEMENT;
2154 // set up the arrival delay
2155 delay = rp->arrival_delay;
2157 delay = (int)(frand() * 3.0) + 3; // between 3 and 6 seconds to arrive
2158 p_objp->arrival_delay = timestamp(delay * 1000);
2160 Int3(); // get allender -- I don't think that this can happen!!!!
2165 // increment the number of times this is used. Incremented here on single player and multiplayer
2166 // server side only. Clients keep track of own count when they actually call something in.
2169 // commented out on 9/9/98 because these messages simply are not used
2171 // now play a message (if there is one to play) for this reinforcement arrival. The first for loop
2172 // determine how many messages there are to play, since the array is packet. Then, if >= 1 message
2173 // to play, play one
2174 for (i = 0; i < MAX_REINFORCEMENT_MESSAGES; i++ )
2175 if ( !strlen(rp->yes_messages[i]) )
2179 // message_send_to_player( rp->yes_messages[myrand() % i], rp->name, MESSAGE_PRIORITY_NORMAL, HUD_SOURCE_FRIENDLY );
2182 mission_log_add_entry(LOG_PLAYER_REINFORCEMENT, rp->name, NULL);
2185 // function to display a list of reinforcements available to the player
2186 void hud_squadmsg_reinforcement_select()
2191 if ( Num_menu_items == -1 ) {
2193 for (i = 0; i < Num_reinforcements; i++) {
2194 rp = &Reinforcements[i];
2196 // don't put reinforcements onto the list that have already been used up.
2197 if ( (rp->num_uses == rp->uses) ){
2201 // don't put items which are not on my team
2202 if((Player_ship != NULL) && (ship_get_reinforcement_team(i) != Player_ship->team)){
2206 Assert ( Num_menu_items < MAX_MENU_ITEMS );
2207 strcpy( MsgItems[Num_menu_items].text, rp->name );
2208 MsgItems[Num_menu_items].instance = i;
2209 MsgItems[Num_menu_items].active = 0;
2211 if ( rp->flags & RF_IS_AVAILABLE ) {
2212 MsgItems[Num_menu_items].active = 1;
2219 // hud_squadmsg_display_menu( "Select Reinforcement" );
2220 hud_squadmsg_display_menu( XSTR( "Select Ship/Wing", 319) ); // AL 11-14-97: Reinforcement didn't fit, so using this for now
2221 k = hud_squadmsg_get_key();
2225 hud_squadmsg_toggle(); // take us out of message mode
2227 rnum = MsgItems[First_menu_item + k].instance;
2229 // check to see if trying to call a reinforcement not yet available. If so, maybe play message, but
2231 if ( MsgItems[First_menu_item + k].active == 0 ) {
2235 // in single player, or a multiplayer master, call in the reinforcement. Clients send a packet to the
2237 if ( MULTIPLAYER_CLIENT ) {
2238 Reinforcements[rnum].num_uses++; // increment this variable here since clients need to maintain a valid count
2239 send_player_order_packet(SQUAD_MSG_REINFORCEMENT, rnum, 0);
2241 hud_squadmsg_call_reinforcement(rnum);
2246 // function to display list of commands for a ship
2247 void hud_squadmsg_ship_command()
2250 int i, orders, default_orders;
2252 // when adding ship commands, we must look at the type of ship, and what messages that
2253 // ship allows. First, place all messages that are possible onto the menu, then
2255 // see if messaging all ships or just one. Messaging all ships will mean all default orders
2256 // show on comm menu.
2257 if ( Msg_instance != MESSAGE_ALL_FIGHTERS ) {
2258 orders = Ships[Msg_instance].orders_accepted;
2259 default_orders = ship_get_default_orders_accepted( &Ship_info[Ships[Msg_instance].ship_info_index] );
2262 default_orders = FIGHTER_MESSAGES;
2263 orders = default_orders;
2266 First_menu_item = 0;
2268 for ( i = 0; i < MAX_SHIP_ORDERS; i++ ) {
2269 // check to see if the comm order should even be added to the menu -- if so, then add it
2270 // the order will be activated if the bit is set for the ship.
2271 if ( default_orders & Comm_orders[i].value ) {
2272 Assert ( Num_menu_items < MAX_MENU_ITEMS );
2273 strcpy( MsgItems[Num_menu_items].text, comm_order_menu_text(i) );
2274 MsgItems[Num_menu_items].instance = Comm_orders[i].value;
2275 MsgItems[Num_menu_items].active = 0;
2276 // check the bit to see if the command is active
2277 if ( orders & Comm_orders[i].value )
2278 MsgItems[Num_menu_items].active = 1;
2280 // if the order cannot be carried out by the ship, then item should be inactive
2281 if ( (Msg_instance != MESSAGE_ALL_FIGHTERS) && !hud_squadmsg_ship_order_valid( Msg_instance, Comm_orders[i].value ) )
2282 MsgItems[Num_menu_items].active = 0;
2284 // do some other checks to possibly gray out other items.
2285 // if no target, remove any items which are associated with the players target
2286 if ( !hud_squadmsg_is_target_order_valid(i, 0) )
2287 MsgItems[Num_menu_items].active = 0;
2289 // if messaging all fighters, see if we should gray out the order if no one will accept it,
2290 // or modify the text if only some of the ships will accept it
2291 if ( Msg_instance == MESSAGE_ALL_FIGHTERS ) {
2294 int partial_accept, all_accept; // value which tells us what to do with menu item
2296 all_accept = Comm_orders[i].value;
2298 for ( so = GET_FIRST(&Ship_obj_list); so != END_OF_LIST(&Ship_obj_list); so = GET_NEXT(so) ) {
2300 // don't send messge to ships not on player's team, or that are in a wing.
2301 shipp = &Ships[Objects[so->objnum].instance];
2302 if ( shipp->team != Player_ship->team )
2305 // don't send message to non fighter wings
2306 if ( !(Ship_info[shipp->ship_info_index].flags & (SIF_FIGHTER | SIF_BOMBER)) )
2309 all_accept &= shipp->orders_accepted; // 'and'ing will either keep this bit set or zero it properly
2310 partial_accept |= (shipp->orders_accepted & Comm_orders[i].value); // 'or'ing will tell us if at least one accepts
2313 if ( !all_accept ) {
2314 // either modify the text if a partial accept, or grey it out if no one accepts
2315 if ( partial_accept ) {
2316 strcat( MsgItems[Num_menu_items].text, XSTR( "(*)", 320) );
2318 MsgItems[Num_menu_items].active = 0;
2327 hud_squadmsg_display_menu( XSTR( "What Command", 321) );
2328 k = hud_squadmsg_get_key();
2330 // when we get a valid goal, we must add the goal to the ai ship's goal list
2333 Assert ( k < Num_menu_items );
2334 // when messaging all fighters or ignoring target, call the send_to_all_fighters routine
2335 if ( (Msg_instance != MESSAGE_ALL_FIGHTERS) && (MsgItems[k].instance != IGNORE_TARGET_ITEM) )
2336 hud_squadmsg_send_ship_command( Msg_instance, MsgItems[k].instance, 1 );
2338 hud_squadmsg_send_to_all_fighters( MsgItems[k].instance );
2339 hud_squadmsg_toggle();
2343 // function to display list of command for a wing
2344 void hud_squadmsg_wing_command()
2348 int default_orders, i, orders;
2350 // when adding commands for wings, we will look at all of the ships in the wing, and create
2351 // the order list from that set of ships. In the future, we may want to do something else....
2353 wingp = &Wings[Msg_instance];
2355 // or together all of the orders for all the ships in the wing
2357 for ( i = 0; i < wingp->current_count; i++ ) {
2358 orders = ship_get_default_orders_accepted( &Ship_info[Ships[wingp->ship_index[i]].ship_info_index] );
2359 default_orders |= orders;
2361 default_orders &= ~CAPTURE_TARGET_ITEM; // we cannot capture any target with a wing.
2364 orders = Ships[wingp->ship_index[0]].orders_accepted; // get the orders that the first ship in the wing will accept
2365 for ( i = 0; i < MAX_SHIP_ORDERS; i++ ) {
2366 // add the set of default orders to the comm menu. We will currently allow all messages
2367 // to be available in the wing.
2368 if ( default_orders & Comm_orders[i].value ) {
2369 Assert ( Num_menu_items < MAX_MENU_ITEMS );
2370 strcpy( MsgItems[Num_menu_items].text, comm_order_menu_text(i) );
2371 MsgItems[Num_menu_items].instance = Comm_orders[i].value;
2372 MsgItems[Num_menu_items].active = 0;
2374 // possibly grey out the menu item depending on whether or not the "wing" will accept this order
2375 // the "wing" won't accept the order if the first ship in the wing doesn't accept it.
2376 if ( orders & Comm_orders[i].value )
2377 MsgItems[Num_menu_items].active = 1;
2379 // do some other checks to possibly gray out other items.
2380 // if no target, remove any items which are associated with the players target
2381 if ( !hud_squadmsg_is_target_order_valid(i, 0) )
2382 MsgItems[Num_menu_items].active = 0;
2388 hud_squadmsg_display_menu( XSTR( "What Command", 321) );
2389 k = hud_squadmsg_get_key();
2392 // ignore target gets sent to everyone.
2393 if ( MsgItems[k].instance != IGNORE_TARGET_ITEM )
2394 hud_squadmsg_send_wing_command( Msg_instance, MsgItems[k].instance, 1 );
2396 hud_squadmsg_send_to_all_fighters( MsgItems[k].instance );
2397 hud_squadmsg_toggle();
2403 //----------------------------------------------------------
2404 // external entry points below!!!!
2406 // when starting messaging mode, we must remove old bindings from the
2407 // keys that are used for messaging mode (which will get restored when
2408 // messaging mode is done).
2410 // this code below will get called only the key config changes (from ControlsConfig.cpp)
2411 // or if the bindings haven't been saved yet. This code doesn't remove the bindings
2412 // but just sets up the array so that the bindings can be removed when messaging
2415 // do_scroll indicates whether we should save the page up and page down keys
2416 void hud_squadmsg_save_keys( int do_scroll )
2423 for ( j=0; j<MAX_KEYS_USED; j++ ) {
2424 for ( i=0; Control_config[i].text[0]; i++ ) { // the text field in this structure is empty at the end of the config list
2425 if ( Control_config[i].key_id == keys_used[j] ) { // this is true if we have a match
2427 // if we are not saving scrolling keys and we are trying to match page up and page down
2429 if ( !do_scroll && ((keys_used[j] == KEY_PAGEDOWN) || (keys_used[j] == KEY_PAGEUP)) )
2432 Assert( num_keys_saved < MAX_KEYS_USED );
2433 key_save[num_keys_saved].option_num = i;
2434 key_save[num_keys_saved].key_value = keys_used[j];
2436 break; // done with this key -- move to next.
2443 // function is called once per mission start. Initializes those values
2444 // which only need to be inited once per mission.
2445 void hud_init_squadmsg( void )
2449 if ( !Mbox_frames_loaded ) {
2450 for ( i = 0; i < NUM_MBOX_FRAMES; i++ ) {
2451 Mbox_gauge[i].first_frame = bm_load_animation(Mbox_fnames[gr_screen.res][i], &Mbox_gauge[i].num_frames);
2452 if ( Mbox_gauge[i].first_frame == -1 ) {
2453 Warning(LOCATION, "Could not load in ani: %s\n", Mbox_fnames[gr_screen.res][i]);
2457 Mbox_frames_loaded = 1;
2460 Msg_eat_key_timestamp = timestamp(0);
2463 // external entry point into code which changes the messaging mode based on the
2464 // previous player flag value. I thought it better to isolate all system changes
2466 void hud_squadmsg_toggle()
2468 // if the emp effect is active, always ignore this
2469 if(emp_active_local()){
2473 // if entering this mode, must setup messaging system. Don't start squadmessging if
2474 // the player is dead.
2475 if ( !(Player->flags & PLAYER_FLAGS_MSG_MODE) ) {
2476 if ( Game_mode & GM_DEAD ){
2479 if ( (Game_mode & GM_MULTIPLAYER) && NETPLAYER_IS_OBSERVER(Net_player) ){
2482 hud_squadmsg_start();
2487 Player->flags ^= PLAYER_FLAGS_MSG_MODE;
2491 // extern entry point to allow messaging of enemies
2492 void hud_enemymsg_toggle()
2494 hud_squadmsg_toggle();
2495 // if we just entered message mode, turn on var that says to message enemies
2496 if ( Player->flags & PLAYER_FLAGS_MSG_MODE )
2501 // external entry point into code when a keyboard shortcut is used for a command
2502 // we are passed in an ID for the command to set internal variables. This command
2503 // will be used in place of the last menu in the messaging code
2504 void hud_squadmsg_shortcut( int command )
2506 // check if the communications system is capable of sending a message
2507 if ( (hud_communications_state(Player_ship, 1) != COMM_OK) && (command != REARM_REPAIR_ME_ITEM) ) {
2511 // observers in multiplayer games cannot have this active either
2512 if ( (Game_mode & GM_MULTIPLAYER) && NETPLAYER_IS_OBSERVER(Net_player) )
2515 // in multiplayer and I cannot message, don't allow anything except calling in for rearm
2516 if ( (Game_mode & GM_MULTIPLAYER) && !multi_can_message(Net_player) && (command != REARM_REPAIR_ME_ITEM) )
2517 gamesnd_play_error_beep();
2519 // player ships which turns traitor cannot rearm
2520 if ( Player_ship->team == TEAM_TRAITOR )
2523 if ( Player->flags & PLAYER_FLAGS_MSG_MODE ) // we are already in messaging mode -- maybe do sometime more interesting?
2525 hud_squadmsg_toggle();
2526 Msg_shortcut_command = command; // save the command for later use
2527 if ( Msg_shortcut_command == CAPTURE_TARGET_ITEM ) // some commands only apply to wings or ships
2528 Squad_msg_mode = SM_MODE_SHIP_SELECT; // -- don't offer choice
2529 else if ( Msg_shortcut_command == IGNORE_TARGET_ITEM ) { // ignoring target applied to all ships
2530 hud_squadmsg_toggle(); // turns off mode which was turned on above
2531 hud_squadmsg_send_to_all_fighters( Msg_shortcut_command );
2535 // external entry point which is called when the player hits a selection key (1-0) while in messaging
2536 // mode. If we are in messaging mode, send the shortcut command to the ships that are part of the
2537 // passed in selection set. If there is no shortcut command, do nothing. Returns 1 if the key
2538 // was used, else 0. This return value is used to tell the key control system that it should
2539 // call the normal targeting selection stuff.
2540 int hud_squadmsg_hotkey_select( int k )
2542 htarget_list *hitem, *plist;
2546 Assert ( Player->flags & PLAYER_FLAGS_MSG_MODE );
2548 if ( Msg_shortcut_command == -1 )
2551 Assert ( (k >= 0) && (k < MAX_KEYED_TARGETS) );
2552 plist = &(Player->keyed_targets[k]);
2554 if ( EMPTY(plist) ) // be sure that we have at least one ship in the list
2558 // for each ship in the selection set list, send the shortcut command that the player
2559 // previously entered. Be sure to check that we are not trying to send a command to
2561 for ( hitem = GET_FIRST(plist); hitem != END_OF_LIST(plist); hitem = GET_NEXT(hitem) ) {
2563 Assert ( objp->type == OBJ_SHIP );
2564 if ( Ships[objp->instance].team != TEAM_FRIENDLY )
2567 // be sure that this ship can accept this command
2568 // DDOI - I changed this , to & which seeems to be in keeping
2569 // with similar code.
2570 if ( !(Msg_shortcut_command & Ships[objp->instance].orders_accepted) )
2573 hud_squadmsg_send_ship_command( objp->instance, Msg_shortcut_command, send_message );
2577 hud_squadmsg_toggle(); // turn off messaging mode
2582 // the next function is called once a frame when the player is messaging someone
2583 // in his squad. After a period of 5 seconds of inactivity (i.e. no keypress to
2584 // select something in the menu), the menu will disappear. This function will only
2585 // get called if the player flag PLAYER_FLAG_MSG_MODE is set. Parameter is the key
2586 // that was hit this frame
2588 int hud_squadmsg_do_frame( )
2592 Assert ( Player->flags & PLAYER_FLAGS_MSG_MODE ); // be sure that messaging mode is set!!!
2594 // if the player is now dead, or the timestamp elapsed, then get out of messaging mode.
2595 if ( (Game_mode & GM_DEAD) || timestamp_elapsed(Msg_mode_timestamp) ) {
2596 hud_squadmsg_toggle();
2602 // check the player's current target. Change in target resets the timer
2604 if ( Msg_target_objnum != Player_ai->target_objnum ) {
2605 Msg_target_objnum = Player_ai->target_objnum;
2609 if ( Msg_targeted_subsys != Player_ai->targeted_subsys ) {
2610 Msg_targeted_subsys = Player_ai->targeted_subsys;
2614 // setup color/font info
2615 // hud_set_default_color();
2616 hud_set_gauge_color(HUD_MESSAGE_BOX);
2618 // check for multiplayer mode - this is really a special case checker for support ship requesting and aborting
2619 if((Game_mode & GM_MULTIPLAYER) && !(Net_player->flags & NETINFO_FLAG_AM_MASTER) && (Squad_msg_mode == SM_MODE_REPAIR_REARM || Squad_msg_mode == SM_MODE_REPAIR_REARM_ABORT)){
2624 // who_to_sig = Objects[Ships[shipnum].objnum].net_signature;
2625 if(Player_ai->target_objnum != -1)
2626 net_sig = Objects[Player_ai->target_objnum].net_signature;
2630 if ((Player_ai->targeted_subsys != NULL) && (Player_ai->targeted_subsys->current_hits > 0.0f))
2631 subsys_name = Player_ai->targeted_subsys->system_info->subobj_name;
2635 // send the correct packet
2636 if(Squad_msg_mode == SM_MODE_REPAIR_REARM)
2637 send_player_order_packet(SQUAD_MSG_SHIP, 0, REARM_REPAIR_ME_ITEM);
2639 send_player_order_packet(SQUAD_MSG_SHIP, 0, ABORT_REARM_REPAIR_ITEM);
2641 // make sure to toggle the mode off
2642 hud_squadmsg_toggle();
2647 // draw top of frame
2648 if ( Mbox_gauge[0].first_frame >= 0 ) {
2649 GR_AABITMAP(Mbox_gauge[0].first_frame, Mbox_top_coords[gr_screen.res][0], Mbox_top_coords[gr_screen.res][1]);
2652 switch( Squad_msg_mode ) {
2654 case SM_MODE_TYPE_SELECT:
2655 hud_squadmsg_type_select();
2658 case SM_MODE_SHIP_SELECT:
2659 hud_squadmsg_ship_select();
2662 case SM_MODE_WING_SELECT:
2663 hud_squadmsg_wing_select();
2666 case SM_MODE_SHIP_COMMAND:
2667 hud_squadmsg_ship_command();
2670 case SM_MODE_WING_COMMAND:
2671 hud_squadmsg_wing_command();
2674 case SM_MODE_REINFORCEMENTS:
2675 hud_squadmsg_reinforcement_select();
2678 case SM_MODE_REPAIR_REARM:
2679 //if((Game_mode & GM_MULTIPLAYER) && (Net_player->flags & NETINFO_FLAG_AM_MASTER) && (addr != NULL)){
2680 // hud_squadmsg_repair_rearm(1,&Objects[Net_players[player_num].player->objnum]);
2682 hud_squadmsg_repair_rearm(1); // note we return right away. repair/rearm code handles messaging, etc
2686 case SM_MODE_REPAIR_REARM_ABORT:
2687 //if((Game_mode & GM_MULTIPLAYER) && (Net_player->flags & NETINFO_FLAG_AM_MASTER) && (addr != NULL)){
2688 // hud_squadmsg_repair_rearm_abort(1,&Objects[Net_players[player_num].player->objnum]);
2690 hud_squadmsg_repair_rearm_abort(1); // note we return right away. repair/rearm code handles messaging, etc
2694 case SM_MODE_ALL_FIGHTERS:
2695 hud_squadmsg_msg_all_fighters();
2699 Int3(); // get allender -- invalid mode in messaging system
2704 // be sure to reset the clip region
2705 HUD_reset_clip(); // JAS: Is this needed?
2707 if ( Msg_key_used || target_changed ) {
2708 Msg_mode_timestamp = timestamp(DEFAULT_MSG_TIMEOUT);
2714 void hud_add_issued_order(const char *name, int order, const char *target)
2716 Squadmsg_history[squadmsg_history_index].ship = get_parse_name_index(name);
2717 Squadmsg_history[squadmsg_history_index].order = order;
2719 Squadmsg_history[squadmsg_history_index].target = get_parse_name_index(target);
2721 Squadmsg_history[squadmsg_history_index].target = -1;
2723 squadmsg_history_index++;
2724 if (squadmsg_history_index >= SQUADMSG_HISTORY_MAX)
2725 squadmsg_history_index = 0;
2728 int hud_query_order_issued(const char *name, const char *order, const char *target)
2730 int i, o=-1, ship, t;
2732 ship = get_parse_name_index(name);
2735 t = get_parse_name_index(target);
2737 for (i=0; i<MAX_SHIP_ORDERS; i++)
2738 if (!stricmp(order, comm_order_menu_text(i)) )
2739 o = Comm_orders[i].value;
2741 Assert(i < MAX_SHIP_ORDERS);
2742 for (i=0; i<SQUADMSG_HISTORY_MAX; i++)
2743 if (Squadmsg_history[i].order == o)
2744 if (ship == Squadmsg_history[i].ship)
2745 if (Squadmsg_history[i].target == t)
2752 void hudsquadmsg_page_in()
2756 for ( i = 0; i < NUM_MBOX_FRAMES; i++ ) {
2757 bm_page_in_aabitmap( Mbox_gauge[i].first_frame, Mbox_gauge[i].num_frames );