src/build_vehicle_gui.cpp
branchgamebalance
changeset 9903 dc85aaa556ae
parent 9895 7bd07f43b0e3
child 9907 3b068c3a1c74
equal deleted inserted replaced
9902:ed8f92929297 9903:dc85aaa556ae
   199 
   199 
   200 static int CDECL TrainEngineRunningCostSorter(const void *a, const void *b)
   200 static int CDECL TrainEngineRunningCostSorter(const void *a, const void *b)
   201 {
   201 {
   202 	const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
   202 	const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
   203 	const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
   203 	const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
   204 
   204 	uint32 cost_class_a, cost_class_b;
   205 	int va = rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class] * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
   205 
   206 	int vb = rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class] * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
   206 	switch (rvi_a->running_cost_class) {
       
   207 		default:
       
   208 		case 0: cost_class_a = _eco->GetPrice(CEconomy::RUNNING_RAIL0); break;
       
   209 		case 1: cost_class_a = _eco->GetPrice(CEconomy::RUNNING_RAIL1); break;
       
   210 		case 2: cost_class_a = _eco->GetPrice(CEconomy::RUNNING_RAIL2); break;
       
   211 	}
       
   212 
       
   213 	switch (rvi_b->running_cost_class) {
       
   214 		default:
       
   215 		case 0: cost_class_b = _eco->GetPrice(CEconomy::RUNNING_RAIL0); break;
       
   216 		case 1: cost_class_b = _eco->GetPrice(CEconomy::RUNNING_RAIL1); break;
       
   217 		case 2: cost_class_b = _eco->GetPrice(CEconomy::RUNNING_RAIL2); break;
       
   218 	}
       
   219 
       
   220 	int va = rvi_a->running_cost_base * cost_class_a * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
       
   221 	int vb = rvi_b->running_cost_base * cost_class_b * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
   207 	int r = va - vb;
   222 	int r = va - vb;
   208 
   223 
   209 	return _internal_sort_order ? -r : r;
   224 	return _internal_sort_order ? -r : r;
   210 }
   225 }
   211 
   226 
   212 static int CDECL TrainEnginePowerVsRunningCostSorter(const void *a, const void *b)
   227 static int CDECL TrainEnginePowerVsRunningCostSorter(const void *a, const void *b)
   213 {
   228 {
   214 	const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
   229 	const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
   215 	const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
   230 	const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
       
   231 	uint32 cost_class_a, cost_class_b;
       
   232 
       
   233 	switch (rvi_a->running_cost_class) {
       
   234 		default:
       
   235 		case 0: cost_class_a = _eco->GetPrice(CEconomy::RUNNING_RAIL0); break;
       
   236 		case 1: cost_class_a = _eco->GetPrice(CEconomy::RUNNING_RAIL1); break;
       
   237 		case 2: cost_class_a = _eco->GetPrice(CEconomy::RUNNING_RAIL2); break;
       
   238 	}
       
   239 
       
   240 	switch (rvi_b->running_cost_class) {
       
   241 		default:
       
   242 		case 0: cost_class_b = _eco->GetPrice(CEconomy::RUNNING_RAIL0); break;
       
   243 		case 1: cost_class_b = _eco->GetPrice(CEconomy::RUNNING_RAIL1); break;
       
   244 		case 2: cost_class_b = _eco->GetPrice(CEconomy::RUNNING_RAIL2); break;
       
   245 	}
   216 
   246 
   217 	/* Here we are using a few tricks to get the right sort.
   247 	/* Here we are using a few tricks to get the right sort.
   218 		* We want power/running cost, but since we usually got higher running cost than power and we store the result in an int,
   248 		* We want power/running cost, but since we usually got higher running cost than power and we store the result in an int,
   219 		* we will actually calculate cunning cost/power (to make it more than 1).
   249 		* we will actually calculate cunning cost/power (to make it more than 1).
   220 		* Because of this, the return value have to be reversed as well and we return b - a instead of a - b.
   250 		* Because of this, the return value have to be reversed as well and we return b - a instead of a - b.
   221 		* Another thing is that both power and running costs should be doubled for multiheaded engines.
   251 		* Another thing is that both power and running costs should be doubled for multiheaded engines.
   222 		* Since it would be multipling with 2 in both numerator and denumerator, it will even themselves out and we skip checking for multiheaded. */
   252 		* Since it would be multipling with 2 in both numerator and denumerator, it will even themselves out and we skip checking for multiheaded. */
   223 	int va = (rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class]) / max((uint16)1, rvi_a->power);
   253 	int va = rvi_a->running_cost_base * cost_class_a / max((uint16)1, rvi_a->power);
   224 	int vb = (rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class]) / max((uint16)1, rvi_b->power);
   254 	int vb = rvi_b->running_cost_base * cost_class_b / max((uint16)1, rvi_b->power);
   225 	int r = vb - va;
   255 	int r = vb - va;
   226 
   256 
   227 	return _internal_sort_order ? -r : r;
   257 	return _internal_sort_order ? -r : r;
   228 }
   258 }
   229 
   259 
   376 
   406 
   377 /* Draw rail wagon specific details */
   407 /* Draw rail wagon specific details */
   378 static int DrawRailWagonPurchaseInfo(int x, int y, EngineID engine_number, const RailVehicleInfo *rvi)
   408 static int DrawRailWagonPurchaseInfo(int x, int y, EngineID engine_number, const RailVehicleInfo *rvi)
   379 {
   409 {
   380 	/* Purchase cost */
   410 	/* Purchase cost */
   381 	SetDParam(0, (rvi->base_cost * _price.build_railwagon) >> 8);
   411 	SetDParam(0, (rvi->base_cost * _eco->GetPrice(CEconomy::BUILD_RAILWAGON)) >> 8);
   382 	DrawString(x, y, STR_PURCHASE_INFO_COST, 0);
   412 	DrawString(x, y, STR_PURCHASE_INFO_COST, 0);
   383 	y += 10;
   413 	y += 10;
   384 
   414 
   385 	/* Wagon weight - (including cargo) */
   415 	/* Wagon weight - (including cargo) */
   386 	SetDParam(0, rvi->weight);
   416 	SetDParam(0, rvi->weight);
   401 static int DrawRailEnginePurchaseInfo(int x, int y, EngineID engine_number, const RailVehicleInfo *rvi)
   431 static int DrawRailEnginePurchaseInfo(int x, int y, EngineID engine_number, const RailVehicleInfo *rvi)
   402 {
   432 {
   403 	int multihead = (rvi->railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
   433 	int multihead = (rvi->railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
   404 
   434 
   405 	/* Purchase Cost - Engine weight */
   435 	/* Purchase Cost - Engine weight */
   406 	SetDParam(0, rvi->base_cost * (_price.build_railvehicle >> 3) >> 5);
   436 	SetDParam(0, rvi->base_cost * (_eco->GetPrice(CEconomy::BUILD_RAILVEHICLE) >> 3) >> 5);
   407 	SetDParam(1, rvi->weight << multihead);
   437 	SetDParam(1, rvi->weight << multihead);
   408 	DrawString(x,y, STR_PURCHASE_INFO_COST_WEIGHT, 0);
   438 	DrawString(x,y, STR_PURCHASE_INFO_COST_WEIGHT, 0);
   409 	y += 10;
   439 	y += 10;
   410 
   440 
   411 	/* Max speed - Engine power */
   441 	/* Max speed - Engine power */
   419 		SetDParam(0, ((rvi->weight << multihead) * 10 * rvi->tractive_effort) / 256);
   449 		SetDParam(0, ((rvi->weight << multihead) * 10 * rvi->tractive_effort) / 256);
   420 		DrawString(x, y, STR_PURCHASE_INFO_MAX_TE, 0);
   450 		DrawString(x, y, STR_PURCHASE_INFO_MAX_TE, 0);
   421 		y += 10;
   451 		y += 10;
   422 	}
   452 	}
   423 
   453 
       
   454 	uint32 cost_class;
       
   455 
       
   456 	switch (rvi->running_cost_class) {
       
   457 		default:
       
   458 		case 0: cost_class = _eco->GetPrice(CEconomy::RUNNING_RAIL0); break;
       
   459 		case 1: cost_class = _eco->GetPrice(CEconomy::RUNNING_RAIL1); break;
       
   460 		case 2: cost_class = _eco->GetPrice(CEconomy::RUNNING_RAIL2); break;
       
   461 	}
       
   462 
   424 	/* Running cost */
   463 	/* Running cost */
   425 	SetDParam(0, (rvi->running_cost_base * _price.running_rail[rvi->running_cost_class] >> 8) << multihead);
   464 	SetDParam(0, (rvi->running_cost_base * cost_class >> 8) << multihead);
   426 	DrawString(x,y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
   465 	DrawString(x,y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
   427 	y += 10;
   466 	y += 10;
   428 
   467 
   429 	/* Powered wagons power - Powered wagons extra weight */
   468 	/* Powered wagons power - Powered wagons extra weight */
   430 	if (rvi->pow_wag_power != 0) {
   469 	if (rvi->pow_wag_power != 0) {
   441 static int DrawRoadVehPurchaseInfo(int x, int y, EngineID engine_number, const RoadVehicleInfo *rvi)
   480 static int DrawRoadVehPurchaseInfo(int x, int y, EngineID engine_number, const RoadVehicleInfo *rvi)
   442 {
   481 {
   443 	bool refittable = (_engine_info[engine_number].refit_mask != 0);
   482 	bool refittable = (_engine_info[engine_number].refit_mask != 0);
   444 
   483 
   445 	/* Purchase cost - Max speed */
   484 	/* Purchase cost - Max speed */
   446 	SetDParam(0, rvi->base_cost * (_price.roadveh_base>>3)>>5);
   485 	SetDParam(0, rvi->base_cost * (_eco->GetPrice(CEconomy::ROADVEH_BASE) >> 3) >> 5);
   447 	SetDParam(1, rvi->max_speed * 10 / 32);
   486 	SetDParam(1, rvi->max_speed * 10 / 32);
   448 	DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0);
   487 	DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0);
   449 	y += 10;
   488 	y += 10;
   450 
   489 
   451 	/* Running cost */
   490 	/* Running cost */
   452 	SetDParam(0, rvi->running_cost * _price.roadveh_running >> 8);
   491 	SetDParam(0, rvi->running_cost * _eco->GetPrice(CEconomy::ROADVEH_RUNNING) >> 8);
   453 	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
   492 	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
   454 	y += 10;
   493 	y += 10;
   455 
   494 
   456 	/* Cargo type + capacity */
   495 	/* Cargo type + capacity */
   457 	SetDParam(0, rvi->cargo_type);
   496 	SetDParam(0, rvi->cargo_type);
   465 
   504 
   466 /* Draw ship specific details */
   505 /* Draw ship specific details */
   467 static int DrawShipPurchaseInfo(int x, int y, EngineID engine_number, const ShipVehicleInfo *svi)
   506 static int DrawShipPurchaseInfo(int x, int y, EngineID engine_number, const ShipVehicleInfo *svi)
   468 {
   507 {
   469 	/* Purchase cost - Max speed */
   508 	/* Purchase cost - Max speed */
   470 	SetDParam(0, svi->base_cost * (_price.ship_base>>3)>>5);
   509 	SetDParam(0, svi->base_cost * (_eco->GetPrice(CEconomy::SHIP_BASE) >> 3) >> 5);
   471 	SetDParam(1, svi->max_speed * 10 / 32);
   510 	SetDParam(1, svi->max_speed * 10 / 32);
   472 	DrawString(x,y, STR_PURCHASE_INFO_COST_SPEED, 0);
   511 	DrawString(x,y, STR_PURCHASE_INFO_COST_SPEED, 0);
   473 	y += 10;
   512 	y += 10;
   474 
   513 
   475 	/* Cargo type + capacity */
   514 	/* Cargo type + capacity */
   478 	SetDParam(2, svi->refittable ? STR_9842_REFITTABLE : STR_EMPTY);
   517 	SetDParam(2, svi->refittable ? STR_9842_REFITTABLE : STR_EMPTY);
   479 	DrawString(x,y, STR_PURCHASE_INFO_CAPACITY, 0);
   518 	DrawString(x,y, STR_PURCHASE_INFO_CAPACITY, 0);
   480 	y += 10;
   519 	y += 10;
   481 
   520 
   482 	/* Running cost */
   521 	/* Running cost */
   483 	SetDParam(0, svi->running_cost * _price.ship_running >> 8);
   522 	SetDParam(0, svi->running_cost * _eco->GetPrice(CEconomy::SHIP_RUNNING) >> 8);
   484 	DrawString(x,y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
   523 	DrawString(x,y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
   485 	y += 10;
   524 	y += 10;
   486 
   525 
   487 	return y;
   526 	return y;
   488 }
   527 }
   491 static int DrawAircraftPurchaseInfo(int x, int y, EngineID engine_number, const AircraftVehicleInfo *avi)
   530 static int DrawAircraftPurchaseInfo(int x, int y, EngineID engine_number, const AircraftVehicleInfo *avi)
   492 {
   531 {
   493 	CargoID cargo;
   532 	CargoID cargo;
   494 
   533 
   495 	/* Purchase cost - Max speed */
   534 	/* Purchase cost - Max speed */
   496 	SetDParam(0, avi->base_cost * (_price.aircraft_base>>3)>>5);
   535 	SetDParam(0, avi->base_cost * (_eco->GetPrice(CEconomy::AIRCRAFT_BASE) >> 3) >> 5);
   497 	SetDParam(1, avi->max_speed * 10 / 16);
   536 	SetDParam(1, avi->max_speed * 10 / 16);
   498 	DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0);
   537 	DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0);
   499 	y += 10;
   538 	y += 10;
   500 
   539 
   501 	/* Cargo capacity */
   540 	/* Cargo capacity */
   513 		DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
   552 		DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
   514 	}
   553 	}
   515 	y += 10;
   554 	y += 10;
   516 
   555 
   517 	/* Running cost */
   556 	/* Running cost */
   518 	SetDParam(0, avi->running_cost * _price.aircraft_running >> 8);
   557 	SetDParam(0, avi->running_cost * _eco->GetPrice(CEconomy::AIRCRAFT_RUNNING) >> 8);
   519 	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
   558 	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
   520 	y += 10;
   559 	y += 10;
   521 
   560 
   522 	return y;
   561 	return y;
   523 }
   562 }