fix: Add safe-guards for scr_orbiting_player_fleet function#994
fix: Add safe-guards for scr_orbiting_player_fleet function#994OH296 merged 1 commit intoAdeptus-Dominus:mainfrom
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughBy the Omnissiah’s datum-cogitation: adds four fleet utility functions (orbiting lookup, distance helper, player-fleet finder, imperial strength aggregation) within scr_fleet_functions.gml and updates a weapon gear tag in scr_weapon.gml. Notes indicate a duplicate scr_orbiting_player_fleet block present. Documentation comments were introduced. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
scripts/scr_fleet_functions/scr_fleet_functions.gml (2)
515-535: Syntax error + faulty self-check in scr_orbiting_player_fleet. Purge the scrapcode.
- Stray ‘s’ after a brace (Line 519) will not compile.
- else if lacks parentheses (Line 523) — invalid GML.
- Inverted struct check makes the main branch unreachable; instances are structs, so !(is_struct(self)) is false.
- Missing instance_exists guard before distance use.
Apply this rite of correction:
-function scr_orbiting_player_fleet(system = "none"){ - if (system == "none" && !(is_struct(self)) && object_index == obj_star){ - var _fleet = instance_nearest(x, y, obj_p_fleet); - if (object_distance(self, _fleet) > 0){s - return -1 - } else{ - return _fleet.id; - } - } else if system != "none"){ - try{ - with (system){ - return scr_orbiting_player_fleet(); - } - } catch(_exception){ - handle_exception(_exception); - } - } - return -1; -} +function scr_orbiting_player_fleet(system = "none"){ + // Called from a star or delegated via `with (system)`. + if (system == "none"){ + if (object_index != obj_star) return -1; + var _fleet = instance_nearest(x, y, obj_p_fleet); + if (!instance_exists(_fleet)) return -1; + return (point_distance(x, y, _fleet.x, _fleet.y) == 0) ? _fleet.id : -1; + } else if (system != "none"){ + try { + with (system) { + return scr_orbiting_player_fleet("none"); + } + } catch(_exception) { + handle_exception(_exception); + } + } + return -1; +}
537-558: Assignment in conditional mutates fleet position; use equality.if (x=xx && y==yy) assigns x, corrupting state and breaking logic. Replace with comparison.
- with (obj_en_fleet){ - if (x=xx && y==yy){ + with (obj_en_fleet){ + if (x==xx && y==yy){
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled
- Linear integration is disabled
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
scripts/scr_fleet_functions/scr_fleet_functions.gml(3 hunks)scripts/scr_weapon/scr_weapon.gml(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.gml
⚙️ CodeRabbit configuration file
**/*.gml: - Macro constants require a space between the constant name and value. Without it, the compiler will throw an error. I.e.#macro ARR_body_parts["arm"]will crash the game, because there is no space between the array and the name of the macro.
- Color codes in the code shouldn't have any spaces in their id. I.e., color code
# 80bf40will crash the game.- All code should comply with the main GML documentation: https://manual.gamemaker.io/beta/en/GameMaker_Language/GML_Reference/GML_Reference.htm
Files:
scripts/scr_weapon/scr_weapon.gmlscripts/scr_fleet_functions/scr_fleet_functions.gml
**/*.*
⚙️ CodeRabbit configuration file
**/*.*: - Having humanly understandable and maintainable code is always the top most priority.
- DRY (Don't repeat yourself) principle is also very important.
- Ensure that the code is compliant with the CODE_STYLE.MD: https://github.com/Adeptus-Dominus/ChapterMaster/blob/main/docs/CODE_STYLE.md
- If a TODO comment is added, ask the user if you should create a GitHub issue for this TODO.
- If a TODO comment is deleted, remind the user if there is an active GitHub issue related to that comment.
Files:
scripts/scr_weapon/scr_weapon.gmlscripts/scr_fleet_functions/scr_fleet_functions.gml
🔇 Additional comments (6)
scripts/scr_weapon/scr_weapon.gml (1)
2890-2891: Tag augmentation acknowledged; no logic impact.Adding "ancient" to the Serpha Jump Pack’s tags is consistent with other ancient gear tags. Sanctified.
scripts/scr_fleet_functions/scr_fleet_functions.gml (5)
434-455: Docs read clean and match behaviour.The specification for scr_orbiting_fleet is clear and aligned with the implementation. Machine-spirits appeased.
456-478: Orbiting-by-faction lookup looks correct.Co-location check, faction match, and idle action gate are sound.
481-495: Utility docs are clear.object_distance contract is concise and useful for orbit checks.
501-514: Approved: scr_orbiting_player_fleet call sites handle –1 sentinel correctly; no “none” comparisons found.
560-580: Verify p_owner array indexing in the obj_star loop
The current loop (for (var i = 0; i <= planets; i++)) may readp_owner[0]or overshoot the array. Confirm whetherp_owneris 1-indexed—if so, iteratei = 1throughplanets; if it’s 0-indexed, usei < planets.
Purpose and Description
Testing done
Related things and/or additional context