8 #include "gb/shlmisc.h" 19 #include "gb/GB_server.h" 20 #include "gb/buffers.h" 22 #include "gb/files_shl.h" 26 #include "gb/tweakables.h" 35 if (s.size() > 1 && s[0] ==
'#') {
37 return string_to_shipnum(s);
40 if (s.size() > 0 && std::isdigit(s[0])) {
41 return (std::stoi(std::string(s.begin(), s.end())));
46 bool authorized(
const governor_t Governor,
const Ship &ship) {
47 return (!Governor || ship.governor == Governor);
70 auto s = string_to_shipnum(p);
77 case ScopeLevel::LEVEL_UNIV:
80 case ScopeLevel::LEVEL_STAR:
82 return Stars[g.snum]->ships;
83 case ScopeLevel::LEVEL_PLAN: {
87 case ScopeLevel::LEVEL_SHIP:
88 auto ship = getship(g.shipno);
96 if (!(shipno = *nextshipno))
return 0;
98 if (!getship(s, shipno))
100 *nextshipno = (*s)->nextship;
109 bool in_list(
const player_t playernum,
const std::string_view list,
110 const Ship &s, shipnum_t *nextshipno) {
111 if (s.owner != playernum || !s.alive)
return false;
113 if (list.length() == 0)
return false;
115 if (list[0] ==
'#' || std::isdigit(list[0])) {
121 for (
const auto &p : list)
122 if (p == Shipltrs[s.type] || p ==
'*')
return true;
126 void DontOwnErr(
int Playernum,
int Governor, shipnum_t shipno) {
127 sprintf(buf,
"You don't own ship #%lu.\n", shipno);
128 notify(Playernum, Governor, buf);
131 int enufAP(
int Playernum,
int Governor,
unsigned short AP,
int x) {
134 if ((blah = (AP < x))) {
135 sprintf(buf,
"You don't have %d action points there.\n", x);
136 notify(Playernum, Governor, buf);
147 std::tuple<player_t, governor_t>
getracenum(
const std::string &racepass,
148 const std::string &govpass) {
149 for (
auto race : races) {
150 if (racepass == race->password) {
152 if (*race->governor[j].password &&
153 govpass == race->governor[j].password) {
154 return {race->Playernum, j};
166 if (isdigit(name[0])) {
167 if ((rnum = std::stoi(name)) < 1 || rnum > Num_races)
return 0;
170 for (player_t i = 1; i <= Num_races; i++)
171 if (name == races[i - 1]->name)
return i;
176 player_t Playernum = g.player;
177 governor_t Governor = g.governor;
182 if (g.level == ScopeLevel::LEVEL_UNIV) {
185 "Change scope to the system you which to transfer global APs to.\n");
186 notify(Playernum, Governor, buf);
189 alloc = std::stoi(argv[1]);
191 notify(Playernum, Governor,
192 "You must specify a positive amount of APs to allocate.\n");
197 maxalloc =
MIN(Sdata.AP[Playernum - 1],
198 LIMIT_APs - Stars[g.snum]->AP[Playernum - 1]);
199 if (alloc > maxalloc) {
200 sprintf(buf,
"Illegal value (%d) - maximum = %d\n", alloc, maxalloc);
201 notify(Playernum, Governor, buf);
204 Sdata.AP[Playernum - 1] -= alloc;
207 Stars[g.snum]->AP[Playernum - 1] =
208 MIN(
LIMIT_APs, Stars[g.snum]->AP[Playernum - 1] + alloc);
210 sprintf(buf,
"Allocated\n");
211 notify(Playernum, Governor, buf);
214 void deductAPs(
const player_t Playernum,
const governor_t Governor,
215 unsigned int n, starnum_t snum,
int sdata) {
220 if (Stars[snum]->AP[Playernum - 1] >= n)
221 Stars[snum]->AP[Playernum - 1] -= n;
223 Stars[snum]->AP[Playernum - 1] = 0;
225 "WHOA! You cheater! Oooohh! OOOOH!\n I'm " 226 "tellllllllliiiiiiinnnnnnnnnggggggggg!!!!!!!\n");
227 notify(Playernum, Governor, buf);
233 Sdata.AP[Playernum - 1] = std::max(0u, Sdata.AP[Playernum - 1] - n);
240 return (atan((
double)x / 10000.) / 3.14159565 + .5);
bool in_list(const player_t playernum, const std::string_view list, const Ship &s, shipnum_t *nextshipno)
Check is the ship is in the given input string.
double morale_factor(double x)
Planet getplanet(const starnum_t star, const planetnum_t pnum)
player_t get_player(const std::string &name)
void DontOwnErr(int Playernum, int Governor, shipnum_t shipno)
bool authorized(const governor_t Governor, const Ship &ship)
shipnum_t start_shiplist(GameObj &g, const std::string_view p)
Get start of ship lists from either a ship number or ScopeLevel.
void deductAPs(const player_t Playernum, const governor_t Governor, unsigned int n, starnum_t snum, int sdata)
int enufAP(int Playernum, int Governor, unsigned short AP, int x)
void putstar(startype *s, starnum_t snum)
std::optional< shipnum_t > string_to_shipnum(std::string_view s)
Convert input string to a shipnum_t.
shipnum_t do_shiplist(Ship **s, shipnum_t *nextshipno)
void getsdata(struct stardata *S)
void getstar(startype **s, int star)
std::tuple< player_t, governor_t > getracenum(const std::string &racepass, const std::string &govpass)
Find the player/governor that matches passwords.
void putsdata(struct stardata *S)
void allocateAPs(const command_t &argv, GameObj &g)