Skip to content

Commit a1875d6

Browse files
authored
Merge pull request #1479 from Flamefire/fix_harborDistanceFlag
Don't set Harbor distance for military buildings if sea attacks are disabled and fix crash when adding objects using player-textures via LUA
2 parents f5e17a2 + 63689a6 commit a1875d6

Some content is hidden

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

52 files changed

+656
-219
lines changed

.github/workflows/release.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
#
33
# SPDX-License-Identifier: GPL-2.0-or-later
44

5+
name: Create Release
6+
57
on:
68
push:
79
tags:
810
- 'v*'
911

10-
name: Create Release
12+
concurrency:
13+
group: ${{format('release-{0}:{1}', github.repository, github.ref)}}
14+
cancel-in-progress: true
1115

1216
jobs:
1317
release:

.github/workflows/static-analysis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88
push:
99
pull_request:
1010

11+
concurrency:
12+
group: ${{format('staticAna-{0}:{1}', github.repository, github.ref)}}
13+
cancel-in-progress: true
14+
1115
env:
1216
CC: clang-10
1317
CXX: clang++-10

.github/workflows/unit-tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88
push:
99
pull_request:
1010

11+
concurrency:
12+
group: ${{format('tests-{0}:{1}', github.repository, github.ref)}}
13+
cancel-in-progress: true
14+
1115
env:
1216
BOOST_VERSION: 1.69.0
1317
ADDITIONAL_CMAKE_FLAGS: -DRTTR_ENABLE_BENCHMARKS=ON

libs/s25main/BasePlayerInfo.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,7 @@ BasePlayerInfo::BasePlayerInfo(Serializer& ser, bool lightData)
2424
name = ser.PopLongString();
2525
nation = helpers::popEnum<Nation>(ser);
2626
color = ser.PopUnsignedInt();
27-
// Temporary workaround: The random team was stored in the file but should not anymore, see PR #1331
28-
auto tmpTeam = ser.Pop<uint8_t>();
29-
if(tmpTeam > static_cast<uint8_t>(Team::Team4))
30-
tmpTeam -= 3; // Was random team 2-4
31-
else if(tmpTeam > helpers::MaxEnumValue_v<Team>)
32-
throw helpers::makeOutOfRange(tmpTeam, helpers::MaxEnumValue_v<Team>);
33-
team = Team(tmpTeam);
34-
if(team == Team::Random)
35-
team = Team::Team1; // Was random team 1
36-
// team = helpers::popEnum<Team>(ser);
27+
team = helpers::popEnum<Team>(ser);
3728
}
3829
}
3930

libs/s25main/CatapultStone.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void CatapultStone::Draw(DrawPoint drawOffset)
5454
DrawPoint drawPos = destPos - drawOffset + worldSize;
5555
drawPos.x %= worldSize.x;
5656
drawPos.y %= worldSize.y;
57-
LOADER.GetMapPlayerImage(3102 + GAMECLIENT.Interpolate(4, event))->DrawFull(drawPos);
57+
LOADER.GetMapTexture(3102 + GAMECLIENT.Interpolate(4, event))->DrawFull(drawPos);
5858
} else
5959
{
6060
// Linear interpolieren zwischen Ausgangs- und Zielpunkt
@@ -64,7 +64,7 @@ void CatapultStone::Draw(DrawPoint drawOffset)
6464
drawPos.x %= worldSize.x;
6565
drawPos.y %= worldSize.y;
6666
// Schatten auf linearer Linie zeichnen
67-
LOADER.GetMapImageN(3101)->DrawFull(drawPos, COLOR_SHADOW);
67+
LOADER.GetMapTexture(3101)->DrawFull(drawPos, COLOR_SHADOW);
6868

6969
Position distance = destPos - startPos;
7070
double whole = std::sqrt(double(distance.x * distance.x + distance.y * distance.y));
@@ -80,7 +80,7 @@ void CatapultStone::Draw(DrawPoint drawOffset)
8080

8181
// Stein auf Parabel zeichnen
8282
drawPos.y = (drawPos.y + diff) % worldSize.y;
83-
LOADER.GetMapPlayerImage(3100)->DrawFull(drawPos);
83+
LOADER.GetMapTexture(3100)->DrawFull(drawPos);
8484
}
8585
}
8686

