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

Implements TransformsInto for UnitType's. #933

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

Rampastring
Copy link
Member

@Rampastring Rampastring commented Dec 3, 2022

Closes #611 , Closes #715

This patch makes it possible for vehicles to transform into other vehicles on deploy.

This behaviour is controlled by a new TransformsInto=<unit type> key for UnitTypes. If it points to a valid UnitType, the unit is transformed into the specified unit type when deployed.

Also, in DTA we have a use-case where we want the transform to have a cooldown. This can be optionally enabled by giving the unit TransformRequiresFullCharge=yes. This re-uses the Mobile EMP's Charge logic: when this key is set, the unit is required to have full charge or it isn't able to transform.

Finally, for implementing this without having the transform break the build limits of units, I had to re-implement a part of the build limit checking for this patch. While at it, I also fixed #611 .

Remarks

If the unit also has DeploysInto= pointing to a building type, the DeploysInto logic is prioritized over unit transformation.

The unit transformation logic, however, is prioritized over the Mobile EMP blast logic.

@github-actions
Copy link

github-actions bot commented Dec 3, 2022

This comment is automaticly generated by Nightly.link and allows non-registered users to get download the artifacts for this pull request.

These links are also updated when the pull request is pushed to.

@Rampastring Rampastring force-pushed the 715-transformsinto branch 7 times, most recently from 6452ce7 to a5491de Compare December 6, 2022 22:47
@CCHyper CCHyper changed the title Implements TransformsInto for UnitTypeClassExtension. #715 Implements TransformsInto for UnitTypeClassExtension. Dec 12, 2022
@CCHyper CCHyper changed the title Implements TransformsInto for UnitTypeClassExtension. Implements TransformsInto for UnitType's. Dec 12, 2022
@tomsons26
Copy link
Contributor

tomsons26 commented Dec 13, 2022

Check if unit type is initialized, if not throw a warning, i suppose could just check if MaxStrength isn't 0, or some other constant that should definitely be set

@CCHyper CCHyper force-pushed the develop branch 3 times, most recently from 48cd2ea to b789478 Compare December 22, 2022 08:32
@CCHyper CCHyper changed the title Implements TransformsInto for UnitType's. Implements TransformsInto for UnitType's. Jan 3, 2023
@Rampastring Rampastring force-pushed the 715-transformsinto branch 2 times, most recently from 25c023e to 1b29304 Compare February 10, 2023 18:40
* Stolen bytes/code.
*/
if (unittype->IsToHarvest || unittype->IsToVeinHarvest) {
harvester_process:
Copy link
Contributor

Choose a reason for hiding this comment

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

Move this label to the end of the function.

unittypeext = Extension::Fetch<UnitTypeClassExtension>(unittype);

if (unittype->DeploysInto != nullptr || unittypeext->TransformsInto != nullptr) {
deployable_process:
Copy link
Contributor

Choose a reason for hiding this comment

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

Move this label to the end of the function.

* @author: Rampastring
*/
DECLARE_PATCH(_UnitClass_Mission_Unload_Transform_To_Vehicle_Patch) {
GET_REGISTER_STATIC(UnitTypeClass*, unittype, eax);
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs a space between UnitTypeClass and *.

This is most likely your MSVC auto-formatting taking over here, you can change those easily in Tools -> Options -> Text Editor -> C/C++.

/**
* We can transform and either don't need charge or we have enough of it, return ACTION_SELF
*/
return_self:
Copy link
Contributor

Choose a reason for hiding this comment

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

A little bit of code duplication here. We could clean this up by using making a single return label, with the return value being a variable that can be set in the jumping case.

_asm { pop esi }
_asm { pop ebp }
_asm { pop ebx }
_asm { add esp, 10h }
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be changed to use 0x10 instead of 10h for hexadecimal values.

if (unittype->DeploysInto != nullptr) {
objectcount += house->BQuantity.Count_Of((BuildingType)unittype->DeploysInto->Get_Heap_ID());
}
else if (unittypeext->TransformsInto != nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Reformat to;

    if (unittype->DeploysInto != nullptr) {
        objectcount += house->BQuantity.Count_Of((BuildingType)unittype->DeploysInto->Get_Heap_ID());
        
    } else if (unittypeext->TransformsInto != nullptr) {

* This unit can transform into another unit, increment the object count
* by the number of transformed units.
*/
objectcount += house->UQuantity.Count_Of((UnitType)(unittypeext->TransformsInto->Get_Heap_ID()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Be careful of such a large operation here. Check the assembly, hopefully, this only uses EAX for each operation.

*/
DECLARE_PATCH(_HouseClass_Can_Build_BuildLimit_Handle_Vehicle_Transform)
{
GET_REGISTER_STATIC(UnitTypeClass*, unittype, edi);
Copy link
Contributor

Choose a reason for hiding this comment

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

A space between the HouseClass/UnitTypeClass and * please.

*/
DECLARE_PATCH(_HouseClass_ShouldDisableCameo_BuildLimit_Fix)
{
GET_REGISTER_STATIC(FactoryClass*, factory, ecx);
Copy link
Contributor

Choose a reason for hiding this comment

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

A space between the FactoryClass/TechnoTypeClass and * please.

*
* Author: Rampastring
*/
int _HouseClass_ShouldDisableCameo_Get_Queued_Count(FactoryClass* factory, TechnoTypeClass* technotype)
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be best to move this to HouseClassExtension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants