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