File: stats.cpp

package info (click to toggle)
freespace2 3.7.4%2Brepack-1.1
  • links: PTS, VCS
  • area: non-free
  • in suites: bullseye
  • size: 22,268 kB
  • sloc: cpp: 393,535; ansic: 4,106; makefile: 1,091; xml: 181; sh: 137
file content (321 lines) | stat: -rw-r--r-- 9,788 bytes parent folder | download | duplicates (2)
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
/*
 * Copyright (C) Volition, Inc. 1999.  All rights reserved.
 *
 * All source code herein is the property of Volition, Inc. You may not sell 
 * or otherwise commercially exploit the source or things you created based on the 
 * source.
 *
*/




#ifdef _WIN32
#include <io.h>
#include <winsock.h>
#endif

#include "globalincs/systemvars.h"
#include "hud/hud.h"
#include "network/multi.h"
#include "playerman/player.h"
#include "stats/stats.h"


#define MISSION_STATS_START_Y 80
#define ALLTIME_STATS_START_Y 270
#define MULTIPLAYER_LIST_START 20


player *Active_player;

void show_stats_init()
{
	if (Game_mode & GM_MULTIPLAYER) {				
		set_player_stats(MY_NET_PLAYER_NUM);
	} else {
		Active_player = Player;		
	}	
}

// write out the label for each stat
void show_stats_label(int stage, int sx, int sy, int dy)
{
	switch ( stage ) {
		case MISSION_STATS:
			gr_printf_menu(sx,sy,XSTR( "Mission Stats", 114));
			sy += 2*dy;
			gr_printf_menu(sx,sy,XSTR( "Total kills", 115));
			sy += 2*dy;
			gr_printf_menu(sx,sy,XSTR( "Primary weapon shots", 116));
			sy += dy;
			gr_printf_menu(sx,sy,XSTR( "Primary weapon hits", 117));
			sy += dy;
			gr_printf_menu(sx,sy,XSTR( "Primary friendly hits", 118));
			sy += dy;
			gr_printf_menu(sx,sy,XSTR( "Primary hit %%", 119));
			sy += dy;
			gr_printf_menu(sx,sy,XSTR( "Primary friendly hit %%", 120));
			sy += 2*dy;

			gr_printf_menu(sx,sy,XSTR( "Secondary weapon shots", 121));
			sy += dy;
			gr_printf_menu(sx,sy,XSTR( "Secondary weapon hits", 122));
			sy += dy;
			gr_printf_menu(sx,sy,XSTR( "Secondary friendly hits", 123));
			sy += dy;
			gr_printf_menu(sx,sy,XSTR( "Secondary hit %%", 124));
			sy += dy;
			gr_printf_menu(sx,sy,XSTR( "Secondary friendly hit %%", 125));
			sy += 2*dy;

			gr_printf_menu(sx,sy,XSTR( "Assists", 126));
			sy += 2*dy;

			if(Game_mode & GM_MULTIPLAYER){
				gr_printf_menu(sx,sy,XSTR( "Player Deaths", 127));
				sy += 2*dy;

				gr_printf_menu(sx,sy,XSTR( "Mission score", 1526));
			}


			break;

		case ALL_TIME_STATS:
			gr_printf_menu(sx,sy,XSTR( "All Time Stats", 128));
			sy += 2*dy;			
			gr_printf_menu(sx,sy,XSTR( "Total kills", 115));
			sy += 2*dy;
			gr_printf_menu(sx,sy,XSTR( "Primary weapon shots", 116));
			sy += dy;
			gr_printf_menu(sx,sy,XSTR( "Primary weapon hits", 117));
			sy += dy;
			gr_printf_menu(sx,sy,XSTR( "Primary friendly hits", 118));
			sy += dy;
			gr_printf_menu(sx,sy,XSTR( "Primary hit %%", 119));
			sy += dy;
			gr_printf_menu(sx,sy,XSTR( "Primary friendly hit %%", 120));
			sy += 2*dy;

			gr_printf_menu(sx,sy,XSTR( "Secondary weapon shots", 121));
			sy += dy;
			gr_printf_menu(sx,sy,XSTR( "Secondary weapon hits", 122));
			sy += dy;
			gr_printf_menu(sx,sy,XSTR( "Secondary friendly hits", 123));
			sy += dy;
			gr_printf_menu(sx,sy,XSTR( "Secondary hit %%", 124));
			sy += dy;
			gr_printf_menu(sx,sy,XSTR( "Secondary friendly hit %%", 125));
			sy += 2*dy;			

			gr_printf_menu(sx,sy,XSTR( "Assists", 126));
			sy += 2*dy;

			if(Game_mode & GM_MULTIPLAYER){
				gr_printf_menu(sx,sy,XSTR( "Score", 1527));
			}
			break;
		} // end switch
}

