fixed emergency protocol by removing sheduled wares requested before ... - #1961
fixed emergency protocol by removing sheduled wares requested before ...#1961tost11 wants to merge 9 commits into
Conversation
… only on activation)
Flamefire
left a comment
There was a problem hiding this comment.
LGTM,
trivial style issue in the NULL check which I fixed directly. git pull if you need to do further changes
Flamefire
left a comment
There was a problem hiding this comment.
You need to run clang-format first. If you have it installed when configuring you can run e.g. make clangFormat
Or use the diff as shown in the CI job.
Can you add a test for that? Might be a bit tricky though
Head branch was pushed to by a user without write access
bc104e8 to
689112e
Compare
|
Well, this is original behavior - you were also able to store out wares to get them going anway (a tactic used with very low goods frequently). This fix breaks this original behavior, doesn't it? This sounds reading your description more like a problem the AI has, and should be fixed for the AI instead of for players (maybe the AI can use that system which is slight cheating but I'd opt for a smarter AI instead of an AI playing only by rules) |
What we have:
Not fully sure how the original handled that as it seems like a minor corner case happening rarely. |
|
The issue can also occur for the player, like On low resources, start when starting with multiple buildings (but the sawmill first, but on hilly terrain) and then multiple other buildings (fast before all boards are given out). Then all boards are scheduled for building. The sawmill and woodcutter are already planed. Then some time later the Terain Blow sawmill is leveled, and it requests boards. But all boards are already given out to other buildings. That results in no boards for the sawmill. But yes, it is an edge case, and yes, I mainly built it for the AI to start proper play on some maps where it gets stuck on low-resource starts. But actually it's an issue in the game, not only an AI issue. So what now? I see multiple options that could be implemented to not block fast start for players.
-- Only hold back needed boards (2 for the sawmill and 2 for the woodcutter) depending on what buildings are missing. Also maybe 1 more if the street gets removed and one is lost by the player or AI. What do you prefer? For me it would be the last option, and I also would implement that more complicated but better emergency program behavior if wanted. |
That depends on the definition of "issue". We want (at least the default) behavior to match that of S2, so if "emergency mode" there meant that only newly built buildings do not get boards/stones then that is (usually) what we want.
No issue with that in any case
See above: That would be the most important thing to check first although it may be difficult to get into exactly this situation. But it looks like your description above should be reasonably easy to check. Could you do that?
I think that is too complicated to avoid such a rare issue. In the end this is a resource management game and the emergency mode already a QoL improvement only. So it could be "incomplete" leaving more responsibility to the player. However as queued wares do not turn up for the player anywhere in the UI it might seem like emergency mode is ignored for a short time. I didn't fully understand @Spikeone
What exactly does this break? You build a building, wares for this building are queued, emergency mode activates, wares for building stop being carried out as-if the building was built/connected right after the activation. So I'd lean into accepting this change to enforce the visible semantics: When emergency mode is active no ware will leave the WHs (with the purpose) of going to a "disallowed" building site. |
Flamefire
left a comment
There was a problem hiding this comment.
I verified with the original too in various situations and you are right: They are immediately stopped in warehouses.
We do have a difference though: S2 activates at 4 boards, RTTR at 10.
Anyway, some minor polishing here and it's good to go
| for(auto it = ware_list.begin(); it != ware_list.end();) | ||
| { | ||
| Ware* ware = *it; | ||
| // checks if this ware is |
| const Statistic& GetStatistic(StatisticTime time) const { return statistic[time]; }; | ||
| unsigned GetStatisticCurrentValue(StatisticType idx) const { return statisticCurrentData[idx]; } | ||
|
|
||
| // remove all wares that are already scheduled but ignoring emergency protocol |
There was a problem hiding this comment.
Not sure what "ignoring ..." means here. Maybe:
| // remove all wares that are already scheduled but ignoring emergency protocol | |
| // Stop wares restricted in emergency mode that are waiting in warehouse to be transported already |
|
|
||
| BOOST_FIXTURE_TEST_CASE(EmergencyProtoclActiveWoodcutterAndSawmillCanBuild, EmergencyFixture) | ||
| { | ||
| initGameRNG(); |
|
|
||
| struct EmergencyFixture : public WorldFixture<CreateEmptyWorld, 1> | ||
| { | ||
| nobHQ* HQ = world.GetPlayer(0).GetHQ(); |
There was a problem hiding this comment.
| nobHQ* HQ = world.GetPlayer(0).GetHQ(); | |
| nobHQ* hq = world.GetPlayer(0).GetHQ(); |
|
|
||
| pos = world.GetPlayer(0).GetHQPos() + MapPoint(3, 0); | ||
| world.SetBuildingSite(BuildingType::Farm, pos, 0); | ||
| world.BuildRoad(0, false, world.GetNeighbour(pos, Direction::SouthEast), |
There was a problem hiding this comment.
Maybe derive from WorldWithGCExecution and use BuildRoadForBlds which checks the the roads are built. Especially in the tests it is otherwise not fully clear that the building site is actually connected. Here it is reasonably clear, but for GetHQPos() + MapPoint(-1, 2) it is a bit trickier
| RTTR_EXEC_TILL(500, HQ->GetInventory()[GoodType::Boards] == 10); | ||
|
|
||
| // activate program (with 10 boards it should trigger) | ||
| world.GetPlayer(0).TestForEmergencyProgramm(); |
There was a problem hiding this comment.
Can't we test that this is done automatically? I.e. shouldn't the above activate it? Or at least in the next GF
| // wait for some more ticks to give time if not working to deliver more boards | ||
| RTTR_SKIP_GFS(200); | ||
| // check boards are still fine and protocol working | ||
| BOOST_TEST_CHECK(world.GetPlayer(0).GetHQ()->GetInventory()[GoodType::Boards] == 10); |
There was a problem hiding this comment.
| // wait for some more ticks to give time if not working to deliver more boards | |
| RTTR_SKIP_GFS(200); | |
| // check boards are still fine and protocol working | |
| BOOST_TEST_CHECK(world.GetPlayer(0).GetHQ()->GetInventory()[GoodType::Boards] == 10); | |
| // No more boards are carried out to the farms due to emergency protocol | |
| RTTR_SKIP_GFS(200); | |
| BOOST_TEST_CHECK(hq->GetInventory()[GoodType::Boards] == 10); |
| } | ||
| }; | ||
|
|
||
| BOOST_FIXTURE_TEST_CASE(EmergencyProtoclActiveWoodcutterAndSawmillCanBuild, EmergencyFixture) |
There was a problem hiding this comment.
Typo here and below
| BOOST_FIXTURE_TEST_CASE(EmergencyProtoclActiveWoodcutterAndSawmillCanBuild, EmergencyFixture) | |
| BOOST_FIXTURE_TEST_CASE(EmergencyProtocolActiveWoodcutterAndSawmillCanBuild, EmergencyFixture) |
| // check if inventory boards are given out | ||
| RTTR_EXEC_TILL(200, HQ->GetInventory()[GoodType::Boards] < 10); | ||
|
|
||
| // check if building where found |
There was a problem hiding this comment.
| // check if building where found | |
| // check that buildings are built |
| // wait for some more ticks to give time if not working to deliver more boards | ||
| RTTR_SKIP_GFS(500); | ||
| // check boards are still fine and protocol working | ||
| BOOST_TEST_CHECK(world.GetPlayer(0).GetHQ()->GetInventory()[GoodType::Boards] == 10); |
There was a problem hiding this comment.
| // wait for some more ticks to give time if not working to deliver more boards | |
| RTTR_SKIP_GFS(500); | |
| // check boards are still fine and protocol working | |
| BOOST_TEST_CHECK(world.GetPlayer(0).GetHQ()->GetInventory()[GoodType::Boards] == 10); | |
| // No boards are carried out to the farms or watchtower due to emergency protocol | |
| RTTR_SKIP_GFS(500); | |
| BOOST_TEST_CHECK(hq->GetInventory()[GoodType::Boards] == 10); |


When emergency protocol is activated and many buildings are already planned, the wares already scheduled for delivery are ignoring the protocol.
So now when emergency protocol is activated, those wares get removed (if not for the sawmill or woodcutter).
This also solved the issue for AI enemies on very low resources where they're not able to start because the first sawmill never got built.