Home | History | Annotate | Line # | Download | only in sail
dr_1.c revision 1.2
      1  1.1      cgd /*
      2  1.1      cgd  * Copyright (c) 1983 Regents of the University of California.
      3  1.1      cgd  * All rights reserved.
      4  1.1      cgd  *
      5  1.1      cgd  * Redistribution and use in source and binary forms, with or without
      6  1.1      cgd  * modification, are permitted provided that the following conditions
      7  1.1      cgd  * are met:
      8  1.1      cgd  * 1. Redistributions of source code must retain the above copyright
      9  1.1      cgd  *    notice, this list of conditions and the following disclaimer.
     10  1.1      cgd  * 2. Redistributions in binary form must reproduce the above copyright
     11  1.1      cgd  *    notice, this list of conditions and the following disclaimer in the
     12  1.1      cgd  *    documentation and/or other materials provided with the distribution.
     13  1.1      cgd  * 3. All advertising materials mentioning features or use of this software
     14  1.1      cgd  *    must display the following acknowledgement:
     15  1.1      cgd  *	This product includes software developed by the University of
     16  1.1      cgd  *	California, Berkeley and its contributors.
     17  1.1      cgd  * 4. Neither the name of the University nor the names of its contributors
     18  1.1      cgd  *    may be used to endorse or promote products derived from this software
     19  1.1      cgd  *    without specific prior written permission.
     20  1.1      cgd  *
     21  1.1      cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22  1.1      cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  1.1      cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  1.1      cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25  1.1      cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  1.1      cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  1.1      cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  1.1      cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  1.1      cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  1.1      cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  1.1      cgd  * SUCH DAMAGE.
     32  1.1      cgd  */
     33  1.1      cgd 
     34  1.1      cgd #ifndef lint
     35  1.2  mycroft /*static char sccsid[] = "from: @(#)dr_1.c	5.4 (Berkeley) 6/1/90";*/
     36  1.2  mycroft static char rcsid[] = "$Id: dr_1.c,v 1.2 1993/08/01 18:51:52 mycroft Exp $";
     37  1.1      cgd #endif /* not lint */
     38  1.1      cgd 
     39  1.1      cgd #include "driver.h"
     40  1.1      cgd 
     41  1.1      cgd unfoul()
     42  1.1      cgd {
     43  1.1      cgd 	register struct ship *sp;
     44  1.1      cgd 	struct ship *to;
     45  1.1      cgd 	register int nat;
     46  1.1      cgd 	register i;
     47  1.1      cgd 
     48  1.1      cgd 	foreachship(sp) {
     49  1.1      cgd 		if (sp->file->captain[0])
     50  1.1      cgd 			continue;
     51  1.1      cgd 		nat = capship(sp)->nationality;
     52  1.1      cgd 		foreachship(to) {
     53  1.1      cgd 			if (nat != capship(to)->nationality &&
     54  1.1      cgd 			    !toughmelee(sp, to, 0, 0))
     55  1.1      cgd 				continue;
     56  1.1      cgd 			for (i = fouled2(sp, to); --i >= 0;)
     57  1.1      cgd 				if (die() <= 2)
     58  1.1      cgd 					cleanfoul(sp, to, 0);
     59  1.1      cgd 		}
     60  1.1      cgd 	}
     61  1.1      cgd }
     62  1.1      cgd 
     63  1.1      cgd boardcomp()
     64  1.1      cgd {
     65  1.1      cgd 	int crew[3];
     66  1.1      cgd 	register struct ship *sp, *sq;
     67  1.1      cgd 
     68  1.1      cgd 	foreachship(sp) {
     69  1.1      cgd 		if (*sp->file->captain)
     70  1.1      cgd 			continue;
     71  1.1      cgd 		if (sp->file->dir == 0)
     72  1.1      cgd 			continue;
     73  1.1      cgd 		if (sp->file->struck || sp->file->captured != 0)
     74  1.1      cgd 			continue;
     75  1.1      cgd 		if (!snagged(sp))
     76  1.1      cgd 			continue;
     77  1.1      cgd 		crew[0] = sp->specs->crew1 != 0;
     78  1.1      cgd 		crew[1] = sp->specs->crew2 != 0;
     79  1.1      cgd 		crew[2] = sp->specs->crew3 != 0;
     80  1.1      cgd 		foreachship(sq) {
     81  1.1      cgd 			if (!Xsnagged2(sp, sq))
     82  1.1      cgd 				continue;
     83  1.1      cgd 			if (meleeing(sp, sq))
     84  1.1      cgd 				continue;
     85  1.1      cgd 			if (!sq->file->dir
     86  1.1      cgd 				|| sp->nationality == capship(sq)->nationality)
     87  1.1      cgd 				continue;
     88  1.1      cgd 			switch (sp->specs->class - sq->specs->class) {
     89  1.1      cgd 			case -3: case -4: case -5:
     90  1.1      cgd 				if (crew[0]) {
     91  1.1      cgd 					/* OBP */
     92  1.1      cgd 					sendbp(sp, sq, crew[0]*100, 0);
     93  1.1      cgd 					crew[0] = 0;
     94  1.1      cgd 				} else if (crew[1]){
     95  1.1      cgd 					/* OBP */
     96  1.1      cgd 					sendbp(sp, sq, crew[1]*10, 0);
     97  1.1      cgd 					crew[1] = 0;
     98  1.1      cgd 				}
     99  1.1      cgd 				break;
    100  1.1      cgd 			case -2:
    101  1.1      cgd 				if (crew[0] || crew[1]) {
    102  1.1      cgd 					/* OBP */
    103  1.1      cgd 					sendbp(sp, sq, crew[0]*100+crew[1]*10,
    104  1.1      cgd 						0);
    105  1.1      cgd 					crew[0] = crew[1] = 0;
    106  1.1      cgd 				}
    107  1.1      cgd 				break;
    108  1.1      cgd 			case -1: case 0: case 1:
    109  1.1      cgd 				if (crew[0]) {
    110  1.1      cgd 					/* OBP */
    111  1.1      cgd 					sendbp(sp, sq, crew[0]*100+crew[1]*10,
    112  1.1      cgd 						0);
    113  1.1      cgd 					crew[0] = crew[1] = 0;
    114  1.1      cgd 				}
    115  1.1      cgd 				break;
    116  1.1      cgd 			case 2: case 3: case 4: case 5:
    117  1.1      cgd 				/* OBP */
    118  1.1      cgd 				sendbp(sp, sq, crew[0]*100+crew[1]*10+crew[2],
    119  1.1      cgd 					0);
    120  1.1      cgd 				crew[0] = crew[1] = crew[2] = 0;
    121  1.1      cgd 				break;
    122  1.1      cgd 			}
    123  1.1      cgd 		}
    124  1.1      cgd 	}
    125  1.1      cgd }
    126  1.1      cgd 
    127  1.1      cgd fightitout(from, to, key)
    128  1.1      cgd struct ship *from, *to;
    129  1.1      cgd int key;
    130  1.1      cgd {
    131  1.1      cgd 	struct ship *fromcap, *tocap;
    132  1.1      cgd 	int crewfrom[3], crewto[3], menfrom, mento;
    133  1.1      cgd 	int pcto, pcfrom, fromstrength, strengthto, frominjured, toinjured;
    134  1.1      cgd 	int topoints;
    135  1.1      cgd 	int index, totalfrom = 0, totalto = 0;
    136  1.1      cgd 	int count;
    137  1.1      cgd 	char message[60];
    138  1.1      cgd 
    139  1.1      cgd 	menfrom = mensent(from, to, crewfrom, &fromcap, &pcfrom, key);
    140  1.1      cgd 	mento = mensent(to, from, crewto, &tocap, &pcto, 0);
    141  1.1      cgd 	if (fromcap == 0)
    142  1.1      cgd 		fromcap = from;
    143  1.1      cgd 	if (tocap == 0)
    144  1.1      cgd 		tocap = to;
    145  1.1      cgd 	if (key) {
    146  1.1      cgd 		if (!menfrom) {		 /* if crew surprised */
    147  1.1      cgd 			if (fromcap == from)
    148  1.1      cgd 				menfrom = from->specs->crew1
    149  1.1      cgd 					+ from->specs->crew2
    150  1.1      cgd 					+ from->specs->crew3;
    151  1.1      cgd 			else
    152  1.1      cgd 				menfrom = from->file->pcrew;
    153  1.1      cgd 		} else {
    154  1.1      cgd 			menfrom *= 2;	/* DBP's fight at an advantage */
    155  1.1      cgd 		}
    156  1.1      cgd 	}
    157  1.1      cgd 	fromstrength = menfrom * fromcap->specs->qual;
    158  1.1      cgd 	strengthto = mento * tocap->specs->qual;
    159  1.1      cgd 	for (count = 0;
    160  1.1      cgd 	     (fromstrength < strengthto * 3 && strengthto < fromstrength * 3
    161  1.1      cgd 	      || fromstrength == -1) && count < 4;
    162  1.1      cgd 	     count++) {
    163  1.1      cgd 		index = fromstrength/10;
    164  1.1      cgd 		if (index > 8)
    165  1.1      cgd 			index = 8;
    166  1.1      cgd 		toinjured = MT[index][2 - die() / 3];
    167  1.1      cgd 		totalto += toinjured;
    168  1.1      cgd 		index = strengthto/10;
    169  1.1      cgd 		if (index > 8)
    170  1.1      cgd 			index = 8;
    171  1.1      cgd 		frominjured = MT[index][2 - die() / 3];
    172  1.1      cgd 		totalfrom += frominjured;
    173  1.1      cgd 		menfrom -= frominjured;
    174  1.1      cgd 		mento -= toinjured;
    175  1.1      cgd 		fromstrength = menfrom * fromcap->specs->qual;
    176  1.1      cgd 		strengthto = mento * tocap->specs->qual;
    177  1.1      cgd 	}
    178  1.1      cgd 	if (fromstrength >= strengthto * 3 || count == 4) {
    179  1.1      cgd 		unboard(to, from, 0);
    180  1.1      cgd 		subtract(from, totalfrom, crewfrom, fromcap, pcfrom);
    181  1.1      cgd 		subtract(to, totalto, crewto, tocap, pcto);
    182  1.1      cgd 		makesignal(from, "boarders from %s repelled", to);
    183  1.1      cgd 		(void) sprintf(message, "killed in melee: %d.  %s: %d",
    184  1.1      cgd 			totalto, from->shipname, totalfrom);
    185  1.1      cgd 		Write(W_SIGNAL, to, 1, (int) message, 0, 0, 0);
    186  1.1      cgd 		if (key)
    187  1.1      cgd 			return 1;
    188  1.1      cgd 	} else if (strengthto >= fromstrength * 3) {
    189  1.1      cgd 		unboard(from, to, 0);
    190  1.1      cgd 		subtract(from, totalfrom, crewfrom, fromcap, pcfrom);
    191  1.1      cgd 		subtract(to, totalto, crewto, tocap, pcto);
    192  1.1      cgd 		if (key) {
    193  1.1      cgd 			if (fromcap != from)
    194  1.1      cgd 				Write(W_POINTS, fromcap, 0,
    195  1.1      cgd 					fromcap->file->points -
    196  1.1      cgd 						from->file->struck
    197  1.1      cgd 						? from->specs->pts
    198  1.1      cgd 						: 2 * from->specs->pts,
    199  1.1      cgd 					0, 0, 0);
    200  1.1      cgd 
    201  1.1      cgd /* ptr1 points to the shipspec for the ship that was just unboarded.
    202  1.1      cgd    I guess that what is going on here is that the pointer is multiplied
    203  1.1      cgd    or something. */
    204  1.1      cgd 
    205  1.1      cgd 			Write(W_CAPTURED, from, 0, to->file->index, 0, 0, 0);
    206  1.1      cgd 			topoints = 2 * from->specs->pts + to->file->points;
    207  1.1      cgd 			if (from->file->struck)
    208  1.1      cgd 				topoints -= from->specs->pts;
    209  1.1      cgd 			Write(W_POINTS, to, 0, topoints, 0, 0, 0);
    210  1.1      cgd 			mento = crewto[0] ? crewto[0] : crewto[1];
    211  1.1      cgd 			if (mento) {
    212  1.1      cgd 				subtract(to, mento, crewto, tocap, pcto);
    213  1.1      cgd 				subtract(from, - mento, crewfrom, to, 0);
    214  1.1      cgd 			}
    215  1.1      cgd 			(void) sprintf(message, "captured by the %s!",
    216  1.1      cgd 				to->shipname);
    217  1.1      cgd 			Write(W_SIGNAL, from, 1, (int) message, 0, 0, 0);
    218  1.1      cgd 			(void) sprintf(message, "killed in melee: %d.  %s: %d",
    219  1.1      cgd 				totalto, from->shipname, totalfrom);
    220  1.1      cgd 			Write(W_SIGNAL, to, 1, (int) message, 0, 0, 0);
    221  1.1      cgd 			mento = 0;
    222  1.1      cgd 			return 0;
    223  1.1      cgd 		}
    224  1.1      cgd 	}
    225  1.1      cgd 	return 0;
    226  1.1      cgd }
    227  1.1      cgd 
    228  1.1      cgd resolve()
    229  1.1      cgd {
    230  1.1      cgd 	int thwart;
    231  1.1      cgd 	register struct ship *sp, *sq;
    232  1.1      cgd 
    233  1.1      cgd 	foreachship(sp) {
    234  1.1      cgd 		if (sp->file->dir == 0)
    235  1.1      cgd 			continue;
    236  1.1      cgd 		for (sq = sp + 1; sq < ls; sq++)
    237  1.1      cgd 			if (sq->file->dir && meleeing(sp, sq) && meleeing(sq, sp))
    238  1.1      cgd 				(void) fightitout(sp, sq, 0);
    239  1.1      cgd 		thwart = 2;
    240  1.1      cgd 		foreachship(sq) {
    241  1.1      cgd 			if (sq->file->dir && meleeing(sq, sp))
    242  1.1      cgd 				thwart = fightitout(sp, sq, 1);
    243  1.1      cgd 			if (!thwart)
    244  1.1      cgd 				break;
    245  1.1      cgd 		}
    246  1.1      cgd 		if (!thwart) {
    247  1.1      cgd 			foreachship(sq) {
    248  1.1      cgd 				if (sq->file->dir && meleeing(sq, sp))
    249  1.1      cgd 					unboard(sq, sp, 0);
    250  1.1      cgd 				unboard(sp, sq, 0);
    251  1.1      cgd 			}
    252  1.1      cgd 			unboard(sp, sp, 1);
    253  1.1      cgd 		} else if (thwart == 2)
    254  1.1      cgd 			unboard(sp, sp, 1);
    255  1.1      cgd 	}
    256  1.1      cgd }
    257  1.1      cgd 
    258  1.1      cgd compcombat()
    259  1.1      cgd {
    260  1.1      cgd 	register n;
    261  1.1      cgd 	register struct ship *sp;
    262  1.1      cgd 	struct ship *closest;
    263  1.1      cgd 	int crew[3], men = 0, target, temp;
    264  1.1      cgd 	int r, guns, ready, load, car;
    265  1.1      cgd 	int index, rakehim, sternrake;
    266  1.1      cgd 	int shootat, hit;
    267  1.1      cgd 
    268  1.1      cgd 	foreachship(sp) {
    269  1.1      cgd 		if (sp->file->captain[0] || sp->file->dir == 0)
    270  1.1      cgd 			continue;
    271  1.1      cgd 		crew[0] = sp->specs->crew1;
    272  1.1      cgd 		crew[1] = sp->specs->crew2;
    273  1.1      cgd 		crew[2] = sp->specs->crew3;
    274  1.1      cgd 		for (n = 0; n < 3; n++) {
    275  1.1      cgd 			if (sp->file->OBP[n].turnsent)
    276  1.1      cgd 				men += sp->file->OBP[n].mensent;
    277  1.1      cgd 		}
    278  1.1      cgd 		for (n = 0; n < 3; n++) {
    279  1.1      cgd 			if (sp->file->DBP[n].turnsent)
    280  1.1      cgd 				men += sp->file->DBP[n].mensent;
    281  1.1      cgd 		}
    282  1.1      cgd 		if (men){
    283  1.1      cgd 			crew[0] = men/100 ? 0 : crew[0] != 0;
    284  1.1      cgd 			crew[1] = (men%100)/10 ? 0 : crew[1] != 0;
    285  1.1      cgd 			crew[2] = men%10 ? 0 : crew[2] != 0;
    286  1.1      cgd 		}
    287  1.1      cgd 		for (r = 0; r < 2; r++) {
    288  1.1      cgd 			if (!crew[2])
    289  1.1      cgd 				continue;
    290  1.1      cgd 			if (sp->file->struck)
    291  1.1      cgd 				continue;
    292  1.1      cgd 			if (r) {
    293  1.1      cgd 				ready = sp->file->readyR;
    294  1.1      cgd 				guns = sp->specs->gunR;
    295  1.1      cgd 				car = sp->specs->carR;
    296  1.1      cgd 			} else {
    297  1.1      cgd 				ready = sp->file->readyL;
    298  1.1      cgd 				guns = sp->specs->gunL;
    299  1.1      cgd 				car = sp->specs->carL;
    300  1.1      cgd 			}
    301  1.1      cgd 			if (!guns && !car)
    302  1.1      cgd 				continue;
    303  1.1      cgd 			if ((ready & R_LOADED) == 0)
    304  1.1      cgd 				continue;
    305  1.1      cgd 			closest = closestenemy(sp, r ? 'r' : 'l', 0);
    306  1.1      cgd 			if (closest == 0)
    307  1.1      cgd 				continue;
    308  1.1      cgd 			if (range(closest, sp) > range(sp, closestenemy(sp, r ? 'r' : 'l', 1)))
    309  1.1      cgd 				continue;
    310  1.1      cgd 			if (closest->file->struck)
    311  1.1      cgd 				continue;
    312  1.1      cgd 			target = range(sp, closest);
    313  1.1      cgd 			if (target > 10)
    314  1.1      cgd 				continue;
    315  1.1      cgd 			if (!guns && target >= 3)
    316  1.1      cgd 				continue;
    317  1.1      cgd 			load = L_ROUND;
    318  1.1      cgd 			if (target == 1 && sp->file->loadwith == L_GRAPE)
    319  1.1      cgd 				load = L_GRAPE;
    320  1.1      cgd 			if (target <= 3 && closest->file->FS)
    321  1.1      cgd 				load = L_CHAIN;
    322  1.1      cgd 			if (target == 1 && load != L_GRAPE)
    323  1.1      cgd 				load = L_DOUBLE;
    324  1.1      cgd 			if (load > L_CHAIN && target < 6)
    325  1.1      cgd 				shootat = HULL;
    326  1.1      cgd 			else
    327  1.1      cgd 				shootat = RIGGING;
    328  1.1      cgd 			rakehim = gunsbear(sp, closest)
    329  1.1      cgd 				&& !gunsbear(closest, sp);
    330  1.1      cgd 			temp = portside(closest, sp, 1)
    331  1.1      cgd 				- closest->file->dir + 1;
    332  1.1      cgd 			if (temp < 1)
    333  1.1      cgd 				temp += 8;
    334  1.1      cgd 			if (temp > 8)
    335  1.1      cgd 				temp -= 8;
    336  1.1      cgd 			sternrake = temp > 4 && temp < 6;
    337  1.1      cgd 			index = guns;
    338  1.1      cgd 			if (target < 3)
    339  1.1      cgd 				index += car;
    340  1.1      cgd 			index = (index - 1) / 3;
    341  1.1      cgd 			index = index > 8 ? 8 : index;
    342  1.1      cgd 			if (!rakehim)
    343  1.1      cgd 				hit = HDT[index][target-1];
    344  1.1      cgd 			else
    345  1.1      cgd 				hit = HDTrake[index][target-1];
    346  1.1      cgd 			if (rakehim && sternrake)
    347  1.1      cgd 				hit++;
    348  1.1      cgd 			hit += QUAL[index][capship(sp)->specs->qual - 1];
    349  1.1      cgd 			for (n = 0; n < 3 && sp->file->captured == 0; n++)
    350  1.1      cgd 				if (!crew[n])
    351  1.1      cgd 					if (index <= 5)
    352  1.1      cgd 						hit--;
    353  1.1      cgd 					else
    354  1.1      cgd 						hit -= 2;
    355  1.1      cgd 			if (ready & R_INITIAL) {
    356  1.1      cgd 				if (!r)
    357  1.1      cgd 					sp->file->readyL &= ~R_INITIAL;
    358  1.1      cgd 				else
    359  1.1      cgd 					sp->file->readyR &= ~R_INITIAL;
    360  1.1      cgd 				if (index <= 3)
    361  1.1      cgd 					hit++;
    362  1.1      cgd 				else
    363  1.1      cgd 					hit += 2;
    364  1.1      cgd 			}
    365  1.1      cgd 			if (sp->file->captured != 0)
    366  1.1      cgd 				if (index <= 1)
    367  1.1      cgd 					hit--;
    368  1.1      cgd 				else
    369  1.1      cgd 					hit -= 2;
    370  1.1      cgd 			hit += AMMO[index][load - 1];
    371  1.1      cgd 			temp = sp->specs->class;
    372  1.1      cgd 			if ((temp >= 5 || temp == 1) && windspeed == 5)
    373  1.1      cgd 				hit--;
    374  1.1      cgd 			if (windspeed == 6 && temp == 4)
    375  1.1      cgd 				hit -= 2;
    376  1.1      cgd 			if (windspeed == 6 && temp <= 3)
    377  1.1      cgd 				hit--;
    378  1.1      cgd 			if (hit >= 0) {
    379  1.1      cgd 				if (load != L_GRAPE)
    380  1.1      cgd 					hit = hit > 10 ? 10 : hit;
    381  1.1      cgd 				table(shootat, load, hit, closest, sp, die());
    382  1.1      cgd 			}
    383  1.1      cgd 		}
    384  1.1      cgd 	}
    385  1.1      cgd }
    386  1.1      cgd 
    387  1.1      cgd next()
    388  1.1      cgd {
    389  1.1      cgd 	if (++turn % 55 == 0)
    390  1.1      cgd 		if (alive)
    391  1.1      cgd 			alive = 0;
    392  1.1      cgd 		else
    393  1.1      cgd 			people = 0;
    394  1.1      cgd 	if (people <= 0 || windspeed == 7) {
    395  1.1      cgd 		register struct ship *s;
    396  1.1      cgd 		struct ship *bestship;
    397  1.1      cgd 		float net, best = 0.0;
    398  1.1      cgd 		foreachship(s) {
    399  1.1      cgd 			if (*s->file->captain)
    400  1.1      cgd 				continue;
    401  1.1      cgd 			net = (float)s->file->points / s->specs->pts;
    402  1.1      cgd 			if (net > best) {
    403  1.1      cgd 				best = net;
    404  1.1      cgd 				bestship = s;
    405  1.1      cgd 			}
    406  1.1      cgd 		}
    407  1.1      cgd 		if (best > 0.0) {
    408  1.1      cgd 			char *p = getenv("WOTD");
    409  1.1      cgd 			if (p == 0)
    410  1.1      cgd 				p = "Driver";
    411  1.1      cgd 			if (islower(*p))
    412  1.1      cgd 				*p = toupper(*p);
    413  1.1      cgd 			(void) strncpy(bestship->file->captain, p,
    414  1.1      cgd 				sizeof bestship->file->captain);
    415  1.1      cgd 			bestship->file->captain
    416  1.1      cgd 				[sizeof bestship->file->captain - 1] = 0;
    417  1.1      cgd 			log(bestship);
    418  1.1      cgd 		}
    419  1.1      cgd 		return -1;
    420  1.1      cgd 	}
    421  1.1      cgd 	Write(W_TURN, SHIP(0), 0, turn, 0, 0, 0);
    422  1.1      cgd 	if (turn % 7 == 0 && (die() >= cc->windchange || !windspeed)) {
    423  1.1      cgd 		switch (die()) {
    424  1.1      cgd 		case 1:
    425  1.1      cgd 			winddir = 1;
    426  1.1      cgd 			break;
    427  1.1      cgd 		case 2:
    428  1.1      cgd 			break;
    429  1.1      cgd 		case 3:
    430  1.1      cgd 			winddir++;
    431  1.1      cgd 			break;
    432  1.1      cgd 		case 4:
    433  1.1      cgd 			winddir--;
    434  1.1      cgd 			break;
    435  1.1      cgd 		case 5:
    436  1.1      cgd 			winddir += 2;
    437  1.1      cgd 			break;
    438  1.1      cgd 		case 6:
    439  1.1      cgd 			winddir -= 2;
    440  1.1      cgd 			break;
    441  1.1      cgd 		}
    442  1.1      cgd 		if (winddir > 8)
    443  1.1      cgd 			winddir -= 8;
    444  1.1      cgd 		if (winddir < 1)
    445  1.1      cgd 			winddir += 8;
    446  1.1      cgd 		if (windspeed)
    447  1.1      cgd 			switch (die()) {
    448  1.1      cgd 			case 1:
    449  1.1      cgd 			case 2:
    450  1.1      cgd 				windspeed--;
    451  1.1      cgd 				break;
    452  1.1      cgd 			case 5:
    453  1.1      cgd 			case 6:
    454  1.1      cgd 				windspeed++;
    455  1.1      cgd 				break;
    456  1.1      cgd 			}
    457  1.1      cgd 		else
    458  1.1      cgd 			windspeed++;
    459  1.1      cgd 		Write(W_WIND, SHIP(0), 0, winddir, windspeed, 0, 0);
    460  1.1      cgd 	}
    461  1.1      cgd 	return 0;
    462  1.1      cgd }
    463