119 |
119 |
120 /** Increase the loan of your company. |
120 /** Increase the loan of your company. |
121 * @param tile unused |
121 * @param tile unused |
122 * @param flags operation to perform |
122 * @param flags operation to perform |
123 * @param p1 unused |
123 * @param p1 unused |
124 * @param p2 when set, loans the maximum amount in one go (press CTRL) |
124 * @param p2 when 0: loans LOAN_INTERVAL |
|
125 * when 1: loans the maximum loan permitting money (press CTRL), |
125 */ |
126 */ |
126 int32 CmdIncreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
127 int32 CmdIncreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
127 { |
128 { |
128 Player *p; |
129 Player *p = GetPlayer(_current_player); |
129 |
|
130 p = GetPlayer(_current_player); |
|
131 |
130 |
132 if (p->current_loan >= _economy.max_loan) { |
131 if (p->current_loan >= _economy.max_loan) { |
133 SetDParam(0, _economy.max_loan); |
132 SetDParam(0, _economy.max_loan); |
134 return_cmd_error(STR_702B_MAXIMUM_PERMITTED_LOAN); |
133 return_cmd_error(STR_702B_MAXIMUM_PERMITTED_LOAN); |
135 } |
134 } |
136 |
135 |
137 if (flags & DC_EXEC) { |
136 int32 loan; |
138 /* Loan the maximum amount or not? */ |
137 switch (p2) { |
139 int32 loan = (p2) ? _economy.max_loan - p->current_loan : (IsHumanPlayer(_current_player) || _patches.ainew_active) ? 10000 : 50000; |
138 default: return CMD_ERROR; // Invalid method |
140 |
139 case 0: // Take some extra loan |
|
140 loan = (IsHumanPlayer(_current_player) || _patches.ainew_active) ? LOAN_INTERVAL : LOAN_INTERVAL_OLD_AI; |
|
141 break; |
|
142 case 1: // Take a loan as big as possible |
|
143 loan = _economy.max_loan - p->current_loan; |
|
144 break; |
|
145 } |
|
146 |
|
147 if (flags & DC_EXEC) { |
141 p->money64 += loan; |
148 p->money64 += loan; |
142 p->current_loan += loan; |
149 p->current_loan += loan; |
143 UpdatePlayerMoney32(p); |
150 UpdatePlayerMoney32(p); |
144 InvalidatePlayerWindows(p); |
151 InvalidatePlayerWindows(p); |
145 } |
152 } |
149 |
156 |
150 /** Decrease the loan of your company. |
157 /** Decrease the loan of your company. |
151 * @param tile unused |
158 * @param tile unused |
152 * @param flags operation to perform |
159 * @param flags operation to perform |
153 * @param p1 unused |
160 * @param p1 unused |
154 * @param p2 when set, pays back the maximum loan permitting money (press CTRL) |
161 * @param p2 when 0: pays back LOAN_INTERVAL |
|
162 * when 1: pays back the maximum loan permitting money (press CTRL), |
155 */ |
163 */ |
156 int32 CmdDecreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
164 int32 CmdDecreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
157 { |
165 { |
158 Player *p; |
166 Player *p = GetPlayer(_current_player); |
|
167 |
|
168 if (p->current_loan == 0) return_cmd_error(STR_702D_LOAN_ALREADY_REPAYED); |
|
169 |
159 int32 loan; |
170 int32 loan; |
160 |
171 switch (p2) { |
161 p = GetPlayer(_current_player); |
172 default: return CMD_ERROR; // Invalid method |
162 |
173 case 0: // Pay back one step |
163 if (p->current_loan == 0) return_cmd_error(STR_702D_LOAN_ALREADY_REPAYED); |
174 loan = min(p->current_loan, (IsHumanPlayer(_current_player) || _patches.ainew_active) ? LOAN_INTERVAL : LOAN_INTERVAL_OLD_AI); |
164 |
175 break; |
165 loan = p->current_loan; |
176 case 1: // Pay back as much as possible |
166 |
177 loan = max(min(p->current_loan, p->player_money), (int32)LOAN_INTERVAL); |
167 /* p2 is true while CTRL is pressed (repay all possible loan, or max money you have) |
178 loan -= loan % LOAN_INTERVAL; |
168 * Repay any loan in chunks of 10.000 pounds */ |
179 break; |
169 if (p2) { |
|
170 loan = min(loan, p->player_money); |
|
171 loan = max(loan, 10000); |
|
172 loan -= loan % 10000; |
|
173 } else { |
|
174 loan = min(loan, (IsHumanPlayer(_current_player) || _patches.ainew_active) ? 10000 : 50000); |
|
175 } |
180 } |
176 |
181 |
177 if (p->player_money < loan) { |
182 if (p->player_money < loan) { |
178 SetDParam(0, loan); |
183 SetDParam(0, loan); |
179 return_cmd_error(STR_702E_REQUIRED); |
184 return_cmd_error(STR_702E_REQUIRED); |