drm/linux: Add kasprintf and kvasprintf()
[dragonfly.git] / games / sail / dr_5.c
blob203f3d205a81f0ed8e1ddc68434e42fe35e949b1
1 /*-
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
29 * @(#)dr_5.c 8.1 (Berkeley) 5/31/93
30 * $FreeBSD: src/games/sail/dr_5.c,v 1.4 1999/11/30 03:49:33 billf Exp $
33 #include "externs.h"
35 void
36 subtract(struct ship *from, int totalfrom, int crewfrom[3], struct ship *fromcap, int pcfrom)
38 int n;
40 if (fromcap == from && totalfrom) { /* if not captured */
41 for (n = 0; n < 3; n++) {
42 if (totalfrom > crewfrom[n]) {
43 totalfrom -= crewfrom[n];
44 crewfrom[n] = 0;
45 } else {
46 crewfrom[n] -= totalfrom;
47 totalfrom = 0;
50 Write(W_CREW, from, crewfrom[0], crewfrom[1], crewfrom[2], 0);
51 } else if (totalfrom) {
52 pcfrom -= totalfrom;
53 pcfrom = pcfrom < 0 ? 0 : pcfrom;
54 Write(W_PCREW, from, pcfrom, 0, 0, 0);
58 int
59 mensent(struct ship *from, struct ship *to, int crew[3], struct ship **captured, int *pc, char isdefense)
60 { /* returns # of crew squares sent */
61 int men = 0;
62 int n;
63 int c1, c2, c3;
64 struct BP *bp;
66 *pc = from->file->pcrew;
67 *captured = from->file->captured;
68 crew[0] = from->specs->crew1;
69 crew[1] = from->specs->crew2;
70 crew[2] = from->specs->crew3;
71 bp = isdefense ? from->file->DBP : from->file->OBP;
72 for (n=0; n < NBP; n++, bp++) {
73 if (bp->turnsent && bp->toship == to)
74 men += bp->mensent;
76 if (men) {
77 c1 = men/100 ? crew[0] : 0;
78 c2 = (men%100)/10 ? crew[1] : 0;
79 c3 = men/10 ? crew[2] : 0;
80 c3 = *captured == NULL ? crew[2] : *pc;
81 } else
82 c1 = c2 = c3 = 0;
83 return(c1 + c2 + c3);