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

Conversation

charles-m-knox
Copy link

@charles-m-knox charles-m-knox commented Sep 16, 2024

Currently, you can repeatedly activate and deactivate a module over and over and it will not consume any capacitor charge. From my testing, this applies to:

  • mining modules
  • shield boosters
  • afterburners
  • survey scanners

It probably applies to all currently supported modules in evemu.

It is important to note that repeating a module's active cycle does consume the expected capacitor amount. It's only the initial activation that doesn't seem to consume charge.

This pull request fixes this issue by simply calculating the charge required in order to activate and deducting it from the ship's capacitor as expected.

2024-09-15-181843_431x355_scrot

Thank you for taking the time to review all of my pull requests 🙂

Summary by Sourcery

Ensure active modules consume capacitor charge on initial activation by checking and deducting the required charge from the ship's capacitor, preventing activation if insufficient charge is available.

Bug Fixes:

  • Fix the issue where active modules do not consume capacitor charge on initial activation by ensuring the required charge is deducted from the ship's capacitor.

Copy link

sourcery-ai bot commented Sep 16, 2024

Reviewer's Guide by Sourcery

This pull request addresses an issue where active modules were not consuming capacitor charge on their initial activation cycle. The implementation adds capacitor consumption checks and deductions for module activation, ensuring that modules now properly consume capacitor charge from the first activation.

File-Level Changes

Change Details Files
Implement capacitor consumption for module activation
  • Add capacitor charge check before module activation
  • Deduct capacitor charge when activating a module
  • Abort module cycle if insufficient capacitor charge
  • Add error message for insufficient capacitor charge
  • Update ship's capacitor level after consumption
src/eve-server/ship/modules/ActiveModule.cpp
Add capacitor check in CanActivate() method
  • Check if ship has sufficient capacitor before allowing module activation
  • Add error message for insufficient capacitor in CanActivate()
src/eve-server/ship/modules/ActiveModule.cpp
Include new header file
  • Add #include for AttributeEnum.h
src/eve-server/ship/modules/ActiveModule.cpp

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @charles-m-knox - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

Comment on lines +546 to +567
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.",
requiredCapacitorCharge,
remainingCapacitorCharge
);

AbortCycle();

return 0;
}

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

m_shipRef->SetShipCapacitorLevel(newCap / shipTotalCapacitor);
}
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;
}


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

src/eve-server/ship/modules/ActiveModule.cpp Show resolved Hide resolved
@charles-m-knox
Copy link
Author

charles-m-knox commented Sep 16, 2024

Closing for now. Need to make an adjustment. Will reopen later. Pushed a commit to fix an issue where double-spending of the capacitor can occur.

@jdhirst
Copy link
Contributor

jdhirst commented Sep 16, 2024

lgtm ❤️

@jdhirst jdhirst merged commit b6b9bc1 into EvEmu-Project:staging Sep 16, 2024
3 checks passed
@charles-m-knox charles-m-knox deleted the fix-initial-module-cycle-capacitor-usage branch September 16, 2024 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants