xref: /original-bsd/games/sail/pl_6.c (revision 2301fdfb)
1 /*
2  * Copyright (c) 1983 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  */
17 
18 #ifndef lint
19 static char sccsid[] = "@(#)pl_6.c	5.3 (Berkeley) 06/18/88";
20 #endif /* not lint */
21 
22 #include "player.h"
23 
24 repair()
25 {
26 	char c;
27 	register char *repairs;
28 	register struct shipspecs *ptr = mc;
29 	register int count;
30 
31 #define FIX(x, m) (m - ptr->x > count \
32 	? (ptr->x += count, count = 0) : (count -= m - ptr->x, ptr->x = m))
33 
34 	if (repaired || loaded || fired || changed || turned()) {
35 		Signal("No hands free to repair", (struct ship *)0);
36 		return;
37 	}
38 	c = sgetch("Repair (hull, guns, rigging)? ", (struct ship *)0, 1);
39 	switch (c) {
40 		case 'h':
41 			repairs = &mf->RH;
42 			break;
43 		case 'g':
44 			repairs = &mf->RG;
45 			break;
46 		case 'r':
47 			repairs = &mf->RR;
48 			break;
49 		default:
50 			Signal("Avast heaving!", (struct ship *)0);
51 			return;
52 	}
53 	if (++*repairs >= 3) {
54 		count = 2;
55 		switch (c) {
56 		case 'h': {
57 			int max = ptr->guns/4;
58 			if (ptr->hull < max) {
59 				FIX(hull, max);
60 				Write(W_HULL, ms, 0, ptr->hull, 0, 0, 0);
61 			}
62 			break;
63 			}
64 		case 'g':
65 			if (ptr->gunL < ptr->gunR) {
66 				int max = ptr->guns/5 - ptr->carL;
67 				if (ptr->gunL < max) {
68 					FIX(gunL, max);
69 					Write(W_GUNL, ms, 0, ptr->gunL,
70 						ptr->carL, 0, 0);
71 				}
72 			} else {
73 				int max = ptr->guns/5 - ptr->carR;
74 				if (ptr->gunR < max) {
75 					FIX(gunR, max);
76 					Write(W_GUNR, ms, 0, ptr->gunR,
77 						ptr->carR, 0, 0);
78 				}
79 			}
80 			break;
81 		case 'r':
82 #define X 2
83 			if (ptr->rig4 >= 0 && ptr->rig4 < X) {
84 				FIX(rig4, X);
85 				Write(W_RIG4, ms, 0, ptr->rig4, 0, 0, 0);
86 			}
87 			if (count && ptr->rig3 < X) {
88 				FIX(rig3, X);
89 				Write(W_RIG3, ms, 0, ptr->rig3, 0, 0, 0);
90 			}
91 			if (count && ptr->rig2 < X) {
92 				FIX(rig2, X);
93 				Write(W_RIG2, ms, 0, ptr->rig2, 0, 0, 0);
94 			}
95 			if (count && ptr->rig1 < X) {
96 				FIX(rig1, X);
97 				Write(W_RIG1, ms, 0, ptr->rig1, 0, 0, 0);
98 			}
99 			break;
100 		}
101 		if (count == 2) {
102 			Signal("Repairs completed.", (struct ship *)0);
103 			*repairs = 2;
104 		} else {
105 			*repairs = 0;
106 			blockalarm();
107 			draw_stat();
108 			unblockalarm();
109 		}
110 	}
111 	blockalarm();
112 	draw_slot();
113 	unblockalarm();
114 	repaired = 1;
115 }
116 
117 turned()
118 {
119 	register char *p;
120 
121 	for (p = movebuf; *p; p++)
122 		if (*p == 'r' || *p == 'l')
123 			return 1;
124 	return 0;
125 }
126 
127 loadplayer()
128 {
129 	char c;
130 	register loadL, loadR, ready, load;
131 
132 	if (!mc->crew3) {
133 		Signal("Out of crew", (struct ship *)0);
134 		return;
135 	}
136 	loadL = mf->loadL;
137 	loadR = mf->loadR;
138 	if (!loadL && !loadR) {
139 		c = sgetch("Load which broadside (left or right)? ",
140 			(struct ship *)0, 1);
141 		if (c == 'r')
142 			loadL = 1;
143 		else
144 			loadR = 1;
145 	}
146 	if (!loadL && loadR || loadL && !loadR) {
147 		c = sgetch("Reload with (round, double, chain, grape)? ",
148 			(struct ship *)0, 1);
149 		switch (c) {
150 		case 'r':
151 			load = L_ROUND;
152 			ready = 0;
153 			break;
154 		case 'd':
155 			load = L_DOUBLE;
156 			ready = R_DOUBLE;
157 			break;
158 		case 'c':
159 			load = L_CHAIN;
160 			ready = 0;
161 			break;
162 		case 'g':
163 			load = L_GRAPE;
164 			ready = 0;
165 			break;
166 		default:
167 			Signal("Broadside not loaded.",
168 				(struct ship *)0);
169 			return;
170 		}
171 		if (!loadR) {
172 			mf->loadR = load;
173 			mf->readyR = ready|R_LOADING;
174 		} else {
175 			mf->loadL = load;
176 			mf->readyL = ready|R_LOADING;
177 		}
178 		loaded = 1;
179 	}
180 }
181