1
1
/*
2
2
This file is part of Warzone 2100.
3
- Copyright (C) 2013-2021 Warzone 2100 Project
3
+ Copyright (C) 2013-2023 Warzone 2100 Project
4
4
5
5
Warzone 2100 is free software; you can redistribute it and/or modify
6
6
it under the terms of the GNU General Public License as published by
@@ -119,7 +119,7 @@ static inline T clip(T x, T min, T max)
119
119
return x < min ? min : x > max ? max : x;
120
120
}
121
121
122
- static void plotBackdropPixel (MapPreviewImage& output, int32_t xx, int32_t yy, MapPreviewColor const &colour)
122
+ static void plotBackdropPixel (MapPreviewImage& output, int32_t xx, int32_t yy, const MapPreviewColor &colour)
123
123
{
124
124
xx = clip (xx, 0 , static_cast <int32_t >(output.width - 1 ));
125
125
yy = clip (yy, 0 , static_cast <int32_t >(output.height - 1 ));
@@ -129,6 +129,47 @@ static void plotBackdropPixel(MapPreviewImage& output, int32_t xx, int32_t yy, M
129
129
pixel[2 ] = colour.b ;
130
130
}
131
131
132
+ // Round direction to nearest axis-aligned direction.
133
+ static inline uint16_t snapDirection (uint16_t direction)
134
+ {
135
+ return (direction + 0x2000 ) & 0xC000 ;
136
+ }
137
+
138
+ static void plotBackdropStructurePixels (MapPreviewImage& output, const Structure &structure, const MapStatsConfiguration& statsConfig, const MapPreviewColor &colour)
139
+ {
140
+ if (statsConfig.isStructExpansionModule (structure.name ))
141
+ {
142
+ // Skip drawing expansion modules on the map preview
143
+ return ;
144
+ }
145
+
146
+ MapStatsConfiguration::StructureSize structStatSize = statsConfig.getStructureSize (structure.name ).value_or (MapStatsConfiguration::StructureSize (1 ,1 ));
147
+
148
+ std::pair<int32_t , int32_t > size = {structStatSize.baseWidth , structStatSize.baseBreadth };
149
+ if ((snapDirection (structure.direction ) & 0x4000 ) != 0 )
150
+ {
151
+ // If building is rotated left or right by 90°, swap width and height
152
+ std::swap (size.first , size.second );
153
+ }
154
+
155
+ // Snap the WorldPos to a tile
156
+ int32_t x = (structure.position .x & ~TILE_MASK) + size.first % 2 * TILE_UNITS / 2 ;
157
+ int32_t y = (structure.position .y & ~TILE_MASK) + size.second % 2 * TILE_UNITS / 2 ;
158
+
159
+ // Calculate starting MapTilePos for output
160
+ std::pair<int32_t , int32_t > map = { map_coord (x), map_coord (y) };
161
+ map.first -= size.first / 2 ;
162
+ map.second -= size.second / 2 ;
163
+
164
+ for (int32_t tileX = map.first ; tileX < map.first + size.first ; ++tileX)
165
+ {
166
+ for (int32_t tileY = map.second ; tileY < map.second + size.second ; ++tileY)
167
+ {
168
+ plotBackdropPixel (output, tileX, tileY, colour);
169
+ }
170
+ }
171
+ }
172
+
132
173
static inline bool isOilResource (const Feature& feature)
133
174
{
134
175
return feature.name .rfind (" OilResource" , 0 ) == 0 ;
@@ -184,7 +225,7 @@ static void plotWzMapFeature(Map &wzMap, const MapPreviewColorScheme& colorSchem
184
225
* present. Additionally we load the player's HQ location into playeridpos so
185
226
* we know the player's starting location.
186
227
*/
187
- bool plotStructurePreviewWzMap (Map &wzMap, const MapPreviewColorScheme& colorScheme, MapPreviewImage& output, LoggingProtocol* pCustomLogger)
228
+ bool plotStructurePreviewWzMap (Map &wzMap, const MapPreviewColorScheme& colorScheme, const MapStatsConfiguration& statsConfig, MapPreviewImage& output, LoggingProtocol* pCustomLogger)
188
229
{
189
230
auto pStructures = wzMap.mapStructures ();
190
231
if (pStructures == nullptr )
@@ -219,7 +260,7 @@ bool plotStructurePreviewWzMap(Map &wzMap, const MapPreviewColorScheme& colorSch
219
260
color = colorScheme.hqColor ;
220
261
}
221
262
// and now we blit the color to the texture
222
- plotBackdropPixel (output, pos. first , pos. second , color);
263
+ plotBackdropStructurePixels (output, structure, statsConfig , color);
223
264
}
224
265
225
266
plotWzMapFeature (wzMap, colorScheme, output, pCustomLogger);
@@ -237,7 +278,7 @@ static inline TYPE_OF_TERRAIN terrainTypeWzMap(const MapData::MapTile& tile, con
237
278
return data.terrainTypes [tileType];
238
279
}
239
280
240
- std::unique_ptr<MapPreviewImage> generate2DMapPreview (Map& wzMap, const MapPreviewColorScheme& colorScheme, LoggingProtocol* pCustomLogger /* = nullptr*/ )
281
+ std::unique_ptr<MapPreviewImage> generate2DMapPreview (Map& wzMap, const MapPreviewColorScheme& colorScheme, const MapStatsConfiguration& statsConfig /* = MapStatsConfiguration() */ , LoggingProtocol* pCustomLogger /* = nullptr*/ )
241
282
{
242
283
auto mapData = wzMap.mapData ();
243
284
if (!mapData)
@@ -303,7 +344,7 @@ std::unique_ptr<MapPreviewImage> generate2DMapPreview(Map& wzMap, const MapPrevi
303
344
}
304
345
305
346
// color our texture with clancolors @ correct position
306
- plotStructurePreviewWzMap (wzMap, colorScheme, *(result.get ()), pCustomLogger);
347
+ plotStructurePreviewWzMap (wzMap, colorScheme, statsConfig, *(result.get ()), pCustomLogger);
307
348
308
349
return result;
309
350
}
0 commit comments