src/build_vehicle_gui.cpp
branchgamebalance
changeset 9912 1ac8aac92385
parent 9911 0b8b245a2391
equal deleted inserted replaced
9911:0b8b245a2391 9912:1ac8aac92385
    13 #include "table/sprites.h"
    13 #include "table/sprites.h"
    14 #include "table/strings.h"
    14 #include "table/strings.h"
    15 #include "window.h"
    15 #include "window.h"
    16 #include "gui.h"
    16 #include "gui.h"
    17 #include "vehicle.h"
    17 #include "vehicle.h"
       
    18 #include "articulated_vehicles.h"
    18 #include "gfx.h"
    19 #include "gfx.h"
    19 #include "station.h"
    20 #include "station.h"
    20 #include "command.h"
    21 #include "command.h"
    21 #include "engine.h"
    22 #include "engine.h"
    22 #include "player.h"
    23 #include "player.h"
    26 #include "newgrf_engine.h"
    27 #include "newgrf_engine.h"
    27 #include "date.h"
    28 #include "date.h"
    28 #include "strings.h"
    29 #include "strings.h"
    29 #include "cargotype.h"
    30 #include "cargotype.h"
    30 #include "group.h"
    31 #include "group.h"
       
    32 #include "road_map.h"
    31 
    33 
    32 
    34 
    33 enum BuildVehicleWidgets {
    35 enum BuildVehicleWidgets {
    34 	BUILD_VEHICLE_WIDGET_CLOSEBOX = 0,
    36 	BUILD_VEHICLE_WIDGET_CLOSEBOX = 0,
    35 	BUILD_VEHICLE_WIDGET_CAPTION,
    37 	BUILD_VEHICLE_WIDGET_CAPTION,
   266 	int r = ListPositionOfEngine(va) - ListPositionOfEngine(vb);
   268 	int r = ListPositionOfEngine(va) - ListPositionOfEngine(vb);
   267 
   269 
   268 	return _internal_sort_order ? -r : r;
   270 	return _internal_sort_order ? -r : r;
   269 }
   271 }
   270 
   272 
       
   273 static int CDECL TrainEngineCapacitySorter(const void *a, const void *b)
       
   274 {
       
   275 	int va = RailVehInfo(*(const EngineID*)a)->capacity;
       
   276 	int vb = RailVehInfo(*(const EngineID*)b)->capacity;
       
   277 	int r = va - vb;
       
   278 
       
   279 	if (r == 0) {
       
   280 		/* Use EngineID to sort instead since we want consistent sorting */
       
   281 		return EngineNumberSorter(a, b);
       
   282 	}
       
   283 	return _internal_sort_order ? -r : r;
       
   284 }
       
   285 
   271 static int CDECL TrainEnginesThenWagonsSorter(const void *a, const void *b)
   286 static int CDECL TrainEnginesThenWagonsSorter(const void *a, const void *b)
   272 {
   287 {
   273 	EngineID va = *(const EngineID*)a;
   288 	EngineID va = *(const EngineID*)a;
   274 	EngineID vb = *(const EngineID*)b;
   289 	EngineID vb = *(const EngineID*)b;
   275 	int val_a = (RailVehInfo(va)->railveh_type == RAILVEH_WAGON ? 1 : 0);
   290 	int val_a = (RailVehInfo(va)->railveh_type == RAILVEH_WAGON ? 1 : 0);
   280 	if (r == 0) return EngineNumberSorter(a, b);
   295 	if (r == 0) return EngineNumberSorter(a, b);
   281 
   296 
   282 	return _internal_sort_order ? -r : r;
   297 	return _internal_sort_order ? -r : r;
   283 }
   298 }
   284 
   299 
       
   300 static int CDECL RoadVehEngineCapacitySorter(const void *a, const void *b)
       
   301 {
       
   302 	int va = RoadVehInfo(*(const EngineID*)a)->capacity;
       
   303 	int vb = RoadVehInfo(*(const EngineID*)b)->capacity;
       
   304 	int r = va - vb;
       
   305 
       
   306 	if (r == 0) {
       
   307 		/* Use EngineID to sort instead since we want consistent sorting */
       
   308 		return EngineNumberSorter(a, b);
       
   309 	}
       
   310 	return _internal_sort_order ? -r : r;
       
   311 }
       
   312 
       
   313 static int CDECL ShipEngineCapacitySorter(const void *a, const void *b)
       
   314 {
       
   315 	int va = ShipVehInfo(*(const EngineID*)a)->capacity;
       
   316 	int vb = ShipVehInfo(*(const EngineID*)b)->capacity;
       
   317 	int r = va - vb;
       
   318 
       
   319 	if (r == 0) {
       
   320 		/* Use EngineID to sort instead since we want consistent sorting */
       
   321 		return EngineNumberSorter(a, b);
       
   322 	}
       
   323 	return _internal_sort_order ? -r : r;
       
   324 }
       
   325 
   285 /* Aircraft sorting functions */
   326 /* Aircraft sorting functions */
   286 
   327 
   287 static int CDECL AircraftEngineCostSorter(const void *a, const void *b)
   328 static int CDECL AircraftEngineCostSorter(const void *a, const void *b)
   288 {
   329 {
   289 	const int va = AircraftVehInfo(*(const EngineID*)a)->base_cost;
   330 	const int va = AircraftVehInfo(*(const EngineID*)a)->base_cost;
   319 	return _internal_sort_order ? -r : r;
   360 	return _internal_sort_order ? -r : r;
   320 }
   361 }
   321 
   362 
   322 static int CDECL AircraftEngineCargoSorter(const void *a, const void *b)
   363 static int CDECL AircraftEngineCargoSorter(const void *a, const void *b)
   323 {
   364 {
   324 	const int va = AircraftVehInfo(*(const EngineID*)a)->passenger_capacity;
   365 	int va = AircraftVehInfo(*(const EngineID*)a)->passenger_capacity;
   325 	const int vb = AircraftVehInfo(*(const EngineID*)b)->passenger_capacity;
   366 	int vb = AircraftVehInfo(*(const EngineID*)b)->passenger_capacity;
   326 	const int r = va - vb;
   367 	int r = va - vb;
   327 
   368 
   328 	if (r == 0) {
   369 	if (r == 0) {
   329 		/* Use EngineID to sort instead since we want consistent sorting */
   370 		/* The planes has the same passenger capacity. Check mail capacity instead */
   330 		return EngineNumberSorter(a, b);
   371 		va = AircraftVehInfo(*(const EngineID*)a)->mail_capacity;
   331 	}
   372 		vb = AircraftVehInfo(*(const EngineID*)b)->mail_capacity;
   332 	return _internal_sort_order ? -r : r;
   373 		r = va - vb;
   333 }
   374 
   334 
   375 		if (r == 0) {
   335 static EngList_SortTypeFunction * const _sorter[][9] = {{
   376 			/* Use EngineID to sort instead since we want consistent sorting */
       
   377 			return EngineNumberSorter(a, b);
       
   378 		}
       
   379 	}
       
   380 	return _internal_sort_order ? -r : r;
       
   381 }
       
   382 
       
   383 static EngList_SortTypeFunction * const _sorter[][10] = {{
   336 	/* Trains */
   384 	/* Trains */
   337 	&TrainEngineNumberSorter,
   385 	&TrainEngineNumberSorter,
   338 	&TrainEngineCostSorter,
   386 	&TrainEngineCostSorter,
   339 	&TrainEngineSpeedSorter,
   387 	&TrainEngineSpeedSorter,
   340 	&TrainEnginePowerSorter,
   388 	&TrainEnginePowerSorter,
   341 	&EngineIntroDateSorter,
   389 	&EngineIntroDateSorter,
   342 	&EngineNameSorter,
   390 	&EngineNameSorter,
   343 	&TrainEngineRunningCostSorter,
   391 	&TrainEngineRunningCostSorter,
   344 	&TrainEnginePowerVsRunningCostSorter,
   392 	&TrainEnginePowerVsRunningCostSorter,
   345 	&EngineReliabilitySorter,
   393 	&EngineReliabilitySorter,
       
   394 	&TrainEngineCapacitySorter,
   346 }, {
   395 }, {
   347 	/* Road vehicles */
   396 	/* Road vehicles */
   348 	&EngineNumberSorter,
   397 	&EngineNumberSorter,
   349 	&EngineIntroDateSorter,
   398 	&EngineIntroDateSorter,
   350 	&EngineNameSorter,
   399 	&EngineNameSorter,
   351 	&EngineReliabilitySorter,
   400 	&EngineReliabilitySorter,
       
   401 	&RoadVehEngineCapacitySorter,
   352 }, {
   402 }, {
   353 	/* Ships */
   403 	/* Ships */
   354 	&EngineNumberSorter,
   404 	&EngineNumberSorter,
   355 	&EngineIntroDateSorter,
   405 	&EngineIntroDateSorter,
   356 	&EngineNameSorter,
   406 	&EngineNameSorter,
   357 	&EngineReliabilitySorter,
   407 	&EngineReliabilitySorter,
       
   408 	&ShipEngineCapacitySorter,
   358 }, {
   409 }, {
   359 	/* Aircraft */
   410 	/* Aircraft */
   360 	&EngineNumberSorter,
   411 	&EngineNumberSorter,
   361 	&AircraftEngineCostSorter,
   412 	&AircraftEngineCostSorter,
   362 	&AircraftEngineSpeedSorter,
   413 	&AircraftEngineSpeedSorter,
   365 	&AircraftEngineRunningCostSorter,
   416 	&AircraftEngineRunningCostSorter,
   366 	&EngineReliabilitySorter,
   417 	&EngineReliabilitySorter,
   367 	&AircraftEngineCargoSorter,
   418 	&AircraftEngineCargoSorter,
   368 }};
   419 }};
   369 
   420 
   370 static const StringID _sort_listing[][10] = {{
   421 static const StringID _sort_listing[][11] = {{
   371 	/* Trains */
   422 	/* Trains */
   372 	STR_ENGINE_SORT_ENGINE_ID,
   423 	STR_ENGINE_SORT_ENGINE_ID,
   373 	STR_ENGINE_SORT_COST,
   424 	STR_ENGINE_SORT_COST,
   374 	STR_SORT_BY_MAX_SPEED,
   425 	STR_SORT_BY_MAX_SPEED,
   375 	STR_ENGINE_SORT_POWER,
   426 	STR_ENGINE_SORT_POWER,
   376 	STR_ENGINE_SORT_INTRO_DATE,
   427 	STR_ENGINE_SORT_INTRO_DATE,
   377 	STR_SORT_BY_DROPDOWN_NAME,
   428 	STR_SORT_BY_DROPDOWN_NAME,
   378 	STR_ENGINE_SORT_RUNNING_COST,
   429 	STR_ENGINE_SORT_RUNNING_COST,
   379 	STR_ENGINE_SORT_POWER_VS_RUNNING_COST,
   430 	STR_ENGINE_SORT_POWER_VS_RUNNING_COST,
   380 	STR_SORT_BY_RELIABILITY,
   431 	STR_SORT_BY_RELIABILITY,
       
   432 	STR_ENGINE_SORT_CARGO_CAPACITY,
   381 	INVALID_STRING_ID
   433 	INVALID_STRING_ID
   382 }, {
   434 }, {
   383 	/* Road vehicles */
   435 	/* Road vehicles */
   384 	STR_ENGINE_SORT_ENGINE_ID,
   436 	STR_ENGINE_SORT_ENGINE_ID,
   385 	STR_ENGINE_SORT_INTRO_DATE,
   437 	STR_ENGINE_SORT_INTRO_DATE,
   386 	STR_SORT_BY_DROPDOWN_NAME,
   438 	STR_SORT_BY_DROPDOWN_NAME,
   387 	STR_SORT_BY_RELIABILITY,
   439 	STR_SORT_BY_RELIABILITY,
       
   440 	STR_ENGINE_SORT_CARGO_CAPACITY,
   388 	INVALID_STRING_ID
   441 	INVALID_STRING_ID
   389 }, {
   442 }, {
   390 	/* Ships */
   443 	/* Ships */
   391 	STR_ENGINE_SORT_ENGINE_ID,
   444 	STR_ENGINE_SORT_ENGINE_ID,
   392 	STR_ENGINE_SORT_INTRO_DATE,
   445 	STR_ENGINE_SORT_INTRO_DATE,
   393 	STR_SORT_BY_DROPDOWN_NAME,
   446 	STR_SORT_BY_DROPDOWN_NAME,
   394 	STR_SORT_BY_RELIABILITY,
   447 	STR_SORT_BY_RELIABILITY,
       
   448 	STR_ENGINE_SORT_CARGO_CAPACITY,
   395 	INVALID_STRING_ID
   449 	INVALID_STRING_ID
   396 }, {
   450 }, {
   397 	/* Aircraft */
   451 	/* Aircraft */
   398 	STR_ENGINE_SORT_ENGINE_ID,
   452 	STR_ENGINE_SORT_ENGINE_ID,
   399 	STR_ENGINE_SORT_COST,
   453 	STR_ENGINE_SORT_COST,
   704 
   758 
   705 	sel_id = INVALID_ENGINE;
   759 	sel_id = INVALID_ENGINE;
   706 
   760 
   707 	for (eid = ROAD_ENGINES_INDEX; eid < ROAD_ENGINES_INDEX + NUM_ROAD_ENGINES; eid++) {
   761 	for (eid = ROAD_ENGINES_INDEX; eid < ROAD_ENGINES_INDEX + NUM_ROAD_ENGINES; eid++) {
   708 		if (!IsEngineBuildable(eid, VEH_ROAD, _local_player)) continue;
   762 		if (!IsEngineBuildable(eid, VEH_ROAD, _local_player)) continue;
       
   763 		if (!HASBIT(bv->filter.roadtypes, HASBIT(EngInfo(eid)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD)) continue;
   709 		EngList_Add(&bv->eng_list, eid);
   764 		EngList_Add(&bv->eng_list, eid);
   710 
   765 
   711 		if (eid == bv->sel_engine) sel_id = eid;
   766 		if (eid == bv->sel_engine) sel_id = eid;
   712 	}
   767 	}
   713 	bv->sel_engine = sel_id;
   768 	bv->sel_engine = sel_id;
  1057 		case VEH_TRAIN:
  1112 		case VEH_TRAIN:
  1058 			WP(w, buildvehicle_d).filter.railtype = (tile == 0) ? RAILTYPE_END : GetRailType(tile);
  1113 			WP(w, buildvehicle_d).filter.railtype = (tile == 0) ? RAILTYPE_END : GetRailType(tile);
  1059 			ResizeWindow(w, 0, 16);
  1114 			ResizeWindow(w, 0, 16);
  1060 			break;
  1115 			break;
  1061 		case VEH_ROAD:
  1116 		case VEH_ROAD:
       
  1117 			WP(w, buildvehicle_d).filter.roadtypes = (tile == 0) ? ROADTYPES_ALL : GetRoadTypes(tile);
  1062 			ResizeWindow(w, 0, 16);
  1118 			ResizeWindow(w, 0, 16);
  1063 		case VEH_SHIP:
  1119 		case VEH_SHIP:
  1064 			break;
  1120 			break;
  1065 		case VEH_AIRCRAFT:
  1121 		case VEH_AIRCRAFT:
  1066 			bv->filter.flags =
  1122 			bv->filter.flags =