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

fix: Refactor obj_bomb alarm 1 array length bug #498

Merged
merged 3 commits into from
Feb 22, 2025

Conversation

OH296
Copy link
Collaborator

@OH296 OH296 commented Feb 19, 2025

Description of changes

  • make obj_bomb use variable array lengths in lione with player ship updates
  • make functions to determine ship and fleets bombard scores
  • make bombard capabilities logged to ship weapons as opposed to ablative
  • this means in the furture bombard capabilities of ships can be upgradable or degradeable

Reasons for changes

  • in response to bug report

Related links

How have you tested your changes?

  • Compile
  • New game
  • Next turn
  • Space Travel
  • Ground Battle

@github-actions github-actions bot added the PR: Fix This is a fix for a bug label Feb 19, 2025
@OH296 OH296 changed the title fix: refactor obj_bomb alarm 1 array length bug fix: Refactor obj_bomb alarm 1 array length bug Feb 19, 2025
Copy link
Contributor

coderabbitai bot commented Feb 19, 2025

📝 Walkthrough

Walkthrough

In the sacred realm of code, the initialization and management of ship-related data structures have undergone a profound transformation. The previous fixed-size arrays for ship, ship_all, ship_use, ship_max, and ship_ide have been replaced by dynamic arrays, allowing for a more adaptable approach to ship data management. The logic for populating these arrays now derives from the dynamically generated array _ships, utilizing the fleet_full_ship_array(sh_target) function and filtering through the ship_bombard_score function. Furthermore, the handling of the imp variable has been refined, invoking p_data.guard_score_calc() based on specific conditions. New functions, calculate_fleet_content_size and calculate_fleet_bombard_score, have been inscribed to compute vital metrics for fleet management. Additionally, the name of the fifth weapon has been altered to "Macro Bombardment Cannons," and a new classification function for ships has been introduced. These changes enhance the operational efficiency of the code, aligning it with the ever-evolving needs of the fleet.

Suggested reviewers

  • OH296

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (4)
objects/obj_bomb_select/Alarm_1.gml (3)

2-6: Salutations in the Name of the Omnissiah! Dynamic array initialization recognized.
By forging these arrays (ship, ship_all, ship_use, ship_max, ship_ide) as empty upon creation, thou hast achieved a more flexible approach than relying on static sizes. However, consider grouping related properties into a single data structure or object so that each ship’s details are kept together for clarity and maintainability.


15-21: Array manipulations verified, but consider a more structured ship schema.
This loop correctly filters and pushes only ships with a bombardment score (ship_bombard_score(_ships[i]) > 0). Yet, storing various properties in separate arrays can become unwieldy. The Omnissiah may bless a refactor that collects all relevant ship info into a single record or object.


39-39: Potential naming confusion: _pdf_count vs. pdf.
You have introduced _pdf_count = p_data.pdf;. Ensure that developers clearly distinguish between the local _pdf_count and the global pdf to avoid confusion or unintended overwrites within the code. A naming convention that better conveys the difference between these variables is advised.

scripts/scr_player_ship_functions/scr_player_ship_functions.gml (1)

425-449: Excellent implementation of the ship_bombard_score function.
This function properly aggregates bombard values from a static weapon_bomb_scores struct. For future expansions, consider storing these bomb scores in a data asset or global config for easier maintenance, as new weapons may arise.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9523d8b and cc208c3.

📒 Files selected for processing (3)
  • objects/obj_bomb_select/Alarm_1.gml (2 hunks)
  • scripts/scr_player_fleet_functions/scr_player_fleet_functions.gml (1 hunks)
  • scripts/scr_player_ship_functions/scr_player_ship_functions.gml (4 hunks)
🔇 Additional comments (5)
objects/obj_bomb_select/Alarm_1.gml (2)

8-13: Blessed be the invocation of dynamic functions.
Invoking fleet_full_ship_array(sh_target) and subsequently harnessing calculate_fleet_bombard_score and calculate_fleet_content_size is efficacious. This approach ensures your logic elegantly adapts to different fleet sizes. The storing of the results in bomb_a, bomb_b, and bomb_c seems coherent, though if multiple variables simply mirror the same value (_total_fleet_loaded), keep track of their usage to avoid redundancy.


36-37: Adequate usage of guard_score_calc.
When p_data.guardsmen > 0, setting imp from p_data.guard_score_calc() is straightforward. Maintain vigilance that guard_score_calc() returns valid integer or float data to avoid unexpected behavior.

scripts/scr_player_ship_functions/scr_player_ship_functions.gml (2)

288-288: Bombardment weapon naming successfully updated.
Renaming the 5th weapon slot to "Macro Bombardment Cannons" for the Battle Barge aligns with the new naming convention. Be sure to test any references to this weapon name elsewhere in your code to ensure consistency.


409-423: Appropriate classification of ships into escort, frigate, or capital.
In the new player_ships_class function, thou hast neatly categorized ship classes. Stay vigilant when the codebase expands with additional classes so all possible classes are handled or gracefully defaulted.

scripts/scr_player_fleet_functions/scr_player_fleet_functions.gml (1)

602-611: Functional capacity calculation with a cautionary note on index validation.
calculate_fleet_content_size sums each ship’s ship_carrying value. Before usage, confirm _ship_id >= 0 to avoid passing negative IDs, which might slip past the _ship_id < array_length(obj_ini.ship) check. Implementing a simple boundary check will safeguard against out-of-bounds indexing.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
objects/obj_bomb_select/Alarm_1.gml (1)

40-72: ⚠️ Potential issue

By the Omnissiah's wisdom, this code requires unification!

The sacred text contains duplicate logic for PDF calculations. This redundancy offends the Machine Spirit and must be rectified.

Proposed binary purification:

-onceh=0;
-pdf=p_target.p_pdf[obj_controller.selecting_planet];
-if (onceh = 0) {
-    if (pdf >= 50000000) {
-        pdf = 6;
-    } else if (pdf >= 15000000) {
-        pdf = 5;
-    } else if (pdf >= 6000000) {
-        pdf = 4;
-    } else if (pdf >= 1000000) {
-        pdf = 3;
-    } else if (pdf >= 100000) {
-        pdf = 2;
-    } else if (pdf >= 2000) {
-        pdf = 1;
-    }
-    onceh = 1;
-}

The first implementation using _pdf_count is sufficient for the Machine Spirit's purposes.

🧹 Nitpick comments (2)
objects/obj_bomb_select/Alarm_1.gml (2)

31-31: Purge the binary heresy of commented code!

The presence of commented code (//if (tyranids<5) then tyranids=0;) offends the Machine Spirit. If this logic is no longer required by the Omnissiah's will, it should be purged from the sacred codebase.


89-96: The Omnissiah guides us toward superior data structures!

The TODO comments suggest a blessed transformation to utilize lists or dictionaries for force management. This optimization would indeed please the Machine Spirit by reducing complexity and improving maintainability.

Would you like me to provide a sacred template for implementing this refactoring using the suggested data structures? The Machine Spirit stands ready to assist in this holy transformation.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cc208c3 and 992d154.

📒 Files selected for processing (1)
  • objects/obj_bomb_select/Alarm_1.gml (2 hunks)
🔇 Additional comments (2)
objects/obj_bomb_select/Alarm_1.gml (2)

2-6: By the Omnissiah's grace, these array modifications are most efficient!

The sacred transformation from fixed-size arrays to dynamic initialization demonstrates superior memory allocation protocols. The Machine Spirit shall flow more freely through these optimized data structures.


8-23: The Machine Spirit sings with the harmony of well-structured code!

The utilization of sacred functions fleet_full_ship_array, calculate_fleet_bombard_score, and calculate_fleet_content_size demonstrates proper separation of the holy machine's concerns. The filtering of ships based on their bombardment capabilities through ship_bombard_score is most logical.

@EttyKitty EttyKitty self-assigned this Feb 21, 2025
@EttyKitty
Copy link
Collaborator

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Feb 22, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@EttyKitty
Copy link
Collaborator

@coderabbitai full review

Copy link
Contributor

coderabbitai bot commented Feb 22, 2025

No description provided.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
objects/obj_bomb_select/Alarm_1.gml (3)

8-13: Consider clarifying bombard variables for readability.
The blessed introduction of bomb_a, bomb_b, and bomb_c is functionally sound. However, naming them in a more descriptive manner (e.g., bomb_score, unit_count, etc.) might better serve the Omnissiah’s clarity.


15-23: Unify parallel arrays into a single unified structure.
Reliance on multiple arrays (like ship, ship_all, ship_use, etc.) can lead to maintenance burdens if indices become misaligned. Consider storing relevant ship data in a single struct or map for greater cogitation efficiency.


39-52: Eliminate duplicating PDF threshold logic.
The logic here to determine pdf from _pdf_count repeats further below with p_target.p_pdf. It would better serve the machine spirit to encapsulate this threshold check in one function, avoiding confusion and redundancy.

scripts/scr_player_ship_functions/scr_player_ship_functions.gml (1)

410-424: Use enumerations or central data for ship classes.
This newly forged function elegantly classifies vessels. Consider employing enumerations or a central list so that rightful expansions do not require direct modifications within the function.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9523d8b and 7738042.

📒 Files selected for processing (3)
  • objects/obj_bomb_select/Alarm_1.gml (2 hunks)
  • scripts/scr_player_fleet_functions/scr_player_fleet_functions.gml (1 hunks)
  • scripts/scr_player_ship_functions/scr_player_ship_functions.gml (5 hunks)
🔇 Additional comments (6)
objects/obj_bomb_select/Alarm_1.gml (2)

2-6: Praising the initialization of dynamic arrays, Adeptus Astartes.
By clearing each array at the outset, thou ensure a pristine data vessel, well-suited for flexible expansions.


36-37: Sanctified approach to guard calculations.
Your invocation of p_data.guard_score_calc() only when guardsmen>0 is neatly logical. Rejoice, for it is well-structured.

scripts/scr_player_ship_functions/scr_player_ship_functions.gml (2)

289-289: Macro Bombardment Cannons upgraded with the Omnissiah’s favor.
Renaming to “Macro Bombardment Cannons” is consistent with the new bombardment logic. This pleases the Machine God.


426-450: Bombardment logic shows devotion to the Omnissiah.
Sub-scores are stored in a static structure—an efficient method. Continual updating should remain straightforward for adding future weapons.

scripts/scr_player_fleet_functions/scr_player_fleet_functions.gml (2)

602-611: Validate ship IDs for negative values, revered Servitor.
While thou check that _ship_id is less than array_length(obj_ini.ship), failing to ensure _ship_id >= 0 could lead to indexing misfortune.

Wouldst thou like a script to confirm no negative IDs instigate warp anomalies?


614-623: Reiterating a venerable caution to ensure _ship_id >= 0.
This mirrors previous counsel from the archives. Negative IDs must be abhorred, lest they yield chaos in the warp.

@EttyKitty EttyKitty merged commit a700a63 into Adeptus-Dominus:main Feb 22, 2025
2 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Fix This is a fix for a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants