annotate ratings.c @ 3:5a977ccbc7a9 default tip

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