47 * 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. |
48 * Also takes a possible error message when it is set. |
48 * Also takes a possible error message when it is set. |
49 * @param ret the command to add the cost of. |
49 * @param ret the command to add the cost of. |
50 * @return this class. |
50 * @return this class. |
51 */ |
51 */ |
52 CommandCost AddCost(CommandCost ret); |
52 CommandCost AddCost(CommandCost ret) |
|
53 { |
|
54 this->AddCost(ret.cost); |
|
55 if (this->success && !ret.success) { |
|
56 this->message = ret.message; |
|
57 this->success = false; |
|
58 } |
|
59 return *this; |
|
60 } |
53 |
61 |
54 /** |
62 /** |
55 * Adds the given cost to the cost of the command. |
63 * Adds the given cost to the cost of the command. |
56 * @param cost the cost to add |
64 * @param cost the cost to add |
57 * @return this class. |
65 * @return this class. |
58 */ |
66 */ |
59 CommandCost AddCost(Money cost); |
67 CommandCost AddCost(Money cost) |
|
68 { |
|
69 this->cost += cost; |
|
70 return *this; |
|
71 } |
60 |
72 |
61 /** |
73 /** |
62 * Multiplies the cost of the command by the given factor. |
74 * Multiplies the cost of the command by the given factor. |
63 * @param cost factor to multiply the costs with |
75 * @param cost factor to multiply the costs with |
64 * @return this class |
76 * @return this class |
65 */ |
77 */ |
66 CommandCost MultiplyCost(int factor); |
78 CommandCost MultiplyCost(int factor) |
|
79 { |
|
80 this->cost *= factor; |
|
81 return *this; |
|
82 } |
67 |
83 |
68 /** |
84 /** |
69 * The costs as made up to this moment |
85 * The costs as made up to this moment |
70 * @return the costs |
86 * @return the costs |
71 */ |
87 */ |
72 Money GetCost() const; |
88 Money GetCost() const |
|
89 { |
|
90 return this->cost; |
|
91 } |
73 |
92 |
74 /** |
93 /** |
75 * The expense type of the cost |
94 * The expense type of the cost |
76 * @return the expense type |
95 * @return the expense type |
77 */ |
96 */ |
78 ExpensesType GetExpensesType() const; |
97 ExpensesType GetExpensesType() const |
|
98 { |
|
99 return this->expense_type; |
|
100 } |
79 |
101 |
80 /** |
102 /** |
81 * Sets the global error message *if* this class has one. |
103 * Sets the global error message *if* this class has one. |
82 */ |
104 */ |
83 void SetGlobalErrorMessage() const; |
105 void SetGlobalErrorMessage() const |
|
106 { |
|
107 extern StringID _error_message; |
|
108 if (this->message != INVALID_STRING_ID) _error_message = this->message; |
|
109 } |
84 |
110 |
85 /** |
111 /** |
86 * Did this command succeed? |
112 * Did this command succeed? |
87 * @return true if and only if it succeeded |
113 * @return true if and only if it succeeded |
88 */ |
114 */ |
89 bool Succeeded() const; |
115 bool Succeeded() const |
|
116 { |
|
117 return this->success; |
|
118 } |
90 |
119 |
91 /** |
120 /** |
92 * Did this command fail? |
121 * Did this command fail? |
93 * @return true if and only if it failed |
122 * @return true if and only if it failed |
94 */ |
123 */ |
95 bool Failed() const; |
124 bool Failed() const |
|
125 { |
|
126 return !this->success; |
|
127 } |
96 }; |
128 }; |
97 |
129 |
98 /** |
130 /** |
99 * List of commands. |
131 * List of commands. |
100 * |
132 * |