@@ -889,6 +889,12 @@ void GamePlayer::FindWarehouseForAllJobs(const Job job)
889889 }
890890}
891891
892+ static bool IsWareFineWithEmergencyProtocol (GoodType goodType, const noBaseBuilding& goal)
893+ {
894+ return (goodType != GoodType::Boards && goodType != GoodType::Stones)
895+ || goal.GetBuildingType () == BuildingType::Woodcutter || goal.GetBuildingType () == BuildingType::Sawmill;
896+ }
897+
892898Ware* GamePlayer::OrderWare (const GoodType ware, noBaseBuilding& goal)
893899{
894900 // / Gibt es ein Lagerhaus mit dieser Ware?
@@ -902,8 +908,7 @@ Ware* GamePlayer::OrderWare(const GoodType ware, noBaseBuilding& goal)
902908 else
903909 {
904910 // Wenn Notfallprogramm aktiv nur an Holzfäller und Sägewerke Bretter/Steine liefern
905- if ((ware != GoodType::Boards && ware != GoodType::Stones)
906- || goal.GetBuildingType () == BuildingType::Woodcutter || goal.GetBuildingType () == BuildingType::Sawmill)
911+ if (IsWareFineWithEmergencyProtocol (ware, goal))
907912 return wh->OrderWare (ware, goal);
908913 else
909914 return nullptr ;
@@ -2089,6 +2094,23 @@ bool GamePlayer::FindHarborForUnloading(noShip* ship, const MapPoint start, Harb
20892094 return false ;
20902095}
20912096
2097+ void GamePlayer::CancelWaresForEmergencyProtocol ()
2098+ {
2099+ for (auto it = ware_list.begin (); it != ware_list.end ();)
2100+ {
2101+ Ware* ware = *it;
2102+ if (ware->IsWaitingInWarehouse () && ware->GetGoal ()
2103+ && !IsWareFineWithEmergencyProtocol (ware->type , *ware->GetGoal ()))
2104+ {
2105+ ware->NotifyGoalAboutLostWare ();
2106+ static_cast <nobBaseWarehouse*>(ware->GetLocation ())->CancelWare (ware);
2107+ it = ware_list.erase (it);
2108+ continue ;
2109+ }
2110+ it++;
2111+ }
2112+ }
2113+
20922114void GamePlayer::TestForEmergencyProgramm ()
20932115{
20942116 // we are already defeated, do not even think about an emergency program - it's too late :-(
@@ -2118,6 +2140,9 @@ void GamePlayer::TestForEmergencyProgramm()
21182140 emergency = true ;
21192141 SendPostMessage (std::make_unique<PostMsg>(
21202142 world.GetEvMgr ().GetCurrentGF (), _ (" The emergency program has been activated." ), PostCategory::Economy));
2143+
2144+ // Handle wares already ordered
2145+ CancelWaresForEmergencyProtocol ();
21212146 }
21222147 } else
21232148 {
0 commit comments