sprintf doesn't necessarily return its first arg
[unix-history] / usr / src / games / sail / pl_6.c
CommitLineData
b5f0675e 1/*
1e008c14
DF
2 * Copyright (c) 1983 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
b5f0675e
EW
5 */
6
7b487c4c 7#ifndef lint
1e008c14
DF
8static char sccsid[] = "@(#)pl_6.c 5.1 (Berkeley) %G%";
9#endif not lint
7b487c4c
EW
10
11#include "player.h"
12
13repair()
14{
15 char c;
586c712a
EW
16 register char *repairs;
17 register struct shipspecs *ptr = mc;
18 register int count;
19
20#define FIX(x, m) (m - ptr->x > count \
21 ? (ptr->x += count, count = 0) : (count -= m - ptr->x, ptr->x = m))
7b487c4c
EW
22
23 if (repaired || loaded || fired || changed || turned()) {
24 Signal("No hands free to repair", (struct ship *)0);
25 return;
26 }
7b487c4c
EW
27 c = sgetch("Repair (hull, guns, rigging)? ", (struct ship *)0, 1);
28 switch (c) {
29 case 'h':
30 repairs = &mf->RH;
31 break;
32 case 'g':
33 repairs = &mf->RG;
34 break;
35 case 'r':
36 repairs = &mf->RR;
37 break;
38 default:
39 Signal("Avast heaving!", (struct ship *)0);
40 return;
41 }
7b487c4c 42 if (++*repairs >= 3) {
586c712a 43 count = 2;
7b487c4c 44 switch (c) {
586c712a
EW
45 case 'h': {
46 int max = ptr->guns/4;
47 if (ptr->hull < max) {
48 FIX(hull, max);
49 Write(W_HULL, ms, 0, ptr->hull, 0, 0, 0);
50 }
7b487c4c 51 break;
586c712a 52 }
7b487c4c
EW
53 case 'g':
54 if (ptr->gunL < ptr->gunR) {
586c712a
EW
55 int max = ptr->guns/5 - ptr->carL;
56 if (ptr->gunL < max) {
57 FIX(gunL, max);
58 Write(W_GUNL, ms, 0, ptr->gunL,
59 ptr->carL, 0, 0);
60 }
61 } else {
62 int max = ptr->guns/5 - ptr->carR;
63 if (ptr->gunR < max) {
64 FIX(gunR, max);
65 Write(W_GUNR, ms, 0, ptr->gunR,
66 ptr->carR, 0, 0);
67 }
68 }
7b487c4c
EW
69 break;
70 case 'r':
586c712a
EW
71#define X 2
72 if (ptr->rig4 >= 0 && ptr->rig4 < X) {
73 FIX(rig4, X);
74 Write(W_RIG4, ms, 0, ptr->rig4, 0, 0, 0);
75 }
76 if (count && ptr->rig3 < X) {
77 FIX(rig3, X);
78 Write(W_RIG3, ms, 0, ptr->rig3, 0, 0, 0);
79 }
80 if (count && ptr->rig2 < X) {
81 FIX(rig2, X);
82 Write(W_RIG2, ms, 0, ptr->rig2, 0, 0, 0);
83 }
84 if (count && ptr->rig1 < X) {
85 FIX(rig1, X);
86 Write(W_RIG1, ms, 0, ptr->rig1, 0, 0, 0);
87 }
7b487c4c
EW
88 break;
89 }
586c712a 90 if (count == 2) {
7b487c4c 91 Signal("Repairs completed.", (struct ship *)0);
fcc6b1db
EW
92 *repairs = 2;
93 } else {
94 *repairs = 0;
490c485f 95 blockalarm();
fcc6b1db 96 draw_stat();
490c485f 97 unblockalarm();
fcc6b1db 98 }
7b487c4c 99 }
490c485f 100 blockalarm();
fcc6b1db 101 draw_slot();
490c485f 102 unblockalarm();
586c712a 103 repaired = 1;
7b487c4c
EW
104}
105
106turned()
107{
108 register char *p;
109
110 for (p = movebuf; *p; p++)
111 if (*p == 'r' || *p == 'l')
112 return 1;
113 return 0;
114}
115
116loadplayer()
117{
118 char c;
119 register loadL, loadR, ready, load;
120
121 if (!mc->crew3) {
122 Signal("Out of crew", (struct ship *)0);
123 return;
124 }
125 loadL = mf->loadL;
126 loadR = mf->loadR;
127 if (!loadL && !loadR) {
128 c = sgetch("Load which broadside (left or right)? ",
129 (struct ship *)0, 1);
130 if (c == 'r')
131 loadL = 1;
132 else
133 loadR = 1;
134 }
135 if (!loadL && loadR || loadL && !loadR) {
136 c = sgetch("Reload with (round, double, chain, grape)? ",
137 (struct ship *)0, 1);
138 switch (c) {
139 case 'r':
140 load = L_ROUND;
141 ready = 0;
142 break;
143 case 'd':
144 load = L_DOUBLE;
145 ready = R_DOUBLE;
146 break;
147 case 'c':
148 load = L_CHAIN;
149 ready = 0;
150 break;
151 case 'g':
152 load = L_GRAPE;
153 ready = 0;
154 break;
155 default:
156 Signal("Broadside not loaded.",
157 (struct ship *)0);
158 return;
159 }
160 if (!loadR) {
161 mf->loadR = load;
162 mf->readyR = ready|R_LOADING;
163 } else {
164 mf->loadL = load;
165 mf->readyL = ready|R_LOADING;
166 }
167 loaded = 1;
168 }
169}