* Does the town authority allow the (destructive) action of the current company? * @param flags Checking flags of the command. * @param t Town that must allow the company action. * @param type Type of action that is wanted. * @return A succeeded command if the action is allowed, a failed command if it is not allowed. */
| 4075 | * @return A succeeded command if the action is allowed, a failed command if it is not allowed. |
| 4076 | */ |
| 4077 | CommandCost CheckforTownRating(DoCommandFlags flags, Town *t, TownRatingCheckType type) |
| 4078 | { |
| 4079 | /* if magic_bulldozer cheat is active, town doesn't restrict your destructive actions */ |
| 4080 | if (t == nullptr || !Company::IsValidID(_current_company) || |
| 4081 | _cheats.magic_bulldozer.value || flags.Test(DoCommandFlag::NoTestTownRating)) { |
| 4082 | return CommandCost(); |
| 4083 | } |
| 4084 | |
| 4085 | /* minimum rating needed to be allowed to remove stuff */ |
| 4086 | static const int needed_rating[][to_underlying(TownRatingCheckType::End)] = { |
| 4087 | /* RoadRemove, TunnelBridgeRemove */ |
| 4088 | { RATING_ROAD_NEEDED_LENIENT, RATING_TUNNEL_BRIDGE_NEEDED_LENIENT}, // Lenient |
| 4089 | { RATING_ROAD_NEEDED_NEUTRAL, RATING_TUNNEL_BRIDGE_NEEDED_NEUTRAL}, // Neutral |
| 4090 | { RATING_ROAD_NEEDED_HOSTILE, RATING_TUNNEL_BRIDGE_NEEDED_HOSTILE}, // Hostile |
| 4091 | { RATING_ROAD_NEEDED_PERMISSIVE, RATING_TUNNEL_BRIDGE_NEEDED_PERMISSIVE}, // Permissive |
| 4092 | }; |
| 4093 | |
| 4094 | /* check if you're allowed to remove the road/bridge/tunnel |
| 4095 | * owned by a town no removal if rating is lower than ... depends now on |
| 4096 | * difficulty setting. Minimum town rating selected by difficulty level |
| 4097 | */ |
| 4098 | int needed = needed_rating[_settings_game.difficulty.town_council_tolerance][to_underlying(type)]; |
| 4099 | |
| 4100 | if (GetRating(t) < needed) { |
| 4101 | return CommandCostWithParam(STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS, t->index); |
| 4102 | } |
| 4103 | |
| 4104 | return CommandCost(); |
| 4105 | } |
| 4106 | |
| 4107 | template <> |
| 4108 | Town::SuppliedHistory SumHistory(std::span<const Town::SuppliedHistory> history) |
no test coverage detected