src/train_cmd.cpp
branchcpp_gui
changeset 6303 84c215fc8eb8
parent 6298 c30fe89622df
child 6307 f40e88cff863
equal deleted inserted replaced
6302:bd80897189ba 6303:84c215fc8eb8
  1332 
  1332 
  1333 				/* 2.1 If the first wagon is sold, update the first-> pointers to NULL */
  1333 				/* 2.1 If the first wagon is sold, update the first-> pointers to NULL */
  1334 				for (Vehicle *tmp = first; tmp != NULL; tmp = tmp->next) tmp->first = NULL;
  1334 				for (Vehicle *tmp = first; tmp != NULL; tmp = tmp->next) tmp->first = NULL;
  1335 
  1335 
  1336 				/* 2.2 If there are wagons present after the deleted front engine, check
  1336 				/* 2.2 If there are wagons present after the deleted front engine, check
  1337          * if the second wagon (which will be first) is an engine. If it is one,
  1337 				 * if the second wagon (which will be first) is an engine. If it is one,
  1338          * promote it as a new train, retaining the unitnumber, orders */
  1338 				 * promote it as a new train, retaining the unitnumber, orders */
  1339 				if (new_f != NULL) {
  1339 				if (new_f != NULL && IsTrainEngine(new_f)) {
  1340 					if (IsTrainEngine(new_f)) {
  1340 					switch_engine = true;
  1341 						switch_engine = true;
  1341 					/* Copy important data from the front engine */
  1342 						/* Copy important data from the front engine */
  1342 					new_f->unitnumber      = first->unitnumber;
  1343 						new_f->unitnumber = first->unitnumber;
  1343 					new_f->current_order   = first->current_order;
  1344 						new_f->current_order = first->current_order;
  1344 					new_f->cur_order_index = first->cur_order_index;
  1345 						new_f->cur_order_index = first->cur_order_index;
  1345 					new_f->orders          = first->orders;
  1346 						new_f->orders = first->orders;
  1346 					new_f->num_orders      = first->num_orders;
  1347 						if (first->prev_shared != NULL) {
  1347 
  1348 							first->prev_shared->next_shared = new_f;
  1348 					if (first->prev_shared != NULL) {
  1349 							new_f->prev_shared = first->prev_shared;
  1349 						first->prev_shared->next_shared = new_f;
  1350 						}
  1350 						new_f->prev_shared = first->prev_shared;
  1351 
       
  1352 						if (first->next_shared != NULL) {
       
  1353 							first->next_shared->prev_shared = new_f;
       
  1354 							new_f->next_shared = first->next_shared;
       
  1355 						}
       
  1356 
       
  1357 						new_f->num_orders = first->num_orders;
       
  1358 						first->orders = NULL; // XXX - to not to delete the orders */
       
  1359 						if (IsLocalPlayer()) ShowTrainViewWindow(new_f);
       
  1360 					}
  1351 					}
       
  1352 
       
  1353 					if (first->next_shared != NULL) {
       
  1354 						first->next_shared->prev_shared = new_f;
       
  1355 						new_f->next_shared = first->next_shared;
       
  1356 					}
       
  1357 
       
  1358 					/*
       
  1359 					 * Remove all order information from the front train, to
       
  1360 					 * prevent the order and the shared order list to be
       
  1361 					 * destroyed by Destroy/DeleteVehicle.
       
  1362 					 */
       
  1363 					first->orders      = NULL;
       
  1364 					first->prev_shared = NULL;
       
  1365 					first->next_shared = NULL;
       
  1366 
       
  1367 					if (IsLocalPlayer()) ShowTrainViewWindow(new_f);
  1361 				}
  1368 				}
  1362 			}
  1369 			}
  1363 
  1370 
  1364 			/* 3. Delete the requested wagon */
  1371 			/* 3. Delete the requested wagon */
  1365 			cost -= v->value;
  1372 			cost -= v->value;
  1742 
  1749 
  1743 	if (v->type != VEH_TRAIN || !CheckOwnership(v->owner)) return CMD_ERROR;
  1750 	if (v->type != VEH_TRAIN || !CheckOwnership(v->owner)) return CMD_ERROR;
  1744 	if (CheckTrainStoppedInDepot(v) < 0) return_cmd_error(STR_TRAIN_MUST_BE_STOPPED);
  1751 	if (CheckTrainStoppedInDepot(v) < 0) return_cmd_error(STR_TRAIN_MUST_BE_STOPPED);
  1745 
  1752 
  1746 	/* Check cargo */
  1753 	/* Check cargo */
  1747 	if (new_cid > NUM_CARGO) return CMD_ERROR;
  1754 	if (new_cid >= NUM_CARGO) return CMD_ERROR;
  1748 
  1755 
  1749 	SET_EXPENSES_TYPE(EXPENSES_TRAIN_RUN);
  1756 	SET_EXPENSES_TYPE(EXPENSES_TRAIN_RUN);
  1750 
  1757 
  1751 	int32 cost = 0;
  1758 	int32 cost = 0;
  1752 	uint num = 0;
  1759 	uint num = 0;
  2156 		/* We do not check for dest_coords if we have a station_index,
  2163 		/* We do not check for dest_coords if we have a station_index,
  2157 		 * because in that case the dest_coords are just an
  2164 		 * because in that case the dest_coords are just an
  2158 		 * approximation of where the station is */
  2165 		 * approximation of where the station is */
  2159 		// found station
  2166 		// found station
  2160 		ttfd->best_track = track;
  2167 		ttfd->best_track = track;
       
  2168 		ttfd->best_bird_dist = 0;
  2161 		return true;
  2169 		return true;
  2162 	} else {
  2170 	} else {
  2163 		// didn't find station, keep track of the best path so far.
  2171 		// didn't find station, keep track of the best path so far.
  2164 		uint dist = DistanceManhattan(tile, ttfd->dest_coords);
  2172 		uint dist = DistanceManhattan(tile, ttfd->dest_coords);
  2165 		if (dist < ttfd->best_bird_dist) {
  2173 		if (dist < ttfd->best_bird_dist) {
  2805 
  2813 
  2806 static uint CountPassengersInTrain(const Vehicle* v)
  2814 static uint CountPassengersInTrain(const Vehicle* v)
  2807 {
  2815 {
  2808 	uint num = 0;
  2816 	uint num = 0;
  2809 	BEGIN_ENUM_WAGONS(v)
  2817 	BEGIN_ENUM_WAGONS(v)
  2810 		if (v->cargo_type == CT_PASSENGERS) num += v->cargo_count;
  2818 		if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) num += v->cargo_count;
  2811 	END_ENUM_WAGONS(v)
  2819 	END_ENUM_WAGONS(v)
  2812 	return num;
  2820 	return num;
  2813 }
  2821 }
  2814 
  2822 
  2815 /*
  2823 /*
  3204 
  3212 
  3205 		InvalidateWindow(WC_VEHICLE_VIEW, v->index);
  3213 		InvalidateWindow(WC_VEHICLE_VIEW, v->index);
  3206 		InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
  3214 		InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
  3207 
  3215 
  3208 		if (!PlayVehicleSound(v, VSE_BREAKDOWN)) {
  3216 		if (!PlayVehicleSound(v, VSE_BREAKDOWN)) {
  3209 			SndPlayVehicleFx((_opt.landscape != LT_CANDY) ?
  3217 			SndPlayVehicleFx((_opt.landscape != LT_TOYLAND) ?
  3210 				SND_10_TRAIN_BREAKDOWN : SND_3A_COMEDY_BREAKDOWN_2, v);
  3218 				SND_10_TRAIN_BREAKDOWN : SND_3A_COMEDY_BREAKDOWN_2, v);
  3211 		}
  3219 		}
  3212 
  3220 
  3213 		if (!(v->vehstatus & VS_HIDDEN)) {
  3221 		if (!(v->vehstatus & VS_HIDDEN)) {
  3214 			Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE);
  3222 			Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE);