10 #include "gb/GB_server.h" 11 #include "gb/files_shl.h" 12 #include "gb/getplace.h" 17 void center(
const command_t &argv, GameObj &g) {
18 if (argv.size() != 2) {
19 g.out <<
"center: which star?\n";
21 auto where = getplace(g, argv[1], 1);
24 g.out <<
"center: bad scope.\n";
27 if (where.level == ScopeLevel::LEVEL_SHIP) {
28 g.out <<
"CHEATER!!!\n";
31 g.lastx[1] = Stars[where.snum]->xpos;
32 g.lasty[1] = Stars[where.snum]->ypos;
35 void cs(
const command_t &argv, GameObj &g) {
36 const player_t Playernum = g.player;
37 const governor_t Governor = g.governor;
38 racetype *Race = races[Playernum - 1];
40 if (argv.size() == 1) {
42 g.level = Race->governor[Governor].deflevel;
43 if ((g.snum = Race->governor[Governor].defsystem) >= Sdata.numstars)
44 g.snum = Sdata.numstars - 1;
45 if ((g.pnum = Race->governor[Governor].defplanetnum) >=
46 Stars[g.snum]->numplanets)
47 g.pnum = Stars[g.snum]->numplanets - 1;
49 g.lastx[0] = g.lasty[0] = 0.0;
50 g.lastx[1] = Stars[g.snum]->xpos;
51 g.lasty[1] = Stars[g.snum]->ypos;
54 if (argv.size() == 2) {
57 auto where = getplace(g, argv[1], 0);
60 g.out <<
"cs: bad scope.\n";
61 g.lastx[0] = g.lasty[0] = 0.0;
68 case ScopeLevel::LEVEL_UNIV:
69 g.lastx[0] = g.lasty[0] = 0.0;
71 case ScopeLevel::LEVEL_STAR:
72 if (where.level == ScopeLevel::LEVEL_UNIV) {
73 g.lastx[1] = Stars[g.snum]->xpos;
74 g.lasty[1] = Stars[g.snum]->ypos;
76 g.lastx[0] = g.lasty[0] = 0.0;
78 case ScopeLevel::LEVEL_PLAN: {
80 if (where.level == ScopeLevel::LEVEL_STAR && where.snum == g.snum) {
81 g.lastx[0] = planet.xpos;
82 g.lasty[0] = planet.ypos;
83 }
else if (where.level == ScopeLevel::LEVEL_UNIV) {
84 g.lastx[1] = Stars[g.snum]->xpos + planet.xpos;
85 g.lasty[1] = Stars[g.snum]->ypos + planet.ypos;
87 g.lastx[0] = g.lasty[0] = 0.0;
89 case ScopeLevel::LEVEL_SHIP:
90 auto s = getship(g.shipno);
92 switch (where.level) {
93 case ScopeLevel::LEVEL_UNIV:
97 case ScopeLevel::LEVEL_STAR:
98 if (s->whatorbits >= ScopeLevel::LEVEL_STAR &&
99 s->storbits == where.snum) {
101 g.lastx[0] = s->xpos - Stars[s->storbits]->xpos;
102 g.lasty[0] = s->ypos - Stars[s->storbits]->ypos;
104 g.lastx[0] = g.lasty[0] = 0.0;
106 case ScopeLevel::LEVEL_PLAN:
107 if (s->whatorbits == ScopeLevel::LEVEL_PLAN &&
108 s->storbits == where.snum && s->pnumorbits == where.pnum) {
110 const auto planet = getplanet(s->storbits, s->pnumorbits);
111 g.lastx[0] = s->xpos - Stars[s->storbits]->xpos - planet.xpos;
112 g.lasty[0] = s->ypos - Stars[s->storbits]->ypos - planet.ypos;
114 g.lastx[0] = g.lasty[0] = 0.0;
116 case ScopeLevel::LEVEL_SHIP:
117 g.lastx[0] = g.lasty[0] = 0.0;
121 g.lastx[0] = g.lasty[0] = 0.0;
124 g.level = where.level;
127 g.shipno = where.shipno;
128 }
else if (argv.size() == 3 && argv[1][1] ==
'd') {
130 auto where = getplace(g, argv[2], 0);
132 if (!where.err && where.level != ScopeLevel::LEVEL_SHIP) {
133 Race->governor[Governor].deflevel = where.level;
134 Race->governor[Governor].defsystem = where.snum;
135 Race->governor[Governor].defplanetnum = where.pnum;
138 g.out <<
"New home system is " << Dispplace(where) <<
"\n";
140 g.out <<
"cs: bad home system.\n";
Planet getplanet(const starnum_t star, const planetnum_t pnum)
void center(const command_t &argv, GameObj &g)
void cs(const command_t &argv, GameObj &g)