1
- /* $NetBSD: dr_2.c,v 1.22 2009/03/14 18:32:47 dholland Exp $ */
1
+ /* $NetBSD: dr_2.c,v 1.23 2009/03/14 19:35:13 dholland Exp $ */
2
2
3
3
/*
4
4
* Copyright (c) 1983, 1993
34
34
#if 0
35
35
static char sccsid [] = "@(#)dr_2.c 8.1 (Berkeley) 5/31/93" ;
36
36
#else
37
- __RCSID ("$NetBSD: dr_2.c,v 1.22 2009/03/14 18:32:47 dholland Exp $" );
37
+ __RCSID ("$NetBSD: dr_2.c,v 1.23 2009/03/14 19:35:13 dholland Exp $" );
38
38
#endif
39
39
#endif /* not lint */
40
40
@@ -47,11 +47,15 @@ __RCSID("$NetBSD: dr_2.c,v 1.22 2009/03/14 18:32:47 dholland Exp $");
47
47
48
48
#define couldwin (f ,t ) (f->specs->crew2 > t->specs->crew2 * 1.5)
49
49
50
- static int str_end (const char * );
51
- static int score (struct ship * , struct ship * , char * , size_t , int );
52
- static void move_ship (struct ship * , const char * , unsigned char * , short * , short * , int * );
53
- static void try (struct ship * f , struct ship * t , char * command , size_t commandmax , char * temp , size_t tempmax , int ma , int ta , int af , int vma , int dir , int * high , int rakeme );
54
- static void rmend (char * );
50
+ static int str_end (const char * );
51
+ static int score (struct ship * , struct ship * , char * , size_t , int );
52
+ static void move_ship (struct ship * , const char * , unsigned char * ,
53
+ short * , short * , int * );
54
+ static void try (struct ship * f , struct ship * t ,
55
+ char * command , size_t commandmax , char * temp , size_t tempmax ,
56
+ int ma , int ta , int af , int vma , int dir , int * high ,
57
+ int rakeme );
58
+ static void rmend (char * );
55
59
56
60
const int dtab [] = {0 ,1 ,1 ,2 ,3 ,4 ,4 ,5 }; /* diagonal distances in x==y */
57
61
@@ -109,11 +113,14 @@ checkup(void)
109
113
if (sink != 1 ) {
110
114
makemsg (sp , "exploding!" );
111
115
foreachship (sq ) {
112
- if (sp != sq && sq -> file -> dir && range (sp , sq ) < 4 )
113
- table (sp , sq , RIGGING , L_EXPLODE , sp -> specs -> guns /13 , 6 );
116
+ if (sp != sq && sq -> file -> dir &&
117
+ range (sp , sq ) < 4 )
118
+ table (sp , sq , RIGGING , L_EXPLODE ,
119
+ sp -> specs -> guns /13 , 6 );
114
120
}
115
- } else
121
+ } else {
116
122
makemsg (sp , "sinking!" );
123
+ }
117
124
}
118
125
}
119
126
@@ -127,9 +134,13 @@ prizecheck(void)
127
134
continue ;
128
135
if (sp -> file -> struck || sp -> file -> dir == 0 )
129
136
continue ;
130
- if (sp -> specs -> crew1 + sp -> specs -> crew2 + sp -> specs -> crew3 > sp -> file -> pcrew * 6 ) {
137
+ if (sp -> specs -> crew1 + sp -> specs -> crew2 + sp -> specs -> crew3 >
138
+ sp -> file -> pcrew * 6 ) {
131
139
Writestr (W_SIGNAL , sp , "prize crew overthrown" );
132
- Write (W_POINTS , sp -> file -> captured , sp -> file -> captured -> file -> points - 2 * sp -> specs -> pts , 0 , 0 , 0 );
140
+ Write (W_POINTS , sp -> file -> captured ,
141
+ sp -> file -> captured -> file -> points
142
+ - 2 * sp -> specs -> pts ,
143
+ 0 , 0 , 0 );
133
144
Write (W_CAPTURED , sp , -1 , 0 , 0 , 0 );
134
145
}
135
146
}
@@ -146,18 +157,21 @@ str_end(const char *str)
146
157
}
147
158
148
159
void
149
- closeon (struct ship * from , struct ship * to , char * command , size_t commandmax , int ta , int ma , int af )
160
+ closeon (struct ship * from , struct ship * to , char * command , size_t commandmax ,
161
+ int ta , int ma , int af )
150
162
{
151
163
int high ;
152
164
char temp [10 ];
153
165
154
166
temp [0 ] = command [0 ] = '\0' ;
155
167
high = -30000 ;
156
- try (from , to , command , commandmax , temp , sizeof (temp ), ma , ta , af , ma , from -> file -> dir , & high , 0 );
168
+ try (from , to , command , commandmax , temp , sizeof (temp ),
169
+ ma , ta , af , ma , from -> file -> dir , & high , 0 );
157
170
}
158
171
159
172
static int
160
- score (struct ship * ship , struct ship * to , char * movement , size_t movementmax , int onlytemp )
173
+ score (struct ship * ship , struct ship * to , char * movement , size_t movementmax ,
174
+ int onlytemp )
161
175
{
162
176
int drift ;
163
177
int row , col , dir , total , ran ;
@@ -188,7 +202,8 @@ score(struct ship *ship, struct ship *to, char *movement, size_t movementmax, in
188
202
}
189
203
190
204
static void
191
- move_ship (struct ship * ship , const char * p , unsigned char * dir , short * row , short * col , int * drift )
205
+ move_ship (struct ship * ship , const char * p , unsigned char * dir ,
206
+ short * row , short * col , int * drift )
192
207
{
193
208
int dist ;
194
209
char moved = 0 ;
@@ -228,7 +243,10 @@ move_ship(struct ship *ship, const char *p, unsigned char *dir, short *row, shor
228
243
}
229
244
230
245
static void
231
- try (struct ship * f , struct ship * t , char * command , size_t commandmax , char * temp , size_t tempmax , int ma , int ta , int af , int vma , int dir , int * high , int rakeme )
246
+ try (struct ship * f , struct ship * t ,
247
+ char * command , size_t commandmax ,
248
+ char * temp , size_t tempmax ,
249
+ int ma , int ta , int af , int vma , int dir , int * high , int rakeme )
232
250
{
233
251
int new , n ;
234
252
char st [4 ];
@@ -243,28 +261,39 @@ try(struct ship *f, struct ship *t, char *command, size_t commandmax, char *temp
243
261
* high = new ;
244
262
strlcpy (command , temp , commandmax );
245
263
}
246
- try (f , t , command , commandmax , temp , tempmax , ma - n , ta , af , vma - n ,
247
- dir , high , rakeme );
264
+ try (f , t , command , commandmax , temp , tempmax ,
265
+ ma - n , ta , af , vma - n ,
266
+ dir , high , rakeme );
248
267
rmend (temp );
249
268
}
250
- if ((ma > 0 && ta > 0 && (n = str_end (temp )) != 'l' && n != 'r' ) || !strlen (temp )) {
269
+ if ((ma > 0 && ta > 0 && (n = str_end (temp )) != 'l' && n != 'r' ) ||
270
+ !strlen (temp )) {
251
271
strlcat (temp , "r" , tempmax );
252
272
new = score (f , t , temp , tempmax , rakeme );
253
- if (new > * high && (!rakeme || (gunsbear (f , t ) && !gunsbear (t , f )))) {
273
+ if (new > * high && (!rakeme ||
274
+ (gunsbear (f , t ) && !gunsbear (t , f )))) {
254
275
* high = new ;
255
276
strlcpy (command , temp , commandmax );
256
277
}
257
- try (f , t , command , commandmax , temp , tempmax , ma - 1 , ta - 1 , af , min (ma - 1 , maxmove (f , (dir == 8 ? 1 : dir + 1 ), 0 )), (dir == 8 ? 1 : dir + 1 ), high , rakeme );
278
+ try (f , t , command , commandmax , temp , tempmax ,
279
+ ma - 1 , ta - 1 , af ,
280
+ min (ma - 1 , maxmove (f , (dir == 8 ? 1 : dir + 1 ), 0 )),
281
+ (dir == 8 ? 1 : dir + 1 ), high , rakeme );
258
282
rmend (temp );
259
283
}
260
- if ((ma > 0 && ta > 0 && (n = str_end (temp )) != 'l' && n != 'r' ) || !strlen (temp )){
284
+ if ((ma > 0 && ta > 0 && (n = str_end (temp )) != 'l' && n != 'r' ) ||
285
+ !strlen (temp )) {
261
286
strlcat (temp , "l" , sizeof (temp ));
262
287
new = score (f , t , temp , tempmax , rakeme );
263
- if (new > * high && (!rakeme || (gunsbear (f , t ) && !gunsbear (t , f )))){
288
+ if (new > * high && (!rakeme ||
289
+ (gunsbear (f , t ) && !gunsbear (t , f )))) {
264
290
* high = new ;
265
291
strlcpy (command , temp , commandmax );
266
292
}
267
- try (f , t , command , commandmax , temp , tempmax , ma - 1 , ta - 1 , af , (min (ma - 1 ,maxmove (f , (dir - 1 ? dir - 1 : 8 ), 0 ))), (dir - 1 ? dir - 1 : 8 ), high , rakeme );
293
+ try (f , t , command , commandmax , temp , tempmax ,
294
+ ma - 1 , ta - 1 , af ,
295
+ (min (ma - 1 ,maxmove (f , (dir - 1 ? dir - 1 : 8 ), 0 ))),
296
+ (dir - 1 ? dir - 1 : 8 ), high , rakeme );
268
297
rmend (temp );
269
298
}
270
299
}
0 commit comments