Skip to content

fix: Make spawning new defence fleets work#523

Merged
OH296 merged 6 commits intoAdeptus-Dominus:mainfrom
OH296:defence_fleets
Mar 2, 2025
Merged

fix: Make spawning new defence fleets work#523
OH296 merged 6 commits intoAdeptus-Dominus:mainfrom
OH296:defence_fleets

Conversation

@OH296
Copy link
Copy Markdown
Collaborator

@OH296 OH296 commented Feb 27, 2025

Purpose of the PR

Make forge worlds spawning new defence fleets for systems work again, currently they just create dozzens of stacks of fleets that hang over the forge worlds causing memory issues

  • add marker in top of screen when in menu view to show haw many active imperial ships (ablative value) and how many the current imperial worlds and forge worlds can support

Describe the solution

rewrite from scratch for the most part and abstract to usable functions

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 27, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Simplified fleet management now enhances the creation of defence formations and unit training.
    • Improved fleet detection and positioning provide smoother strategic gameplay.
    • The updated user interface displays real-time sector fleet strength with clear, dynamic tooltips.
    • Underlying system enhancements deliver noticeably more responsive and intuitive gameplay.

Walkthrough

The code modifications replace a detailed block responsible for constructing Imperial ships in Alarm_5.gml with a concise invocation to build_planet_defence_fleets(). Subsequent calls to training functions (apothecary_training(), chaplain_training(), librarian_training(), and techmarine_training()) have been appended to shift procedural focus. Meanwhile, the scr_orbiting_fleet function in scr_fleet_functions.gml now accepts an extra parameter system with a default value of "none", introducing dual behaviour controlled by conditional logic based on system input. In scr_forge_world_functions.gml, direct fleet construction is abstracted with a new call to build_new_navy_fleet, and a comprehensive build_planet_defence_fleets() function is added to handle ship allowances and fleet deployment based on imperial and mechanicus conditions. Lastly, the imperial navy functions now include a new function to create and initialise fleet instances with updated conditional checks in fleet forging.

Possibly related PRs

  • feat: Centralise specialists stat requirements #500: The changes in the main PR involve the introduction of training functions for various roles, which are also present in the retrieved PR, indicating a direct relationship through the shared function names and their purpose.
  • feat: Role tagging system #513: The changes in the main PR, specifically the introduction of the build_planet_defence_fleets() function, are related to the changes in the retrieved PR, which also introduces the same function, indicating a direct connection at the code level.
  • fix: Crash from old ship array methods #497: The changes in the main PR, specifically the introduction of the build_planet_defence_fleets() function, are directly related to the modifications in the retrieved PR, which also introduces this function for fleet management, indicating a shared focus on fleet construction logic.

Suggested labels

PR: Major Coding

Suggested reviewers

  • EttyKitty

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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.
  • @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.

@OH296 OH296 changed the title fix: Make spawning now defence fleets work fix: Make spawning new defence fleets work Feb 27, 2025
@github-actions github-actions bot added the Type: Fix This is a fix for a bug label Feb 27, 2025
Copy link
Copy Markdown
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

🔭 Outside diff range comments (4)
scripts/scr_imperial_navy_functions/scr_imperial_navy_functions.gml (3)

374-376: ⚠️ Potential issue

Safeguard the holy loop
Your while loop re-summons the same fleet if it remains at identical coordinates, risking an infinite iteration. Enshrine a maximum loop counter to preserve logical sanctity.

