(buil): Use typematch() to search for ship, plane, land unit and nuke
type. The old code didn't work correctly when "sbb super battleship" came before "sb submarine" in mchr[].
This commit is contained in:
parent
100d0fc495
commit
856539fc54
1 changed files with 34 additions and 82 deletions
|
@ -78,7 +78,6 @@ buil(void)
|
||||||
int rqtech;
|
int rqtech;
|
||||||
int tlev;
|
int tlev;
|
||||||
int rlev;
|
int rlev;
|
||||||
int n;
|
|
||||||
int type;
|
int type;
|
||||||
int what;
|
int what;
|
||||||
struct lchrstr *lp;
|
struct lchrstr *lp;
|
||||||
|
@ -88,7 +87,7 @@ buil(void)
|
||||||
s_char *p;
|
s_char *p;
|
||||||
int gotsect = 0;
|
int gotsect = 0;
|
||||||
int built;
|
int built;
|
||||||
int hold, found, number = 1, x;
|
int number = 1, x;
|
||||||
int asked = 0;
|
int asked = 0;
|
||||||
s_char buf[1024];
|
s_char buf[1024];
|
||||||
|
|
||||||
|
@ -114,96 +113,62 @@ buil(void)
|
||||||
p = getstarg(player->argp[3], "Plane type? ", buf);
|
p = getstarg(player->argp[3], "Plane type? ", buf);
|
||||||
if (p == 0 || *p == 0)
|
if (p == 0 || *p == 0)
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
n = strlen(p);
|
type = typematch(p, EF_PLANE);
|
||||||
while (n && iscntrl(p[n - 1]))
|
if (type >= 0) {
|
||||||
n--;
|
pp = &plchr[type];
|
||||||
if (!n)
|
rqtech = pp->pl_tech;
|
||||||
return RET_SYN;
|
if (rqtech > tlev)
|
||||||
for (found = 0, type = 0, pp = plchr; type <= pln_maxno;
|
type = -1;
|
||||||
type++, pp++) {
|
|
||||||
if (pp->pl_tech > tlev)
|
|
||||||
continue;
|
|
||||||
if (pp->pl_name && strncmp(p, pp->pl_name, n) == 0) {
|
|
||||||
found++;
|
|
||||||
hold = type;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
if (type < 0) {
|
||||||
if (found != 1) {
|
|
||||||
pr("Illegal plane type: \"%s\"\n", p);
|
pr("Illegal plane type: \"%s\"\n", p);
|
||||||
if (confirm("List plane types? "))
|
if (confirm("List plane types? "))
|
||||||
show_plane_build(tlev);
|
show_plane_build(tlev);
|
||||||
player->argp[3] = 0;
|
player->argp[3] = 0;
|
||||||
goto ask_again;
|
goto ask_again;
|
||||||
}
|
}
|
||||||
type = hold;
|
|
||||||
pp = &(plchr[type]);
|
|
||||||
rqtech = pp->pl_tech;
|
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
p = getstarg(player->argp[3], "Ship type? ", buf);
|
p = getstarg(player->argp[3], "Ship type? ", buf);
|
||||||
if (p == 0 || *p == 0)
|
if (p == 0 || *p == 0)
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
n = strlen(p);
|
type = typematch(p, EF_SHIP);
|
||||||
while (n && iscntrl(p[n - 1]))
|
if (type >= 0) {
|
||||||
n--;
|
mp = &mchr[type];
|
||||||
if (!n)
|
rqtech = mp->m_tech;
|
||||||
return RET_SYN;
|
if (rqtech > tlev)
|
||||||
for (found = 0, mp = mchr, type = 0; type <= shp_maxno;
|
type = -1;
|
||||||
type++, mp++) {
|
|
||||||
if (mp->m_tech > tlev)
|
|
||||||
continue;
|
|
||||||
/* Can't build trade ships unless it's turned on */
|
|
||||||
if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
|
if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
|
||||||
continue;
|
type = -1;
|
||||||
if (mp->m_name && strncmp(p, mp->m_name, n) == 0) {
|
|
||||||
found++;
|
|
||||||
hold = type;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
if (type < 0) {
|
||||||
if (found != 1) {
|
|
||||||
pr("Illegal ship type: \"%s\"\n", p);
|
pr("Illegal ship type: \"%s\"\n", p);
|
||||||
if (confirm("List ship types? "))
|
if (confirm("List ship types? "))
|
||||||
show_ship_build(tlev);
|
show_ship_build(tlev);
|
||||||
player->argp[3] = 0;
|
player->argp[3] = 0;
|
||||||
goto ask_again;
|
goto ask_again;
|
||||||
}
|
}
|
||||||
type = hold;
|
|
||||||
mp = &(mchr[type]);
|
|
||||||
rqtech = mp->m_tech;
|
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
p = getstarg(player->argp[3], "Land unit type? ", buf);
|
p = getstarg(player->argp[3], "Land unit type? ", buf);
|
||||||
if (p == 0 || *p == 0)
|
if (p == 0 || *p == 0)
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
n = strlen(p);
|
type = typematch(p, EF_LAND);
|
||||||
while (n && iscntrl(p[n - 1]))
|
if (type >= 0) {
|
||||||
n--;
|
lp = &lchr[type];
|
||||||
if (!n)
|
rqtech = lp->l_tech;
|
||||||
return RET_SYN;
|
if (rqtech > tlev)
|
||||||
for (found = 0, lp = lchr, type = 0; type <= lnd_maxno;
|
type = -1;
|
||||||
type++, lp++) {
|
|
||||||
if (lp->l_tech > tlev)
|
|
||||||
continue;
|
|
||||||
if ((lp->l_flags & L_SPY) && !opt_LANDSPIES)
|
if ((lp->l_flags & L_SPY) && !opt_LANDSPIES)
|
||||||
continue;
|
type = -1;
|
||||||
if (lp->l_name && strncmp(p, lp->l_name, n) == 0) {
|
|
||||||
found++;
|
|
||||||
hold = type;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
if (type < 0) {
|
||||||
if (found != 1) {
|
|
||||||
pr("Illegal land unit type: \"%s\"\n", p);
|
pr("Illegal land unit type: \"%s\"\n", p);
|
||||||
if (confirm("List unit types? "))
|
if (confirm("List unit types? "))
|
||||||
show_land_build(tlev);
|
show_land_build(tlev);
|
||||||
player->argp[3] = 0;
|
player->argp[3] = 0;
|
||||||
goto ask_again;
|
goto ask_again;
|
||||||
}
|
}
|
||||||
type = hold;
|
|
||||||
lp = &(lchr[type]);
|
|
||||||
rqtech = lp->l_tech;
|
|
||||||
break;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
if (natp->nat_level[NAT_TLEV] + 0.005 < buil_bt) {
|
if (natp->nat_level[NAT_TLEV] + 0.005 < buil_bt) {
|
||||||
|
@ -230,27 +195,17 @@ buil(void)
|
||||||
p = getstarg(player->argp[3], "Nuke type? ", buf);
|
p = getstarg(player->argp[3], "Nuke type? ", buf);
|
||||||
if (p == 0 || *p == 0)
|
if (p == 0 || *p == 0)
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
n = strlen(p);
|
type = typematch(p, EF_NUKE);
|
||||||
while (n && iscntrl(p[n - 1]))
|
if (type >= 0) {
|
||||||
n--;
|
np = &nchr[type];
|
||||||
if (!n)
|
rqtech = np->n_tech;
|
||||||
return RET_SYN;
|
if (rqtech > tlev
|
||||||
for (found = 0, np = nchr, type = 0; type < nuk_maxno;
|
|| (opt_DRNUKE && np->n_tech * drnuke_const > rlev))
|
||||||
type++, np++) {
|
type = -1;
|
||||||
if ((np->n_tech > tlev)
|
if ((np->n_flags & N_NEUT) && !opt_NEUTRON)
|
||||||
|| (opt_DRNUKE
|
type = -1;
|
||||||
&& ((np->n_tech * drnuke_const) > rlev)))
|
|
||||||
continue;
|
|
||||||
if (opt_NEUTRON == 0 && (np->n_flags & N_NEUT))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (np->n_name && strncmp(p, np->n_name, n) == 0) {
|
|
||||||
found++;
|
|
||||||
hold = type;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
if (type < 0) {
|
||||||
if (found != 1) {
|
|
||||||
int tt = tlev;
|
int tt = tlev;
|
||||||
pr("Possible nuke types are:\n");
|
pr("Possible nuke types are:\n");
|
||||||
if (opt_DRNUKE)
|
if (opt_DRNUKE)
|
||||||
|
@ -261,9 +216,6 @@ buil(void)
|
||||||
player->argp[3] = 0;
|
player->argp[3] = 0;
|
||||||
goto ask_again;
|
goto ask_again;
|
||||||
}
|
}
|
||||||
type = hold;
|
|
||||||
np = &(nchr[type]);
|
|
||||||
rqtech = np->n_tech;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
pr("You can't build that!\n");
|
pr("You can't build that!\n");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue