# ai_error.hpp File Reference

Everything to query errors. More...

`#include "ai_object.hpp"`
`#include <map>`

Go to the source code of this file.

## Data Structures
class | AIError
| Class that handles all error related functions. More...
## Defines
#define | EnforcePrecondition(returnval, condition)
| Helper to write precondition enforcers for the AI API in an abbreviated manner.
#define | EnforcePreconditionCustomError(returnval, condition, error_code)
| Helper to write precondition enforcers for the AI API in an abbreviated manner.

## Detailed Description

Everything to query errors.

Definition in file ai_error.hpp.

## Define Documentation

#define EnforcePrecondition | ( | returnval,
|  | condition |  | ) |

Value:

    if (!(condition)) {                                           \
        AIObject::SetLastError(AIError::ERR_PRECONDITION_FAILED);   \
        return returnval;                                           \
      }

Helper to write precondition enforcers for the AI API in an abbreviated manner.

Parameters:

  | returnval | The value to return on failure.
  | condition | The condition that must be obeyed.

Definition at line 23 of file ai_error.hpp.

Referenced by AIRoad::_BuildRoadInternal(), AIRoad::_BuildRoadStationInternal(), AIVehicle::_MoveWagonInternal(), AIVehicle::_SellWagonInternal(), AIOrder::_SetOrderFlags(), AIOrder::AppendConditionalOrder(), AIOrder::AppendOrder(), AIAirport::BuildAirport(), AIBridge::BuildBridge(), AIMarine::BuildBuoy(), AIMarine::BuildCanal(), AICompany::BuildCompanyHQ(), AIMarine::BuildDock(), AIIndustryType::BuildIndustry(), AIMarine::BuildLock(), AIRail::BuildNewGRFRailStation(), AIRail::BuildRail(), AIRail::BuildRailDepot(), AIRail::BuildRailStation(), AIRail::BuildRailTrack(), AIRail::BuildRailWaypoint(), AIRoad::BuildRoadDepot(), AISign::BuildSign(), AIRail::BuildSignal(), AITunnel::BuildTunnel(), AIVehicle::BuildVehicle(), AIMarine::BuildWaterDepot(), AIVehicle::CloneVehicle(), AIRail::ConvertRailType(), AIOrder::CopyOrders(), AIGroup::DeleteGroup(), AITile::DemolishTile(), AIGroup::EnableAutoReplaceProtection(), AIOrder::InsertConditionalOrder(), AIOrder::InsertOrder(), AITile::LevelTiles(), AITile::LowerTile(), AIOrder::MoveOrder(), AIGroup::MoveVehicle(), AITown::PerformTownAction(), AITile::PlantTree(), AITile::PlantTreeRectangle(), AIIndustryType::ProspectIndustry(), AITile::RaiseTile(), AIVehicle::RefitVehicle(), AIAirport::RemoveAirport(), AIBridge::RemoveBridge(), AIMarine::RemoveBuoy(), AIMarine::RemoveCanal(), AIMarine::RemoveDock(), AIMarine::RemoveLock(), AIOrder::RemoveOrder(), AIRail::RemoveRail(), AIRail::RemoveRailStationTileRectangle(), AIRail::RemoveRailTrack(), AIRail::RemoveRailWaypointTileRectangle(), AIRoad::RemoveRoad(), AIRoad::RemoveRoadDepot(), AIRoad::RemoveRoadFull(), AIRoad::RemoveRoadStation(), AISign::RemoveSign(), AIRail::RemoveSignal(), AITunnel::RemoveTunnel(), AIMarine::RemoveWaterDepot(), AIVehicle::ReverseVehicle(), AIVehicle::SellVehicle(), AIVehicle::SendVehicleToDepot(), AIVehicle::SendVehicleToDepotForServicing(), AIGroup::SetAutoReplace(), AICompany::SetLoanAmount(), AICompany::SetMinimumLoanAmount(), AIVehicle::SetName(), AISign::SetName(), AIGroup::SetName(), AICompany::SetName(), AIBaseStation::SetName(), AIOrder::SetOrderCompareFunction(), AIOrder::SetOrderCompareValue(), AIOrder::SetOrderCondition(), AIOrder::SetOrderJumpTo(), AICompany::SetPresidentGender(), AICompany::SetPresidentName(), AIOrder::SetStopLocation(), AIOrder::ShareOrders(), AIOrder::SkipToOrder(), AIVehicle::StartStopVehicle(), AIGroup::StopAutoReplace(), and AIOrder::UnshareOrders().

#define EnforcePreconditionCustomError | ( | returnval,
|  | condition,
|  | error_code |  | ) |

Value:

    if (!(condition)) {                                                      \
        AIObject::SetLastError(error_code);                                    \
        return returnval;                                                      \
      }

Helper to write precondition enforcers for the AI API in an abbreviated manner.

Parameters:

  | returnval | The value to return on failure.
  | condition | The condition that must be obeyed.
  | error_code | The error code passed to AIObject::SetLastError.

Definition at line 35 of file ai_error.hpp.

Referenced by AISign::BuildSign(), AIVehicle::BuildVehicle(), AIVehicle::SetName(), AISign::SetName(), AIGroup::SetName(), AICompany::SetName(), and AIBaseStation::SetName().