Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ECM crime - Don't use your ECM near a station #5916

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions data/lang/ui-core/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2463,6 +2463,10 @@
"description": "",
"message": "Unlawful weapons discharge"
},
"UNLAWFUL_ECM_DISCHARGE": {
"description": "",
"message": "Unlawful ECM discharge"
},
"UNOCCUPIED_PASSENGER_CABINS": {
"description": "",
"message": "Unoccupied Passenger Cabins"
Expand Down
2 changes: 2 additions & 0 deletions data/libs/Legal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ local l = Lang.GetResource("ui-core")
-- PIRACY - fired on ship
-- TRADING_ILLEGAL_GOODS - attempted to sell illegal goods
-- WEAPONS_DISCHARGE - weapons discharged too close to station
-- ECM_DISCHARGE - ECM discharged too close to station
--
-- Availability:
--
Expand All @@ -41,6 +42,7 @@ Legal.CrimeType["MURDER"] = {basefine = 1.5e6, name = l.MURDER}
Legal.CrimeType["PIRACY"] = {basefine = 1e5, name = l.PIRACY}
Legal.CrimeType["TRADING_ILLEGAL_GOODS"] = {basefine = 5e3, name = l.TRADING_ILLEGAL_GOODS}
Legal.CrimeType["WEAPONS_DISCHARGE"] = {basefine = 5e2, name = l.UNLAWFUL_WEAPONS_DISCHARGE}
Legal.CrimeType["ECM_DISCHARGE"] = {basefine = 5e2, name = l.UNLAWFUL_ECM_DISCHARGE}
Legal.CrimeType["CONTRACT_FRAUD"] = {basefine = 5e2, name = l.CONTRACT_FRAUD}


Expand Down
8 changes: 8 additions & 0 deletions data/modules/CrimeTracking/CrimeTracking.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ local onShipFiring = function(ship)
end


local onUseECM = function(ship)
if ship:IsPlayer() then
Legal:notifyOfCrime(ship,"ECM_DISCHARGE")
end
end


local onLeaveSystem = function(ship)
if not ship:IsPlayer() then return end
-- if we leave the system, the space station object will be invalid
Expand All @@ -121,6 +128,7 @@ end
Event.Register("onShipHit", onShipHit)
Event.Register("onShipDestroyed", onShipDestroyed)
Event.Register("onShipFiring", onShipFiring)
Event.Register("onUseECM", onUseECM)
Event.Register("onJettison", onJettison)
Event.Register("onGameStart", onGameStart)
Event.Register("onGameEnd", onGameEnd)
Expand Down
17 changes: 11 additions & 6 deletions src/Ship.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,15 +800,20 @@ Ship::ECMResult Ship::UseECM()
Space::BodyNearList nearby = Pi::game->GetSpace()->GetBodiesMaybeNear(this, ECM_RADIUS);
for (Body *body : nearby) {
if (body->GetFrame() != GetFrame()) continue;
if (!body->IsType(ObjectType::MISSILE)) continue;

double dist = (body->GetPosition() - GetPosition()).Length();
if (dist < ECM_RADIUS) {
// increasing chance of destroying it with proximity
if (Pi::rng.Double() > (dist / ECM_RADIUS)) {
static_cast<Missile *>(body)->ECMAttack(ecm_power_cap);
if (body->IsType(ObjectType::MISSILE)) {
double dist = (body->GetPosition() - GetPosition()).Length();
if (dist < ECM_RADIUS) {
// increasing chance of destroying it with proximity
if (Pi::rng.Double() > (dist / ECM_RADIUS)) {
static_cast<Missile *>(body)->ECMAttack(ecm_power_cap);
}
}
}
else if (body->IsType(ObjectType::SPACESTATION)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little hesitant about this check here and the associated event naming. This seems a bit brittle, and the onUseECM name doesn't really match what's happening here.

LuaEvent::Queue("onUseECM", this);
}
else { continue; }
}
return ECM_ACTIVATED;
} else
Expand Down