(rada): Using struct empobj to generalize the code.
This commit is contained in:
parent
09248d018d
commit
90ff9ae2b0
1 changed files with 41 additions and 64 deletions
|
@ -35,9 +35,8 @@
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
#include "land.h"
|
|
||||||
#include "optlist.h"
|
#include "optlist.h"
|
||||||
#include "ship.h"
|
#include "empobj.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
rada(void)
|
rada(void)
|
||||||
|
@ -47,20 +46,16 @@ rada(void)
|
||||||
double tech;
|
double tech;
|
||||||
struct nstr_item ni;
|
struct nstr_item ni;
|
||||||
struct nstr_sect ns;
|
struct nstr_sect ns;
|
||||||
struct shpstr ship;
|
union empobj_storage item;
|
||||||
struct lndstr land;
|
|
||||||
struct sctstr sect;
|
|
||||||
int from_unit;
|
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
short type;
|
||||||
|
|
||||||
from_unit = (**player->argp == 'l');
|
type = player->argp[0][0] == 'l' ? EF_LAND : EF_SHIP;
|
||||||
|
|
||||||
if (!from_unit)
|
|
||||||
cp = getstarg(player->argp[1],
|
|
||||||
"Radar from (ship # or sector(s)) : ", buf);
|
|
||||||
else
|
|
||||||
cp = getstarg(player->argp[1],
|
cp = getstarg(player->argp[1],
|
||||||
|
type == EF_SHIP ? "Radar from (ship # or sector(s)) : " :
|
||||||
"Radar from (unit # or sector(s)) : ", buf);
|
"Radar from (unit # or sector(s)) : ", buf);
|
||||||
|
|
||||||
if (cp == 0)
|
if (cp == 0)
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
switch (sarg_type(cp)) {
|
switch (sarg_type(cp)) {
|
||||||
|
@ -72,74 +67,56 @@ rada(void)
|
||||||
tech = WORLD_Y / 4.0;
|
tech = WORLD_Y / 4.0;
|
||||||
if (tech > WORLD_X / 8.0)
|
if (tech > WORLD_X / 8.0)
|
||||||
tech = WORLD_X / 8.0;
|
tech = WORLD_X / 8.0;
|
||||||
while (nxtsct(&ns, §)) {
|
while (nxtsct(&ns, &item.sect)) {
|
||||||
if (sect.sct_type != SCT_RADAR)
|
if (item.sect.sct_type != SCT_RADAR)
|
||||||
continue;
|
continue;
|
||||||
if (!player->owner)
|
if (!player->owner)
|
||||||
continue;
|
continue;
|
||||||
radmap(sect.sct_x, sect.sct_y, (int)sect.sct_effic,
|
radmap(item.sect.sct_x, item.sect.sct_y, item.sect.sct_effic,
|
||||||
(int)(tech * 2.0), 0.0);
|
(int)(tech * 2.0), 0.0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case NS_LIST:
|
case NS_LIST:
|
||||||
case NS_GROUP:
|
case NS_GROUP:
|
||||||
if (!from_unit) {
|
/* assumes a NS_LIST return is a unit no */
|
||||||
/* assumes a NS_LIST return is a shipno */
|
if (!snxtitem(&ni, type, cp)) {
|
||||||
if (!snxtitem(&ni, EF_SHIP, cp)) {
|
pr("Specify at least one %s\n",
|
||||||
pr("Specify at least one ship\n");
|
type == EF_SHIP ? "ship" : "unit");
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
}
|
}
|
||||||
while (nxtitem(&ni, &ship)) {
|
while (nxtitem(&ni, &item)) {
|
||||||
if (!player->owner)
|
if (!player->owner)
|
||||||
continue;
|
continue;
|
||||||
if (mchr[(int)ship.shp_type].m_flags & M_SONAR)
|
|
||||||
tf = techfact(ship.shp_tech, 1.0);
|
|
||||||
else
|
|
||||||
tf = 0.0;
|
tf = 0.0;
|
||||||
pr("%s at ", prship(&ship));
|
if (type == EF_SHIP) {
|
||||||
tech = techfact(ship.shp_tech,
|
if (mchr[(int)item.ship.shp_type].m_flags & M_SONAR)
|
||||||
mchr[(int)ship.shp_type].m_vrnge);
|
tf = techfact(item.ship.shp_tech, 1.0);
|
||||||
if (tech > WORLD_Y / 2.0)
|
tech = techfact(item.ship.shp_tech,
|
||||||
tech = WORLD_Y / 2.0;
|
mchr[(int)item.ship.shp_type].m_vrnge);
|
||||||
if (tech > WORLD_X / 4.0)
|
|
||||||
tech = WORLD_X / 4.0;
|
|
||||||
radmap(ship.shp_x, ship.shp_y, ship.shp_effic,
|
|
||||||
(int)tech, tf);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
/* from a land unit */
|
if (!(lchr[(int)item.land.lnd_type].l_flags & L_RADAR)) {
|
||||||
if (!snxtitem(&ni, EF_LAND, cp)) {
|
pr("%s can't use radar!\n", prland(&item.land));
|
||||||
pr("Specify at least one unit\n");
|
|
||||||
return RET_SYN;
|
|
||||||
}
|
|
||||||
while (nxtitem(&ni, &land)) {
|
|
||||||
if (!player->owner)
|
|
||||||
continue;
|
|
||||||
if (!(lchr[(int)land.lnd_type].l_flags & L_RADAR)) {
|
|
||||||
pr("%s can't use radar!\n", prland(&land));
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (land.lnd_ship >= 0) {
|
if (item.land.lnd_ship >= 0) {
|
||||||
pr("Units on ships can't use radar!\n");
|
pr("Units on ships can't use radar!\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
tf = 0.0;
|
tech = techfact(item.land.lnd_tech, item.land.lnd_spy);
|
||||||
pr("%s at ", prland(&land));
|
}
|
||||||
tech = techfact(land.lnd_tech, land.lnd_spy);
|
|
||||||
|
pr("%s at ", obj_nameof(&item.gen));
|
||||||
if (tech > WORLD_Y / 2.0)
|
if (tech > WORLD_Y / 2.0)
|
||||||
tech = WORLD_Y / 2.0;
|
tech = WORLD_Y / 2.0;
|
||||||
if (tech > WORLD_X / 4.0)
|
if (tech > WORLD_X / 4.0)
|
||||||
tech = WORLD_X / 4.0;
|
tech = WORLD_X / 4.0;
|
||||||
radmap(land.lnd_x, land.lnd_y, land.lnd_effic,
|
radmap(item.gen.x, item.gen.y, item.gen.effic,
|
||||||
(int)tech, tf);
|
(int)tech, tf);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (!from_unit)
|
pr("Must use a %s or sector specifier\n",
|
||||||
pr("Must use a ship or sector specifier\n");
|
type == EF_SHIP ? "ship" : "unit");
|
||||||
else
|
|
||||||
pr("Must use a unit or sector specifier\n");
|
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
}
|
}
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue