2 * Copyright (C) Volition, Inc. 2005. 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 the
11 * $Logfile: /Freespace2/code/Network/multi_sw.cpp $
13 * $Date: 9/13/99 11:30a $
16 * $Log: /Freespace2/code/Network/multi_sw.cpp $
18 * 10 9/13/99 11:30a Dave
19 * Added checkboxes and functionality for disabling PXO banners as well as
20 * disabling d3d zbuffer biasing.
22 * 9 9/04/99 8:00p Dave
23 * Fixed up 1024 and 32 bit movie support.
25 * 8 8/25/99 4:38p Dave
26 * Updated PXO stuff. Make squad war report stuff much more nicely.
28 * 7 4/09/99 2:21p Dave
29 * Multiplayer beta stuff. CD checking.
31 * 6 2/24/99 2:25p Dave
32 * Fixed up chatbox bugs. Made squad war reporting better. Fixed a respawn
33 * bug for dogfight more.
35 * 5 2/19/99 2:55p Dave
36 * Temporary checking to report the winner of a squad war match.
38 * 4 2/17/99 2:11p Dave
39 * First full run of squad war. All freespace and tracker side stuff
42 * 3 2/12/99 6:16p Dave
43 * Pre-mission Squad War code is 95% done.
45 * 2 2/11/99 3:08p Dave
46 * PXO refresh button. Very preliminary squad war support.
53 #include "systemvars.h"
58 #include "multi_fstracker.h"
59 #include "multimsgs.h"
60 #include "multi_team.h"
62 #include "multi_pmsg.h"
63 #include "multiutil.h"
64 #include "freespace.h"
66 // ------------------------------------------------------------------------------------
67 // MULTIPLAYER SQUAD WAR DEFINES/VARS
70 // global request info
71 squad_war_request Multi_sw_request;
74 squad_war_result Multi_sw_result;
76 // set on the host in response to a standalone sw query, -1 == waiting, 0 == fail, 1 == success
77 int Multi_sw_std_query = -1;
80 char Multi_sw_match_code[MATCH_CODE_LEN];
82 // reply from a standalone on a bad response
83 char Multi_sw_bad_reply[MAX_SQUAD_RESPONSE_LEN+1] = "";
86 extern int Multi_team0_score;
87 extern int Multi_team1_score;
89 // ------------------------------------------------------------------------------------
90 // MULTIPLAYER SQUAD WAR FORWARD DECLARATIONS
93 // popup_till_condition do frame function for the host doing verification through the standalone
94 int multi_sw_query_tracker_A();
96 // condition do frame function for the standalone querying PXO
97 int multi_sw_query_tracker_B();
99 // stuff Multi_sw_request
100 void multi_sw_stuff_request(char *match_code);
102 // stuff Multi_sw_result
103 void multi_sw_stuff_result();
105 // verify that we have the proper # of players
106 int multi_sw_verify_squad_counts();
109 // ------------------------------------------------------------------------------------
110 // MULTIPLAYER SQUAD WAR FUNCTIONS
113 // call before loading level - mission sync phase. only the server need do this
114 void multi_sw_level_init()
118 // determine if everything is ok to move forward for a squad war match
119 int multi_sw_ok_to_commit()
122 char match_code[MATCH_CODE_LEN] = "";
123 char bad_response[MAX_SQUAD_RESPONSE_LEN+1] = "";
126 // make sure we have enough players per team
127 if(!multi_sw_verify_squad_counts()){
131 // prompt the host for the match code
132 ret = popup_input_sync(0, XSTR("Please enter the match code", 1076), 32);
136 SDL_strlcpy(match_code, ret, SDL_arraysize(match_code));
138 SDL_strlcpy(Multi_sw_match_code, "", SDL_arraysize(Multi_sw_match_code));
140 // if we're the server, do the nice case
141 if(MULTIPLAYER_MASTER){
142 // stuff match request
143 multi_sw_stuff_request(match_code);
145 // return an MSW_STATUS_* value
146 if(multi_fs_tracker_validate_sw(&Multi_sw_request, bad_response, SDL_arraysize(bad_response)) == MSW_STATUS_VALID){
147 // store the match code
148 SDL_strlcpy(Multi_sw_match_code, match_code, SDL_arraysize(Multi_sw_match_code));
153 // do - didn't check out properly
155 if(strlen(bad_response) > 0){
156 popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, "Error validating Squad War match\n\n(%s)", bad_response);
158 popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, "Error validating Squad War match\n\n(%s)", "Unknown");
162 // otherwise we have to do it through the standalone - ARRRGHH!
164 // send the query packet and wait for a response
165 Multi_sw_std_query = -1;
166 memset(Multi_sw_bad_reply, 0, MAX_SQUAD_RESPONSE_LEN+1);
167 send_sw_query_packet(SW_STD_START, match_code);
168 if(popup_till_condition(multi_sw_query_tracker_A, XSTR("&Cancel", 667), XSTR("Validating squad war", 1075)) == 10){
172 if(strlen(Multi_sw_bad_reply) > 0){
173 popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, "Error validating Squad War match\n\n(%s)", Multi_sw_bad_reply);
175 popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, "Error validating Squad War match\n\n(%s)", "Unknown");
180 // hmm, should probably never get here
184 // query PXO on the standalone
185 void multi_sw_std_query(char *match_code)
187 char bad_response[MAX_SQUAD_RESPONSE_LEN+1];
189 // stuff match request
190 multi_sw_stuff_request(match_code);
192 SDL_strlcpy(Multi_sw_match_code, "", SDL_arraysize(Multi_sw_match_code));
194 // return an MSW_STATUS_* value
195 if(multi_fs_tracker_validate_sw(&Multi_sw_request, bad_response, SDL_arraysize(bad_response)) != MSW_STATUS_VALID){
196 send_sw_query_packet(SW_STD_BAD, bad_response);
198 // store the match code
199 SDL_strlcpy(Multi_sw_match_code, match_code, SDL_arraysize(Multi_sw_match_code));
201 send_sw_query_packet(SW_STD_OK, NULL);
205 // call to update everything on the tracker
206 #define SEND_AND_DISPLAY(mesg) do { send_game_chat_packet(Net_player, mesg, MULTI_MSG_ALL, NULL, NULL, 1); multi_display_chat_msg(mesg, 0, 0); } while(0);
207 void multi_sw_report(int stats_saved)
209 char bad_response[MAX_SQUAD_RESPONSE_LEN+1] = "";
211 // stuff Multi_sw_result
212 multi_sw_stuff_result();
216 if ( multi_fs_tracker_store_sw(&Multi_sw_result, bad_response, SDL_arraysize(bad_response)) ) {
217 SEND_AND_DISPLAY(XSTR("<SquadWar results stored on PXO>", 1079));
219 SEND_AND_DISPLAY(XSTR("<SquadWar results rejected by PXO>", 1080));
220 if(strlen(bad_response) > 0){
221 SEND_AND_DISPLAY(bad_response);
225 // doh. something was bogus
227 SEND_AND_DISPLAY(XSTR("<SquadWar results invalidated>", 1478));
231 // ------------------------------------------------------------------------------------
232 // MULTIPLAYER SQUAD WAR FORWARD DEFINITIONS
235 // condition do frame function for the standalone querying PXO
236 int multi_sw_query_tracker_A()
238 switch(Multi_sw_std_query){
252 // shouldn't get here
256 // stuff Multi_sw_request
257 void multi_sw_stuff_request(char *match_code)
260 squad_war_request *s = &Multi_sw_request;
262 // stuff squad id #'s, counts, and squad names
265 for(idx=0; idx<MAX_PLAYERS; idx++){
266 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx])){
268 if(Net_players[idx].p_info.team == 0){
269 s->squad_plr1[s->squad_count1++] = Net_players[idx].tracker_player_id;
273 s->squad_plr2[s->squad_count2++] = Net_players[idx].tracker_player_id;
279 SDL_strlcpy(s->match_code, match_code, SDL_arraysize(s->match_code));
282 // verify that we have the proper # of players
283 int multi_sw_verify_squad_counts()
288 char err_string[255] = "";
290 for(idx=0; idx<MAX_PLAYERS; idx++){
291 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx])){
292 if(Net_players[idx].p_info.team == 0){
299 if((team0_count < MULTI_SW_MIN_PLAYERS) || (team1_count < MULTI_SW_MIN_PLAYERS)){
300 // print up the error string
301 SDL_snprintf(err_string, SDL_arraysize(err_string), XSTR("You need to have at least %d players per squad for Squad War", 1073), MULTI_SW_MIN_PLAYERS);
302 popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, err_string);
310 // stuff Multi_sw_result
311 void multi_sw_stuff_result()
313 squad_war_result *s = &Multi_sw_result;
317 SDL_strlcpy(s->match_code, Multi_sw_match_code, SDL_arraysize(s->match_code));
319 // determine what happened
320 switch(multi_team_winner()){
331 // stuff squad id #'s, counts, and squad names
334 for(idx=0; idx<MAX_PLAYERS; idx++){
335 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx])){
337 if(Net_players[idx].p_info.team == 0){
338 s->squad_winners[s->squad_count1++] = Net_players[idx].tracker_player_id;
342 s->squad_losers[s->squad_count2++] = Net_players[idx].tracker_player_id;
351 // stuff squad id #'s, counts, and squad names
354 for(idx=0; idx<MAX_PLAYERS; idx++){
355 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx])){
357 if(Net_players[idx].p_info.team == 1){
358 s->squad_winners[s->squad_count1++] = Net_players[idx].tracker_player_id;
362 s->squad_losers[s->squad_count2++] = Net_players[idx].tracker_player_id;