2
|
1 /*--------------------------------------------------------------------------
|
|
2 NETREK II -- Paradise
|
|
3
|
|
4 Permission to use, copy, modify, and distribute this software and its
|
|
5 documentation, or any derivative works thereof, for any NON-COMMERCIAL
|
|
6 purpose and without fee is hereby granted, provided that this copyright
|
|
7 notice appear in all copies. No representations are made about the
|
|
8 suitability of this software for any purpose. This software is provided
|
|
9 "as is" without express or implied warranty.
|
|
10
|
|
11 Xtrek Copyright 1986 Chris Guthrie
|
|
12 Netrek (Xtrek II) Copyright 1989 Kevin P. Smith
|
|
13 Scott Silvey
|
|
14 Paradise II (Netrek II) Copyright 1993 Larry Denys
|
|
15 Kurt Olsen
|
|
16 Brandon Gillespie
|
|
17 --------------------------------------------------------------------------*/
|
|
18
|
|
19 #include "config.h"
|
|
20 #include <stdio.h>
|
|
21 #include <signal.h>
|
|
22 #include <setjmp.h>
|
|
23 #include <sys/types.h>
|
|
24 #include <sys/time.h>
|
|
25
|
|
26 #include "defs.h"
|
|
27 #include "struct.h"
|
|
28 #include "data.h"
|
|
29 #include "shmem.h"
|
|
30
|
|
31 #if 0
|
|
32 extern jmp_buf env;
|
|
33 #endif
|
|
34
|
|
35
|
|
36 /* Figure out ratings for player p. Computed ratings are filled into r */
|
|
37 void
|
|
38 compute_ratings(p, r)
|
|
39 struct player *p;
|
|
40 struct rating *r;
|
|
41 {
|
|
42 struct stats *s;
|
|
43 float t, t2;
|
|
44
|
|
45 s = &p->p_stats;
|
|
46
|
|
47 r->ratio = (s->st_tlosses != 0) ? (float) s->st_tkills /
|
|
48 (float) s->st_tlosses : s->st_tkills;
|
|
49
|
|
50 if (status->timeprod == 0)
|
|
51 status->timeprod = 1;
|
|
52
|
|
53 t = (float) s->st_tticks / (float) status->timeprod; /* hour ratio */
|
|
54 if (t == 0.0)
|
|
55 t = 1.0;
|
|
56
|
|
57 t2 = t * (float) status->kills; /* get expected kills */
|
|
58 t2 /= 2; /* lower expectation */
|
|
59 printf("ticks %f timeprod %u %f %f %d\n", (float) s->st_tticks, status->timeprod, t2, t, status->kills);
|
|
60 r->offrat = s->st_tkills / t2;/* calc offense rating */
|
|
61
|
|
62 t2 = t * (float) status->dooshes; /* expected armies dooshed */
|
|
63 r->dooshrat = (float) s->st_tdooshes / t2; /* doosh rating */
|
|
64
|
|
65 r->battle = r->offrat + r->dooshrat; /* get battle rating */
|
|
66
|
|
67 t2 = t * (float) status->armsbomb; /* expected armies bombed */
|
|
68 r->bombrat = (float) s->st_tarmsbomb / t2; /* bomb rating */
|
|
69
|
|
70 t2 = t * (float) status->resbomb; /* expected resources bombed */
|
|
71 r->resrat = (float) s->st_tresbomb / t2; /* resource bombed rating */
|
|
72
|
|
73 t2 = t * (float) status->planets; /* expected planets */
|
|
74 r->planetrat = (float) s->st_tplanets / t2; /* get planet rating */
|
|
75
|
|
76 printf("planetrat %f tplanets %f t2 %f\n", (float) r->planetrat, (float) s->st_tplanets, (float) t2);
|
|
77
|
|
78 r->strategy = r->bombrat + r->resrat + r->planetrat; /* strategy rating */
|
|
79
|
|
80 t2 = (float) status->sbkills / (float) status->sblosses;
|
|
81 if (s->st_sblosses == 0)
|
|
82 r->sbrat = (float) s->st_sbkills / t2;
|
|
83 else
|
|
84 r->sbrat = ((float) s->st_sbkills / (float) s->st_sblosses) / t2;
|
|
85
|
|
86 t2 = (float) status->wbkills / (float) status->wblosses;
|
|
87 if (s->st_wblosses == 0)
|
|
88 r->wbrat = (float) s->st_wbkills / t2;
|
|
89 else
|
|
90 r->wbrat = ((float) s->st_wbkills / (float) s->st_wblosses) / t2;
|
|
91
|
|
92 t = (float) s->st_jsticks / (float) status->jstime;
|
|
93 t2 = t * (float) status->jsplanets; /* get expected js planets */
|
|
94 if (t2 == 0.0)
|
|
95 r->jsrat = 0.0;
|
|
96 else
|
|
97 r->jsrat = (float) s->st_jsplanets / t2; /* js rating */
|
|
98
|
|
99 r->special = r->sbrat + r->wbrat + r->jsrat; /* get special ship rating */
|
|
100 }
|
|
101
|
|
102
|
|
103 /*-----------------------------------DEATH---------------------------------*/
|
|
104 /*
|
|
105 * This function is called when the player dies. It checks to see if the
|
|
106 * player has been promoted.
|
|
107 */
|
|
108
|
|
109
|
|
110 extern int savestats();
|
|
111
|
|
112 void
|
|
113 death()
|
|
114 {
|
|
115 struct stats *s; /* to point to player's stats */
|
|
116 struct rating r; /* filled in by compute_ratings() */
|
|
117 int genocides; /* player's genocides */
|
|
118 float di; /* player's di */
|
|
119
|
|
120 #if 0
|
|
121 stop_interruptor();
|
|
122 #endif
|
|
123 me->p_status = POUTFIT; /* Stop the ghost buster */
|
|
124 switch (me->p_whydead)
|
|
125 { /* determine whether the player */
|
|
126 case KTORP: /* should be forced out of the */
|
|
127 case KPLASMA: /* game or not */
|
|
128 case KPHASER:
|
|
129 case KPLANET:
|
|
130 case KSHIP:
|
|
131 case KGENOCIDE:
|
|
132 case KGHOST:
|
|
133 case KPROVIDENCE:
|
|
134 case KASTEROID:
|
|
135 default:
|
|
136 break;
|
|
137 case KQUIT:
|
|
138 case KDAEMON:
|
|
139 case KWINNER:
|
|
140 mustexit = 1; /* set global var to force player out */
|
|
141 break;
|
|
142 }
|
|
143 me->p_flags &= ~(PFWAR | PFREFITTING); /* turn off most flags */
|
|
144 if (me->p_stats.st_rank < NUMRANKS - 1)
|
|
145 { /* should we try to promote */
|
|
146 s = &(me->p_stats); /* get player's stat struct */
|
|
147 genocides = s->st_genocides;/* get # genocides */
|
|
148 di = s->st_di; /* get player's DI */
|
|
149
|
|
150 compute_ratings(me, &r);
|
|
151
|
|
152 /*--[ check for promotion ]--*/
|
|
153 if (configvals->bronco_ranks)
|
|
154 {
|
|
155 if ((di >= ranks[s->st_rank + 1].di)
|
|
156 && (r.battle >= ranks[s->st_rank + 1].battle)
|
|
157 && (r.strategy * 3 / 2 >= ranks[s->st_rank + 1].strategy)
|
|
158 && (r.special * 3 >= ranks[s->st_rank + 1].specship))
|
|
159 s->st_rank++; /* we have a promotion */
|
|
160 }
|
|
161 else
|
|
162 {
|
|
163 if ((genocides >= ranks[s->st_rank + 1].genocides)
|
|
164 && (di >= ranks[s->st_rank + 1].di)
|
|
165 && (r.battle >= ranks[s->st_rank + 1].battle)
|
|
166 && (r.strategy >= ranks[s->st_rank + 1].strategy)
|
|
167 && (r.special >= ranks[s->st_rank + 1].specship))
|
|
168 s->st_rank++; /* we have a promotion */
|
|
169 }
|
|
170 }
|
|
171 updateClient(); /* update the client */
|
|
172 savestats(); /* save players stats */
|
|
173 #if 0
|
|
174 longjmp(env, 0); /* jump to start of ntserv */
|
|
175 #endif
|
|
176 }
|
|
177
|
|
178 /*-------------------------------------------------------------------------*/
|
|
179
|
|
180
|
|
181 /*----END OF FILE-----*/
|