]> git.pond.sub.org Git - empserver/blob - src/lib/commands/foll.c
Update copyright notice.
[empserver] / src / lib / commands / foll.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2007, 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 files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  foll.c: Set leader of a set of ships
29  * 
30  *  Known contributors to this file:
31  *     Robert Forsman
32  */
33
34 #include <config.h>
35
36 #include "commands.h"
37 #include "optlist.h"
38 #include "ship.h"
39 #include <ctype.h>
40
41 int
42 foll(void)
43 {
44     struct shpstr ship;
45     char *cp;
46     int good, leader, count = 0;
47     coord x, y;
48     struct nstr_item nstr;
49     char buf[1024];
50
51     if (!opt_SAIL) {
52         pr("The SAIL option is not enabled, so this command is not valid.\n");
53         return RET_FAIL;
54     }
55     if (!snxtitem(&nstr, EF_SHIP, player->argp[1]))
56         return RET_SYN;
57     cp = getstarg(player->argp[2], "leader?", buf);
58     if (cp == 0)
59         cp = "";
60     good = sscanf(cp, "%d", &leader);
61     if (!good)
62         return RET_SYN;
63     getship(leader, &ship);
64     if (ship.shp_own != player->cnum &&
65         getrel(getnatp(ship.shp_own), player->cnum) < FRIENDLY) {
66         pr("That ship won't let you follow.\n");
67         return RET_FAIL;
68     }
69     x = ship.shp_x;
70     y = ship.shp_y;
71     while (nxtitem(&nstr, &ship)) {
72         if (!player->owner)
73             continue;
74         if (ship.shp_x != x || ship.shp_y != y) {
75             pr("Ship #%d not in same sector as #%d\n",
76                ship.shp_uid, leader);
77             continue;
78         }
79         if (ship.shp_uid == leader) {
80             pr("Ship #%d can't follow itself!\n", leader);
81             continue;
82         }
83         if ((ship.shp_autonav & AN_AUTONAV)
84             && !(ship.shp_autonav & AN_STANDBY)) {
85             pr("Ship #%d has other orders!\n", ship.shp_uid);
86             continue;
87         }
88         count++;
89         ship.shp_mission = 0;
90         *ship.shp_path = 'f';
91         ship.shp_path[1] = 0;
92         ship.shp_follow = leader;
93         pr("Ship #%d follows #%d.\n", ship.shp_uid, leader);
94         putship(ship.shp_uid, &ship);
95     }
96     if (count == 0) {
97         if (player->argp[1])
98             pr("%s: No ship(s)\n", player->argp[1]);
99         else
100             pr("%s: No ship(s)\n", "");
101         return RET_FAIL;
102     } else
103         pr("%d ship%s\n", count, splur(count));
104     return RET_OK;
105 }