diff --git a/sources/Gameplay/BaseClasses/Frontend/World/AWorldComponent.uc b/sources/Gameplay/BaseClasses/Frontend/World/AWorldComponent.uc index 803155f..3795bd9 100644 --- a/sources/Gameplay/BaseClasses/Frontend/World/AWorldComponent.uc +++ b/sources/Gameplay/BaseClasses/Frontend/World/AWorldComponent.uc @@ -71,6 +71,25 @@ public function TracingIterator TracePlayerSight(EPlayer player); */ public function TracingIterator TraceSight(EPawn pawn); +// TODO: Add `CanSpawnExplain()` method +/** + * Spawns a new `EPlaceable` based on the given `template` at a given location + * `location`, facing it into the given direction `direction`. + * + * @param template Describes entity (supporting `EPlaceable` interface) to + * spawn into the world. + * @param location At what location to spawn that entity. + * @param direction In what direction spawned entity must face. + * @return `EPlaceable` interface for the spawned entity. `none` if spawning it + * has failed. If method returns interface to a non-existent entity, it + * means that entity has successfully spawned, but then something handled + * its spawning and destroyed it. + */ +public function EPlaceable Spawn( + BaseText template, + optional Vector location, + optional Rotator direction); + defaultproperties { } \ No newline at end of file diff --git a/sources/Gameplay/BaseClasses/Frontend/World/TracingIterator.uc b/sources/Gameplay/BaseClasses/Frontend/World/TracingIterator.uc index ec01ddc..0a9f30c 100644 --- a/sources/Gameplay/BaseClasses/Frontend/World/TracingIterator.uc +++ b/sources/Gameplay/BaseClasses/Frontend/World/TracingIterator.uc @@ -36,17 +36,7 @@ public function AcediaObject Get() { return none; } * currently at. Origin vector (with all coordinates set to `0.0`) if * iteration has already finished. */ -public function Vector GetHitLocation() -{ - if (!initialized) { - return Vect(0.0f, 0.0f, 0.0f); - } - TryTracing(); - if (HasFinished()) { - return Vect(0.0f, 0.0f, 0.0f); - } - return hitLocations[currentIndex]; -} +public function Vector GetHitLocation(); /** * Returns hit normal for the `EPlaceable` that `TracingIterator` is @@ -56,17 +46,7 @@ public function Vector GetHitLocation() * currently at. Origin vector (with all coordinates set to `0.0`) if * iteration has already finished. */ -public function Vector GetHitNormal() -{ - if (!initialized) { - return Vect(0.0f, 0.0f, 0.0f); - } - TryTracing(); - if (HasFinished()) { - return Vect(0.0f, 0.0f, 0.0f); - } - return hitNormals[currentIndex]; -} +public function Vector GetHitNormal(); /** * Returns `EPlaceable` caller `TracingIterator` is currently at. @@ -77,11 +57,7 @@ public function Vector GetHitNormal() * * @return `EPlaceable` caller `TracingIterator` is currently at. */ -public function EPlaceable GetPlaceable() -{ - // We only create `EPlaceable` child classes in this class - return EPlaceable(Get()); -} +public function EPlaceable GetPlaceable(); /** * Returns `EPlaceable` caller `TracingIterator` is currently at as `EPawn`, diff --git a/sources/Gameplay/KF1Frontend/World/KF1_WorldComponent.uc b/sources/Gameplay/KF1Frontend/World/KF1_WorldComponent.uc index 25e600c..059b676 100644 --- a/sources/Gameplay/KF1Frontend/World/KF1_WorldComponent.uc +++ b/sources/Gameplay/KF1Frontend/World/KF1_WorldComponent.uc @@ -84,6 +84,32 @@ public function TracingIterator TraceSight(EPawn pawn) return TraceBetween(start, end); } +public function EPlaceable Spawn( + BaseText template, + optional Vector location, + optional Rotator direction) +{ + local Actor result; + local Pawn resultPawn; + local class actorClass; + local ServerLevelCore core; + + actorClass = class(_.memory.LoadClass(template)); + if (actorClass == none) { + return none; + } + core = ServerLevelCore(class'ServerLevelCore'.static.GetInstance()); + result = core.Spawn(actorClass,,, location, direction); + if (result == none) { + return none; + } + resultPawn = Pawn(result); + if (resultPawn != none) { + return class'EKFPawn'.static.Wrap(resultPawn); + } + return class'EKFUnknownPlaceable'.static.Wrap(resultPawn); +} + defaultproperties { tracingDistance = 10000