Solved possible issue when setting new Bounty_target via host messing up scores or new target itself - only set if player decided why to unset Bounty_target, keeping code flow and game logic in order; Fixed two compiler warnings regarding set but unused variables

This commit is contained in:
zicodxx 2011-05-15 11:59:12 +02:00
parent aa520e662a
commit ecdeed6228
2 changed files with 68 additions and 35 deletions

View file

@ -1,5 +1,9 @@
D2X-Rebirth Changelog
20110515
--------
main/multi.c: Solved possible issue when setting new Bounty_target via host messing up scores or new target itself - only set if player decided why to unset Bounty_target, keeping code flow and game logic in order; Fixed two compiler warnings regarding set but unused variables
20110513
--------
main/multi.c: Send player position also when multi_send_player_explode() is called so powerups drop at the right spot in case the respawn packet arrives first

View file

@ -131,7 +131,8 @@ fix Show_kill_list_timer = 0;
char Multi_is_guided=0;
char PKilledFlags[MAX_NUM_NET_PLAYERS];
int Bounty_target = 0; // Target for bounty mode netgame
int Bounty_target = 0, new_Bounty_target = -1; // Target for bounty mode netgame. NOTE: new_Bounty_target is a helper variable solving issues in case multi_do_bounty and multi_do_kill/multi_disconnect_player are processed in wrong order in case Bounty_target suicide/left game
int multi_sending_message[MAX_NUM_NET_PLAYERS] = { 0,0,0,0,0,0,0,0 };
int multi_defining_message = 0;
@ -763,21 +764,32 @@ void multi_compute_kill(int killer, int killed)
HUD_init_message(HM_MULTI, "%s %s", killed_name, TXT_SUICIDE);
/* Bounty mode needs some lovin' */
if( Game_mode & GM_BOUNTY && killed_pnum == Bounty_target && multi_i_am_master() )
if( Game_mode & GM_BOUNTY && killed_pnum == Bounty_target )
{
/* Select a random number */
int new_bounty_target = d_rand() % MAX_NUM_NET_PLAYERS;
/* Make sure they're valid: Don't check against kill flags,
* just in case everyone's dead! */
while( !Players[new_bounty_target].connected )
new_bounty_target = d_rand() % MAX_NUM_NET_PLAYERS;
/* Select new target */
multi_new_bounty_target( new_bounty_target );
/* Send this new data */
multi_send_bounty();
if ( multi_i_am_master() )
{
/* Select a random number */
int new = d_rand() % MAX_NUM_NET_PLAYERS;
/* Make sure they're valid: Don't check against kill flags,
* just in case everyone's dead! */
while( !Players[new].connected )
new = d_rand() % MAX_NUM_NET_PLAYERS;
/* Select new target */
multi_new_bounty_target( new );
/* Send this new data */
multi_send_bounty();
}
else
{
/* check if we already got a new target from host. if yes set it, if not just unset the current one. */
if ( new_Bounty_target != -1 )
Bounty_target = new_Bounty_target;
else
Bounty_target = -1;
}
}
}
@ -2025,21 +2037,32 @@ void multi_disconnect_player(int pnum)
}
// Bounty target left - select a new one
if( Game_mode & GM_BOUNTY && pnum == Bounty_target && multi_i_am_master() )
if( Game_mode & GM_BOUNTY && pnum == Bounty_target )
{
/* Select a random number */
int new_bounty_target = d_rand() % MAX_NUM_NET_PLAYERS;
/* Make sure they're valid: Don't check against kill flags,
* just in case everyone's dead! */
while( !Players[new_bounty_target].connected )
new_bounty_target = d_rand() % MAX_NUM_NET_PLAYERS;
/* Select new target */
multi_new_bounty_target( new_bounty_target );
/* Send this new data */
multi_send_bounty();
if ( multi_i_am_master() )
{
/* Select a random number */
int new = d_rand() % MAX_NUM_NET_PLAYERS;
/* Make sure they're valid: Don't check against kill flags,
* just in case everyone's dead! */
while( !Players[new].connected )
new = d_rand() % MAX_NUM_NET_PLAYERS;
/* Select new target */
multi_new_bounty_target( new );
/* Send this new data */
multi_send_bounty();
}
else
{
/* check if we already got a new target from host. if yes set it, if not just unset the current one. */
if ( new_Bounty_target != -1 )
Bounty_target = new_Bounty_target;
else
Bounty_target = -1;
}
}
multi_sending_message[pnum] = 0;
}
@ -3308,6 +3331,7 @@ void multi_prep_level(void)
PhallicMan=-1;
Drop_afterburner_blob_flag=0;
Bounty_target = 0;
new_Bounty_target = -1;
multi_consistency_error(1);
for (i=0;i<MAX_NUM_NET_PLAYERS;i++)
@ -4919,6 +4943,8 @@ void multi_send_bounty( void )
/* Test game mode */
if( !( Game_mode & GM_BOUNTY ) )
return;
if ( !multi_i_am_master() )
return;
/* Add opcode and target ID */
multibuf[0] = MULTI_DO_BOUNTY;
@ -4930,8 +4956,13 @@ void multi_send_bounty( void )
void multi_do_bounty( char *buf )
{
/* New target! */
multi_new_bounty_target( buf[1] );
if ( multi_i_am_master() )
return;
/* check if there's still a valid target */
if (Bounty_target == -1)
multi_new_bounty_target( buf[1] ); /* nope - set new target! */
else
new_Bounty_target = buf[1]; /* still have valid target - store new one until we unset the current. */
}
void multi_new_bounty_target( int pnum )
@ -5122,14 +5153,12 @@ void multi_save_game(ubyte slot, uint id, char *desc)
void multi_restore_game(ubyte slot, uint id)
{
char filename[PATH_MAX];
player saved_player;
int pnum,i;
int i;
int thisid;
if ((Endlevel_sequence) || (Control_center_destroyed))
return;
saved_player = Players[Player_num];
snprintf(filename, PATH_MAX, GameArg.SysUsePlayersDir? "Players/%s.mg%d" : "%s.mg%d", Players[Player_num].callsign, slot);
for (i = 0; i < N_players; i++)
@ -5146,7 +5175,7 @@ void multi_restore_game(ubyte slot, uint id)
return;
}
pnum = state_restore_all_sub( filename, 0 );
state_restore_all_sub( filename, 0 );
multi_send_score(); // send my restored scores. I sent 0 when I loaded the level anyways...
}