Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
royfalk committed Nov 21, 2024
2 parents bd42430 + 47eefd0 commit 4f72ce2
Show file tree
Hide file tree
Showing 40 changed files with 773 additions and 382 deletions.
2 changes: 2 additions & 0 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ SET(LIBPYTHON

SET(LIBCOMPONENT
src/components/component.cpp
src/components/component_utils

src/components/energy_consumer.cpp
src/components/energy_container.cpp
Expand Down Expand Up @@ -1757,6 +1758,7 @@ IF (USE_GTEST)

ADD_LIBRARY(vegastrike-testing
${LIBPYTHON}
${LIBVS_LOGGING}
${LIBCONFIG}
${LIBDAMAGE}
${LIBRESOURCE}
Expand Down
35 changes: 4 additions & 31 deletions engine/src/cmd/basecomputer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ using VSFileSystem::SaveFile;
#include "python/base_computer/ship_view.h"


//#define VS_PI 3.1415926535897931


//for directory thing
#if defined (_WIN32) && !defined (__CYGWIN__)
Expand Down Expand Up @@ -2024,6 +2022,7 @@ void BaseComputer::updateTransactionControlsForSelection(TransactionList *tlist)
}
}
//Description.
// TODO: this adds the description to the price. We should move everything to component.
descString += item.GetDescription();
descString += tailString;

Expand Down Expand Up @@ -5006,7 +5005,7 @@ void showUnitStats(Unit *playerUnit, string &text, int subunitlevel, int mode, C
switch (replacement_mode) {
case 0: //Replacement or new Module
if (MODIFIES_ALTEMPTY(replacement_mode, &uc, &buc, radar.maxrange, FLT_MAX)
|| MODIFIES_ALTEMPTY(replacement_mode, &uc, &buc, radar.maxcone, VS_PI)) {
|| MODIFIES_ALTEMPTY(replacement_mode, &uc, &buc, radar.maxcone, M_PI)) {
PRETTY_ADDU(statcolor + "Tracking range: #-c", uc.radar.maxrange / 1000, 0, "km");
if ((acos(uc.radar.maxcone) * 360 / PI) < 359) {
PRETTY_ADDU(statcolor + "Tracking cone: #-c", acos(uc.radar.maxcone) * 2, 2, "radians");
Expand Down Expand Up @@ -5060,40 +5059,14 @@ void showUnitStats(Unit *playerUnit, string &text, int subunitlevel, int mode, C
if (MODIFIES(replacement_mode, playerUnit, blankUnit, maxEnergyData()))
PRETTY_ADDU(statcolor + "Installs main capacitor bank with storage capacity: #-c",
(playerUnit->maxEnergyData() * RSconverter), 0, "MJ");
if (MODIFIES(replacement_mode, playerUnit, blankUnit, getWarpEnergy()))
if (MODIFIES(replacement_mode, playerUnit, blankUnit, ftl_energy.MaxLevel()))
PRETTY_ADDU(statcolor + "Installs warp capacitor bank with storage capacity: #-c",
playerUnit->getWarpEnergy() * RSconverter * Wconv, 0, "MJ");
playerUnit->ftl_energy.MaxLevel() * RSconverter * Wconv, 0, "MJ");
if (buj.Installed() && !uj.Installed()) {
text += statcolor +
"#n#Allows travel via Jump Points.#n#Consult your personal info screen for ship specific energy requirements. #-c";
}
break;
case 1: //Additive
if (MODIFIES(replacement_mode, playerUnit, blankUnit, reactor.Capacity()))
PRETTY_ADDU(statcolor + "Increases recharge rate by #-c",
playerUnit->reactor.Capacity() * RSconverter, 0, "MJ/s");
if (MODIFIES(replacement_mode, playerUnit, blankUnit, maxEnergyData()))
PRETTY_ADDU(statcolor + "Adds #-c",
(playerUnit->maxEnergyData() * RSconverter),
0,
"MJ of storage to main capacitor banks");
if (MODIFIES(replacement_mode, playerUnit, blankUnit, getWarpEnergy()))
PRETTY_ADDU(statcolor + "Adds #-c",
playerUnit->getWarpEnergy() * RSconverter * Wconv,
0,
"MJ of storage to warp capacitor bank");
break;
case 2: //multiplicative
if (MODIFIES(replacement_mode, playerUnit, blankUnit, reactor.Capacity()))
PRETTY_ADDU(statcolor + "Increases reactor recharge rate by #-c",
100.0 * (playerUnit->reactor.Capacity() - 1), 0, "%");
if (MODIFIES(replacement_mode, playerUnit, blankUnit, maxEnergyData()))
PRETTY_ADDU(statcolor + "Increases main capacitor bank storage by #-c",
100.0 * (playerUnit->maxEnergyData() - 1), 0, "%");
if (MODIFIES(replacement_mode, playerUnit, blankUnit, getWarpEnergy()))
PRETTY_ADDU(statcolor + "Increases warp capacitor bank storage by #-c",
(playerUnit->getWarpEnergy() - 1) * 100, 0, "%");
break;
default: //Failure
text += "Oh dear, this wasn't an upgrade. Please debug code.";
break;
Expand Down
3 changes: 1 addition & 2 deletions engine/src/cmd/jump_capable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,7 @@ bool JumpCapable::AutoPilotToErrorMessage(const Unit *target,
failuremessage = configuration()->graphics_config.hud.already_near_message;
return false;
}
unit->ftl_energy.Deplete(true, static_cast<double>(totpercent) * unit->ftl_drive.GetAtomConsumption());
// TODO: figure out to do unit->ftl_drive.Consume() instead

if (unsafe == false && totpercent == 0) {
end = endne;
}
Expand Down
2 changes: 1 addition & 1 deletion engine/src/cmd/planet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ void Planet::InitPlanet(QVector x,
VSSprite *tmp = pImage->pHudImage;
pImage->pHudImage = un->GetImageInformation().pHudImage;
un->GetImageInformation().pHudImage = tmp;
ftl_energy.SetCapacity(un->warpCapData());
ftl_energy.SetCapacity(un->ftl_energy.MaxLevel());
if (smartplanets) {
SubUnits.prepend(un);
un->SetRecursiveOwner(this);
Expand Down
169 changes: 91 additions & 78 deletions engine/src/cmd/unit_csv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ static vector<SubUnitStruct> GetSubUnits(const std::string &subunits) {
Q.i = nextElementFloat(subunits, elemstart, elemend);
Q.j = nextElementFloat(subunits, elemstart, elemend);
Q.k = nextElementFloat(subunits, elemstart, elemend);
double restricted = cos(nextElementFloat(subunits, elemstart, elemend, 180) * VS_PI / 180.0);
double restricted = cos(nextElementFloat(subunits, elemstart, elemend, 180) * M_PI / 180.0);

ret.push_back(SubUnitStruct(filename, pos, Q, R, restricted));
} else {
Expand Down Expand Up @@ -609,9 +609,6 @@ void LoadCockpit(Unit *thus, const string &cockpit) {
thus->pImage->CockpitCenter.k = nextElementFloat(cockpit, elemstart, elemend);
}

float getFuelConversion() {
return configuration()->fuel.fuel_conversion;
}

const std::string EMPTY_STRING("");

Expand All @@ -624,8 +621,8 @@ void YawPitchRollParser(std::string unit_key,
float main_value = UnitCSVFactory::GetVariable(unit_key, main_string, 0.0f);
float right_value = UnitCSVFactory::GetVariable(unit_key, right_string, 0.0f);
float left_value = UnitCSVFactory::GetVariable(unit_key, left_string, 0.0f);
right_pointer = (right_value > 0 ? right_value : main_value) * VS_PI / 180.;
left_pointer = (left_value > 0 ? left_value : main_value) * VS_PI / 180.;
right_pointer = (right_value > 0 ? right_value : main_value) * M_PI / 180.;
left_pointer = (left_value > 0 ? left_value : main_value) * M_PI / 180.;
}

void Unit::LoadRow(std::string unit_identifier, string modification, bool saved_game) {
Expand Down Expand Up @@ -738,7 +735,7 @@ void Unit::LoadRow(std::string unit_identifier, string modification, bool saved_
pImage->CockpitCenter.j = UnitCSVFactory::GetVariable(unit_key, "CockpitY", 0.0f) * xml.unitscale;
pImage->CockpitCenter.k = UnitCSVFactory::GetVariable(unit_key, "CockpitZ", 0.0f) * xml.unitscale;
Mass = UnitCSVFactory::GetVariable(unit_key, "Mass", 1.0f);
Momentofinertia = UnitCSVFactory::GetVariable(unit_key, "Moment_Of_Inertia", 1.0f);
Momentofinertia = Mass;


// Hull
Expand All @@ -749,14 +746,28 @@ void Unit::LoadRow(std::string unit_identifier, string modification, bool saved_
specInterdiction = UnitCSVFactory::GetVariable(unit_key, "Spec_Interdiction", 0.0f);

// Init armor
std::string armor_keys[] = {"Armor_Front_Top_Left", "Armor_Front_Top_Right",
// We support 2 options:
// 1. armor = x. Could be 0, 40, etc. This populaes the 8 facets below
// 2. armor = "". Use the old method of reading all 8 facets.
const std::string armor_single_value_string = UnitCSVFactory::GetVariable(unit_key, "armor", std::string());
float armor_values[8];

if(armor_single_value_string != "") {
int armor_single_value = std::stoi(armor_single_value_string, 0);

for (int i = 0; i < 8; i++) {
armor_values[i] = armor_single_value;
}
} else {
std::string armor_keys[] = {"Armor_Front_Top_Left", "Armor_Front_Top_Right",
"Armor_Front_Bottom_Left", "Armor_Front_Bottom_Right",
"Armor_Back_Top_Left", "Armor_Back_Top_Right",
"Armor_Back_Bottom_Left", "Armor_Back_Bottom_Right"};
float armor_values[8];
for (int i = 0; i < 8; i++) {
float tmp_armor_value = UnitCSVFactory::GetVariable(unit_key, armor_keys[i], 0.0f);
armor_values[i] = tmp_armor_value;

for (int i = 0; i < 8; i++) {
float tmp_armor_value = UnitCSVFactory::GetVariable(unit_key, armor_keys[i], 0.0f);
armor_values[i] = tmp_armor_value;
}
}

armor->UpdateFacets(8, armor_values);
Expand All @@ -776,66 +787,69 @@ void Unit::LoadRow(std::string unit_identifier, string modification, bool saved_
//float efficiency = UnitCSVFactory::GetVariable(unit_key, "Shield_Efficiency", 1.0f );

// Get shield count

int shield_count = 0;
float shield_values[4];
std::string shield_string_values[4];
std::vector<string> shield_sections;

const std::string shield_strength_string = UnitCSVFactory::GetVariable(unit_key, "shield_strength", std::string());
const std::string shield_facets_string = UnitCSVFactory::GetVariable(unit_key, "shield_facets", std::string());

if(shield_strength_string != "" && shield_facets_string != "") {
int shield_strength = std::stoi(shield_strength_string);
int shield_facets = std::stoi(shield_facets_string);
shield->number_of_facets = shield_facets;
shield->UpdateFacets(shield_strength);
} else {
int shield_count = 0;
float shield_values[4];


// TODO: this mapping should really go away
// I love macros, NOT.
shield_string_values[0] = UnitCSVFactory::GetVariable(unit_key, "Shield_Front_Top_Right", std::string());
shield_string_values[1] = UnitCSVFactory::GetVariable(unit_key, "Shield_Back_Top_Left", std::string());
shield_string_values[2] = UnitCSVFactory::GetVariable(unit_key, "Shield_Front_Bottom_Right", std::string());
shield_string_values[3] = UnitCSVFactory::GetVariable(unit_key, "Shield_Front_Bottom_Left", std::string());
// TODO: this mapping should really go away
// I love macros, NOT.
shield_string_values[0] = UnitCSVFactory::GetVariable(unit_key, "Shield_Front_Top_Right", std::string());
shield_string_values[1] = UnitCSVFactory::GetVariable(unit_key, "Shield_Back_Top_Left", std::string());
shield_string_values[2] = UnitCSVFactory::GetVariable(unit_key, "Shield_Front_Bottom_Right", std::string());
shield_string_values[3] = UnitCSVFactory::GetVariable(unit_key, "Shield_Front_Bottom_Left", std::string());

for (int i = 0; i < 4; i++) {
shield_values[i] = 0.0f;
for (int i = 0; i < 4; i++) {
shield_values[i] = 0.0f;

if (shield_string_values[i].empty()) {
continue;
}

if (shield_string_values[i].empty()) {
continue;
shield_values[i] = ::stof(shield_string_values[i]);
// Should add up to the shield type - quad or dual
shield_count++;
}

shield_values[i] = ::stof(shield_string_values[i]);
// Should add up to the shield type - quad or dual
shield_count++;
/*
We are making the following assumptions:
1. The CSV is correct
2. Dual shields are 0 front and 1 rear
3. Quad shields are front (0), rear(1), right(2) and left(3)
4. There is no support for 8 facet shields in the game.
This has more to do with the cockpit code than anything else
5. We map the above index to our own
*/

if (shield_count == 4 || shield_count == 2) {
shield->number_of_facets = shield_count;
shield->UpdateFacets(shield_count, shield_values);
}
}

/*
We are making the following assumptions:
1. The CSV is correct
2. Dual shields are 0 front and 1 rear
3. Quad shields are front (0), rear(1), right(2) and left(3)
4. There is no support for 8 facet shields in the game.
This has more to do with the cockpit code than anything else
5. We map the above index to our own
*/

if (shield_count == 4 || shield_count == 2) {
shield->number_of_facets = shield_count;
shield->UpdateFacets(shield_count, shield_values);
}


// End shield section

// Energy
// TODO: The following code has a bug.
// It will set the max of the component as the current value loaded from the
// CSV. If the component is damaged, this will be lower than the original value.
fuel.SetCapacity(UnitCSVFactory::GetVariable(unit_key, "Fuel_Capacity", 0.0), true);
energy.SetCapacity(UnitCSVFactory::GetVariable(unit_key, "Primary_Capacitor", 0.0), true);
ftl_energy.SetCapacity(UnitCSVFactory::GetVariable(unit_key, "Warp_Capacitor", 0.0), true);
reactor.SetCapacity(UnitCSVFactory::GetVariable(unit_key, "Reactor_Recharge", 0.0));

const bool WCfuelhack = configuration()->fuel.fuel_equals_warp;

if (WCfuelhack) {
ftl_energy.SetCapacity(0);
fuel.SetCapacity(ftl_energy.MaxLevel());
ftl_drive = FtlDrive(&fuel);
jump_drive = JumpDrive(&fuel);
// Add any other component that relies on FTL.
// Especially note the cloaking device support for FTL as an energy source.
}
fuel.Load("", unit_key);
energy.Load("", unit_key);
ftl_energy.Load("", unit_key);
reactor.Load("", unit_key);

// End Energy

Expand All @@ -845,7 +859,7 @@ void Unit::LoadRow(std::string unit_identifier, string modification, bool saved_
// Bleed factor hints at losing energy. However, here, at 2.0 it's a factor
// for reducing warp cost
double ftl_factor = configuration()->warp_config.bleed_factor;
ftl_drive.Load("", unit_key, ftl_factor);
ftl_drive.Load("", unit_key);
jump_drive.Load("", unit_key);


Expand All @@ -859,9 +873,9 @@ void Unit::LoadRow(std::string unit_identifier, string modification, bool saved_
afterburntype = UnitCSVFactory::GetVariable(unit_key,
"Afterburner_Type",
0); //type 1 == "use fuel", type 0 == "use reactor energy", type 2 ==(hopefully) "use jump fuel" 3: NO AFTERBURNER
limits.yaw = UnitCSVFactory::GetVariable(unit_key, "Maneuver_Yaw", 0.0f) * VS_PI / 180.0;
limits.pitch = UnitCSVFactory::GetVariable(unit_key, "Maneuver_Pitch", 0.0f) * VS_PI / 180.0;
limits.roll = UnitCSVFactory::GetVariable(unit_key, "Maneuver_Roll", 0.0f) * VS_PI / 180.0;
limits.yaw = UnitCSVFactory::GetVariable(unit_key, "Maneuver_Yaw", 0.0f) * M_PI / 180.0;
limits.pitch = UnitCSVFactory::GetVariable(unit_key, "Maneuver_Pitch", 0.0f) * M_PI / 180.0;
limits.roll = UnitCSVFactory::GetVariable(unit_key, "Maneuver_Roll", 0.0f) * M_PI / 180.0;

YawPitchRollParser(unit_key,
"Yaw_Governor",
Expand Down Expand Up @@ -941,9 +955,9 @@ void Unit::LoadRow(std::string unit_identifier, string modification, bool saved_
}

computer.radar.maxrange = UnitCSVFactory::GetVariable(unit_key, "Radar_Range", FLT_MAX);
computer.radar.maxcone = cos(UnitCSVFactory::GetVariable(unit_key, "Max_Cone", 180.0f) * VS_PI / 180);
computer.radar.trackingcone = cos(UnitCSVFactory::GetVariable(unit_key, "Tracking_Cone", 180.0f) * VS_PI / 180);
computer.radar.lockcone = cos(UnitCSVFactory::GetVariable(unit_key, "Lock_Cone", 180.0f) * VS_PI / 180);
computer.radar.maxcone = cos(UnitCSVFactory::GetVariable(unit_key, "Max_Cone", 180.0f) * M_PI / 180);
computer.radar.trackingcone = cos(UnitCSVFactory::GetVariable(unit_key, "Tracking_Cone", 180.0f) * M_PI / 180);
computer.radar.lockcone = cos(UnitCSVFactory::GetVariable(unit_key, "Lock_Cone", 180.0f) * M_PI / 180);

const static bool warp_energy_for_cloak = configuration()->warp_config.use_warp_energy_for_cloak;
cloak = Cloak(unit_key, (warp_energy_for_cloak ? &ftl_energy : &energy));
Expand Down Expand Up @@ -1240,7 +1254,7 @@ const std::map<std::string, std::string> Unit::UnitToMap() {
subunits[k].Q.i,
subunits[k].Q.j,
subunits[k].Q.k,
((double) acos(subunits[k].restricted) * 180. / VS_PI));
((double) acos(subunits[k].restricted) * 180. / M_PI));
str += "{" + subunits[k].filename + tmp;
}
unit["Sub_Units"] = str;
Expand All @@ -1266,7 +1280,6 @@ const std::map<std::string, std::string> Unit::UnitToMap() {
unit["Cargo"] = carg;
}
unit["Mass"] = tos(Mass);
unit["Moment_Of_Inertia"] = tos(Momentofinertia);
unit["Fuel_Capacity"] = tos(fuel.Level());
unit["Hull"] = tos(GetHullLayer().facets[0].health);
unit["Spec_Interdiction"] = tos(specInterdiction);
Expand Down Expand Up @@ -1343,15 +1356,15 @@ const std::map<std::string, std::string> Unit::UnitToMap() {
unit["Wormhole"] = tos(forcejump != 0);
unit["Afterburner_Usage_Cost"] = tos(afterburnenergy);
unit["Afterburner_Type"] = tos(afterburntype);
unit["Maneuver_Yaw"] = tos(limits.yaw * 180 / (VS_PI));
unit["Maneuver_Pitch"] = tos(limits.pitch * 180 / (VS_PI));
unit["Maneuver_Roll"] = tos(limits.roll * 180 / (VS_PI));
unit["Yaw_Governor_Right"] = tos(computer.max_yaw_right * 180 / VS_PI);
unit["Yaw_Governor_Left"] = tos(computer.max_yaw_left * 180 / VS_PI);
unit["Pitch_Governor_Up"] = tos(computer.max_pitch_up * 180 / VS_PI);
unit["Pitch_Governor_Down"] = tos(computer.max_pitch_down * 180 / VS_PI);
unit["Roll_Governor_Right"] = tos(computer.max_roll_right * 180 / VS_PI);
unit["Roll_Governor_Left"] = tos(computer.max_roll_left * 180 / VS_PI);
unit["Maneuver_Yaw"] = tos(limits.yaw * 180 / (M_PI));
unit["Maneuver_Pitch"] = tos(limits.pitch * 180 / (M_PI));
unit["Maneuver_Roll"] = tos(limits.roll * 180 / (M_PI));
unit["Yaw_Governor_Right"] = tos(computer.max_yaw_right * 180 / M_PI);
unit["Yaw_Governor_Left"] = tos(computer.max_yaw_left * 180 / M_PI);
unit["Pitch_Governor_Up"] = tos(computer.max_pitch_up * 180 / M_PI);
unit["Pitch_Governor_Down"] = tos(computer.max_pitch_down * 180 / M_PI);
unit["Roll_Governor_Right"] = tos(computer.max_roll_right * 180 / M_PI);
unit["Roll_Governor_Left"] = tos(computer.max_roll_left * 180 / M_PI);
const float game_accel = configuration()->physics_config.game_accel;
const float game_speed = configuration()->physics_config.game_speed;
unit["Afterburner_Accel"] = tos(limits.afterburn / (game_accel * game_speed));
Expand All @@ -1365,9 +1378,9 @@ const std::map<std::string, std::string> Unit::UnitToMap() {
unit["Can_Lock"] = tos(computer.radar.canlock);
unit["Radar_Color"] = std::to_string(computer.radar.capability);
unit["Radar_Range"] = tos(computer.radar.maxrange);
unit["Tracking_Cone"] = tos(acos(computer.radar.trackingcone) * 180. / VS_PI);
unit["Max_Cone"] = tos(acos(computer.radar.maxcone) * 180. / VS_PI);
unit["Lock_Cone"] = tos(acos(computer.radar.lockcone) * 180. / VS_PI);
unit["Tracking_Cone"] = tos(acos(computer.radar.trackingcone) * 180. / M_PI);
unit["Max_Cone"] = tos(acos(computer.radar.maxcone) * 180. / M_PI);
unit["Lock_Cone"] = tos(acos(computer.radar.lockcone) * 180. / M_PI);

cloak.SaveToCSV(unit);
unit["Repair_Droid"] = tos(repair_droid);
Expand Down
Loading

0 comments on commit 4f72ce2

Please sign in to comment.