xref: /original-bsd/games/sail/dr_5.c (revision 65d10654)
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[] = "@(#)dr_5.c	8.2 (Berkeley) 04/28/95";
10 #endif /* not lint */
11 
12 #include "extern.h"
13 
14 subtract(from, totalfrom, crewfrom, fromcap, pcfrom)
15 struct ship *from, *fromcap;
16 int pcfrom;
17 register int  totalfrom, crewfrom[3];
18 {
19 	register int n;
20 
21 	if (fromcap == from && totalfrom) {		/* if not captured */
22 		for (n = 0; n < 3; n++) {
23 			if (totalfrom > crewfrom[n]) {
24 				totalfrom -= crewfrom[n];
25 				crewfrom[n] = 0;
26 			} else {
27 				crewfrom[n] -= totalfrom;
28 				totalfrom = 0;
29 			}
30 		}
31 		Write(W_CREW, from, 0, crewfrom[0], crewfrom[1], crewfrom[2], 0);
32 	} else if (totalfrom) {
33 		pcfrom -= totalfrom;
34 		pcfrom = pcfrom < 0 ? 0 : pcfrom;
35 		Write(W_PCREW, from, 0, pcfrom, 0, 0, 0);
36 	}
37 }
38 
39 mensent(from, to, crew, captured, pc, isdefense)
40 struct ship *from, *to, **captured;
41 int crew[3], *pc;
42 char isdefense;
43 {					/* returns # of crew squares sent */
44 	int men = 0;
45 	register int n;
46 	int c1, c2, c3;
47 	register struct BP *bp;
48 
49 	*pc = from->file->pcrew;
50 	*captured = from->file->captured;
51 	crew[0] = from->specs->crew1;
52 	crew[1] = from->specs->crew2;
53 	crew[2] = from->specs->crew3;
54 	bp = isdefense ? from->file->DBP : from->file->OBP;
55 	for (n=0; n < NBP; n++, bp++) {
56 		if (bp->turnsent && bp->toship == to)
57 			men += bp->mensent;
58 	}
59 	if (men) {
60 		c1 = men/100 ? crew[0] : 0;
61 		c2 = (men%100)/10 ? crew[1] : 0;
62 		c3 = men/10 ? crew[2] : 0;
63 		c3 = *captured == 0 ? crew[2] : *pc;
64 	} else
65 		c1 = c2 = c3 = 0;
66 	return(c1 + c2 + c3);
67 }
68