Skip to content

Commit

Permalink
Merge branch 'master' into ai_battle
Browse files Browse the repository at this point in the history
  • Loading branch information
wichern authored Jun 18, 2024
2 parents a716d1e + 1d3b15a commit 2c78c28
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 36 deletions.
33 changes: 17 additions & 16 deletions libs/s25main/figures/nofFarmhand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,28 +204,29 @@ bool nofFarmhand::IsPointAvailable(const MapPoint pt) const

void nofFarmhand::WalkToWorkpoint()
{
// Sind wir am Ziel angekommen?
if(pos == dest)
if(GetPointQuality(dest) == PointQuality::NotPossible)
{
// Point became invalid -> Abort and go home
WorkAborted();
StartWalkingHome();
} else if(pos == dest)
{
// Anfangen zu arbeiten
// Arrived at target -> Start working
state = State::Work;
current_ev = GetEvMgr().AddEvent(this, JOB_CONSTS[job_].work_length, 1);
WorkStarted();
return;
}

// Weg suchen und gucken ob der Punkt noch in Ordnung ist
const auto dir = world->FindHumanPath(pos, dest, 20);
if(!dir || GetPointQuality(dest) == PointQuality::NotPossible)
{
// Punkt freigeben
world->SetReserved(dest, false);
// Kein Weg führt mehr zum Ziel oder Punkt ist nich mehr in Ordnung --> wieder nach Hause gehen
StartWalkingHome();
} else
{
// All good, let's start walking there
StartWalking(*dir);
// Keep on walking if possible
const auto dir = world->FindHumanPath(pos, dest, 20);
if(dir)
StartWalking(*dir);
else
{
// Point now unreachable -> abort and go gome
WorkAborted();
StartWalkingHome();
}
}
}

Expand Down
28 changes: 14 additions & 14 deletions libs/s25main/figures/nofFisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,34 +89,34 @@ unsigned short nofFisher::GetCarryID() const
return 70;
}

/// Abgeleitete Klasse informieren, wenn sie anfängt zu arbeiten (Vorbereitungen)
void nofFisher::WorkStarted()
{
// Punkt mit Fisch suchen (mit zufälliger Richtung beginnen)
// Find a random neighbour point with fish
unsigned fishAmount = 0;
for(Direction dir : helpers::enumRange(RANDOM_ENUM(Direction)))
{
fishing_dir = dir;
Resource neighbourRes = world->GetNode(world->GetNeighbour(pos, fishing_dir)).resources;
const Resource neighbourRes = world->GetNode(world->GetNeighbour(pos, dir)).resources;
if(neighbourRes.has(ResourceType::Fish))
{
fishing_dir = dir;
fishAmount = neighbourRes.getAmount();
break;
}
}

// Wahrscheinlichkeit, einen Fisch zu fangen sinkt mit abnehmendem Bestand
unsigned short probability =
40 + (world->GetNode(world->GetNeighbour(pos, fishing_dir)).resources.getAmount()) * 10;
successful = (RANDOM_RAND(100) < probability);
// Probability to catch a fish is proportional to the amount of fish
const int probability = (fishAmount == 0) ? 0 : 40 + fishAmount * 10;
successful = RANDOM_RAND(100) < probability;
// On success remove the fish now to make it unavailable to others
if(successful && !world->GetGGS().isEnabled(AddonId::INEXHAUSTIBLE_FISH))
world->ReduceResource(world->GetNeighbour(pos, fishing_dir));
}

/// Abgeleitete Klasse informieren, wenn fertig ist mit Arbeiten
void nofFisher::WorkFinished()
{
// Wenn ich einen Fisch gefangen habe, den Fisch "abbauen" und in die Hand nehmen
if(successful)
{
if(!world->GetGGS().isEnabled(AddonId::INEXHAUSTIBLE_FISH))
world->ReduceResource(world->GetNeighbour(pos, fishing_dir));
ware = GoodType::Fish;
} else
else
ware = boost::none;
}

Expand Down
9 changes: 4 additions & 5 deletions libs/s25main/ogl/glFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
#include "FontStyle.h"
#include "Loader.h"
#include "drivers/VideoDriverWrapper.h"
#include "glArchivItem_Bitmap.h"
#include "glArchivItem_Bitmap_Raw.h"
#include "helpers/containerUtils.h"
#include "libsiedler2/ArchivItem_Bitmap_Player.h"
#include "libsiedler2/ArchivItem_Font.h"
#include "libsiedler2/IAllocator.h"
#include "libsiedler2/PixelBufferBGRA.h"
#include "libsiedler2/libsiedler2.h"
#include "s25util/utf8.h"
Expand All @@ -27,8 +26,8 @@ using utf8 = utf::utf_traits<char>;

glFont::glFont(const libsiedler2::ArchivItem_Font& font) : maxCharSize(font.getDx(), font.getDy()), asciiMapping{}
{
fontWithOutline = libsiedler2::getAllocator().create<glArchivItem_Bitmap>(libsiedler2::BobType::Bitmap);
fontNoOutline = libsiedler2::getAllocator().create<glArchivItem_Bitmap>(libsiedler2::BobType::Bitmap);
fontWithOutline = std::make_unique<glArchivItem_Bitmap_Raw>();
fontNoOutline = std::make_unique<glArchivItem_Bitmap_Raw>();

// first, we have to find how much chars we really have
unsigned numChars = 0;
Expand Down Expand Up @@ -79,7 +78,7 @@ glFont::glFont(const libsiedler2::ArchivItem_Font& font) : maxCharSize(font.getD
fontNoOutline->create(bufferNoOutline);
fontWithOutline->create(bufferWithOutline);

// Set the placeholder for non-existant glyphs. Use '?' (should always be possible)
// Set the placeholder for non-existent glyphs. Use '?' (should always be possible)
if(CharExist(0xFFFD))
placeHolder = GetCharInfo(0xFFFD);
else if(CharExist('?'))
Expand Down
2 changes: 1 addition & 1 deletion libs/s25main/world/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ GO_Type World::GetGOT(const MapPoint pt) const

void World::ReduceResource(const MapPoint pt)
{
uint8_t curAmount = GetNodeInt(pt).resources.getAmount();
const uint8_t curAmount = GetNodeInt(pt).resources.getAmount();
RTTR_Assert(curAmount > 0);
GetNodeInt(pt).resources.setAmount(curAmount - 1u);
}
Expand Down
5 changes: 5 additions & 0 deletions tests/s25Main/integration/testGameWorldView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later

#include "PointOutput.h"
#include "uiHelper/uiHelpers.hpp"
#include "worldFixtures/CreateEmptyWorld.h"
#include "worldFixtures/WorldFixture.h"
#include "world/GameWorldView.h"
Expand All @@ -19,6 +20,8 @@ using EmptyWorldFixture1P = WorldFixture<CreateEmptyWorld, 1>;

BOOST_FIXTURE_TEST_CASE(HasCorrectDrawCoords, EmptyWorldFixture1P)
{
uiHelper::initGUITests(); // Required for GameWorldView

GameWorldViewer gwv(0, world);
const auto viewSize = rttr::test::randomPoint<Extent>(100, 1000);
GameWorldView view(gwv, Position(0, 0), viewSize);
Expand Down Expand Up @@ -78,6 +81,8 @@ BOOST_FIXTURE_TEST_CASE(HasCorrectDrawCoords, EmptyWorldFixture1P)

BOOST_FIXTURE_TEST_CASE(GetsCorrectMaxHeight, EmptyWorldFixture1P)
{
uiHelper::initGUITests(); // Required for GameWorldView

GameWorldViewer gwv(0, world);
const auto viewSize = rttr::test::randomPoint<Extent>(100, 1000);
GameWorldView view(gwv, Position(0, 0), viewSize);
Expand Down

0 comments on commit 2c78c28

Please sign in to comment.