libs/s25main/FOWObjects.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,12 @@ void fowTree::Draw(DrawPoint drawPt) const
144144
if(size == 3)
145145
{
146146
// Ausgewachsen
147-
LOADER.GetMapImageN(200 + type * 15)->DrawFull(drawPt, FOW_DRAW_COLOR);
148-
LOADER.GetMapImageN(350 + type * 15)->DrawFull(drawPt, COLOR_SHADOW);
147+
LOADER.GetMapTexture(200 + type * 15)->DrawFull(drawPt, FOW_DRAW_COLOR);
148+
LOADER.GetMapTexture(350 + type * 15)->DrawFull(drawPt, COLOR_SHADOW);
149149
} else
150150
{
151-
LOADER.GetMapImageN(208 + type * 15 + size)->DrawFull(drawPt, FOW_DRAW_COLOR);
152-
LOADER.GetMapImageN(358 + type * 15 + size)->DrawFull(drawPt, COLOR_SHADOW);
151+
LOADER.GetMapTexture(208 + type * 15 + size)->DrawFull(drawPt, FOW_DRAW_COLOR);
152+
LOADER.GetMapTexture(358 + type * 15 + size)->DrawFull(drawPt, COLOR_SHADOW);
153153
}
154154
}
155155

libs/s25main/Loader.cpp

Lines changed: 65 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,12 @@ glArchivItem_Bitmap_Player* Loader::GetNationPlayerImage(Nation nation, unsigned
163163
return checkedCast<glArchivItem_Bitmap_Player*>(GetNationImageN(nation, nr));
164164
}
165165

166-
glArchivItem_Bitmap* Loader::GetMapImageN(unsigned nr)
166+
glArchivItem_Bitmap* Loader::GetMapImage(unsigned nr)
167167
{
168168
return convertChecked<glArchivItem_Bitmap*>(map_gfx->get(nr));
169169
}
170170

171-
ITexture* Loader::GetMapTexN(unsigned nr)
171+
ITexture* Loader::GetMapTexture(unsigned nr)
172172
{
173173
return convertChecked<ITexture*>(map_gfx->get(nr));
174174
}
@@ -343,6 +343,47 @@ void Loader::LoadDummyGUIFiles()
343343
}
344344
}
345345

