]> git.pond.sub.org Git - empserver/blob - src/lib/commands/sail.c
autonav: Remove the feature
[empserver] / src / lib / commands / sail.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2014, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                Ken Stevens, Steve McClure, Markus Armbruster
5  *
6  *  Empire 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 3 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, see <http://www.gnu.org/licenses/>.
18  *
19  *  ---
20  *
21  *  See files README, COPYING and CREDITS in the root of the source
22  *  tree for related information and legal notices.  It is expected
23  *  that future projects/authors will amend these files as needed.
24  *
25  *  ---
26  *
27  *  sail.c: Set sail path for leaders
28  *
29  *  Known contributors to this file:
30  *     Robert Forsman
31  */
32
33 #include <config.h>
34
35 #include "commands.h"
36 #include "optlist.h"
37 #include "path.h"
38 #include "ship.h"
39
40 static int
41 show_sail(struct nstr_item *nstr)
42 {
43     int count = 0;
44     struct shpstr ship;
45
46     while (nxtitem(nstr, &ship)) {
47         if (!player->owner || ship.shp_own == 0)
48             continue;
49         if (count++ == 0) {
50             if (player->god)
51                 pr("own ");
52             pr("shp#     ship type       x,y    ");
53             pr("mobil mobquota follows path\n");
54         }
55         if (player->god)
56             pr("%3d ", ship.shp_own);
57         pr("%4d ", ship.shp_uid);
58         pr("%-16.16s ", mchr[(int)ship.shp_type].m_name);
59         prxy("%4d,%-4d ", ship.shp_x, ship.shp_y);
60         pr("%3d  ", ship.shp_mobil);
61         pr("   %3d     ", ship.shp_mobquota);
62         pr("   %3d   ", ship.shp_follow);
63         if (ship.shp_path[0]) {
64             pr("%s", ship.shp_path);
65         }
66         pr("\n");
67         if (ship.shp_name[0] != 0) {
68             if (player->god)
69                 pr("    ");
70             pr("       %s\n", ship.shp_name);
71         }
72     }
73     if (count == 0) {
74         if (player->argp[1])
75             pr("%s: No ship(s)\n", player->argp[1]);
76         else
77             pr("%s: No ship(s)\n", "");
78         return RET_FAIL;
79     } else
80         pr("%d ship%s\n", count, splur(count));
81     return RET_OK;
82 }
83
84 static int
85 cmd_unsail_ship(struct nstr_item *nstr)
86 {
87     struct shpstr ship;
88     int count = 0;
89
90     while (nxtitem(nstr, &ship)) {
91         if (!player->owner || ship.shp_own == 0)
92             continue;
93         if (ship.shp_path[0]) {
94             pr("Ship #%d unsailed\n", ship.shp_uid);
95             count++;
96             ship.shp_path[0] = 0;
97             putship(ship.shp_uid, &ship);
98         }
99     }
100     return RET_OK;
101 }
102
103 static int
104 cmd_sail_ship(struct nstr_item *nstr)
105 {
106     char *cp;
107     struct shpstr ship;
108     char navpath[MAX_PATH_LEN];
109
110     while (nxtitem(nstr, &ship)) {
111         if (!player->owner || ship.shp_own == 0)
112             continue;
113
114         pr("Ship #%d at %s\n", ship.shp_uid,
115            xyas(ship.shp_x, ship.shp_y, player->cnum));
116         cp = getpath(navpath, player->argp[2],
117                      ship.shp_x, ship.shp_y, 0, 0, MOB_SAIL);
118         if (!cp)
119             return RET_FAIL;
120         if (!check_ship_ok(&ship))
121             continue;
122         strncpy(ship.shp_path, cp, sizeof(ship.shp_path) - 1);
123         ship.shp_mission = 0;
124         putship(ship.shp_uid, &ship);
125     }
126     return RET_OK;
127 }
128
129 int
130 sail(void)
131 {
132     char *cp;
133     struct nstr_item nstr;
134
135     if (!opt_SAIL) {
136         pr("The SAIL option is not enabled, so this command is not valid.\n");
137         return RET_FAIL;
138     }
139     if (!snxtitem(&nstr, EF_SHIP, player->argp[1], NULL))
140         return RET_SYN;
141     cp = player->argp[2];
142     if (*player->argp[0] == 'u' || (cp && !strcmp(cp, "-")))
143         return cmd_unsail_ship(&nstr);
144     if (cp && *cp == 'q')
145         return show_sail(&nstr);
146     return cmd_sail_ship(&nstr);
147 }