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

Make X2SoldierClassTemplate::IsWeaponAllowedByClass() more flexible #1135

Merged
merged 2 commits into from
May 21, 2023

Conversation

Iridar
Copy link
Contributor

@Iridar Iridar commented Jan 27, 2022

Closes #1057

This replaces all instances of IsWeaponAllowedByClass() with a new wrapper in existing CHL and base game code.

I've tested the PR and it works as intended, e.g. if a Pistol weapon category is added to soldier class' AllowedWeapons, then the event listener for OverrideShowItemInLockerList is all that's required to equip it in-game.

static function EventListenerReturn OnOverrideShowItemInLockerList(Object EventData, Object EventSource, XComGameState GameState, Name EventID, Object CallbackObject)
{
    local XComGameState_Item ItemState;
    local XComLWTuple Tuple;
    local bool bSlotShowItemInLockerList;
    local EInventorySlot Slot;
    local XComGameState_Unit UnitState;

    ItemState = XComGameState_Item(EventSource);
    Tuple = XComLWTuple(EventData);

    bSlotShowItemInLockerList = Tuple.Data[0].b;
    Slot = EInventorySlot(Tuple.Data[1].i);
    UnitState = XComGameState_Unit(Tuple.Data[2].o);

    // Your code here
    if (Slot == eInvSlot_PrimaryWeapon && ItemState.GetWeaponCategory() == 'Pistol'
      //&& UnitState.GetSoldierClassTemplate().IsWeaponAllowedByClass_CH(X2WeaponTemplate(ItemState.GetMyTemplate()), eInvSlot_PrimaryWeapon)
        )
	{
		bSlotShowItemInLockerList = true;
	}

    Tuple.Data[0].b = bSlotShowItemInLockerList;

    return ELR_NoInterrupt;
}

The IsWeaponAllowedByClass_CH() in this listener itself is optional; if omitted then pistols will show up for all soldier classes, but the in-game UI will forbid equipping them, mentioning that they are "sharpshooter only", or whichever soldier class is found by GetAllowedClassForWeapon_CH() first.

Note: the HeavyWeaponTemplate.InventorySlot == eInvSlot_HeavyWeapon check in XCGS_Unit::GetBestHeavyWeaponTemplates() is not useless, even though the original X2SoldierClassTemplate::IsWeaponAllowedByClass() allows any weapons that are not primary or secondary weapons, nothing is stopping mods from creating their own soldier classes that would restrict the use of heavy weapons.

@Iridar Iridar added this to the 1.24.0 milestone Jan 27, 2022
@Iridar Iridar added the ready-to-review A pull request is ready to be reviewed label Jan 27, 2022
@Iridar Iridar self-assigned this Jan 27, 2022
@Iridar Iridar force-pushed the 1057-IsWeaponAllowedByClass-Fix branch from 2ff5ce8 to cd4a28a Compare January 27, 2022 09:46
Copy link
Member

@Xymanek Xymanek left a comment

Choose a reason for hiding this comment

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

Please add HL-Docs: ref: to the changed calls

@Xymanek Xymanek modified the milestone: 1.24.0 Feb 26, 2022
@Xymanek Xymanek added waiting-on-author A pull request is waiting on changes from the author and removed ready-to-review A pull request is ready to be reviewed labels Feb 26, 2022
@Iridar
Copy link
Contributor Author

Iridar commented Feb 27, 2022

Doneso.

@Iridar Iridar added ready-to-review A pull request is ready to be reviewed and removed waiting-on-author A pull request is waiting on changes from the author labels Feb 27, 2022
@Xymanek
Copy link
Member

Xymanek commented Feb 27, 2022

Better compare: 0518418...5d6bfce

@Xymanek
Copy link
Member

Xymanek commented Feb 27, 2022

Something went quite wrong with the generated docs:

image

@robojumper any ideas?

@robojumper
Copy link
Member

Something went quite wrong with the generated docs:

what would you expect given the documentation comments? the body of ref items is appended to the body of the main feature item

@Xymanek
Copy link
Member

Xymanek commented Feb 27, 2022

the body of ref items is appended to the body of the main feature item

I see (wasn't aware of that behaviour). @Iridar mind adjusting so that the generated docs page is sanely readable?

@Iridar
Copy link
Contributor Author

Iridar commented Feb 27, 2022

the body of ref items is appended to the body of the main feature item

I see (wasn't aware of that behaviour). @Iridar mind adjusting so that the generated docs page is sanely readable?

Sure, I'll try.

@Iridar
Copy link
Contributor Author

Iridar commented Feb 27, 2022

Do you mind giving me a link where I can preview the docs?

@Xymanek
Copy link
Member

Xymanek commented Mar 2, 2022

Better compare: 0518418...cfcc538

@Xymanek Xymanek modified the milestones: 1.24.0, 1.26.0 Mar 2, 2022
@Iridar Iridar force-pushed the 1057-IsWeaponAllowedByClass-Fix branch from b470f3b to ee3ed07 Compare March 2, 2022 12:05
@Iridar
Copy link
Contributor Author

Iridar commented Mar 2, 2022

Adjusted based on feedback and discord conversation, rebased to have just two commits.

@Iridar Iridar modified the milestones: 1.26.0, 1.25.0 Jun 26, 2022
@Iridar Iridar force-pushed the 1057-IsWeaponAllowedByClass-Fix branch from a4df699 to 23be844 Compare May 21, 2023 08:26
@Iridar Iridar merged commit 8248f3d into X2CommunityCore:master May 21, 2023
@Iridar Iridar deleted the 1057-IsWeaponAllowedByClass-Fix branch May 21, 2023 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-review A pull request is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

X2SoldierClassTemplate::IsWeaponAllowedByClass() is inflexible
3 participants