truelight@0: #include "stdafx.h" truelight@0: #include "ttd.h" truelight@0: //#include "gui.h" truelight@0: #include "window.h" truelight@0: #include "gfx.h" truelight@0: #include "command.h" truelight@0: #include "viewport.h" truelight@0: #include "industry.h" truelight@0: #include "town.h" truelight@0: truelight@0: static const byte _build_industry_types[4][12] = { truelight@0: { 1, 2, 4, 6, 8, 0, 3, 5, 9, 11, 18 }, truelight@0: { 1, 14, 4, 13, 7, 0, 3, 9, 11, 15 }, truelight@0: { 25, 13, 4, 23, 22, 11, 17, 10, 24, 19, 20, 21 }, truelight@0: { 27, 30, 31, 33, 26, 28, 29, 32, 34, 35, 36 }, truelight@0: }; truelight@0: truelight@0: extern const byte _industry_type_costs[37]; truelight@0: truelight@0: static void BuildIndustryWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: truelight@0: DrawWindowWidgets(w); truelight@0: if (_thd.place_mode == 1 && _thd.window_class == WC_BUILD_INDUSTRY) { truelight@0: int ind_type = _build_industry_types[_opt.landscape][WP(w,def_d).data_1]; truelight@0: truelight@0: SET_DPARAM32(0, (_price.build_industry >> 5) * _industry_type_costs[ind_type]); truelight@0: DrawStringCentered(85, w->height - 21, STR_482F_COST, 0); truelight@0: } truelight@0: break; truelight@0: truelight@0: case WE_CLICK: { truelight@0: int wid = e->click.widget; truelight@0: if (wid >= 3) { truelight@0: if (HandlePlacePushButton(w, wid, 0xFF1, 1, NULL)) truelight@0: WP(w,def_d).data_1 = wid - 3; truelight@0: } truelight@0: } break; truelight@0: truelight@0: case WE_PLACE_OBJ: truelight@0: if (DoCommandP(e->place.tile, _build_industry_types[_opt.landscape][WP(w,def_d).data_1], 0, NULL, CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY))) truelight@0: ResetObjectToPlace(); truelight@0: break; truelight@0: truelight@0: case WE_ABORT_PLACE_OBJ: truelight@0: w->click_state = 0; truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: } truelight@0: } truelight@0: truelight@0: static const Widget _build_industry_land0_widgets[] = { truelight@0: { WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5,STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY,STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@0: { WWT_PANEL, 7, 0, 169, 14, 115, 0x0,0}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 16, 27, STR_0241_POWER_STATION,STR_0263_CONSTRUCT_POWER_STATION}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 29, 40, STR_0242_SAWMILL,STR_0264_CONSTRUCT_SAWMILL}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY,STR_0266_CONSTRUCT_OIL_REFINERY}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 55, 66, STR_0246_FACTORY,STR_0268_CONSTRUCT_FACTORY}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 68, 79, STR_0247_STEEL_MILL,STR_0269_CONSTRUCT_STEEL_MILL}, truelight@0: { WWT_LAST}, truelight@0: }; truelight@0: truelight@0: static const Widget _build_industry_land1_widgets[] = { truelight@0: { WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5,STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY,STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@0: { WWT_PANEL, 7, 0, 169, 14, 115, 0x0,0}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 16, 27, STR_0241_POWER_STATION,STR_0263_CONSTRUCT_POWER_STATION}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 29, 40, STR_024C_PAPER_MILL, STR_026E_CONSTRUCT_PAPER_MILL}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY,STR_0266_CONSTRUCT_OIL_REFINERY}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 55, 66, STR_024D_FOOD_PROCESSING_PLANT,STR_026F_CONSTRUCT_FOOD_PROCESSING}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 68, 79, STR_024E_PRINTING_WORKS,STR_0270_CONSTRUCT_PRINTING_WORKS}, truelight@0: { WWT_LAST}, truelight@0: }; truelight@0: truelight@0: static const Widget _build_industry_land2_widgets[] = { truelight@0: { WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5,STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY,STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@0: { WWT_PANEL, 7, 0, 169, 14, 115, 0x0,0}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 16, 27, STR_0250_LUMBER_MILL,STR_0273_CONSTRUCT_LUMBER_MILL_TO}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 29, 40, STR_024D_FOOD_PROCESSING_PLANT,STR_026F_CONSTRUCT_FOOD_PROCESSING}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY,STR_0266_CONSTRUCT_OIL_REFINERY}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 55, 66, STR_0246_FACTORY,STR_0268_CONSTRUCT_FACTORY}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 68, 79, STR_0254_WATER_TOWER,STR_0277_CONSTRUCT_WATER_TOWER_CAN}, truelight@0: { WWT_LAST}, truelight@0: }; truelight@0: truelight@0: static const Widget _build_industry_land3_widgets[] = { truelight@0: { WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5,STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY,STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@0: { WWT_PANEL, 7, 0, 169, 14, 115, 0x0,0}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 16, 27, STR_0258_CANDY_FACTORY,STR_027B_CONSTRUCT_CANDY_FACTORY}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 29, 40, STR_025B_TOY_SHOP,STR_027E_CONSTRUCT_TOY_SHOP}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 42, 53, STR_025C_TOY_FACTORY,STR_027F_CONSTRUCT_TOY_FACTORY}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 55, 66, STR_025E_FIZZY_DRINK_FACTORY,STR_0281_CONSTRUCT_FIZZY_DRINK_FACTORY}, truelight@0: { WWT_LAST}, truelight@0: }; truelight@0: truelight@0: static const Widget _build_industry_land0_widgets_extra[] = { truelight@0: { WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5,STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY,STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@0: { WWT_PANEL, 7, 0, 169, 14, 187, 0x0,0}, truelight@0: truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 16, 27, STR_0241_POWER_STATION,STR_0263_CONSTRUCT_POWER_STATION}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 29, 40, STR_0242_SAWMILL,STR_0264_CONSTRUCT_SAWMILL}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY,STR_0266_CONSTRUCT_OIL_REFINERY}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 55, 66, STR_0246_FACTORY,STR_0268_CONSTRUCT_FACTORY}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 68, 79, STR_0247_STEEL_MILL,STR_0269_CONSTRUCT_STEEL_MILL}, truelight@0: truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 84, 95, STR_0240_COAL_MINE, STR_CONSTRUCT_COAL_MINE_TIP}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 97, 108, STR_0243_FOREST, STR_CONSTRUCT_FOREST_TIP}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 110, 121, STR_0245_OIL_RIG, STR_CONSTRUCT_OIL_RIG_TIP}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 123, 134, STR_0248_FARM, STR_CONSTRUCT_FARM_TIP}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 136, 147, STR_024A_OIL_WELLS, STR_CONSTRUCT_OIL_WELLS_TIP}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 149, 160, STR_0249_IRON_ORE_MINE, STR_CONSTRUCT_IRON_ORE_MINE_TIP}, truelight@0: truelight@0: { WWT_LAST}, truelight@0: }; truelight@0: truelight@0: static const Widget _build_industry_land1_widgets_extra[] = { truelight@0: { WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5,STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY,STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@0: { WWT_PANEL, 7, 0, 169, 14, 174, 0x0,0}, truelight@0: truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 16, 27, STR_0241_POWER_STATION,STR_0263_CONSTRUCT_POWER_STATION}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 29, 40, STR_024C_PAPER_MILL, STR_026E_CONSTRUCT_PAPER_MILL}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY,STR_0266_CONSTRUCT_OIL_REFINERY}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 55, 66, STR_024D_FOOD_PROCESSING_PLANT,STR_026F_CONSTRUCT_FOOD_PROCESSING}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 68, 79, STR_024E_PRINTING_WORKS,STR_0270_CONSTRUCT_PRINTING_WORKS}, truelight@0: truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 81+3, 92+3, STR_0240_COAL_MINE,STR_CONSTRUCT_COAL_MINE_TIP}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 94+3, 105+3, STR_0243_FOREST,STR_CONSTRUCT_FOREST_TIP}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 107+3, 118+3, STR_0248_FARM,STR_CONSTRUCT_FARM_TIP}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 120+3, 131+3, STR_024A_OIL_WELLS,STR_CONSTRUCT_OIL_WELLS_TIP}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 133+3, 144+3, STR_024F_GOLD_MINE,STR_CONSTRUCT_GOLD_MINE_TIP}, truelight@0: { WWT_LAST}, truelight@0: }; truelight@0: truelight@0: static const Widget _build_industry_land2_widgets_extra[] = { truelight@0: { WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5,STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY,STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@0: { WWT_PANEL, 7, 0, 169, 14, 200, 0x0,0}, truelight@0: truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 16, 27, STR_0250_LUMBER_MILL,STR_0273_CONSTRUCT_LUMBER_MILL_TO}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 29, 40, STR_024D_FOOD_PROCESSING_PLANT,STR_026F_CONSTRUCT_FOOD_PROCESSING}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY,STR_0266_CONSTRUCT_OIL_REFINERY}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 55, 66, STR_0246_FACTORY,STR_0268_CONSTRUCT_FACTORY}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 68, 79, STR_0254_WATER_TOWER,STR_0277_CONSTRUCT_WATER_TOWER_CAN}, truelight@0: truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 81+3, 92+3, STR_024A_OIL_WELLS,STR_CONSTRUCT_OIL_WELLS_TIP}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 94+3, 105+3, STR_0255_DIAMOND_MINE,STR_CONSTRUCT_DIAMOND_MINE_TIP}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 107+3, 118+3, STR_0256_COPPER_ORE_MINE,STR_CONSTRUCT_COPPER_ORE_MINE_TIP}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 120+3, 131+3, STR_0248_FARM,STR_CONSTRUCT_FARM_TIP}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 133+3, 144+3, STR_0251_FRUIT_PLANTATION,STR_CONSTRUCT_FRUIT_PLANTATION_TIP}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 146+3, 157+3, STR_0252_RUBBER_PLANTATION,STR_CONSTRUCT_RUBBER_PLANTATION_TIP}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 159+3, 170+3, STR_0253_WATER_SUPPLY,STR_CONSTRUCT_WATER_SUPPLY_TIP}, truelight@0: { WWT_LAST}, truelight@0: }; truelight@0: truelight@0: static const Widget _build_industry_land3_widgets_extra[] = { truelight@0: { WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5,STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY,STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@0: { WWT_PANEL, 7, 0, 169, 14, 187, 0x0,0}, truelight@0: truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 16, 27, STR_0258_CANDY_FACTORY,STR_027B_CONSTRUCT_CANDY_FACTORY}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 29, 40, STR_025B_TOY_SHOP,STR_027E_CONSTRUCT_TOY_SHOP}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 42, 53, STR_025C_TOY_FACTORY,STR_027F_CONSTRUCT_TOY_FACTORY}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 55, 66, STR_025E_FIZZY_DRINK_FACTORY,STR_0281_CONSTRUCT_FIZZY_DRINK_FACTORY}, truelight@0: truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 68+3, 79+3, STR_0257_COTTON_CANDY_FOREST,STR_CONSTRUCT_COTTON_CANDY_TIP}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 81+3, 92+3, STR_0259_BATTERY_FARM,STR_CONSTRUCT_BATTERY_FARM_TIP}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 94+3, 105+3, STR_025A_COLA_WELLS,STR_CONSTRUCT_COLA_WELLS_TIP}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 107+3, 118+3, STR_025D_PLASTIC_FOUNTAINS,STR_CONSTRUCT_PLASTIC_FOUNTAINS_TIP}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 120+3, 131+3, STR_025F_BUBBLE_GENERATOR,STR_CONSTRUCT_BUBBLE_GENERATOR_TIP}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 133+3, 144+3, STR_0260_TOFFEE_QUARRY,STR_CONSTRUCT_TOFFEE_QUARRY_TIP}, truelight@0: { WWT_CLOSEBOX, 14, 2, 167, 146+3, 157+3, STR_0261_SUGAR_MINE,STR_CONSTRUCT_SUGAR_MINE_TIP}, truelight@0: { WWT_LAST}, truelight@0: }; truelight@0: truelight@0: truelight@0: static const WindowDesc _build_industry_land0_desc = { truelight@0: -1, -1, 170, 116, truelight@0: WC_BUILD_INDUSTRY,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _build_industry_land0_widgets, truelight@0: BuildIndustryWndProc truelight@0: }; truelight@0: truelight@0: static const WindowDesc _build_industry_land1_desc = { truelight@0: -1, -1, 170, 116, truelight@0: WC_BUILD_INDUSTRY,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _build_industry_land1_widgets, truelight@0: BuildIndustryWndProc truelight@0: }; truelight@0: truelight@0: static const WindowDesc _build_industry_land2_desc = { truelight@0: -1, -1, 170, 116, truelight@0: WC_BUILD_INDUSTRY,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _build_industry_land2_widgets, truelight@0: BuildIndustryWndProc truelight@0: }; truelight@0: truelight@0: static const WindowDesc _build_industry_land3_desc = { truelight@0: -1, -1, 170, 116, truelight@0: WC_BUILD_INDUSTRY,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _build_industry_land3_widgets, truelight@0: BuildIndustryWndProc truelight@0: }; truelight@0: truelight@0: static const WindowDesc _build_industry_land0_desc_extra = { truelight@0: -1, -1, 170, 188, truelight@0: WC_BUILD_INDUSTRY,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _build_industry_land0_widgets_extra, truelight@0: BuildIndustryWndProc truelight@0: }; truelight@0: truelight@0: static const WindowDesc _build_industry_land1_desc_extra = { truelight@0: -1, -1, 170, 175, truelight@0: WC_BUILD_INDUSTRY,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _build_industry_land1_widgets_extra, truelight@0: BuildIndustryWndProc truelight@0: }; truelight@0: truelight@0: static const WindowDesc _build_industry_land2_desc_extra = { truelight@0: -1, -1, 170, 201, truelight@0: WC_BUILD_INDUSTRY,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _build_industry_land2_widgets_extra, truelight@0: BuildIndustryWndProc truelight@0: }; truelight@0: truelight@0: static const WindowDesc _build_industry_land3_desc_extra = { truelight@0: -1, -1, 170, 188, truelight@0: WC_BUILD_INDUSTRY,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _build_industry_land3_widgets_extra, truelight@0: BuildIndustryWndProc truelight@0: }; truelight@0: truelight@0: static const WindowDesc * const _industry_window_desc[2][4] = { truelight@0: { truelight@0: &_build_industry_land0_desc, truelight@0: &_build_industry_land1_desc, truelight@0: &_build_industry_land2_desc, truelight@0: &_build_industry_land3_desc, truelight@0: }, truelight@0: { truelight@0: &_build_industry_land0_desc_extra, truelight@0: &_build_industry_land1_desc_extra, truelight@0: &_build_industry_land2_desc_extra, truelight@0: &_build_industry_land3_desc_extra, truelight@0: }, truelight@0: }; truelight@0: truelight@0: void ShowBuildIndustryWindow() truelight@0: { truelight@0: AllocateWindowDescFront(_industry_window_desc[_patches.build_rawmaterial_ind][_opt.landscape],0); truelight@0: } truelight@0: truelight@0: static void IndustryViewWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: Industry *i; truelight@0: StringID str; truelight@0: truelight@0: switch(e->event) { truelight@0: case WE_PAINT: truelight@0: // in editor, use bulldoze to destroy industry truelight@0: // Destroy Industry button costing money removed per request of dominik truelight@0: //w->disabled_state = (_patches.extra_dynamite && !_networking && _game_mode != GM_EDITOR) ? 0 : (1 << 6); truelight@0: i = DEREF_INDUSTRY(w->window_number); truelight@0: SET_DPARAM16(0, i->town->index); truelight@0: SET_DPARAM16(1, i->type + STR_4802_COAL_MINE); truelight@0: DrawWindowWidgets(w); truelight@0: truelight@0: if (i->accepts_cargo[0] != 0xFF) { truelight@0: SET_DPARAM16(0, _cargoc.names_s[i->accepts_cargo[0]]); truelight@0: str = STR_4827_REQUIRES; truelight@0: if (i->accepts_cargo[1] != 0xFF) { truelight@0: SET_DPARAM16(1, _cargoc.names_s[i->accepts_cargo[1]]); truelight@0: str++; truelight@0: if (i->accepts_cargo[2] != 0xFF) { truelight@0: SET_DPARAM16(2, _cargoc.names_s[i->accepts_cargo[2]]); truelight@0: str++; truelight@0: } truelight@0: } truelight@0: DrawString(2, 107, str, 0); truelight@0: } truelight@0: truelight@0: if (i->produced_cargo[0] != 0xFF) { truelight@0: DrawString(2, 117, STR_482A_PRODUCTION_LAST_MONTH, 0); truelight@0: truelight@0: SET_DPARAM16(1, i->total_production[0]); truelight@0: SET_DPARAM16(0, _cargoc.names_long_s[i->produced_cargo[0]] + ((i->total_production[0]!=1)<<5)); truelight@0: SET_DPARAM16(2, i->pct_transported[0] * 100 >> 8); truelight@0: DrawString(4, 127, STR_482B_TRANSPORTED, 0); truelight@0: truelight@0: if (i->produced_cargo[1] != 0xFF) { truelight@0: SET_DPARAM16(1, i->total_production[1]); truelight@0: SET_DPARAM16(0, _cargoc.names_long_s[i->produced_cargo[1]] + ((i->total_production[1]!=1)<<5)); truelight@0: SET_DPARAM16(2, i->pct_transported[1] * 100 >> 8); truelight@0: DrawString(4, 137, STR_482B_TRANSPORTED, 0); truelight@0: } truelight@0: } truelight@0: truelight@0: DrawWindowViewport(w); truelight@0: break; truelight@0: truelight@0: case WE_CLICK: truelight@0: switch(e->click.widget) { truelight@0: case 5: truelight@0: i = DEREF_INDUSTRY(w->window_number); truelight@0: ScrollMainWindowToTile(i->xy + TILE_XY(1,1)); truelight@0: break; truelight@0: case 6: truelight@0: // Destroy Industry button costing money removed per request of dominik truelight@0: //i = DEREF_INDUSTRY(w->window_number); truelight@0: /* passing only i->xy is not safe if industry has a weird shape like: truelight@0: _ X X truelight@0: X X X truelight@0: _ <--- grass, no industry, but i->xy points there (first top-left tile)!, truelight@0: so passing i->xy to destroy industry will fail in called procedure truelight@0: */ truelight@0: //DoCommandP(i->xy, w->window_number, 0, CcPlaySound10, CMD_DESTROY_INDUSTRY | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA)); truelight@0: break; truelight@0: } truelight@0: break; truelight@0: } truelight@0: } truelight@0: truelight@0: static const Widget _industry_view_widgets[] = { truelight@0: { WWT_TEXTBTN, 9, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 9, 11, 259, 0, 13, STR_4801, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@0: { WWT_IMGBTN, 9, 0, 259, 14, 105, 0x0}, truelight@0: { WWT_6, 9, 2, 257, 16, 103, 0x0}, truelight@0: { WWT_IMGBTN, 9, 0, 259, 106, 147, 0x0}, truelight@0: { WWT_PUSHTXTBTN, 9, 0, 129, 148, 159, STR_00E4_LOCATION, STR_482C_CENTER_THE_MAIN_VIEW_ON}, truelight@0: { WWT_IMGBTN, 9, 130, 259, 148, 159, 0x0, 0}, truelight@0: // Destroy Industry button costing money removed per request of dominik truelight@0: //{ WWT_PUSHTXTBTN, 9, 130, 259, 148, 159, STR_INDUSTRYDIR_DESTROY, STR_482C_DESTROY_INDUSTRY}, truelight@0: { WWT_LAST}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _industry_view_desc = { truelight@0: -1, -1, 260, 160, truelight@0: WC_INDUSTRY_VIEW,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, truelight@0: _industry_view_widgets, truelight@0: IndustryViewWndProc truelight@0: }; truelight@0: truelight@0: void ShowIndustryViewWindow(int industry) truelight@0: { truelight@0: Window *w; truelight@0: Industry *i; truelight@0: truelight@0: w = AllocateWindowDescFront(&_industry_view_desc, industry); truelight@0: if (w) { truelight@0: w->flags4 |= WF_DISABLE_VP_SCROLL; truelight@0: i = DEREF_INDUSTRY(w->window_number); truelight@0: AssignWindowViewport(w, 3, 17, 0xFE, 0x56, i->xy + TILE_XY(1,1), 1); truelight@0: } truelight@0: } truelight@0: truelight@0: static const Widget _industry_directory_widgets[] = { truelight@0: { WWT_TEXTBTN, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 13, 11, 507, 0, 13, STR_INDUSTRYDIR_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@0: { WWT_PUSHTXTBTN, 13, 0, 100, 14, 25, STR_SORT_BY_NAME, STR_SORT_TIP}, truelight@0: { WWT_PUSHTXTBTN, 13, 101, 200, 14, 25, STR_SORT_BY_TYPE, STR_SORT_TIP}, truelight@0: { WWT_PUSHTXTBTN, 13, 201, 300, 14, 25, STR_SORT_BY_PRODUCTION, STR_SORT_TIP}, truelight@0: { WWT_PUSHTXTBTN, 13, 301, 400, 14, 25, STR_SORT_BY_TRANSPORTED, STR_SORT_TIP}, truelight@0: { WWT_PANEL, 13, 401, 496, 14, 25, 0x0, 0}, truelight@0: { WWT_IMGBTN, 13, 0, 496, 26, 189, 0x0, STR_200A_TOWN_NAMES_CLICK_ON_NAME}, truelight@0: { WWT_SCROLLBAR, 13, 497, 507, 14, 189, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, truelight@0: { WWT_LAST}, truelight@0: }; truelight@0: truelight@0: static byte _industry_sort[lengthof(_industries)]; truelight@0: static uint _num_industry_sort; truelight@0: truelight@0: static char _bufcache[96]; truelight@0: static byte _last_industry_idx; truelight@0: truelight@0: static byte _industry_sort_order; truelight@0: truelight@0: static int CDECL IndustrySorter(const void *a, const void *b) truelight@0: { truelight@0: char buf1[96]; truelight@0: Industry *i, *j; truelight@0: byte val; truelight@0: int r = 0; truelight@0: truelight@0: i = DEREF_INDUSTRY(*(byte*)a); truelight@0: j = DEREF_INDUSTRY(*(byte*)b); truelight@0: truelight@0: switch (_industry_sort_order >> 1) { truelight@0: case 0: truelight@0: r = 0; truelight@0: break; truelight@0: case 1: /* Case 1, sort by type */ truelight@0: r = i->type - j->type; truelight@0: break; truelight@0: case 2: /* Case 2, sort by production */ truelight@0: if (i->produced_cargo[0] != 0xFF && j->produced_cargo[0] != 0xFF) { //producing any cargo? truelight@0: if (i->produced_cargo[1] == 0xFF) //producing one or two things? truelight@0: r = j->total_production[0] - i->total_production[0]; truelight@0: else truelight@0: r = (j->total_production[0] + j->total_production[1]) / 2 - (i->total_production[0] + i->total_production[1]) / 2; truelight@0: } else if (i->produced_cargo[0] == 0xFF && j->produced_cargo[0] == 0xFF) //None of them producing anything, let them go to the name-sorting truelight@0: r = 0; truelight@0: else if (i->produced_cargo[0] == 0xFF) //Non-producers, end up last/first in list truelight@0: r = 1; truelight@0: else truelight@0: r = -1; truelight@0: break; truelight@0: case 3: /* Case 3, sort by transportation */ truelight@0: if (i->produced_cargo[0] != 0xFF && j->produced_cargo[0] != 0xFF) { //producing any cargo? truelight@0: if (i->produced_cargo[1] == 0xFF) //producing one or two things? truelight@0: r = (j->pct_transported[0] * 100 >> 8) - (i->pct_transported[0] * 100 >> 8); truelight@0: else truelight@0: r = ((j->pct_transported[0] * 100 >> 8) + (j->pct_transported[1] * 100 >> 8)) / 2 - ((i->pct_transported[0] * 100 >> 8) + (i->pct_transported[1] * 100 >> 8)) / 2; truelight@0: } else if (i->produced_cargo[0] == 0xFF && j->produced_cargo[0] == 0xFF) //None of them producing anything, let them go to the name-sorting truelight@0: r = 0; truelight@0: else if (i->produced_cargo[0] == 0xFF) //Non-producers, end up last/first in list truelight@0: r = 1; truelight@0: else truelight@0: r = -1; truelight@0: break; truelight@0: } truelight@0: truelight@0: // default to string sorting if they are otherwise equal truelight@0: if (r == 0) { truelight@0: SET_DPARAM32(0, i->town->townnameparts); truelight@0: GetString(buf1, i->town->townnametype); truelight@0: truelight@0: if ( (val=*(byte*)b) != _last_industry_idx) { truelight@0: _last_industry_idx = val; truelight@0: SET_DPARAM32(0, j->town->townnameparts); truelight@0: GetString(_bufcache, j->town->townnametype); truelight@0: } truelight@0: r = strcmp(buf1, _bufcache); truelight@0: } truelight@0: truelight@0: if (_industry_sort_order & 1) truelight@0: r = -r; truelight@0: truelight@0: return r; truelight@0: } truelight@0: truelight@0: static void MakeSortedIndustryList() truelight@0: { truelight@0: Industry *i; truelight@0: int n = 0, index = 0; truelight@0: truelight@0: for(i=_industries; i != endof(_industries); i++) { truelight@0: if(i->xy) _industry_sort[n++] = index; truelight@0: index++; truelight@0: } truelight@0: _num_industry_sort = n; truelight@0: _last_industry_idx = 255; // used for "cache" truelight@0: truelight@0: qsort(_industry_sort, n, 1, IndustrySorter); truelight@0: } truelight@0: truelight@0: truelight@0: static void IndustryDirectoryWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: { truelight@0: int n; truelight@0: uint p; truelight@0: Industry *i; truelight@0: static const uint16 _indicator_positions[4] = {88, 187, 284, 387}; truelight@0: truelight@0: if (_industry_sort_dirty) { truelight@0: _industry_sort_dirty = false; truelight@0: MakeSortedIndustryList(); truelight@0: } truelight@0: truelight@0: w->vscroll.count = _num_industry_sort; truelight@0: truelight@0: DrawWindowWidgets(w); truelight@0: DoDrawString(_industry_sort_order & 1 ? "\xAA" : "\xA0", _indicator_positions[_industry_sort_order>>1], 15, 0x10); truelight@0: truelight@0: p = w->vscroll.pos; truelight@0: n = 0; truelight@0: truelight@0: while (p < _num_industry_sort) { truelight@0: i = DEREF_INDUSTRY(_industry_sort[p]); truelight@0: SET_DPARAM16(0, i->town->index); truelight@0: SET_DPARAM16(1, i->type + STR_4802_COAL_MINE); truelight@0: if (i->produced_cargo[0] != 0xFF) { truelight@0: SET_DPARAM16(3, i->total_production[0] * 100 >> 8); truelight@0: SET_DPARAM16(2, _cargoc.names_long_s[i->produced_cargo[0]] + ((i->total_production[0]!=1)<<5)); truelight@0: truelight@0: if (i->produced_cargo[1] != 0xFF) { truelight@0: SET_DPARAM16(5, i->total_production[1] * 100 >> 8); truelight@0: SET_DPARAM16(4, _cargoc.names_long_s[i->produced_cargo[1]] + ((i->total_production[1]!=1)<<5)); truelight@0: SET_DPARAM16(6, i->pct_transported[0] * 100 >> 8); truelight@0: SET_DPARAM16(7, i->pct_transported[1] * 100 >> 8); truelight@0: DrawString(4, 28+n*10, STR_INDUSTRYDIR_ITEM_TWO, 0); truelight@0: } else { truelight@0: SET_DPARAM16(4, i->pct_transported[0] * 100 >> 8); truelight@0: DrawString(4, 28+n*10, STR_INDUSTRYDIR_ITEM, 0); truelight@0: } truelight@0: } else { truelight@0: DrawString(4, 28+n*10, STR_INDUSTRYDIR_ITEM_NOPROD, 0); truelight@0: } truelight@0: p++; truelight@0: if (++n == 16) truelight@0: break; truelight@0: } truelight@0: } break; truelight@0: truelight@0: case WE_CLICK: truelight@0: switch(e->click.widget) { truelight@0: case 2: { truelight@0: _industry_sort_order = _industry_sort_order==0 ? 1 : 0; truelight@0: _industry_sort_dirty = true; truelight@0: SetWindowDirty(w); truelight@0: } break; truelight@0: truelight@0: case 3: { truelight@0: _industry_sort_order = _industry_sort_order==2 ? 3 : 2; truelight@0: _industry_sort_dirty = true; truelight@0: SetWindowDirty(w); truelight@0: } break; truelight@0: truelight@0: case 4: { truelight@0: _industry_sort_order = _industry_sort_order==4 ? 5 : 4; truelight@0: _industry_sort_dirty = true; truelight@0: SetWindowDirty(w); truelight@0: } break; truelight@0: truelight@0: case 5: { truelight@0: _industry_sort_order = _industry_sort_order==6 ? 7 : 6; truelight@0: _industry_sort_dirty = true; truelight@0: SetWindowDirty(w); truelight@0: } break; truelight@0: truelight@0: case 7: { truelight@0: int y = (e->click.pt.y - 28) / 10; truelight@0: byte p; truelight@0: Industry *c; truelight@0: truelight@0: if (!IS_INT_INSIDE(y, 0, 16)) truelight@0: return; truelight@0: p = y + w->vscroll.pos; truelight@0: if (p < _num_industry_sort) { truelight@0: c = DEREF_INDUSTRY(_industry_sort[p]); truelight@0: ScrollMainWindowToTile(c->xy); truelight@0: } truelight@0: } break; truelight@0: } truelight@0: break; truelight@0: truelight@0: case WE_4: truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: } truelight@0: } truelight@0: truelight@0: truelight@0: /* Industry List */ truelight@0: static const WindowDesc _industry_directory_desc = { truelight@0: -1, -1, 508, 190, truelight@0: WC_INDUSTRY_DIRECTORY,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, truelight@0: _industry_directory_widgets, truelight@0: IndustryDirectoryWndProc truelight@0: }; truelight@0: truelight@0: truelight@0: truelight@0: void ShowIndustryDirectory() truelight@0: { truelight@0: /* Industry List */ truelight@0: Window *w; truelight@0: truelight@0: w = AllocateWindowDescFront(&_industry_directory_desc, 0); truelight@0: if (w) { truelight@0: w->vscroll.cap = 16; truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: }