diff --git a/CREDITS.md b/CREDITS.md index 7ca3132006..9616d31e06 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -717,6 +717,7 @@ This page lists all the individual contributions to the project by their author. - Fix an issue that the move mission of the jumpjet does not end correctly - Fix the issue that the Jumpjet must end its movement before starting the next mission - Taunt warhead + - Export interface for external call - **solar-III (凤九歌)** - Target scanning delay customization (documentation) - Skip target scanning function calling for unarmed technos (documentation) diff --git a/Phobos.vcxproj b/Phobos.vcxproj index d45a6ac91f..ac9389869b 100644 --- a/Phobos.vcxproj +++ b/Phobos.vcxproj @@ -30,6 +30,8 @@ + + @@ -221,6 +223,8 @@ + + diff --git a/README.md b/README.md index 52c77fe94d..e99a76ab2c 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,10 @@ Credits This project was founded by [@Belonit](https://github.com/Belonit) (Gluk-v48) and [@Metadorius](https://github.com/Metadorius) (Kerbiter) in 2020, with the first public stable release in 2021. Since then it has grown into a large community project with many contributors and maintainers. +### Interoperability + +Phobos has opened the external interfaces of some key components. If you are also developing your own engine extension and wish to use Phobos at the same time, please check out [Interop](https://github.com/Phobos-developers/Phobos/tree/develop/src/Interop). + ### Maintenance crew Maintenance crew consists of experienced Phobos contributors who are recognized and given the permission to maintain and shape the project to the extent of their permissions. diff --git a/docs/Whats-New.md b/docs/Whats-New.md index 30d14e66cf..ad1c142a9d 100644 --- a/docs/Whats-New.md +++ b/docs/Whats-New.md @@ -545,6 +545,7 @@ New: - [Taunt warhead](New-or-Enhanced-Logics.md#taunt-warhead) (by TaranDahl) - [Custom hover vehicles shutdown drowning death](New-or-Enhanced-Logics.md#custom-hover-vehicles-shutdown-drowning-death) (by FlyStar) - [SHP turret vehicles support the use of `*tur.shp` files](New-or-Enhanced-Logics.md#independent-shp-vehicle-turret-files) (by FlyStar) +- [Export interface for external call](index.md#interoperability) (by TaranDahl) Vanilla fixes: - Fixed sidebar not updating queued unit numbers when adding or removing units when the production is on hold (by CrimRecya) diff --git a/src/Interop/AttachEffect.cpp b/src/Interop/AttachEffect.cpp new file mode 100644 index 0000000000..007f9d5045 --- /dev/null +++ b/src/Interop/AttachEffect.cpp @@ -0,0 +1,109 @@ + +#include "AttachEffect.h" +#include "New/Entity/AttachEffectClass.h" +#include "New/Type/AttachEffectTypeClass.h" + +int __stdcall AE_Attach( + TechnoClass* pTarget, + HouseClass* pInvokerHouse, + TechnoClass* pInvoker, + AbstractClass* pSource, + const char** effectTypeNames, + int typeCount, + int durationOverride, + int delay, + int initialDelay, + int recreationDelay +) +{ + if (!pTarget || !effectTypeNames || typeCount <= 0) + return 0; + + AEAttachInfoTypeClass attachInfo; + + for (int i = 0; i < typeCount; i++) + { + if (effectTypeNames[i]) + { + if (auto pType = AttachEffectTypeClass::Find(effectTypeNames[i])) + attachInfo.AttachTypes.push_back(pType); + } + } + + if (attachInfo.AttachTypes.empty()) + return 0; + + if (durationOverride != 0) + attachInfo.DurationOverrides.push_back(durationOverride); + + if (delay >= 0) + attachInfo.Delays.push_back(delay); + + if (initialDelay >= 0) + attachInfo.InitialDelays.push_back(initialDelay); + + if (recreationDelay >= -1) + attachInfo.RecreationDelays.push_back(recreationDelay); + + return AttachEffectClass::Attach(pTarget, pInvokerHouse, pInvoker, pSource, attachInfo); +} + +int __stdcall AE_Detach( + TechnoClass* pTarget, + const char** effectTypeNames, + int typeCount +) +{ + if (!pTarget || !effectTypeNames || typeCount <= 0) + return 0; + + AEAttachInfoTypeClass detachInfo; + + for (int i = 0; i < typeCount; i++) + { + if (effectTypeNames[i]) + { + if (auto pType = AttachEffectTypeClass::Find(effectTypeNames[i])) + detachInfo.RemoveTypes.push_back(pType); + } + } + + if (detachInfo.RemoveTypes.empty()) + return 0; + + return AttachEffectClass::Detach(pTarget, detachInfo); +} + +int __stdcall AE_DetachByGroups( + TechnoClass* pTarget, + const char** groupNames, + int groupCount +) +{ + if (!pTarget || !groupNames || groupCount <= 0) + return 0; + + AEAttachInfoTypeClass detachInfo; + + for (int i = 0; i < groupCount; i++) + { + if (groupNames[i]) + detachInfo.RemoveGroups.push_back(groupNames[i]); + } + + if (detachInfo.RemoveGroups.empty()) + return 0; + + return AttachEffectClass::DetachByGroups(pTarget, detachInfo); +} + +void __stdcall AE_TransferEffects( + TechnoClass* pSource, + TechnoClass* pTarget +) +{ + if (!pSource || !pTarget) + return; + + AttachEffectClass::TransferAttachedEffects(pSource, pTarget); +} diff --git a/src/Interop/AttachEffect.h b/src/Interop/AttachEffect.h new file mode 100644 index 0000000000..95d2d8ac12 --- /dev/null +++ b/src/Interop/AttachEffect.h @@ -0,0 +1,50 @@ +#pragma once + +#include +#include +#include + +extern "C" +{ + /// + /// Attaches AttachEffect instances to a target unit. + /// + __declspec(dllexport) int __stdcall AE_Attach( + TechnoClass* pTarget, + HouseClass* pInvokerHouse, + TechnoClass* pInvoker, + AbstractClass* pSource, + const char** effectTypeNames, + int typeCount, + int durationOverride, + int delay, + int initialDelay, + int recreationDelay + ); + + /// + /// Removes AttachEffect instances matching given types from a unit. + /// + __declspec(dllexport) int __stdcall AE_Detach( + TechnoClass* pTarget, + const char** effectTypeNames, + int typeCount + ); + + /// + /// Removes AttachEffect instances matching given groups from a unit. + /// + __declspec(dllexport) int __stdcall AE_DetachByGroups( + TechnoClass* pTarget, + const char** groupNames, + int groupCount + ); + + /// + /// Transfers AttachEffect instances from one unit to another. + /// + __declspec(dllexport) void __stdcall AE_TransferEffects( + TechnoClass* pSource, + TechnoClass* pTarget + ); +} diff --git a/src/Interop/TechnoExt.cpp b/src/Interop/TechnoExt.cpp new file mode 100644 index 0000000000..959d9216e4 --- /dev/null +++ b/src/Interop/TechnoExt.cpp @@ -0,0 +1,7 @@ +#include "TechnoExt.h" +#include + +extern "C" __declspec(dllexport) bool __stdcall ConvertToType_Phobos(FootClass* pThis, TechnoTypeClass* toType) +{ + return TechnoExt::ConvertToType(pThis, toType); +} diff --git a/src/Interop/TechnoExt.h b/src/Interop/TechnoExt.h new file mode 100644 index 0000000000..90ec6c460e --- /dev/null +++ b/src/Interop/TechnoExt.h @@ -0,0 +1,15 @@ +#pragma once + +#include +#include + +extern "C" +{ + /// + /// Converts a unit to a different type. + /// + /// Pointer to the FootClass instance to convert + /// Pointer to the target TechnoTypeClass + /// true if conversion was successful, false otherwise + __declspec(dllexport) bool __stdcall ConvertToType_Phobos(FootClass* pThis, TechnoTypeClass* toType); +}