Clean up move_ground()'s parsing of DIR_MAP
Split with parse() and pass first two arguments instead of the raw tail to the map() callback. Advantages: * Consistent with do_unit_move(). * Does the right thing when the tail is just spaces. Before, the spaces got passed to the map() callback, which complained about syntax. Now, they are ignored. This is what the commit I just reverted tried to fix. * Works better when the tail splits into more than two arguments. Except for explore_map(), which ignores the argument(s), the map() callbacks use display_region_map(), which split the tail at the first space, and complained about any spaces in the second part. Now, display_region_map() takes two argument strings instead of a single, unsplit argument string, and extra arguments get silently ignored, as usual.
This commit is contained in:
parent
40cfb41b4e
commit
28d4847416
Notes:
Markus Armbruster
2012-02-11 09:54:40 +01:00
Deprecate usage without space between DIR_MAP and first argument.
7 changed files with 36 additions and 34 deletions
|
@ -61,8 +61,7 @@ extern void blankfill(char *, struct range *, int);
|
||||||
extern void border(struct range *, char *, char *);
|
extern void border(struct range *, char *, char *);
|
||||||
/* src/lib/subs/maps.c */
|
/* src/lib/subs/maps.c */
|
||||||
extern int do_map(int bmap, int unit_type, char *arg1, char *arg2);
|
extern int do_map(int bmap, int unit_type, char *arg1, char *arg2);
|
||||||
extern int display_region_map(int bmap, int unit_type, coord curx,
|
extern int display_region_map(int, int, coord, coord, char *, char *);
|
||||||
coord cury, char *arg);
|
|
||||||
extern int bmaps_intersect(natid, natid);
|
extern int bmaps_intersect(natid, natid);
|
||||||
extern int share_bmap(natid, natid, struct nstr_sect *, char, char *);
|
extern int share_bmap(natid, natid, struct nstr_sect *, char, char *);
|
||||||
|
|
||||||
|
|
|
@ -464,7 +464,7 @@ extern int cando(int, int);
|
||||||
extern int check_lmines(coord, coord, double);
|
extern int check_lmines(coord, coord, double);
|
||||||
extern int move_ground(struct sctstr *, struct sctstr *,
|
extern int move_ground(struct sctstr *, struct sctstr *,
|
||||||
double, char *,
|
double, char *,
|
||||||
int (*)(coord, coord, char *),
|
int (*)(coord, coord, char *, char *),
|
||||||
int, int *);
|
int, int *);
|
||||||
extern int fly_map(coord, coord);
|
extern int fly_map(coord, coord);
|
||||||
/* mslsub.c */
|
/* mslsub.c */
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
#include "optlist.h"
|
#include "optlist.h"
|
||||||
#include "plague.h"
|
#include "plague.h"
|
||||||
|
|
||||||
static int explore_map(coord curx, coord cury, char *arg);
|
static int explore_map(coord, coord, char *, char *);
|
||||||
|
|
||||||
int
|
int
|
||||||
explore(void)
|
explore(void)
|
||||||
|
@ -274,7 +274,7 @@ explore(void)
|
||||||
|
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
static int
|
static int
|
||||||
explore_map(coord curx, coord cury, char *arg)
|
explore_map(coord curx, coord cury, char *arg1, char *arg2)
|
||||||
{
|
{
|
||||||
struct nstr_sect ns;
|
struct nstr_sect ns;
|
||||||
struct sctstr sect;
|
struct sctstr sect;
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
#include "plague.h"
|
#include "plague.h"
|
||||||
|
|
||||||
|
|
||||||
static int cmd_move_map(coord curx, coord cury, char *arg);
|
static int cmd_move_map(coord, coord, char *, char *);
|
||||||
|
|
||||||
int
|
int
|
||||||
move(void)
|
move(void)
|
||||||
|
@ -341,9 +341,9 @@ move(void)
|
||||||
*/
|
*/
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
static int
|
static int
|
||||||
cmd_move_map(coord curx, coord cury, char *arg)
|
cmd_move_map(coord curx, coord cury, char *arg1, char *arg2)
|
||||||
{
|
{
|
||||||
return display_region_map(0, EF_SHIP, curx, cury, arg);
|
return display_region_map(0, EF_SHIP, curx, cury, arg1, arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
*
|
*
|
||||||
* Known contributors to this file:
|
* Known contributors to this file:
|
||||||
* Steve McClure, 2000
|
* Steve McClure, 2000
|
||||||
* Markus Armbruster, 2006-2009
|
* Markus Armbruster, 2006-2011
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
@ -40,8 +40,8 @@
|
||||||
#include "plane.h"
|
#include "plane.h"
|
||||||
#include "ship.h"
|
#include "ship.h"
|
||||||
|
|
||||||
static int tran_pmap(coord curx, coord cury, char *arg);
|
static int tran_pmap(coord, coord, char *, char *);
|
||||||
static int tran_nmap(coord curx, coord cury, char *arg);
|
static int tran_nmap(coord, coord, char *, char *);
|
||||||
static int tran_nuke(void);
|
static int tran_nuke(void);
|
||||||
static int tran_plane(void);
|
static int tran_plane(void);
|
||||||
|
|
||||||
|
@ -245,13 +245,13 @@ tran_plane(void)
|
||||||
*/
|
*/
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
static int
|
static int
|
||||||
tran_pmap(coord curx, coord cury, char *arg)
|
tran_pmap(coord curx, coord cury, char *arg1, char *arg2)
|
||||||
{
|
{
|
||||||
return display_region_map(0, EF_PLANE, curx, cury, arg);
|
return display_region_map(0, EF_PLANE, curx, cury, arg1, arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
tran_nmap(coord curx, coord cury, char *arg)
|
tran_nmap(coord curx, coord cury, char *arg1, char *arg2)
|
||||||
{
|
{
|
||||||
return display_region_map(0, EF_NUKE, curx, cury, arg);
|
return display_region_map(0, EF_NUKE, curx, cury, arg1, arg2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -420,29 +420,21 @@ unit_map(int unit_type, int uid, struct nstr_sect *nsp, char *originp)
|
||||||
|
|
||||||
int
|
int
|
||||||
display_region_map(int bmap, int unit_type, coord curx, coord cury,
|
display_region_map(int bmap, int unit_type, coord curx, coord cury,
|
||||||
char *arg)
|
char *arg1, char *arg2)
|
||||||
{
|
{
|
||||||
char coordinates[80];
|
char coordinates[80];
|
||||||
char *map_flag_arg;
|
|
||||||
|
|
||||||
if (!arg || !*arg) {
|
if (!arg1 || !*arg1) {
|
||||||
struct natstr *np;
|
struct natstr *np;
|
||||||
|
|
||||||
np = getnatp(player->cnum);
|
np = getnatp(player->cnum);
|
||||||
sprintf(coordinates, "%d:%d,%d:%d",
|
sprintf(coordinates, "%d:%d,%d:%d",
|
||||||
xrel(np, curx - 10), xrel(np, curx + 10),
|
xrel(np, curx - 10), xrel(np, curx + 10),
|
||||||
yrel(np, cury - 5), yrel(np, cury + 5));
|
yrel(np, cury - 5), yrel(np, cury + 5));
|
||||||
arg = coordinates;
|
arg1 = coordinates;
|
||||||
map_flag_arg = NULL;
|
|
||||||
} else {
|
|
||||||
map_flag_arg = strchr(arg, ' ');
|
|
||||||
if (map_flag_arg != NULL) {
|
|
||||||
*map_flag_arg++ = '\0';
|
|
||||||
while (isspace(*map_flag_arg)) map_flag_arg++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
player->condarg = NULL;
|
player->condarg = NULL;
|
||||||
return do_map(bmap, unit_type, arg, map_flag_arg);
|
return do_map(bmap, unit_type, arg1, arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -47,8 +47,8 @@ static int move_map(coord curx, coord cury, char *arg);
|
||||||
int
|
int
|
||||||
move_ground(struct sctstr *start, struct sctstr *end,
|
move_ground(struct sctstr *start, struct sctstr *end,
|
||||||
double weight, char *path,
|
double weight, char *path,
|
||||||
int (*map)(coord, coord, char *), int exploring,
|
int (*map)(coord, coord, char *, char *),
|
||||||
int *dam)
|
int exploring, int *dam)
|
||||||
{
|
{
|
||||||
struct sctstr sect;
|
struct sctstr sect;
|
||||||
struct sctstr next;
|
struct sctstr next;
|
||||||
|
@ -62,6 +62,9 @@ move_ground(struct sctstr *start, struct sctstr *end,
|
||||||
size_t len;
|
size_t len;
|
||||||
double mobility = start->sct_mobil;
|
double mobility = start->sct_mobil;
|
||||||
int dir;
|
int dir;
|
||||||
|
char scanspace[1024];
|
||||||
|
char *argp[128];
|
||||||
|
int ac;
|
||||||
int intcost;
|
int intcost;
|
||||||
int takedam = *dam;
|
int takedam = *dam;
|
||||||
int out = 0;
|
int out = 0;
|
||||||
|
@ -119,7 +122,7 @@ move_ground(struct sctstr *start, struct sctstr *end,
|
||||||
oldy = cury;
|
oldy = cury;
|
||||||
if (!movstr || *movstr == 0) {
|
if (!movstr || *movstr == 0) {
|
||||||
if (exploring) {
|
if (exploring) {
|
||||||
map(curx, cury, NULL);
|
map(curx, cury, NULL, NULL);
|
||||||
} else {
|
} else {
|
||||||
move_map(curx, cury, NULL);
|
move_map(curx, cury, NULL);
|
||||||
}
|
}
|
||||||
|
@ -168,15 +171,23 @@ move_ground(struct sctstr *start, struct sctstr *end,
|
||||||
*movstr = 0;
|
*movstr = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
movstr++;
|
|
||||||
if (dir == DIR_MAP) {
|
if (dir == DIR_MAP) {
|
||||||
|
ac = parse(movstr, scanspace, argp, NULL, NULL, NULL);
|
||||||
|
if (ac == 1) {
|
||||||
|
pr("Use of '%c' without a space before its argument is deprecated.\n"
|
||||||
|
"Support for it will go away in a future release\n",
|
||||||
|
*movstr);
|
||||||
|
argp[1] = argp[0] + 1;
|
||||||
|
}
|
||||||
if (!exploring)
|
if (!exploring)
|
||||||
map(curx, cury, movstr + 1);
|
map(curx, cury, argp[1], argp[2]);
|
||||||
*movstr = 0;
|
*movstr = 0;
|
||||||
continue;
|
continue;
|
||||||
} else if (dir == DIR_STOP)
|
}
|
||||||
|
movstr++;
|
||||||
|
if (dir == DIR_STOP)
|
||||||
break;
|
break;
|
||||||
else if (dir == DIR_VIEW) {
|
if (dir == DIR_VIEW) {
|
||||||
pr("%d%% %s with %d civilians.\n", sect.sct_effic,
|
pr("%d%% %s with %d civilians.\n", sect.sct_effic,
|
||||||
dchr[sect.sct_type].d_name, sect.sct_item[I_CIVIL]);
|
dchr[sect.sct_type].d_name, sect.sct_item[I_CIVIL]);
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue