public override void RunTestLevel(string name) { LevGenType genType = LevGenType.Any; if (this._enableSingle && !this._enableMulti) { genType = LevGenType.SinglePlayer; } else if (!this._enableSingle && this._enableMulti) { genType = LevGenType.Deathmatch; } Level.current = !this._levelThings.Exists((Predicate <Thing>)(x => x is ChallengeMode)) ? (!this._levelThings.Exists((Predicate <Thing>)(x => x is ArcadeMode)) ? (Level) new DuckGameTestArea((Editor)this, name, this._procSeed, this._centerTile, genType) : (Level) new ArcadeLevel(name)) : (Level) new ChallengeLevel(name); Level.current.AddThing((Thing) new EditorTestLevel((Editor)this)); }
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; }
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]); }