src/command_type.h
changeset 8230 64f28fe2d5c8
parent 8123 ce31d2843a95
child 8486 6118595a0091
equal deleted inserted replaced
8229:00e7467ceeee 8230:64f28fe2d5c8
    12 /**
    12 /**
    13  * Common return value for all commands. Wraps the cost and
    13  * Common return value for all commands. Wraps the cost and
    14  * a possible error message/state together.
    14  * a possible error message/state together.
    15  */
    15  */
    16 class CommandCost {
    16 class CommandCost {
       
    17 	ExpensesType expense_type; ///< the type of expence as shown on the finances view
    17 	Money cost;       ///< The cost of this action
    18 	Money cost;       ///< The cost of this action
    18 	StringID message; ///< Warning message for when success is unset
    19 	StringID message; ///< Warning message for when success is unset
    19 	bool success;     ///< Whether the comment went fine up to this moment
    20 	bool success;     ///< Whether the comment went fine up to this moment
    20 
    21 
    21 public:
    22 public:
    22 	/**
    23 	/**
    23 	 * Creates a command cost return with no cost and no error
    24 	 * Creates a command cost return with no cost and no error
    24 	 */
    25 	 */
    25 	CommandCost() : cost(0), message(INVALID_STRING_ID), success(true) {}
    26 	CommandCost() : expense_type(INVALID_EXPENSES), cost(0), message(INVALID_STRING_ID), success(true) {}
    26 
    27 
    27 	/**
    28 	/**
    28 	 * Creates a command return value the is failed with the given message
    29 	 * Creates a command return value the is failed with the given message
    29 	 */
    30 	 */
    30 	CommandCost(StringID msg) : cost(0), message(msg), success(false) {}
    31 	CommandCost(StringID msg) : expense_type(INVALID_EXPENSES), cost(0), message(msg), success(false) {}
    31 
    32 
    32 	/**
    33 	/**
    33 	 * Creates a command return value with the given start cost
    34 	 * Creates a command cost with given expense type and start cost of 0
       
    35 	 * @param ex_t the expense type
       
    36 	 */
       
    37 	CommandCost(ExpensesType ex_t) : expense_type(ex_t), cost(0), message(INVALID_STRING_ID), success(true) {}
       
    38 
       
    39 	/**
       
    40 	 * Creates a command return value with the given start cost and expense type
       
    41 	 * @param ex_t the expense type
    34 	 * @param cst the initial cost of this command
    42 	 * @param cst the initial cost of this command
    35 	 */
    43 	 */
    36 	CommandCost(Money cst) : cost(cst), message(INVALID_STRING_ID), success(true) {}
    44 	CommandCost(ExpensesType ex_t, Money cst) : expense_type(ex_t), cost(cst), message(INVALID_STRING_ID), success(true) {}
    37 
    45 
    38 	/**
    46 	/**
    39 	 * Adds the cost of the given command return value to this cost.
    47 	 * Adds the cost of the given command return value to this cost.
    40 	 * Also takes a possible error message when it is set.
    48 	 * Also takes a possible error message when it is set.
    41 	 * @param ret the command to add the cost of.
    49 	 * @param ret the command to add the cost of.
    60 	/**
    68 	/**
    61 	 * The costs as made up to this moment
    69 	 * The costs as made up to this moment
    62 	 * @return the costs
    70 	 * @return the costs
    63 	 */
    71 	 */
    64 	Money GetCost() const;
    72 	Money GetCost() const;
       
    73 
       
    74 	/**
       
    75 	 * The expense type of the cost
       
    76 	 * @return the expense type
       
    77 	 */
       
    78 	ExpensesType GetExpensesType() const;
    65 
    79 
    66 	/**
    80 	/**
    67 	 * Sets the global error message *if* this class has one.
    81 	 * Sets the global error message *if* this class has one.
    68 	 */
    82 	 */
    69 	void SetGlobalErrorMessage() const;
    83 	void SetGlobalErrorMessage() const;