11 #include "gb/getplace.h" 19 #include "gb/GB_server.h" 20 #include "gb/buffers.h" 21 #include "gb/files_shl.h" 24 #include "gb/shlmisc.h" 25 #include "gb/tweakables.h" 30 static placetype
getplace2(
int Playernum,
int Governor,
const char *string,
31 placetype *where,
int ignoreexpl,
int God);
33 placetype
getplace(GameObj &g,
const std::string &string,
34 const int ignoreexpl) {
35 player_t Playernum = g.player;
36 governor_t Governor = g.governor;
39 const auto God = races[Playernum - 1]->God;
43 if (string.size() != 0) {
46 where.level = ScopeLevel::LEVEL_UNIV;
48 where.pnum = where.shipno = 0;
49 return (getplace2(Playernum, Governor, string.c_str() + 1, &where,
52 auto shipnotmp = string_to_shipnum(string);
54 where.shipno = *shipnotmp;
58 auto ship = getship(where.shipno);
60 DontOwnErr(Playernum, Governor, where.shipno);
64 if ((ship->owner == Playernum || ignoreexpl || God) &&
65 (ship->alive || God)) {
66 where.level = ScopeLevel::LEVEL_SHIP;
67 where.snum = ship->storbits;
68 where.pnum = ship->pnumorbits;
76 where.level = ScopeLevel::LEVEL_UNIV;
82 where.level = g.level;
85 if (where.level == ScopeLevel::LEVEL_SHIP) where.shipno = g.shipno;
86 if (string.size() != 0 && string[0] == CHAR_CURR_SCOPE)
return where;
88 return getplace2(Playernum, Governor, string.c_str(), &where, ignoreexpl,
92 static placetype getplace2(
const int Playernum,
const int Governor,
93 const char *string, placetype *where,
94 const int ignoreexpl,
const int God) {
100 if (where->err || string ==
nullptr || *string ==
'\0' || *string ==
'\n')
102 if (*string ==
'.') {
103 if (where->level == ScopeLevel::LEVEL_UNIV) {
104 sprintf(buf,
"Can't go higher.\n");
105 notify(Playernum, Governor, buf);
109 if (where->level == ScopeLevel::LEVEL_SHIP) {
110 auto ship = getship(where->shipno);
111 where->level = ship->whatorbits;
113 if (where->level == ScopeLevel::LEVEL_SHIP)
114 where->shipno = ship->destshipno;
115 }
else if (where->level == ScopeLevel::LEVEL_STAR) {
116 where->level = ScopeLevel::LEVEL_UNIV;
117 }
else if (where->level == ScopeLevel::LEVEL_PLAN) {
118 where->level = ScopeLevel::LEVEL_STAR;
120 while (*string ==
'.') string++;
121 while (*string ==
'/') string++;
122 return (getplace2(Playernum, Governor, string, where, ignoreexpl, God));
125 sscanf(string,
"%[^/ \n]", substr);
130 }
while (*string !=
'/' && *string !=
'\n' && *string !=
'\0');
132 if (where->level == ScopeLevel::LEVEL_UNIV) {
133 for (i = 0; i < Sdata.numstars; i++)
134 if (!strncmp(substr, Stars[i]->name, l)) {
135 where->level = ScopeLevel::LEVEL_STAR;
137 if (ignoreexpl ||
isset(Stars[where->snum]->explored, Playernum) ||
139 tick = (*string ==
'/');
140 return (getplace2(Playernum, Governor, string + tick, where,
143 sprintf(buf,
"You have not explored %s yet.\n",
144 Stars[where->snum]->name);
145 notify(Playernum, Governor, buf);
149 if (i >= Sdata.numstars) {
150 sprintf(buf,
"No such star %s.\n", substr);
151 notify(Playernum, Governor, buf);
155 }
else if (where->level == ScopeLevel::LEVEL_STAR) {
156 for (i = 0; i < Stars[where->snum]->numplanets; i++)
157 if (!strncmp(substr, Stars[where->snum]->pnames[i], l)) {
158 where->level = ScopeLevel::LEVEL_PLAN;
161 if (ignoreexpl || p.info[Playernum - 1].explored || God) {
162 tick = (*string ==
'/');
163 return (getplace2(Playernum, Governor, string + tick, where,
166 sprintf(buf,
"You have not explored %s yet.\n",
167 Stars[where->snum]->pnames[i]);
168 notify(Playernum, Governor, buf);
172 if (i >= Stars[where->snum]->numplanets) {
173 sprintf(buf,
"No such planet %s.\n", substr);
174 notify(Playernum, Governor, buf);
179 sprintf(buf,
"Can't descend to %s.\n", substr);
180 notify(Playernum, Governor, buf);
191 switch (ship->whatorbits) {
192 case ScopeLevel::LEVEL_STAR:
193 sprintf(
Disps,
"/%-4.4s", Stars[ship->storbits]->name);
195 case ScopeLevel::LEVEL_PLAN:
196 sprintf(
Disps,
"/%s", Stars[ship->storbits]->name);
197 for (i = 2; (
Disps[i] && (i < 5)); i++)
199 sprintf(
Disps + i,
"/%-4.4s",
200 Stars[ship->storbits]->pnames[ship->pnumorbits]);
202 case ScopeLevel::LEVEL_SHIP:
203 sprintf(
Disps,
"#%lu", ship->destshipno);
205 case ScopeLevel::LEVEL_UNIV:
212 switch (ship->whatorbits) {
213 case ScopeLevel::LEVEL_STAR:
214 sprintf(
Disps,
"/%s", Stars[ship->storbits]->name);
216 case ScopeLevel::LEVEL_PLAN:
217 sprintf(
Disps,
"/%s/%s", Stars[ship->storbits]->name,
218 Stars[ship->storbits]->pnames[ship->pnumorbits]);
220 case ScopeLevel::LEVEL_SHIP:
221 sprintf(
Disps,
"#%lu", ship->destshipno);
223 case ScopeLevel::LEVEL_UNIV:
230 std::ostringstream out;
231 switch (where.level) {
232 case ScopeLevel::LEVEL_STAR:
233 out <<
"/" << Stars[where.snum]->name;
235 case ScopeLevel::LEVEL_PLAN:
236 out <<
"/" << Stars[where.snum]->name <<
"/" 237 << Stars[where.snum]->pnames[where.pnum];
239 case ScopeLevel::LEVEL_SHIP:
240 out <<
"#" << where.shipno;
242 case ScopeLevel::LEVEL_UNIV:
248 bool testship(
const player_t playernum,
const governor_t governor,
251 sprintf(buf,
"%s has been destroyed.\n", ship_to_string(s).c_str());
252 notify(playernum, governor, buf);
256 if (s.owner != playernum || !authorized(governor, s)) {
262 sprintf(buf,
"%s is irradiated %d%% and inactive.\n",
263 ship_to_string(s).c_str(), s.rad);
264 notify(playernum, governor, buf);
char * Dispshiploc(Ship *ship)
char * Dispshiploc_brief(Ship *ship)
Planet getplanet(const starnum_t star, const planetnum_t pnum)
void DontOwnErr(int Playernum, int Governor, shipnum_t shipno)
static placetype getplace2(int Playernum, int Governor, const char *string, placetype *where, int ignoreexpl, int God)
placetype getplace(GameObj &g, const std::string &string, const int ignoreexpl)
static char Disps[PLACENAMESIZE]
bool testship(const player_t playernum, const governor_t governor, const Ship &s)
std::string Dispplace(const placetype &where)