public bool Reroll(Func <RandomLevelData, bool> requirements) { TileConnection requirement = TileConnection.None; if (this.data.up && this.up != null && this.up.data != null) { requirement |= TileConnection.Up; } if (this.data.down && this.down != null && this.down.data != null) { requirement |= TileConnection.Down; } if (this.data.left && this.left != null && this.left.data != null) { requirement |= TileConnection.Left; } if (this.data.right && this.right != null && this.right.data != null) { requirement |= TileConnection.Right; } RandomLevelData tile = LevelGenerator.GetTile(requirement, this.data, type: LevGenType.Deathmatch, lambdaReq: requirements); if (tile == null) { return(false); } this.data = tile; if (this.symmetricalPartner != null) { this.symmetricalPartner.data = tile.Flipped(); } return(true); }
public TestArea(Editor editor, string level, int seed = 0, RandomLevelData center = null) { this._editor = editor; this._level = level; this._seed = seed; this._center = center; }
public RandomLevelData Symmetric() { RandomLevelData randomLevelData = new RandomLevelData() { data = this.data, flip = this.flip, left = this.right, right = this.left, up = this.up, down = this.down, symmetry = true, file = this.file, canMirror = this.canMirror, isMirrored = this.isMirrored }; randomLevelData.right = randomLevelData.left; randomLevelData.chance = this.chance; randomLevelData.max = this.max; randomLevelData.numWeapons = this.numWeapons; randomLevelData.numSuperWeapons = this.numSuperWeapons; randomLevelData.numFatalWeapons = this.numFatalWeapons; randomLevelData.numPermanentWeapons = this.numPermanentWeapons; randomLevelData.numPermanentSuperWeapons = this.numPermanentSuperWeapons; randomLevelData.numPermanentFatalWeapons = this.numPermanentFatalWeapons; randomLevelData.numArmor = this.numArmor; randomLevelData.numEquipment = this.numEquipment; randomLevelData.numSpawns = this.numSpawns; randomLevelData.numTeamSpawns = this.numTeamSpawns; randomLevelData.numLockedDoors = this.numLockedDoors; randomLevelData.numKeys = this.numKeys; return(randomLevelData); }
public void SolveSymmetry() { if (this.mirror) { if (this.leftSymmetric) { if (this.left == null || this.left.data == null || this.right == null) { return; } this.right.data = this.left.data.Flipped(); this.right.symmetricalPartner = this.left; this.left.symmetricalPartner = this.right; } else { if (this.right == null || this.right.data == null || this.left == null) { return; } this.left.data = this.right.data.Flipped(); this.right.symmetricalPartner = this.left; this.left.symmetricalPartner = this.right; } } else { if (this.data == null) { return; } if (this.removeRight && this.right != null) { this.right.data = this.data.Flipped(); this.right.symmetricalPartner = this; this.symmetricalPartner = this.right; } if (!this.removeLeft || this.left == null) { return; } this.left.data = this.data.Flipped(); this.left.symmetricalPartner = this; this.symmetricalPartner = this.left; } }
public DuckGameTestArea( Editor editor, string level, int seed = 0, RandomLevelData center = null, LevGenType genType = LevGenType.Any) : base(level) { this._editor = editor; DeathmatchLevel._started = true; this._followCam.lerpMult = 1.1f; this._seed = seed; this._center = center; this._genType = genType; this._levelValue = level; DuckGameTestArea.currentEditor = editor; }
public RandomLevelData Combine(RandomLevelData dat) { RandomLevelData randomLevelData = new RandomLevelData(); BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; foreach (FieldInfo field in this.GetType().GetFields(bindingAttr)) { if (field.FieldType == typeof(int)) { field.SetValue((object)randomLevelData, (object)((int)field.GetValue((object)this) + (int)field.GetValue((object)dat))); } if (field.FieldType.IsGenericType && field.FieldType.GetGenericTypeDefinition() == typeof(Dictionary <,>)) { Dictionary <System.Type, int> dictionary1 = field.GetValue((object)this) as Dictionary <System.Type, int>; Dictionary <System.Type, int> dictionary2 = field.GetValue((object)dat) as Dictionary <System.Type, int>; Dictionary <System.Type, int> dictionary3 = new Dictionary <System.Type, int>(); foreach (KeyValuePair <System.Type, int> keyValuePair in dictionary1) { if (!dictionary3.ContainsKey(keyValuePair.Key)) { dictionary3[keyValuePair.Key] = 0; } Dictionary <System.Type, int> dictionary4; System.Type key; (dictionary4 = dictionary3)[key = keyValuePair.Key] = dictionary4[key] + keyValuePair.Value; } foreach (KeyValuePair <System.Type, int> keyValuePair in dictionary2) { if (!dictionary3.ContainsKey(keyValuePair.Key)) { dictionary3[keyValuePair.Key] = 0; } Dictionary <System.Type, int> dictionary4; System.Type key; (dictionary4 = dictionary3)[key = keyValuePair.Key] = dictionary4[key] + keyValuePair.Value; } field.SetValue((object)randomLevelData, (object)dictionary3); } } return(randomLevelData); }
private static bool TryReroll( RandomLevelData combined, List <RandomLevelNode> available, Func <RandomLevelData, bool> problem, Func <RandomLevelData, bool> solution, RandomLevelNode specific = null) { if (available.Count == 0 && specific == null) { return(false); } if (problem(combined)) { List <RandomLevelNode> randomLevelNodeList = new List <RandomLevelNode>(); if (specific != null) { randomLevelNodeList.Add(specific); } else { randomLevelNodeList.AddRange((IEnumerable <RandomLevelNode>)available); } do { RandomLevelNode randomLevelNode = randomLevelNodeList[Rando.Int(randomLevelNodeList.Count - 1)]; if (randomLevelNode.Reroll(solution)) { available.Remove(randomLevelNode); goto label_10; } else { randomLevelNodeList.Remove(randomLevelNode); } }while (randomLevelNodeList.Count != 0); return(false); } label_10: return(true); }
private RandomLevelData Combine() { this.visited = true; RandomLevelData dat = new RandomLevelData(); if (this.left != null && this.left.data != null && !this.left.visited) { dat = this.left.data.Combine(dat); } if (this.right != null && this.right.data != null && !this.right.visited) { dat = this.right.data.Combine(dat); } if (this.up != null && this.up.data != null && !this.up.visited) { dat = this.up.data.Combine(dat); } if (this.down != null && this.down.data != null && !this.down.visited) { dat = this.down.data.Combine(dat); } return(dat.Combine(this.data)); }
private void GenerateTilesRecurse(RandomLevelData tile, LevGenType type = LevGenType.Any) { this.visited = true; if (tile == null) { return; } this.data = tile; this.connectionUp = this.data.up; this.connectionDown = this.data.down; this.connectionLeft = this.data.left; this.connectionRight = this.data.right; if (this.symmetric) { if (this.kingTile) { if (this.connectionLeft && this.connectionRight || !this.connectionLeft && !this.connectionRight) { this.mirror = true; } else { if (!this.connectionLeft) { if (this.up != null) { this.up.left = (RandomLevelNode)null; this.up.removeRight = true; } if (this.down != null) { this.down.left = (RandomLevelNode)null; this.down.removeRight = true; } this.removeRight = true; this.left = (RandomLevelNode)null; } if (!this.connectionRight) { if (this.up != null) { this.up.right = (RandomLevelNode)null; this.up.removeLeft = true; } if (this.down != null) { this.down.right = (RandomLevelNode)null; this.down.removeLeft = true; } this.removeLeft = true; this.right = (RandomLevelNode)null; } } } if (this.mirror) { this.connectionRight = this.data.left; } if (this.up != null) { this.up.mirror = this.mirror; } if (this.down != null) { this.down.mirror = this.mirror; } } List <TileConnection> source = new List <TileConnection>() { TileConnection.Right, TileConnection.Left, TileConnection.Up, TileConnection.Down }; if (this.removeLeft) { source.Remove(TileConnection.Left); } if (this.removeRight) { source.Remove(TileConnection.Right); } foreach (TileConnection tileConnection in (IEnumerable <TileConnection>)source.OrderBy <TileConnection, float>((Func <TileConnection, float>)(x => Rando.Float(1f)))) { switch (tileConnection) { case TileConnection.Left: if (this.connectionLeft && this.left != null && this.left.data == null && (!this.mirror || !this.symmetric || !this.rightSymmetric)) { if (this.mirror && this.symmetric) { this.leftSymmetric = true; if (this.down != null) { this.down.leftSymmetric = this.leftSymmetric; if (this.down.down != null) { this.down.down.leftSymmetric = this.leftSymmetric; } } if (this.up != null) { this.up.leftSymmetric = this.leftSymmetric; if (this.up.up != null) { this.up.up.leftSymmetric = this.leftSymmetric; } } } this.left.leftSymmetric = this.leftSymmetric; this.left.rightSymmetric = this.rightSymmetric; this.left.symmetric = this.symmetric; this.left.GenerateTilesRecurse(LevelGenerator.GetTile(TileConnection.Right, tile, type: type, mirror: this.left.mirror, filter: this.left.GetFilter()), type); continue; } continue; case TileConnection.Right: if (this.connectionRight && this.right != null && this.right.data == null && (!this.mirror || !this.symmetric || !this.leftSymmetric)) { if (this.mirror && this.symmetric) { this.rightSymmetric = true; if (this.down != null) { this.down.rightSymmetric = this.rightSymmetric; if (this.down.down != null) { this.down.down.rightSymmetric = this.rightSymmetric; } } if (this.up != null) { this.up.rightSymmetric = this.rightSymmetric; if (this.up.up != null) { this.up.up.rightSymmetric = this.rightSymmetric; } } } this.right.leftSymmetric = this.leftSymmetric; this.right.rightSymmetric = this.rightSymmetric; this.right.symmetric = this.symmetric; this.right.GenerateTilesRecurse(LevelGenerator.GetTile(TileConnection.Left, tile, type: type, mirror: this.right.mirror, filter: this.right.GetFilter()), type); continue; } continue; case TileConnection.Up: if (this.connectionUp && this.up != null && this.up.data == null) { this.up.leftSymmetric = this.leftSymmetric; this.up.rightSymmetric = this.rightSymmetric; this.up.symmetric = this.symmetric; this.up.GenerateTilesRecurse(LevelGenerator.GetTile(TileConnection.Down, tile, type: type, mirror: this.mirror, filter: this.up.GetFilter()), type); continue; } continue; case TileConnection.Down: if (this.connectionDown && this.down != null && this.down.data == null) { this.down.leftSymmetric = this.leftSymmetric; this.down.rightSymmetric = this.rightSymmetric; this.down.symmetric = this.symmetric; this.down.GenerateTilesRecurse(LevelGenerator.GetTile(TileConnection.Up, tile, type: type, mirror: this.mirror, filter: this.down.GetFilter()), type); continue; } continue; default: continue; } } if (!this.kingTile || !this.symmetric) { return; } this.SolveSymmetry(); if (this.up != null) { this.up.SolveSymmetry(); } if (this.down == null) { return; } this.down.SolveSymmetry(); }
public void GenerateTiles(RandomLevelData tile = null, LevGenType type = LevGenType.Any, bool symmetricVal = false) { this.symmetric = symmetricVal; this.GenerateTilesRecurse(tile != null ? tile : LevelGenerator.GetTile(TileConnection.None, tile, false, type, requiresSpawns: true), type); this.ClearFlags(); }
public static RandomLevelData GetTile( TileConnection requirement, RandomLevelData current, bool canBeNull = true, LevGenType type = LevGenType.Any, Func <RandomLevelData, bool> lambdaReq = null, bool mirror = false, TileConnection filter = TileConnection.None, bool requiresSpawns = false) { List <RandomLevelData> tiles = LevelGenerator.GetTiles(requirement, filter); RandomLevelData randomLevelData1 = new RandomLevelData(); bool flag = false; while (tiles.Count != 0) { RandomLevelData randomLevelData2 = tiles[Rando.Int(tiles.Count - 1)]; if (randomLevelData2.numSpawns <= 0 && requiresSpawns) { tiles.Remove(randomLevelData2); } else if (lambdaReq != null && !lambdaReq(randomLevelData2)) { tiles.Remove(randomLevelData2); } else if (mirror && !randomLevelData2.canMirror) { tiles.Remove(randomLevelData2); } else if (mirror && (randomLevelData2.flip || requirement == TileConnection.Right && !randomLevelData2.left)) { tiles.Remove(randomLevelData2); } else { int num = 0; if (LevelGenerator._used.TryGetValue(randomLevelData2.file, out num) && num >= randomLevelData2.max) { tiles.Remove(randomLevelData2); } else { if (tiles.Count == 1 && !canBeNull) { if (flag) { return(randomLevelData1); } randomLevelData2 = tiles.First <RandomLevelData>(); } else if ((double)randomLevelData2.chance != 1.0 && (double)Rando.Float(1f) >= (double)randomLevelData2.chance) { randomLevelData1 = randomLevelData2; tiles.Remove(randomLevelData2); flag = true; randomLevelData2 = (RandomLevelData)null; } if (randomLevelData2 != null) { if (LevelGenerator._used.ContainsKey(randomLevelData2.file)) { Dictionary <string, int> used; string file; (used = LevelGenerator._used)[file = randomLevelData2.file] = used[file] + 1; } else { LevelGenerator._used[randomLevelData2.file] = 1; } return(randomLevelData2); } if (tiles.Count == 0) { return(flag ? randomLevelData1 : (RandomLevelData)null); } } } } return(flag ? randomLevelData1 : (RandomLevelData)null); }
public static RandomLevelNode MakeLevel( RandomLevelData tile = null, bool allowSymmetry = true, int seed = 0, LevGenType type = LevGenType.Any, int varwide = 0, int varhigh = 0, int genX = 1, int genY = 1, List <GeneratorRule> rules = null) { Random generator = Rando.generator; if (seed == 0) { seed = Rando.Int(2147483646); } Rando.generator = new Random(seed); bool flag1 = true; int num1 = 0; int length1; int length2; RandomLevelNode[,] randomLevelNodeArray; while (true) { LevelGenerator._used.Clear(); length1 = varwide; length2 = varhigh; if (varwide == 0) { length1 = (double)Rando.Float(1f) <= 0.800000011920929 ? 3 : 2; } if (varhigh == 0) { float num2 = Rando.Float(1f); if ((double)num2 > 0.800000011920929) { ; } length2 = (double)num2 <= 0.349999994039536 ? 3 : 2; } if (flag1) { length1 = length2 = 3; } genX = length1 != 3 ? 0 : 1; genY = length2 != 3 ? 0 : 1; if (genX > length1 - 1) { genX = length1 - 1; } if (genY > length2 - 1) { genY = length2 - 1; } randomLevelNodeArray = new RandomLevelNode[length1, length2]; for (int index1 = 0; index1 < length1; ++index1) { for (int index2 = 0; index2 < length2; ++index2) { randomLevelNodeArray[index1, index2] = new RandomLevelNode(); randomLevelNodeArray[index1, index2].map = randomLevelNodeArray; } } for (int index1 = 0; index1 < length1; ++index1) { for (int index2 = 0; index2 < length2; ++index2) { RandomLevelNode randomLevelNode = randomLevelNodeArray[index1, index2]; if (index1 > 0) { randomLevelNode.left = randomLevelNodeArray[index1 - 1, index2]; } if (index1 < length1 - 1) { randomLevelNode.right = randomLevelNodeArray[index1 + 1, index2]; } if (index2 > 0) { randomLevelNode.up = randomLevelNodeArray[index1, index2 - 1]; } if (index2 < length2 - 1) { randomLevelNode.down = randomLevelNodeArray[index1, index2 + 1]; } } } if (tile != null) { LevelGenerator._used[tile.file] = 1; } randomLevelNodeArray[genX, genY].kingTile = true; randomLevelNodeArray[genX, genY].GenerateTiles(tile, type, (double)Rando.Float(1f) > 0.300000011920929); List <RandomLevelNode> available = new List <RandomLevelNode>(); for (int index1 = 0; index1 < length1; ++index1) { for (int index2 = 0; index2 < length2; ++index2) { RandomLevelNode randomLevelNode = randomLevelNodeArray[index1, index2]; if (randomLevelNode.data != null) { available.Add(randomLevelNode); } } } if (rules == null) { rules = new List <GeneratorRule>(); rules.Add(new GeneratorRule((Func <RandomLevelData, bool>)(problem => problem.numPermanentFatalWeapons < 1), (Func <RandomLevelData, bool>)(solution => solution.numPermanentFatalWeapons > 0), varMandatory: true)); rules.Add(new GeneratorRule((Func <RandomLevelData, bool>)(problem => problem.numLockedDoors > 0 && problem.numKeys == 0), (Func <RandomLevelData, bool>)(solution => solution.numLockedDoors == 0 && solution.numKeys > 0))); } bool flag2 = false; foreach (GeneratorRule rule in rules) { if ((double)rule.chance == 1.0 || (double)Rando.Float(1f) < (double)rule.chance) { RandomLevelNode specific = (RandomLevelNode)null; if (rule.special == SpecialRule.AffectCenterTile && length1 == 3) { specific = randomLevelNodeArray[1, Rando.Int(length2 - 1)]; } if (!LevelGenerator.TryReroll(randomLevelNodeArray[genX, genY].totalData, available, rule.problem, rule.solution, specific) && rule.mandatory) { flag2 = true; break; } } } if (flag2 && num1 < 6) { if (num1 > 3) { flag1 = true; } ++num1; } else { break; } } Rando.generator = generator; randomLevelNodeArray[genX, genY].seed = seed; randomLevelNodeArray[genX, genY].tilesWide = length1; randomLevelNodeArray[genX, genY].tilesHigh = length2; randomLevelNodeArray[genX, genY].tiles = randomLevelNodeArray; return(randomLevelNodeArray[genX, genY]); }
public static RandomLevelData LoadInTile(string tile, string realName = null) { RandomLevelData element = new RandomLevelData(); element.file = tile; if (realName != null) { element.file = realName; } LevelData levelData = Content.GetLevel(tile) ?? DuckFile.LoadLevel(tile); int sideMask = levelData.proceduralData.sideMask; if (sideMask == 0) { return((RandomLevelData)null); } if ((sideMask & 1) != 0) { element.up = true; } if ((sideMask & 2) != 0) { element.right = true; } if ((sideMask & 4) != 0) { element.down = true; } if ((sideMask & 8) != 0) { element.left = true; } element.chance = levelData.proceduralData.chance; element.max = levelData.proceduralData.maxPerLevel; element.single = levelData.proceduralData.enableSingle; element.multi = levelData.proceduralData.enableMulti; element.ApplyWeaponData(levelData.proceduralData.weaponConfig); element.ApplySpawnerData(levelData.proceduralData.spawnerConfig); element.numArmor = levelData.proceduralData.numArmor; element.numEquipment = levelData.proceduralData.numEquipment; element.numKeys = levelData.proceduralData.numKeys; element.numLockedDoors = levelData.proceduralData.numLockedDoors; element.numSpawns = levelData.proceduralData.numSpawns; element.numTeamSpawns = levelData.proceduralData.numTeamSpawns; element.canMirror = levelData.proceduralData.canMirror; element.isMirrored = levelData.proceduralData.isMirrored; element.data = levelData.objects.objects; LevelGenerator._tiles.Add(element); if (element.up) { LevelGenerator._connections.Add(TileConnection.Up, element); } if (element.down) { LevelGenerator._connections.Add(TileConnection.Down, element); } if (element.left) { LevelGenerator._connections.Add(TileConnection.Left, element); LevelGenerator._connections.Add(TileConnection.Right, element.Flipped()); } if (element.right) { LevelGenerator._connections.Add(TileConnection.Right, element); LevelGenerator._connections.Add(TileConnection.Left, element.Flipped()); } LevelGenerator._tiles.Add(element.Flipped()); return(element); }