Skip to content

Commit 1790b17

Browse files
authored
Merge pull request #333 from TheStarport/milo/CargoDrop
Adjust cargo drop to allow server owners to specify as many 'hull' drop commodities as they like on player death.
2 parents 421e2a7 + a2005fa commit 1790b17

File tree

3 files changed

+47
-41
lines changed

3 files changed

+47
-41
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 4.0.5
4+
5+
- Changed CargoDrop plugin to accept more than two commodities, amount of Hull drops now calculcated by mass rather than ship hold size.
6+
37
## 4.0.4
48

59
- Update autobuy to cover miscellaneous ammo types if they are present (HP_GUN).

plugins/cargo_drop/CargoDrop.cpp

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
* @author Cannon (Ported by Raikkonen 2022)
44
* @defgroup CargoDrop Cargo Drop
55
* @brief
6-
* The "Cargo Drop" plugin handles consequences to a player who disconnects whilst in space.
6+
* The "Cargo Drop" plugin handles consequences for a player who disconnects whilst in space and allows servers to ensure that cargo items are dropped on player
7+
* death rather than lost. Is also allows server owners to set additional commodities that are spawned as loot when a player ship dies based on hull mass (i.e.
8+
* salvage).
79
*
810
* @paragraph cmds Player Commands
911
* There are no player commands in this plugin.
@@ -17,8 +19,7 @@
1719
* "cargoDropContainer": "lootcrate_ast_loot_metal",
1820
* "disconnectMsg": "%player is attempting to engage cloaking device",
1921
* "disconnectingPlayersRange": 5000.0,
20-
* "hullDrop1NickName": "commodity_super_alloys",
21-
* "hullDrop2NickName": "commodity_engine_components",
22+
* "playerOnDeathCargo": ["commodity_super_alloys", "commodity_engine_components"]
2223
* "hullDropFactor": 0.1,
2324
* "killDisconnectingPlayers": true,
2425
* "lootDisconnectingPlayers": true,
@@ -44,12 +45,15 @@ namespace Plugins::CargoDrop
4445
void LoadSettings()
4546
{
4647
auto config = Serializer::JsonToObject<Config>();
47-
global->cargoDropContainerId = CreateID(config.cargoDropContainer.c_str());
48-
global->hullDrop1NickNameId = CreateID(config.hullDrop1NickName.c_str());
49-
global->hullDrop2NickNameId = CreateID(config.hullDrop2NickName.c_str());
48+
for (const auto& cargo : config.playerOnDeathCargo)
49+
{
50+
global->playerOnDeathCargo.push_back(CreateID(cargo.c_str()));
51+
}
5052

5153
for (const auto& noLootItem : config.noLootItems)
54+
{
5255
global->noLootItemsIds.push_back(CreateID(noLootItem.c_str()));
56+
}
5357

5458
global->config = std::make_unique<Config>(config);
5559
}
@@ -141,45 +145,46 @@ namespace Plugins::CargoDrop
141145
void SendDeathMsg([[maybe_unused]] const std::wstring& message, const SystemId& system, ClientId& clientVictim, ClientId& clientKiller)
142146
{
143147
// If player ship loot dropping is enabled then check for a loot drop.
144-
if (global->config->hullDropFactor == 0.0f)
148+
149+
if (global->config->hullDropFactor == 0.0f || !global->config->enablePlayerCargoDropOnDeath)
150+
{
145151
return;
152+
}
146153

147154
int remainingHoldSize;
148155
auto cargo = Hk::Player::EnumCargo(clientVictim, remainingHoldSize);
149156
if (cargo.has_error())
157+
{
150158
return;
159+
}
151160

152-
uint ship = Hk::Player::GetShip(clientVictim).value();
153-
auto [position, _] = Hk::Solar::GetLocation(ship, IdType::Ship).value();
161+
auto ship = Archetype::GetShip(Hk::Player::GetShipID(clientVictim).value());
162+
auto [position, _] = Hk::Solar::GetLocation(Hk::Player::GetShip(clientVictim).value(), IdType::Ship).value();
154163
position.x += 30.0f;
155164

156-
int shipSizeEstimate = remainingHoldSize;
157-
if (global->config->enablePlayerCargoDropOnDeath)
165+
for (const auto& [iId, count, archId, status, mission, mounted, hardpoint] : cargo.value())
158166
{
159-
for (const auto& [iId, count, archId, status, mission, mounted, hardpoint] : cargo.value())
167+
if (!mounted && !mission && std::ranges::find(global->noLootItemsIds, archId) == global->noLootItemsIds.end())
160168
{
161-
if (!mounted)
162-
{
163-
shipSizeEstimate += count;
164-
if (!mission && std::ranges::find(global->noLootItemsIds, archId) == global->noLootItemsIds.end())
165-
Server.MineAsteroid(
166-
system, position, global->cargoDropContainerId, archId, std::min(count, global->config->maxPlayerCargoDropCount), clientKiller);
167-
}
169+
Server.MineAsteroid(
170+
system, position, global->cargoDropContainerId, archId, std::min(count, global->config->maxPlayerCargoDropCount), clientKiller);
168171
}
169172
}
170-
if (const auto hullDrop = static_cast<int>(global->config->hullDropFactor * static_cast<float>(shipSizeEstimate)); hullDrop > 0)
173+
174+
if (const auto hullDropTotal = int(global->config->hullDropFactor * float(ship->fMass)); hullDropTotal > 0)
171175
{
172-
if (FLHookConfig::i()->general.debugMode)
173-
Console::ConInfo(std::format("Cargo drop in system {:#X} at {:.2f}, {:.2f}, {:.2f} for ship size of shipSizeEst={} iHullDrop={}\n",
174-
system,
175-
position.x,
176-
position.y,
177-
position.z,
178-
shipSizeEstimate,
179-
hullDrop));
180-
181-
Server.MineAsteroid(system, position, global->cargoDropContainerId, global->hullDrop1NickNameId, hullDrop, clientKiller);
182-
Server.MineAsteroid(system, position, global->cargoDropContainerId, global->hullDrop2NickNameId, static_cast<int>(0.5 * hullDrop), clientKiller);
176+
Console::ConDebug(std::format("Cargo drop in system {:#X} at {:.2f}, {:.2f}, {:.2f} for ship size of shipMass={} iHullDrop={}\n",
177+
system,
178+
position.x,
179+
position.y,
180+
position.z,
181+
ship->fMass,
182+
hullDropTotal));
183+
184+
for (const auto& playerCargo : global->playerOnDeathCargo)
185+
{
186+
Server.MineAsteroid(system, position, global->cargoDropContainerId, playerCargo, int(hullDropTotal), clientKiller);
187+
}
183188
}
184189
}
185190

