Example #1
0
 /// <summary>
 /// Creates a resource of given entry at given tile
 /// </summary>
 /// <param id="entry">Db entry of the resource</param>
 /// <param id="tile">Tile if the resource</param>
 /// <returns>The created resource</returns>
 public IScriptResource CreateResource(IScriptDbEntry entry, IScriptTile tile)
 {
   Resource r = new Resource();
   r.Initialize((EntryDb)entry, this, NaturePlayer, (Tile)tile);
   r.InitializeGraphics();
   SendData(Network.MakeServerMessage(MessageType.GameObjCreate, tile));
   return r;
 }
Example #2
0
    public void Generate(Random random, int players)
    {
      var terrain = new MapGenerator(random, ROUGHNESS, Width, Height, players, MAP_GEN_ATTEMPTS);
      terrain.Generate();

      if (!terrain.Valid)
      {
        Valid = false;
        return;
      }

      StartLocations = new List<Tile>();
      foreach (var position in terrain.StartLocations)
      {
        StartLocations.Add(Tiles[position.X, position.Y]);
      }

      for (int iRow = 0; iRow < Height; iRow++)
      {
        for (int iCol = 0; iCol < Width; iCol++)
        {
          Tile tile = Tiles[iCol, iRow];
          int elevation = terrain.MapElevations[iCol, iRow];
          tile.SetElevation(elevation);

          if (elevation < MapBoard.SEA_LEVEL) continue;

          foreach (var item in Db.Instance.Resources)
          {
            if (random.NextDouble() < item.Value.OccurChance)
            {
              Resource r = new Resource();
              r.Initialize(item.Value, Game, Game.NaturePlayer, tile);
              r.InitializeGraphics();
              break;
            }
          }
        }
      }

      foreach (var item in Tiles)
      {
        item.UpdateTerrainBarHeight();
      }
    }