ship_gui.c
changeset 193 0a7025304867
parent 176 84990c4b9212
child 243 9a40daa560ae
equal deleted inserted replaced
192:614bba52258d 193:0a7025304867
    24 
    24 
    25 static void ShipRefitWndProc(Window *w, WindowEvent *e)
    25 static void ShipRefitWndProc(Window *w, WindowEvent *e)
    26 {
    26 {
    27 	switch(e->event) {
    27 	switch(e->event) {
    28 	case WE_PAINT: {
    28 	case WE_PAINT: {
    29 		Vehicle *v = &_vehicles[w->window_number];	
    29 		Vehicle *v = &_vehicles[w->window_number];
    30 		const byte *b;
    30 		const byte *b;
    31 		int sel;
    31 		int sel;
    32 		int x,y;
    32 		int x,y;
    33 		byte color;
    33 		byte color;
    34 		int cargo;
    34 		int cargo;
    36 		SET_DPARAM16(0, v->string_id);
    36 		SET_DPARAM16(0, v->string_id);
    37 		SET_DPARAM16(1, v->unitnumber);
    37 		SET_DPARAM16(1, v->unitnumber);
    38 		DrawWindowWidgets(w);
    38 		DrawWindowWidgets(w);
    39 
    39 
    40 		DrawString(1, 15, STR_983F_SELECT_CARGO_TYPE_TO_CARRY, 0);
    40 		DrawString(1, 15, STR_983F_SELECT_CARGO_TYPE_TO_CARRY, 0);
    41 		
    41 
    42 		cargo = -1;
    42 		cargo = -1;
    43 		x = 6;
    43 		x = 6;
    44 		y = 25;
    44 		y = 25;
    45 		sel = WP(w,refit_d).sel;
    45 		sel = WP(w,refit_d).sel;
    46 
    46 
   101 					SetWindowDirty(w);
   101 					SetWindowDirty(w);
   102 				}
   102 				}
   103 			} break;
   103 			} break;
   104 		case 4: /* refit button */
   104 		case 4: /* refit button */
   105 			if (WP(w,refit_d).cargo != 0xFF) {
   105 			if (WP(w,refit_d).cargo != 0xFF) {
   106 				Vehicle *v = &_vehicles[w->window_number];	
   106 				Vehicle *v = &_vehicles[w->window_number];
   107 				if (DoCommandP(v->tile, v->index, WP(w,refit_d).cargo, NULL, CMD_REFIT_SHIP | CMD_MSG(STR_9841_CAN_T_REFIT_SHIP)))
   107 				if (DoCommandP(v->tile, v->index, WP(w,refit_d).cargo, NULL, CMD_REFIT_SHIP | CMD_MSG(STR_9841_CAN_T_REFIT_SHIP)))
   108 					DeleteWindow(w);
   108 					DeleteWindow(w);
   109 			}
   109 			}
   110 		  break;
   110 		  break;
   111 		}
   111 		}
   134 static void ShowShipRefitWindow(Vehicle *v)
   134 static void ShowShipRefitWindow(Vehicle *v)
   135 {
   135 {
   136 	Window *w;
   136 	Window *w;
   137 
   137 
   138 	DeleteWindowById(WC_VEHICLE_REFIT, v->index);
   138 	DeleteWindowById(WC_VEHICLE_REFIT, v->index);
   139 	
   139 
   140 	_alloc_wnd_parent_num = v->index;	
   140 	_alloc_wnd_parent_num = v->index;
   141 	w = AllocateWindowDesc(&_ship_refit_desc);
   141 	w = AllocateWindowDesc(&_ship_refit_desc);
   142 	w->window_number = v->index;
   142 	w->window_number = v->index;
   143 	w->caption_color = v->owner;
   143 	w->caption_color = v->owner;
   144 	WP(w,refit_d).sel = -1;
   144 	WP(w,refit_d).sel = -1;
   145 }
   145 }
   164 		{
   164 		{
   165 			int year = v->age / 366;
   165 			int year = v->age / 366;
   166 			StringID str;
   166 			StringID str;
   167 
   167 
   168 			SET_DPARAM16(1, year);
   168 			SET_DPARAM16(1, year);
   169 			
   169 
   170 			str = STR_0199_YEAR;
   170 			str = STR_0199_YEAR;
   171 			if (year != 1) {
   171 			if (year != 1) {
   172 				str++;
   172 				str++;
   173 				if (v->max_age - 366 < v->age)
   173 				if (v->max_age - 366 < v->age)
   174 					str++;
   174 					str++;
   210 
   210 
   211 		SET_DPARAM16(1, 1920 + v->build_year);
   211 		SET_DPARAM16(1, 1920 + v->build_year);
   212 		SET_DPARAM16(0, GetCustomEngineName(v->engine_type));
   212 		SET_DPARAM16(0, GetCustomEngineName(v->engine_type));
   213 		SET_DPARAM32(2, v->value);
   213 		SET_DPARAM32(2, v->value);
   214 		DrawString(74, 57, STR_9816_BUILT_VALUE, 0);
   214 		DrawString(74, 57, STR_9816_BUILT_VALUE, 0);
   215 		
   215 
   216 		SET_DPARAM16(0, _cargoc.names_long_p[v->cargo_type]);
   216 		SET_DPARAM16(0, _cargoc.names_long_p[v->cargo_type]);
   217 		SET_DPARAM16(1, v->cargo_cap);
   217 		SET_DPARAM16(1, v->cargo_cap);
   218 		DrawString(74, 67, STR_9817_CAPACITY, 0);
   218 		DrawString(74, 67, STR_9817_CAPACITY, 0);
   219 
   219 
   220 		str = STR_8812_EMPTY;
   220 		str = STR_8812_EMPTY;
   293 {
   293 {
   294 	Window *w;
   294 	Window *w;
   295 	VehicleID veh = v->index;
   295 	VehicleID veh = v->index;
   296 	DeleteWindowById(WC_VEHICLE_ORDERS, veh);
   296 	DeleteWindowById(WC_VEHICLE_ORDERS, veh);
   297 	DeleteWindowById(WC_VEHICLE_DETAILS, veh);
   297 	DeleteWindowById(WC_VEHICLE_DETAILS, veh);
   298 	_alloc_wnd_parent_num = veh;	
   298 	_alloc_wnd_parent_num = veh;
   299 	w = AllocateWindowDesc(&_ship_details_desc);
   299 	w = AllocateWindowDesc(&_ship_details_desc);
   300 	w->window_number = veh;
   300 	w->window_number = veh;
   301 	w->caption_color = v->owner;
   301 	w->caption_color = v->owner;
   302 }
   302 }
   303 
   303 
   312 		RestoreVehicleOrders(v, _backup_orders_data);
   312 		RestoreVehicleOrders(v, _backup_orders_data);
   313 	}
   313 	}
   314 	ShowShipViewWindow(v);
   314 	ShowShipViewWindow(v);
   315 }
   315 }
   316 
   316 
   317 static void NewShipWndProc(Window *w, WindowEvent *e) 
   317 static void NewShipWndProc(Window *w, WindowEvent *e)
   318 {
   318 {
   319 	YearMonthDay ymd;
   319 	YearMonthDay ymd;
   320 	switch(e->event) {
   320 	switch(e->event) {
   321 	case WE_PAINT:
   321 	case WE_PAINT:
   322 		if (w->window_number == 0)
   322 		if (w->window_number == 0)
   352 					if (IS_INT_INSIDE(--pos, -4, 0)) {
   352 					if (IS_INT_INSIDE(--pos, -4, 0)) {
   353 						DrawString(x+75, y+7, GetCustomEngineName(engine_id), sel==0 ? 0xC : 0x10);
   353 						DrawString(x+75, y+7, GetCustomEngineName(engine_id), sel==0 ? 0xC : 0x10);
   354 						DrawShipEngine(x+35, y+10, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
   354 						DrawShipEngine(x+35, y+10, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
   355 						y += 24;
   355 						y += 24;
   356 					}
   356 					}
   357 					sel--; 
   357 					sel--;
   358 				}
   358 				}
   359 			} while (++engine_id, ++e,--num);
   359 			} while (++engine_id, ++e,--num);
   360 
   360 
   361 			WP(w,buildtrain_d).sel_engine = selected_id;
   361 			WP(w,buildtrain_d).sel_engine = selected_id;
   362 
   362 
   368 				SET_DPARAM16(2, _cargoc.names_long_p[ship_vehicle_info(selected_id).cargo_type]);
   368 				SET_DPARAM16(2, _cargoc.names_long_p[ship_vehicle_info(selected_id).cargo_type]);
   369 				SET_DPARAM16(3, ship_vehicle_info(selected_id).capacity);
   369 				SET_DPARAM16(3, ship_vehicle_info(selected_id).capacity);
   370 				SET_DPARAM16(4, ship_vehicle_info(selected_id).refittable ? STR_9842_REFITTABLE : STR_EMPTY);
   370 				SET_DPARAM16(4, ship_vehicle_info(selected_id).refittable ? STR_9842_REFITTABLE : STR_EMPTY);
   371 				SET_DPARAM32(5, ship_vehicle_info(selected_id).running_cost * _price.ship_running >> 8);
   371 				SET_DPARAM32(5, ship_vehicle_info(selected_id).running_cost * _price.ship_running >> 8);
   372 
   372 
   373 				e = &_engines[selected_id];	
   373 				e = &_engines[selected_id];
   374 				SET_DPARAM16(7, e->lifelength);
   374 				SET_DPARAM16(7, e->lifelength);
   375 				SET_DPARAM8(8, e->reliability * 100 >> 16);
   375 				SET_DPARAM8(8, e->reliability * 100 >> 16);
   376 				ConvertDayToYMD(&ymd, e->intro_date);
   376 				ConvertDayToYMD(&ymd, e->intro_date);
   377 				SET_DPARAM16(6, ymd.year + 1920);
   377 				SET_DPARAM16(6, ymd.year + 1920);
   378 				
   378 
   379 				DrawString(2, 111, STR_980A_COST_SPEED_CAPACITY_RUNNING, 0);
   379 				DrawString(2, 111, STR_980A_COST_SPEED_CAPACITY_RUNNING, 0);
   380 			}
   380 			}
   381 		}
   381 		}
   382 		break;
   382 		break;
   383 
   383 
   454 	DeleteWindowById(WC_BUILD_VEHICLE, tile);
   454 	DeleteWindowById(WC_BUILD_VEHICLE, tile);
   455 
   455 
   456 	w = AllocateWindowDesc(&_new_ship_desc);
   456 	w = AllocateWindowDesc(&_new_ship_desc);
   457 	w->window_number = tile;
   457 	w->window_number = tile;
   458 	w->vscroll.cap = 4;
   458 	w->vscroll.cap = 4;
   459 	
   459 
   460 	if (tile != 0) {
   460 	if (tile != 0) {
   461 		w->caption_color = _map_owner[tile];
   461 		w->caption_color = _map_owner[tile];
   462 	} else {
   462 	} else {
   463 		w->caption_color = _local_player;
   463 		w->caption_color = _local_player;
   464 	}
   464 	}
   465 	
   465 
   466 }
   466 }
   467 
   467 
   468 
   468 
   469 static void ShipViewWndProc(Window *w, WindowEvent *e) {
   469 static void ShipViewWndProc(Window *w, WindowEvent *e) {
   470 	switch(e->event) {
   470 	switch(e->event) {
   477 		if (ship_vehicle_info(v->engine_type).refittable &&
   477 		if (ship_vehicle_info(v->engine_type).refittable &&
   478 				v->vehstatus&VS_STOPPED &&
   478 				v->vehstatus&VS_STOPPED &&
   479 				v->u.ship.state == 0x80 &&
   479 				v->u.ship.state == 0x80 &&
   480 				IsShipDepotTile(v->tile))
   480 				IsShipDepotTile(v->tile))
   481 			disabled = 0;
   481 			disabled = 0;
   482 					
   482 
   483 		if (v->owner != _local_player)
   483 		if (v->owner != _local_player)
   484 			disabled |= 1<<7 | 1<<6;
   484 			disabled |= 1<<7 | 1<<6;
   485 		w->disabled_state = disabled;
   485 		w->disabled_state = disabled;
   486 
   486 
   487 		/* draw widgets & caption */
   487 		/* draw widgets & caption */
   533 	case WE_CLICK: {
   533 	case WE_CLICK: {
   534 		Vehicle *v = &_vehicles[w->window_number];
   534 		Vehicle *v = &_vehicles[w->window_number];
   535 
   535 
   536 		switch(e->click.widget) {
   536 		switch(e->click.widget) {
   537 		case 4: /* start stop */
   537 		case 4: /* start stop */
   538 			DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_SHIP | CMD_MSG(STR_9818_CAN_T_STOP_START_SHIP)); 
   538 			DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_SHIP | CMD_MSG(STR_9818_CAN_T_STOP_START_SHIP));
   539 			break;
   539 			break;
   540 		case 5: /* center main view */
   540 		case 5: /* center main view */
   541 			ScrollMainWindowTo(v->x_pos, v->y_pos);
   541 			ScrollMainWindowTo(v->x_pos, v->y_pos);
   542 			break;
   542 			break;
   543 		case 6: /* goto hangar */
   543 		case 6: /* goto hangar */
   544 			DoCommandP(v->tile, v->index, 0, NULL, CMD_SEND_SHIP_TO_DEPOT | CMD_MSG(STR_9819_CAN_T_SEND_SHIP_TO_DEPOT)); 
   544 			DoCommandP(v->tile, v->index, 0, NULL, CMD_SEND_SHIP_TO_DEPOT | CMD_MSG(STR_9819_CAN_T_SEND_SHIP_TO_DEPOT));
   545 			break;
   545 			break;
   546 		case 7: /* refit */
   546 		case 7: /* refit */
   547 			ShowShipRefitWindow(v);
   547 			ShowShipRefitWindow(v);
   548 			break;
   548 			break;
   549 		case 8: /* show orders */
   549 		case 8: /* show orders */
   555 		}
   555 		}
   556 	} break;
   556 	} break;
   557 
   557 
   558 	case WE_DESTROY:
   558 	case WE_DESTROY:
   559 		DeleteWindowById(WC_VEHICLE_ORDERS, w->window_number);
   559 		DeleteWindowById(WC_VEHICLE_ORDERS, w->window_number);
   560 		DeleteWindowById(WC_VEHICLE_REFIT, w->window_number);		
   560 		DeleteWindowById(WC_VEHICLE_REFIT, w->window_number);
   561 		DeleteWindowById(WC_VEHICLE_DETAILS, w->window_number);
   561 		DeleteWindowById(WC_VEHICLE_DETAILS, w->window_number);
   562 		break;
   562 		break;
   563 	}
   563 	}
   564 }
   564 }
   565 
   565 
   639 	y = 15;
   639 	y = 15;
   640 	num = w->vscroll.pos * 3;
   640 	num = w->vscroll.pos * 3;
   641 
   641 
   642 	FOR_ALL_VEHICLES(v) {
   642 	FOR_ALL_VEHICLES(v) {
   643 		if (v->type == VEH_Ship &&
   643 		if (v->type == VEH_Ship &&
   644 				v->u.ship.state == 0x80 && 
   644 				v->u.ship.state == 0x80 &&
   645 				v->tile == (TileIndex)tile &&
   645 				v->tile == (TileIndex)tile &&
   646 				--num < 0 && num >=	-6) {
   646 				--num < 0 && num >=	-6) {
   647 
   647 
   648 			DrawShipImage(v, x+19, y, WP(w,traindepot_d).sel);
   648 			DrawShipImage(v, x+19, y, WP(w,traindepot_d).sel);
   649 			
   649 
   650 			SET_DPARAM16(0, v->unitnumber);
   650 			SET_DPARAM16(0, v->unitnumber);
   651 			DrawString(x, y, (uint16)(v->max_age-366) >= v->age ? STR_00E2 : STR_00E3, 0);
   651 			DrawString(x, y, (uint16)(v->max_age-366) >= v->age ? STR_00E2 : STR_00E3, 0);
   652 
   652 
   653 			DrawSprite( (v->vehstatus & VS_STOPPED) ? 0xC12 : 0xC13, x, y + 9);
   653 			DrawSprite( (v->vehstatus & VS_STOPPED) ? 0xC12 : 0xC13, x, y + 9);
   654 			
   654 
   655 			if ((x+=90) == 2+90*3) {
   655 			if ((x+=90) == 2+90*3) {
   656 				x = 2;
   656 				x = 2;
   657 				y += 24;
   657 				y += 24;
   658 			}
   658 			}
   659 		}
   659 		}
   664 {
   664 {
   665 	uint xt,yt,xm,ym;
   665 	uint xt,yt,xm,ym;
   666 	TileIndex tile;
   666 	TileIndex tile;
   667 	Vehicle *v;
   667 	Vehicle *v;
   668 	int pos;
   668 	int pos;
   669 		
   669 
   670 	xt = x / 90;
   670 	xt = x / 90;
   671 	xm = x % 90;
   671 	xm = x % 90;
   672 	if (xt >= 5)
   672 	if (xt >= 5)
   673 		return 1;
   673 		return 1;
   674 
   674 
   680 	pos = (yt + w->vscroll.pos) * 3 + xt;
   680 	pos = (yt + w->vscroll.pos) * 3 + xt;
   681 
   681 
   682 	tile = w->window_number;
   682 	tile = w->window_number;
   683 	FOR_ALL_VEHICLES(v) {
   683 	FOR_ALL_VEHICLES(v) {
   684 		if (v->type == VEH_Ship &&
   684 		if (v->type == VEH_Ship &&
   685 				v->vehstatus&VS_HIDDEN && 
   685 				v->vehstatus&VS_HIDDEN &&
   686 				v->tile == (TileIndex)tile &&
   686 				v->tile == (TileIndex)tile &&
   687 				--pos < 0) {
   687 				--pos < 0) {
   688 					*veh = v;
   688 					*veh = v;
   689 					if (xm >= 19)
   689 					if (xm >= 19)
   690 						return 0;
   690 						return 0;
   693 					return -2; /* start stop */
   693 					return -2; /* start stop */
   694 				}
   694 				}
   695 	}
   695 	}
   696 
   696 
   697 	return 1; /* outside */
   697 	return 1; /* outside */
   698 	
   698 
   699 }
   699 }
   700 
   700 
   701 static void ShipDepotClick(Window *w, int x, int y)
   701 static void ShipDepotClick(Window *w, int x, int y)
   702 {
   702 {
   703 	Vehicle *v;
   703 	Vehicle *v;
   712 
   712 
   713 	case 0: // start dragging of vehicle
   713 	case 0: // start dragging of vehicle
   714 		if (v != NULL) {
   714 		if (v != NULL) {
   715 			WP(w,traindepot_d).sel = v->index;
   715 			WP(w,traindepot_d).sel = v->index;
   716 			SetWindowDirty(w);
   716 			SetWindowDirty(w);
   717 			SetObjectToPlaceWnd( SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner)) + 
   717 			SetObjectToPlaceWnd( SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner)) +
   718 				GetShipImage(v, 6), 4, w);
   718 				GetShipImage(v, 6), 4, w);
   719 		}
   719 		}
   720 		break;
   720 		break;
   721 
   721 
   722 	case -1: // show info window
   722 	case -1: // show info window
   741 	case WE_CLICK:
   741 	case WE_CLICK:
   742 		switch(e->click.widget) {
   742 		switch(e->click.widget) {
   743 		case 2:
   743 		case 2:
   744 			ShipDepotClick(w, e->click.pt.x, e->click.pt.y);
   744 			ShipDepotClick(w, e->click.pt.x, e->click.pt.y);
   745 			break;
   745 			break;
   746 			
   746 
   747 		case 5:
   747 		case 5:
   748 			ShowBuildShipWindow(w->window_number);
   748 			ShowBuildShipWindow(w->window_number);
   749 			break;
   749 			break;
   750 
   750 
   751 		case 6: /* scroll to tile */
   751 		case 6: /* scroll to tile */
   771 					v != NULL &&
   771 					v != NULL &&
   772 					sel == v->index) {
   772 					sel == v->index) {
   773 				ShowShipViewWindow(v);
   773 				ShowShipViewWindow(v);
   774 			}
   774 			}
   775 		} break;
   775 		} break;
   776 					
   776 
   777 		case 3:
   777 		case 3:
   778 			if (!HASBIT(w->disabled_state, 3) &&
   778 			if (!HASBIT(w->disabled_state, 3) &&
   779 					WP(w,traindepot_d).sel != INVALID_VEHICLE)	{
   779 					WP(w,traindepot_d).sel != INVALID_VEHICLE)	{
   780 				Vehicle *v;
   780 				Vehicle *v;
   781 				
   781 
   782 				HandleButtonClick(w, 3);
   782 				HandleButtonClick(w, 3);
   783 
   783 
   784 				v = &_vehicles[WP(w,traindepot_d).sel];
   784 				v = &_vehicles[WP(w,traindepot_d).sel];
   785 				WP(w,traindepot_d).sel = INVALID_VEHICLE;
   785 				WP(w,traindepot_d).sel = INVALID_VEHICLE;
   786 
   786 
   787 				_backup_orders_tile = v->tile;
   787 				_backup_orders_tile = v->tile;
   788 				BackupVehicleOrders(v, _backup_orders_data);
   788 				BackupVehicleOrders(v, _backup_orders_data);
   789 	
   789 
   790 				if (!DoCommandP(v->tile, v->index, 0, NULL, CMD_SELL_SHIP | CMD_MSG(STR_980C_CAN_T_SELL_SHIP)))
   790 				if (!DoCommandP(v->tile, v->index, 0, NULL, CMD_SELL_SHIP | CMD_MSG(STR_980C_CAN_T_SELL_SHIP)))
   791 					_backup_orders_tile = 0;
   791 					_backup_orders_tile = 0;
   792 			}
   792 			}
   793 			break;
   793 			break;
   794 		default:
   794 		default:
   852 		}
   852 		}
   853 		sel--;
   853 		sel--;
   854 
   854 
   855 		if ((ord & OT_MASK) == OT_GOTO_STATION) {
   855 		if ((ord & OT_MASK) == OT_GOTO_STATION) {
   856 			st = DEREF_STATION(ord >> 8);
   856 			st = DEREF_STATION(ord >> 8);
   857 			
   857 
   858 			if (!(st->had_vehicle_of_type & HVOT_BUOY)) {
   858 			if (!(st->had_vehicle_of_type & HVOT_BUOY)) {
   859 				SET_DPARAM16(0, ord >> 8);
   859 				SET_DPARAM16(0, ord >> 8);
   860 				DrawString(x, y, STR_A036, 0);
   860 				DrawString(x, y, STR_A036, 0);
   861 
   861 
   862 				y += 6;
   862 				y += 6;
   892 
   892 
   893 		// create cumulative ship-ownage
   893 		// create cumulative ship-ownage
   894 		// ships are stored as a cummulative index, eg 25, 41, 43. This means
   894 		// ships are stored as a cummulative index, eg 25, 41, 43. This means
   895 		// Player0: 25; Player1: (41-25) 16; Player2: (43-41) 2
   895 		// Player0: 25; Player1: (41-25) 16; Player2: (43-41) 2
   896 		for (i = &_num_ship_sort[1]; i != endof(_num_ship_sort); i++) {*i += *(i-1);}
   896 		for (i = &_num_ship_sort[1]; i != endof(_num_ship_sort); i++) {*i += *(i-1);}
   897 	
   897 
   898 		// sort by owner, then only subsort the requested owner-vehicles
   898 		// sort by owner, then only subsort the requested owner-vehicles
   899 		qsort(_ship_sort, n, sizeof(_ship_sort[0]), GeneralOwnerSorter);
   899 		qsort(_ship_sort, n, sizeof(_ship_sort[0]), GeneralOwnerSorter);
   900 
   900 
   901 		_last_vehicle_idx = 0; // used for "cache" in namesorting
   901 		_last_vehicle_idx = 0; // used for "cache" in namesorting
   902 		_vehicle_sort_dirty[VEHSHIP] = false;
   902 		_vehicle_sort_dirty[VEHSHIP] = false;
   937 
   937 
   938 		// ships are stored as a cummulative index, eg 25, 41, 43. This means
   938 		// ships are stored as a cummulative index, eg 25, 41, 43. This means
   939 		// Player0: 25; Player1: (41-25) 16; Player2: (43-41) 2 ships
   939 		// Player0: 25; Player1: (41-25) 16; Player2: (43-41) 2 ships
   940 		i = (window_number == 0) ? 0 : _num_ship_sort[window_number-1];
   940 		i = (window_number == 0) ? 0 : _num_ship_sort[window_number-1];
   941 		SetVScrollCount(w, _num_ship_sort[window_number] - i);
   941 		SetVScrollCount(w, _num_ship_sort[window_number] - i);
   942 		
   942 
   943 		/* draw the widgets */
   943 		/* draw the widgets */
   944 		{
   944 		{
   945 			Player *p = DEREF_PLAYER(window_number);
   945 			Player *p = DEREF_PLAYER(window_number);
   946 			/* Company Name -- (###) Ships */
   946 			/* Company Name -- (###) Ships */
   947 			SET_DPARAM16(0, p->name_1);
   947 			SET_DPARAM16(0, p->name_1);
   980 				DrawString(x, y+2, str, 0);
   980 				DrawString(x, y+2, str, 0);
   981 
   981 
   982 				SET_DPARAM32(0, v->profit_this_year);
   982 				SET_DPARAM32(0, v->profit_this_year);
   983 				SET_DPARAM32(1, v->profit_last_year);
   983 				SET_DPARAM32(1, v->profit_last_year);
   984 				DrawString(x + 12, y + 28, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, 0);
   984 				DrawString(x + 12, y + 28, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, 0);
   985 				
   985 
   986 				if (v->string_id != STR_SV_SHIP_NAME) {
   986 				if (v->string_id != STR_SV_SHIP_NAME) {
   987 					SET_DPARAM16(0, v->string_id);
   987 					SET_DPARAM16(0, v->string_id);
   988 					DrawString(x+12, y, STR_01AB, 0);
   988 					DrawString(x+12, y, STR_01AB, 0);
   989 				}
   989 				}
   990 
   990 
  1008 		case 3: case 4:/* Select sorting criteria dropdown menu */
  1008 		case 3: case 4:/* Select sorting criteria dropdown menu */
  1009 			ShowDropDownMenu(w, _vehicle_sort_listing, _ship_sort_type[(byte)w->window_number], 4, 0); // do it for widget 4
  1009 			ShowDropDownMenu(w, _vehicle_sort_listing, _ship_sort_type[(byte)w->window_number], 4, 0); // do it for widget 4
  1010 			return;
  1010 			return;
  1011 		case 6: { /* Matrix to show vehicles */
  1011 		case 6: { /* Matrix to show vehicles */
  1012 			uint32 id_v = (e->click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / PLY_WND_PRC__SIZE_OF_ROW_BIG;
  1012 			uint32 id_v = (e->click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / PLY_WND_PRC__SIZE_OF_ROW_BIG;
  1013 			
  1013 
  1014 			if (id_v >= w->vscroll.cap) { return;} // click out of bounds
  1014 			if (id_v >= w->vscroll.cap) { return;} // click out of bounds
  1015 
  1015 
  1016 			id_v += w->vscroll.pos;
  1016 			id_v += w->vscroll.pos;
  1017 
  1017 
  1018 			{
  1018 			{
  1033 		case 8: { /* Build new Vehicle */
  1033 		case 8: { /* Build new Vehicle */
  1034 			uint tile;
  1034 			uint tile;
  1035 
  1035 
  1036 			tile = _last_built_ship_depot_tile;
  1036 			tile = _last_built_ship_depot_tile;
  1037 			do {
  1037 			do {
  1038 				if (_map_owner[tile] == _local_player && IsShipDepotTile(tile)) {					
  1038 				if (_map_owner[tile] == _local_player && IsShipDepotTile(tile)) {
  1039 					ShowShipDepotWindow(tile);
  1039 					ShowShipDepotWindow(tile);
  1040 					ShowBuildShipWindow(tile);
  1040 					ShowBuildShipWindow(tile);
  1041 					return;
  1041 					return;
  1042 				}
  1042 				}
  1043 				
  1043 
  1044 				tile = TILE_MASK(tile + 1);
  1044 				tile = TILE_MASK(tile + 1);
  1045 			} while(tile != _last_built_ship_depot_tile);
  1045 			} while(tile != _last_built_ship_depot_tile);
  1046 			
  1046 
  1047 			ShowBuildShipWindow(0);
  1047 			ShowBuildShipWindow(0);
  1048 		} break;
  1048 		} break;
  1049 		}
  1049 		}
  1050 	}	break;
  1050 	}	break;
  1051 
  1051