00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <config.h>
00035
00036 #include "commands.h"
00037 #include "optlist.h"
00038 #include "empobj.h"
00039
00040 int
00041 rada(void)
00042 {
00043 return radar(EF_SHIP);
00044 }
00045
00046 int
00047 lrad(void)
00048 {
00049 return radar(EF_LAND);
00050 }
00051
00052 int
00053 radar(short type)
00054 {
00055 char *cp;
00056 double tf;
00057 double tech;
00058 struct nstr_item ni;
00059 struct nstr_sect ns;
00060 union empobj_storage item;
00061 char buf[1024];
00062 char prompt[80];
00063
00064 sprintf(prompt, "Radar from (%s # or sector(s)) : ", ef_nameof(type));
00065 cp = getstarg(player->argp[1], prompt, buf);
00066
00067 if (cp == 0)
00068 return RET_SYN;
00069 switch (sarg_type(cp)) {
00070 case NS_AREA:
00071 if (!snxtsct(&ns, cp))
00072 return RET_SYN;
00073 tech = tfact(player->cnum, 8.0);
00074 if (tech > WORLD_Y / 4.0)
00075 tech = WORLD_Y / 4.0;
00076 if (tech > WORLD_X / 8.0)
00077 tech = WORLD_X / 8.0;
00078 while (nxtsct(&ns, &item.sect)) {
00079 if (item.sect.sct_type != SCT_RADAR)
00080 continue;
00081 if (!player->owner)
00082 continue;
00083 radmap(item.sect.sct_x, item.sect.sct_y, item.sect.sct_effic,
00084 (int)(tech * 2.0), 0.0);
00085 }
00086 break;
00087 case NS_LIST:
00088 case NS_GROUP:
00089
00090 if (!snxtitem(&ni, type, cp)) {
00091 pr("Specify at least one %s\n", ef_nameof(type));
00092 return RET_SYN;
00093 }
00094 while (nxtitem(&ni, &item)) {
00095 if (!player->owner)
00096 continue;
00097 tf = 0.0;
00098 if (type == EF_SHIP) {
00099 if (mchr[(int)item.ship.shp_type].m_flags & M_SONAR)
00100 tf = techfact(item.ship.shp_tech, 1.0);
00101 tech = techfact(item.ship.shp_tech,
00102 mchr[(int)item.ship.shp_type].m_vrnge);
00103 } else {
00104 if (!(lchr[(int)item.land.lnd_type].l_flags & L_RADAR)) {
00105 pr("%s can't use radar!\n", prland(&item.land));
00106 continue;
00107 }
00108 if (item.land.lnd_ship >= 0) {
00109 pr("Units on ships can't use radar!\n");
00110 continue;
00111 }
00112 tech = techfact(item.land.lnd_tech, item.land.lnd_spy);
00113 }
00114
00115 pr("%s at ", obj_nameof(&item.gen));
00116 if (tech > WORLD_Y / 2.0)
00117 tech = WORLD_Y / 2.0;
00118 if (tech > WORLD_X / 4.0)
00119 tech = WORLD_X / 4.0;
00120 radmap(item.gen.x, item.gen.y, item.gen.effic,
00121 (int)tech, tf);
00122 }
00123 break;
00124 default:
00125 pr("Must use a %s or sector specifier\n", ef_nameof(type));
00126 return RET_SYN;
00127 }
00128 return RET_OK;
00129 }