346+
void Loader::LoadDummyMapFiles()
347+
{
348+
libsiedler2::Archiv& map = files_["map_0_z"].archive;
349+
if(!map.empty())
350+
return;
351+
const auto pushRange = [&map](unsigned from, unsigned to) {
352+
map.alloc_inc(to - map.size() + 1);
353+
libsiedler2::PixelBufferBGRA buffer(1, 1);
354+
for(unsigned i = from; i <= to; i++)
355+
{
356+
auto bmp = std::make_unique<glArchivItem_Bitmap_Raw>();
357+
bmp->create(buffer);
358+
map.set(i, std::move(bmp));
359+
};
360+
};
361+
map_gfx = &map;
362+
363+
// Some ID ranges as found in map_0_z.lst
364+
pushRange(20, 23);
365+
pushRange(40, 46);
366+
pushRange(50, 55);
367+
pushRange(59, 67);
368+
pushRange(200, 282);
369+
pushRange(290, 334);
370+
pushRange(350, 432);
371+
pushRange(440, 484);
372+
pushRange(500, 527);
373+
374+
for(int j = 0; j <= 5; j++)
375+
{
376+
libsiedler2::Archiv& bobs = files_[ResourceId("mis" + std::to_string(j) + "bobs")].archive;
377+
libsiedler2::PixelBufferBGRA buffer(1, 1);
378+
for(unsigned i = 0; i <= 10; i++)
379+
{
380+
auto bmp = std::make_unique<glArchivItem_Bitmap_Raw>();
381+
bmp->create(buffer);
382+
bobs.push(std::move(bmp));
383+
}
384+
}
385+
}
386+
346387
namespace {
347388
struct NationResourcesSource
348389
{
@@ -473,17 +514,17 @@ void Loader::fillCaches()
473514

474515
bmp.reset();
475516

476-
bmp.add(GetMapImageN(ANIMALCONSTS[species].walking_id
477-
+ ANIMALCONSTS[species].animation_steps * rttr::enum_cast(dir + 3u) + ani_step));
517+
bmp.add(GetMapImage(ANIMALCONSTS[species].walking_id
518+
+ ANIMALCONSTS[species].animation_steps * rttr::enum_cast(dir + 3u) + ani_step));
478519

479520
if(ANIMALCONSTS[species].shadow_id)
480521
{
481522
if(species == Species::Duck)
482523
// Ente Sonderfall, da gibts nur einen Schatten für jede Richtung!
483-
bmp.addShadow(GetMapImageN(ANIMALCONSTS[species].shadow_id));
524+
bmp.addShadow(GetMapImage(ANIMALCONSTS[species].shadow_id));
484525
else
485526
// ansonsten immer pro Richtung einen Schatten
486-
bmp.addShadow(GetMapImageN(ANIMALCONSTS[species].shadow_id + rttr::enum_cast(dir + 3u)));
527+
bmp.addShadow(GetMapImage(ANIMALCONSTS[species].shadow_id + rttr::enum_cast(dir + 3u)));
487528
}
488529

489530
stp->add(bmp);
@@ -496,11 +537,11 @@ void Loader::fillCaches()
496537

497538
if(ANIMALCONSTS[species].dead_id)
498539
{
499-
bmp.add(GetMapImageN(ANIMALCONSTS[species].dead_id));
540+
bmp.add(GetMapImage(ANIMALCONSTS[species].dead_id));
500541

501542
if(ANIMALCONSTS[species].shadow_dead_id)
502543
{
503-
bmp.addShadow(GetMapImageN(ANIMALCONSTS[species].shadow_dead_id));
544+
bmp.addShadow(GetMapImage(ANIMALCONSTS[species].shadow_dead_id));
504545
}
505546

506547
stp->add(bmp);
@@ -593,7 +634,7 @@ void Loader::fillCaches()
593634
bob_jobs->getBody(spriteData.isFat(), imgDir, ani_step)));
594635
bmp.add(dynamic_cast<glArchivItem_Bitmap_Player*>(
595636
bob_jobs->getOverlay(spriteData.getBobId(Nation(nation)), spriteData.isFat(), imgDir, ani_step)));
596-
bmp.addShadow(GetMapImageN(900 + static_cast<unsigned>(imgDir) * 8 + ani_step));
637+
bmp.addShadow(GetMapImage(900 + static_cast<unsigned>(imgDir) * 8 + ani_step));
597638

598639
stp->add(bmp);
599640
}
@@ -611,7 +652,7 @@ void Loader::fillCaches()
611652

612653
bmp.add(dynamic_cast<glArchivItem_Bitmap_Player*>(bob_jobs->getBody(true, imgDir, ani_step)));
613654
bmp.add(dynamic_cast<glArchivItem_Bitmap_Player*>(bob_jobs->getOverlay(0, true, imgDir, ani_step)));
614-
bmp.addShadow(GetMapImageN(900 + static_cast<unsigned>(imgDir) * 8 + ani_step));
655+
bmp.addShadow(GetMapImage(900 + static_cast<unsigned>(imgDir) * 8 + ani_step));
615656

