public ChunkHelper(LevelGeneratorPreset preset) { this.preset = preset; chunkMetaData = new List <ChunkMetadata> (); BuildMetadata(Resources.LoadAll <GameObject> (GlobalPaths.RelativeChunkPath)); this.progress = new ChunkHelperProgress(preset); }
//Other than IsConstraintSatisfied, this method depends on the current context of the chunk generation //Returns true, if the ConstraintAmount has not YET been satisfied public bool HandleRoomAmount(ChunkMetadata meta, ChunkHelperProgress progress, bool previousResult) { float remaining = progress.Remaining(target) + 0.0001f; //Remaining rooms that need be created float priorityBonus = (absoluteAmount / remaining); //A chunk gets a priority bonus if the constrain is satisfied and not all chunks have been created int wantedAmount = GetAmountValue(progress.TotalRoomCount(target)); bool enoughCreated = matchingChunksUsed >= wantedAmount; meta.Priority += previousResult && !enoughCreated ? priorityBonus: 0f; if (previousResult) { meta.RegisterAsMatching(this); //Registers this constraint at the chunkmeta and will be notified, if the chunk has been created } bool stillSatisfied = true; switch (amount) { case ConstraintAmount.AtLeast: stillSatisfied = true; //Allways true, since there is no upper limit break; case ConstraintAmount.Exactly: //Exactly and AtMost are handled identically. case ConstraintAmount.AtMost: //The upper amount for AtMost is randomly specified in the GetAmountMethod stillSatisfied = !previousResult || (previousResult && !enoughCreated); break; } return(stillSatisfied); }
//Used only for Chunks by the ChunkHelper Class public bool IsConstraintSatisfied(ChunkMetadata meta, ChunkHelperProgress progress) { ChunkTags chunkTags = meta.Chunk.GetComponent <ChunkTags> (); bool result = ConstraintResult(chunkTags); if (amount == ConstraintAmount.None) { //Eventhough the amount is none, we don't want to return false //If the result was true, meaning the constraint applies to this chunk, we want to negate it to false //This will result in the chunk not being used. If the result was false before, this means that this constraint //Doesn't apply to the given chunk, meaning, that we don't want to affect it's creation by returning false, thus returning true result = !result; } else if (amount != ConstraintAmount.All) { result = HandleRoomAmount(meta, progress, result); } return(result); }