comparison src/economy.cpp @ 18251:137b272acca5 draft

(svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
author michi_cc <michi_cc@openttd.org>
date Fri, 04 Nov 2011 00:38:51 +0000
parents 3141f1ed78eb
children c7bd632d9cc2
comparison
equal deleted inserted replaced
18250:f6c3afbfcc60 18251:137b272acca5
1273 } 1273 }
1274 1274
1275 /* Do not pick up goods when we have no-load set or loading is stopped. */ 1275 /* Do not pick up goods when we have no-load set or loading is stopped. */
1276 if (front->current_order.GetLoadType() & OLFB_NO_LOAD || HasBit(front->vehicle_flags, VF_STOP_LOADING)) continue; 1276 if (front->current_order.GetLoadType() & OLFB_NO_LOAD || HasBit(front->vehicle_flags, VF_STOP_LOADING)) continue;
1277 1277
1278 /* This order has a refit, the vehicle is a normal vehicle and completely empty, do it now. */
1279 if (front->current_order.IsRefit() && !v->IsArticulatedPart() && v->cargo.Count() == 0 &&
1280 (v->type != VEH_AIRCRAFT || (Aircraft::From(v)->IsNormalAircraft() && v->Next()->cargo.Count() == 0))) {
1281 CargoID new_cid = front->current_order.GetRefitCargo();
1282 byte new_subtype = front->current_order.GetRefitSubtype();
1283
1284 Backup<CompanyByte> cur_company(_current_company, front->owner, FILE_LINE);
1285
1286 /* Check if all articulated parts are empty and collect refit mask. */
1287 uint32 refit_mask = e->info.refit_mask;
1288 Vehicle *w = v;
1289 while (w->HasArticulatedPart()) {
1290 w = w->GetNextArticulatedPart();
1291 if (w->cargo.Count() > 0) new_cid = CT_NO_REFIT;
1292 refit_mask |= EngInfo(w->engine_type)->refit_mask;
1293 }
1294
1295 if (new_cid == CT_AUTO_REFIT) {
1296 /* Get refittable cargo type with the most waiting cargo. */
1297 int amount = 0;
1298 CargoID cid;
1299 FOR_EACH_SET_CARGO_ID(cid, refit_mask) {
1300 if (cargo_left[cid] > amount) {
1301 /* Try to find out if auto-refitting would succeed. In case the refit is allowed,
1302 * the returned refit capacity will be greater than zero. */
1303 DoCommand(v->tile, v->index, cid | 1U << 6 | new_subtype << 8 | 1U << 16, DC_QUERY_COST, GetCmdRefitVeh(v)); // Auto-refit and only this vehicle including artic parts.
1304 if (_returned_refit_capacity > 0) {
1305 amount = cargo_left[cid];
1306 new_cid = cid;
1307 }
1308 }
1309 }
1310 }
1311
1312 /* Refit if given a valid cargo. */
1313 if (new_cid < NUM_CARGO) {
1314 DoCommand(v->tile, v->index, new_cid | 1U << 6 | new_subtype << 8 | 1U << 16, DC_EXEC, GetCmdRefitVeh(v)); // Auto-refit and only this vehicle including artic parts.
1315 ge = &st->goods[v->cargo_type];
1316 }
1317
1318 cur_company.Restore();
1319 }
1320
1278 /* update stats */ 1321 /* update stats */
1279 int t; 1322 int t;
1280 switch (front->type) { 1323 switch (front->type) {
1281 case VEH_TRAIN: /* FALL THROUGH */ 1324 case VEH_TRAIN: /* FALL THROUGH */
1282 case VEH_SHIP: 1325 case VEH_SHIP: