2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2005-02-05 15:58:59 +00:00
|
|
|
#include "debug.h"
|
2005-07-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2005-02-06 08:18:00 +00:00
|
|
|
#include "strings.h"
|
2004-11-25 10:47:30 +00:00
|
|
|
#include "table/strings.h"
|
2005-06-06 13:47:06 +00:00
|
|
|
#include "table/sprites.h"
|
2004-12-15 22:18:54 +00:00
|
|
|
#include "map.h"
|
2005-02-19 14:40:32 +00:00
|
|
|
#include "gui.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "window.h"
|
|
|
|
#include "gfx.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "viewport.h"
|
|
|
|
#include "industry.h"
|
|
|
|
#include "town.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
/* Present in table/build_industry.h" */
|
|
|
|
extern const byte _build_industry_types[4][12];
|
2004-08-09 17:04:08 +00:00
|
|
|
extern const byte _industry_type_costs[37];
|
|
|
|
|
2005-01-14 00:14:13 +00:00
|
|
|
static void UpdateIndustryProduction(Industry *i);
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static void BuildIndustryWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2006-02-01 06:32:03 +00:00
|
|
|
switch (e->event) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_PAINT:
|
|
|
|
DrawWindowWidgets(w);
|
|
|
|
if (_thd.place_mode == 1 && _thd.window_class == WC_BUILD_INDUSTRY) {
|
2005-05-11 00:00:27 +00:00
|
|
|
int ind_type = _build_industry_types[_opt_ptr->landscape][WP(w,def_d).data_1];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-28 21:58:16 +00:00
|
|
|
SetDParam(0, (_price.build_industry >> 5) * GetIndustrySpec(ind_type)->cost_multiplier);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawStringCentered(85, w->height - 21, STR_482F_COST, 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_CLICK: {
|
2006-09-23 02:39:24 +00:00
|
|
|
int wid = e->we.click.widget;
|
2004-08-09 17:04:08 +00:00
|
|
|
if (wid >= 3) {
|
2005-06-06 13:47:06 +00:00
|
|
|
if (HandlePlacePushButton(w, wid, SPR_CURSOR_INDUSTRY, 1, NULL))
|
2004-08-09 17:04:08 +00:00
|
|
|
WP(w,def_d).data_1 = wid - 3;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case WE_PLACE_OBJ:
|
2006-09-23 02:39:24 +00:00
|
|
|
if (DoCommandP(e->we.place.tile, _build_industry_types[_opt_ptr->landscape][WP(w,def_d).data_1], 0, NULL, CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY)))
|
2004-08-09 17:04:08 +00:00
|
|
|
ResetObjectToPlace();
|
|
|
|
break;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_ABORT_PLACE_OBJ:
|
2006-10-03 20:16:20 +00:00
|
|
|
RaiseWindowButtons(w);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _build_industry_land0_widgets[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 7, 0, 169, 14, 115, 0x0, STR_NULL},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 16, 27, STR_0241_POWER_STATION, STR_0263_CONSTRUCT_POWER_STATION},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 29, 40, STR_0242_SAWMILL, STR_0264_CONSTRUCT_SAWMILL},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY, STR_0266_CONSTRUCT_OIL_REFINERY},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 55, 66, STR_0246_FACTORY, STR_0268_CONSTRUCT_FACTORY},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 68, 79, STR_0247_STEEL_MILL, STR_0269_CONSTRUCT_STEEL_MILL},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const Widget _build_industry_land1_widgets[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 7, 0, 169, 14, 115, 0x0, STR_NULL},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 16, 27, STR_0241_POWER_STATION, STR_0263_CONSTRUCT_POWER_STATION},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 29, 40, STR_024C_PAPER_MILL, STR_026E_CONSTRUCT_PAPER_MILL},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY, STR_0266_CONSTRUCT_OIL_REFINERY},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 55, 66, STR_024D_FOOD_PROCESSING_PLANT, STR_026F_CONSTRUCT_FOOD_PROCESSING},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 68, 79, STR_024E_PRINTING_WORKS, STR_0270_CONSTRUCT_PRINTING_WORKS},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const Widget _build_industry_land2_widgets[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 7, 0, 169, 14, 115, 0x0, STR_NULL},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 16, 27, STR_0250_LUMBER_MILL, STR_0273_CONSTRUCT_LUMBER_MILL_TO},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 29, 40, STR_024D_FOOD_PROCESSING_PLANT, STR_026F_CONSTRUCT_FOOD_PROCESSING},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY, STR_0266_CONSTRUCT_OIL_REFINERY},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 55, 66, STR_0246_FACTORY, STR_0268_CONSTRUCT_FACTORY},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 68, 79, STR_0254_WATER_TOWER, STR_0277_CONSTRUCT_WATER_TOWER_CAN},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const Widget _build_industry_land3_widgets[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 7, 0, 169, 14, 115, 0x0, STR_NULL},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 16, 27, STR_0258_CANDY_FACTORY, STR_027B_CONSTRUCT_CANDY_FACTORY},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 29, 40, STR_025B_TOY_SHOP, STR_027E_CONSTRUCT_TOY_SHOP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 42, 53, STR_025C_TOY_FACTORY, STR_027F_CONSTRUCT_TOY_FACTORY},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 55, 66, STR_025E_FIZZY_DRINK_FACTORY, STR_0281_CONSTRUCT_FIZZY_DRINK_FACTORY},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const Widget _build_industry_land0_widgets_extra[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 7, 0, 169, 14, 187, 0x0, STR_NULL},
|
|
|
|
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 16, 27, STR_0241_POWER_STATION, STR_0263_CONSTRUCT_POWER_STATION},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 29, 40, STR_0242_SAWMILL, STR_0264_CONSTRUCT_SAWMILL},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY, STR_0266_CONSTRUCT_OIL_REFINERY},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 55, 66, STR_0246_FACTORY, STR_0268_CONSTRUCT_FACTORY},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 68, 79, STR_0247_STEEL_MILL, STR_0269_CONSTRUCT_STEEL_MILL},
|
|
|
|
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 84, 95, STR_0240_COAL_MINE, STR_CONSTRUCT_COAL_MINE_TIP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 97, 108, STR_0243_FOREST, STR_CONSTRUCT_FOREST_TIP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 110, 121, STR_0245_OIL_RIG, STR_CONSTRUCT_OIL_RIG_TIP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 123, 134, STR_0248_FARM, STR_CONSTRUCT_FARM_TIP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 136, 147, STR_024A_OIL_WELLS, STR_CONSTRUCT_OIL_WELLS_TIP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 149, 160, STR_0249_IRON_ORE_MINE, STR_CONSTRUCT_IRON_ORE_MINE_TIP},
|
2004-09-07 21:48:09 +00:00
|
|
|
|
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const Widget _build_industry_land1_widgets_extra[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 7, 0, 169, 14, 174, 0x0, STR_NULL},
|
|
|
|
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 16, 27, STR_0241_POWER_STATION, STR_0263_CONSTRUCT_POWER_STATION},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 29, 40, STR_024C_PAPER_MILL, STR_026E_CONSTRUCT_PAPER_MILL},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY, STR_0266_CONSTRUCT_OIL_REFINERY},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 55, 66, STR_024D_FOOD_PROCESSING_PLANT, STR_026F_CONSTRUCT_FOOD_PROCESSING},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 68, 79, STR_024E_PRINTING_WORKS, STR_0270_CONSTRUCT_PRINTING_WORKS},
|
|
|
|
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 84, 95, STR_0240_COAL_MINE, STR_CONSTRUCT_COAL_MINE_TIP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 97, 108, STR_0243_FOREST, STR_CONSTRUCT_FOREST_TIP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 110, 121, STR_0248_FARM, STR_CONSTRUCT_FARM_TIP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 123, 134, STR_024A_OIL_WELLS, STR_CONSTRUCT_OIL_WELLS_TIP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 136, 147, STR_024F_GOLD_MINE, STR_CONSTRUCT_GOLD_MINE_TIP},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const Widget _build_industry_land2_widgets_extra[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 7, 0, 169, 14, 200, 0x0, STR_NULL},
|
|
|
|
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 16, 27, STR_0250_LUMBER_MILL, STR_0273_CONSTRUCT_LUMBER_MILL_TO},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 29, 40, STR_024D_FOOD_PROCESSING_PLANT, STR_026F_CONSTRUCT_FOOD_PROCESSING},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY, STR_0266_CONSTRUCT_OIL_REFINERY},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 55, 66, STR_0246_FACTORY, STR_0268_CONSTRUCT_FACTORY},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 68, 79, STR_0254_WATER_TOWER, STR_0277_CONSTRUCT_WATER_TOWER_CAN},
|
|
|
|
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 84, 95, STR_024A_OIL_WELLS, STR_CONSTRUCT_OIL_WELLS_TIP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 97, 108, STR_0255_DIAMOND_MINE, STR_CONSTRUCT_DIAMOND_MINE_TIP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 110, 121, STR_0256_COPPER_ORE_MINE, STR_CONSTRUCT_COPPER_ORE_MINE_TIP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 123, 134, STR_0248_FARM, STR_CONSTRUCT_FARM_TIP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 136, 147, STR_0251_FRUIT_PLANTATION, STR_CONSTRUCT_FRUIT_PLANTATION_TIP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 149, 160, STR_0252_RUBBER_PLANTATION, STR_CONSTRUCT_RUBBER_PLANTATION_TIP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 162, 173, STR_0253_WATER_SUPPLY, STR_CONSTRUCT_WATER_SUPPLY_TIP},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const Widget _build_industry_land3_widgets_extra[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 7, 0, 169, 14, 187, 0x0, STR_NULL},
|
|
|
|
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 16, 27, STR_0258_CANDY_FACTORY, STR_027B_CONSTRUCT_CANDY_FACTORY},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 29, 40, STR_025B_TOY_SHOP, STR_027E_CONSTRUCT_TOY_SHOP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 42, 53, STR_025C_TOY_FACTORY, STR_027F_CONSTRUCT_TOY_FACTORY},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 55, 66, STR_025E_FIZZY_DRINK_FACTORY, STR_0281_CONSTRUCT_FIZZY_DRINK_FACTORY},
|
|
|
|
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 71, 82, STR_0257_COTTON_CANDY_FOREST, STR_CONSTRUCT_COTTON_CANDY_TIP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 84, 95, STR_0259_BATTERY_FARM, STR_CONSTRUCT_BATTERY_FARM_TIP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 97, 108, STR_025A_COLA_WELLS, STR_CONSTRUCT_COLA_WELLS_TIP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 110, 121, STR_025D_PLASTIC_FOUNTAINS, STR_CONSTRUCT_PLASTIC_FOUNTAINS_TIP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 123, 134, STR_025F_BUBBLE_GENERATOR, STR_CONSTRUCT_BUBBLE_GENERATOR_TIP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 136, 147, STR_0260_TOFFEE_QUARRY, STR_CONSTRUCT_TOFFEE_QUARRY_TIP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 149, 160, STR_0261_SUGAR_MINE, STR_CONSTRUCT_SUGAR_MINE_TIP},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const WindowDesc _build_industry_land0_desc = {
|
|
|
|
-1, -1, 170, 116,
|
|
|
|
WC_BUILD_INDUSTRY,0,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
|
|
_build_industry_land0_widgets,
|
|
|
|
BuildIndustryWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _build_industry_land1_desc = {
|
|
|
|
-1, -1, 170, 116,
|
|
|
|
WC_BUILD_INDUSTRY,0,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
|
|
_build_industry_land1_widgets,
|
|
|
|
BuildIndustryWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _build_industry_land2_desc = {
|
|
|
|
-1, -1, 170, 116,
|
|
|
|
WC_BUILD_INDUSTRY,0,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
|
|
_build_industry_land2_widgets,
|
|
|
|
BuildIndustryWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _build_industry_land3_desc = {
|
|
|
|
-1, -1, 170, 116,
|
|
|
|
WC_BUILD_INDUSTRY,0,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
|
|
_build_industry_land3_widgets,
|
|
|
|
BuildIndustryWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _build_industry_land0_desc_extra = {
|
|
|
|
-1, -1, 170, 188,
|
|
|
|
WC_BUILD_INDUSTRY,0,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
|
|
_build_industry_land0_widgets_extra,
|
|
|
|
BuildIndustryWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _build_industry_land1_desc_extra = {
|
|
|
|
-1, -1, 170, 175,
|
|
|
|
WC_BUILD_INDUSTRY,0,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
|
|
_build_industry_land1_widgets_extra,
|
|
|
|
BuildIndustryWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _build_industry_land2_desc_extra = {
|
|
|
|
-1, -1, 170, 201,
|
|
|
|
WC_BUILD_INDUSTRY,0,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
|
|
_build_industry_land2_widgets_extra,
|
|
|
|
BuildIndustryWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _build_industry_land3_desc_extra = {
|
|
|
|
-1, -1, 170, 188,
|
|
|
|
WC_BUILD_INDUSTRY,0,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
|
|
_build_industry_land3_widgets_extra,
|
|
|
|
BuildIndustryWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc * const _industry_window_desc[2][4] = {
|
|
|
|
{
|
|
|
|
&_build_industry_land0_desc,
|
|
|
|
&_build_industry_land1_desc,
|
|
|
|
&_build_industry_land2_desc,
|
|
|
|
&_build_industry_land3_desc,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
&_build_industry_land0_desc_extra,
|
|
|
|
&_build_industry_land1_desc_extra,
|
|
|
|
&_build_industry_land2_desc_extra,
|
|
|
|
&_build_industry_land3_desc_extra,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void ShowBuildIndustryWindow(void)
|
2004-09-10 19:02:27 +00:00
|
|
|
{
|
2006-10-14 15:49:43 +00:00
|
|
|
if (_current_player == PLAYER_SPECTATOR) return;
|
2005-05-11 00:00:27 +00:00
|
|
|
AllocateWindowDescFront(_industry_window_desc[_patches.build_rawmaterial_ind][_opt_ptr->landscape],0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-08-02 18:36:53 +00:00
|
|
|
static inline bool isProductionMinimum(const Industry *i, int pt) {
|
|
|
|
return i->production_rate[pt] == 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool isProductionMaximum(const Industry *i, int pt) {
|
|
|
|
return i->production_rate[pt] == 255;
|
|
|
|
}
|
|
|
|
|
2006-07-30 14:56:40 +00:00
|
|
|
static inline bool IsProductionAlterable(const Industry *i)
|
|
|
|
{
|
|
|
|
return ((_game_mode == GM_EDITOR || _cheats.setup_prod.value) &&
|
|
|
|
(i->accepts_cargo[0] == CT_INVALID || i->accepts_cargo[0] == CT_VALUABLES));
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static void IndustryViewWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2005-01-14 00:14:13 +00:00
|
|
|
// WP(w,vp2_d).data_1 is for the editbox line
|
|
|
|
// WP(w,vp2_d).data_2 is for the clickline
|
|
|
|
// WP(w,vp2_d).data_3 is for the click pos (left or right)
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-01 06:32:03 +00:00
|
|
|
switch (e->event) {
|
2005-01-14 00:14:13 +00:00
|
|
|
case WE_PAINT: {
|
2006-07-26 03:33:12 +00:00
|
|
|
const Industry *i = GetIndustry(w->window_number);
|
2005-10-26 07:12:14 +00:00
|
|
|
|
2005-07-15 18:30:13 +00:00
|
|
|
SetDParam(0, w->window_number);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
2005-01-14 00:14:13 +00:00
|
|
|
if (i->accepts_cargo[0] != CT_INVALID) {
|
2006-02-06 09:18:04 +00:00
|
|
|
StringID str;
|
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, _cargoc.names_s[i->accepts_cargo[0]]);
|
2004-08-09 17:04:08 +00:00
|
|
|
str = STR_4827_REQUIRES;
|
2005-01-14 00:14:13 +00:00
|
|
|
if (i->accepts_cargo[1] != CT_INVALID) {
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(1, _cargoc.names_s[i->accepts_cargo[1]]);
|
2006-02-06 09:18:04 +00:00
|
|
|
str = STR_4828_REQUIRES;
|
2005-01-14 00:14:13 +00:00
|
|
|
if (i->accepts_cargo[2] != CT_INVALID) {
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(2, _cargoc.names_s[i->accepts_cargo[2]]);
|
2006-02-06 09:18:04 +00:00
|
|
|
str = STR_4829_REQUIRES;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
DrawString(2, 107, str, 0);
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-14 00:14:13 +00:00
|
|
|
if (i->produced_cargo[0] != CT_INVALID) {
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawString(2, 117, STR_482A_PRODUCTION_LAST_MONTH, 0);
|
|
|
|
|
2005-07-16 20:58:04 +00:00
|
|
|
SetDParam(0, _cargoc.names_long[i->produced_cargo[0]]);
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(1, i->total_production[0]);
|
2005-07-15 14:53:44 +00:00
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(2, i->pct_transported[0] * 100 >> 8);
|
2006-07-30 14:56:40 +00:00
|
|
|
DrawString(4 + (IsProductionAlterable(i) ? 30 : 0), 127, STR_482B_TRANSPORTED, 0);
|
2005-01-14 00:14:13 +00:00
|
|
|
// Let's put out those buttons..
|
2006-08-02 18:36:53 +00:00
|
|
|
if (IsProductionAlterable(i)) {
|
|
|
|
DrawArrowButtons(5, 127, 3, (WP(w,vp2_d).data_2 == 1) ? WP(w,vp2_d).data_3 : 0,
|
|
|
|
!isProductionMinimum(i, 0), !isProductionMaximum(i, 0));
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-14 00:14:13 +00:00
|
|
|
if (i->produced_cargo[1] != CT_INVALID) {
|
2005-07-16 20:58:04 +00:00
|
|
|
SetDParam(0, _cargoc.names_long[i->produced_cargo[1]]);
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(1, i->total_production[1]);
|
|
|
|
SetDParam(2, i->pct_transported[1] * 100 >> 8);
|
2006-07-30 14:56:40 +00:00
|
|
|
DrawString(4 + (IsProductionAlterable(i) ? 30 : 0), 137, STR_482B_TRANSPORTED, 0);
|
2005-01-14 00:14:13 +00:00
|
|
|
// Let's put out those buttons..
|
2006-08-02 18:36:53 +00:00
|
|
|
if (IsProductionAlterable(i)) {
|
|
|
|
DrawArrowButtons(5, 137, 3, (WP(w,vp2_d).data_2 == 2) ? WP(w,vp2_d).data_3 : 0,
|
|
|
|
!isProductionMinimum(i, 1), !isProductionMaximum(i, 1));
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawWindowViewport(w);
|
2005-01-14 00:14:13 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
2005-01-14 00:14:13 +00:00
|
|
|
case WE_CLICK: {
|
|
|
|
Industry *i;
|
|
|
|
|
2006-09-23 02:39:24 +00:00
|
|
|
switch (e->we.click.widget) {
|
2005-01-14 00:14:13 +00:00
|
|
|
case 5: {
|
2006-07-30 14:55:25 +00:00
|
|
|
int line, x;
|
2005-01-14 00:14:13 +00:00
|
|
|
|
|
|
|
i = GetIndustry(w->window_number);
|
|
|
|
|
2005-01-26 10:52:23 +00:00
|
|
|
// We should work if needed..
|
2006-07-30 14:56:40 +00:00
|
|
|
if (!IsProductionAlterable(i)) return;
|
2005-01-14 00:14:13 +00:00
|
|
|
|
2006-09-23 02:39:24 +00:00
|
|
|
x = e->we.click.pt.x;
|
|
|
|
line = (e->we.click.pt.y - 127) / 10;
|
|
|
|
if (e->we.click.pt.y >= 127 && IS_INT_INSIDE(line, 0, 2) && i->produced_cargo[line] != CT_INVALID) {
|
2005-01-15 08:58:31 +00:00
|
|
|
if (IS_INT_INSIDE(x, 5, 25) ) {
|
2006-07-30 14:55:25 +00:00
|
|
|
/* Clicked buttons, decrease or increase production */
|
2005-01-15 08:58:31 +00:00
|
|
|
if (x < 15) {
|
2006-08-02 18:36:53 +00:00
|
|
|
if (isProductionMinimum(i, line)) return;
|
2006-07-30 14:55:25 +00:00
|
|
|
i->production_rate[line] = maxu(i->production_rate[line] / 2, 1);
|
2005-01-14 00:14:13 +00:00
|
|
|
} else {
|
2006-08-02 18:36:53 +00:00
|
|
|
if (isProductionMaximum(i, line)) return;
|
2006-07-30 14:55:25 +00:00
|
|
|
i->production_rate[line] = minu(i->production_rate[line] * 2, 255);
|
2005-01-14 00:14:13 +00:00
|
|
|
}
|
2006-07-30 14:55:25 +00:00
|
|
|
|
2005-01-14 00:14:13 +00:00
|
|
|
UpdateIndustryProduction(i);
|
|
|
|
SetWindowDirty(w);
|
|
|
|
w->flags4 |= 5 << WF_TIMEOUT_SHL;
|
|
|
|
WP(w,vp2_d).data_2 = line+1;
|
|
|
|
WP(w,vp2_d).data_3 = (x < 15 ? 1 : 2);
|
|
|
|
} else if (IS_INT_INSIDE(x, 34, 160)) {
|
|
|
|
// clicked the text
|
|
|
|
WP(w,vp2_d).data_1 = line;
|
|
|
|
SetDParam(0, i->production_rate[line] * 8);
|
2005-01-15 08:58:31 +00:00
|
|
|
ShowQueryString(STR_CONFIG_PATCHES_INT32,
|
|
|
|
STR_CONFIG_GAME_PRODUCTION,
|
|
|
|
10, 100, w->window_class,
|
2006-08-19 09:31:22 +00:00
|
|
|
w->window_number, CS_ALPHANUMERAL);
|
2005-01-14 00:14:13 +00:00
|
|
|
}
|
2005-01-15 08:58:31 +00:00
|
|
|
}
|
2006-07-30 14:55:25 +00:00
|
|
|
} break;
|
2004-12-22 01:32:30 +00:00
|
|
|
case 6:
|
2005-01-06 22:31:58 +00:00
|
|
|
i = GetIndustry(w->window_number);
|
2005-06-25 16:44:57 +00:00
|
|
|
ScrollMainWindowToTile(i->xy + TileDiffXY(1, 1));
|
2006-07-30 14:55:25 +00:00
|
|
|
} break;
|
|
|
|
|
2005-01-14 00:14:13 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WE_TIMEOUT:
|
|
|
|
WP(w,vp2_d).data_2 = 0;
|
|
|
|
WP(w,vp2_d).data_3 = 0;
|
|
|
|
SetWindowDirty(w);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2005-01-14 00:14:13 +00:00
|
|
|
|
|
|
|
case WE_ON_EDIT_TEXT:
|
2006-09-23 02:39:24 +00:00
|
|
|
if (e->we.edittext.str[0] != '\0') {
|
2006-02-13 21:15:00 +00:00
|
|
|
Industry* i = GetIndustry(w->window_number);
|
|
|
|
int line = WP(w,vp2_d).data_1;
|
2005-01-14 00:14:13 +00:00
|
|
|
|
2006-09-23 02:39:24 +00:00
|
|
|
i->production_rate[line] = clampu(atoi(e->we.edittext.str), 0, 255);
|
2005-01-14 00:14:13 +00:00
|
|
|
UpdateIndustryProduction(i);
|
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-14 00:14:13 +00:00
|
|
|
static void UpdateIndustryProduction(Industry *i)
|
|
|
|
{
|
|
|
|
if (i->produced_cargo[0] != CT_INVALID)
|
|
|
|
i->total_production[0] = 8 * i->production_rate[0];
|
|
|
|
|
|
|
|
if (i->produced_cargo[1] != CT_INVALID)
|
|
|
|
i->total_production[1] = 8 * i->production_rate[1];
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static const Widget _industry_view_widgets[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 9, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 9, 11, 247, 0, 13, STR_4801, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_STICKYBOX, RESIZE_NONE, 9, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON},
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 9, 0, 259, 14, 105, 0x0, STR_NULL},
|
|
|
|
{ WWT_6, RESIZE_NONE, 9, 2, 257, 16, 103, 0x0, STR_NULL},
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 9, 0, 259, 106, 147, 0x0, STR_NULL},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 9, 0, 129, 148, 159, STR_00E4_LOCATION, STR_482C_CENTER_THE_MAIN_VIEW_ON},
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 9, 130, 259, 148, 159, 0x0, STR_NULL},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _industry_view_desc = {
|
|
|
|
-1, -1, 260, 160,
|
|
|
|
WC_INDUSTRY_VIEW,0,
|
2004-12-22 01:32:30 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
|
2004-08-09 17:04:08 +00:00
|
|
|
_industry_view_widgets,
|
|
|
|
IndustryViewWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
void ShowIndustryViewWindow(int industry)
|
|
|
|
{
|
2006-07-26 03:33:12 +00:00
|
|
|
Window *w = AllocateWindowDescFront(&_industry_view_desc, industry);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-06 09:18:04 +00:00
|
|
|
if (w != NULL) {
|
2004-08-09 17:04:08 +00:00
|
|
|
w->flags4 |= WF_DISABLE_VP_SCROLL;
|
2005-01-14 00:14:13 +00:00
|
|
|
WP(w,vp2_d).data_1 = 0;
|
|
|
|
WP(w,vp2_d).data_2 = 0;
|
|
|
|
WP(w,vp2_d).data_3 = 0;
|
2006-02-06 09:18:04 +00:00
|
|
|
AssignWindowViewport(w, 3, 17, 0xFE, 0x56, GetIndustry(w->window_number)->xy + TileDiffXY(1, 1), 1);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _industry_directory_widgets[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 13, 11, 495, 0, 13, STR_INDUSTRYDIR_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_STICKYBOX, RESIZE_NONE, 13, 496, 507, 0, 13, 0x0, STR_STICKY_BUTTON},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 0, 100, 14, 25, STR_SORT_BY_NAME, STR_SORT_ORDER_TIP},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 101, 200, 14, 25, STR_SORT_BY_TYPE, STR_SORT_ORDER_TIP},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 201, 300, 14, 25, STR_SORT_BY_PRODUCTION, STR_SORT_ORDER_TIP},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 301, 400, 14, 25, STR_SORT_BY_TRANSPORTED, STR_SORT_ORDER_TIP},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 13, 401, 495, 14, 25, 0x0, STR_NULL},
|
|
|
|
{ WWT_IMGBTN, RESIZE_BOTTOM, 13, 0, 495, 26, 189, 0x0, STR_200A_TOWN_NAMES_CLICK_ON_NAME},
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_BOTTOM, 13, 496, 507, 14, 177, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_TB, 13, 496, 507, 178, 189, 0x0, STR_RESIZE_BUTTON},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static uint _num_industry_sort;
|
|
|
|
|
|
|
|
static char _bufcache[96];
|
2006-08-15 07:07:17 +00:00
|
|
|
static const Industry* _last_industry;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
static byte _industry_sort_order;
|
|
|
|
|
2004-09-06 18:15:13 +00:00
|
|
|
static int CDECL GeneralIndustrySorter(const void *a, const void *b)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-08-15 07:07:17 +00:00
|
|
|
const Industry* i = *(const Industry**)a;
|
|
|
|
const Industry* j = *(const Industry**)b;
|
2006-08-15 13:31:43 +00:00
|
|
|
int r;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
switch (_industry_sort_order >> 1) {
|
2006-08-15 13:31:43 +00:00
|
|
|
default: NOT_REACHED();
|
|
|
|
case 0: /* Sort by Name (handled later) */
|
2004-08-09 17:04:08 +00:00
|
|
|
r = 0;
|
2006-08-15 13:31:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: /* Sort by Type */
|
|
|
|
r = i->type - j->type;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: /* Sort by Production */
|
|
|
|
if (i->produced_cargo[0] == CT_INVALID) {
|
|
|
|
r = (j->produced_cargo[0] == CT_INVALID ? 0 : -1);
|
|
|
|
} else {
|
|
|
|
if (j->produced_cargo[0] == CT_INVALID) {
|
|
|
|
r = 1;
|
|
|
|
} else {
|
|
|
|
r =
|
|
|
|
(i->total_production[0] + i->total_production[1]) -
|
|
|
|
(j->total_production[0] + j->total_production[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3: /* Sort by transported fraction */
|
|
|
|
if (i->produced_cargo[0] == CT_INVALID) {
|
|
|
|
r = (j->produced_cargo[0] == CT_INVALID ? 0 : -1);
|
|
|
|
} else {
|
|
|
|
if (j->produced_cargo[0] == CT_INVALID) {
|
|
|
|
r = 1;
|
|
|
|
} else {
|
|
|
|
int pi;
|
|
|
|
int pj;
|
|
|
|
|
|
|
|
pi = i->pct_transported[0] * 100 >> 8;
|
|
|
|
if (i->produced_cargo[1] != CT_INVALID) {
|
|
|
|
int p = i->pct_transported[1] * 100 >> 8;
|
|
|
|
if (p < pi) pi = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
pj = j->pct_transported[0] * 100 >> 8;
|
|
|
|
if (j->produced_cargo[1] != CT_INVALID) {
|
|
|
|
int p = j->pct_transported[1] * 100 >> 8;
|
|
|
|
if (p < pj) pj = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = pi - pj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// default to string sorting if they are otherwise equal
|
|
|
|
if (r == 0) {
|
2006-08-15 13:31:43 +00:00
|
|
|
char buf1[96];
|
|
|
|
|
2005-07-15 18:30:13 +00:00
|
|
|
SetDParam(0, i->town->index);
|
|
|
|
GetString(buf1, STR_TOWN);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-15 07:07:17 +00:00
|
|
|
if (j != _last_industry) {
|
|
|
|
_last_industry = j;
|
2005-07-15 18:30:13 +00:00
|
|
|
SetDParam(0, j->town->index);
|
|
|
|
GetString(_bufcache, STR_TOWN);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
r = strcmp(buf1, _bufcache);
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
|
|
|
if (_industry_sort_order & 1) r = -r;
|
2004-08-09 17:04:08 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static void MakeSortedIndustryList(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-08-15 07:07:17 +00:00
|
|
|
const Industry* i;
|
2005-01-06 22:31:58 +00:00
|
|
|
int n = 0;
|
|
|
|
|
2006-09-18 06:34:37 +00:00
|
|
|
/* Don't attempt a sort if there are no industries */
|
|
|
|
if (GetIndustryArraySize() == 0) return;
|
|
|
|
|
2005-01-06 22:31:58 +00:00
|
|
|
/* Create array for sorting */
|
2006-08-22 20:41:26 +00:00
|
|
|
_industry_sort = realloc((void *)_industry_sort, GetIndustryArraySize() * sizeof(_industry_sort[0]));
|
2005-01-06 22:31:58 +00:00
|
|
|
if (_industry_sort == NULL)
|
|
|
|
error("Could not allocate memory for the industry-sorting-list");
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-22 15:33:35 +00:00
|
|
|
FOR_ALL_INDUSTRIES(i) _industry_sort[n++] = i;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
_num_industry_sort = n;
|
2006-08-15 07:07:17 +00:00
|
|
|
_last_industry = NULL; // used for "cache"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-15 07:07:17 +00:00
|
|
|
qsort((void*)_industry_sort, n, sizeof(_industry_sort[0]), GeneralIndustrySorter);
|
2004-08-16 14:48:35 +00:00
|
|
|
|
2004-08-16 22:15:44 +00:00
|
|
|
DEBUG(misc, 1) ("Resorting Industries list...");
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void IndustryDirectoryWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2006-02-01 06:32:03 +00:00
|
|
|
switch (e->event) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_PAINT: {
|
|
|
|
int n;
|
|
|
|
uint p;
|
|
|
|
static const uint16 _indicator_positions[4] = {88, 187, 284, 387};
|
|
|
|
|
|
|
|
if (_industry_sort_dirty) {
|
|
|
|
_industry_sort_dirty = false;
|
|
|
|
MakeSortedIndustryList();
|
|
|
|
}
|
|
|
|
|
2005-04-08 23:46:18 +00:00
|
|
|
SetVScrollCount(w, _num_industry_sort);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
DrawWindowWidgets(w);
|
2005-09-10 07:38:03 +00:00
|
|
|
DoDrawString(_industry_sort_order & 1 ? DOWNARROW : UPARROW, _indicator_positions[_industry_sort_order>>1], 15, 0x10);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
p = w->vscroll.pos;
|
|
|
|
n = 0;
|
|
|
|
|
|
|
|
while (p < _num_industry_sort) {
|
2006-08-15 07:07:17 +00:00
|
|
|
const Industry* i = _industry_sort[p];
|
2006-02-06 09:18:04 +00:00
|
|
|
|
2005-07-15 18:30:13 +00:00
|
|
|
SetDParam(0, i->index);
|
2005-09-28 19:35:36 +00:00
|
|
|
if (i->produced_cargo[0] != CT_INVALID) {
|
2005-07-16 20:58:04 +00:00
|
|
|
SetDParam(1, _cargoc.names_long[i->produced_cargo[0]]);
|
2005-07-15 18:30:13 +00:00
|
|
|
SetDParam(2, i->total_production[0]);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-09-28 19:35:36 +00:00
|
|
|
if (i->produced_cargo[1] != CT_INVALID) {
|
2005-07-16 20:58:04 +00:00
|
|
|
SetDParam(3, _cargoc.names_long[i->produced_cargo[1]]);
|
2005-07-15 18:30:13 +00:00
|
|
|
SetDParam(4, i->total_production[1]);
|
|
|
|
SetDParam(5, i->pct_transported[0] * 100 >> 8);
|
|
|
|
SetDParam(6, i->pct_transported[1] * 100 >> 8);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawString(4, 28+n*10, STR_INDUSTRYDIR_ITEM_TWO, 0);
|
|
|
|
} else {
|
2005-07-15 18:30:13 +00:00
|
|
|
SetDParam(3, i->pct_transported[0] * 100 >> 8);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawString(4, 28+n*10, STR_INDUSTRYDIR_ITEM, 0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
DrawString(4, 28+n*10, STR_INDUSTRYDIR_ITEM_NOPROD, 0);
|
|
|
|
}
|
|
|
|
p++;
|
2006-02-01 06:32:03 +00:00
|
|
|
if (++n == w->vscroll.cap) break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case WE_CLICK:
|
2006-09-23 02:39:24 +00:00
|
|
|
switch (e->we.click.widget) {
|
2004-12-22 01:32:30 +00:00
|
|
|
case 3: {
|
2004-08-09 17:04:08 +00:00
|
|
|
_industry_sort_order = _industry_sort_order==0 ? 1 : 0;
|
|
|
|
_industry_sort_dirty = true;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
} break;
|
|
|
|
|
2004-12-22 01:32:30 +00:00
|
|
|
case 4: {
|
2004-08-09 17:04:08 +00:00
|
|
|
_industry_sort_order = _industry_sort_order==2 ? 3 : 2;
|
|
|
|
_industry_sort_dirty = true;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
} break;
|
|
|
|
|
2004-12-22 01:32:30 +00:00
|
|
|
case 5: {
|
2004-08-09 17:04:08 +00:00
|
|
|
_industry_sort_order = _industry_sort_order==4 ? 5 : 4;
|
|
|
|
_industry_sort_dirty = true;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
} break;
|
|
|
|
|
2004-12-22 01:32:30 +00:00
|
|
|
case 6: {
|
2004-08-09 17:04:08 +00:00
|
|
|
_industry_sort_order = _industry_sort_order==6 ? 7 : 6;
|
|
|
|
_industry_sort_dirty = true;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
} break;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-12-22 01:32:30 +00:00
|
|
|
case 8: {
|
2006-09-23 02:39:24 +00:00
|
|
|
int y = (e->we.click.pt.y - 28) / 10;
|
2004-12-28 17:50:17 +00:00
|
|
|
uint16 p;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-06 09:18:04 +00:00
|
|
|
if (!IS_INT_INSIDE(y, 0, w->vscroll.cap)) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
p = y + w->vscroll.pos;
|
|
|
|
if (p < _num_industry_sort) {
|
2006-08-15 07:07:17 +00:00
|
|
|
ScrollMainWindowToTile(_industry_sort[p]->xy);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_4:
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
2005-01-03 19:45:18 +00:00
|
|
|
|
|
|
|
case WE_RESIZE:
|
2006-09-23 02:39:24 +00:00
|
|
|
w->vscroll.cap += e->we.sizing.diff.y / 10;
|
2005-01-03 19:45:18 +00:00
|
|
|
break;
|
2004-09-10 19:02:27 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Industry List */
|
|
|
|
static const WindowDesc _industry_directory_desc = {
|
|
|
|
-1, -1, 508, 190,
|
|
|
|
WC_INDUSTRY_DIRECTORY,0,
|
2005-01-03 19:45:18 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
|
2004-08-09 17:04:08 +00:00
|
|
|
_industry_directory_widgets,
|
|
|
|
IndustryDirectoryWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void ShowIndustryDirectory(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-07-26 03:33:12 +00:00
|
|
|
Window *w = AllocateWindowDescFront(&_industry_directory_desc, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-06 09:18:04 +00:00
|
|
|
if (w != NULL) {
|
2004-08-09 17:04:08 +00:00
|
|
|
w->vscroll.cap = 16;
|
2005-01-03 19:45:18 +00:00
|
|
|
w->resize.height = w->height - 6 * 10; // minimum 10 items
|
|
|
|
w->resize.step_height = 10;
|
2004-08-09 17:04:08 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
}
|