Skip to content

Commit ab693d9

Browse files
committed
Cleanup.
1 parent 9871e08 commit ab693d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2318
-1489
lines changed

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
**/bin/**
22
**/obj/**
3-
**/.vs/**
4-
appsettings.json
3+
**/.vs/**

appsettings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"Civ2Path": "C:\\Civ2\\"
2+
"Civ2Path": "C:\\Program Files (x86)\\Civ2\\"
33
}

civ2.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
<ItemGroup>
1212
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="5.0.0" />
1313
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
14+
<PackageReference Include="Roslynator.Analyzers" Version="3.0.0">
15+
<PrivateAssets>all</PrivateAssets>
16+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
17+
</PackageReference>
1418
</ItemGroup>
1519
<ItemGroup>
1620
<Reference Include="System.Configuration" />

src/Bitmaps/CivColors.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace civ2.Bitmaps
44
{
55
public static class CivColors
66
{
7-
public static readonly Color[] Light =
7+
public static readonly Color[] Light =
88
{
99
Color.FromArgb(243, 0, 0), //RED
1010
Color.FromArgb(239, 239, 239), //WHITE

src/Bitmaps/Draw.City.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static Bitmap City(City city, bool citySizeWindow, int zoom)
8282
if (!city.ImprovementExists(ImprovementType.CityWalls)) // no city walls
8383
{
8484
graphics.DrawImage(Images.City[(int)style, sizeStyle], 0, 0);
85-
85+
8686
// Draw city size window
8787
if (citySizeWindow)
8888
{
@@ -112,7 +112,7 @@ public static Bitmap City(City city, bool citySizeWindow, int zoom)
112112

113113
// Filling of rectangle
114114
graphics.FillRectangle(new SolidBrush(CivColors.Light[city.OwnerId]), Images.cityWallSizeWindowLoc[(int)style, sizeStyle, 0], Images.cityWallSizeWindowLoc[(int)style, sizeStyle, 1], 8, 12);
115-
115+
116116
// Size text
117117
graphics.DrawString(city.Size.ToString(), new Font("Times New Roman", 10.0f, FontStyle.Bold), new SolidBrush(Color.Black), Images.cityWallSizeWindowLoc[(int)style, sizeStyle, 0] + 4, Images.cityWallSizeWindowLoc[(int)style, sizeStyle, 1] + 6, sf);
118118
}

src/Bitmaps/Draw.CityPanel.cs

+78-60
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,15 @@ public static Bitmap DrawFoodStorage(City city)
6262
graphics.DrawImage(Images.CitymapFoodLargeBigger, starting_x + wheat_spacing * col, 27 + wheatH * row);
6363
count++;
6464

65-
if (count >= city.FoodInStorage) break;
65+
if (count >= city.FoodInStorage)
66+
{
67+
break;
68+
}
69+
}
70+
if (count >= city.FoodInStorage)
71+
{
72+
break;
6673
}
67-
if (count >= city.FoodInStorage) break;
6874
}
6975

7076
//3rd horizontal line (shorter)
@@ -118,7 +124,10 @@ public static Bitmap Citizens(City city, int zoom)
118124
for (int i = 0; i < city.Size; i++)
119125
{
120126
drawIndex = (int)peoples[i];
121-
if (i % 2 == 1 && (drawIndex == 0 || drawIndex == 2 || drawIndex == 4 || drawIndex == 6)) drawIndex++; // Change men/woman appearance
127+
if (i % 2 == 1 && (drawIndex == 0 || drawIndex == 2 || drawIndex == 4 || drawIndex == 6))
128+
{
129+
drawIndex++; // Change men/woman appearance
130+
}
122131
//graphics.DrawImage(Images.PeopleL[drawIndex, 0], i * spacing + 1, 1); // Shadow
123132
graphics.DrawImage(ModifyImage.ResizeImage(Images.PeopleLshadow[drawIndex, 0], zoom), i * spacing + 1, 1); // Shadow
124133
graphics.DrawImage(ModifyImage.ResizeImage(Images.PeopleL[drawIndex, 0], zoom), i * spacing, 0);
@@ -163,65 +172,74 @@ public static Bitmap DrawCityProduction(City city)
163172
return icons;
164173
}
165174

166-
public static Bitmap DrawCityResourcesMap(City city) //Draw terrain in city form
175+
// Draw resource map
176+
public static Bitmap CityResourcesMap(City city, int zoom)
167177
{
168-
Bitmap map = new Bitmap(4 * 64, 4 * 32);
178+
var _map = new Bitmap(4 * 8 * (8 + zoom), 4 * 4 * (8 + zoom));
169179

170-
//Bitmap image;
171-
//using (Graphics graphics = Graphics.FromImage(map))
172-
//{
173-
// //First draw squares around city
174-
// for (int x_ = -3; x_ <= 3; x_++)
175-
// for (int y_ = -3; y_ <= 3; y_++)
176-
// if ((x_ == -1 & y_ == -3) || (x_ == 1 & y_ == -3) || (x_ == -2 & y_ == -2) || (x_ == 0 & y_ == -2) || (x_ == 2 & y_ == -2) || (x_ == -3 & y_ == -1) || (x_ == -1 & y_ == -1) || (x_ == 1 & y_ == -1) || (x_ == 3 & y_ == -1) || (x_ == -2 & y_ == 0) || (x_ == 0 & y_ == 0) || (x_ == 2 & y_ == 0) || (x_ == -3 & y_ == 1) || (x_ == -1 & y_ == 1) || (x_ == 1 & y_ == 1) || (x_ == 3 & y_ == 1) || (x_ == -2 & y_ == 2) || (x_ == 0 & y_ == 2) || (x_ == 2 & y_ == 2) || (x_ == -1 & y_ == 3) || (x_ == 1 & y_ == 3))
177-
// {
178-
// int newX = city.X + x_;
179-
// int newY = city.Y + y_;
180-
// //TODO: correct this
181-
// //if (newX >= 0 && newX < 2 * Data.MapXdim && newY >= 0 && newY < Data.MapYdim) image = TerrainBitmap((newX - (newY % 2)) / 2, newY);
182-
// //else image = Blank;
183-
// image = Blank;
184-
// graphics.DrawImage(image, 32 * (x_ + 3), 16 * (y_ + 3));
185-
// }
186-
187-
// //Then draw city
188-
// graphics.DrawImage(CreateCityBitmap(city, false, 8), 64 * 1 + 32 * (3 % 2) + 1, 16 * 2 + 1);
189-
190-
// //Then draw food/shield/trade icons around the city (21 squares around city)
191-
// int[,] offsets = new int[21, 2] { { 0, 0 }, { -1, -3 }, { -3, -1 }, { -3, 1 }, { -1, 3 }, { 1, 3 }, { 3, 1 }, { 3, -1 }, { 1, -3 }, { -2, -2 }, { -2, 2 }, { 2, 2 },
192-
// { 2, -2 }, { 0, -2 }, { -1, -1 }, { -2, 0 }, { -1, 1 }, { 0, 2 }, { 1, 1 }, { 2, 0 }, { 1, -1 } }; //offset of squares from city square (0,0)
193-
// int[] cityFood = city.FoodDistribution;
194-
// int[] cityShld = city.ShieldDistribution;
195-
// int[] cityTrad = city.TradeDistribution;
196-
// for (int i = 0; i < 21; i++)
197-
// if (city.DistributionWorkers[i] == 1)
198-
// {
199-
// //First count all icons on this square to determine the spacing between icons (10 = no spacing, 15 = no spacing @ 50% scaled)
200-
// int spacing;
201-
// switch (cityFood[i] + cityShld[i] + cityTrad[i])
202-
// {
203-
// case 1:
204-
// case 2: spacing = 17; break; //50 % larger (orignal = 11, 1 pixel gap)
205-
// case 3: spacing = 15; break; //50 % larger (orignal = 10, no gap)
206-
// case 4: spacing = 11; break; //50 % larger (orignal = 7)
207-
// case 5: spacing = 8; break; //50 % larger (orignal = 5)
208-
// case 6: spacing = 6; break; //50 % larger (orignal = 4)
209-
// case 7:
210-
// case 8: spacing = 5; break; //50 % larger (orignal = 3)
211-
// case 9: spacing = 3; break; //50 % larger (orignal = 2)
212-
// case 10: spacing = 2; break; //50 % larger (orignal = 1)
213-
// default: spacing = 2; break; //50 % larger (orignal = 1)
214-
// }
215-
216-
// //First draw food, then shields, then trade icons
217-
// int x_offset = 32 - ((cityFood[i] + cityShld[i] + cityTrad[i] - 1) * spacing + 15) / 2;
218-
// int y_offset = 9;
219-
// for (int j = 0; j < cityFood[i]; j++) graphics.DrawImage(CitymapFoodSmallBigger, x_offset + (3 + offsets[i, 0]) * 32 + j * spacing, y_offset + (3 + offsets[i, 1]) * 16);
220-
// for (int j = 0; j < cityShld[i]; j++) graphics.DrawImage(CitymapShieldSmallBigger, x_offset + (3 + offsets[i, 0]) * 32 + (cityFood[i] + j) * spacing, y_offset + (3 + offsets[i, 1]) * 16);
221-
// for (int j = 0; j < cityTrad[i]; j++) graphics.DrawImage(CitymapTradeSmallBigger, x_offset + (3 + offsets[i, 0]) * 32 + (cityFood[i] + cityShld[i] + j) * spacing, y_offset + (3 + offsets[i, 1]) * 16);
222-
// }
223-
//}
224-
return map;
180+
Bitmap _image;
181+
using (Graphics graphics = Graphics.FromImage(_map))
182+
{
183+
// First draw squares around city
184+
for (int x_ = -3; x_ <= 3; x_++)
185+
{
186+
for (int y_ = -3; y_ <= 3; y_++)
187+
{
188+
if ((x_ == -1 && y_ == -3) || (x_ == 1 && y_ == -3) || (x_ == -2 && y_ == -2) || (x_ == 0 && y_ == -2) || (x_ == 2 && y_ == -2) || (x_ == -3 && y_ == -1)
189+
|| (x_ == -1 && y_ == -1) || (x_ == 1 && y_ == -1) || (x_ == 3 && y_ == -1) || (x_ == -2 && y_ == 0) || (x_ == 0 && y_ == 0) || (x_ == 2 && y_ == 0)
190+
|| (x_ == -3 && y_ == 1) || (x_ == -1 && y_ == 1) || (x_ == 1 && y_ == 1) || (x_ == 3 && y_ == 1) || (x_ == -2 && y_ == 2) || (x_ == 0 && y_ == 2)
191+
|| (x_ == 2 && y_ == 2) || (x_ == -1 && y_ == 3) || (x_ == 1 && y_ == 3))
192+
{
193+
int newX = city.X + x_;
194+
int newY = city.Y + y_;
195+
//TODO: correct this
196+
//if (newX >= 0 && newX < 2 * Data.MapXdim && newY >= 0 && newY < Data.MapYdim) image = TerrainBitmap((newX - (newY % 2)) / 2, newY);
197+
//else image = Blank;
198+
//image = Blank;
199+
//graphics.DrawImage(image, 32 * (x_ + 3), 16 * (y_ + 3));
200+
graphics.DrawImage(ModifyImage.ResizeImage(Images.Blank, zoom), 4 * (8 + zoom) * (x_ + 3), 2 * (8 + zoom) * (y_ + 3));
201+
}
202+
}
203+
}
204+
205+
// //Then draw city
206+
// graphics.DrawImage(CreateCityBitmap(city, false, 8), 64 * 1 + 32 * (3 % 2) + 1, 16 * 2 + 1);
207+
208+
// //Then draw food/shield/trade icons around the city (21 squares around city)
209+
// int[,] offsets = new int[21, 2] { { 0, 0 }, { -1, -3 }, { -3, -1 }, { -3, 1 }, { -1, 3 }, { 1, 3 }, { 3, 1 }, { 3, -1 }, { 1, -3 }, { -2, -2 }, { -2, 2 }, { 2, 2 },
210+
// { 2, -2 }, { 0, -2 }, { -1, -1 }, { -2, 0 }, { -1, 1 }, { 0, 2 }, { 1, 1 }, { 2, 0 }, { 1, -1 } }; //offset of squares from city square (0,0)
211+
// int[] cityFood = city.FoodDistribution;
212+
// int[] cityShld = city.ShieldDistribution;
213+
// int[] cityTrad = city.TradeDistribution;
214+
// for (int i = 0; i < 21; i++)
215+
// if (city.DistributionWorkers[i] == 1)
216+
// {
217+
// //First count all icons on this square to determine the spacing between icons (10 = no spacing, 15 = no spacing @ 50% scaled)
218+
// int spacing;
219+
// switch (cityFood[i] + cityShld[i] + cityTrad[i])
220+
// {
221+
// case 1:
222+
// case 2: spacing = 17; break; //50 % larger (orignal = 11, 1 pixel gap)
223+
// case 3: spacing = 15; break; //50 % larger (orignal = 10, no gap)
224+
// case 4: spacing = 11; break; //50 % larger (orignal = 7)
225+
// case 5: spacing = 8; break; //50 % larger (orignal = 5)
226+
// case 6: spacing = 6; break; //50 % larger (orignal = 4)
227+
// case 7:
228+
// case 8: spacing = 5; break; //50 % larger (orignal = 3)
229+
// case 9: spacing = 3; break; //50 % larger (orignal = 2)
230+
// case 10: spacing = 2; break; //50 % larger (orignal = 1)
231+
// default: spacing = 2; break; //50 % larger (orignal = 1)
232+
// }
233+
234+
// //First draw food, then shields, then trade icons
235+
// int x_offset = 32 - ((cityFood[i] + cityShld[i] + cityTrad[i] - 1) * spacing + 15) / 2;
236+
// int y_offset = 9;
237+
// for (int j = 0; j < cityFood[i]; j++) graphics.DrawImage(CitymapFoodSmallBigger, x_offset + (3 + offsets[i, 0]) * 32 + j * spacing, y_offset + (3 + offsets[i, 1]) * 16);
238+
// for (int j = 0; j < cityShld[i]; j++) graphics.DrawImage(CitymapShieldSmallBigger, x_offset + (3 + offsets[i, 0]) * 32 + (cityFood[i] + j) * spacing, y_offset + (3 + offsets[i, 1]) * 16);
239+
// for (int j = 0; j < cityTrad[i]; j++) graphics.DrawImage(CitymapTradeSmallBigger, x_offset + (3 + offsets[i, 0]) * 32 + (cityFood[i] + cityShld[i] + j) * spacing, y_offset + (3 + offsets[i, 1]) * 16);
240+
// }
241+
}
242+
return _map;
225243
}
226244
}
227245
}

src/Bitmaps/Draw.Map.cs

+8-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public partial class Draw
1515
public static Bitmap DrawMap(int civ, bool flatEarth) // Draw for normal zoom level
1616
{
1717
// Define a bitmap for drawing
18-
Bitmap mapPic = new Bitmap(32 * (2 * Map.Xdim + 1), 16 * (2 * Map.Ydim + 1));
18+
var mapPic = new Bitmap(32 * (2 * Map.Xdim + 1), 16 * (2 * Map.Ydim + 1));
1919

2020
// Draw map
2121
int zoom = 0; // Default zoom
@@ -54,24 +54,28 @@ public partial class Draw
5454
{
5555
int[] offset = new int[] { -1, 1 };
5656
for (int tileX = 0; tileX < 2; tileX++)
57+
{
5758
for (int tileY = 0; tileY < 2; tileY++)
5859
{
5960
int colNew = col + offset[tileX];
6061
int rowNew = row + offset[tileY];
6162
if (colNew >= 0 && colNew < 2 * Map.Xdim && rowNew >= 0 && rowNew < Map.Ydim) // Don't observe outside map limits
63+
{
6264
if (!Map.VisibilityC2(colNew, rowNew, civ)) // Surrounding tile is not visible -> dither
6365
g.DrawImage(Images.DitherDots[tileX, tileY], 32 * (col + tileX), 16 * (row + tileY));
66+
}
6467
}
68+
}
6569
}
6670

6771
// Units
6872
List<IUnit> unitsHere = Game.GetUnits.Where(u => u.X == col && u.Y == row).ToList();
69-
if (unitsHere.Any())
73+
if (unitsHere.Count > 0)
7074
{
7175
IUnit unit = unitsHere.Last();
7276
if (!unit.IsInCity)
7377
{
74-
g.DrawImage(Draw.Unit(unit, unitsHere.Count() > 1, zoom), 32 * col, 16 * row - 16);
78+
g.DrawImage(Draw.Unit(unit, unitsHere.Count > 1, zoom), 32 * col, 16 * row - 16);
7579
}
7680
}
7781

@@ -92,7 +96,7 @@ public partial class Draw
9296
if ((civ < 8 && Map.VisibilityC2(city.X, city.Y, civ)) || civ == 8)
9397
{
9498
Bitmap cityNameBitmap = Draw.CityName(city, zoom);
95-
g.DrawImage(cityNameBitmap, 32 * city.X + 32 - cityNameBitmap.Width / 2, 16 * city.Y + 3 * 8);
99+
g.DrawImage(cityNameBitmap, 32 * city.X + 32 - (cityNameBitmap.Width / 2), 16 * city.Y + 3 * 8);
96100
}
97101
}
98102
}

0 commit comments

Comments
 (0)