12 #include "gb/GB_server.h" 13 #include "gb/buffers.h" 14 #include "gb/files_shl.h" 19 #include "gb/shlmisc.h" 20 #include "gb/tweakables.h" 21 #include "gb/utils/rand.h" 24 void launch(
const command_t &argv, GameObj &g) {
25 player_t Playernum = g.player;
26 governor_t Governor = g.governor;
33 if (argv.size() < 2) {
34 g.out <<
"Launch what?\n";
38 nextshipno = start_shiplist(g, argv[1]);
41 if (in_list(Playernum, argv[1], *s, &nextshipno) &&
42 authorized(Governor, *s)) {
43 if (!speed_rating(*s) && landed(*s)) {
44 sprintf(buf,
"That ship is not designed to be launched.\n");
45 notify(Playernum, Governor, buf);
50 if (!(s->docked || s->whatorbits == ScopeLevel::LEVEL_SHIP)) {
51 sprintf(buf,
"%s is not landed or docked.\n",
52 ship_to_string(*s).c_str());
53 notify(Playernum, Governor, buf);
57 if (!landed(*s)) APcount = 0;
58 if (landed(*s) && s->resource > max_resource(*s)) {
59 sprintf(buf,
"%s is too overloaded to launch.\n",
60 ship_to_string(*s).c_str());
61 notify(Playernum, Governor, buf);
65 if (s->whatorbits == ScopeLevel::LEVEL_SHIP) {
67 if (s->type == ShipType::OTYPE_FACTORY && s->on) {
68 notify(Playernum, Governor,
69 "Factories cannot be launched once turned on.\n");
70 g.out <<
"Consider using 'scrap'.\n";
74 auto s2 = getship(s->destshipno);
76 remove_sh_ship(*s, *s2);
77 auto p = getplanet(s2->storbits, s2->pnumorbits);
78 insert_sh_plan(&p, s);
79 putplanet(p, Stars[s2->storbits], s2->pnumorbits);
80 s->storbits = s2->storbits;
81 s->pnumorbits = s2->pnumorbits;
82 s->destpnum = s2->pnumorbits;
83 s->deststar = s2->deststar;
86 s->land_x = s2->land_x;
87 s->land_y = s2->land_y;
89 s->whatdest = ScopeLevel::LEVEL_PLAN;
91 s2->hanger -= size(*s);
92 sprintf(buf,
"Landed on %s/%s.\n", Stars[s->storbits]->name,
93 Stars[s->storbits]->pnames[s->pnumorbits]);
94 notify(Playernum, Governor, buf);
97 }
else if (s2->whatorbits == ScopeLevel::LEVEL_PLAN) {
98 remove_sh_ship(*s, *s2);
99 sprintf(buf,
"%s launched from %s.\n", ship_to_string(*s).c_str(),
100 ship_to_string(*s2).c_str());
101 notify(Playernum, Governor, buf);
105 s->whatdest = ScopeLevel::LEVEL_UNIV;
107 s2->hanger -= size(*s);
108 auto p = getplanet(s2->storbits, s2->pnumorbits);
109 insert_sh_plan(&p, s);
110 s->storbits = s2->storbits;
111 s->pnumorbits = s2->pnumorbits;
112 putplanet(p, Stars[s2->storbits], s2->pnumorbits);
113 sprintf(buf,
"Orbiting %s/%s.\n", Stars[s->storbits]->name,
114 Stars[s->storbits]->pnames[s->pnumorbits]);
115 notify(Playernum, Governor, buf);
118 }
else if (s2->whatorbits == ScopeLevel::LEVEL_STAR) {
119 remove_sh_ship(*s, *s2);
120 sprintf(buf,
"%s launched from %s.\n", ship_to_string(*s).c_str(),
121 ship_to_string(*s2).c_str());
122 notify(Playernum, Governor, buf);
126 s->whatdest = ScopeLevel::LEVEL_UNIV;
128 s2->hanger -= size(*s);
129 getstar(&(Stars[s2->storbits]), (
int)s2->storbits);
130 insert_sh_star(Stars[s2->storbits], s);
131 s->storbits = s2->storbits;
132 putstar(Stars[s2->storbits], (
int)s2->storbits);
133 sprintf(buf,
"Orbiting %s.\n", Stars[s->storbits]->name);
134 notify(Playernum, Governor, buf);
137 }
else if (s2->whatorbits == ScopeLevel::LEVEL_UNIV) {
138 remove_sh_ship(*s, *s2);
139 sprintf(buf,
"%s launched from %s.\n", ship_to_string(*s).c_str(),
140 ship_to_string(*s2).c_str());
141 notify(Playernum, Governor, buf);
145 s->whatdest = ScopeLevel::LEVEL_UNIV;
147 s2->hanger -= size(*s);
149 insert_sh_univ(&Sdata, s);
150 g.out <<
"Universe level.\n";
155 g.out <<
"You can't launch that ship.\n";
160 }
else if (s->whatdest == ScopeLevel::LEVEL_SHIP) {
161 auto s2 = getship(s->destshipno);
162 if (s2->whatorbits == ScopeLevel::LEVEL_UNIV) {
163 if (!
enufAP(Playernum
, Governor
, Sdata.AP[Playernum - 1]
, APcount
)) {
170 Stars[s->storbits]->AP[Playernum - 1]
, APcount
)) {
177 s->whatdest = ScopeLevel::LEVEL_UNIV;
180 s2->whatdest = ScopeLevel::LEVEL_UNIV;
182 sprintf(buf,
"%s undocked from %s.\n", ship_to_string(*s).c_str(),
183 ship_to_string(*s2).c_str());
184 notify(Playernum, Governor, buf);
189 if (!
enufAP(Playernum
, Governor
, Stars[s->storbits]->AP[Playernum - 1]
, 197 auto p =
getplanet((
int)s->storbits
, (
int)s->pnumorbits
);
198 sprintf(buf,
"Planet /%s/%s has gravity field of %.2f\n",
199 Stars[s->storbits]->name,
200 Stars[s->storbits]->pnames[s->pnumorbits],
gravity(p
));
201 notify(Playernum, Governor, buf);
203 Stars[s->storbits]->xpos + p.xpos +
206 Stars[s->storbits]->ypos + p.ypos +
211 if (s->fuel < fuel) {
212 sprintf(buf,
"%s does not have enough fuel! (%.1f)\n",
213 ship_to_string(*s).c_str(), fuel);
214 notify(Playernum, Governor, buf);
220 s->whatdest = ScopeLevel::LEVEL_UNIV;
222 case ShipType::OTYPE_CANIST:
223 case ShipType::OTYPE_GREEN:
224 s->special.timer.count = 0;
237 sprintf(buf,
"%s observed launching from planet /%s/%s.\n",
238 ship_to_string(*s).c_str(), Stars[s->storbits]->name,
239 Stars[s->storbits]->pnames[s->pnumorbits]);
240 for (player_t i = 1; i <= Num_races; i++)
241 if (p.info[i - 1].numsectsowned && i != Playernum)
242 notify(i, (
int)Stars[s->storbits]->governor[i - 1], buf);
244 sprintf(buf,
"%s launched from planet,", ship_to_string(*s).c_str());
245 notify(Playernum, Governor, buf);
246 sprintf(buf,
" using %.1f fuel.\n", fuel);
247 notify(Playernum, Governor, buf);
250 case ShipType::OTYPE_CANIST:
251 notify(Playernum, Governor,
252 "A cloud of dust envelopes your planet.\n");
254 case ShipType::OTYPE_GREEN:
255 notify(Playernum, Governor,
256 "Green house gases surround the planet.\n");
void use_fuel(Ship *s, double amt)
Planet getplanet(const starnum_t star, const planetnum_t pnum)
#define LAUNCH_GRAV_MASS_FACTOR
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)
shipnum_t do_shiplist(Ship **s, shipnum_t *nextshipno)
void getsdata(struct stardata *S)
void putplanet(const Planet &p, startype *star, const int pnum)
void launch(const command_t &argv, GameObj &g)
void putsdata(struct stardata *S)
double gravity(const Planet &p)