616657
stp->add(bmp);
617658
}
@@ -681,10 +722,10 @@ void Loader::fillCaches()
681722
682723
bmp.reset();
683724
684-
bmp.add(static_cast<glArchivItem_Bitmap_Player *>(GetMapImageN(3162+ani_step)));
725+
bmp.add(static_cast<glArchivItem_Bitmap_Player *>(GetMapTexture(3162+ani_step)));
685726
686727
int a, b, c, d;
687-
static_cast<glArchivItem_Bitmap_Player *>(GetMapImageN(3162+ani_step))->getVisibleArea(a, b, c, d);
728+
static_cast<glArchivItem_Bitmap_Player *>(GetMapTexture(3162+ani_step))->getVisibleArea(a, b, c, d);
688729
fprintf(stderr, "%i,%i (%ix%i)\n", a, b, c, d);
689730
690731
@@ -700,8 +741,8 @@ void Loader::fillCaches()
700741

701742
bmp.reset();
702743

703-
bmp.add(GetMapImageN(200 + type * 15 + ani_step));
704-
bmp.addShadow(GetMapImageN(350 + type * 15 + ani_step));
744+
bmp.add(GetMapImage(200 + type * 15 + ani_step));
745+
bmp.addShadow(GetMapImage(350 + type * 15 + ani_step));
705746

706747
stp->add(bmp);
707748
}
@@ -716,8 +757,8 @@ void Loader::fillCaches()
716757

717758
bmp.reset();
718759

719-
bmp.add(GetMapImageN(516 + rttr::enum_cast(type) * 6 + size));
720-
bmp.addShadow(GetMapImageN(616 + rttr::enum_cast(type) * 6 + size));
760+
bmp.add(GetMapImage(516 + rttr::enum_cast(type) * 6 + size));
761+
bmp.addShadow(GetMapImage(616 + rttr::enum_cast(type) * 6 + size));
721762

722763
stp->add(bmp);
723764
}
@@ -732,8 +773,8 @@ void Loader::fillCaches()
732773

733774
bmp.reset();
734775

735-
bmp.add(GetMapImageN(532 + type * 5 + size));
736-
bmp.addShadow(GetMapImageN(632 + type * 5 + size));
776+
bmp.add(GetMapImage(532 + type * 5 + size));
777+
bmp.addShadow(GetMapImage(632 + type * 5 + size));
737778

738779
stp->add(bmp);
739780
}
@@ -748,8 +789,8 @@ void Loader::fillCaches()
748789

749790
bmp.reset();
750791

751-
bmp.add(GetMapImageN(2000 + rttr::enum_cast(dir + 3u) * 8 + ani_step));
752-
bmp.addShadow(GetMapImageN(2048 + rttr::enum_cast(dir) % 3));
792+
bmp.add(GetMapImage(2000 + rttr::enum_cast(dir + 3u) * 8 + ani_step));
793+
bmp.addShadow(GetMapImage(2048 + rttr::enum_cast(dir) % 3));
753794

754795
stp->add(bmp);
755796
}
@@ -765,7 +806,7 @@ void Loader::fillCaches()
765806
bmp.reset();
766807

767808
bmp.add(GetPlayerImage("boat", rttr::enum_cast(dir + 3u) * 8 + ani_step));
768-
bmp.addShadow(GetMapImageN(2048 + rttr::enum_cast(dir) % 3));
809+
bmp.addShadow(GetMapImage(2048 + rttr::enum_cast(dir) % 3));
769810

770811
stp->add(bmp);
771812
}
@@ -796,7 +837,7 @@ void Loader::fillCaches()
796837
bmp.add(dynamic_cast<glArchivItem_Bitmap_Player*>(bob_carrier->getBody(fat, imgDir, ani_step)));
797838
bmp.add(
798839
dynamic_cast<glArchivItem_Bitmap_Player*>(bob_carrier->getOverlay(id, fat, imgDir, ani_step)));
799-
bmp.addShadow(GetMapImageN(900 + static_cast<unsigned>(imgDir) * 8 + ani_step));
840+
bmp.addShadow(GetMapImage(900 + static_cast<unsigned>(imgDir) * 8 + ani_step));
800841

