Browse Source

Add spawning support to the world component

pull/8/head
Anton Tarasenko 2 years ago
parent
commit
b32f52abf0
  1. 19
      sources/Gameplay/BaseClasses/Frontend/World/AWorldComponent.uc
  2. 30
      sources/Gameplay/BaseClasses/Frontend/World/TracingIterator.uc
  3. 26
      sources/Gameplay/KF1Frontend/World/KF1_WorldComponent.uc

19
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
{
}

30
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`,

26
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<Actor> actorClass;
local ServerLevelCore core;
actorClass = class<Actor>(_.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

Loading…
Cancel
Save