~ubuntu-branches/ubuntu/karmic/netrek-client-cow/karmic

« back to all changes in this revision

Viewing changes to ranklist.c

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese, Barry deFreese
  • Date: 2009-06-16 15:27:20 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090616152720-whngeaf1w8l23u14
Tags: 3.3.0-1
[ Barry deFreese ]
* New upstream release.
* Install upstream desktop file. (Closes: #522587).
* Add quilt patch system.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#include "struct.h"
13
13
#include "data.h"
14
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 */
 
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
 
15
67
void    ranklist(void)
16
68
{
17
 
  register int i;
18
 
  char    buf[80];
 
69
  int i;
 
70
  char buf[80];
 
71
  int col = F_sp_rank ? textColor : W_Grey;
 
72
  static int size = 0;
19
73
 
20
 
  /* W_ClearWindow(rankw); */
21
 
  (void) strcpy(buf, "  Rank       Hours  Defense  Ratings      DI");
22
 
  W_WriteText(rankw, 1, 1, textColor, buf, strlen(buf), W_BoldFont);
23
 
  for (i = 0; i < NUMRANKS; i++)
24
 
    {
25
 
      sprintf(buf, "%-11.11s %5.0f %8.2f %8.2f   %7.2f",
26
 
              ranks[i].name,
27
 
              ranks[i].hours,
28
 
              ranks[i].defense,
29
 
              ranks[i].ratings,
30
 
              ranks[i].ratings * ranks[i].hours);
31
 
      if (mystats->st_rank == i)
32
 
        {
33
 
          W_WriteText(rankw, 1, i + 2, W_Cyan, buf, strlen(buf), W_BoldFont);
34
 
        }
35
 
      else
36
 
        {
37
 
          W_WriteText(rankw, 1, i + 2, textColor, buf, strlen(buf), W_RegularFont);
38
 
        }
 
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);
39
101
    }
 
102
  }
40
103
  strcpy(buf, "To achieve a rank, you need the corresponding DI");
41
 
  W_WriteText(rankw, 1, i + 3, textColor, buf, strlen(buf), W_RegularFont);
42
 
  strcpy(buf, "in less than the hours allowed.");
43
 
  W_WriteText(rankw, 1, i + 4, textColor, buf, strlen(buf), W_RegularFont);
44
 
  strcpy(buf, "OR, get offense+boming+planets above corresponding Ratings");
45
 
  W_WriteText(rankw, 1, i + 5, textColor, buf, strlen(buf), W_RegularFont);
 
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);
46
109
  strcpy(buf, "Promotions also occur at 2xDI with Ratings - 1");
47
 
  W_WriteText(rankw, 1, i + 6, textColor, buf, strlen(buf), W_RegularFont);
48
 
  strcpy(buf, "and at 4xDI with Ratings - 2");
49
 
  W_WriteText(rankw, 1, i + 7, textColor, buf, strlen(buf), W_RegularFont);
50
 
  strcpy(buf, " also, some servers require .8 defense for promotion.");
51
 
  W_WriteText(rankw, 1, i + 8, textColor, buf, strlen(buf), W_RegularFont);
 
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();
52
114
}