src/build_vehicle_gui.cpp
changeset 5868 94430141c189
parent 5824 8398b44ad3bc
child 5871 a98c86408de4
equal deleted inserted replaced
5867:b7aa408ce6f3 5868:94430141c189
   185 static int CDECL TrainEnginePowerSorter(const void *a, const void *b)
   185 static int CDECL TrainEnginePowerSorter(const void *a, const void *b)
   186 {
   186 {
   187 	const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
   187 	const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
   188 	const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
   188 	const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
   189 
   189 
   190 	int va = rvi_a->power << (rvi_a->flags & RVI_MULTIHEAD ? 1 : 0);
   190 	int va = rvi_a->power << (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
   191 	int vb = rvi_b->power << (rvi_b->flags & RVI_MULTIHEAD ? 1 : 0);
   191 	int vb = rvi_b->power << (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
   192 	int r = va - vb;
   192 	int r = va - vb;
   193 
   193 
   194 	return _internal_sort_order ? -r : r;
   194 	return _internal_sort_order ? -r : r;
   195 }
   195 }
   196 
   196 
   197 static int CDECL TrainEngineRunningCostSorter(const void *a, const void *b)
   197 static int CDECL TrainEngineRunningCostSorter(const void *a, const void *b)
   198 {
   198 {
   199 	const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
   199 	const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
   200 	const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
   200 	const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
   201 
   201 
   202 	int va = rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class] * (rvi_a->flags & RVI_MULTIHEAD ? 2 : 1);
   202 	int va = rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class] * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
   203 	int vb = rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class] * (rvi_b->flags & RVI_MULTIHEAD ? 2 : 1);
   203 	int vb = rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class] * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
   204 	int r = va - vb;
   204 	int r = va - vb;
   205 
   205 
   206 	return _internal_sort_order ? -r : r;
   206 	return _internal_sort_order ? -r : r;
   207 }
   207 }
   208 
   208 
   226 
   226 
   227 static int CDECL TrainEnginesThenWagonsSorter(const void *a, const void *b)
   227 static int CDECL TrainEnginesThenWagonsSorter(const void *a, const void *b)
   228 {
   228 {
   229 	EngineID va = *(const EngineID*)a;
   229 	EngineID va = *(const EngineID*)a;
   230 	EngineID vb = *(const EngineID*)b;
   230 	EngineID vb = *(const EngineID*)b;
   231 	int val_a = ((RailVehInfo(va)->flags & RVI_WAGON) != 0) ? 1 : 0;
   231 	int val_a = (RailVehInfo(va)->railveh_type != RAILVEH_WAGON ? 1 : 0);
   232 	int val_b = ((RailVehInfo(vb)->flags & RVI_WAGON) != 0) ? 1 : 0;
   232 	int val_b = (RailVehInfo(vb)->railveh_type != RAILVEH_WAGON ? 1 : 0);
   233 	int r = val_a - val_b;
   233 	int r = val_a - val_b;
   234 
   234 
   235 	/* Use EngineID to sort instead since we want consistent sorting */
   235 	/* Use EngineID to sort instead since we want consistent sorting */
   236 	if (r == 0) return EngineNumberSorter(a, b);
   236 	if (r == 0) return EngineNumberSorter(a, b);
   237 
   237 
   386 }
   386 }
   387 
   387 
   388 /* Draw locomotive specific details */
   388 /* Draw locomotive specific details */
   389 static int DrawRailEnginePurchaseInfo(int x, int y, EngineID engine_number, const RailVehicleInfo *rvi)
   389 static int DrawRailEnginePurchaseInfo(int x, int y, EngineID engine_number, const RailVehicleInfo *rvi)
   390 {
   390 {
   391 	int multihead = (rvi->flags&RVI_MULTIHEAD?1:0);
   391 	int multihead = (rvi->railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
   392 
   392 
   393 	/* Purchase Cost - Engine weight */
   393 	/* Purchase Cost - Engine weight */
   394 	SetDParam(0, rvi->base_cost * (_price.build_railvehicle >> 3) >> 5);
   394 	SetDParam(0, rvi->base_cost * (_price.build_railvehicle >> 3) >> 5);
   395 	SetDParam(1, rvi->weight << multihead);
   395 	SetDParam(1, rvi->weight << multihead);
   396 	DrawString(x,y, STR_PURCHASE_INFO_COST_WEIGHT, 0);
   396 	DrawString(x,y, STR_PURCHASE_INFO_COST_WEIGHT, 0);
   527 		case VEH_Train: {
   527 		case VEH_Train: {
   528 			const RailVehicleInfo *rvi = RailVehInfo(engine_number);
   528 			const RailVehicleInfo *rvi = RailVehInfo(engine_number);
   529 
   529 
   530 			refitable = (EngInfo(engine_number)->refit_mask != 0) && (rvi->capacity > 0);
   530 			refitable = (EngInfo(engine_number)->refit_mask != 0) && (rvi->capacity > 0);
   531 
   531 
   532 			if (rvi->flags & RVI_WAGON) {
   532 			if (rvi->railveh_type == RAILVEH_WAGON) {
   533 				y = DrawRailWagonPurchaseInfo(x, y, engine_number, rvi);
   533 				y = DrawRailWagonPurchaseInfo(x, y, engine_number, rvi);
   534 			} else {
   534 			} else {
   535 				y = DrawRailEnginePurchaseInfo(x, y, engine_number, rvi);
   535 				y = DrawRailEnginePurchaseInfo(x, y, engine_number, rvi);
   536 			}
   536 			}
   537 
   537 
   538 			/* Cargo type + capacity, or N/A */
   538 			/* Cargo type + capacity, or N/A */
   539 			if (rvi->capacity == 0) {
   539 			if (rvi->capacity == 0) {
   540 				SetDParam(0, CT_INVALID);
   540 				SetDParam(0, CT_INVALID);
   541 				SetDParam(2, STR_EMPTY);
   541 				SetDParam(2, STR_EMPTY);
   542 			} else {
   542 			} else {
   543 				int multihead = (rvi->flags & RVI_MULTIHEAD ? 1 : 0);
   543 				int multihead = (rvi->railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
   544 
   544 
   545 				SetDParam(0, rvi->cargo_type);
   545 				SetDParam(0, rvi->cargo_type);
   546 				SetDParam(1, (rvi->capacity * (CountArticulatedParts(engine_number) + 1)) << multihead);
   546 				SetDParam(1, (rvi->capacity * (CountArticulatedParts(engine_number) + 1)) << multihead);
   547 				SetDParam(2, refitable ? STR_9842_REFITTABLE : STR_EMPTY);
   547 				SetDParam(2, refitable ? STR_9842_REFITTABLE : STR_EMPTY);
   548 			}
   548 			}
   564 			refitable = true;
   564 			refitable = true;
   565 			break;
   565 			break;
   566 	}
   566 	}
   567 
   567 
   568 	/* Draw details, that applies to all types except rail wagons */
   568 	/* Draw details, that applies to all types except rail wagons */
   569 	if (e->type != VEH_Train || !(RailVehInfo(engine_number)->flags & RVI_WAGON)) {
   569 	if (e->type != VEH_Train || RailVehInfo(engine_number)->railveh_type != RAILVEH_WAGON) {
   570 		/* Design date - Life length */
   570 		/* Design date - Life length */
   571 		SetDParam(0, ymd.year);
   571 		SetDParam(0, ymd.year);
   572 		SetDParam(1, e->lifelength);
   572 		SetDParam(1, e->lifelength);
   573 		DrawString(x, y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0);
   573 		DrawString(x, y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0);
   574 		y += 10;
   574 		y += 10;
   605 
   605 
   606 		if (bv->filter.railtype != RAILTYPE_END && !HasPowerOnRail(rvi->railtype, bv->filter.railtype)) continue;
   606 		if (bv->filter.railtype != RAILTYPE_END && !HasPowerOnRail(rvi->railtype, bv->filter.railtype)) continue;
   607 		if (!IsEngineBuildable(eid, VEH_Train, _local_player)) continue;
   607 		if (!IsEngineBuildable(eid, VEH_Train, _local_player)) continue;
   608 
   608 
   609 		EngList_Add(&bv->eng_list, eid);
   609 		EngList_Add(&bv->eng_list, eid);
   610 		if ((rvi->flags & RVI_WAGON) == 0) {
   610 		if (rvi->railveh_type != RAILVEH_WAGON) {
   611 			num_engines++;
   611 			num_engines++;
   612 		} else {
   612 		} else {
   613 			num_wagons++;
   613 			num_wagons++;
   614 		}
   614 		}
   615 
   615 
   824 		case BUILD_VEHICLE_WIDGET_BUILD: {
   824 		case BUILD_VEHICLE_WIDGET_BUILD: {
   825 			EngineID sel_eng = bv->sel_engine;
   825 			EngineID sel_eng = bv->sel_engine;
   826 			if (sel_eng != INVALID_ENGINE) {
   826 			if (sel_eng != INVALID_ENGINE) {
   827 				switch (bv->vehicle_type) {
   827 				switch (bv->vehicle_type) {
   828 					case VEH_Train:
   828 					case VEH_Train:
   829 						DoCommandP(w->window_number, sel_eng, 0, (RailVehInfo(sel_eng)->flags & RVI_WAGON) ? CcBuildWagon : CcBuildLoco,
   829 						DoCommandP(w->window_number, sel_eng, 0, (RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) ? CcBuildWagon : CcBuildLoco,
   830 								   CMD_BUILD_RAIL_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE));
   830 								   CMD_BUILD_RAIL_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE));
   831 						break;
   831 						break;
   832 					case VEH_Road:
   832 					case VEH_Road:
   833 						DoCommandP(w->window_number, sel_eng, 0, CcBuildRoadVeh, CMD_BUILD_ROAD_VEH | CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE));
   833 						DoCommandP(w->window_number, sel_eng, 0, CcBuildRoadVeh, CMD_BUILD_ROAD_VEH | CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE));
   834 						break;
   834 						break;