5 #include <boost/format.hpp> 8 #include "gb/defense.h" 11 #include "gb/files_shl.h" 19 bool has_switch(
const Ship &s) {
return Shipdata[s.type][ABIL_HASSWITCH]; }
23 return Shipdata[s.type][ABIL_GUNS] && (s.type != ShipType::STYPE_MINE);
28 return Shipdata[s.type][ABIL_SPEED] > 0 && s.type != ShipType::OTYPE_TERRA &&
29 s.type != ShipType::OTYPE_VN;
34 return s.type >= ShipType::STYPE_MIRROR && s.type <= ShipType::OTYPE_TRACT;
38 unsigned long armor(
const Ship &s) {
39 return (s.type == ShipType::OTYPE_FACTORY) ? Shipdata[s.type][ABIL_ARMOR]
40 : s.armor * (100 - s.damage) / 100;
44 return (s.guns == GTYPE_NONE) ? 0
45 : (s.guns ==
PRIMARY ? s.primary : s.secondary);
49 return (s.type == ShipType::OTYPE_FACTORY)
50 ? Shipdata[s.type][ABIL_MAXCREW] - s.troops
51 : s.max_crew - s.troops;
55 return (s.type == ShipType::OTYPE_FACTORY)
56 ? Shipdata[s.type][ABIL_MAXCREW] - s.popn
57 : s.max_crew - s.popn;
61 return (s.type == ShipType::OTYPE_FACTORY) ? Shipdata[s.type][ABIL_CARGO]
67 return (s.type == ShipType::OTYPE_FACTORY) ? Shipdata[s.type][ABIL_FUELCAP]
72 return (s.type == ShipType::OTYPE_FACTORY) ? Shipdata[s.type][ABIL_DESTCAP]
77 return (s.type == ShipType::OTYPE_FACTORY) ? Shipdata[s.type][ABIL_SPEED]
82 return (s.type == ShipType::OTYPE_FACTORY)
83 ? 2 * s.build_cost * s.on + Shipdata[s.type][ABIL_COST]
87 double mass(
const Ship &s) {
return s.mass; }
90 return (s.type == ShipType::OTYPE_PROBE) || s.popn;
93 long retaliate(
const Ship &s) {
return s.retaliate; }
95 int size(
const Ship &s) {
return s.size; }
97 int shipbody(
const Ship &s) {
return s.size - s.max_hanger; }
99 long hanger(
const Ship &s) {
return s.max_hanger - s.hanger; }
102 return (s.type == ShipType::OTYPE_FACTORY) ? s.on :
max_crew(s
);
105 Shiplist::Iterator::Iterator(shipnum_t a) {
106 auto tmpship = getship(a);
115 Shiplist::Iterator &Shiplist::Iterator::operator++() {
116 auto tmpship = getship(elem.nextship);
128 const auto p = getplanet(ship.storbits, ship.pnumorbits);
129 const auto sect = getsector(p, ship.land_x, ship.land_y);
130 return (2 * Defensedata[sect.condition]);
136 bool laser_on(
const Ship &ship) {
return (ship.laser && ship.fire_laser); }
139 return (ship.whatdest == ScopeLevel::LEVEL_PLAN && ship.docked);
143 Shiplist shiplist(ship.ships);
144 for (
auto s : shiplist) {
146 s.owner = ship.owner;
147 s.governor = ship.governor;
149 g.out << ship_to_string(s) <<
" CAPTURED!\n";
154 return str(boost::format(
"%c%lu %s [%d]") % Shipltrs[s.type] % s.number %
169 return (std::floor(size));
175 factor += (
double)Shipdata[s.build_type][ABIL_COST];
176 factor +=
GUN_COST * (
double)s.primary;
177 factor +=
GUN_COST * (
double)s.secondary;
178 factor +=
CREW_COST * (
double)s.max_crew;
179 factor +=
CARGO_COST * (
double)s.max_resource;
180 factor +=
FUEL_COST * (
double)s.max_fuel;
181 factor +=
AMMO_COST * (
double)s.max_destruct;
183 SPEED_COST * (
double)s.max_speed * (
double)sqrt((
double)s.max_speed);
185 factor +=
ARMOR_COST * (
double)s.armor * (
double)sqrt((
double)s.armor);
186 factor +=
CEW_COST * (
double)(s.cew * s.cew_range);
189 double advantage = 0.0;
190 advantage += 0.5 * !!s.hyper_drive.has;
191 advantage += 0.5 * !!s.laser;
192 advantage += 0.5 * !!s.cloak;
193 advantage += 0.5 * !!s.mount;
195 factor *= sqrt(1.0 + advantage);
200 void system_cost(
double *advantage,
double *disadvantage,
int value,
int base) {
203 factor = (((
double)value + 1.0) / (base + 1.0)) - 1.0;
205 *advantage += factor;
207 *disadvantage -= factor;
212 double advantage = 0.;
213 double disadvantage = 0.;
216 Shipdata[s.build_type][ABIL_GUNS]
);
218 Shipdata[s.build_type][ABIL_GUNS]
);
220 Shipdata[s.build_type][ABIL_MAXCREW]
);
222 Shipdata[s.build_type][ABIL_CARGO]
);
224 Shipdata[s.build_type][ABIL_FUELCAP]
);
226 Shipdata[s.build_type][ABIL_DESTCAP]
);
228 Shipdata[s.build_type][ABIL_SPEED]
);
230 Shipdata[s.build_type][ABIL_HANGER]
);
232 Shipdata[s.build_type][ABIL_ARMOR]
);
236 double factor = sqrt((1.0 + advantage) * exp(-(
double)disadvantage / 10.0));
238 sqrt((
double)(Shipdata[s.build_type][ABIL_TECH] + 1)) +
241 return (factor * (
double)Shipdata[s.build_type][ABIL_TECH]);
unsigned short speed_rating(const Ship &s)
population_t max_crew(const Ship &s)
bool can_navigate(const Ship &s)
long max_speed(const Ship &s)
unsigned long armor(const Ship &s)
bool laser_on(const Ship &ship)
bool can_bombard(const Ship &s)
bool has_switch(const Ship &s)
std::string ship_to_string(const Ship &s)
long hanger(const Ship &s)
int shipbody(const Ship &s)
int getdefense(const Ship &ship)
population_t max_mil(const Ship &s)
#define COMPLEXITY_FACTOR
unsigned int ship_size(const Ship &s)
long repair(const Ship &s)
long shipcost(const Ship &s)
long max_resource(const Ship &s)
long shipsight(const Ship &s)
void system_cost(double *advantage, double *disadvantage, int value, int base)
int max_crystals(const Ship &)
bool can_aim(const Ship &s)
double complexity(const Ship &s)
long retaliate(const Ship &s)
long max_destruct(const Ship &s)
double getmass(const Ship &s)
double mass(const Ship &s)
void capture_stuff(const Ship &ship, GameObj &g)
bool landed(const Ship &ship)
long max_fuel(const Ship &s)
double cost(const Ship &s)