1 /* ranklist.c
2  *
3  * Kevin P. Smith 12/5/88
4  *
5  */
6 #include "config.h"
7 #include "copyright2.h"
8 
9 #include <stdio.h>
10 #include "Wlib.h"
11 #include "defs.h"
12 #include "struct.h"
13 #include "data.h"
14 
15 /* Calculate DI to next rank, following server logic */
16 /* Credit: Bill Balcerski, revision 1.2, 2007/04/02 10:12:38, Netrek XP */
toNextRank(int rank)17 static float toNextRank(int rank)
18 {
19     int hourratio;
20     float rankDI, myDI, oRating, pRating, bRating, Ratings;
21 
22     /* TODO: add support for INL mode */
23     if (!strcmp(me->p_name, "guest") || !strcmp(me->p_name, "Guest"))
24         hourratio = 5;
25     else
26         hourratio = 1;
27 
28     oRating = offenseRating (me);
29     pRating = planetRating (me);
30     bRating = bombingRating (me);
31     Ratings = oRating + pRating + bRating;
32     myDI = (float) (Ratings * (me->p_stats.st_tticks / 36000.0));
33     rankDI = ranks[rank].ratings * ranks[rank].hours / hourratio;
34 
35     if (Ratings > ranks[rank].ratings)
36     {
37         if (myDI > rankDI)
38             return (0.0);
39         else
40             return (rankDI - myDI);
41     }
42     else if (Ratings > (ranks[rank-1].ratings))
43     {
44         if (myDI > 2*rankDI)
45             return (0.0);
46         else
47             return (2*rankDI - myDI);
48     }
49     else if (me->p_stats.st_rank > 0 && Ratings > (ranks[rank-2].ratings))
50     {
51         if (myDI > 4*rankDI)
52             return (0.0);
53         else
54             return (4*rankDI - myDI);
55     }
56     else if (me->p_stats.st_rank >= 4 && Ratings > (ranks[rank-3].ratings))
57     {
58         if (myDI > 8*rankDI)
59             return (0.0);
60         else
61             return (8*rankDI - myDI);
62     }
63     else
64         return (-1);
65 }
66 
ranklist(void)67 void    ranklist(void)
68 {
69   int i;
70   char buf[80];
71   int col = F_sp_rank ? textColor : W_Grey;
72   static int size = 0;
73 
74   if (size != nranks) {
75     W_ClearWindow(rankw);
76     W_ResizeTextWindow(rankw, 65, nranks + 9);
77     size = nranks;
78   }
79   strcpy(buf, "  Rank       Hours  Offense  Ratings      DI");
80   W_WriteText(rankw, 1, 1, col, buf, strlen(buf), W_BoldFont);
81   for (i = 0; i < nranks; i++) {
82     sprintf(buf, "%-11.11s %5.0f %8.2f %8.2f   %7.2f",
83             ranks[i].name,
84             ranks[i].hours,
85             ranks[i].offense,
86             ranks[i].ratings, ranks[i].ratings * ranks[i].hours);
87     if (mystats->st_rank == i) {
88       if (i < nranks-1) {
89         char buf2[35];
90         float DI;
91         if ((DI = toNextRank(i+1)) != -1) {
92             sprintf(buf2, " (need %.2f DI)", DI);
93             strcat(buf, buf2);
94         } else {
95           strcat(buf, " (need ratings)");
96         }
97       }
98       W_WriteText(rankw, 1, i + 2, W_Cyan, buf, strlen(buf), W_BoldFont);
99     } else {
100       W_WriteText(rankw, 1, i + 2, col, buf, strlen(buf), W_RegularFont);
101     }
102   }
103   strcpy(buf, "To achieve a rank, you need the corresponding DI");
104   W_WriteText(rankw, 1, i + 3, col, buf, strlen (buf), W_RegularFont);
105   strcpy(buf, "in less than the hours allowed (DI = ratings x hours).");
106   W_WriteText(rankw, 1, i + 4, col, buf, strlen (buf), W_RegularFont);
107   strcpy(buf, "OR, get offense+bombing+planets above corresponding Ratings");
108   W_WriteText(rankw, 1, i + 5, col, buf, strlen (buf), W_RegularFont);
109   strcpy(buf, "Promotions also occur at 2xDI with Ratings - 1");
110   W_WriteText(rankw, 1, i + 6, col, buf, strlen (buf), W_RegularFont);
111   strcpy(buf, "4xDI with Ratings - 2, and 8xDI with Ratings - 3");
112   W_WriteText(rankw, 1, i + 7, col, buf, strlen (buf), W_RegularFont);
113   W_Flush();
114 }
115