7 #include "gb/commands/orbit.h" 13 #include "gb/GB_server.h" 14 #include "gb/buffers.h" 15 #include "gb/files_shl.h" 17 #include "gb/getplace.h" 22 #include "gb/tweakables.h" 28 static void DispStar(
const GameObj &,
const ScopeLevel, startype *,
int, Race *,
30 static void DispPlanet(
const GameObj &,
const ScopeLevel,
const Planet &,
31 char *,
int, Race *,
char *);
32 static void DispShip(
const GameObj &, placetype *, Ship *, Race *,
char *,
33 const Planet & = Planet());
45 void orbit(
const command_t &argv, GameObj &g) {
53 DontDispPlanets = DontDispShips = DontDispStars = 0;
56 for (
int flag = 1; flag <= argv.size() - 1; flag++)
57 if (*argv[flag].c_str() ==
'-') {
58 for (
int i = 1; argv[flag][i] !=
'\0'; i++)
switch (argv[flag][i]) {
69 if (sscanf(argv[flag].c_str() + 1,
"%d", &DontDispNum) != 1) {
70 sprintf(buf,
"Bad number %s.\n", argv[flag].c_str() + 1);
71 notify(g.player, g.governor, buf);
74 if (DontDispNum) DontDispNum--;
79 if (argv.size() == 1) {
80 where = getplace(g,
":", 0);
81 int i = (g.level == ScopeLevel::LEVEL_UNIV);
86 where = getplace(g, argv[argv.size() - 1], 0);
92 notify(g.player, g.governor,
"orbit: error in args.\n");
99 auto Race = races[g.player - 1];
101 switch (where.level) {
102 case ScopeLevel::LEVEL_UNIV:
103 for (starnum_t i = 0; i < Sdata.numstars; i++)
104 if (DontDispNum != i) {
105 DispStar(g, ScopeLevel::LEVEL_UNIV, Stars[i], DontDispStars, Race,
109 if (!DontDispShips) {
110 Shiplist shiplist{Sdata.ships};
111 for (
auto &s : shiplist) {
112 if (DontDispNum != s.number) {
113 DispShip(g, &where, &s, Race, buf);
119 case ScopeLevel::LEVEL_STAR: {
120 DispStar(g, ScopeLevel::LEVEL_STAR, Stars[where.snum], DontDispStars,
124 for (planetnum_t i = 0; i < Stars[where.snum]->numplanets; i++)
125 if (DontDispNum != i) {
127 DispPlanet(g, ScopeLevel::LEVEL_STAR, p, Stars[where.snum]->pnames[i],
128 DontDispPlanets, Race, buf);
137 Shiplist shiplist{Stars[where.snum]->ships};
138 for (
auto &s : shiplist) {
139 if (s.owner == g.player && shipsight(s)) {
145 if (!DontDispShips) {
146 Shiplist shiplist{Stars[where.snum]->ships};
147 for (
auto &s : shiplist) {
148 if (DontDispNum != s.number &&
149 !(s.owner != g.player && s.type == ShipType::STYPE_MINE)) {
150 if ((s.owner == g.player) || iq) {
151 DispShip(g, &where, &s, Race, buf);
158 case ScopeLevel::LEVEL_PLAN: {
160 DispPlanet(g, ScopeLevel::LEVEL_PLAN, p,
161 Stars[where.snum]->pnames[where.pnum], DontDispPlanets, Race,
168 Shiplist shiplist{p.ships};
169 for (
auto &s : shiplist) {
170 if (s.owner == g.player && shipsight(s)) {
176 if (!DontDispShips) {
177 for (
auto &s : shiplist) {
178 if (DontDispNum != s.number) {
180 if ((s.owner == g.player) || iq) {
181 DispShip(g, &where, &s, Race, buf, p);
190 g.out <<
"Bad scope.\n";
193 strcat(output,
"\n");
194 notify(g.player, g.governor, output);
199 static void DispStar(
const GameObj &g,
const ScopeLevel level, startype *star,
200 int , Race *r,
char *string) {
207 if (level == ScopeLevel::LEVEL_UNIV) {
210 }
else if (level == ScopeLevel::LEVEL_STAR) {
216 if (y >= 0 && x >= 0) {
217 if (r->governor[g.governor].toggle.color) {
218 stand = (
isset(star->explored, g.player) ? g.player : 0) +
'?';
219 sprintf(temp,
"%c %d %d 0 * ", (
char)stand, x, y);
220 strcat(string, temp);
221 stand = (
isset(star->inhabited, g.player) ? g.player : 0) +
'?';
222 sprintf(temp,
"%c %s;", (
char)stand, star->name);
223 strcat(string, temp);
225 stand = (
isset(star->explored, g.player) ? 1 : 0);
226 sprintf(temp,
"%d %d %d 0 * ", stand, x, y);
227 strcat(string, temp);
228 stand = (
isset(star->inhabited, g.player) ? 1 : 0);
229 sprintf(temp,
"%d %s;", stand, star->name);
230 strcat(string, temp);
237 static void DispPlanet(
const GameObj &g,
const ScopeLevel level,
238 const Planet &p,
char *name,
int ,
239 Race *r,
char *string) {
246 if (level == ScopeLevel::LEVEL_STAR) {
249 }
else if (level == ScopeLevel::LEVEL_PLAN) {
253 if (x >= 0 && y >= 0) {
254 if (r->governor[g.governor].toggle.color) {
255 stand = (p.info[g.player - 1].explored ? g.player : 0) +
'?';
256 sprintf(temp,
"%c %d %d 0 %c ", (
char)stand, x, y,
257 (stand >
'0' ? Psymbol[p.type] :
'?'));
258 strcat(string, temp);
259 stand = (p.info[g.player - 1].numsectsowned ? g.player : 0) +
'?';
260 sprintf(temp,
"%c %s", (
char)stand, name);
261 strcat(string, temp);
263 stand = p.info[g.player - 1].explored ? 1 : 0;
264 sprintf(temp,
"%d %d %d 0 %c ", stand, x, y,
265 (stand ? Psymbol[p.type] :
'?'));
266 strcat(string, temp);
267 stand = p.info[g.player - 1].numsectsowned ? 1 : 0;
268 sprintf(temp,
"%d %s", stand, name);
269 strcat(string, temp);
271 if (r->governor[g.governor].toggle.compat &&
272 p.info[g.player - 1].explored) {
274 strcat(string, temp);
280 static void DispShip(
const GameObj &g, placetype *where, Ship *ship, Race *r,
281 char *string,
const Planet &pl) {
290 if (!ship->alive)
return;
294 switch (where->level) {
295 case ScopeLevel::LEVEL_PLAN:
298 (ship->xpos - (Stars[where->snum]->xpos + pl.xpos) -
Lastx)) /
302 (ship->ypos - (Stars[where->snum]->ypos + pl.ypos) -
Lasty)) /
305 case ScopeLevel::LEVEL_STAR:
307 (
SCALE * (ship->xpos - Stars[where->snum]->xpos -
Lastx)) /
310 (
SCALE * (ship->ypos - Stars[where->snum]->ypos -
Lasty)) /
313 case ScopeLevel::LEVEL_UNIV:
318 notify(g.player, g.governor,
"WHOA! error in DispShip.\n");
322 switch (ship->type) {
323 case ShipType::STYPE_MIRROR:
324 if (ship->special.aimed_at.level == ScopeLevel::LEVEL_STAR) {
325 xt = Stars[ship->special.aimed_at.snum]->xpos;
326 yt = Stars[ship->special.aimed_at.snum]->ypos;
327 }
else if (ship->special.aimed_at.level == ScopeLevel::LEVEL_PLAN) {
328 if (where->level == ScopeLevel::LEVEL_PLAN &&
329 ship->special.aimed_at.pnum == where->pnum) {
331 xt = Stars[ship->special.aimed_at.snum]->xpos + pl.xpos;
332 yt = Stars[ship->special.aimed_at.snum]->ypos + pl.ypos;
335 xt = Stars[ship->special.aimed_at.snum]->xpos + apl.xpos;
336 yt = Stars[ship->special.aimed_at.snum]->ypos + apl.ypos;
338 }
else if (ship->special.aimed_at.level == ScopeLevel::LEVEL_SHIP) {
339 auto aship = getship(ship->special.aimed_at.shipno);
349 if (xt == ship->xpos) {
355 slope = (yt - ship->ypos) / (xt - ship->xpos);
356 if (yt == ship->ypos) {
361 }
else if (yt > ship->ypos) {
362 if (slope < -2.414) wm = 4;
363 if (slope > -2.414) wm = 5;
364 if (slope > -0.414) wm = 6;
365 if (slope > 0.000) wm = 2;
366 if (slope > 0.414) wm = 3;
367 if (slope > 2.414) wm = 4;
368 }
else if (yt < ship->ypos) {
369 if (slope < -2.414) wm = 0;
370 if (slope > -2.414) wm = 1;
371 if (slope > -0.414) wm = 2;
372 if (slope > 0.000) wm = 6;
373 if (slope > 0.414) wm = 7;
374 if (slope > 2.414) wm = 0;
379 if (x >= 0 && y >= 0) {
380 if (r->governor[g.governor].toggle.color) {
381 sprintf(string,
"%c %d %d %d %c %c %lu;", (
char)(ship->owner +
'?'),
382 x, y, wm, Shipltrs[ship->type], (
char)(ship->owner +
'?'),
385 stand = (ship->owner == r->governor[g.governor].toggle.highlight);
386 sprintf(string,
"%d %d %d %d %c %d %lu;", stand, x, y, wm,
387 Shipltrs[ship->type], stand, ship->number);
392 case ShipType::OTYPE_CANIST:
393 case ShipType::OTYPE_GREEN:
399 if (ship->whatorbits != ScopeLevel::LEVEL_UNIV ||
400 ((ship->owner == g.player) || g.god))
401 if (x >= 0 && y >= 0) {
402 if (r->governor[g.governor].toggle.color) {
403 sprintf(string,
"%c %d %d %d %c %c %lu;", (
char)(ship->owner +
'?'),
404 x, y, wm, Shipltrs[ship->type], (
char)(ship->owner +
'?'),
407 stand = (ship->owner == r->governor[g.governor].toggle.highlight);
408 sprintf(string,
"%d %d %d %d %c %d %lu;", stand, x, y, wm,
409 Shipltrs[ship->type], stand, ship->number);
void orbit(const command_t &argv, GameObj &g)
Planet getplanet(const starnum_t star, const planetnum_t pnum)
double compatibility(const Planet &planet, const Race *race)
static void DispShip(const GameObj &, placetype *, Ship *, Race *, char *, const Planet &=Planet())
static void DispStar(const GameObj &, const ScopeLevel, startype *, int, Race *, char *)
static void DispPlanet(const GameObj &, const ScopeLevel, const Planet &, char *, int, Race *, char *)