]> git.pond.sub.org Git - empserver/blob - src/lib/commands/mobq.c
99acb05e8dc0a4c53d91eb41d11b5f61340cf86e
[empserver] / src / lib / commands / mobq.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2008, 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  *  mobq.c: Set the sailing mobility quota for a ship
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
40
41 int
42 mobq(void)
43 {
44     struct shpstr ship;
45     char *cp, *oldmq;
46     int good, mobquota, count = 0;
47     struct nstr_item nstr;
48     char buf[1024];
49
50     if (!opt_SAIL) {
51         pr("The SAIL option is not enabled, so this command is not valid.\n");
52         return RET_FAIL;
53     }
54     if (!snxtitem(&nstr, EF_SHIP, player->argp[1], NULL))
55         return RET_SYN;
56     oldmq = player->argp[2];
57     if (oldmq) {
58         good = sscanf(oldmq, "%d", &mobquota);
59         if (!good)
60             return RET_SYN;
61         if (mobquota < 0 || mobquota > ship_mob_max) {
62             pr("Bad mobility quota value %d.\n", mobquota);
63             return RET_SYN;
64         }
65         if (mobquota + (ship_mob_scale * (float)etu_per_update) >
66             ship_mob_max) {
67             pr("warning: %d less than optimal\n", mobquota);
68         }
69     }
70     while (nxtitem(&nstr, &ship)) {
71         if (!player->owner)
72             continue;
73         if (!oldmq)
74             pr("Ship #%d at %s.  Old value %d.\n", ship.shp_uid,
75                xyas(ship.shp_x, ship.shp_y, player->cnum),
76                ship.shp_mobquota);
77         cp = getstarg(player->argp[2], "mobility quota? ", buf);
78         if (!cp)
79             return RET_SYN;
80         if (!check_ship_ok(&ship))
81             continue;
82         good = sscanf(cp, "%d", &mobquota);
83         if (!good) {
84             pr("Huh?\n");
85             continue;
86         }
87         if (!oldmq) {
88             if (mobquota < 0 || mobquota > ship_mob_max) {
89                 pr("Bad mobility quota value %d.\n", mobquota);
90                 continue;
91             }
92             if (mobquota + (ship_mob_scale * (float)etu_per_update) >
93                 ship_mob_max) {
94                 pr("warning: %d less than optimal\n", mobquota);
95             }
96         }
97         ship.shp_mobquota = mobquota;
98         count++;
99         putship(ship.shp_uid, &ship);
100     }
101     if (count == 0) {
102         if (player->argp[1])
103             pr("%s: No ship(s)\n", player->argp[1]);
104         else
105             pr("%s: No ship(s)\n", "");
106         return RET_FAIL;
107     } else
108         pr("%d ship%s\n", count, splur(count));
109     return RET_OK;
110 }