801842
stp->add(bmp);
802843
}
@@ -810,8 +851,8 @@ void Loader::fillCaches()
810851
const unsigned char color_count = 4;
811852

812853
libsiedler2::ArchivItem_Palette* palette = GetPaletteN("pal5");
813-
glArchivItem_Bitmap* image = GetMapImageN(561);
814-
glArchivItem_Bitmap* shadow = GetMapImageN(661);
854+
auto* image = GetMapImage(561);
855+
auto* shadow = GetMapImage(661);
815856

816857
if((image) && (shadow) && (palette))
817858
{

libs/s25main/Loader.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class Loader
8585

8686
/// Creates archives with empty files for the GUI (for testing purposes)
8787
void LoadDummyGUIFiles();
88+
void LoadDummyMapFiles();
8889
/// Load a file and save it into the loader repo
8990
bool Load(const boost::filesystem::path& path, const libsiedler2::ArchivItem_Palette* palette = nullptr);
9091
bool Load(const ResourceId& resId, const libsiedler2::ArchivItem_Palette* palette = nullptr);
@@ -117,22 +118,26 @@ class Loader
117118
/// Same as GetNationImage but returns a ITexture. Note glArchivItem_Bitmap is a ITexture
118119
ITexture* GetNationTex(Nation nation, unsigned nr);
119120
glArchivItem_Bitmap_Player* GetNationPlayerImage(Nation nation, unsigned nr);
120-
glArchivItem_Bitmap* GetMapImageN(unsigned nr);
121-
/// Same as GetMapImageN but returns a ITexture. Note glArchivItem_Bitmap is a ITexture
122-
ITexture* GetMapTexN(unsigned nr);
121+
/// Return the map texture with the given number
122+
ITexture* GetMapTexture(unsigned nr);
123+
/// Return the more specialized map image. Note: Prefer GetMapTexture which also handles (pseudo) player bitmaps
124+
glArchivItem_Bitmap* GetMapImage(unsigned nr);
123125
/// Get the ware symbol texture
124-
ITexture* GetWareTex(GoodType ware) { return GetMapTexN(WARES_TEX_MAP_OFFSET + rttr::enum_cast(ware)); }
126+
ITexture* GetWareTex(GoodType ware) { return GetMapTexture(WARES_TEX_MAP_OFFSET + rttr::enum_cast(ware)); }
125127
/// Get the ware stack texture (lying on ground)
126-
ITexture* GetWareStackTex(GoodType ware) { return GetMapTexN(WARE_STACK_TEX_MAP_OFFSET + rttr::enum_cast(ware)); }
128+
ITexture* GetWareStackTex(GoodType ware)
129+
{
130+
return GetMapTexture(WARE_STACK_TEX_MAP_OFFSET + rttr::enum_cast(ware));
131+
}
127132
/// Get the ware texture when carried by donky
128133
ITexture* GetWareDonkeyTex(GoodType ware)
129134
{
130-
return GetMapTexN(WARES_DONKEY_TEX_MAP_OFFSET + rttr::enum_cast(ware));
135+
return GetMapTexture(WARES_DONKEY_TEX_MAP_OFFSET + rttr::enum_cast(ware));
131136
}
132137
/// Get job symbol texture
133138
ITexture* GetJobTex(Job job)
134139
{
135-
return (job == Job::CharBurner) ? GetTextureN("io_new", 5) : GetMapTexN(2300 + rttr::enum_cast(job));
140+
return (job == Job::CharBurner) ? GetTextureN("io_new", 5) : GetMapTexture(2300 + rttr::enum_cast(job));
136141
}
137142
glArchivItem_Bitmap_Player* GetMapPlayerImage(unsigned nr);
138143

0 commit comments

Comments
 (0)