Skip to content

Commit

Permalink
Fix mantis 2923
Browse files Browse the repository at this point in the history
Backout all_time and multi_stats from the pilotfile stats as
required
  • Loading branch information
niffiwan committed May 25, 2014
1 parent c1b2d7c commit f840822
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 3 deletions.
11 changes: 10 additions & 1 deletion code/missionui/missiondebrief.cpp
Expand Up @@ -47,6 +47,7 @@
#include "network/multi_campaign.h"
#include "network/multi_endgame.h"
#include "missionui/chatbox.h"
#include "pilotfile/pilotfile.h"


#define MAX_TOTAL_DEBRIEF_LINES 200
Expand Down Expand Up @@ -2123,6 +2124,7 @@ void debrief_init()
void debrief_close()
{
int i;
scoring_struct *sc;

Assert(Debrief_inited);

Expand All @@ -2135,11 +2137,17 @@ void debrief_close()
if(MULTIPLAYER_MASTER){
for(i=0; i<MAX_PLAYERS; i++){
if(MULTI_CONNECTED(Net_players[i]) && !MULTI_STANDALONE(Net_players[i]) && !MULTI_PERM_OBSERVER(Net_players[i]) && (Net_players[i].m_player != NULL)){
scoring_backout_accept(&Net_players[i].m_player->stats);
sc = &Net_players[i].m_player->stats;
scoring_backout_accept(sc);

if (Net_player == &Net_players[i]) {
Pilot.update_stats_backout( sc );
}
}
}
} else {
scoring_backout_accept( &Player->stats );
Pilot.update_stats_backout( &Player->stats );
}
}
} else {
Expand All @@ -2150,6 +2158,7 @@ void debrief_close()
Campaign.next_mission = Campaign.current_mission;
}
scoring_backout_accept( &Player->stats );
Pilot.update_stats_backout( &Player->stats );
}
}

Expand Down
11 changes: 9 additions & 2 deletions code/network/multi_dogfight.cpp
Expand Up @@ -30,7 +30,7 @@
#include "stats/scoring.h"
#include "mission/missionparse.h"
#include "iff_defs/iff_defs.h"

#include "pilotfile/pilotfile.h"
#include "fs2netd/fs2netd_client.h"
#include "cfile/cfile.h"

Expand Down Expand Up @@ -296,6 +296,7 @@ void multi_df_debrief_do()
void multi_df_debrief_close()
{
int idx;
scoring_struct *sc;

// shutdown the chatbox
chatbox_close();
Expand All @@ -307,11 +308,17 @@ void multi_df_debrief_close()
if(MULTIPLAYER_MASTER){
for(idx=0; idx<MAX_PLAYERS; idx++){
if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx]) && (Net_players[idx].m_player != NULL)){
scoring_backout_accept(&Net_players[idx].m_player->stats);
sc = &Net_players[idx].m_player->stats;
scoring_backout_accept(sc);

if (Net_player == &Net_players[idx]) {
Pilot.update_stats_backout( sc );
}
}
}
} else {
scoring_backout_accept( &Player->stats );
Pilot.update_stats_backout( &Player->stats );
}
}
}
Expand Down
108 changes: 108 additions & 0 deletions code/pilotfile/pilotfile.cpp
Expand Up @@ -182,6 +182,114 @@ void pilotfile::update_stats(scoring_struct *stats, bool training)

void pilotfile::update_stats_backout(scoring_struct *stats, bool training)
{
int i, j;
uint idx;
size_t list_size;
index_list_t ilist;
scoring_special_t *p_stats = NULL;

if (Game_mode & GM_MULTIPLAYER) {
p_stats = &multi_stats;
} else {
p_stats = &all_time_stats;
}

// medals
if (stats->m_medal_earned >= 0) {
list_size = p_stats->medals_earned.size();

j = -1;

for (idx = 0; idx < list_size; idx++) {
if ( p_stats->medals_earned[idx].name.compare(Medals[stats->m_medal_earned].name) == 0 ) {
j = idx;
break;
}
}

if (j >= 0) {
p_stats->medals_earned[j].val = MAX(0,p_stats->medals_earned[j].val--);
} else {
Assertion(true, "Medal '%s' not found, should have been added by pilotfile::update_stats.", Medals[stats->m_medal_earned].name);
}
}

// only medals can be awarded in training missions
if (training) {
return;
}

p_stats->score -= stats->m_score;

p_stats->assists -= stats->m_assists;
p_stats->kill_count -= stats->m_kill_count;
p_stats->kill_count_ok -= stats->m_kill_count_ok;
p_stats->bonehead_kills -= stats->m_bonehead_kills;

p_stats->p_shots_fired -= stats->mp_shots_fired;
p_stats->p_shots_hit -= stats->mp_shots_hit;
p_stats->p_bonehead_hits -= stats->mp_bonehead_hits;

p_stats->s_shots_fired -= stats->ms_shots_fired;
p_stats->s_shots_hit -= stats->ms_shots_hit;
p_stats->s_bonehead_hits -= stats->ms_bonehead_hits;

p_stats->flight_time -= (unsigned int)f2i(Missiontime);
p_stats->last_flown = p_stats->last_backup;
p_stats->missions_flown--;

if (stats->m_promotion_earned >= 0) {
// deal with a multi-rank promotion mission
for (i = 0; i < MAX_FREESPACE2_RANK; ++i) {
if (p_stats->score <= Ranks[i].points) {
p_stats->rank = i-1;
break;
}
}
Assertion (p_stats->rank >= 0, "Rank became negative.");
}

// badges
if (stats->m_badge_earned >= 0) {
list_size = p_stats->medals_earned.size();

j = -1;

for (idx = 0; idx < list_size; idx++) {
if ( p_stats->medals_earned[idx].name.compare(Medals[stats->m_badge_earned].name) == 0 ) {
j = idx;
break;
}
}

if (j >= 0) {
p_stats->medals_earned[j].val = 0;
} else {
Assertion (true, "Badge '%s' not found, should have been added by pilotfile::update_stats.", Medals[stats->m_badge_earned].name);
}
}

// ship kills
for (i = 0; i < Num_ship_classes; i++) {
if (stats->m_okKills[i] > 0) {
list_size = p_stats->ship_kills.size();

j = -1;

for (idx = 0; idx < list_size; idx++) {
if ( p_stats->ship_kills[idx].name.compare(Ship_info[i].name) == 0 ) {
j = i;
break;
}
}

if (j >= 0) {
p_stats->ship_kills[j].val -= stats->m_okKills[i];
} else {
Assertion(true, "Ship kills of '%s' not found, should have been added by pilotfile::update_stats.", stats->m_okKills[i]);
}
}
}
}

/**
Expand Down

0 comments on commit f840822

Please sign in to comment.