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

Destroy cosmetic pawns when items are unequipped #1244

Merged
merged 2 commits into from
Aug 19, 2023

Conversation

Tedster59
Copy link
Contributor

Fixes Issue #1108 by creating a new function DestroyCosmeticPawn_CH that is modeled on the existing GetCosmeticPawn function, but destroys the requested cosmetic pawn instead of returning it. This function is now called by RemoveItemFromInventory on XComGameState_Unit

New PR to use proper rebased branch with cleaned up commits.

Added to XCGS_Unit to remove cosmetic pawns when items are removed from a unit's loadout.
@Tedster59 Tedster59 added bug-basegame ready-to-review A pull request is ready to be reviewed labels Aug 17, 2023
@Iridar Iridar added this to the 1.26.0 milestone Aug 18, 2023
Copy link
Contributor

@Iridar Iridar left a comment

Choose a reason for hiding this comment

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

@Tedster59 I've made some adjustments to the PR, see the comments for details. I tested and it still works fine. Please take a look to see if you agree with my changes, and if all is good, I'll squash merge this.

@@ -259,7 +259,8 @@ simulated function XComUnitPawn GetCosmeticPawnInternal(out array<PawnInfo> Pawn
return PawnStore[StoreIdx].Cosmetics[CosmeticSlot].Pawn;
}

/// Start issue #1108 - new function to destroy cosmetic pawns. INTERNAL CHL API, not covered by BC policy.
// Start issue #1108
// Destroy a cosmetic pawn associated with a particular inventory slot on a particular unit, if there is one.
Copy link
Contributor

Choose a reason for hiding this comment

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

It's preferable to keep comments to the point, just explaining what the function does, giving its history unless it's relevant is unnecessary.

I for one got mislead by "use the new function", which can be interpreted as there's an old version of DestroyCosmeticPawn().

I also decided to remove the mention of "internal CHL API", because that would imply we don't want mods using this new function. I don't see any harm in keeping it open, though I confess I can't come up with a potential use case on the spot.

@@ -290,8 +291,7 @@ simulated final function bool DestroyCosmeticPawn_CH(int CosmeticSlot, int UnitR
return false;
}

// Helper function used by DestroyCosmeticPawn_CH. Also internal only, and not covered by BC policy.
simulated final function bool DestroyCosmeticPawnInternal_CH(out array<PawnInfo> PawnStore, int CosmeticSlot, int StoreIdx)
simulated private function bool DestroyCosmeticPawnInternal_CH(out array<PawnInfo> PawnStore, int CosmeticSlot, int StoreIdx)
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that's an actual internal CHL API function, but in this case just adding private is enough to imply that, per Xym's guidelines.

@@ -8485,9 +8485,6 @@ simulated function bool RemoveItemFromInventory(XComGameState_Item Item, optiona
local X2ArmorTemplate ArmorTemplate;
local int RemoveIndex;

// Variable for Issue #1108
local UIPawnMgr PawnMgr;
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you're not gonna be none-checking the UIPawnMgr - and the user has bigger problems then accessed-none log warnings if UIPawnManager is missing - I decided to get rid of the local var for code brevity.

}
}

/// HL-Docs: ref:Bugfixes; issue:1108
Copy link
Contributor

Choose a reason for hiding this comment

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

In general we do want to ship most submissions with a HL-Docs entry, one was missing from this PR.


/// HL-Docs: ref:Bugfixes; issue:1108
/// If there is a cosmetic pawn associated with the unequipped item item, remove it.
`PRESBASE.GetUIPawnMgr().DestroyCosmeticPawn_CH(Item.InventorySlot, self.ObjectID);
Copy link
Contributor

Choose a reason for hiding this comment

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

As I understand it, there are two main presentation layers, HQPRES for strategy and PRES for tactical. Both of them extend PRESBASE. Using PRESBASE macro will yield you either HQPRES or PRES depending on where you are.

Since GetUIPawnMgr() lives in PRESBASE, and it is technically possible to unequip items in tactical, I think it's more appropriate to use PRESBASE here.

@Iridar Iridar added ready-for-merge the pull request was reviewed and is ready to be merged. and removed ready-to-review A pull request is ready to be reviewed labels Aug 19, 2023
@Iridar
Copy link
Contributor

Iridar commented Aug 19, 2023

Approved by Tedster, merging.

@Iridar Iridar merged commit 4d4250d into X2CommunityCore:master Aug 19, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-basegame ready-for-merge the pull request was reviewed and is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants