Skip to content

Commit

Permalink
#66 avoid unnecessary calls when spawning static encounters
Browse files Browse the repository at this point in the history
  • Loading branch information
Aelto committed May 2, 2022
1 parent d92e606 commit 2ba1654
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
24 changes: 18 additions & 6 deletions src/static_encounters/states/spawning.ws
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@ state Spawning in RER_StaticEncounterManager {

public latent function spawnStaticEncounters(master: CRandomEncounters) {
var player_position: Vector;
var current_region: string;
var max_distance: float;
var large_chance: float;
var small_chance: float;
var has_spawned: bool;
var i: int;

if (isPlayerBusy()) {
return;
}

current_region = AreaTypeToName(theGame.GetCommonMapManager().GetCurrentArea());

max_distance = StringToFloat(theGame.GetInGameConfigWrapper().GetVarValue('RERencountersGeneral', 'minSpawnDistance'))
+ StringToFloat(theGame.GetInGameConfigWrapper().GetVarValue('RERencountersGeneral', 'spawnDiameter'));

Expand All @@ -35,7 +42,8 @@ state Spawning in RER_StaticEncounterManager {
player_position,
max_distance,
small_chance,
large_chance
large_chance,
current_region
);

SleepOneFrame();
Expand All @@ -49,14 +57,15 @@ state Spawning in RER_StaticEncounterManager {
player_position,
max_distance,
small_chance,
large_chance
large_chance,
current_region
);
}

private latent function trySpawnStaticEncounter(master: CRandomEncounters, encounter: RER_StaticEncounter, player_position: Vector, max_distance: float, small_chance: float, large_chance: float): bool {
private latent function trySpawnStaticEncounter(master: CRandomEncounters, encounter: RER_StaticEncounter, player_position: Vector, max_distance: float, small_chance: float, large_chance: float, current_region: string): bool {
var composition: CreatureHuntingGroundComposition;

if (!encounter.canSpawn(player_position, small_chance, large_chance, max_distance)) {
if (!encounter.canSpawn(player_position, small_chance, large_chance, max_distance, current_region)) {
return false;
}

Expand All @@ -70,7 +79,7 @@ state Spawning in RER_StaticEncounterManager {
return true;
}

private latent function spawnPlaceholderStaticEncounters(master: CRandomEncounters, player_position: Vector, max_distance: float, small_chance: float, large_chance: float) {
private latent function spawnPlaceholderStaticEncounters(master: CRandomEncounters, player_position: Vector, max_distance: float, small_chance: float, large_chance: float, current_region: string) {
var placeholder_static_encounter: RER_PlaceholderStaticEncounter;
var rng: RandomNumberGenerator;
var positions: array<Vector>;
Expand All @@ -84,6 +93,8 @@ state Spawning in RER_StaticEncounterManager {
NLOG("spawnPlaceholderStaticEncounters(), found " + positions.Size() + " available point of interests for placeholder static encounters");

for (i = 0; i < positions.Size(); i += 1) {
SleepOneFrame();

current_position = positions[i];

can_spawn = RER_placeholderStaticEncounterCanSpawnAtPosition(
Expand All @@ -106,7 +117,8 @@ state Spawning in RER_StaticEncounterManager {
player_position,
max_distance,
small_chance,
large_chance
large_chance,
current_region
);
}

Expand Down
9 changes: 1 addition & 8 deletions src/static_encounters/static_encounter.ws
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,11 @@ class RER_StaticEncounter {
return true;
}

public function canSpawn(player_position: Vector, small_chance: float, large_chance: float, max_distance: float): bool {
public function canSpawn(player_position: Vector, small_chance: float, large_chance: float, max_distance: float, current_region: string): bool {
var entities: array<CGameplayEntity>;
var current_region: string;
var radius: float;
var i: int;

if (isPlayerBusy()) {
return false;
}

current_region = AreaTypeToName(theGame.GetCommonMapManager().GetCurrentArea());

if (!this.isInRegion(current_region)) {
return false;
}
Expand Down

0 comments on commit 2ba1654

Please sign in to comment.