public bool Boolean() { if (this.bytePos == 0 && this.bitPos == 0) { this.Fill(); SeededRandom seededRandom = this; seededRandom.bitPos = (byte)(seededRandom.bitPos + 1); return((this.byteBuffer[0] & 1) == 1); } bool flag = (this.byteBuffer[this.bytePos] & 1 << (this.bitPos & 31)) == 1 << (this.bitPos & 31); SeededRandom seededRandom1 = this; byte num = (byte)(seededRandom1.bitPos + 1); byte num1 = num; seededRandom1.bitPos = num; if (num1 == 8) { this.bitPos = 0; SeededRandom seededRandom2 = this; byte num2 = (byte)(seededRandom2.bytePos + 1); num1 = num2; seededRandom2.bytePos = num2; if (num1 == 16) { this.bytePos = 0; } } return(flag); }
private void SpawnEnemies() { var numEnemies = GetNumberOfEnemiesForFloor(); enemies = Level.GetRequiredEnemies(); var spawnLocations = Level.GetPossibleSpawnLocations(); foreach (var enemy in enemies) { var enemyLocation = BattleManager.ConvertVector(enemy.transform.position); spawnLocations.Remove(enemyLocation); //If this is the boss if (enemy.AI is BossBrain) { PlaceBoss(enemy); } else { map[enemyLocation.x, enemyLocation.y].tileEntityType = Roguelike.Tile.TileEntityType.enemy; PlaceObjectOn(enemyLocation.x, enemyLocation.y, enemy); } } while (enemies.Count < numEnemies && spawnLocations.Count > 0) { var location = SeededRandom.PickRandom(spawnLocations); spawnLocations.Remove(location); map[location.x, location.y].tileEntityType = Roguelike.Tile.TileEntityType.enemy; SpawnEnemyAt(location.x, location.y); } }
private void Read(BinaryReader reader) { this.lastChangeTime = reader.ReadDouble(); this.on = this.lastChangeTime > 0; if (!this.on) { this.lastChangeTime = -this.lastChangeTime; } int num = reader.ReadInt32(); uint num1 = reader.ReadUInt32(); byte num2 = reader.ReadByte(); Array.Resize <LightSwitch.StylistCTX>(ref this.stylistCTX, (int)num2); Array.Resize <LightStylist>(ref this.stylists, (int)num2); for (int i = 0; i < num2; i++) { this.stylistCTX[i].Read(reader); } if (num != this.rand.Seed) { this._randSeed = num; this.rand = new SeededRandom(num); } this.rand.PositionData = num1; this.JumpUpdate(); }
/// <summary> /// Paints the tileMap to match the roguelike map /// </summary> /// <param name="tileMap"></param> /// <param name="map"></param> public void Paint(Tilemap tileMap, Roguelike.Tile[,] map, int sizeX, int sizeZ) { for (int i = 0; i < sizeX; i++) { for (int j = 0; j < sizeZ; j++) { Tile tile = null; switch (map[i, j].tileEntityType) { //Enemies and the player can only spawn on floors case Roguelike.Tile.TileEntityType.enemy: case Roguelike.Tile.TileEntityType.player: case Roguelike.Tile.TileEntityType.empty: if (map[i, j].tileTerrainType == Roguelike.Tile.TileTerrainType.stairsDown) { decorations.PaintStairs(new Vector3Int(i, j, 0)); } tile = SeededRandom.PickRandom(FloorTiles); break; case Roguelike.Tile.TileEntityType.wall: tile = GetWallTile(i, j, map); break; } if (tile != null) { tileMap.SetTile(new Vector3Int(i, j, 0), tile); var getTile = tileMap.GetTile(new Vector3Int(i, j, 0)); Debug.Log(getTile.name); } } } }
/// <summary> /// Creates a new game using the provided GameConfiguration. Calling this constructor will trigger /// map generation and generate the map based on the GameConfiguration that was passed into the game. /// </summary> /// <param name="gameConfiguration">Settings that determine how the game should be configured during generation.</param> public Game(GameConfiguration gameConfiguration) { SeededRandom = new SeededRandom(gameConfiguration.MapConfiguration.Seed); // Creates a new game state and makes a time machine to reference the state GameState.GameState state = new GameState.GameState(gameConfiguration); TimeMachine = new TimeMachine(state); // Creates the map generator with a random seed MapGenerator mapGenerator = new MapGenerator(gameConfiguration.MapConfiguration, state.GetPlayers()); // Generate the map List <Outpost> generatedOutposts = mapGenerator.GenerateMap(); // Add the outposts to the map state.GetOutposts().AddRange(generatedOutposts); // Populate the specialist pool SpecialistPool = new SpecialistPool(SeededRandom, gameConfiguration.GameSettings.AllowedSpecialists.ToList()); // All owned factories should start producing drillers foreach (Outpost o in generatedOutposts) { if (o is Factory && o.GetComponent <DrillerCarrier>().GetOwner() != null) { Factory f = (Factory)o; TimeMachine.AddEvent(new FactoryProduction(f, f.GetTicksToFirstProduction())); } } }
public void SetSize() { var width = SeededRandom.Range(Info.MinWidth, Info.MaxWidth); var height = SeededRandom.Range(Info.MinHeight, Info.MaxHeight); Bounds.Resize(width, height); }
/// <summary> /// Map Generation constructor to seed map generation /// </summary> /// <param name="seed">The seed to set the random number generator</param> public MapGenerator(GameConfiguration gameConfiguration) { if (gameConfiguration.Players.Count <= 0) { throw new PlayerCountException("A game must have at least one player."); } if (gameConfiguration.OutpostsPerPlayer <= 0) { throw new OutpostPerPlayerException("outpostsPerPlayer must be greater than or equal to one."); } this.RandomGenerator = new SeededRandom(gameConfiguration.Seed); this.DormantsPerPlayer = gameConfiguration.DormantsPerPlayer; this.Players = gameConfiguration.Players; this.NumPlayers = gameConfiguration.Players.Count; this.OutpostsPerPlayer = gameConfiguration.OutpostsPerPlayer; this.MinOutpostDistance = gameConfiguration.MinimumOutpostDistance; this.MaxSeedDistance = gameConfiguration.MaxiumumOutpostDistance; // Set the map size. int halfPlayers = (int)(Math.Floor(this.Players.Count / 2.0)); RftVector.Map = new Rft(gameConfiguration.MaxiumumOutpostDistance * 4, halfPlayers * gameConfiguration.MaxiumumOutpostDistance * 2); }
public void AutoDecorate() { for (int i = Room.Bounds.Left; i < Room.Bounds.Right; i++) { for (int j = Room.Bounds.Bottom; j < Room.Bounds.Top; j++) { var type = GetTypeOfWall(i, j); if (type == TypeOfTile.Top) { if (SeededRandom.RandBool(.125f)) { DecorativeTileMap.SpawnTorch(i, j); } else if (SeededRandom.RandBool(.125f)) { Level.Decorations.SetTile(new Vector3Int(i, j, 0), Painter.GetRandomTopWallDecoration()); } } if (type == TypeOfTile.Left && SeededRandom.RandBool(.125f) && IsFloor(i + 1, j)) { DecorativeTileMap.SpawnSideTorch(i + 1, j, true); } if (type == TypeOfTile.Right && SeededRandom.RandBool(.125f) && IsFloor(i - 1, j)) { DecorativeTileMap.SpawnSideTorch(i - 1, j, false); } if (type == TypeOfTile.Floor && SeededRandom.RandBool(.02f)) { Level.Decorations.SetTile(new Vector3Int(i, j, 0), Painter.GetRandomFloorDecoration()); } } } }
private void Read(BinaryReader reader) { this.lastChangeTime = reader.ReadDouble(); this.on = this.lastChangeTime > 0.0; if (!this.on) { this.lastChangeTime = -this.lastChangeTime; } int seed = reader.ReadInt32(); uint num2 = reader.ReadUInt32(); byte newSize = reader.ReadByte(); Array.Resize <StylistCTX>(ref this.stylistCTX, newSize); Array.Resize <LightStylist>(ref this.stylists, newSize); for (int i = 0; i < newSize; i++) { this.stylistCTX[i].Read(reader); } if (seed != this.rand.Seed) { this._randSeed = seed; this.rand = new SeededRandom(seed); } this.rand.PositionData = num2; this.JumpUpdate(); }
private GameCube MakeCube(SeededRandom dice) { GameCube toReturn = GameObject.Instantiate(cube); toReturn.Initialize(owner, dice); return(toReturn); }
public void ShouldUseRandomSeed() { var seededSample = new Random(theSeed).Next(); var actualSample = SeededRandom.Next(); Assert.AreNotEqual(seededSample, actualSample); }
private void SpawnEnemyAt(int x, int z, string name = "") { var spawnLoc = new Vector2Int(x, z); var rand = SeededRandom.Range(1, 4); GameObject newEnemy; switch (rand) { case 1: newEnemy = EnemySpawner.SpawnArcher(spawnLoc); break; case 2: newEnemy = EnemySpawner.SpawnBrute(spawnLoc); break; default: newEnemy = EnemySpawner.SpawnBasicMeleeEnemy(spawnLoc); break; } var enemyBody = newEnemy.GetComponent <EnemyBody>(); enemies.Add(enemyBody); enemyBody.name = "EnemyID: " + enemies.Count; PlaceObjectOn(spawnLoc.x, spawnLoc.y, enemyBody); }
public static T Choose <T>(List <T> list, SeededRandom rand) where T : IWeighted { T result; if (list.Count == 0) { result = default(T); return(result); } float num = 0f; for (int i = 0; i < list.Count; i++) { float num2 = num; result = list[i]; num = num2 + result.weight; } float num3 = rand.RandomValue() * num; float num4 = 0f; for (int j = 0; j < list.Count; j++) { num4 += list[j].weight; if (num4 > num3) { return(list[j]); } } return(list[list.Count - 1]); }
private void PlaceTraps() { traps = Level.GetRequiredTraps(); var spawnLocations = Level.GetPossibleSpawnLocations(); foreach (var trap in traps) { var trapLocation = BattleManager.ConvertVector(trap.transform.position); spawnLocations.Remove(trapLocation); PlaceTerrainOn(trapLocation.x, trapLocation.y, trap); } var numTraps = GetNumberOfTrapsForFloor(); while (traps.Count < numTraps && spawnLocations.Count > 0) { var spawnLoc = SeededRandom.PickRandom(spawnLocations); spawnLocations.Remove(spawnLoc); var trap = EnemySpawner.SpawnSpikes(spawnLoc).GetComponent <Spikes>(); traps.Add(trap); PlaceTerrainOn(spawnLoc.x, spawnLoc.y, trap); if (SeededRandom.RandBool(.5f)) { trap.MakeInvisible(); } } }
private List <Room> TryCreateBranch(Room roomToBranch, Room currentRoom, int numConnRooms) { int tries; float angle; var currentBranch = new List <Room>(); for (int j = 0; j < numConnRooms; j++) { var connRoom = new ConnectionRoom(); tries = 3; do { tries--; angle = AttemptToPlaceRoom(currentRoom, connRoom, SeededRandom.RandomDirection()); } while (tries > 0 && angle == -1); if (angle == -1) //If we failed to place the connecting room, remove all rooms on this branch { foreach (var branchRoom in currentBranch) { branchRoom.Reset(); PlacedRooms.Remove(branchRoom); } currentBranch.Clear(); return(currentBranch); } else { currentRoom = connRoom; currentBranch.Add(connRoom); PlacedRooms.Add(connRoom); } } tries = 10; do { tries--; angle = AttemptToPlaceRoom(currentRoom, roomToBranch, SeededRandom.RandomDirection()); } while (tries > 0 && angle == -1); if (angle == -1) { roomToBranch.Reset(); foreach (var branchRoom in currentBranch) { branchRoom.Reset(); PlacedRooms.Remove(branchRoom); } currentBranch.Clear(); return(currentBranch); } else { currentBranch.Add(roomToBranch); PlacedRooms.Add(roomToBranch); } return(currentBranch); }
public void PaintRightWall(int minY, int maxY, int xValue) { for (int i = minY; i < maxY; i++) { var tile = SeededRandom.PickRandom(Painter.RightWallTiles); Level.Terrain.SetTile(new Vector3Int(xValue, i, 0), tile); } }
public void PaintTopWall(int minX, int maxX, int yValue) { for (int i = minX; i < maxX; i++) { var tile = SeededRandom.PickRandom(Painter.TopWallTiles); Level.Terrain.SetTile(new Vector3Int(i, yValue, 0), tile); } }
public static void Prefix( Sim.Cell[] cells, Chunk world, SeededRandom rnd, HashSet <int> borderCells) { _cells = cells; _world = world; }
public void ShouldUseGivenSeed() { var seededSample = new Random(theSeed).Next(); SeededRandom.Seed = theSeed; var actualSample = SeededRandom.Next(); Assert.AreEqual(seededSample, actualSample); }
public WeightedSimHash GetOneWeightedSimHash(string item, SeededRandom rnd) { if (ElementChoiceGroups.ContainsKey(item)) { return(WeightedRandom.Choose(ElementChoiceGroups[item].choices, rnd)); } Debug.LogError("Couldnt get SimHash [" + item + "]"); return(null); }
public void Process(WorldGen worldGen, Chunk world, SeededRandom rnd) { SetValuesFunction setValues = delegate(int index, object elem, Sim.PhysicsData pd, Sim.DiseaseCell dc) { SimMessages.ModifyCell(index, ElementLoader.GetElementIndex((elem as Element).id), pd.temperature, pd.mass, dc.diseaseIdx, dc.elementCount, SimMessages.ReplaceType.Replace, false, -1); }; DoProcess(worldGen, world, setValues, rnd); }
public void Stagger(SeededRandom rnd, float maxDistance = 10f, float staggerRange = 3f) { List <Segment> list = new List <Segment>(); for (int i = 0; i < pathElements.Count; i++) { list.AddRange(pathElements[i].Stagger(rnd, maxDistance, staggerRange)); } pathElements = list; }
public void IndexedRand() { int seed = 1234; SeededRandom rand1 = new SeededRandom(seed); SeededRandom rand2 = new SeededRandom(seed); Assert.AreEqual(rand1.GetDouble(100), rand2.GetDouble(100)); Assert.AreEqual(rand1.GetRand(200, 0, 10), rand2.GetRand(200, 0, 10)); }
// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| // Use this for internal initialization void Awake() { // Make FixedUpdate select the next wave (or generate it) state = WaveState.Waiting; SpaceObjectDirection.SetAngle(initialAngle); SpaceObjectDirection.SetAngularSpeed(fullCircleRotationTime); SeededRandom.SetSeed(initialSeed); lastSpaceObjectContainer = this; waveIndex = Mathf.Min(waves.Length - 1, Global.startWave); }
public void PaintFloorArea(int minX, int maxX, int minY, int maxY) { for (int i = minX; i <= maxX; i++) { for (int j = minY; j <= maxY; j++) { var tile = SeededRandom.PickRandom(Painter.FloorTiles); Level.Terrain.SetTile(new Vector3Int(i, j, 0), tile); } } }
private Tile GetWallTile(int x, int y) { //This is terrible but no super easy way of doing it right now int maxX = Room.Bounds.Right; int maxY = Room.Bounds.Top; if (IsFloor(x, y - 1)) { return(SeededRandom.PickRandom(Painter.TopWallTiles)); } if (IsFloor(x + 1, y) && IsFloor(x, y + 1)) { return(SeededRandom.PickRandom(Painter.TurnRightTiles)); } if (IsFloor(x - 1, y) && IsFloor(x, y + 1)) { return(SeededRandom.PickRandom(Painter.TurnLeftTiles)); } if (IsFloor(x - 1, y)) { return(SeededRandom.PickRandom(Painter.RightWallTiles)); } if (IsFloor(x + 1, y)) { return(SeededRandom.PickRandom(Painter.LeftWallTiles)); } if (IsFloor(x, y + 1)) { return(SeededRandom.PickRandom(Painter.BottomWallTiles)); } if (IsFloor(x + 1, y - 1)) { Room.Corners.Add(new Vector2Int(x, y)); return(SeededRandom.PickRandom(Painter.LeftWallTiles)); } if (IsFloor(x - 1, y - 1)) { Room.Corners.Add(new Vector2Int(x, y)); return(SeededRandom.PickRandom(Painter.RightWallTiles)); } if (IsFloor(x + 1, y + 1)) { Room.Corners.Add(new Vector2Int(x, y)); return(Painter.BottomLeftCorner); } if (IsFloor(x - 1, y + 1)) { Room.Corners.Add(new Vector2Int(x, y)); return(Painter.BottomRightCorner); } return(null); }
private void SpawnMoneyAt(int x, int z) { GameObject moneyObj = ItemSpawner.SpawnMoney(new Vector2Int(x, z)); DroppedMoney newMoneyBloodMoney = moneyObj.GetComponent <DroppedMoney>(); int amount = SeededRandom.Range(10, 20); // Technically, the amount of money can change if you swap floors. Hopefully nobody notices. newMoneyBloodMoney.Initialize(amount); // Set how much this is worth newMoneyBloodMoney.xPos = x; newMoneyBloodMoney.zPos = z; map[x, z].SetItemOnTile(newMoneyBloodMoney); }
protected virtual bool PlaceExit(Room prev, float direction, float pathVariance) { var res = AttemptToPlaceRoom(prev, exit, direction + SeededRandom.Range(-pathVariance, pathVariance)); if (res != -1) { PlacedRooms.Add(exit); return(true); } else { return(false); } }
protected override bool PlaceExit(Room prev, float direction, float pathVariance) { var res = AttemptToPlaceRoom(prev, BossRoom, direction + SeededRandom.Range(-pathVariance, pathVariance)); if (res != -1) { PlacedRooms.Add(BossRoom); return(base.PlaceExit(BossRoom, direction, pathVariance)); } else { return(false); } }
public override List <EnemyBody> GetAnyRequiredEnemies(Level level) { var possibleSpawnLocations = GetPossibleSpawnLocations(level); var spawnLoc = SeededRandom.PickRandom(possibleSpawnLocations); if (spawnLoc != null) { var brute = EnemySpawner.SpawnBrute(spawnLoc); return(new List <EnemyBody> { brute.GetComponent <EnemyBody>() }); } return(new List <EnemyBody>()); }