private void PaintCells(Graphics g)
{
float colorPercent;
int rgb, cellX, cellY, totalCells;
TerrainTile room = null;
Color cellColor = Color.White;
Dictionary<PointF, string> cityNames = new Dictionary<PointF, string>();
cellX = (int)m_viewport.Left;
cellY = (int)m_viewport.Top;
totalCells = (int)((m_viewport.Width + 1) * (m_viewport.Height + 1));
if (m_world != null)
{
for (int index = 0; index < totalCells; index++)
{
room = m_world.LoadTile(cellX, cellY);
colorPercent = room.Height / m_world.TerrainHeight;
rgb = (int)Math.Max(Math.Min(255 * Math.Abs(colorPercent), 255), 0);
if(m_tempMap)
{
colorPercent = (float)(room.m_temp / 50);
rgb = (int)Math.Max(Math.Min(255 * Math.Abs(colorPercent), 255), 0);
cellColor = Color.FromArgb(255, rgb, 0, 255-rgb);
}
else if (m_heightMap)
{
if (room.Height > m_world.CoastLine)
{
cellColor = Color.FromArgb(255, rgb, rgb, rgb);
}
else
{
cellColor = Color.FromArgb(255, 0, 0, 255 - rgb);
}
}
else
{
switch (room.Terrain)
{
case TerrainTypes.Ocean:
cellColor = Color.FromArgb(255, 0, 0, 255 - rgb);
break;
case TerrainTypes.Dirt:
cellColor = ControlPaint.Light(Color.SaddleBrown, colorPercent);
break;
case TerrainTypes.Sand:
cellColor = ControlPaint.Light(Color.BurlyWood, colorPercent);
break;
case TerrainTypes.Grass:
RandomNoise rn = new RandomNoise(1);
double val = rn.GetValue(cellX, cellY);
if (val < .33)
cellColor = Color.Green;
else if (val < .66)
cellColor = Color.ForestGreen;
else
cellColor = Color.DarkGreen;
break;
case TerrainTypes.Stone:
cellColor = Color.SlateGray;
break;
case TerrainTypes.Snow:
cellColor = ControlPaint.Light(Color.LightGray, colorPercent);
break;
case TerrainTypes.Lava:
cellColor = Color.Red;
break;
case TerrainTypes.Ice:
cellColor = Color.Cyan;
break;
case TerrainTypes.None:
cellColor = Color.Black;
break;
case TerrainTypes.Road:
cellColor = Color.Yellow;
//City city = m_world.GetCity(cellX, cellY);
cityNames.Add(new PointF((cellX * m_cellWidth) + m_cellWidth, (cellY * m_cellHeight) + m_cellHeight), room.Name);
break;
}
}
if(IsSelected(room))
{
g.FillRectangle(new SolidBrush(Color.FromArgb(255, 255 - cellColor.R, 255 - cellColor.G, 255 - cellColor.B)), new RectangleF(room.X * m_cellWidth, room.Y * m_cellHeight, m_cellWidth, m_cellHeight));
}
else
{
g.FillRectangle(new SolidBrush(cellColor), new RectangleF(cellX * m_cellWidth, cellY * m_cellHeight, m_cellWidth, m_cellHeight));
}
cellX++;
if (cellX > m_viewport.Right)
{
cellY++;
cellX = (int)m_viewport.Left;
}
}
Font f = new Font(FontFamily.GenericMonospace, 11 * 1 / m_scale, FontStyle.Bold);
foreach (PointF p in cityNames.Keys)
{
g.DrawString(cityNames[p], f, new SolidBrush(Color.Black), new PointF(p.X, p.Y));
}
}
}