2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
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.
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.
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
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.
28 * orde.c: Turn on/off autonavigation
30 * Known contributors to this file:
46 * ORDER <ship> Show orders
47 * ORDER <ship> c[ancel] Cancel orders
48 * ORDER <ship> s[top] Suspend orders
49 * ORDER <ship> r[esume] Resume orders
50 * ORDER <ship> d[eclare] <dest1> Set destination
51 * d[eclare] <dest1> <dest2>
52 * ORDER <ship> l[evel] <field> <start/end> <comm> <level>
55 * qorder <ship> display cargo levels
56 * sorder <ship> display statistical info
67 coord p0x, p0y, p1x, p1y;
74 if (!snxtitem(&nb, EF_SHIP, player->argp[1], NULL))
76 while (!player->aborted && nxtitem(&nb, (&ship))) {
77 if (!player->owner || ship.shp_own == 0)
81 pr("Ship #%d has a \"sail\" path!\n", ship.shp_uid);
86 "Ship #%d, declare, cancel, suspend, resume, level? ",
88 p = getstarg(player->argp[2], prompt, buf);
89 if (player->aborted || !p || !*p)
91 if (!check_ship_ok(&ship))
95 pr("Bad order type!\n");
97 case 'c': /* clear ship fields */
99 ship.shp_autonav &= ~(AN_AUTONAV + AN_STANDBY + AN_LOADING);
100 for (i = 0; i < TMAX; i++) {
101 ship.shp_tstart[i] = I_NONE;
102 ship.shp_tend[i] = I_NONE;
103 ship.shp_lstart[i] = 0;
104 ship.shp_lend[i] = 0;
107 case 's': /* suspend ship movement */
108 ship.shp_mission = 0;
109 ship.shp_autonav |= AN_STANDBY;
111 case 'r': /* resume ship movement */
112 ship.shp_mission = 0;
113 ship.shp_autonav &= ~AN_STANDBY;
115 case 'd': /* declare path */
118 p = getstarg(player->argp[3], "Destination? ", buf);
121 if (!sarg_xy(p, &p0x, &p0y))
126 p = getstarg(player->argp[4], "Second dest? ", buf);
129 if (!check_ship_ok(&ship))
131 if (!*p || !strcmp(p, "-")) {
132 pr("A one-way order has been accepted.\n");
133 } else if (!strncmp(p, "s", 1)) {
134 if (opt_TRADESHIPS) {
135 if (!(mchr[(int)ship.shp_type].m_flags & M_TRADE)) {
136 pr("You can't auto-scuttle that ship!\n");
140 pr("You can't auto-scuttle that ship!\n");
143 pr("A scuttle order has been accepted.\n");
146 if (!sarg_xy(p, &p1x, &p1y))
148 pr("A circular order has been accepted.\n");
152 * Set new destination and trade type fields.
154 ship.shp_mission = 0;
155 ship.shp_destx[1] = p1x;
156 ship.shp_desty[1] = p1y;
157 ship.shp_destx[0] = p0x;
158 ship.shp_desty[0] = p0y;
160 ship.shp_autonav &= ~(AN_STANDBY | AN_LOADING);
161 ship.shp_autonav |= AN_AUTONAV;
164 ship.shp_autonav |= AN_SCUTTLE;
167 /* set cargo levels on the ship */
170 /* convert player->argp[3] to an integer */
171 sprintf(buf1, "Field (1-%d) ", TMAX);
172 if (!getstarg(player->argp[3], buf1, buf))
174 if (!check_ship_ok(&ship))
177 /* check to make sure value in within range. */
178 if (sub > TMAX || sub < 1) {
179 pr("Value must range from 1 to %d\n", TMAX);
183 /* to keep sub in range of our arrays
184 subtract 1 so the new range is 0-(TMAX-1)
188 if (ship.shp_autonav & AN_AUTONAV) {
189 dest = getstarg(player->argp[4], "Start or end? ", buf);
194 pr("You must enter 'start' or 'end'\n");
198 i1 = whatitem(player->argp[5], "Commodity? ");
201 p1 = getstarg(player->argp[6], "Amount? ",
205 if (!check_ship_ok(&ship))
209 level = 0; /* prevent negatives. */
210 pr("You must use positive number! Level set to 0.\n");
212 ship.shp_tstart[sub] = i1->i_uid;
213 ship.shp_lstart[sub] = level;
218 i1 = whatitem(player->argp[5], "Commodity? ");
221 p1 = getstarg(player->argp[6], "Amount? ",
225 if (!check_ship_ok(&ship))
230 pr("You must use positive number! Level set to 0.\n");
232 ship.shp_tend[sub] = i1->i_uid;
233 ship.shp_lend[sub] = level;
238 pr("You need to 'declare' a ship path first, see 'info order'\n");
241 } /* end of switch (*p) */
246 * Set loading flag if ship is already in one
247 * of the specified harbors and a cargo has been
251 if (((ship.shp_x == ship.shp_destx[0])
252 && (ship.shp_y == ship.shp_desty[0])
253 && (ship.shp_lstart[0] != ' '))
254 || ((ship.shp_x == ship.shp_desty[1])
255 && (ship.shp_y == ship.shp_desty[1])
256 && (ship.shp_lstart[1] != ' '))) {
263 ship.shp_autonav |= AN_LOADING;
265 /* swap variables, this keeps
266 the load_it() procedure happy. CZ
268 tcord = ship.shp_destx[0];
269 ship.shp_destx[0] = ship.shp_destx[1];
270 ship.shp_destx[1] = tcord;
271 tcord = ship.shp_desty[0];
272 ship.shp_desty[0] = ship.shp_desty[1];
273 ship.shp_desty[1] = tcord;
275 for (i = 0; i < TMAX; i++) {
276 lev[i] = ship.shp_lstart[i];
277 ship.shp_lstart[i] = ship.shp_lend[i];
278 ship.shp_lend[i] = lev[i];
279 tcomm = ship.shp_tstart[i];
280 ship.shp_tstart[i] = ship.shp_tend[i];
281 ship.shp_tend[i] = tcomm;
285 putship(ship.shp_uid, &ship);
291 eta_calc(struct shpstr *sp, char *path, int *len, int *nupdates)
293 double mobcost, mobil;
300 mobcost = shp_mobcost(sp);
301 mobil = sp->shp_mobil;
307 mobil += (ship_mob_scale * (float)etu_per_update);
314 prhold(int hold, i_type itype, int amt)
316 if (itype != I_NONE && amt != 0) {
317 if (CANT_HAPPEN(itype <= I_NONE || itype > I_MAX))
320 pr("%c", ichr[itype].i_mnem);
334 if (!snxtitem(&nb, EF_SHIP, player->argp[1], NULL))
336 while (nxtitem(&nb, (&ship))) {
337 if (!player->owner || ship.shp_own == 0)
339 if (!(ship.shp_autonav & AN_AUTONAV)
340 && (!opt_SAIL || !ship.shp_path[0]))
343 if (!nships) { /* 1st ship, print banner */
346 pr("shp# ship type ");
347 pr("[Starting] (Ending) \n");
351 pr("%3d ", ship.shp_own);
353 pr(" %-16.16s", mchr[(int)ship.shp_type].m_name);
355 if (ship.shp_autonav & AN_AUTONAV) {
357 for (i = 0; i < TMAX; i++)
358 prhold(i, ship.shp_tend[i], ship.shp_lend[i]);
360 for (i = 0; i < TMAX; i++)
361 prhold(i, ship.shp_tstart[i], ship.shp_lstart[i]);
363 if (ship.shp_autonav & AN_SCUTTLE)
367 pr(" has a sail path\n");
369 if (ship.shp_name[0] != 0) {
372 pr(" %s\n", ship.shp_name);
377 pr("%s: No ship(s)\n", player->argp[1]);
379 pr("%s: No ship(s)\n", "");
382 pr("%d ship%s\n", nships, splur(nships));
396 if (!snxtitem(&nb, EF_SHIP, player->argp[1], NULL))
398 while (nxtitem(&nb, (&ship))) {
399 if (!player->owner || ship.shp_own == 0)
401 if (!(ship.shp_autonav & AN_AUTONAV)
402 && (!opt_SAIL || !ship.shp_path[0]))
405 if (!nships) { /* 1st ship, print banner */
408 pr("shp# ship type x,y ");
414 pr("%3d ", ship.shp_own);
416 pr(" %-16.16s", mchr[(int)ship.shp_type].m_name);
417 prxy(" %3d,%-3d", ship.shp_x, ship.shp_y, player->cnum);
419 if (ship.shp_autonav & AN_AUTONAV) {
422 ship.shp_destx[1], ship.shp_desty[1], player->cnum);
425 if ((ship.shp_destx[1] != ship.shp_destx[0])
426 || (ship.shp_desty[1] != ship.shp_desty[0])) {
428 ship.shp_destx[0], ship.shp_desty[0], player->cnum);
432 if (ship.shp_autonav & AN_STANDBY)
434 else if (ship.shp_autonav & AN_LOADING)
437 /* ETA calculation */
439 c = BestShipPath(buf, ship.shp_x, ship.shp_y,
440 ship.shp_destx[0], ship.shp_desty[0],
443 pr(" no route possible");
447 /* distance to destination */
448 eta_calc(&ship, c, &len, &updates);
449 pr(" %3d %4d", len, updates);
452 if (ship.shp_autonav & AN_SCUTTLE)
456 pr(" has a sail path\n");
458 if (ship.shp_name[0] != 0) {
461 pr(" %s\n", ship.shp_name);
466 pr("%s: No ship(s)\n", player->argp[1]);
468 pr("%s: No ship(s)\n", "");
471 pr("%d ship%s\n", nships, splur(nships));