| 1 | #ifndef lint |
| 2 | static char *sccsid = "@(#)dr_5.c 2.1 83/10/31"; |
| 3 | #endif |
| 4 | #include "externs.h" |
| 5 | |
| 6 | subtract(from, totalfrom, crewfrom, fromcap, pcfrom) |
| 7 | struct ship *from, *fromcap; |
| 8 | int pcfrom; |
| 9 | register int totalfrom, crewfrom[3]; |
| 10 | { |
| 11 | register int n; |
| 12 | |
| 13 | if (fromcap == from && totalfrom) { /* if not captured */ |
| 14 | for (n = 0; n < 3; n++) { |
| 15 | if (totalfrom > crewfrom[n]) { |
| 16 | totalfrom -= crewfrom[n]; |
| 17 | crewfrom[n] = 0; |
| 18 | } else { |
| 19 | crewfrom[n] -= totalfrom; |
| 20 | totalfrom = 0; |
| 21 | } |
| 22 | } |
| 23 | Write(W_CREW, from, 0, crewfrom[0], crewfrom[1], crewfrom[2], 0); |
| 24 | } else if (totalfrom) { |
| 25 | pcfrom -= totalfrom; |
| 26 | pcfrom = pcfrom < 0 ? 0 : pcfrom; |
| 27 | Write(W_PCREW, from, 0, pcfrom, 0, 0, 0); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | mensent(from, to, crew, captured, pc, isdefense) |
| 32 | struct ship *from, *to, **captured; |
| 33 | int crew[3], *pc; |
| 34 | char isdefense; |
| 35 | { /* returns # of crew squares sent */ |
| 36 | int men = 0; |
| 37 | register int n; |
| 38 | int c1, c2, c3; |
| 39 | register struct BP *bp; |
| 40 | |
| 41 | *pc = from->file->pcrew; |
| 42 | *captured = from->file->captured; |
| 43 | crew[0] = from->specs->crew1; |
| 44 | crew[1] = from->specs->crew2; |
| 45 | crew[2] = from->specs->crew3; |
| 46 | bp = isdefense ? from->file->DBP : from->file->OBP; |
| 47 | for (n=0; n < NBP; n++, bp++) { |
| 48 | if (bp->turnsent && bp->toship == to) |
| 49 | men += bp->mensent; |
| 50 | } |
| 51 | if (men) { |
| 52 | c1 = men/100 ? crew[0] : 0; |
| 53 | c2 = (men%100)/10 ? crew[1] : 0; |
| 54 | c3 = men/10 ? crew[2] : 0; |
| 55 | c3 = *captured == 0 ? crew[2] : *pc; |
| 56 | } else |
| 57 | c1 = c2 = c3 = 0; |
| 58 | return(c1 + c2 + c3); |
| 59 | } |