comparison ratings.c @ 3:5a977ccbc7a9 default tip

Empty changelog
author darius
date Sat, 06 Dec 1997 05:41:29 +0000
parents
children
comparison
equal deleted inserted replaced
2:fba0b6e6cdc7 3:5a977ccbc7a9
1 /* $Id: ratings.c,v 1.1.1.1 1997/12/06 05:41:30 darius Exp $ */
2
3 /*
4 * ratings.c, 2/13/94 Bill Dyess
5 */
6 #include "copyright.h"
7
8 #include <stdio.h>
9 #include <math.h>
10 #include "Wlib.h"
11 #include "defs.h"
12 #include "struct.h"
13 #include "data.h"
14 #include "gameconf.h"
15
16 /*
17 fills the ratings struct pointed to by r with the stats for the player
18 pointed to by j [BDyess]
19 */
20 struct ratings *
21 get_ratings(j, r)
22 struct player *j;
23 struct ratings *r;
24 {
25 if (paradise) {
26 struct stats2 *s; /* point to player's paradise stats */
27 float t, t2; /* temps */
28
29 s = &(j->p_stats2);
30 /* fill in kills, losses, and maxkills based on ship type */
31 if (j->p_ship->s_type == STARBASE) {
32 r->r_kills = s->st_sbkills;
33 r->r_losses = s->st_sblosses;
34 r->r_maxkills = s->st_sbmaxkills;
35 } else if (j->p_ship->s_type == WARBASE) {
36 r->r_kills = s->st_wbkills;
37 r->r_losses = s->st_wblosses;
38 r->r_maxkills = s->st_wbmaxkills;
39 } else {
40 r->r_kills = s->st_tkills;
41 r->r_losses = s->st_tlosses;
42 r->r_maxkills = s->st_tmaxkills;
43 }
44 /* calculate ratio */
45 r->r_ratio = (r->r_losses != 0) ? r->r_kills / (float) r->r_losses
46 : r->r_kills;
47 /*
48 r->r_ratio = (s->st_tlosses != 0) ? (float) s->st_tkills / (float)
49 s->st_tlosses : s->st_tkills;
50 */
51 if(!status2->timeprod)
52 t = s->st_tticks;
53 else
54 t = (float) s->st_tticks / (float) status2->timeprod; /* hour ratio */
55 if (t == 0.0)
56 t = 1.0;
57 t2 = t * (float) status2->losses; /* get expected losses */
58 if(t2 == 0) t2=1;
59 r->r_defrat = s->st_tlosses / t2; /* calc defense rating */
60
61 t2 = t * (float) status2->kills; /* get expected kills */
62 if(t2 == 0) t2=1;
63 r->r_offrat = s->st_tkills / t2; /* calc offense rating */
64
65 t2 = t * (float) status2->armsbomb; /* expected armies bombed */
66 if(t2 == 0) t2=1;
67 r->r_bombrat = (float) s->st_tarmsbomb / t2; /* bomb rating */
68
69 t2 = t * (float) status2->resbomb; /* expected resources bmbd */
70 if(t2 == 0) t2=1;
71 r->r_resrat = (float) s->st_tresbomb / t2; /* resrce bmbd rating */
72
73 t2 = t * (float) status2->dooshes; /* expected armies dooshed */
74 if(t2 == 0) t2=1;
75 r->r_dooshrat = (float) s->st_tdooshes / t2; /* doosh rating */
76
77 r->r_batrat = r->r_dooshrat + r->r_offrat; /* get battle rating */
78
79 t2 = t * (float) status2->planets; /* expected planets */
80 if(t2 == 0) t2=1;
81 r->r_planetrat = (float) s->st_tplanets / t2; /* get planet rating */
82 /* strategy rating */
83 r->r_stratrat = r->r_bombrat + r->r_resrat + r->r_planetrat;
84 /* calculate sb rating */
85 t2 = (float) status2->sbkills / (float)( (status2->sblosses > 0) ? status2->sblosses : 1);
86 if (s->st_sblosses == 0)
87 r->r_sbrat = 0.0;
88 else
89 r->r_sbrat = ((float) s->st_sbkills / (float) s->st_sblosses) / t2;
90 /* calculate wb rating */
91 t2 = (float) status2->wbkills / (float)( (status2->wblosses > 0) ? status2->wblosses : 1);
92 if (s->st_wblosses == 0)
93 r->r_wbrat = 0.0;
94 else
95 r->r_wbrat = ((float) s->st_wbkills / (float) s->st_wblosses) / t2;
96 /* calculate js rating */
97 t = (float) s->st_jsticks / (float)( (status2->jstime > 0) ? status2->jstime : 1);
98 t2 = t * (float) status2->jsplanets; /* get expected js planets */
99 if (t2 == 0.0)
100 r->r_jsrat = 0.0;
101 else
102 r->r_jsrat = (float) s->st_jsplanets / t2; /* js rating */
103 r->r_jsplanets = s->st_jsplanets; /* store js planets */
104
105 r->r_specrat = r->r_sbrat + r->r_wbrat + r->r_jsrat; /* get special ship
106 rating */
107 /* put the sum of the three major ratings in the 'ratings' slot */
108 r->r_ratings = r->r_specrat + r->r_batrat + r->r_stratrat;
109 r->r_genocides = s->st_genocides; /* get # genocides */
110 r->r_di = s->st_di; /* get player's DI */
111 t = (s->st_tticks) ? s->st_tticks : 1.0;
112 r->r_killsPerHour = r->r_kills * 36000.0 / t;
113 r->r_lossesPerHour = r->r_losses * 36000.0 / t;
114 r->r_planets = s->st_tplanets;
115 r->r_armies = s->st_tarmsbomb;
116 r->r_resources = s->st_tresbomb;
117 r->r_dooshes = s->st_tdooshes;
118 /* r->r_jsplanets = s->st_jsplanets; */
119 } else { /* bronco stats */
120 struct stats *s = &j->p_stats;
121
122 r->r_offrat = offenseRating(j); /* offense */
123 r->r_planetrat = planetRating(j); /* planet */
124 r->r_bombrat = bombingRating(j); /* bombing */
125 r->r_offrat = offenseRating(j); /* offense */
126 r->r_defrat = defenseRating(j); /* defense */
127 r->r_resrat = 0; /* these don't apply */
128 r->r_dooshrat = 0;
129 r->r_stratrat = 0;
130 r->r_batrat = 0;
131 r->r_sbrat = 0;
132 r->r_wbrat = 0;
133 r->r_jsrat = 0;
134 r->r_jsplanets = 0;
135 r->r_specrat = 0;
136 r->r_ratings = r->r_offrat + r->r_planetrat + r->r_bombrat; /* ratings */
137 r->r_di = r->r_ratings * s->st_tticks / 36000.0; /* di */
138 /* fill in kills, losses, and ratio based on ship type */
139 if (j->p_ship->s_type == STARBASE) {
140 r->r_kills = s->st_sbkills;
141 r->r_losses = s->st_sblosses;
142 r->r_ratio = (s->st_sblosses != 0)
143 ? (float) r->r_kills / (float) r->r_losses
144 : (float) j->p_stats.st_sbkills;
145 r->r_maxkills = j->p_stats.st_sbmaxkills;
146 } else {
147 r->r_kills = s->st_kills + s->st_tkills;
148 r->r_losses = s->st_losses + s->st_tlosses;
149 r->r_ratio = (r->r_losses != 0)
150 ? (float) r->r_kills / (float) r->r_losses
151 : r->r_kills;
152 r->r_maxkills = s->st_maxkills;
153 }
154 r->r_planets = s->st_tplanets + s->st_planets;
155 r->r_armies = s->st_armsbomb + s->st_tarmsbomb;
156 /* not recorded in bronco */
157 r->r_resources = 0;
158 /* r->r_jsplanets = 0; */
159 r->r_dooshes = 0;
160 r->r_genocides = 0;
161 }
162 return r;
163 }