void stats_underline_text(int sx, int sy, char *text)
{
	int w,h,fh;

	gr_get_string_size(&w,&h,text);
	fh=gr_get_font_height();
	gr_line(sx-1, sy+fh, sx+w+1, sy+fh, GR_RESIZE_MENU);
}

void show_stats_numbers(int stage, int sx, int sy, int dy,int add_mission)
{
   char		text[30];
	float		pct;

	sy += 2*dy;
	switch ( stage ) {
		case MISSION_STATS:
         // mission kills stats
			sprintf(text,"%d",Active_player->stats.m_kill_count_ok);
			gr_printf_menu(sx,sy,text);
			sy += 2*dy;
         // mission primary weapon stats
			sprintf(text,"%u",Active_player->stats.mp_shots_fired);
			gr_printf_menu(sx,sy,text);
			sy += dy;
			sprintf(text,"%u",Active_player->stats.mp_shots_hit);
			gr_printf_menu(sx,sy,text);
			sy += dy;
			sprintf(text,"%u",Active_player->stats.mp_bonehead_hits);
			gr_printf_menu(sx,sy,text);
			sy += dy;
			if(Active_player->stats.mp_shots_fired>0)
				pct=(float)100.0*((float)Active_player->stats.mp_shots_hit/(float)Active_player->stats.mp_shots_fired);
			else pct=(float)0.0;
			sprintf(text,"%d",(int)pct); strcat_s(text," %%");
			gr_printf_menu(sx,sy,text);
			sy += dy;
			if(Active_player->stats.mp_shots_fired>0)
				pct=(float)100.0*((float)Active_player->stats.mp_bonehead_hits/(float)Active_player->stats.mp_shots_fired);
			else pct=(float)0.0;
			sprintf(text,"%d",(int)pct); strcat_s(text," %%");
			gr_printf_menu(sx,sy,text);
			sy += 2*dy;

			// mission secondary weapon stats
			sprintf(text,"%u",Active_player->stats.ms_shots_fired);
			gr_printf_menu(sx,sy,text);
			sy += dy;
			sprintf(text,"%u",Active_player->stats.ms_shots_hit);
			gr_printf_menu(sx,sy,text);
			sy += dy;
			sprintf(text,"%u",Active_player->stats.ms_bonehead_hits);
			gr_printf_menu(sx,sy,text);
			sy += dy;
			if(Active_player->stats.ms_shots_fired>0)
				pct=(float)100.0*((float)Active_player->stats.ms_shots_hit/(float)Active_player->stats.ms_shots_fired);
			else pct=(float)0.0;
			sprintf(text,"%d",(int)pct); strcat_s(text," %%");
			gr_printf_menu(sx,sy,text);
			sy += dy;
			if(Active_player->stats.ms_shots_fired>0)
				pct=(float)100.0*((float)Active_player->stats.ms_bonehead_hits/(float)Active_player->stats.ms_shots_fired);
			else pct=(float)0.0;
			sprintf(text,"%d",(int)pct); strcat_s(text," %%");
			gr_printf_menu(sx,sy,text);
			sy += 2*dy;

			// mission assists and player rescues (respawns)
			sprintf(text,"%d",(int)Active_player->stats.m_assists);
			gr_printf_menu(sx,sy,text);
			sy += 2*dy;

			if(Game_mode & GM_MULTIPLAYER){
				sprintf(text,"%d",(int)Active_player->stats.m_player_deaths);
				gr_printf_menu(sx,sy,text);
				sy += 2*dy;

				// mission score
				gr_printf_menu(sx, sy, "%d", (int)Active_player->stats.m_score);
			}


			break;

		case ALL_TIME_STATS:
			 scoring_struct add;
			
			// if we are passed mission_add (the stats for the current mission), copy it to "add", otherwise,
			// leave it blank
			if (add_mission) {
				add.kill_count_ok = Active_player->stats.m_kill_count_ok;
				add.p_shots_fired  = Active_player->stats.mp_shots_fired;
				add.p_shots_hit = Active_player->stats.mp_shots_hit;
				add.p_bonehead_hits = Active_player->stats.mp_bonehead_hits;				
				
				add.s_shots_fired = Active_player->stats.ms_shots_fired;
				add.s_shots_hit = Active_player->stats.ms_shots_hit;
				add.s_bonehead_hits = Active_player->stats.ms_bonehead_hits;				
			}			

         // mission kills stats
			sprintf(text,"%d",Active_player->stats.kill_count_ok + add.kill_count_ok);
			hud_num_make_mono(text, gr_get_current_fontnum());
			gr_printf_menu(sx,sy,text);
			sy += 2*dy;
         // alltime primary weapon stats
			sprintf(text,"%u",Active_player->stats.p_shots_fired + add.p_shots_fired);
			gr_printf_menu(sx,sy,text);
			sy += dy;
			sprintf(text,"%u",Active_player->stats.p_shots_hit + add.p_shots_hit);
			gr_printf_menu(sx,sy,text);
			sy += dy;
			sprintf(text,"%u",Active_player->stats.p_bonehead_hits + add.p_bonehead_hits);
			gr_printf_menu(sx,sy,text);
			sy += dy;
			if((Active_player->stats.p_shots_fired + add.p_shots_fired)>0)
				pct=(float)100.0*((float)(Active_player->stats.p_shots_hit+add.p_shots_hit)/(float)(Active_player->stats.p_shots_fired + add.p_shots_fired));
			else pct=(float)0.0;
			sprintf(text,"%d",(int)pct); strcat_s(text," %%");
			gr_printf_menu(sx,sy,text);
			sy += dy;
			if((Active_player->stats.p_bonehead_hits + add.p_bonehead_hits)>0)
				pct=(float)100.0*((float)(Active_player->stats.p_bonehead_hits+add.p_bonehead_hits)/(float)(Active_player->stats.p_shots_fired + add.p_shots_fired));
			else pct=(float)0.0;
			sprintf(text,"%d",(int)pct); strcat_s(text," %%");
			gr_printf_menu(sx,sy,text);
			sy += 2*dy;

			// alltime secondary weapon stats
			sprintf(text,"%u",Active_player->stats.s_shots_fired + add.s_shots_fired);
			gr_printf_menu(sx,sy,text);
			sy += dy;
			sprintf(text,"%u",Active_player->stats.s_shots_hit + add.s_shots_hit);
			gr_printf_menu(sx,sy,text);
			sy += dy;
			sprintf(text,"%u",Active_player->stats.s_bonehead_hits + add.s_bonehead_hits);
			gr_printf_menu(sx,sy,text);
			sy += dy;
			if((Active_player->stats.s_shots_fired+add.s_shots_fired)>0)
				pct=(float)100.0*((float)(Active_player->stats.s_shots_hit + add.s_shots_hit)/(float)(Active_player->stats.s_shots_fired + add.s_shots_fired));
			else pct=(float)0.0;
			sprintf(text,"%d",(int)pct); strcat_s(text," %%");
			gr_printf_menu(sx,sy,text);
			sy += dy;
			if((Active_player->stats.s_bonehead_hits + add.s_bonehead_hits)>0)
				pct=(float)100.0*((float)(Active_player->stats.s_bonehead_hits+add.s_bonehead_hits)/(float)(Active_player->stats.s_shots_fired+add.s_shots_fired));
			else pct=(float)0.0;
			sprintf(text,"%d",(int)pct); strcat_s(text," %%");
			gr_printf_menu(sx,sy,text);
			sy += 2*dy;

			// alltime assists
			sprintf(text,"%d",(int)Active_player->stats.assists + add.assists);
			gr_printf_menu(sx,sy,text);
			sy += 2*dy;

			if (Game_mode & GM_MULTIPLAYER) {
				gr_printf_menu(sx, sy, "%d", (int)Active_player->stats.score);
			}
			break;
	} // end switch
}

int find_netplayer_n(int n)
{
	int idx;
	int target;
   target = n;
	n=0;
   for(idx=0;idx<MAX_PLAYERS;idx++){
		if(MULTI_CONNECTED(Net_players[idx])){
			n++;
			if(n == target)
				return idx;
		}
	}
	return -1;
}


void show_stats_close()
{	
}
 
// initialize the statistics portion of the player structure for multiplayer.  Only the host of
// a netgame needs to be doing this (and if fact, only he *should* be doing this)
void init_multiplayer_stats( )
{
	scoring_struct *ptr;

	for (int idx=0; idx < MAX_PLAYERS; idx++) {
		ptr = &Players[idx].stats;
		scoring_level_init( ptr );
	}
}

void set_player_stats(int pid)
{
   Active_player = Net_players[pid].m_player;
}