/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
- * Ken Stevens, Steve McClure
+ * Copyright (C) 1986-2015, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Ken Stevens, Steve McClure, Markus Armbruster
*
- * This program is free software; you can redistribute it and/or modify
+ * Empire is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ---
*
* Known contributors to this file:
* Ken Stevens, 1995 (rewritten)
* Ron Koenderink, 2006-2007
+ * Markus Armbruster, 2006-2014
*/
#include <config.h>
#include "map.h"
#include "optlist.h"
#include "path.h"
-#include "empobj.h"
#include "unit.h"
static void pr_leader_change(struct empobj *leader);
struct nstr_item ni_ship;
struct emp_qelem ship_list;
double minmob, maxmob;
- int together;
if (!snxtitem(&ni_ship, EF_SHIP, player->argp[1], NULL))
return RET_SYN;
shp_sel(&ni_ship, &ship_list);
- shp_nav(&ship_list, &minmob, &maxmob, &together, player->cnum);
+ shp_nav(&ship_list, &minmob, &maxmob, player->cnum);
if (QEMPTY(&ship_list)) {
pr("No ships\n");
return RET_FAIL;
}
-
- return do_unit_move(&ship_list, &together, &minmob, &maxmob);
+ return do_unit_move(&ship_list, &minmob, &maxmob);
}
int
-do_unit_move(struct emp_qelem *ulist, int *together,
- double *minmob, double *maxmob)
+do_unit_move(struct emp_qelem *ulist, double *minmob, double *maxmob)
{
char *cp = NULL;
int leader_uid;
int dir;
int stopping = 0;
int skip = 0;
+ int moved = 0;
char buf[1024];
char prompt[128];
- char scanspace[1024];
- char pathtaken[1024]; /* Doubtful we'll have a path longer than this */
- char *pt = pathtaken;
char bmap_flag;
int ac;
int type;
type = leader->ef_type;
pr("%s is %s\n",
type == EF_SHIP ? "Flagship" : "Leader",
- obj_nameof(leader));
+ unit_nameof(leader));
if (player->argp[2]) {
strcpy(buf, player->argp[2]);
- if (!(cp = unit_path(*together, leader, buf)))
- cp = player->argp[2];
+ cp = unit_path(leader, buf, sizeof(buf));
}
- *pt = '\0';
while (!QEMPTY(ulist)) {
char dp[80];
if (cp == NULL || *cp == '\0' || stopping) {
stopping = 0;
if (type == EF_SHIP)
- shp_nav(ulist, minmob, maxmob, together, player->cnum);
+ shp_nav(ulist, minmob, maxmob, player->cnum);
else
- lnd_mar(ulist, minmob, maxmob, together, player->cnum);
+ lnd_mar(ulist, minmob, maxmob, player->cnum);
if (QEMPTY(ulist)) {
pr("No %s left\n", type == EF_SHIP ? "ships" : "lands");
- if (type == EF_SHIP && strlen(pathtaken) > 1) {
- pathtaken[strlen(pathtaken) - 1] = '\0';
- pr("Path taken: %s\n", pathtaken);
- }
return RET_OK;
}
leader = get_leader(ulist);
* at the prompt, we call shp_nav() or lnd_mar() again.
*/
if (type == EF_SHIP)
- shp_nav(ulist, minmob, maxmob, together, player->cnum);
+ shp_nav(ulist, minmob, maxmob, player->cnum);
else
- lnd_mar(ulist, minmob, maxmob, together, player->cnum);
+ lnd_mar(ulist, minmob, maxmob, player->cnum);
if (QEMPTY(ulist)) {
pr("No %s left\n", type == EF_SHIP ? "ships" : "lands");
- if (type == EF_SHIP && strlen(pathtaken) > 1) {
- pathtaken[strlen(pathtaken) - 1] = '\0';
- pr("Path taken: %s\n", pathtaken);
- }
return RET_OK;
}
leader = get_leader(ulist);
stopping = 1;
continue;
}
- if (!(cp = unit_path(*together, leader, buf)))
- cp = buf;
+ if (cp)
+ cp = unit_path(leader, buf, sizeof(buf));
}
if (type == EF_SHIP) {
- radmapnopr(leader->x, leader->y, (int)leader->effic,
- (int)techfact(leader->tech,
- mchr[(int)leader->type].m_vrnge),
- (mchr[(int)leader->type].m_flags & M_SONAR)
- ? techfact(leader->tech, 1.0) : 0.0);
+ rad_map_set(player->cnum, leader->x, leader->y, leader->effic,
+ leader->tech, mchr[leader->type].m_vrnge);
}
if (cp == NULL || *cp == '\0')
cp = &dirch[DIR_STOP];
dir = chkdir(*cp, DIR_STOP, DIR_LAST);
if (dir >= 0) {
- if (type == EF_SHIP) {
- stopping |= shp_nav_one_sector(ulist, dir,
- player->cnum, *together);
- if (stopping != 2) {
- *pt++ = dirch[dir];
- *pt = '\0';
- }
- } else
- stopping |=
- lnd_mar_one_sector(ulist, dir, player->cnum,
- *together);
+ if (type == EF_SHIP)
+ stopping |= shp_nav_one_sector(ulist, dir, player->cnum);
+ else {
+ if (!moved && !lnd_abandon_askyn(ulist))
+ return RET_FAIL;
+ stopping |= lnd_mar_one_sector(ulist, dir, player->cnum);
+ }
+ moved = 1;
cp++;
continue;
}
- ac = parse(cp, scanspace, player->argp, NULL, NULL, NULL);
+ ac = parse(cp, player->argbuf, player->argp, NULL, NULL, NULL);
if (ac <= 0) {
player->argp[0] = "";
cp = NULL;
* fall through
*/
case 'M':
- do_map(bmap_flag, leader->ef_type, player->argp[1],
- player->argp[2]);
+ display_region_map(bmap_flag, type, leader->x, leader->y,
+ player->argp[1], player->argp[2]);
skip = 1;
continue;
case 'f':
if (type == EF_SHIP)
stopping |= shp_sweep(ulist, 1, 1, player->cnum);
else {
- lnd_sweep(ulist, 1, 1, player->cnum);
- stopping |= lnd_check_mines(ulist);
+ stopping |= lnd_sweep(ulist, 1, 1, player->cnum);
}
continue;
case 'r':
pr("`d' to drop mines, and `m' to minesweep\n");
stopping = 1;
}
- if (type == EF_SHIP && strlen(pathtaken) > 1) {
- pathtaken[strlen(pathtaken) - 1] = '\0';
- pr("Path taken: %s\n", pathtaken);
- }
return RET_OK;
}
{
pr("Changing %s to %s\n",
leader->ef_type == EF_SHIP ? "flagship" : "leader",
- obj_nameof(leader));
+ unit_nameof(leader));
}
static struct empobj *