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: Make spawning new defence fleets work #523

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

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

Describe the solution

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

Copy link
Contributor

coderabbitai bot commented Feb 27, 2025

Important

Review skipped

Draft detected.

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

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 default value "none", introducing dual behavior 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 initialize fleet instances with updated conditional checks in fleet forging.

Possibly related PRs

Suggested labels

PR: Fix


🪧 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 PR: Fix This is a fix for a bug label Feb 27, 2025
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

🔭 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?

Comment on lines 370 to 376
function scr_orbiting_fleet(faction, system="none"){
if (system == "none"){
nearest_fleet = instance_nearest(x,y,obj_en_fleet);
var _valid = false;
if (is_array(faction)){
_valid = array_contains(faction, nearest_fleet.owner);
} else {
_valid = nearest_fleet.owner;
while (nearest_fleet.x==x && nearest_fleet.y==y){
nearest_fleet = instance_nearest(x,y,obj_en_fleet);
var _valid = false;
if (is_array(faction)){
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ward against the infinite loop
Within this while incantation, ‘instance_nearest’ may perpetually yield itself if no other fleets exist at different coordinates. Bestow a failsafe to avoid eternal recursion.

Comment on lines 382 to 389
instance_activate_object(obj_en_fleet);
return nearest_fleet.id;
} else {
instance_deactivate_object(nearest_fleet.id);
}
}
if (_valid && nearest_fleet.action == ""){
instance_activate_object(obj_en_fleet);
return nearest_fleet.id;
} else {
instance_deactivate_object(nearest_fleet.id);
instance_activate_object(obj_en_fleet);
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Employ precise object reactivation
Observe that instance_activate_object(obj_en_fleet) resurrects all fleets of that type. If the plan is to quicken only the chosen orbiting fleet, feed in its direct ID to appease the machine spirit.

Comment on lines 187 to 205
var targeted=false;
var target;
//shuffle the contents, if any
array_shuffle_ext(system_4);
array_shuffle_ext(system_3);
array_shuffle_ext(system_other);

if (targeted) {
target = array_pop(system_4)
targeted=true;
}
if (targeted) {
target = array_pop(system_3)
targeted=true;
}
if (targeted) {
target = array_pop(system_other)
targeted=true;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix reversed condition for system targeting
This segment sets targeted=false but only performs array_pop if targeted is already true. This logic never triggers. Adjust the condition to set targeted before popping from the arrays.

-var targeted=false;
-if (targeted) {
-    target = array_pop(system_4);
-    targeted=true;
+var targeted=false;
+if (!targeted && array_length(system_4) > 0) {
+    target = array_pop(system_4);
+    targeted=true;
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
var targeted=false;
var target;
//shuffle the contents, if any
array_shuffle_ext(system_4);
array_shuffle_ext(system_3);
array_shuffle_ext(system_other);
if (targeted) {
target = array_pop(system_4)
targeted=true;
}
if (targeted) {
target = array_pop(system_3)
targeted=true;
}
if (targeted) {
target = array_pop(system_other)
targeted=true;
}
var targeted=false;
var target;
//shuffle the contents, if any
array_shuffle_ext(system_4);
array_shuffle_ext(system_3);
array_shuffle_ext(system_other);
if (!targeted && array_length(system_4) > 0) {
target = array_pop(system_4);
targeted = true;
}
if (targeted) {
target = array_pop(system_3)
targeted = true;
}
if (targeted) {
target = array_pop(system_other)
targeted = true;
}

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.

1 participant