BSD 4_4_Lite2 release
[unix-history] / usr / src / games / sail / game.c
CommitLineData
b5f0675e 1/*
9dceaff0
KB
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
c0ca48ec 4 *
c0567266
KB
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. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
b5f0675e
EW
32 */
33
cd818f56 34#ifndef lint
fd88f5c5 35static char sccsid[] = "@(#)game.c 8.2 (Berkeley) 4/28/95";
c0ca48ec 36#endif /* not lint */
cd818f56 37
1833b448 38#include "extern.h"
cd818f56 39
6c17b19a 40maxturns(ship, af)
b3a57661 41register struct ship *ship;
6c17b19a 42char *af;
cd818f56 43{
7fc06086 44 register int turns;
cd818f56 45
b3a57661 46 turns = ship->specs->ta;
6c17b19a 47 if (*af = (ship->file->drift > 1 && turns)) {
cd818f56 48 turns--;
b3a57661 49 if (ship->file->FS == 1)
cd818f56 50 turns = 0;
cd818f56 51 }
b3a57661 52 return turns;
cd818f56
CL
53}
54
b3a57661
EW
55maxmove(ship, dir, fs)
56register struct ship *ship;
57int dir, fs;
cd818f56 58{
b3a57661 59 register int riggone = 0, Move, flank = 0;
cd818f56 60
b3a57661
EW
61 Move = ship->specs->bs;
62 if (!ship->specs->rig1)
63 riggone++;
64 if (!ship->specs->rig2)
65 riggone++;
66 if (!ship->specs->rig3)
67 riggone++;
68 if (!ship->specs->rig4)
69 riggone++;
70 if ((ship->file->FS || fs) && fs != -1) {
cd818f56 71 flank = 1;
b3a57661 72 Move = ship->specs->fs;
cd818f56
CL
73 }
74 if (dir == winddir)
b3a57661 75 Move -= 1 + WET[windspeed][ship->specs->class-1].B;
cd818f56 76 else if (dir == winddir + 2 || dir == winddir - 2 || dir == winddir - 6 || dir == winddir + 6)
b3a57661 77 Move -= 1 + WET[windspeed][ship->specs->class-1].C;
cd818f56 78 else if (dir == winddir + 3 || dir == winddir - 3 || dir == winddir - 5 || dir == winddir + 5)
b3a57661 79 Move = (flank ? 2 : 1) - WET[windspeed][ship->specs->class-1].D;
cd818f56
CL
80 else if (dir == winddir + 4 || dir == winddir - 4)
81 Move = 0;
82 else
b3a57661 83 Move -= WET[windspeed][ship->specs->class-1].A;
cd818f56
CL
84 Move -= riggone;
85 Move = Move < 0 ? 0 : Move;
86 return(Move);
87}