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