1 /*
2  * XPilot NG, a multiplayer space war game.
3  *
4  * Copyright (C) 1999-2004 by
5  *
6  *      Marcus Sundberg      <mackan@stacken.kth.se>
7  *      Kristian S�derblom   <kps@users.sourceforge.net>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23 
24 #ifndef RANK_H
25 #define RANK_H
26 
27 #include "xpcommon.h"
28 
29 #ifndef PLAYER_H
30 /* need player */
31 #include "player.h"
32 #endif
33 
34 typedef struct ranknode {
35 
36     char name[MAX_NAME_LEN];
37     char user[MAX_NAME_LEN];
38     char host[MAX_HOST_LEN];
39 
40     time_t timestamp;
41 
42     int kills, deaths;
43     int rounds, shots;
44     int deadliest;
45     int ballsCashed, ballsSaved;
46     int ballsWon, ballsLost;
47     double bestball;
48     double score;
49     player_t *pl;
50     double max_survival_time;
51 } ranknode_t;
52 
53 bool Rank_get_stats(const char *name, char *buf, size_t size);
54 ranknode_t *Rank_get_by_name(const char *name);
55 void Rank_init_saved_scores(void);
56 void Rank_get_saved_score(player_t *pl);
57 void Rank_save_score(player_t *pl);
58 void Rank_write_rankfile(void);
59 void Rank_write_webpage(void);
60 void Rank_show_ranks(void);
61 
Rank_add_score(player_t * pl,double points)62 static inline void Rank_add_score(player_t *pl, double points)
63 {
64     Add_Score(pl,points);
65     pl->update_score = true;
66     if (pl->rank)
67 	pl->rank->score += points;
68 }
69 
Rank_set_score(player_t * pl,double points)70 static inline void Rank_set_score(player_t *pl, double points)
71 {
72     Set_Score(pl,points);
73     pl->update_score = true;
74     if (pl->rank)
75 	pl->rank->score = points;
76 }
77 
Rank_fire_shot(player_t * pl)78 static inline void Rank_fire_shot(player_t *pl)
79 {
80     pl->shots++;
81     if (pl->rank)
82 	pl->rank->shots++;
83 }
84 
Rank_add_kill(player_t * pl)85 static inline void Rank_add_kill(player_t *pl)
86 {
87     pl->kills++;
88     if (pl->rank)
89 	pl->rank->kills++;
90 }
91 
Rank_add_death(player_t * pl)92 static inline void Rank_add_death(player_t *pl)
93 {
94     pl->deaths++;
95     if (pl->rank)
96 	pl->rank->deaths++;
97 }
98 
Rank_add_round(player_t * pl)99 static inline void Rank_add_round(player_t *pl)
100 {
101     if (pl->rank)
102 	pl->rank->rounds++;
103 }
104 
Rank_add_deadliest(player_t * pl)105 static inline void Rank_add_deadliest(player_t *pl)
106 {
107     if (pl->rank)
108 	pl->rank->deadliest++;
109 }
110 
Rank_cashed_ball(player_t * pl)111 static inline void Rank_cashed_ball(player_t *pl)
112 {
113     if (pl->rank)
114 	pl->rank->ballsCashed++;
115 }
116 
Rank_saved_ball(player_t * pl)117 static inline void Rank_saved_ball(player_t *pl)
118 {
119     if (pl->rank)
120 	pl->rank->ballsSaved++;
121 }
122 
Rank_won_ball(player_t * pl)123 static inline void Rank_won_ball(player_t *pl)
124 {
125     if (pl->rank)
126 	pl->rank->ballsWon++;
127 }
128 
Rank_lost_ball(player_t * pl)129 static inline void Rank_lost_ball(player_t *pl)
130 {
131     if (pl->rank)
132 	pl->rank->ballsLost++;
133 }
134 
Rank_ballrun(player_t * pl,double tim)135 static inline void Rank_ballrun(player_t *pl, double tim)
136 {
137     if (pl->rank) {
138 	if (pl->rank->bestball == 0.0 || tim < pl->rank->bestball)
139 	    pl->rank->bestball = tim;
140     }
141 }
142 
Rank_survival(player_t * pl,double tim)143 static inline void Rank_survival(player_t *pl, double tim)
144 {
145     if (pl->rank) {
146         if (pl->rank->max_survival_time == 0
147             || tim > pl->rank->max_survival_time)
148 	    pl->rank->max_survival_time = tim;
149     }
150 }
151 
152 
Rank_get_max_survival_time(player_t * pl)153 static inline double Rank_get_max_survival_time(player_t *pl)
154 {
155     return pl->rank ? pl->rank->max_survival_time : 0;
156 }
157 
158 
Rank_get_best_ballrun(player_t * pl)159 static inline double Rank_get_best_ballrun(player_t *pl)
160 {
161     return pl->rank ? pl->rank->bestball : 0.0;
162 }
163 
Rank_add_ball_kill(player_t * pl)164 static inline void Rank_add_ball_kill(player_t *pl)      { Rank_add_kill(pl); }
Rank_add_explosion_kill(player_t * pl)165 static inline void Rank_add_explosion_kill(player_t *pl) { Rank_add_kill(pl); }
Rank_add_laser_kill(player_t * pl)166 static inline void Rank_add_laser_kill(player_t *pl)     { Rank_add_kill(pl); }
Rank_add_runover_kill(player_t * pl)167 static inline void Rank_add_runover_kill(player_t *pl)   { Rank_add_kill(pl); }
Rank_add_shot_kill(player_t * pl)168 static inline void Rank_add_shot_kill(player_t *pl)      { Rank_add_kill(pl); }
Rank_add_shove_kill(player_t * pl)169 static inline void Rank_add_shove_kill(player_t *pl)     { Rank_add_kill(pl); }
Rank_add_tank_kill(player_t * pl)170 static inline void Rank_add_tank_kill(player_t *pl)      { Rank_add_kill(pl); }
Rank_add_target_kill(player_t * pl)171 static inline void Rank_add_target_kill(player_t *pl)    { Rank_add_kill(pl); }
Rank_add_treasure_kill(player_t * pl)172 static inline void Rank_add_treasure_kill(player_t *pl)  { Rank_add_kill(pl); }
173 
174 
175 #endif /* RANK_H */
176