@@ -206,8 +211,8 @@ namespace Plugins::CargoDrop
206211

207212
using namespace Plugins::CargoDrop;
208213
REFL_AUTO(type(Config), field(reportDisconnectingPlayers), field(killDisconnectingPlayers), field(lootDisconnectingPlayers), field(disconnectingPlayersRange),
209-
field(hullDropFactor), field(disconnectMsg), field(cargoDropContainer), field(hullDrop1NickName), field(hullDrop2NickName), field(noLootItems),
210-
field(enablePlayerCargoDropOnDeath), field(maxPlayerCargoDropCount))
214+
field(hullDropFactor), field(disconnectMsg), field(cargoDropContainer), field(playerOnDeathCargo), field(noLootItems), field(enablePlayerCargoDropOnDeath),
215+
field(maxPlayerCargoDropCount))
211216

212217
DefaultDllMainSettings(LoadSettings);
213218

plugins/cargo_drop/CargoDrop.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,14 @@ namespace Plugins::CargoDrop
3636
int maxPlayerCargoDropCount = 3000;
3737
//! Distance used to decide if report/player death should occur based on proximity to other players.
3838
float disconnectingPlayersRange = 5000.0f;
39-
//! Ratio of ship's unused cargo space to 'ship parts' commodities left behind on death, specified in hullDrop1NickName and hullDrop2NickName.
39+
//! Ratio of ship's mass space to 'ship parts' commodities left behind on death, specified in playerOnDeathCargo. The number of items dropped of each type is equal to ship mass multiplied by hullDropFactor.
4040
float hullDropFactor = 0.1f;
4141
//! Message broadcasted to nearby players upon disconnect if reportDisconnectingPlayers is true.
4242
std::string disconnectMsg = "%player is attempting to engage cloaking device";
4343
//! Nickname of loot container model containing cargo/ship parts left behind upon death/disconnection.
4444
std::string cargoDropContainer = "lootcrate_ast_loot_metal";
45-
//! Ship parts commodity left behind on death if hullDropFactor is above zero.
46-
std::string hullDrop1NickName = "commodity_super_alloys";
47-
//! Ship parts commodity left behind on death if hullDropFactor is above zero.
48-
std::string hullDrop2NickName = "commodity_engine_components";
45+
//! Contains a list of nicknames of items that will always be dropped into space when a player is destroyed if hullDropFactor is above zero.
46+
std::vector<std::string> playerOnDeathCargo = {"commodity_super_alloys", "commodity_engine_components"};
4947
//! Contains a list of nicknames of items that will not be dropped into space under any circumstances.
5048
std::vector<std::string> noLootItems = {};
5149
};
@@ -61,9 +59,8 @@ namespace Plugins::CargoDrop
6159
std::map<uint, Info> info;
6260
//! The id of the container to drop
6361
uint cargoDropContainerId;
64-
//! These two ids are commodities to represent the ship after destruction
65-
uint hullDrop1NickNameId;
66-
uint hullDrop2NickNameId;
62+
//! This id is for commodities to represent the ship after destruction
63+
std::vector<uint> playerOnDeathCargo;
6764
//! Items we don't want to be looted
6865
std::vector<uint> noLootItemsIds;
6966
};

0 commit comments

Comments
 (0)