Skip to content

Conversation

@EttyKitty
Copy link
Collaborator

@EttyKitty EttyKitty commented Mar 29, 2025

Purpose of changes

  • Fix bugs.
  • Make the code more readable and simple.
  • Account for the most of edge cases.

Describe the solution

  • The code is refactored to be more readable.
  • The new engaged check is taken from the combat overhaul branch.
  • Most of the target selection edge cases are accounted for, with retargeting, stopping to look for vehicles or attacking vehicles instead.
  • A couple of log error added, to keep track if some stuff breaks.

Describe alternatives you've considered

None

Testing done

  • A lot. Like, a lot, a lot, to fix this shit. I can only hope that I wasn't lucky to miss some apparent shit.

Related links

https://discord.com/channels/714022226810372107/714023282780799028/1355327467686068314
https://discord.com/channels/714022226810372107/1121959429546455050/1355359142205853858
#579

Custom player notes entry

Use the PR title.

@coderabbitai
Copy link
Contributor

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

    • Revamped combat mechanics now deliver more reliable and varied melee and ranged engagements.
    • Enhanced weapon effects offer scenario-specific behaviour to enrich tactical gameplay.
  • Refactor

    • Improved target selection processes ensure more efficient combat performance.
    • Optimised initialisation routines contribute to smoother overall gameplay.

Walkthrough

Hail, brethren of the Machine Spirit! This pull request imbues our code with refined logic for unit engagement and shooting mechanics. In the objects/obj_enunit/Alarm_0.gml, the targeting system has been recalibrated, replacing the old chapter_fuck with the more precise target_unit_index and switching to collision-based melee detection. Enhanced shooting routines now check weapon validity meticulously—logging sacred debug data—and differentiate between AP and non-AP armaments. Concurrently, the initialisation loops in both objects/obj_enunit/Create_0.gml and objects/obj_pnunit/Create_0.gml no longer worship the zero initialization of the combi array, potentially altering default states. Moreover, in scripts/scr_en_weapon/scr_en_weapon.gml, direct assignments now honour specific weapon attributes based on names and enemy types, with adjustments to the weapon slot logic. Thus, this commit delivers a restructured and detailed combat simulation.

Possibly related PRs

Suggested labels

PR: Fix, Size: Medium

Suggested reviewers

  • Blogaugis

🪧 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 plan to trigger planning for file edits and PR creation.
  • @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.

@github-actions github-actions bot added Type: Refactor Rewriting/restructuring code, while keeping general behavior Size: Epic labels Mar 29, 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 (1)
objects/obj_enunit/Alarm_0.gml (1)

320-430: 🧹 Nitpick (assertive)

Consider unifying duplicated shooting logic.

A portion of the latter half of this Alarm event replicates earlier range checks and shooting routines. Merging these shared behaviours into a single function (or script) would reduce the chance of divergence and relieve the burden of future maintenance.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b851492 and 2008c6e.

📒 Files selected for processing (4)
  • objects/obj_enunit/Alarm_0.gml (2 hunks)
  • objects/obj_enunit/Create_0.gml (0 hunks)
  • objects/obj_pnunit/Create_0.gml (0 hunks)
  • scripts/scr_en_weapon/scr_en_weapon.gml (3 hunks)
💤 Files with no reviewable changes (2)
  • objects/obj_pnunit/Create_0.gml
  • objects/obj_enunit/Create_0.gml
🧰 Additional context used
📓 Path-based instructions (2)
`**/*.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 ga...

**/*.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.

  • objects/obj_enunit/Alarm_0.gml
  • scripts/scr_en_weapon/scr_en_weapon.gml
`**/*.gml`: Color codes in the code shouldn't have any spaces in their id. I.e., color code `# 80 bf40` will crash the game.

**/*.gml: Color codes in the code shouldn't have any spaces in their id. I.e., color code # 80 bf40 will crash the game.

  • objects/obj_enunit/Alarm_0.gml
  • scripts/scr_en_weapon/scr_en_weapon.gml
🔇 Additional comments (6)
objects/obj_enunit/Alarm_0.gml (6)

44-44: Melee detection logic looks sound.

By using collision_point checks on both x-10 and x+10, you cover engagements on either side. This is a more direct approach than purely distance-based checks, ensuring that if a unit physically occupies an adjacent space, melee is triggered. No obvious concerns arise here.


48-74: Commendable sanity checks for ranged attacks.

These lines rightly confirm the unit is not engaged in melee before opening fire. Further checks for empty weapons, ammo depletion, or broken range ensure the code does not proceed with invalid or futile attacks. All these validations exemplify beneficial error-proofing for the combat routine.


112-143: Armour-piercing logic is well-structured.

Your use of _armour_piercing along with checks for vehicles, forts, and fallback to other rows ensures that these weapons strike appropriate targets. The debug messages are thorough in revealing how the logic flows.


154-235: Non-AP fallback logic is suitably flexible.

Should no valid infantry targets present themselves, the code attempts to find vehicles or fortifications. This layered approach helps ensure that any offensive potential isn’t wasted. The debug statements further clarify the AI’s target selection, which aids debugging.


236-241: Helpful debug for insufficient range.

The message indicates precisely why the unit cannot shoot, which helps the Machine Spirit’s caretaker diagnose short-range inefficacy.


245-314: Melee subroutine includes a fallback for AP or non-AP weapons.

Your code dispatches armour-piercing strikes if possible, reverting to standard attacks otherwise. This layered approach suits the varied battlefield conditions. Verify edge cases where newly arrived blocks might appear mid-combat, though no immediate concerns are evident here.

@EttyKitty EttyKitty added the Type: Fix This is a fix for a bug label Mar 29, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 29, 2025
@EttyKitty EttyKitty force-pushed the refactor/enemy-target branch from 1d2731c to 9f84852 Compare March 29, 2025 22:03
@EttyKitty EttyKitty marked this pull request as ready for review March 29, 2025 22:15
Copy link
Collaborator

@OH296 OH296 left a comment

Choose a reason for hiding this comment

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

Looks good to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Size: Epic Type: Fix This is a fix for a bug Type: Refactor Rewriting/restructuring code, while keeping general behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants