Skip to content

Commit

Permalink
Irateredkite/solar ipc interface fixes (#425)
Browse files Browse the repository at this point in the history
* fix: Change how solar formations are fetched and ensured that CreateUserDefinedSolarFormation() returns a uint so objects spawned by this function can be properly tracked by other plugins using the IPC interface

* chore: Update changelog.md

* chore: Remove TODO comments
  • Loading branch information
IrateRedKite authored Jun 17, 2024
1 parent 551f449 commit 69c0e9c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 4.0.32
- Properly expose data for CreateUserDefinedSolarFormation() so objects spawned this way can be tracked by other plugins.

## 4.0.31
- Fixed a case in Advanced Startup Solars where randomly placed solars could occupy the same position

Expand Down
24 changes: 21 additions & 3 deletions plugins/solar_control/SolarControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,18 +359,36 @@ namespace Plugins::SolarControl
/** @ingroup SolarControl
* @brief Creates a premade group of solars defined in the solar json file
*/
void CreateUserDefinedSolarFormation(const std::wstring& formation, const Vector& position, uint system)
std::vector<uint> CreateUserDefinedSolarFormation(const std::wstring& formation, const Vector& position, uint system)
{
for (auto component : global->config->solarArchFormations[formation].components)
std::vector<uint> formationSpaceIds;

auto group = global->config->solarArchFormations.find(formation);

if (group == global->config->solarArchFormations.end())
{
Console::ConErr(std::format("Unable to find {} while attempting to spawn user defined formation", wstos(formation)));
return {};
}

for (auto& component : group->second.components)
{
CreateUserDefinedSolar(stows(component.solarArchName),
if (component.relativePosition.size() != 3 || component.rotation.size() != 3)
{
Console::ConErr(std::format("Invalid rotation or coordinate values provided for '{}', failed to create", component.solarArchName));
return {};
}

auto solar = CreateUserDefinedSolar(stows(component.solarArchName),
Vector {
{position.x + component.relativePosition[0]}, {position.y + component.relativePosition[1]}, {position.z + component.relativePosition[2]}},
EulerMatrix(Vector {component.rotation[0], component.rotation[1], component.rotation[2]}),
system,
false,
false);
formationSpaceIds.emplace_back(solar);
}
return formationSpaceIds;
}

/** @ingroup SolarControl
Expand Down
2 changes: 1 addition & 1 deletion plugins/solar_control/SolarControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace Plugins::SolarControl
explicit SolarCommunicator(const std::string& plug);

uint PluginCall(CreateSolar, const std::wstring& name, Vector position, const Matrix& rotation, SystemId system, bool varyPosition, bool mission);
void PluginCall(CreateSolarFormation, const std::wstring& formation, const Vector& position, uint system);
std::vector<uint> PluginCall(CreateSolarFormation, const std::wstring& formation, const Vector& position, uint system);
};

//! Global data for this plugin
Expand Down

0 comments on commit 69c0e9c

Please sign in to comment.