pl_4.c revision 1.6
1/*	$OpenBSD: pl_4.c,v 1.6 2015/12/31 16:44:22 mestre Exp $	*/
2/*	$NetBSD: pl_4.c,v 1.4 1995/04/24 12:25:17 cgd Exp $	*/
3
4/*
5 * Copyright (c) 1983, 1993
6 *	The Regents of the University of California.  All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 *    may be used to endorse or promote products derived from this software
18 *    without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#include <ctype.h>
34
35#include "extern.h"
36#include "player.h"
37
38void
39changesail()
40{
41	int rig, full;
42
43	rig = mc->rig1;
44	full = mf->FS;
45	if (windspeed == 6 || (windspeed == 5 && mc->class > 4))
46		rig = 0;
47	if (mc->crew3 && rig) {
48		if (!full) {
49			if (sgetch("Increase to Full sails? ",
50				(struct ship *)0, 1) == 'y') {
51				changed = 1;
52				Write(W_FS, ms, 1, 0, 0, 0);
53			}
54		} else {
55			if (sgetch("Reduce to Battle sails? ",
56				(struct ship *)0, 1) == 'y') {
57				Write(W_FS, ms, 0, 0, 0, 0);
58				changed = 1;
59			}
60		}
61	} else if (!rig)
62		Msg("Sails rent to pieces");
63}
64
65void
66acceptsignal()
67{
68	char buf[60];
69	char *p = buf;
70
71	*p++ = '"';
72	sgetstr("Message? ", p, sizeof buf - 2);
73	while (*p++)
74		;
75	p[-1] = '"';
76	*p = 0;
77	Writestr(W_SIGNAL, ms, buf);
78}
79
80void
81lookout()
82{
83	struct ship *sp;
84	char buf[3];
85	char c;
86
87	sgetstr("What ship? ", buf, sizeof buf);
88	foreachship(sp) {
89		c = *countryname[sp->nationality];
90		if ((c == *buf || tolower((unsigned char)c) == *buf || colours(sp) == *buf)
91		    && (sp->file->stern == buf[1] || sterncolour(sp) == buf[1]
92			|| buf[1] == '?')) {
93			eyeball(sp);
94		}
95	}
96}
97
98const char *
99saywhat(sp, flag)
100	struct ship *sp;
101	char flag;
102{
103	if (sp->file->captain[0])
104		return sp->file->captain;
105	else if (sp->file->struck)
106		return "(struck)";
107	else if (sp->file->captured != 0)
108		return "(captured)";
109	else if (flag)
110		return "(available)";
111	else
112		return "(computer)";
113}
114
115void
116eyeball(ship)
117	struct ship *ship;
118{
119	int i;
120
121	if (ship->file->dir != 0) {
122		Msg("Sail ho! (range %d, %s)",
123		    range(ms, ship), saywhat(ship, 0));
124		i = portside(ms, ship, 1) - mf->dir;
125		if (i <= 0)
126			i += 8;
127		Signal("$$ %s %s %s.",
128			ship, countryname[ship->nationality],
129			classname[ship->specs->class], directionname[i]);
130	}
131}
132