1 /* enter.c
2  *
3  * This version modified to work as the client in a socket based protocol.
4  *
5  */
6 #include "config.h"
7 #include "copyright.h"
8 
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <sys/types.h>
12 #include <errno.h>
13 #include <pwd.h>
14 #include <string.h>
15 #include <ctype.h>
16 #include "Wlib.h"
17 #include "defs.h"
18 #include "struct.h"
19 #include "data.h"
20 #include "enter.h"
21 
22 /* Enter the game */
23 
24 /* long random();        */
25 
26 static void drawTstats();
27 
enter(void)28 void enter(void)
29 {
30   drawTstats();
31   delay = 0;
32 }
33 
openmem(void)34 void openmem(void)
35 {
36   int     i;
37 
38   players = universe.players;
39   torps = universe.torps;
40   plasmatorps = universe.plasmatorps;
41   status = universe.status;
42   planets = universe.planets;
43   phasers = universe.phasers;
44   mctl = universe.mctl;
45   messages = universe.messages;
46   context = universe.context;
47   context->gameup = GU_UNSAFE;
48   for (i = 0; i < MAXPLAYER; i++)
49     {
50       players[i].p_status = PFREE;
51       players[i].p_cloakphase = 0;
52       players[i].p_no = i;
53       players[i].p_ntorp = 0;
54       players[i].p_explode = 1;
55       players[i].p_stats.st_tticks = 1;
56     }
57   mctl->mc_current = 0;
58   status->time = 1;
59   status->timeprod = 1;
60   status->kills = 1;
61   status->losses = 1;
62   status->time = 1;
63   status->planets = 1;
64   status->armsbomb = 1;
65   for (i = 0; i < MAXPLAYER * MAXTORP; i++)
66     {
67       torps[i].t_status = TFREE;
68       torps[i].t_owner = (i / MAXTORP);
69     }
70   for (i = 0; i < MAXPLAYER; i++)
71     {
72       phasers[i].ph_status = PHFREE;
73 #ifdef SOUND
74       phasers[i].sound_phaser = 0;
75 #endif
76     }
77   for (i = 0; i < MAXPLAYER * MAXPLASMA; i++)
78     {
79       plasmatorps[i].pt_status = PTFREE;
80       plasmatorps[i].pt_owner = (i / MAXPLASMA);
81     }
82   for (i = 0; i < MAXPLANETS; i++)
83     {
84       planets[i].pl_no = i;
85     }
86   /* initialize planet redraw for moving planets */
87   for (i = 0; i < MAXPLANETS; i++)
88     {
89       pl_update[i].plu_update = -1;
90     }
91   /* initialise dynamic rank table */
92   nranks = DEFAULT_NUMRANKS;
93   i = nranks * sizeof(struct rank);
94   ranks = malloc(i);
95   memcpy(ranks, &default_ranks, i);
96   /* initialize pointers if ghost start */
97   if (ghoststart)
98     {
99       me = &players[ghost_pno];
100       myship = &(me->p_ship);
101       mystats = &(me->p_stats);
102     }
103 }
104 
drawTstats(void)105 void drawTstats(void)
106 {
107   char    buf[BUFSIZ];
108 
109   if (newDashboard)
110     return;
111   sprintf(buf, "Flags        Warp Dam Shd Torps  Kills Armies   Fuel  Wtemp Etemp");
112   W_WriteText(tstatw, 50, 5, textColor, buf, strlen(buf), W_RegularFont);
113   sprintf(buf,
114 	  "Maximum:      %2d  %3d %3d               %3d   %6d   %3d   %3d",
115 	  me->p_ship.s_maxspeed, me->p_ship.s_maxdamage,
116 	  me->p_ship.s_maxshield, me->p_ship.s_maxarmies,
117 	  me->p_ship.s_maxfuel, me->p_ship.s_maxwpntemp / 10,
118 	  me->p_ship.s_maxegntemp / 10);
119   W_WriteText(tstatw, 50, 27, textColor, buf, strlen(buf), W_RegularFont);
120 }
121 
122 #ifdef HOCKEY_LINES
init_hockey_lines(void)123 void init_hockey_lines(void)
124 {
125   int     i = 0;				 /* This is incremented for *
126 
127 						  *
128 						  *
129 						  * * each line added */
130 
131   /* For speed, the normal netrek walls are not done this way */
132 
133   /* Defines for Hockey lines and the Hockey lines themselves */
134 #define RINK_TOP 0
135 #define RINK_BOTTOM (GWIDTH)
136 #define TENTH (((RINK_BOTTOM - RINK_TOP)/10))
137 #define R_MID (((RINK_BOTTOM - RINK_TOP)/2))	 /* center (red) line */
138 #define RINK_LENGTH ((RINK_BOTTOM - RINK_TOP))
139 #define RINK_WIDTH ((GWIDTH*2/3))
140 #define G_MID ((GWIDTH/2))			 /* center of goal */
141 #define RINK_LEFT ((G_MID-(RINK_WIDTH/2)))
142 #define RINK_RIGHT ((G_MID+(RINK_WIDTH/2)))
143 #define G_LFT (R_MID-TENTH)			 /* left edge of goal */
144 #define G_RGT (R_MID+TENTH)			 /* right edge of goal */
145 #define RED_1 (RINK_LEFT + (1*RINK_WIDTH/5))
146 #define RED_2 (RINK_LEFT + (2*RINK_WIDTH/5))
147 #define RED_3 (RINK_LEFT + (3*RINK_WIDTH/5))
148 #define RED_4 (RINK_LEFT + (4*RINK_WIDTH/5))
149 #define ORI_G (RINK_BOTTOM - /*2* */TENTH)	 /* Ori goal line */
150 #define ORI_E (RINK_BOTTOM -   TENTH/2)		 /* end of Ori goal */
151 #define ORI_B (RINK_BOTTOM - (RINK_LENGTH/3))	 /* Ori blue line */
152 #define KLI_G (RINK_TOP    + /*2* */TENTH)	 /* Kli goal line */
153 #define KLI_E (RINK_TOP    +   TENTH/2)		 /* end of Kli goal */
154 #define KLI_B (RINK_TOP    + (RINK_LENGTH/3))	 /* Kli blue line */
155 
156   /* The Kli goal line */
157   s_lines[i].begin_x = G_LFT;
158   s_lines[i].end_x = G_RGT;
159   s_lines[i].begin_y = s_lines[i].end_y = KLI_G;
160   s_lines[i].color = W_Red;
161   s_lines[i].flag = &hockey_s_lines;
162   s_lines[i++].orientation = S_LINE_HORIZONTAL;
163   /* fprintf(stderr,"Kli Goal: x: %i to %i, y: %i to * *
164    * %i\n",s_lines[i-1].begin_x, * *
165    * s_lines[i-1].end_x,s_lines[i-1].begin_y,s_lines[i-1].end_y); */
166 
167   /* The left side goal line */
168   s_lines[i].begin_x = s_lines[i].end_x = G_LFT;
169   s_lines[i].begin_y = KLI_G;
170   s_lines[i].end_y = KLI_E;
171   s_lines[i].color = W_Green;
172   s_lines[i].flag = &hockey_s_lines;
173   s_lines[i++].orientation = S_LINE_VERTICAL;
174   /* fprintf(stderr,"L K Goal: x: %i to %i, y: %i to * *
175    * %i\n",s_lines[i-1].begin_x, * *
176    * s_lines[i-1].end_x,s_lines[i-1].begin_y,s_lines[i-1].end_y); */
177 
178   /* The right side goal line */
179   s_lines[i].begin_x = s_lines[i].end_x = G_RGT;
180   s_lines[i].begin_y = KLI_G;
181   s_lines[i].end_y = KLI_E;
182   s_lines[i].color = W_Green;
183   s_lines[i].flag = &hockey_s_lines;
184   s_lines[i++].orientation = S_LINE_VERTICAL;
185   /* fprintf(stderr,"K R Goal: x: %i to %i, y: %i to * *
186    * %i\n",s_lines[i-1].begin_x, * *
187    * s_lines[i-1].end_x,s_lines[i-1].begin_y,s_lines[i-1].end_y); */
188 
189   /* The End of kli goal line */
190   s_lines[i].begin_x = G_LFT;
191   s_lines[i].end_x = G_RGT;
192   s_lines[i].begin_y = s_lines[i].end_y = KLI_E;
193   s_lines[i].color = W_Green;
194   s_lines[i].flag = &hockey_s_lines;
195   s_lines[i++].orientation = S_LINE_HORIZONTAL;
196   /* fprintf(stderr,"K B Goal: x: %i to %i, y: %i to * *
197    * %i\n",s_lines[i-1].begin_x, * *
198    * s_lines[i-1].end_x,s_lines[i-1].begin_y,s_lines[i-1].end_y); */
199 
200   /* The Kli blue line */
201   s_lines[i].begin_x = RINK_LEFT;
202   s_lines[i].end_x = RINK_RIGHT;
203   s_lines[i].begin_y = s_lines[i].end_y = KLI_B;
204   s_lines[i].color = W_Cyan;
205   s_lines[i].flag = &hockey_s_lines;
206   s_lines[i++].orientation = S_LINE_HORIZONTAL;
207   /* fprintf(stderr,"Kli Blue: x: %i to %i, y: %i to * *
208    * %i\n",s_lines[i-1].begin_x, * *
209    * s_lines[i-1].end_x,s_lines[i-1].begin_y,s_lines[i-1].end_y); */
210 
211   /* The Ori goal line */
212   s_lines[i].begin_x = G_LFT;
213   s_lines[i].end_x = G_RGT;
214   s_lines[i].begin_y = s_lines[i].end_y = ORI_G;
215   s_lines[i].color = W_Red;
216   s_lines[i].flag = &hockey_s_lines;
217   s_lines[i++].orientation = S_LINE_HORIZONTAL;
218   /* fprintf(stderr,"Ori Goal: x: %i to %i, y: %i to * *
219    * %i\n",s_lines[i-1].begin_x, * *
220    * s_lines[i-1].end_x,s_lines[i-1].begin_y,s_lines[i-1].end_y); */
221 
222   /* The left side goal line */
223   s_lines[i].begin_x = s_lines[i].end_x = G_LFT;
224   s_lines[i].begin_y = ORI_G;
225   s_lines[i].end_y = ORI_E;
226   s_lines[i].color = W_Cyan;
227   s_lines[i].flag = &hockey_s_lines;
228   s_lines[i++].orientation = S_LINE_VERTICAL;
229   /* fprintf(stderr,"O L Goal: x: %i to %i, y: %i to * *
230    * %i\n",s_lines[i-1].begin_x, * *
231    * s_lines[i-1].end_x,s_lines[i-1].begin_y,s_lines[i-1].end_y); */
232 
233   /* The right side goal line */
234   s_lines[i].begin_x = s_lines[i].end_x = G_RGT;
235   s_lines[i].begin_y = ORI_G;
236   s_lines[i].end_y = ORI_E;
237   s_lines[i].color = W_Cyan;
238   s_lines[i].flag = &hockey_s_lines;
239   s_lines[i++].orientation = S_LINE_VERTICAL;
240   /* fprintf(stderr,"O R Goal: x: %i to %i, y: %i to * *
241    * %i\n",s_lines[i-1].begin_x, * *
242    * s_lines[i-1].end_x,s_lines[i-1].begin_y,s_lines[i-1].end_y); */
243 
244   /* The End of ori goal line */
245   s_lines[i].begin_x = G_LFT;
246   s_lines[i].end_x = G_RGT;
247   s_lines[i].begin_y = s_lines[i].end_y = ORI_E;
248   s_lines[i].color = W_Cyan;
249   s_lines[i].flag = &hockey_s_lines;
250   s_lines[i++].orientation = S_LINE_HORIZONTAL;
251   /* fprintf(stderr,"O B Goal: x: %i to %i, y: %i to * *
252    * %i\n",s_lines[i-1].begin_x, * *
253    * s_lines[i-1].end_x,s_lines[i-1].begin_y,s_lines[i-1].end_y); */
254 
255   /* The Ori blue line */
256   s_lines[i].begin_x = RINK_LEFT;
257   s_lines[i].end_x = RINK_RIGHT;
258   s_lines[i].begin_y = s_lines[i].end_y = ORI_B;
259   s_lines[i].color = W_Cyan;
260   s_lines[i].flag = &hockey_s_lines;
261   s_lines[i++].orientation = S_LINE_HORIZONTAL;
262   /* fprintf(stderr,"Ori Blue: x: %i to %i, y: %i to * *
263    * %i\n",s_lines[i-1].begin_x, * *
264    * s_lines[i-1].end_x,s_lines[i-1].begin_y,s_lines[i-1].end_y); */
265 
266   /* The red line */
267   s_lines[i].begin_x = RINK_LEFT;
268   s_lines[i].end_x = RINK_RIGHT;
269   s_lines[i].begin_y = s_lines[i].end_y = R_MID;
270   s_lines[i].color = W_Red;
271   s_lines[i].flag = &hockey_s_lines;
272   s_lines[i++].orientation = S_LINE_HORIZONTAL;
273   /* fprintf(stderr,"Red Line: x: %i to %i, y: %i to * *
274    * %i\n",s_lines[i-1].begin_x, * *
275    * s_lines[i-1].end_x,s_lines[i-1].begin_y,s_lines[i-1].end_y); */
276 
277   /* Right rink boundary */
278   s_lines[i].begin_x = s_lines[i].end_x = RINK_RIGHT;
279   s_lines[i].begin_y = 0;
280   s_lines[i].end_y = GWIDTH - 1;
281   s_lines[i].color = W_Grey;
282   s_lines[i].flag = &hockey_s_lines;
283   s_lines[i++].orientation = S_LINE_VERTICAL;
284   /* fprintf(stderr,"Rt. Line: x: %i to %i, y: %i to * *
285    * %i\n",s_lines[i-1].begin_x, * *
286    * s_lines[i-1].end_x,s_lines[i-1].begin_y,s_lines[i-1].end_y); */
287 
288   /* Left rink boundary */
289   s_lines[i].begin_x = s_lines[i].end_x = RINK_LEFT;
290   s_lines[i].begin_y = 0;
291   s_lines[i].end_y = GWIDTH - 1;
292   s_lines[i].color = W_Grey;
293   s_lines[i].flag = &hockey_s_lines;
294   s_lines[i++].orientation = S_LINE_VERTICAL;
295   /* fprintf(stderr,"Lef Line: x: %i to %i, y: %i to * *
296    * %i\n",s_lines[i-1].begin_x, * *
297    * s_lines[i-1].end_x,s_lines[i-1].begin_y,s_lines[i-1].end_y); */
298 
299   /* NOTE:  The number of lines must EXACTLY match the NUM_HOCKEY_LINES */
300   /* in defs.h for it to run properly.                           */
301 }
302 #endif
303