Skip to content

Commit

Permalink
add flags to getRandomEntryFromBestiary to ignore settlement or bio…
Browse files Browse the repository at this point in the history
…me rules
  • Loading branch information
Aelto committed Jul 25, 2021
1 parent 7beabc3 commit a20a932
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 148 deletions.
29 changes: 24 additions & 5 deletions src/bestiary/bestiary.ws
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RER_Bestiary {
}
}

public latent function getRandomEntryFromBestiary(master: CRandomEncounters, encounter_type: EncounterType, optional for_bounty: bool, optional left_offset: CreatureType, optional right_offset: CreatureType, optional offset_multiplier: float): RER_BestiaryEntry {
public latent function getRandomEntryFromBestiary(master: CRandomEncounters, encounter_type: EncounterType, optional flags: RER_BestiaryRandomBestiaryEntryFlag, optional filter: RER_SpawnRollerFilter): RER_BestiaryEntry {
var creatures_preferences: RER_CreaturePreferences;
var spawn_roll: SpawnRoller_Roll;
var manager : CWitcherJournalManager;
Expand All @@ -32,15 +32,26 @@ class RER_Bestiary {
creatures_preferences
.setCurrentRegion(AreaTypeToName(theGame.GetCommonMapManager().GetCurrentArea()));

if (!for_bounty) {
if ((flags & RER_BREF_IGNORE_BIOMES) == 0) {
creatures_preferences
.setIsNight(theGame.envMgr.IsNight())
.setExternalFactorsCoefficient(master.settings.external_factors_coefficient)
.setIsNearWater(master.rExtra.IsPlayerNearWater())
.setIsInForest(master.rExtra.IsPlayerInForest())
.setIsInSwamp(master.rExtra.IsPlayerInSwamp())
.setIsInSwamp(master.rExtra.IsPlayerInSwamp());
}
else {
NLOG("getRandomEntryFromBestiary - ignore biomes");
}

if ((flags & RER_BREF_IGNORE_SETTLEMENT) == 0) {

creatures_preferences
.setIsInCity(master.rExtra.isPlayerInSettlement() || master.rExtra.getCustomZone(thePlayer.GetWorldPosition()) == REZ_CITY);
}
else {
NLOG("getRandomEntryFromBestiary - ignore settlement");
}

for (i = 0; i < CreatureMAX; i += 1) {
this.entries[i]
Expand Down Expand Up @@ -68,7 +79,9 @@ class RER_Bestiary {
}
}

master.spawn_roller.setOffsets(left_offset, right_offset, offset_multiplier);
if (filter) {
master.spawn_roller.applyFilter(filter);
}

spawn_roll = master.spawn_roller.rollCreatures(
master.ecosystem_manager,
Expand Down Expand Up @@ -256,4 +269,10 @@ class RER_Bestiary {



}
}

enum RER_BestiaryRandomBestiaryEntryFlag {
RER_BREF_NONE = 0,
RER_BREF_IGNORE_SETTLEMENT = 10,
RER_BREF_IGNORE_BIOMES = 01
};
12 changes: 8 additions & 4 deletions src/bounty/bounty_manager.ws
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,14 @@ statemachine class RER_BountyManager extends CEntity {
current_bestiary_entry = this.master.bestiary.getRandomEntryFromBestiary(
this.master,
EncounterType_CONTRACT,
true,
CreatureDRACOLIZARD,
CreatureMAX,
0.1 // creature outside the offset have -90% chance to appear
RER_BREF_IGNORE_BIOMES | RER_BREF_IGNORE_SETTLEMENT,
(new RER_SpawnRollerFilter in this)
.init()
.setOffsets(
CreatureDRACOLIZARD,
CreatureMAX,
0.1 // creature outside the offset have -90% chance to appear
)
);

current_group_data.type = current_bestiary_entry.type;
Expand Down
5 changes: 3 additions & 2 deletions src/compositions/contract.ws
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ class CreatureContractComposition extends CompositionSpawner {
this.master,
EncounterType_CONTRACT,
, // for bounty
CreatureDRACOLIZARD, // left offset
CreatureMAX // right offset
(new RER_SpawnRollerFilter in this)
.init()
.setOffsets(CreatureDRACOLIZARD, CreatureMAX)
);

this
Expand Down
5 changes: 3 additions & 2 deletions src/entities/contract/states/phases/ambush.ws
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ state Ambush in RandomEncountersReworkedContractEntity {
parent.master,
EncounterType_CONTRACT,
, // for bounty
CreatureHUMAN, // left offset
CreatureDRACOLIZARD // right offset
(new RER_SpawnRollerFilter in parent)
.init()
.setOffsets(CreatureDRACOLIZARD, CreatureMAX)
);

parent.entities = bestiary_entry.spawn(
Expand Down
5 changes: 3 additions & 2 deletions src/entities/contract/states/phases/npc_rescue.ws
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ state NpcRescue in RandomEncountersReworkedContractEntity {
parent.master,
EncounterType_CONTRACT,
, // for bounty
CreatureHUMAN, // left offset
CreatureDRACOLIZARD // right offset
(new RER_SpawnRollerFilter in parent)
.init()
.setOffsets(CreatureDRACOLIZARD, CreatureMAX)
);

parent.entities = bestiary_entry.spawn(
Expand Down
5 changes: 3 additions & 2 deletions src/entities/contract/states/phases/trail_combat.ws
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ state TrailCombat in RandomEncountersReworkedContractEntity extends TrailPhase {
parent.master,
EncounterType_CONTRACT,
, // for bounty
CreatureHUMAN, // left offset
CreatureDRACOLIZARD // right offset
(new RER_SpawnRollerFilter in parent)
.init()
.setOffsets(CreatureDRACOLIZARD, CreatureMAX)
);

parent.entities = bestiary_entry.spawn(
Expand Down
136 changes: 41 additions & 95 deletions src/entities/nest/nest_entity.ws
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,17 @@ statemachine class RER_MonsterNest extends CMonsterNestEntity {
SUH_makeEntitiesTargetPlayer(this.entities);
}

event OnFireHit(source: CGameplayEntity) {}
event OnFireHit(source: CGameplayEntity) {
if (this.monsters_spawned_count > this.monsters_spawned_limit * 0.75) {
GetEncounter();
wasExploded = true;

interactionComponent.SetEnabled( false );
airDmg = false;

this.GotoState('Explosion');
}
}
event OnAardHit(sign: W3AardProjectile) {}

event OnInteraction(actionName: string, activator: CEntity) {
Expand Down Expand Up @@ -123,101 +133,37 @@ statemachine class RER_MonsterNest extends CMonsterNestEntity {
return true;
}

private latent function getRandomNestCreatureType(master: CRandomEncounters): CreatureType {
var spawn_roller: SpawnRoller;
var creatures_preferences: RER_CreaturePreferences;
var i: int;
var can_spawn_creature: bool;
var manager : CWitcherJournalManager;
var roll: SpawnRoller_Roll;

spawn_roller = new SpawnRoller in this;
spawn_roller.fill_arrays();

creatures_preferences = new RER_CreaturePreferences in this;
creatures_preferences
.setIsNight(theGame.envMgr.IsNight())
.setExternalFactorsCoefficient(master.settings.external_factors_coefficient)
.setIsNearWater(master.rExtra.IsPlayerNearWater())
.setIsInForest(master.rExtra.IsPlayerInForest())
.setIsInSwamp(master.rExtra.IsPlayerInSwamp())
.setIsInCity(master.rExtra.isPlayerInSettlement() || master.rExtra.getCustomZone(thePlayer.GetWorldPosition()) == REZ_CITY)
.setCurrentRegion(AreaTypeToName(theGame.GetCommonMapManager().GetCurrentArea()));

creatures_preferences
.reset();

master.bestiary.entries[CreatureGHOUL]
.setCreaturePreferences(creatures_preferences, EncounterType_DEFAULT)
.fillSpawnRoller(spawn_roller);

master.bestiary.entries[CreatureALGHOUL]
.setCreaturePreferences(creatures_preferences, EncounterType_DEFAULT)
.fillSpawnRoller(spawn_roller);

master.bestiary.entries[CreatureDROWNER]
.setCreaturePreferences(creatures_preferences, EncounterType_DEFAULT)
.fillSpawnRoller(spawn_roller);

master.bestiary.entries[CreatureDROWNERDLC]
.setCreaturePreferences(creatures_preferences, EncounterType_DEFAULT)
.fillSpawnRoller(spawn_roller);

master.bestiary.entries[CreatureROTFIEND]
.setCreaturePreferences(creatures_preferences, EncounterType_DEFAULT)
.fillSpawnRoller(spawn_roller);

master.bestiary.entries[CreatureARACHAS]
.setCreaturePreferences(creatures_preferences, EncounterType_DEFAULT)
.fillSpawnRoller(spawn_roller);

master.bestiary.entries[CreatureENDREGA]
.setCreaturePreferences(creatures_preferences, EncounterType_DEFAULT)
.fillSpawnRoller(spawn_roller);

master.bestiary.entries[CreatureNEKKER]
.setCreaturePreferences(creatures_preferences, EncounterType_DEFAULT)
.fillSpawnRoller(spawn_roller);

master.bestiary.entries[CreatureHARPY]
.setCreaturePreferences(creatures_preferences, EncounterType_DEFAULT)
.fillSpawnRoller(spawn_roller);

master.bestiary.entries[CreatureSPIDER]
.setCreaturePreferences(creatures_preferences, EncounterType_DEFAULT)
.fillSpawnRoller(spawn_roller);

master.bestiary.entries[CreatureCENTIPEDE]
.setCreaturePreferences(creatures_preferences, EncounterType_DEFAULT)
.fillSpawnRoller(spawn_roller);

master.bestiary.entries[CreatureECHINOPS]
.setCreaturePreferences(creatures_preferences, EncounterType_DEFAULT)
.fillSpawnRoller(spawn_roller);

master.bestiary.entries[CreatureKIKIMORE]
.setCreaturePreferences(creatures_preferences, EncounterType_DEFAULT)
.fillSpawnRoller(spawn_roller);

master.bestiary.entries[CreatureSIREN]
.setCreaturePreferences(creatures_preferences, EncounterType_DEFAULT)
.fillSpawnRoller(spawn_roller);

// we remove every unknown creatures from the spawning pool
if (master.settings.only_known_bestiary_creatures) {
manager = theGame.GetJournalManager();

for (i = 0; i < CreatureMAX; i += 1) {
can_spawn_creature = bestiaryCanSpawnEnemyTemplateList(master.bestiary.entries[i].template_list, manager);

if (!can_spawn_creature) {
spawn_roller.setCreatureCounter(i, 0);
}
}
}
latent function getRandomNestCreatureType(master: CRandomEncounters): RER_BestiaryEntry {
var bentry: RER_BestiaryEntry;

bentry = master.bestiary.getRandomEntryFromBestiary(
master,
EncounterType_CONTRACT,
RER_BREF_IGNORE_SETTLEMENT,
(new RER_SpawnRollerFilter in this)
.init()
.removeEveryone()
.allowCreature(CreatureARACHAS)
.allowCreature(CreatureENDREGA)
.allowCreature(CreatureGHOUL)
.allowCreature(CreatureALGHOUL)
.allowCreature(CreatureNEKKER)
.allowCreature(CreatureDROWNER)
.allowCreature(CreatureROTFIEND)
.allowCreature(CreatureWOLF)
.allowCreature(CreatureHARPY)
.allowCreature(CreatureSPIDER)
.allowCreature(CreatureCENTIPEDE)
.allowCreature(CreatureDROWNERDLC)
.allowCreature(CreatureBOAR)
.allowCreature(CreatureECHINOPS)
.allowCreature(CreatureKIKIMORE)
.allowCreature(CreatureSKELWOLF)
.allowCreature(CreatureSIREN)
.allowCreature(CreatureWRAITH)
);

roll = spawn_roller.rollCreatures(master.ecosystem_manager);
return roll.roll;
return bentry;
}

timer function intervalLifeCheck(optional dt : float, optional id : Int32) {
Expand Down
15 changes: 8 additions & 7 deletions src/entities/nest/states/loading.ws
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ state Loading in RER_MonsterNest {
}

entry function Loading_main() {
parent.bestiary_entry = parent.master.bestiary.getRandomEntryFromBestiary(
parent.master,
EncounterType_HUNTINGGROUND,
false,
CreatureARACHAS, // left offset
CreatureDRACOLIZARD // right offset
);
parent.bestiary_entry = parent.getRandomNestCreatureType(parent.master);

if (parent.bestiary_entry.type == CreatureARACHAS ) {
parent.monsters_spawned_limit /= 3;
}
if (parent.bestiary_entry.type == CreatureWRAITH) {
parent.monsters_spawned_limit /= 2;
}

this.placeMarker();

Expand Down
8 changes: 1 addition & 7 deletions src/entities/nest/states/spawning.ws
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ state Spawning in RER_MonsterNest {

entry function Spawning_main() {
if (!parent.bestiary_entry) {
parent.bestiary_entry = parent.master.bestiary.getRandomEntryFromBestiary(
parent.master,
EncounterType_HUNTINGGROUND,
false,
CreatureARACHAS, // left offset
CreatureDRACOLIZARD // right offset
);
parent.bestiary_entry = parent.getRandomNestCreatureType(parent.master);
}

// start by spawning a few monsters around the nest
Expand Down
Loading

0 comments on commit a20a932

Please sign in to comment.