7 #include "gb/commands/scrap.h" 12 #include "gb/GB_server.h" 13 #include "gb/buffers.h" 14 #include "gb/files_shl.h" 20 #include "gb/shlmisc.h" 23 void scrap(
const command_t &argv, GameObj &g) {
37 if (argv.size() < 2) {
38 g.out <<
"Scrap what?\n";
42 nextshipno = start_shiplist(g, argv[1]);
45 if (in_list(g.player, argv[1], *s, &nextshipno) &&
46 authorized(g.governor, *s)) {
47 if (s->max_crew && !s->popn) {
48 notify(g.player, g.governor,
"Can't scrap that ship - no crew.\n");
52 if (s->whatorbits == ScopeLevel::LEVEL_UNIV) {
55 if (!
enufAP(g.player
, g.governor
, Stars[s->storbits]->AP[g.player - 1]
, 60 if (s->whatorbits == ScopeLevel::LEVEL_PLAN &&
61 s->type == ShipType::OTYPE_TOXWC) {
63 "WARNING: This will release %d toxin points back into the " 65 s->special.waste.toxic);
66 notify(g.player, g.governor, buf);
70 "%s is not landed or docked.\nNo resources can be reclaimed.\n",
71 ship_to_string(*s).c_str());
72 notify(g.player, g.governor, buf);
74 if (s->whatorbits == ScopeLevel::LEVEL_PLAN) {
76 const auto planet =
getplanet(s->storbits
, s->pnumorbits
);
77 if (landed(*s)) sect =
getsector(planet
, s->land_x
, s->land_y
);
79 std::optional<Ship> s2;
81 s2 = getship(s->destshipno);
87 if (!(s2->docked && s2->destshipno == s->number) &&
88 s->whatorbits != ScopeLevel::LEVEL_SHIP) {
89 g.out <<
"Warning, other ship not docked..\n";
95 scrapval = shipcost(*s) / 2 + s->resource;
98 sprintf(buf,
"%s: original cost: %ld\n", ship_to_string(*s).c_str(),
100 notify(g.player, g.governor, buf);
101 sprintf(buf,
" scrap value%s: %d rp's.\n",
102 s->resource ?
"(with stockpile) " :
"", scrapval);
103 notify(g.player, g.governor, buf);
105 if (s->whatdest == ScopeLevel::LEVEL_SHIP &&
106 s2->resource + scrapval > max_resource(*s2) &&
107 s2->type != ShipType::STYPE_SHUTTLE) {
108 scrapval = max_resource(*s2) - s2->resource;
109 sprintf(buf,
"(There is only room for %d resources.)\n", scrapval);
110 notify(g.player, g.governor, buf);
113 sprintf(buf,
"Fuel recovery: %.0f.\n", s->fuel);
114 notify(g.player, g.governor, buf);
116 if (s->whatdest == ScopeLevel::LEVEL_SHIP &&
117 s2->fuel + fuelval > max_fuel(*s2)) {
118 fuelval = max_fuel(*s2) - s2->fuel;
119 sprintf(buf,
"(There is only room for %.2f fuel.)\n", fuelval);
120 notify(g.player, g.governor, buf);
126 sprintf(buf,
"Weapons recovery: %d.\n", s->destruct);
127 notify(g.player, g.governor, buf);
128 destval = s->destruct;
129 if (s->whatdest == ScopeLevel::LEVEL_SHIP &&
130 s2->destruct + destval > max_destruct(*s2)) {
131 destval = max_destruct(*s2) - s2->destruct;
132 sprintf(buf,
"(There is only room for %d destruct.)\n", destval);
133 notify(g.player, g.governor, buf);
138 if (s->popn + s->troops) {
139 if (s->whatdest == ScopeLevel::LEVEL_PLAN && sect.owner > 0 &&
140 sect.owner != g.player) {
141 g.out <<
"You don't own this sector; no crew can be recovered.\n";
143 sprintf(buf,
"Population/Troops recovery: %lu/%lu.\n", s->popn,
145 notify(g.player, g.governor, buf);
146 troopval = s->troops;
147 if (s->whatdest == ScopeLevel::LEVEL_SHIP &&
148 s2->troops + troopval > max_mil(*s2)) {
149 troopval = max_mil(*s2) - s2->troops;
150 sprintf(buf,
"(There is only room for %d troops.)\n", troopval);
151 notify(g.player, g.governor, buf);
154 if (s->whatdest == ScopeLevel::LEVEL_SHIP &&
155 s2->popn + crewval > max_crew(*s2)) {
156 crewval = max_crew(*s2) - s2->popn;
157 sprintf(buf,
"(There is only room for %d crew.)\n", crewval);
158 notify(g.player, g.governor, buf);
166 if (s->crystals + s->mounted) {
167 if (s->whatdest == ScopeLevel::LEVEL_PLAN && sect.owner > 0 &&
168 sect.owner != g.player) {
170 <<
"You don't own this sector; no crystals can be recovered.\n";
172 xtalval = s->crystals + s->mounted;
173 if (s->whatdest == ScopeLevel::LEVEL_SHIP &&
174 s2->crystals + xtalval > max_crystals(*s2)) {
175 xtalval = max_crystals(*s2) - s2->crystals;
176 sprintf(buf,
"(There is only room for %d crystals.)\n", xtalval);
177 notify(g.player, g.governor, buf);
179 sprintf(buf,
"Crystal recovery: %d.\n", xtalval);
180 notify(g.player, g.governor, buf);
187 if (s->whatorbits == ScopeLevel::LEVEL_SHIP) s2->hanger -= s->size;
189 if (s->whatorbits == ScopeLevel::LEVEL_UNIV)
194 Race = races[g.player - 1];
198 kill_ship(g.player, s);
201 s2->crystals += xtalval;
202 rcv_fuel(&*s2, (
double)fuelval);
203 rcv_destruct(&*s2, destval);
204 rcv_resource(&*s2, scrapval);
205 rcv_troops(&*s2, troopval, Race->mass);
206 rcv_popn(&*s2, crewval, Race->mass);
208 if (!(s->whatorbits == ScopeLevel::LEVEL_SHIP)) {
210 s2->whatdest = ScopeLevel::LEVEL_UNIV;
216 if (s->whatorbits == ScopeLevel::LEVEL_PLAN) {
219 if (sect.owner == g.player) {
220 sect.popn += troopval;
221 sect.popn += crewval;
222 }
else if (sect.owner == 0) {
223 sect.owner = g.player;
224 sect.popn += crewval;
225 sect.troops += troopval;
226 planet.info[g.player - 1].numsectsowned++;
227 planet.info[g.player - 1].popn += crewval;
228 planet.info[g.player - 1].popn += troopval;
229 sprintf(buf,
"Sector %d,%d Colonized.\n", s->land_x, s->land_y);
230 notify(g.player, g.governor, buf);
232 planet.info[g.player - 1].resource += scrapval;
233 planet.popn += crewval;
234 planet.info[g.player - 1].destruct += destval;
235 planet.info[g.player - 1].fuel += (
int)fuelval;
236 planet.info[g.player - 1].crystals += (
int)xtalval;
242 g.out <<
"\nScrapped.\n";
244 g.out <<
"\nDestroyed.\n";
Planet getplanet(const starnum_t star, const planetnum_t pnum)
void putsector(const Sector &s, const Planet &p, const int x, const int y)
void deductAPs(const player_t Playernum, const governor_t Governor, unsigned int n, starnum_t snum, int sdata)
void scrap(const command_t &argv, GameObj &g)
int enufAP(int Playernum, int Governor, unsigned short AP, int x)
shipnum_t do_shiplist(Ship **s, shipnum_t *nextshipno)
void putplanet(const Planet &p, startype *star, const int pnum)
Sector getsector(const Planet &p, const int x, const int y)