]> git.pond.sub.org Git - empserver/blob - src/lib/commands/sail.c
(getpath): Parameter showxy makes no sense and is not used. Remove.
[empserver] / src / lib / commands / sail.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23  *  related information and legal notices. It is expected that any future
24  *  projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  sail.c: Set sail path for leaders
29  * 
30  *  Known contributors to this file:
31  *     Robert Forsman
32  */
33
34 #include <ctype.h>
35 #include "misc.h"
36 #include "player.h"
37 #include "ship.h"
38 #include "path.h"
39 #include "xy.h"
40 #include "nsc.h"
41 #include "file.h"
42 #include "commands.h"
43 #include "optlist.h"
44
45 static int
46 show_sail(struct nstr_item *nstr)
47 {
48     int count = 0;
49     struct shpstr ship;
50
51     while (nxtitem(nstr, &ship)) {
52         if (!player->owner || ship.shp_own == 0)
53             continue;
54         if (ship.shp_type < 0 || ship.shp_type > shp_maxno) {
55             pr("bad ship type %d (#%d)\n", ship.shp_type, nstr->cur);
56             continue;
57         }
58         if (count++ == 0) {
59             if (player->god)
60                 pr("own ");
61             pr("shp#     ship type       x,y    ");
62             pr("mobil mobquota follows path\n");
63         }
64         if (player->god)
65             pr("%3d ", ship.shp_own);
66         pr("%4d ", ship.shp_uid);
67         pr("%-16.16s ", mchr[(int)ship.shp_type].m_name);
68         prxy("%4d,%-4d ", ship.shp_x, ship.shp_y, player->cnum);
69         pr("%3d  ", ship.shp_mobil);
70         pr("   %3d     ", ship.shp_mobquota);
71         pr("   %3d   ", ship.shp_follow);
72         if (ship.shp_path[0]) {
73             pr(ship.shp_path);
74         } else if ((ship.shp_autonav & AN_AUTONAV)) {
75             pr("Has orders");
76         }
77         pr("\n");
78         if (ship.shp_name[0] != 0) {
79             if (player->god)
80                 pr("    ");
81             pr("       %s\n", ship.shp_name);
82         }
83     }
84     if (count == 0) {
85         if (player->argp[1])
86             pr("%s: No ship(s)\n", player->argp[1]);
87         else
88             pr("%s: No ship(s)\n", "");
89         return RET_FAIL;
90     } else
91         pr("%d ship%s\n", count, splur(count));
92     return RET_OK;
93 }
94
95 static int
96 cmd_unsail_ship(struct nstr_item *nstr)
97 {
98     struct shpstr ship;
99     int count = 0;
100
101     while (nxtitem(nstr, &ship)) {
102         if (!player->owner || ship.shp_own == 0)
103             continue;
104         if (ship.shp_type < 0 || ship.shp_type > shp_maxno) {
105             pr("bad ship type %d (#%d)\n", ship.shp_type, nstr->cur);
106             continue;
107         }
108         if (ship.shp_path[0]) {
109             pr("Ship #%d unsailed\n", ship.shp_uid);
110             count++;
111             ship.shp_path[0] = 0;
112             putship(ship.shp_uid, &ship);
113         }
114     }
115     return RET_OK;
116 }
117
118 static int
119 cmd_sail_ship(struct nstr_item *nstr)
120 {
121     s_char *cp;
122     struct shpstr ship;
123     char navpath[MAX_PATH_LEN];
124
125     while (!player->aborted && nxtitem(nstr, &ship)) {
126         if (!player->owner || ship.shp_own == 0)
127             continue;
128         if (ship.shp_type < 0 || ship.shp_type > shp_maxno) {
129             pr("bad ship type %d (#%d)\n", ship.shp_type, nstr->cur);
130             continue;
131         }
132         if ((ship.shp_autonav & AN_AUTONAV) &&
133             !(ship.shp_autonav & AN_STANDBY)) {
134             pr("Ship #%d has other orders!\n", ship.shp_uid);
135             continue;
136         }
137
138         pr("Ship #%d at %s\n", ship.shp_uid,
139            xyas(ship.shp_x, ship.shp_y, ship.shp_own));
140         cp = getpath(navpath, player->argp[2],
141                      ship.shp_x, ship.shp_y, 0, 0, P_SAILING);
142         if (!check_ship_ok(&ship))
143             continue;
144         if (!player->aborted) {
145             strncpy(ship.shp_path, cp, sizeof(ship.shp_path) - 2);
146             ship.shp_mission = 0;
147             putship(ship.shp_uid, &ship);
148         }
149     }
150     return RET_OK;
151 }
152
153 int
154 sail(void)
155 {
156     s_char *cp;
157     struct nstr_item nstr;
158
159     if (!opt_SAIL) {
160         pr("The SAIL option is not enabled, so this command is not valid.\n");
161         return RET_FAIL;
162     }
163     if (!snxtitem(&nstr, EF_SHIP, player->argp[1]))
164         return RET_SYN;
165     cp = player->argp[2];
166     if ((*player->argp[0] == 'q') /*qsail command */ ||(cp && *cp == 'q')) {
167         return show_sail(&nstr);
168     } else if (*player->argp[0] == 'u'  /*unsail command */
169                || (cp && *cp == '-')) {
170         return cmd_unsail_ship(&nstr);
171     } else
172         return cmd_sail_ship(&nstr);
173 }