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

Active modules now typically consume capacitor charge on initial cycle #293

Merged
Changes from 1 commit
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
40 changes: 40 additions & 0 deletions src/eve-server/ship/modules/ActiveModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "StatisticMgr.h"
#include "exploration/Probes.h"
#include "exploration/Scan.h"
#include "inventory/AttributeEnum.h"
#include "ship/Missile.h"
#include "ship/modules/ActiveModule.h"
#include "ship/modules/ModuleItem.h"
Expand Down Expand Up @@ -541,6 +542,30 @@ uint32 ActiveModule::DoCycle()
}
}

// check if ship has sufficient capacitor capacity - if not, abort the cycle
if (m_modRef->HasAttribute(AttrCapacitorNeed)) {
float remainingCapacitorCharge = m_shipRef->GetAttribute(AttrCapacitorCharge).get_float();
float requiredCapacitorCharge = GetAttribute(AttrCapacitorNeed).get_float();

float newCap = remainingCapacitorCharge - requiredCapacitorCharge;

if (newCap < 0) {
m_shipRef->GetPilot()->SendNotifyMsg(
"This module requires %.0f GJ, but your capacitor only has %.0f GJ remaining.",
Copy link

Choose a reason for hiding this comment

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

suggestion: Consider rephrasing the error message to use percentage values

Using percentage values instead of absolute GJ values in the error message could be more intuitive for players who may not be familiar with the unit 'GJ'.

                "This module requires %.1f%% of your capacitor, but you only have %.1f%% remaining.",
                (requiredCapacitorCharge / m_shipRef->GetCapacitorCapacity()) * 100,
                (remainingCapacitorCharge / m_shipRef->GetCapacitorCapacity()) * 100

requiredCapacitorCharge,
remainingCapacitorCharge
);

AbortCycle();

return 0;
}

float shipTotalCapacitor = m_shipRef->GetAttribute(AttrCapacitorCapacity).get_float();

m_shipRef->SetShipCapacitorLevel(newCap / shipTotalCapacitor);
}
Comment on lines +548 to +569
Copy link

Choose a reason for hiding this comment

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

suggestion: Consider extracting the capacitor check logic into a separate method

The capacitor check logic is duplicated in both DoCycle() and CanActivate(). Extracting this into a separate method would improve maintainability and reduce the risk of inconsistencies.

bool CheckCapacitorRequirement() {
    if (!m_modRef->HasAttribute(AttrCapacitorNeed)) return true;

    float remainingCapacitorCharge = m_shipRef->GetAttribute(AttrCapacitorCharge).get_float();
    float requiredCapacitorCharge = GetAttribute(AttrCapacitorNeed).get_float();
    float newCap = remainingCapacitorCharge - requiredCapacitorCharge;

    if (newCap < 0) {
        m_shipRef->GetPilot()->SendNotifyMsg("This module requires %.0f GJ, but your capacitor only has %.0f GJ remaining.", requiredCapacitorCharge, remainingCapacitorCharge);
        return false;
    }

    m_shipRef->SetShipCapacitorLevel(newCap / m_shipRef->GetAttribute(AttrCapacitorCapacity).get_float());
    return true;
}


// not sure if this is entirely accurate...wip
charles-m-knox marked this conversation as resolved.
Show resolved Hide resolved
switch (m_modRef->groupID()) {
case EVEDB::invGroups::Projectile_Weapon:
Expand Down Expand Up @@ -1045,6 +1070,21 @@ bool ActiveModule::CanActivate()
}
}

if (m_modRef->HasAttribute(AttrCapacitorNeed)) {
float remainingCapacitorCharge = m_shipRef->GetAttribute(AttrCapacitorCharge).get_float();
float requiredCapacitorCharge = GetAttribute(AttrCapacitorNeed).get_float();

if (requiredCapacitorCharge > remainingCapacitorCharge) {
m_shipRef->GetPilot()->SendNotifyMsg(
"This module requires %.0f GJ, but your capacitor only has %.0f GJ remaining.",
requiredCapacitorCharge,
remainingCapacitorCharge
);

return false;
}
}

// check distance for targetable actions
if (m_targetSE != nullptr) {
// weapons use ships AttrMaxTargetRange which is checked in TargetMgr
Expand Down
Loading