1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
#include "globalincs/pstypes.h"
#include "pilotfile/pilotfile.h"
#include "ship/ship.h"
#include "stats/medals.h"
pilotfile Pilot;
pilotfile::pilotfile()
{
m_have_flags = false;
m_have_info = false;
m_data_invalid = false;
m_size_offset = 0;
cfp = NULL;
p = NULL;
}
pilotfile::~pilotfile()
{
if (cfp) {
cfclose(cfp);
}
}
void pilotfile::startSection(Section::id section_id)
{
Assert( cfp );
const int zero = 0;
cfwrite_ushort( (ushort)section_id, cfp );
// to be updated when endSection() is called
cfwrite_int(zero, cfp);
// starting offset, for size of section
m_size_offset = cftell(cfp);
}
void pilotfile::endSection()
{
Assert( cfp );
Assert( m_size_offset > 0 );
size_t cur = cftell(cfp);
Assert( cur >= m_size_offset );
size_t section_size = cur - m_size_offset;
if (section_size) {
// go back to section size in file and write proper value
cfseek(cfp, cur - section_size - sizeof(int), CF_SEEK_SET);
cfwrite_int((int)section_size, cfp);
// go back to previous location for next section
cfseek(cfp, cur, CF_SEEK_SET);
}
}
void pilotfile::update_stats(scoring_struct *stats, bool training)
{
int idx, i, j, 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 = (int)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) ) {
j = idx;
break;
}
}
if (j >= 0) {
p_stats->medals_earned[j].val++;
} else {
ilist.name = Medals[stats->m_medal_earned].name;
ilist.val = 1;
p_stats->medals_earned.push_back(ilist);
}
}
// early out if these stats are from a training mission
if (training) {
return;
}
if (stats->m_promotion_earned >= 0) {
p_stats->rank = stats->m_promotion_earned;
}
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_backup = p_stats->last_flown;
p_stats->last_flown = stats->last_flown;
p_stats->missions_flown++;
// badges
if (stats->m_badge_earned >= 0) {
list_size = (int)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) ) {
j = idx;
break;
}
}
if (j >= 0) {
p_stats->medals_earned[j].val = 1;
} else {
ilist.name = Medals[stats->m_badge_earned].name;
ilist.val = 1;
p_stats->medals_earned.push_back(ilist);
}
}
// ship kills
for (idx = 0; idx < Num_ship_classes; idx++) {
if (stats->m_okKills[idx] > 0) {
list_size = (int)p_stats->ship_kills.size();
j = -1;
for (i = 0; i < list_size; i++) {
if ( p_stats->ship_kills[i].name.compare(Ship_info[idx].name) ) {
j = i;
break;
}
}
if (j >= 0) {
p_stats->ship_kills[j].val += stats->m_okKills[idx];
} else {
ilist.name = Ship_info[idx].name;
ilist.val = stats->m_okKills[idx];
p_stats->ship_kills.push_back(ilist);
}
}
}
}
|