Skip to content

Commit

Permalink
Merge branch 'master' into task_clean_ships
Browse files Browse the repository at this point in the history
  • Loading branch information
royfalk authored Nov 21, 2024
2 parents 40281f3 + 12c034a commit 1105774
Show file tree
Hide file tree
Showing 36 changed files with 679 additions and 322 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
68 changes: 27 additions & 41 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 @@ -849,21 +846,10 @@ void Unit::LoadRow(std::string unit_identifier, string modification, bool saved_
// 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 @@ -873,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 @@ -887,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 @@ -969,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 @@ -1268,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 Down Expand Up @@ -1370,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 @@ -1392,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
2 changes: 0 additions & 2 deletions engine/src/cmd/unit_csv_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
#include <boost/algorithm/string.hpp>
#include <iostream>

#include "vsfilesystem.h"

const std::string keys[] = {"Key", "Directory", "Name", "Object_Type",
"Combat_Role", "Textual_Description", "Hud_image", "Unit_Scale", "Cockpit",
"CockpitX", "CockpitY", "CockpitZ", "Mesh", "Shield_Mesh",
Expand Down
12 changes: 3 additions & 9 deletions engine/src/cmd/unit_generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1267,14 +1267,14 @@ void Unit::DamageRandSys(float dam, const Vector &vec, float randnum, float degr

switch(dist20(rng)) {
case 0: fuel.Damage(); break; // Fuel
case 1: energy.Damage(); break; // Energy
case 1: energy.Damage(); break; // Energy
case 2: ftl_energy.Damage(); break;
case 3: ftl_drive.Damage(); break;
case 4: jump_drive.Damage(); break;
case 5: this->afterburnenergy += ((1 - dam) * reactor.Capacity()); break;
case 6: CargoVolume *= dam; break;
case 7: UpgradeVolume *= dam; break;
case 8:
case 8:
//Do something NASTY to the cargo
if (cargo.size() > 0) {
unsigned int i = 0;
Expand Down Expand Up @@ -3073,12 +3073,6 @@ bool Unit::UpAndDownGrade(const Unit *up,
if (!csv_cell_null_check || force_change_on_nothing
|| cell_has_recursive_data(upgrade_name, up->faction, "ECM_Rating"))
STDUPGRADE(ecm, up->ecm, templ->ecm, 0); //ecm is unsigned --chuck_starchaser
/*if (!csv_cell_null_check || force_change_on_nothing
|| cell_has_recursive_data(upgrade_name, up->faction, "Primary_Capacitor")) {
temporary_upgrade_float_variable = static_cast<float>(energy.MaxValue());
STDUPGRADE(temporary_upgrade_float_variable, up->energy.MaxValue(), templ->energy.MaxValue(), 0);
energy.SetMaxValue(temporary_upgrade_float_variable);
}*/
}
//Maneuvering stuff
if (!csv_cell_null_check || force_change_on_nothing
Expand Down Expand Up @@ -4266,7 +4260,7 @@ void Unit::UpdatePhysics3(const Transformation &trans,
ActTurn();

static CloakingStatus previous_status = cloak.status;
cloak.Update(this);
cloak.Update();

// Play once per cloaking
if(cloak.Cloaking() && previous_status != CloakingStatus::cloaking) {
Expand Down
6 changes: 3 additions & 3 deletions engine/src/cmd/unit_generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ class Unit : public Armed, public Audible, public Drawable, public Damageable, p

public:
// Components
EnergyContainer fuel = EnergyContainer(EnergyType::Fuel);
EnergyContainer energy = EnergyContainer(EnergyType::Energy);
EnergyContainer ftl_energy = EnergyContainer(EnergyType::FTL);
EnergyContainer fuel = EnergyContainer(ComponentType::Fuel);
EnergyContainer energy = EnergyContainer(ComponentType::Capacitor);
EnergyContainer ftl_energy = EnergyContainer(ComponentType::FtlCapacitor);

// TODO: move this to a single constructor?!
Reactor reactor = Reactor(&fuel, &energy, &ftl_energy);
Expand Down
3 changes: 2 additions & 1 deletion engine/src/cmd/unit_xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ using namespace XMLSupport;

/*ADDED FOR extensible use of unit pretty print and unit load */
UNITLOADTYPE current_unit_load_mode = DEFAULT;
extern float getFuelConversion();

string KillQuadZeros(string inp) {
std::string::size_type text = 0;
Expand Down Expand Up @@ -115,6 +114,8 @@ string MakeUnitXMLPretty(string str, Unit *un) {
return writestr;
}

// TODO: delete this at some point.
// We no longer support add/mul modes of upgrades
int GetModeFromName(const char *input_buffer) {
if (strlen(input_buffer) > 3) {
if (input_buffer[0] == 'a'
Expand Down
Loading

0 comments on commit 1105774

Please sign in to comment.