15 #include "gb/GB_server.h" 16 #include "gb/doship.h" 17 #include "gb/files_shl.h" 19 #include "gb/getplace.h" 21 #include "gb/moveship.h" 24 #include "gb/shlmisc.h" 25 #include "gb/tweakables.h" 34 static int do_trip(
const placetype &,
double fuel,
double gravity_factor);
35 static void fuel_output(
int Playernum,
int Governor,
double dist,
double fuel,
36 double grav,
double mass, segments_t segs);
39 const player_t Playernum = g.player;
40 const governor_t Governor = g.governor;
44 segments_t current_segs;
49 double current_fuel = 0.0;
50 double gravity_factor = 0.0;
53 if ((argv.size() < 2) || (argv.size() > 3)) {
54 notify(Playernum, Governor,
55 "Invalid number of options.\n\"fuel " 56 "#<shipnumber> [destination]\"...\n");
59 if (argv[1][0] !=
'#') {
60 notify(Playernum, Governor,
61 "Invalid first option.\n\"fuel #<shipnumber> [destination]\"...\n");
64 auto shipno = string_to_shipnum(argv[1]);
65 if (!shipno || *shipno > Numships() || *shipno < 1) {
66 sprintf(buf,
"rst: no such ship #%lu \n", *shipno);
67 notify(Playernum, Governor, buf);
70 auto ship = getship(*shipno);
71 if (ship->owner != Playernum) {
72 g.out <<
"You do not own this ship.\n";
75 if (landed(*ship) && (argv.size() == 2)) {
76 g.out <<
"You must specify a destination for landed or docked ships...\n";
80 g.out <<
"That ship is not moving!\n";
83 if ((!speed_rating(*ship)) || (ship->type == ShipType::OTYPE_FACTORY)) {
84 g.out <<
"That ship does not have a speed rating...\n";
87 if (landed(*ship) && (ship->whatorbits == ScopeLevel::LEVEL_PLAN)) {
88 const auto p = getplanet(ship->storbits, ship->pnumorbits);
89 gravity_factor = gravity(p);
90 sprintf(plan_buf,
"/%s/%s", Stars[(
int)ship->storbits]->name,
91 Stars[(
int)ship->storbits]->pnames[(
int)ship->pnumorbits]);
94 if (argv.size() == 2) {
95 deststr = prin_ship_dest(*ship);
99 tmpdest = getplace(g, deststr, 1);
101 g.out <<
"fuel: bad scope.\n";
104 if (tmpdest.level == ScopeLevel::LEVEL_SHIP) {
105 (
void)getship(&tmpship, tmpdest.shipno);
106 if (!followable(&*ship, tmpship)) {
107 g.out <<
"The ship's destination is out of range.\n";
113 if (tmpdest.level != ScopeLevel::LEVEL_UNIV &&
114 tmpdest.level != ScopeLevel::LEVEL_SHIP &&
115 ((ship->storbits != tmpdest.snum) &&
116 tmpdest.level != ScopeLevel::LEVEL_STAR) &&
117 isclr(Stars[tmpdest.snum]->explored, ship->owner)) {
118 g.out <<
"You haven't explored the destination system.\n";
121 if (tmpdest.level == ScopeLevel::LEVEL_UNIV) {
122 g.out <<
"Invalid ship destination.\n";
130 if (tmpdest.level == ScopeLevel::LEVEL_UNIV) {
131 notify(Playernum, Governor,
132 "That ship currently has no destination orders...\n");
135 if (tmpdest.level == ScopeLevel::LEVEL_SHIP) {
136 (
void)getship(&tmpship, tmpdest.shipno);
137 if (
tmpship->owner != Playernum) {
138 g.out <<
"Nice try.\n";
144 }
else if (tmpdest.level == ScopeLevel::LEVEL_PLAN) {
146 x_1 = p.xpos + Stars[tmpdest.snum]->xpos;
147 y_1 = p.ypos + Stars[tmpdest.snum]->ypos;
148 }
else if (tmpdest.level == ScopeLevel::LEVEL_STAR) {
149 x_1 = Stars[tmpdest.snum]->xpos;
150 y_1 = Stars[tmpdest.snum]->ypos;
152 printf(
"ERROR 99\n");
158 notify(Playernum, Governor,
159 "That ship is within 10.0 units of the destination.\n");
164 (
void)getship(&tmpship, *shipno);
168 if (current_settings) current_fuel = level -
tmpship->fuel;
172 fuel_usage = level =
tmpship->max_fuel;
175 (
void)getship(&tmpship, *shipno);
176 computing =
do_trip(tmpdest
, level
, gravity_factor
);
177 if ((computing) && (
tmpship->fuel >= 0.05)) {
181 }
else if (computing) {
188 (
void)getship(&tmpship, *shipno);
190 "\n ----- ===== FUEL ESTIMATES ===== ----\n\nAt Current Fuel " 194 notify(Playernum, Governor, buf);
195 if (!current_settings) {
196 sprintf(buf,
"The ship will not be able to complete the trip.\n");
197 notify(Playernum, Governor, buf);
201 sprintf(buf,
"At Optimum Fuel Level (%.2ff):\n", fuel_usage);
202 notify(Playernum, Governor, buf);
204 sprintf(buf,
"The ship will not be able to complete the trip.\n");
205 notify(Playernum, Governor, buf);
215 static void fuel_output(
int Playernum,
int Governor,
double dist,
double fuel,
216 double grav,
double mass, segments_t segs) {
221 sprintf(grav_buf,
" (%.2f used to launch from %s)\n",
224 sprintf(grav_buf,
" ");
226 "Total Distance = %.2f Number of Segments = %d\nFuel = %.2f%s ",
227 dist, segs, fuel, grav_buf);
228 notify(Playernum, Governor, buf);
229 if (nsegments_done > segments)
232 "Estimated arrival time not available due to segment # discrepancy.\n");
234 time_t effective_time =
235 next_segment_time + ((segs - 1) * (update_time / segments) * 60);
238 next_update_time + (
long)((segs - 1) * (update_time * 60));
239 sprintf(buf,
"ESTIMATED Arrival Time: %s\n", ctime(&effective_time));
240 notify(Playernum, Governor, buf);
245 static int do_trip(
const placetype &tmpdest,
double fuel,
246 double gravity_factor) {
247 segments_t effective_segment_number;
254 effective_segment_number = nsegments_done;
257 tmpship->destshipno = (
unsigned short)tmpdest.shipno;
258 tmpship->whatdest = tmpdest.level;
259 tmpship->deststar = tmpdest.snum;
260 tmpship->destpnum = tmpdest.pnum;
261 if (
tmpship->whatdest == ScopeLevel::LEVEL_SHIP ||
tmpship->ships) {
264 ships = (Ship **)malloc(
sizeof(Ship *) * (Num_ships) + 1);
265 for (shipnum_t i = 1; i <= Num_ships; i++) (
void)getship(&ships[i], i);
276 while (trip_resolved == 0) {
281 effective_segment_number++;
282 if (effective_segment_number == (segments + 1))
283 effective_segment_number = 1;
288 case ScopeLevel::LEVEL_STAR:
289 if (tmpdist <= (
double)
SYSTEMSIZE) trip_resolved = 1;
291 case ScopeLevel::LEVEL_PLAN:
292 if (tmpdist <= (
double)
PLORBITSIZE) trip_resolved = 1;
294 case ScopeLevel::LEVEL_SHIP:
300 if (((
tmpship->fuel == fuel_level1) && (!
tmpship->hyper_drive.on)) &&
301 (trip_resolved == 0)) {
302 if (
tmpship->whatdest == ScopeLevel::LEVEL_SHIP) {
303 for (shipnum_t i = 1; i <= Num_ships; i++) free(ships[i]);
309 if (
tmpship->whatdest == ScopeLevel::LEVEL_SHIP ||
tmpship->ships) {
310 for (shipnum_t i = 1; i <= Num_ships; i++) free(ships[i]);
#define Distsq(x1, y1, x2, y2)
Planet getplanet(const starnum_t star, const planetnum_t pnum)
static char plan_buf[1024]
#define LAUNCH_GRAV_MASS_FACTOR
static void fuel_output(int Playernum, int Governor, double dist, double fuel, double grav, double mass, segments_t segs)
void moveship(Ship *, int, int, int)
void proj_fuel(const command_t &argv, GameObj &g)
static segments_t number_segments
static int do_trip(const placetype &, double fuel, double gravity_factor)