Skip to content

Commit

Permalink
Merge pull request #1479 from Flamefire/fix_harborDistanceFlag
Browse files Browse the repository at this point in the history
Don't set Harbor distance for military buildings if sea attacks are disabled and fix crash when adding objects using player-textures via LUA
  • Loading branch information
Flow86 authored Dec 15, 2021
2 parents f5e17a2 + 63689a6 commit a1875d6
Show file tree
Hide file tree
Showing 52 changed files with 656 additions and 219 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
#
# SPDX-License-Identifier: GPL-2.0-or-later

name: Create Release

on:
push:
tags:
- 'v*'

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

jobs:
release:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ on:
push:
pull_request:

concurrency:
group: ${{format('staticAna-{0}:{1}', github.repository, github.ref)}}
cancel-in-progress: true

env:
CC: clang-10
CXX: clang++-10
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ on:
push:
pull_request:

concurrency:
group: ${{format('tests-{0}:{1}', github.repository, github.ref)}}
cancel-in-progress: true

env:
BOOST_VERSION: 1.69.0
ADDITIONAL_CMAKE_FLAGS: -DRTTR_ENABLE_BENCHMARKS=ON
Expand Down
2 changes: 1 addition & 1 deletion external/libutil
11 changes: 1 addition & 10 deletions libs/s25main/BasePlayerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,7 @@ BasePlayerInfo::BasePlayerInfo(Serializer& ser, bool lightData)
name = ser.PopLongString();
nation = helpers::popEnum<Nation>(ser);
color = ser.PopUnsignedInt();
// Temporary workaround: The random team was stored in the file but should not anymore, see PR #1331
auto tmpTeam = ser.Pop<uint8_t>();
if(tmpTeam > static_cast<uint8_t>(Team::Team4))
tmpTeam -= 3; // Was random team 2-4
else if(tmpTeam > helpers::MaxEnumValue_v<Team>)
throw helpers::makeOutOfRange(tmpTeam, helpers::MaxEnumValue_v<Team>);
team = Team(tmpTeam);
if(team == Team::Random)
team = Team::Team1; // Was random team 1
// team = helpers::popEnum<Team>(ser);
team = helpers::popEnum<Team>(ser);
}
}

Expand Down
6 changes: 3 additions & 3 deletions libs/s25main/CatapultStone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void CatapultStone::Draw(DrawPoint drawOffset)
DrawPoint drawPos = destPos - drawOffset + worldSize;
drawPos.x %= worldSize.x;
drawPos.y %= worldSize.y;
LOADER.GetMapPlayerImage(3102 + GAMECLIENT.Interpolate(4, event))->DrawFull(drawPos);
LOADER.GetMapTexture(3102 + GAMECLIENT.Interpolate(4, event))->DrawFull(drawPos);
} else
{
// Linear interpolieren zwischen Ausgangs- und Zielpunkt
Expand All @@ -64,7 +64,7 @@ void CatapultStone::Draw(DrawPoint drawOffset)
drawPos.x %= worldSize.x;
drawPos.y %= worldSize.y;
// Schatten auf linearer Linie zeichnen
LOADER.GetMapImageN(3101)->DrawFull(drawPos, COLOR_SHADOW);
LOADER.GetMapTexture(3101)->DrawFull(drawPos, COLOR_SHADOW);

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

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

Expand Down
8 changes: 4 additions & 4 deletions libs/s25main/FOWObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ void fowTree::Draw(DrawPoint drawPt) const
if(size == 3)
{
// Ausgewachsen
LOADER.GetMapImageN(200 + type * 15)->DrawFull(drawPt, FOW_DRAW_COLOR);
LOADER.GetMapImageN(350 + type * 15)->DrawFull(drawPt, COLOR_SHADOW);
LOADER.GetMapTexture(200 + type * 15)->DrawFull(drawPt, FOW_DRAW_COLOR);
LOADER.GetMapTexture(350 + type * 15)->DrawFull(drawPt, COLOR_SHADOW);
} else
{
LOADER.GetMapImageN(208 + type * 15 + size)->DrawFull(drawPt, FOW_DRAW_COLOR);
LOADER.GetMapImageN(358 + type * 15 + size)->DrawFull(drawPt, COLOR_SHADOW);
LOADER.GetMapTexture(208 + type * 15 + size)->DrawFull(drawPt, FOW_DRAW_COLOR);
LOADER.GetMapTexture(358 + type * 15 + size)->DrawFull(drawPt, COLOR_SHADOW);
}
}

Expand Down
89 changes: 65 additions & 24 deletions libs/s25main/Loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ glArchivItem_Bitmap_Player* Loader::GetNationPlayerImage(Nation nation, unsigned
return checkedCast<glArchivItem_Bitmap_Player*>(GetNationImageN(nation, nr));
}

glArchivItem_Bitmap* Loader::GetMapImageN(unsigned nr)
glArchivItem_Bitmap* Loader::GetMapImage(unsigned nr)
{
return convertChecked<glArchivItem_Bitmap*>(map_gfx->get(nr));
}

ITexture* Loader::GetMapTexN(unsigned nr)
ITexture* Loader::GetMapTexture(unsigned nr)
{
return convertChecked<ITexture*>(map_gfx->get(nr));
}
Expand Down Expand Up @@ -343,6 +343,47 @@ void Loader::LoadDummyGUIFiles()
}
}

void Loader::LoadDummyMapFiles()
{
libsiedler2::Archiv& map = files_["map_0_z"].archive;
if(!map.empty())
return;
const auto pushRange = [&map](unsigned from, unsigned to) {
map.alloc_inc(to - map.size() + 1);
libsiedler2::PixelBufferBGRA buffer(1, 1);
for(unsigned i = from; i <= to; i++)
{
auto bmp = std::make_unique<glArchivItem_Bitmap_Raw>();
bmp->create(buffer);
map.set(i, std::move(bmp));
};
};
map_gfx = &map;

// Some ID ranges as found in map_0_z.lst
pushRange(20, 23);
pushRange(40, 46);
pushRange(50, 55);
pushRange(59, 67);
pushRange(200, 282);
pushRange(290, 334);
pushRange(350, 432);
pushRange(440, 484);
pushRange(500, 527);

for(int j = 0; j <= 5; j++)
{
libsiedler2::Archiv& bobs = files_[ResourceId("mis" + std::to_string(j) + "bobs")].archive;
libsiedler2::PixelBufferBGRA buffer(1, 1);
for(unsigned i = 0; i <= 10; i++)
{
auto bmp = std::make_unique<glArchivItem_Bitmap_Raw>();
bmp->create(buffer);
bobs.push(std::move(bmp));
}
}
}

namespace {
struct NationResourcesSource
{
Expand Down Expand Up @@ -473,17 +514,17 @@ void Loader::fillCaches()

bmp.reset();

bmp.add(GetMapImageN(ANIMALCONSTS[species].walking_id
+ ANIMALCONSTS[species].animation_steps * rttr::enum_cast(dir + 3u) + ani_step));
bmp.add(GetMapImage(ANIMALCONSTS[species].walking_id
+ ANIMALCONSTS[species].animation_steps * rttr::enum_cast(dir + 3u) + ani_step));

if(ANIMALCONSTS[species].shadow_id)
{
if(species == Species::Duck)
// Ente Sonderfall, da gibts nur einen Schatten für jede Richtung!
bmp.addShadow(GetMapImageN(ANIMALCONSTS[species].shadow_id));
bmp.addShadow(GetMapImage(ANIMALCONSTS[species].shadow_id));
else
// ansonsten immer pro Richtung einen Schatten
bmp.addShadow(GetMapImageN(ANIMALCONSTS[species].shadow_id + rttr::enum_cast(dir + 3u)));
bmp.addShadow(GetMapImage(ANIMALCONSTS[species].shadow_id + rttr::enum_cast(dir + 3u)));
}

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

if(ANIMALCONSTS[species].dead_id)
{
bmp.add(GetMapImageN(ANIMALCONSTS[species].dead_id));
bmp.add(GetMapImage(ANIMALCONSTS[species].dead_id));

if(ANIMALCONSTS[species].shadow_dead_id)
{
bmp.addShadow(GetMapImageN(ANIMALCONSTS[species].shadow_dead_id));
bmp.addShadow(GetMapImage(ANIMALCONSTS[species].shadow_dead_id));
}

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

stp->add(bmp);
}
Expand All @@ -611,7 +652,7 @@ void Loader::fillCaches()

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

stp->add(bmp);
}
Expand Down Expand Up @@ -681,10 +722,10 @@ void Loader::fillCaches()
bmp.reset();
bmp.add(static_cast<glArchivItem_Bitmap_Player *>(GetMapImageN(3162+ani_step)));
bmp.add(static_cast<glArchivItem_Bitmap_Player *>(GetMapTexture(3162+ani_step)));
int a, b, c, d;
static_cast<glArchivItem_Bitmap_Player *>(GetMapImageN(3162+ani_step))->getVisibleArea(a, b, c, d);
static_cast<glArchivItem_Bitmap_Player *>(GetMapTexture(3162+ani_step))->getVisibleArea(a, b, c, d);
fprintf(stderr, "%i,%i (%ix%i)\n", a, b, c, d);
Expand All @@ -700,8 +741,8 @@ void Loader::fillCaches()

bmp.reset();

bmp.add(GetMapImageN(200 + type * 15 + ani_step));
bmp.addShadow(GetMapImageN(350 + type * 15 + ani_step));
bmp.add(GetMapImage(200 + type * 15 + ani_step));
bmp.addShadow(GetMapImage(350 + type * 15 + ani_step));

stp->add(bmp);
}
Expand All @@ -716,8 +757,8 @@ void Loader::fillCaches()

bmp.reset();

bmp.add(GetMapImageN(516 + rttr::enum_cast(type) * 6 + size));
bmp.addShadow(GetMapImageN(616 + rttr::enum_cast(type) * 6 + size));
bmp.add(GetMapImage(516 + rttr::enum_cast(type) * 6 + size));
bmp.addShadow(GetMapImage(616 + rttr::enum_cast(type) * 6 + size));

stp->add(bmp);
}
Expand All @@ -732,8 +773,8 @@ void Loader::fillCaches()

bmp.reset();

bmp.add(GetMapImageN(532 + type * 5 + size));
bmp.addShadow(GetMapImageN(632 + type * 5 + size));
bmp.add(GetMapImage(532 + type * 5 + size));
bmp.addShadow(GetMapImage(632 + type * 5 + size));

stp->add(bmp);
}
Expand All @@ -748,8 +789,8 @@ void Loader::fillCaches()

bmp.reset();

bmp.add(GetMapImageN(2000 + rttr::enum_cast(dir + 3u) * 8 + ani_step));
bmp.addShadow(GetMapImageN(2048 + rttr::enum_cast(dir) % 3));
bmp.add(GetMapImage(2000 + rttr::enum_cast(dir + 3u) * 8 + ani_step));
bmp.addShadow(GetMapImage(2048 + rttr::enum_cast(dir) % 3));

stp->add(bmp);
}
Expand All @@ -765,7 +806,7 @@ void Loader::fillCaches()
bmp.reset();

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

stp->add(bmp);
}
Expand Down Expand Up @@ -796,7 +837,7 @@ void Loader::fillCaches()
bmp.add(dynamic_cast<glArchivItem_Bitmap_Player*>(bob_carrier->getBody(fat, imgDir, ani_step)));
bmp.add(
dynamic_cast<glArchivItem_Bitmap_Player*>(bob_carrier->getOverlay(id, fat, imgDir, ani_step)));
bmp.addShadow(GetMapImageN(900 + static_cast<unsigned>(imgDir) * 8 + ani_step));
bmp.addShadow(GetMapImage(900 + static_cast<unsigned>(imgDir) * 8 + ani_step));

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

libsiedler2::ArchivItem_Palette* palette = GetPaletteN("pal5");
glArchivItem_Bitmap* image = GetMapImageN(561);
glArchivItem_Bitmap* shadow = GetMapImageN(661);
auto* image = GetMapImage(561);
auto* shadow = GetMapImage(661);

if((image) && (shadow) && (palette))
{
Expand Down
19 changes: 12 additions & 7 deletions libs/s25main/Loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class Loader

/// Creates archives with empty files for the GUI (for testing purposes)
void LoadDummyGUIFiles();
void LoadDummyMapFiles();
/// Load a file and save it into the loader repo
bool Load(const boost::filesystem::path& path, const libsiedler2::ArchivItem_Palette* palette = nullptr);
bool Load(const ResourceId& resId, const libsiedler2::ArchivItem_Palette* palette = nullptr);
Expand Down Expand Up @@ -117,22 +118,26 @@ class Loader
/// Same as GetNationImage but returns a ITexture. Note glArchivItem_Bitmap is a ITexture
ITexture* GetNationTex(Nation nation, unsigned nr);
glArchivItem_Bitmap_Player* GetNationPlayerImage(Nation nation, unsigned nr);
glArchivItem_Bitmap* GetMapImageN(unsigned nr);
/// Same as GetMapImageN but returns a ITexture. Note glArchivItem_Bitmap is a ITexture
ITexture* GetMapTexN(unsigned nr);
/// Return the map texture with the given number
ITexture* GetMapTexture(unsigned nr);
/// Return the more specialized map image. Note: Prefer GetMapTexture which also handles (pseudo) player bitmaps
glArchivItem_Bitmap* GetMapImage(unsigned nr);
/// Get the ware symbol texture
ITexture* GetWareTex(GoodType ware) { return GetMapTexN(WARES_TEX_MAP_OFFSET + rttr::enum_cast(ware)); }
ITexture* GetWareTex(GoodType ware) { return GetMapTexture(WARES_TEX_MAP_OFFSET + rttr::enum_cast(ware)); }
/// Get the ware stack texture (lying on ground)
ITexture* GetWareStackTex(GoodType ware) { return GetMapTexN(WARE_STACK_TEX_MAP_OFFSET + rttr::enum_cast(ware)); }
ITexture* GetWareStackTex(GoodType ware)
{
return GetMapTexture(WARE_STACK_TEX_MAP_OFFSET + rttr::enum_cast(ware));
}
/// Get the ware texture when carried by donky
ITexture* GetWareDonkeyTex(GoodType ware)
{
return GetMapTexN(WARES_DONKEY_TEX_MAP_OFFSET + rttr::enum_cast(ware));
return GetMapTexture(WARES_DONKEY_TEX_MAP_OFFSET + rttr::enum_cast(ware));
}
/// Get job symbol texture
ITexture* GetJobTex(Job job)
{
return (job == Job::CharBurner) ? GetTextureN("io_new", 5) : GetMapTexN(2300 + rttr::enum_cast(job));
return (job == Job::CharBurner) ? GetTextureN("io_new", 5) : GetMapTexture(2300 + rttr::enum_cast(job));
}
glArchivItem_Bitmap_Player* GetMapPlayerImage(unsigned nr);

Expand Down
11 changes: 10 additions & 1 deletion libs/s25main/SavedFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "SavedFile.h"
#include "BasePlayerInfo.h"
#include "RTTR_Version.h"
#include "enum_cast.hpp"
#include "libendian/ConvertEndianess.h"
#include "s25util/BinaryFile.h"
#include "s25util/Serializer.h"
Expand Down Expand Up @@ -131,7 +132,15 @@ void SavedFile::ReadPlayerData(BinaryFile& file)
const unsigned playerCt = ser.PopUnsignedChar();
players.reserve(playerCt);
for(unsigned i = 0; i < playerCt; i++)
AddPlayer(BasePlayerInfo(ser, true));
{
BasePlayerInfo player(ser, true);
// Temporary workaround: The random team was stored in the file but should not anymore, see PR #1331
if(player.team > Team::Team4)
player.team = Team(rttr::enum_cast(player.team) - 3); // Was random team 2-4
else if(player.team == Team::Random)
player.team = Team::Team1; // Was random team 1
AddPlayer(player);
}
}

/**
Expand Down
3 changes: 1 addition & 2 deletions libs/s25main/ai/aijh/AIConstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,7 @@ helpers::OptionalEnum<BuildingType> AIConstruction::ChooseMilitaryBuilding(const
if(((rand() % 3) == 0 || inventory.people[Job::Private] < 15)
&& (inventory.goods[GoodType::Stones] > 6 || bldPlanner.GetNumBuildings(BuildingType::Quarry) > 0))
bld = BuildingType::Guardhouse;
if(aijh.getAIInterface().isHarborPosClose(pt, 19) && rand() % 10 != 0
&& aijh.ggs.getSelection(AddonId::SEA_ATTACK) != 2)
if(aijh.getAIInterface().isHarborPosClose(pt, 19) && rand() % 10 != 0 && aijh.ggs.isEnabled(AddonId::SEA_ATTACK))
{
if(aii.CanBuildBuildingtype(BuildingType::Watchtower))
return BuildingType::Watchtower;
Expand Down
Loading

0 comments on commit a1875d6

Please sign in to comment.