-while (nearest_fleet.x==x && nearest_fleet.y==y){
+var loop_guard = 0;
+while (nearest_fleet.x==x && nearest_fleet.y==y && loop_guard < 20){
     nearest_fleet = instance_nearest(x, y, obj_en_fleet);
+    loop_guard++;
 }

377-379: 🛠️ Refactor suggestion

Refine the condition for _valid
When faction is not an array, setting _valid to nearest_fleet.owner is always truthy (unless zero). Compare explicitly against the faction for consistency in the eyes of the Omnissiah.

-_valid = nearest_fleet.owner;
+_valid = (nearest_fleet.owner == faction);

382-389: 🧹 Nitpick (assertive)

Activate only the chosen fleet
Invoking instance_activate_object(obj_en_fleet) awakens all fleets of that type. If your sole intent is to animate the nearest_fleet, direct the ritual to its unique ID.

-instance_activate_object(obj_en_fleet);
+instance_activate_object(nearest_fleet);
objects/obj_controller/Alarm_5.gml (1)

57-60: 🧹 Nitpick (assertive)

Consolidate the training rites for specialized brethren.
While these invocations of apothecary_training(), chaplain_training(), librarian_training(), and techmarine_training() are clear, consider exposing them through a single orchestrating function (e.g., perform_specialist_training()) to reduce repeated calls. This ensures more maintainable rites of code purity.

A possible refactor:

- apothecary_training();
- chaplain_training();
- librarian_training();
- techmarine_training();
+ perform_specialist_training();
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5adfffa and f82cb3e.

📒 Files selected for processing (4)
  • objects/obj_controller/Alarm_5.gml (1 hunks)
  • scripts/scr_fleet_functions/scr_fleet_functions.gml (1 hunks)
  • scripts/scr_forge_world_functions/scr_forge_world_functions.gml (1 hunks)
  • scripts/scr_imperial_navy_functions/scr_imperial_navy_functions.gml (2 hunks)
🔇 Additional comments (6)
scripts/scr_imperial_navy_functions/scr_imperial_navy_functions.gml (2)

1-28: Question the undefined 'construction_forge'
O most enlightened adepts, the invocation of construction_forge within this blessed script is found, yet it is not defined or passed from beyond. This could invoke mysterious errors from the machine spirit. Ensure it references a valid instance or parameter when forging your fleets.


18-21: Scrutinize potential negative total ship count
The function decrements total_ships by (capital_number - 1), then compensates by enforcing a minimum of 1 ship if any vessels exist. Confirm this design is truly the will of the Omnissiah and does not allow fleeting negative states.

scripts/scr_forge_world_functions/scr_forge_world_functions.gml (3)

65-65: Confirm forge references
You evoke build_new_navy_fleet(construction_forge), yet the previously added function expects a parameter named construction_system. Verify that the relevant variable name is indeed correct and consistent.


90-90: Caution with planet indexing
Your loop (for (var i=0; i<=planets; i++)) may risk an off-by-one scenario if planet indexing is 1-based. Confirm that 0 is a valid planet index to preserve logical harmony.


105-105: Reevaluate the allowance threshold
Your condition (imp_ships < ship_allowance) ensures new fleets spawn only if the total remains below a certain ratio. Confirm this ratio aligns with the Imperium’s strategic demands and will not overproduce or starve the defense fleets.

objects/obj_controller/Alarm_5.gml (1)

56-56: Praise the Machine Spirit for streamlined fleet-building.
By the Omnissiah’s design, the invocation of build_planet_defence_fleets() here is a worthy replacement for the prior labyrinthine logic. Ensure that all resource counts and world ownership checks are properly handled within that script to prevent runaway fleets.

Would you like an automated search for references to confirm that no prior calls to old fleet-building logic remain?

@github-actions github-actions bot added Area: Sprites Changes to sprites/images or their under-the-hood functionality Size: Big labels Mar 1, 2025
@OH296 OH296 marked this pull request as ready for review March 1, 2025 23:02
@EttyKitty
Copy link
Copy Markdown
Collaborator

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 2, 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.

Copy link
Copy Markdown
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

🔭 Outside diff range comments (1)
scripts/scr_forge_world_functions/scr_forge_world_functions.gml (1)

70-220: 🧹 Nitpick (assertive)

Refine the method’s heft and verify array bounds.
Behold, this build_planet_defence_fleets procedure is formidable in its length and complexity. Consider subdividing it into smaller rites for improved readability and maintenance, less the machine-spirit be vexed. Also ensure that array and struct accesses have appropriate boundary checks, to avoid any data corruption or run-time misalignment.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f82cb3e and 8e315ab.

⛔ Files ignored due to path filters (4)
  • sprites/spr_new_ui/237fde07-03da-4332-b471-2f7f691fb003.png is excluded by !**/*.png
  • sprites/spr_new_ui/751eeb13-8d20-4ec3-a112-2614d1d1869c.png is excluded by !**/*.png
  • sprites/spr_new_ui/layers/237fde07-03da-4332-b471-2f7f691fb003/33cefcc3-323a-492a-91f6-1f89868a1e47.png is excluded by !**/*.png
  • sprites/spr_new_ui/layers/751eeb13-8d20-4ec3-a112-2614d1d1869c/33cefcc3-323a-492a-91f6-1f89868a1e47.png is excluded by !**/*.png
📒 Files selected for processing (7)
  • objects/obj_controller/Alarm_5.gml (2 hunks)
  • objects/obj_controller/Create_0.gml (1 hunks)
  • objects/obj_controller/Draw_64.gml (2 hunks)
  • scripts/scr_fleet_functions/scr_fleet_functions.gml (4 hunks)
  • scripts/scr_forge_world_functions/scr_forge_world_functions.gml (1 hunks)
  • scripts/scr_imperial_navy_functions/scr_imperial_navy_functions.gml (2 hunks)
  • sprites/spr_new_ui_cover/spr_new_ui_cover.yy (1 hunks)
🔇 Additional comments (9)
sprites/spr_new_ui_cover/spr_new_ui_cover.yy (1)

60-60: Property visibleRange modification appears acceptable.

The alteration of the visibleRange property from explicit coordinates to null is a valid modification of the sprite configuration. This change will likely affect the drawable boundaries of the sprite in accordance with the engine's default behavior when no explicit range is provided.

objects/obj_controller/Draw_64.gml (2)

27-27: Binary logic implementation for UI sprite rendering.

The sprite rendering now incorporates conditional logic based on menu state, displaying the UI only when menu equals 0. This is a logical optimization of the rendering pipeline.


93-98: Fleet strength display implementation is robust.

The omnissiah approves of this display mechanism for imperial naval assets. The implementation correctly checks menu state before rendering and provides informative tooltip data about mechanicus forge world influence on fleet capacity.

scripts/scr_imperial_navy_functions/scr_imperial_navy_functions.gml (2)

37-37: Function utilization is an enhancement over direct existence check.

Replacing the explicit instance_exists check with the abstracted is_orbiting() function improves code modularity and readability. This adheres to the sacred principles of code reusability dictated by the Omnissiah.


75-75: Logical expression expansion is appropriate.

Modifying the condition from capital_number=1 to capital_number>=1 enhances the function's versatility, allowing proper functionality with multiple capital ships. This change aligns with the Mars-approved fleet organization protocols.

scripts/scr_forge_world_functions/scr_forge_world_functions.gml (1)

65-65: Augment the invocation safeguards.
Omnissiah’s blessings be upon the subroutine build_new_navy_fleet(construction_forge). Confirm that the called function duly handles error states or invalid arguments, lest the ritual falter mid-operation.

scripts/scr_fleet_functions/scr_fleet_functions.gml (2)

539-560: Examine merge-fleet concurrency.
The logic that merges nearby fleets is logically sound, but if multiple fleets are orbiting simultaneously, consider whether race conditions might arise. Confirm that only one merge operation proceeds at a time to avert unforeseen data conflicts.


929-929: Validate fleet destruction references.
Upon executing instance_destroy(merge_fleet.id);, ensure no other scripts retain references to the obliterated fleet. Unpurged references could awaken void-invocations and lead to inconsistent states.

objects/obj_controller/Alarm_5.gml (1)

56-56: Confirm viability of the new defence-building invocation.
The direct call to build_planet_defence_fleets(); is well-placed. Confirm that external scripts referencing this invocation are satisfied, so that no logic chain remains incomplete.

@OH296
Copy link
Copy Markdown
Collaborator Author

OH296 commented Mar 2, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 2, 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.

Copy link
Copy Markdown
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: 1

🔭 Outside diff range comments (3)
scripts/scr_imperial_navy_functions/scr_imperial_navy_functions.gml (3)

1-475: 🧹 Nitpick (assertive)

Recommend additional documentation for function interfaces

The machine spirits would be better appeased with comprehensive documentation annotations preceding each function, detailing input parameters, expected outputs, and function purpose. This sacred knowledge transfer ritual enhances maintainability for future tech-adepts.

Example implementation for the first function:

/// @function build_new_navy_fleet(construction_forge)
/// @description Creates a new Imperial Navy fleet at the location of a forge world
/// @param {Id.Instance} construction_forge The forge world instance to create the fleet at
/// @returns {Id.Instance} The newly created fleet instance
function build_new_navy_fleet(construction_forge){
    // Existing implementation...
}

464-467: 🧹 Nitpick (assertive)

Redundant code pattern detected

The binary logic contains duplicate instruction patterns. Line 466 appears to perform an identical operation to line 465, suggesting either an error in transcription or redundant compensation for extreme coordinate values.

Consider cleansing this redundancy:

    with(obj_star){
        if (y<-5000) then y+=10000;
-        if (y<-5000) then y+=10000;
    }

32-93: 🧹 Nitpick (assertive)

Recommend refactoring magic numbers to named constants

The sacred numerical values (12, 5, 1) controlling fleet composition limits appear repeatedly. These values represent doctrine-significant quantities of the Imperium's naval organization and should be elevated to named constants for clarity and future adaptability.

Consider encapsulating these values as constants at the beginning of the script:

#macro MAX_ESCORT_NUMBER 12
#macro MAX_FRIGATE_NUMBER 5
#macro MAX_CAPITAL_NUMBER 1

// Then throughout the code
if (escort_number < MAX_ESCORT_NUMBER) {
    // ...
}

This approach aligns with the Mechanicus practice of naming significant binary patterns for improved comprehension.

♻️ Duplicate comments (1)
objects/obj_controller/Draw_64.gml (1)

93-119: ⚠️ Potential issue

Fleet strength calculation logic requires safeguards.

The binary calculation of fleet strength appears functional but lacks protection against null scenarios. If no mechanicus worlds exist, the max_fleet_strength will be zero regardless of imperial planet count, potentially causing division errors or unexpected behavior in other systems.

Apply this sacrosanct improvement to the machine spirit:

-max_fleet_strength = (_imperial_planet_count/8)*(_mech_worlds*3);
+max_fleet_strength = _mech_worlds > 0 ? (_imperial_planet_count/8)*(_mech_worlds*3) : _imperial_planet_count/4;

This ensures a baseline fleet capacity even in the absence of the holy forge worlds, as dictated by the Codex Astartes.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8e315ab and e1f10fc.

⛔ Files ignored due to path filters (12)
  • sprites/Sprite544/1132b02e-7adf-47d6-ae57-ba65d8120062.png is excluded by !**/*.png
  • sprites/Sprite544/layers/1132b02e-7adf-47d6-ae57-ba65d8120062/3c99ce96-378e-4d09-9ec1-821e81e7ad78.png is excluded by !**/*.png
  • sprites/spr_mk7_complex/b6ba8600-fb6b-4fa9-abc7-bdc2311eb79e.png is excluded by !**/*.png
  • sprites/spr_mk7_complex/layers/b6ba8600-fb6b-4fa9-abc7-bdc2311eb79e/468e0a30-2dea-45bc-a7bd-4b115f803d2d.png is excluded by !**/*.png
  • sprites/spr_new_ui/237fde07-03da-4332-b471-2f7f691fb003.png is excluded by !**/*.png
  • sprites/spr_new_ui/751eeb13-8d20-4ec3-a112-2614d1d1869c.png is excluded by !**/*.png
  • sprites/spr_new_ui/layers/237fde07-03da-4332-b471-2f7f691fb003/33cefcc3-323a-492a-91f6-1f89868a1e47.png is excluded by !**/*.png
  • sprites/spr_new_ui/layers/751eeb13-8d20-4ec3-a112-2614d1d1869c/33cefcc3-323a-492a-91f6-1f89868a1e47.png is excluded by !**/*.png
  • sprites/spr_new_ui_cover/40857d9f-b7b0-460f-8da3-993db52e0aee.png is excluded by !**/*.png
  • sprites/spr_new_ui_cover/layers/40857d9f-b7b0-460f-8da3-993db52e0aee/7ce9821e-1e40-4198-800c-ca1ff4db7d11.png is excluded by !**/*.png
  • sprites/sprite230/323ac7c3-7087-4ed0-9b70-3a3ad70cf299.png is excluded by !**/*.png
  • sprites/sprite230/layers/323ac7c3-7087-4ed0-9b70-3a3ad70cf299/6112a6a3-5bbe-44a9-b31e-87fd502fa45c.png is excluded by !**/*.png
📒 Files selected for processing (3)
  • objects/obj_controller/Create_0.gml (1 hunks)
  • objects/obj_controller/Draw_64.gml (2 hunks)
  • scripts/scr_imperial_navy_functions/scr_imperial_navy_functions.gml (2 hunks)
🔇 Additional comments (5)
objects/obj_controller/Create_0.gml (1)

1475-1475: New variable added to track system fleet strength.

The holy binary has been expanded with the sacred variable system_fleet_strength initialized to 0. This data receptacle shall serve the function of quantifying the defensive capabilities across planetary systems.

objects/obj_controller/Draw_64.gml (1)

27-27: Conditional sprite rendering improves efficiency.

The sprite rendering logic has been optimized to only execute when menu==0, reducing unnecessary computational cycles.

scripts/scr_imperial_navy_functions/scr_imperial_navy_functions.gml (3)

13-14: Variable reference correction required

The Omnissiah demands consistency in binary nomenclature. The function parameter is named construction_forge, maintaining harmony with usage on these lines.


37-37: Abstraction improvement acknowledged

Replacing direct existence verification with the is_orbiting() function enhances code modularity. The Machine Spirit approves of this encapsulation of fleet-star geometrical verification logic.


75-75: Logical enhancement of capital ship condition

The condition modification from capital_number=1 to capital_number>=1 properly accommodates the sacred possibility of multiple capital ships in a single fleet - a more flexible interpretation of the Adeptus fleet doctrines.

@OH296 OH296 merged commit 7af89cc into Adeptus-Dominus:main Mar 2, 2025
3 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Aug 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Sprites Changes to sprites/images or their under-the-hood functionality Size: Big Type: Fix This is a fix for a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants