Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spike/addons/settlers iv mining #1501

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions libs/s25main/GlobalGameSettings.cpp
Expand Up @@ -66,6 +66,10 @@ void GlobalGameSettings::registerAllAddons()
AddonBurnDuration,
AddonCatapultGraphics,
AddonChangeGoldDeposits,
AddonMinesGranite,
Flamefire marked this conversation as resolved.
Show resolved Hide resolved
AddonMinesGold,
AddonMinesIron,
AddonMinesCoal,
AddonCharburner,
AddonCoinsCapturedBld,
AddonCustomBuildSequence,
Expand Down
27 changes: 27 additions & 0 deletions libs/s25main/addons/AddonMinesCoal.h
@@ -0,0 +1,27 @@
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include "AddonList.h"
#include "mygettext/mygettext.h"

class AddonMinesCoal : public AddonList
{
public:
AddonMinesCoal()
: AddonList(AddonId::MINES_COAL, AddonGroup::Economy, _("Change coal mine behavior"),
_("This addon lets you control mining behavior.\n\n"
"No change: Original behavior\n"
"Settlers IV: Mines never deplete, but mining becomes less successfull\n"
"Inexhaustible: Mines never deplete\n"
"Everywhere: Mines never deplete, can mine everywhere"),
{
_("No change"),
_("Settlers IV"),
_("Inexhaustible"),
_("Everywhere"),
})
{}
};
27 changes: 27 additions & 0 deletions libs/s25main/addons/AddonMinesGold.h
@@ -0,0 +1,27 @@
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include "AddonList.h"
#include "mygettext/mygettext.h"

class AddonMinesGold : public AddonList
{
public:
AddonMinesGold()
: AddonList(AddonId::MINES_GOLD, AddonGroup::Economy, _("Change gold mine behavior"),
_("This addon lets you control mining behavior.\n\n"
"No change: Original behavior\n"
"Settlers IV: Mines never deplete, but mining becomes less successfull\n"
"Inexhaustible: Mines never deplete\n"
"Everywhere: Mines never deplete, can mine everywhere"),
{
_("No change"),
_("Settlers IV"),
_("Inexhaustible"),
_("Everywhere"),
})
{}
};
28 changes: 28 additions & 0 deletions libs/s25main/addons/AddonMinesGranite.h
@@ -0,0 +1,28 @@
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include "AddonList.h"
#include "mygettext/mygettext.h"

class AddonMinesGranite : public AddonList
{
public:
AddonMinesGranite()
: AddonList(AddonId::MINES_GRANITE, AddonGroup::Economy,
_("Change granite mine behavior"),
_("This addon lets you control mining behavior.\n\n"
"No change: Original behavior\n"
"Settlers IV: Mines never deplete, but mining becomes less successfull\n"
"Inexhaustible: Mines never deplete\n"
"Everywhere: Mines never deplete, can mine everywhere"),
{
_("No change"),
_("Settlers IV"),
_("Inexhaustible"),
_("Everywhere"),
})
{}
};
27 changes: 27 additions & 0 deletions libs/s25main/addons/AddonMinesIron.h
@@ -0,0 +1,27 @@
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include "AddonList.h"
#include "mygettext/mygettext.h"

class AddonMinesIron : public AddonList
{
public:
AddonMinesIron()
: AddonList(AddonId::MINES_IRON, AddonGroup::Economy, _("Change iron mine behavior"),
_("This addon lets you control mining behavior.\n\n"
"No change: Original behavior\n"
"Settlers IV: Mines never deplete, but mining becomes less successfull\n"
"Inexhaustible: Mines never deplete\n"
"Everywhere: Mines never deplete, can mine everywhere"),
{
_("No change"),
_("Settlers IV"),
_("Inexhaustible"),
_("Everywhere"),
})
{}
};
Flamefire marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 6 additions & 1 deletion libs/s25main/addons/Addons.h
Expand Up @@ -34,11 +34,16 @@
#include "addons/AddonToolOrdering.h"

#include "addons/AddonInexhaustibleFish.h"
#include "addons/AddonInexhaustibleGraniteMines.h"
#include "addons/AddonMaxRank.h"
#include "addons/AddonMilitaryAid.h"
#include "addons/AddonSeaAttack.h"

#include "addons/AddonInexhaustibleGraniteMines.h"
#include "addons/AddonMinesGranite.h"
#include "addons/AddonMinesGold.h"
#include "addons/AddonMinesIron.h"
#include "addons/AddonMinesCoal.h"

#include "addons/AddonBattlefieldPromotion.h"
#include "addons/AddonBurnDuration.h"
#include "addons/AddonHalfCostMilEquip.h"
Expand Down
5 changes: 5 additions & 0 deletions libs/s25main/addons/const_addons.h
Expand Up @@ -55,6 +55,11 @@ ENUM_WITH_STRING(AddonId, LIMIT_CATAPULTS = 0x00000000, INEXHAUSTIBLE_MINES = 0x

INEXHAUSTIBLE_GRANITEMINES = 0x00800000,

MINES_GRANITE = 0x00800001,
MINES_GOLD = 0x00800002,
MINES_IRON = 0x00800003,
MINES_COAL = 0x00800004,

MAX_RANK = 0x00900000, SEA_ATTACK = 0x00900001, INEXHAUSTIBLE_FISH = 0x00900002,
MORE_ANIMALS = 0x00900003, BURN_DURATION = 0x00900004, NO_ALLIED_PUSH = 0x00900005,
BATTLEFIELD_PROMOTION = 0x00900006, HALF_COST_MIL_EQUIP = 0x00900007, MILITARY_CONTROL = 0x00900008,
Expand Down
7 changes: 1 addition & 6 deletions libs/s25main/ai/aijh/AIPlayerJH.cpp
Expand Up @@ -977,13 +977,8 @@ MapPoint AIPlayerJH::FindPositionForBuildingAround(BuildingType type, const MapP
foundPos = FindBestPosition(around, AIResource::Ironore, BuildingQuality::Mine, searchRadius);
break;
case BuildingType::GraniteMine:
if(!ggs.isEnabled(
AddonId::INEXHAUSTIBLE_GRANITEMINES)) // inexhaustible granite mines do not require granite
foundPos = FindBestPosition(around, AIResource::Granite, BuildingQuality::Mine, searchRadius);
else
foundPos = SimpleFindPosition(around, BuildingQuality::Mine, searchRadius);
foundPos = FindBestPosition(around, AIResource::Granite, BuildingQuality::Mine, searchRadius);
break;

case BuildingType::Fishery:
foundPos = FindBestPosition(around, AIResource::Fish, BUILDING_SIZE[type], searchRadius);
if(foundPos.isValid() && !ValidFishInRange(foundPos))
Expand Down
3 changes: 3 additions & 0 deletions libs/s25main/buildings/nobUsual.h
Expand Up @@ -57,6 +57,9 @@ class nobUsual : public noBuilding
/// Wird gerade gearbeitet oder nicht?
bool is_working;

/// is this an empty cycle? (use wares but produce nothing)
bool is_emptyCycle;

~nobUsual() override;

void Serialize(SerializedGameData& sgd) const override;
Expand Down
99 changes: 90 additions & 9 deletions libs/s25main/figures/nofMiner.cpp
Expand Up @@ -11,6 +11,7 @@
#include "network/GameClient.h"
#include "ogl/glArchivItem_Bitmap_Player.h"
#include "world/GameWorld.h"
#include <random/Random.h>

nofMiner::nofMiner(const MapPoint pos, const unsigned char player, nobUsual* workplace)
: nofWorkman(Job::Miner, pos, player, workplace)
Expand Down Expand Up @@ -71,20 +72,100 @@ helpers::OptionalEnum<GoodType> nofMiner::ProduceWare()

bool nofMiner::AreWaresAvailable() const
{
// FindPointWithResource triggeres outofresource message
if(GetAddonSetting() == 3)
return true;

return nofWorkman::AreWaresAvailable() && FindPointWithResource(GetRequiredResType()).isValid();
}

bool nofMiner::StartWorking()
unsigned int nofMiner::GetAddonSetting() const
{
MapPoint resPt = FindPointWithResource(GetRequiredResType());
if(!resPt.isValid())
return false;
const GlobalGameSettings& settings = world->GetGGS();
bool inexhaustibleRes = settings.isEnabled(AddonId::INEXHAUSTIBLE_MINES)
|| (workplace->GetBuildingType() == BuildingType::GraniteMine
&& settings.isEnabled(AddonId::INEXHAUSTIBLE_GRANITEMINES));
if(!inexhaustibleRes)
world->ReduceResource(resPt);

switch(workplace->GetBuildingType())
{
case BuildingType::GoldMine: return settings.getSelection(AddonId::MINES_GOLD);
case BuildingType::IronMine: return settings.getSelection(AddonId::MINES_IRON);
case BuildingType::CoalMine: return settings.getSelection(AddonId::MINES_COAL);
case BuildingType::GraniteMine: return settings.getSelection(AddonId::MINES_GRANITE);
default: return 0;
}
}

bool nofMiner::StartWorking()
{
workplace->is_emptyCycle = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a property of the workplace? Shouldn't this be part of the miner? You can use this in ProduceWare to return boost::none aka "nothing"


// needs to have at least one resource spot
// 0 = is exhaustible
// 1 = settlers IV like
// 2 = inexhaustible
// 3 = everywhere
unsigned int addonSettings = GetAddonSetting();
Flamefire marked this conversation as resolved.
Show resolved Hide resolved

switch (addonSettings)
{
case 1: // settlers IV style
{
int sumResAmount = 0;
MapPoint useResPt;

std::vector<MapPoint> resPts = FindAllPointsWithResource(GetRequiredResType());
Flamefire marked this conversation as resolved.
Show resolved Hide resolved

// iterate over all points
for each(MapPoint curPt in resPts)
Flamefire marked this conversation as resolved.
Show resolved Hide resolved
{
// calculate the absolute amount of resource beneath
uint8_t resAmount = world->GetNode(curPt).resources.getAmount();
Flamefire marked this conversation as resolved.
Show resolved Hide resolved
sumResAmount += resAmount;

// if there is one with more than 1 quantity, keep it (for reducing)
if(resAmount > 1 && !useResPt.isValid())
Flamefire marked this conversation as resolved.
Show resolved Hide resolved
useResPt = curPt;
}

// no resources left (mine was built on invalid spot)
if(sumResAmount == 0)
return false;

// 19 = amount of nodes a mine can reach
// 7 = maximum resource amount a node possibly has
if(RANDOM.Rand(RANDOM_CONTEXT(), 19 * 7) > sumResAmount)
Flamefire marked this conversation as resolved.
Show resolved Hide resolved
{
// failed, use food and start working - but produce nothing
workplace->is_emptyCycle = true;
} else
{
// if success, use 1 quantity if any
if(!useResPt.isValid())
Flamefire marked this conversation as resolved.
Show resolved Hide resolved
world->ReduceResource(useResPt);
}
}
break;
case 2: // inexhaustible
{
MapPoint resPt = FindPointWithResource(GetRequiredResType());
if(!resPt.isValid())
Flamefire marked this conversation as resolved.
Show resolved Hide resolved
return false;
}
break;
case 3: // inexhaustible, everywhere
{
}
Flamefire marked this conversation as resolved.
Show resolved Hide resolved
break;
case 0: // original behavior
default:
Flamefire marked this conversation as resolved.
Show resolved Hide resolved
{
MapPoint resPt = FindPointWithResource(GetRequiredResType());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MapPoint resPt = FindPointWithResource(GetRequiredResType());
const MapPoint resPt = FindPointWithResource(GetRequiredResType());

if(!resPt.isValid())
return false;

world->ReduceResource(resPt);
}
break;
}

return nofWorkman::StartWorking();
}

Expand Down
3 changes: 2 additions & 1 deletion libs/s25main/figures/nofMiner.h
Expand Up @@ -9,7 +9,7 @@
class SerializedGameData;
class nobUsual;

/// Klasse für den Schreiner
/// Klasse für den Miner
Flamefire marked this conversation as resolved.
Show resolved Hide resolved
class nofMiner : public nofWorkman
{
protected:
Expand All @@ -23,6 +23,7 @@ class nofMiner : public nofWorkman
bool AreWaresAvailable() const override;
bool StartWorking() override;
ResourceType GetRequiredResType() const;
unsigned int GetAddonSetting() const;

public:
nofMiner(MapPoint pos, unsigned char player, nobUsual* workplace);
Expand Down
12 changes: 11 additions & 1 deletion libs/s25main/figures/nofWorkman.cpp
Expand Up @@ -55,7 +55,7 @@ void nofWorkman::HandleStateWaiting2()
{
current_ev = nullptr;
// Ware erzeugen... (noch nicht "richtig"!, sondern nur viruell erstmal)
if(!(ware = ProduceWare()).has_value())
if(!(ware = ProduceWare()).has_value() || workplace->is_emptyCycle)
Flamefire marked this conversation as resolved.
Show resolved Hide resolved
{
// Soll keine erzeugt werden --> wieder anfangen zu arbeiten
TryToWork();
Expand Down Expand Up @@ -110,3 +110,13 @@ MapPoint nofWorkman::FindPointWithResource(ResourceType type) const

return MapPoint::Invalid();
}

std::vector<MapPoint> nofWorkman::FindAllPointsWithResource(ResourceType type) const
Flamefire marked this conversation as resolved.
Show resolved Hide resolved
{
// int maxResults = (int)((MINER_RADIUS * MINER_RADIUS + MINER_RADIUS) * 3u + 1u);
Flamefire marked this conversation as resolved.
Show resolved Hide resolved

const std::vector<MapPoint> pts =
world->GetMatchingPointsInRadius<19>(pos, MINER_RADIUS, NodeHasResource(*world, type), true);
Flamefire marked this conversation as resolved.
Show resolved Hide resolved

return pts;
}
3 changes: 3 additions & 0 deletions libs/s25main/figures/nofWorkman.h
Expand Up @@ -8,6 +8,7 @@
#include "nofBuildingWorker.h"
#include "gameTypes/GoodTypes.h"
#include "gameTypes/Resource.h"
#include <vector>
Flamefire marked this conversation as resolved.
Show resolved Hide resolved
class SerializedGameData;
class nobBaseWarehouse;
class nobUsual;
Expand Down Expand Up @@ -38,6 +39,8 @@ class nofWorkman : public nofBuildingWorker

/// Looks for a point with a given resource on the node
MapPoint FindPointWithResource(ResourceType type) const;
/// Looks for all points with a given resource on the node
std::vector<MapPoint> FindAllPointsWithResource(ResourceType type) const;

public:
/// Going to workplace
Expand Down