diff --git a/Content/Tangibles/TangibleCharacter.uasset b/Content/Tangibles/TangibleCharacter.uasset index f904704a..5b097651 100644 --- a/Content/Tangibles/TangibleCharacter.uasset +++ b/Content/Tangibles/TangibleCharacter.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d0b118706fa908857aa5263c9ee31998b98cbcde6148b0c14ff16c49e5c77419 -size 453893 +oid sha256:d72a8140e97dfc027f4809904d17655cc1010bc184f6f40bdd0e3162fd211a53 +size 448186 diff --git a/Source/Integration/IntegrationGameModeBase.cpp b/Source/Integration/IntegrationGameModeBase.cpp index 7f71b30b..e47ddfa0 100644 --- a/Source/Integration/IntegrationGameModeBase.cpp +++ b/Source/Integration/IntegrationGameModeBase.cpp @@ -120,6 +120,12 @@ void AIntegrationGameModeBase::UpdateTangibles() { for (int i = 0; i < alltans.Num(); i++) { alltans[i]->UpdateAnimationQueue(allqueues[i]); } + + // Maybe call 'BecomePossessed' on some tangible. + UlxTangible *poss = TangibleManager->SetPossessedTangible(PlayerId); + if (poss != nullptr) { + IlxTangibleInterface::Execute_BecomePossessed(poss->GetActor()); + } } // This is where we run the blueprint code that updates animation // states. Be aware that the blueprint code could call back diff --git a/Source/Integration/Tangible.cpp b/Source/Integration/Tangible.cpp index eac680f4..3d5b500e 100644 --- a/Source/Integration/Tangible.cpp +++ b/Source/Integration/Tangible.cpp @@ -52,7 +52,13 @@ void UlxTangible::SetActorBlueprint(const FString &name) { // Now destroy the actor itself. According to various // documents I've read online, it may be necessary to take // further steps to delete the object. Not clear. - CurrentActor->Destroy(); + CurrentActor->Destroy(); + + // If this actor previously was posessed by a player controller, + // then it's not posessed anymore, because there is no actor any more. + if (Manager->PossessedTangible == this) { + Manager->PossessedTangible = nullptr; + }; } // Update the blueprint name diff --git a/Source/Integration/Tangible.h b/Source/Integration/Tangible.h index 22096c5a..eabff0fe 100644 --- a/Source/Integration/Tangible.h +++ b/Source/Integration/Tangible.h @@ -34,6 +34,9 @@ class INTEGRATION_API IlxTangibleInterface public: UFUNCTION(BlueprintImplementableEvent, Category = "Tangible Functionality") bool AnimationStateChanged(); + + UFUNCTION(BlueprintImplementableEvent, Category = "Tangible Functionality") + void BecomePossessed(); }; diff --git a/Source/Integration/TangibleManager.cpp b/Source/Integration/TangibleManager.cpp index 9649084f..7947d9a3 100644 --- a/Source/Integration/TangibleManager.cpp +++ b/Source/Integration/TangibleManager.cpp @@ -35,6 +35,7 @@ UClass *UlxTangibleManager::GetTangibleClass(const FString &name) { UlxTangibleManager::UlxTangibleManager() { World = nullptr; + PossessedTangible = nullptr; } void UlxTangibleManager::Init(UWorld* world, AIntegrationGameModeBase *gamemode) { @@ -53,6 +54,7 @@ UlxTangible* UlxTangibleManager::GetTangible(int64 id) const { #pragma optimize("", off) UlxTangible* UlxTangibleManager::MakeTangible(int64 id) { + check(id > 0); UlxTangible*& t = IdToTangible.FindOrAdd(id); if (t == nullptr) { t = NewObject(); @@ -75,6 +77,19 @@ TanArray UlxTangibleManager::GetAllTangibles() const { return result; } +UlxTangible *UlxTangibleManager::SetPossessedTangible(int64 id) { + UlxTangible *t = GetTangible(id); + if ((t == nullptr) || (t->GetActor() == nullptr)) { + PossessedTangible = nullptr; + return nullptr; + } else if (t == PossessedTangible) { + return nullptr; + } else { + PossessedTangible = t; + return t; + } +} + #pragma optimize("", off) void UlxTangibleManager::UpdateNearAccordingToLuprex(IdView near) { // Clear all the 'NearAccordingToLuprex' flags. diff --git a/Source/Integration/TangibleManager.h b/Source/Integration/TangibleManager.h index 4711d982..bb75ed5a 100644 --- a/Source/Integration/TangibleManager.h +++ b/Source/Integration/TangibleManager.h @@ -33,6 +33,9 @@ public: UPROPERTY() TMap IdToTangible; + // The Tangible ID of the posessed tangible, if any. + UlxTangible *PossessedTangible; + public: UlxTangibleManager(); @@ -63,6 +66,19 @@ public: // TanArray GetAllTangibles() const; + // Set the currently-posessed tangible. + // + // If the specified tangible is invalid: + // Sets the possessed tangible to nullptr and returns nullptr. + // + // If the specified tangible is valid, but it's already possessed: + // Does nothing and returns nullptr. + // + // If the specified tangible is valid, and is not already possessed: + // Sets the possessed tangible as specified and returns it. + // + UlxTangible *SetPossessedTangible(int64 playerid); + // Update the 'NearAccordingToLuprex' flags. // // Also creates stub tangibles for every Id in the list.