]> icculus.org git repositories - taylor/freespace2.git/blob - include/scoring.h
proper padding of PXO stats struct for FS2 demo
[taylor/freespace2.git] / include / scoring.h
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
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
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/Stats/Scoring.h $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * Scoring system structures, medals, rank, etc.
16  *
17  * $Log$
18  * Revision 1.5  2005/03/29 02:18:47  taylor
19  * Various 64-bit platform fixes
20  * Fix compiler errors with MAKE_FS1 and fix gr_set_bitmap() too
21  * Make sure that turrets can fire at asteroids for FS1 (needed for a couple missions)
22  * Streaming audio support (big thanks to Pierre Willenbrock!!)
23  * Removed dependance on strings.tbl for FS1 since we don't actually need it now
24  *
25  * Revision 1.4  2003/06/11 18:30:32  taylor
26  * plug memory leaks
27  *
28  * Revision 1.3  2003/05/25 02:30:42  taylor
29  * Freespace 1 support
30  *
31  * Revision 1.2  2002/06/09 04:41:14  relnev
32  * added copyright header
33  *
34  * Revision 1.1.1.1  2002/05/03 03:28:12  root
35  * Initial import.
36  *
37  * 
38  * 6     8/30/99 5:01p Dave
39  * Made d3d do less state changing in the nebula. Use new chat server for
40  * PXO.
41  * 
42  * 5     8/26/99 8:49p Jefff
43  * Updated medals screen and about everything that ever touches medals in
44  * one way or another.  Sheesh.
45  * 
46  * 4     2/23/99 2:29p Dave
47  * First run of oldschool dogfight mode. 
48  * 
49  * 3     1/29/99 2:08a Dave
50  * Fixed beam weapon collisions with players. Reduced size of scoring
51  * struct for multiplayer. Disabled PXO.
52  * 
53  * 2     10/07/98 10:54a Dave
54  * Initial checkin.
55  * 
56  * 1     10/07/98 10:51a Dave
57  * 
58  * 32    9/15/98 11:44a Dave
59  * Renamed builtin ships and wepaons appropriately in FRED. Put in scoring
60  * scale factors. Fixed standalone filtering of MD missions to non-MD
61  * hosts.
62  * 
63  * 31    5/15/98 9:52p Dave
64  * Added new stats for freespace. Put in artwork for viewing stats on PXO.
65  * 
66  * 30    5/15/98 4:12p Allender
67  * removed redbook code.  Put back in ingame join timer.  Major fixups for
68  * stats in multiplayer.  Pass correct score, medals, etc when leaving
69  * game.  Be sure clients display medals, badges, etc.
70  * 
71  * 29    5/06/98 3:15p Allender
72  * fixed some ranking problems.  Made vasudan support ship available in
73  * multiplayer mode.
74  * 
75  * 28    5/05/98 2:10p Dave
76  * Verify campaign support for testing. More new tracker code.
77  * 
78  * 27    4/27/98 6:02p Dave
79  * Modify how missile scoring works. Fixed a team select ui bug. Speed up
80  * multi_lag system. Put in new main hall.
81  * 
82  * 26    4/21/98 11:55p Dave
83  * Put in player deaths statskeeping. Use arrow keys in the ingame join
84  * ship select screen. Don't quit the game if in the debriefing and server
85  * leaves.
86  * 
87  * 25    4/21/98 4:44p Dave
88  * Implement Vasudan ships in multiplayer. Added a debug function to bash
89  * player rank. Fixed a few rtvoice buffer overrun problems. Fixed ui
90  * problem in options screen. 
91  * 
92  * 24    4/13/98 4:19p Hoffoss
93  * Added rank voice file support.
94  * 
95  * 23    3/09/98 5:54p Dave
96  * Fixed stats to take asteroid hits into account. Polished up UI stuff in
97  * team select. Finished up pilot info popup. Tracked down and fixed
98  * double click bug.
99  * 
100  * 22    3/09/98 4:30p Allender
101  * multiplayer secondary weapon changes.  red-alert and cargo-known-delay
102  * sexpressions.  Add time cargo revealed to ship structure
103  * 
104  * 21    3/02/98 4:24p Allender
105  * change how scoring works.  Call scoring level close when debriefing is
106  * initialized.  Made a "backout" function when mission is not accepted.
107  * 
108  * 20    2/05/98 5:34p Hoffoss
109  * Changed code to allow each rank promotion to have it's own specific
110  * debriefing text.
111  * 
112  * 19    2/04/98 6:36p Dave
113  * Changed how stats are handled for net players.
114  * 
115  * 18    2/02/98 4:59p Hoffoss
116  * Added a promotion text field to rank.tbl and code to support it in
117  * FreeSpace.
118  * 
119  * 17    1/27/98 5:01p Dave
120  * Put in support for leaving multiplayer games in the pause state. Fixed
121  * a popup bug which freed saved screens incorrectly. Reworked scoring
122  * kill and assist evaluation.
123  * 
124  * 16    1/27/98 4:23p Allender
125  * enhanced internal scoring mechanisms.
126  * 
127  * 15    12/31/97 2:52p Hoffoss
128  * Added award window stuff to debriefing screen.
129  * 
130  * 14    12/10/97 4:45p Dave
131  * Added in more detailed support for multiplayer packet lag/loss. Fixed
132  * some multiplayer stuff. Added some controls to the standalone.
133  * 
134  * 13    11/18/97 5:30p Dave
135  * Reorganized some stats code. Made sure that mission stats (single and
136  * multi) are only merged with alltime stats at the proper times.
137  * 
138  * 12    11/06/97 4:39p Allender
139  * a ton of medal work.  Removed an uneeded elemen in the scoring
140  * structure.  Fix up medals screen to apprioriate display medals (after
141  * mask was changed).  Fix Fred to only display medals which may actually
142  * be granted.  Added image_filename to player struct for Jason Hoffoss
143  * 
144  * 11    11/06/97 9:54a Dave
145  * Dependant checkin
146  * 
147  * 10    11/05/97 4:43p Allender
148  * reworked medal/rank system to read all data from tables.  Made Fred
149  * read medals.tbl.  Changed ai-warp to ai-warp-out which doesn't require
150  * waypoint for activation
151  * 
152  * 9     11/04/97 11:21p Allender
153  * added gramt-promotion and grant-medal sexpressions.  Changed MAX_MEDALS
154  * to NUM_MEDALS and made it be the correct number.  Temporaritly move
155  * medal names to missionparse.cpp so Fred could get at them
156  * 
157  * 8     9/25/97 4:57p Dave
158  * Finished up work on assigning kills and assists in player (and
159  * multiplayer) stats.
160  * 
161  * 7     9/24/97 5:03p Dave
162  * Beginning changes on how kills/assists are evaluated in both single and
163  * multiplayer
164  * 
165  * 6     9/18/97 10:14p Dave
166  * Updated the scoring system struct. Added rank.tbl. Modified how medal
167  * names are displayed.
168  * 
169  * 5     9/18/97 9:21a Dave
170  * Added view medals state. Changed pilot scoring struct to reflect.
171  * 
172  * 4     7/25/97 4:32p Dave
173  * Added bonehead stats management.
174  * 
175  * 3     7/24/97 2:59p Dave
176  * modified the scoring_struct type, and its corresponding init function
177  * 
178  * 2     5/01/97 10:24a Hoffoss
179  * Created new scoring structure, and added code to save/restore it
180  * to/from pilot file.
181  * 
182  * 1     4/30/97 10:19a Hoffoss
183  *
184  * $NoKeywords: $
185  */
186
187 #ifndef _SCORING_HEADER_FILE
188 #define _SCORING_HEADER_FILE
189
190 #include "ship.h"
191 #include "weapon.h"
192
193 struct player;
194
195 // ARGH. IMPORTANT : do not change NUM_MEDALS without talking to DaveB first. It will affect the size of the scoring struct and hence, will break
196 // a lot of PXO related stuff. SEE ALSO : MAX_SHIP_TYPES
197 #ifdef FS2_DEMO
198         #define NUM_MEDALS                      16
199         #define NUM_MEDALS_FS1          16
200 #elif MAKE_FS1
201         #define NUM_MEDALS                      16
202         #define NUM_MEDALS_FS1          16
203 #else
204         #define NUM_MEDALS                      18
205         #define NUM_MEDALS_FS1          16
206 #endif
207
208 #define NUM_RANKS                               10
209
210 #define RANK_ENSIGN                             0
211 #define RANK_LT_JUNIOR                  1
212 #define RANK_LT                                 2
213 #define RANK_LT_CMDR                            3
214 #define RANK_CMDR                                       4
215 #define RANK_CAPTAIN                            5
216 #define RANK_COMMODORE                  6
217 #define RANK_REAR_ADMIRAL               7
218 #define RANK_VICE_ADMIRAL               8
219 #define RANK_ADMIRAL                    9
220
221 #define MAX_FREESPACE1_RANK     RANK_COMMODORE
222 #define MAX_FREESPACE2_RANK     RANK_ADMIRAL
223
224 /*
225         The ins and outs of when/where stats are stored and retreived - BE SURE TO FOLLOW THESE GUIDELINES
226
227    SINGLE PLAYER :
228                 scoring_level_init() is called from game_level_init(). This zeroes out mission specific stats
229                 scoring_level_close() is called from the debriefing screen when the player hits accept. This saves the mission
230                         stats to alltime stats, and updates any campaign stats
231                 NOTE : in single player mode, if the player is going back to replay an old mission, the stats shouldn't be 
232                         stored again
233
234    MULTI PLAYER :
235                 scoring_level_init() is called in game_level_init() again.
236                 init_multiplayer_stats() is called on all computers in the game when moving _into_ the MISSION_SYNC state
237
238                 scoring_level_close() is called on all machines when the host selects accept. If the host is not on the standalone
239                         he sends a packet to all players indicating that they should save their data. If he _is_ on the standalone, he should 
240                         send only to the standalone, and then it rebroadcasts the packet ot everyone else.              
241 */
242
243
244 typedef struct rank_stuff {
245         char            name[NAME_LENGTH];              // name of this rank
246         char            *promotion_text;                        // text to display when promoted to this rank
247         int             points;                                         // points needed to reach this rank
248         char            bitmap[NAME_LENGTH];            // bitmap of this rank medal
249         char            promotion_voice_base[MAX_FILENAME_LEN - 1];
250 } rank_stuff;
251
252 #define STATS_FLAG_INVALID                      (1<<0)
253 #define STATS_FLAG_CAMPAIGN             (1<<1)
254 #define STATS_FLAG_MULTIPLAYER  (1<<2)
255
256 typedef struct scoring_struct {
257         int flags;
258
259         // All-time total
260         int score;                                                              // all time score
261         int rank;                                                               // all time rank
262         int medals[NUM_MEDALS];                         // all time medal counts
263
264 #ifdef MAKE_FS1
265         int kills[MAX_SHIP_TYPES];                      // only valid kills (i.e. not on friendlies).
266 #else
267         ushort kills[MAX_SHIP_TYPES];           // only valid kills (i.e. not on friendlies).
268 #endif
269         int assists;                                                    // alltime assists
270         int kill_count;                                         // total alltime kills
271         int kill_count_ok;                                      // total valid alltime kills (no friendlies)
272         unsigned int p_shots_fired;             // primary weapon shots fired
273         unsigned int s_shots_fired;             // secondary weapon shots fired
274
275         unsigned int p_shots_hit;                       // primary weapon shots hit
276         unsigned int s_shots_hit;                       // secondary weapon shots hit
277
278         unsigned int p_bonehead_hits;           // alltime primary friendly hits
279         unsigned int s_bonehead_hits;           // alltime secondary friendly hits
280    int          bonehead_kills;         // alltime friendly kills
281
282         unsigned int missions_flown;            // total # of missions flown
283         unsigned int flight_time;                       // total # of flight hours the player has
284         fs_time_t last_flown;                                   // last time the player has flown
285         fs_time_t last_backup;                                  // so we can easily call scoring_level_backout()
286
287         // Mission total
288         int m_medal_earned;                                     // which medal (if any) earned this mission
289         int m_badge_earned;                                     // which badge was earned.  Calculated after mission is over
290         int m_promotion_earned;                         // was a promotion earned.  Calculated after mission is over
291
292         int m_score;
293 #ifdef MAKE_FS1
294         int m_kills[MAX_SHIP_TYPES];     // this will represent all kills in the mission (bonehead or not)
295         int m_okKills[MAX_SHIP_TYPES];   // this will be only the "valid" kills the player made
296 #else
297         ushort m_kills[MAX_SHIP_TYPES];     // this will represent all kills in the mission (bonehead or not)
298         ushort m_okKills[MAX_SHIP_TYPES];   // this will be only the "valid" kills the player made
299 #endif
300         int m_kill_count;                                               // total kills for this mission
301         int m_kill_count_ok;             // total (non-friendly) kills for this mission
302         int m_assists;                                                  // player assits for the mission
303    unsigned int mp_shots_fired;         // primary shots fired for the mission
304         unsigned int ms_shots_fired;            // secondary shots fired for the mission
305         unsigned int mp_shots_hit;                      // primary shots hit for the mission
306         unsigned int ms_shots_hit;                      // secondary shots hit for the mission
307         unsigned int mp_bonehead_hits;  // primary friendly hits for the mission
308         unsigned int ms_bonehead_hits;  // secondary friendly hits for the mission
309         int m_bonehead_kills;                           // # of friendly kills for the mission
310         int m_player_deaths;                                    // player deaths for the mission (really only useful for multiplayer)
311
312 #ifndef MAKE_FS1
313         // kills by player for multiplayer dogfight
314         ushort m_dogfight_kills[MAX_PLAYERS];
315 #endif
316 } scoring_struct;
317
318 extern rank_stuff Ranks[NUM_RANKS];
319
320 void init_scoring_element(scoring_struct *s);
321
322 void parse_rank_tbl();
323 void scoring_tbl_close();
324 void scoring_level_init( scoring_struct *score );
325 void scoring_level_close(int accepted = 1);
326 void scoring_backout_accept( scoring_struct *score );
327 void scoring_do_accept( scoring_struct *score );
328
329 // function to give a medal to a player if he earned it
330 void scoring_check_medal(scoring_struct *sc);
331
332 void scoring_add_damage(object *ship_obj,object *other_obj,float damage);
333 void scoring_eval_kill(object *ship_obj);
334 void scoring_eval_assists(ship *sp,int killer_sig);
335
336 // bash the passed player to the specified rank
337 void scoring_bash_rank(player *pl,int rank);
338
339 // eval a hit on an object (for primary and secondary hit purposes)
340 void scoring_eval_hit(object *hit_obj, object *other_obj, int from_blast = 0);
341
342 // get a scaling factor for adding/subtracting from mission score
343 float scoring_get_scale_factor();
344
345 #endif
346