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