-
Notifications
You must be signed in to change notification settings - Fork 87
Spike/addons/settlers iv mining #1501
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
Draft
Spikeone
wants to merge
15
commits into
master
Choose a base branch
from
spike/addons/settlers_iv_mining
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a778a07
AI: do no longer treat inexhaustible granite mines like it was intend…
Spikeone 088db97
Addons: Add options for each mine type for changing the behavior
Spikeone 174c99b
use one base class for mining overhaul addons
Spikeone 33bd9ab
use enum
Spikeone 3c20586
fixup local build failing due to includes, remove workplace changes
Spikeone 40a9160
rework coding for settlers iv like mining, remove some magic numbers
Spikeone 4e5a182
add new line in mapbase.cpp
Spikeone 65f7e39
rename numPointsRadius to GetNumPointsInRadius to match other naming,…
Spikeone a25a950
rename new consts
Spikeone 833f17a
remove unused include
Spikeone bf302f2
move include
Spikeone df850e3
improve main implementation
Spikeone 8d58bd5
improve addon description
Spikeone b44986b
add saving and loading of isAlteredWorkcycle
Spikeone ae9e40f
ctrl + k, ctrl + d for all files that failed formatting tests
Spikeone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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"), | ||
| }) | ||
| {} | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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"), | ||
| }) | ||
| {} | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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"), | ||
| }) | ||
| {} | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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) | ||||||
|
|
@@ -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; | ||||||
|
||||||
|
|
||||||
| // 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.
Outdated
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.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| // iterate over all points | ||||||
| for each(MapPoint curPt in resPts) | ||||||
Flamefire marked this conversation as resolved.
Outdated
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.
Outdated
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.
Outdated
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.
Outdated
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.
Outdated
Show resolved
Hide resolved
|
||||||
| world->ReduceResource(useResPt); | ||||||
| } | ||||||
| } | ||||||
| break; | ||||||
| case 2: // inexhaustible | ||||||
| { | ||||||
| MapPoint resPt = FindPointWithResource(GetRequiredResType()); | ||||||
| if(!resPt.isValid()) | ||||||
Flamefire marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| return false; | ||||||
| } | ||||||
| break; | ||||||
| case 3: // inexhaustible, everywhere | ||||||
| { | ||||||
| } | ||||||
Flamefire marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| break; | ||||||
| case 0: // original behavior | ||||||
| default: | ||||||
Flamefire marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| { | ||||||
| MapPoint resPt = FindPointWithResource(GetRequiredResType()); | ||||||
|
||||||
| MapPoint resPt = FindPointWithResource(GetRequiredResType()); | |
| const MapPoint resPt = FindPointWithResource(GetRequiredResType()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.