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"
|
2004-11-25 10:47:30 +00:00
|
|
|
#include "table/strings.h"
|
2005-07-28 09:17:32 +00:00
|
|
|
#include "table/sprites.h"
|
2005-07-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "window.h"
|
|
|
|
#include "gui.h"
|
|
|
|
#include "viewport.h"
|
|
|
|
#include "gfx.h"
|
|
|
|
#include "engine.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "news.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.h"
|
2006-02-03 12:55:21 +00:00
|
|
|
#include "newgrf_engine.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
static StringID GetEngineCategoryName(EngineID engine)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-11-19 19:13:32 +00:00
|
|
|
if (engine < NUM_TRAIN_ENGINES) {
|
2005-06-07 18:13:49 +00:00
|
|
|
switch (GetEngine(engine)->railtype) {
|
2006-03-29 16:30:26 +00:00
|
|
|
case RAILTYPE_RAIL: return STR_8102_RAILROAD_LOCOMOTIVE;
|
|
|
|
case RAILTYPE_ELECTRIC: return STR_8102_RAILROAD_LOCOMOTIVE;
|
|
|
|
case RAILTYPE_MONO: return STR_8106_MONORAIL_LOCOMOTIVE;
|
|
|
|
case RAILTYPE_MAGLEV: return STR_8107_MAGLEV_LOCOMOTIVE;
|
2007-01-10 18:56:51 +00:00
|
|
|
default: NOT_REACHED();
|
2004-11-19 19:13:32 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (engine < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES)
|
|
|
|
return STR_8103_ROAD_VEHICLE;
|
|
|
|
|
|
|
|
if (engine < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES)
|
|
|
|
return STR_8105_SHIP;
|
|
|
|
|
|
|
|
return STR_8104_AIRCRAFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _engine_preview_widgets[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 5, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
2005-01-03 19:45:18 +00:00
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 5, 11, 299, 0, 13, STR_8100_MESSAGE_FROM_VEHICLE_MANUFACTURE, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
2006-10-24 14:15:17 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 5, 0, 299, 14, 191, 0x0, STR_NULL},
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 5, 85, 144, 172, 183, STR_00C9_NO, STR_NULL},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 5, 155, 214, 172, 183, STR_00C8_YES, STR_NULL},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
typedef void DrawEngineProc(int x, int y, EngineID engine, uint32 image_ormod);
|
|
|
|
typedef void DrawEngineInfoProc(EngineID, int x, int y, int maxw);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
typedef struct DrawEngineInfo {
|
|
|
|
DrawEngineProc *engine_proc;
|
|
|
|
DrawEngineInfoProc *info_proc;
|
|
|
|
} DrawEngineInfo;
|
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
static void DrawTrainEngineInfo(EngineID engine, int x, int y, int maxw);
|
|
|
|
static void DrawRoadVehEngineInfo(EngineID engine, int x, int y, int maxw);
|
|
|
|
static void DrawShipEngineInfo(EngineID engine, int x, int y, int maxw);
|
|
|
|
static void DrawAircraftEngineInfo(EngineID engine, int x, int y, int maxw);
|
2005-07-01 14:05:44 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static const DrawEngineInfo _draw_engine_list[4] = {
|
|
|
|
{DrawTrainEngine,DrawTrainEngineInfo},
|
|
|
|
{DrawRoadVehEngine,DrawRoadVehEngineInfo},
|
|
|
|
{DrawShipEngine,DrawShipEngineInfo},
|
|
|
|
{DrawAircraftEngine,DrawAircraftEngineInfo},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void EnginePreviewWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2005-11-14 19:48:04 +00:00
|
|
|
switch (e->event) {
|
2005-10-01 12:43:34 +00:00
|
|
|
case WE_PAINT: {
|
|
|
|
EngineID engine = w->window_number;
|
2005-11-14 19:48:04 +00:00
|
|
|
const DrawEngineInfo* dei;
|
|
|
|
int width;
|
2005-10-01 12:43:34 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, GetEngineCategoryName(engine));
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawStringMultiCenter(150, 44, STR_8101_WE_HAVE_JUST_DESIGNED_A, 296);
|
|
|
|
|
|
|
|
DrawStringCentered(w->width >> 1, 80, GetCustomEngineName(engine), 0x10);
|
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
(dei = _draw_engine_list,engine < NUM_TRAIN_ENGINES) ||
|
|
|
|
(dei++,engine < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES) ||
|
|
|
|
(dei++,engine < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES) ||
|
2004-08-09 17:04:08 +00:00
|
|
|
(dei++, true);
|
|
|
|
|
|
|
|
width = w->width;
|
|
|
|
dei->engine_proc(width >> 1, 100, engine, 0);
|
|
|
|
dei->info_proc(engine, width >> 1, 130, width - 52);
|
|
|
|
break;
|
2005-10-01 12:43:34 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
case WE_CLICK:
|
2006-09-23 02:39:24 +00:00
|
|
|
switch (e->we.click.widget) {
|
2005-11-14 19:48:04 +00:00
|
|
|
case 4:
|
|
|
|
DoCommandP(0, w->window_number, 0, NULL, CMD_WANT_ENGINE_PREVIEW);
|
2006-11-18 17:04:44 +00:00
|
|
|
/* Fallthrough */
|
|
|
|
case 3:
|
2005-11-14 19:48:04 +00:00
|
|
|
DeleteWindow(w);
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const WindowDesc _engine_preview_desc = {
|
|
|
|
WDP_CENTER, WDP_CENTER, 300, 192,
|
|
|
|
WC_ENGINE_PREVIEW,0,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
|
|
_engine_preview_widgets,
|
|
|
|
EnginePreviewWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
void ShowEnginePreviewWindow(EngineID engine)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-11-19 22:24:18 +00:00
|
|
|
AllocateWindowDescFront(&_engine_preview_desc, engine);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
static void DrawTrainEngineInfo(EngineID engine, int x, int y, int maxw)
|
2005-07-01 14:05:44 +00:00
|
|
|
{
|
|
|
|
const RailVehicleInfo *rvi = RailVehInfo(engine);
|
|
|
|
uint multihead = (rvi->flags & RVI_MULTIHEAD) ? 1 : 0;
|
|
|
|
|
|
|
|
SetDParam(0, (_price.build_railvehicle >> 3) * rvi->base_cost >> 5);
|
2006-04-08 12:04:23 +00:00
|
|
|
SetDParam(2, rvi->max_speed);
|
2005-07-01 14:05:44 +00:00
|
|
|
SetDParam(3, rvi->power << multihead);
|
|
|
|
SetDParam(1, rvi->weight << multihead);
|
|
|
|
|
2006-01-07 16:47:59 +00:00
|
|
|
SetDParam(4, rvi->running_cost_base * _price.running_rail[rvi->running_cost_class] >> 8 << multihead);
|
2005-07-01 14:05:44 +00:00
|
|
|
|
2005-10-23 13:04:44 +00:00
|
|
|
if (rvi->capacity != 0) {
|
2006-10-20 11:53:29 +00:00
|
|
|
SetDParam(5, rvi->cargo_type);
|
2005-10-23 13:04:44 +00:00
|
|
|
SetDParam(6, rvi->capacity << multihead);
|
|
|
|
} else {
|
2006-10-20 19:48:25 +00:00
|
|
|
SetDParam(5, CT_INVALID);
|
2005-07-01 14:05:44 +00:00
|
|
|
}
|
2006-03-31 17:40:31 +00:00
|
|
|
DrawStringMultiCenter(x, y, STR_VEHICLE_INFO_COST_WEIGHT_SPEED_POWER, maxw);
|
2005-07-01 14:05:44 +00:00
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
void DrawNewsNewTrainAvail(Window *w)
|
|
|
|
{
|
2005-10-01 12:43:34 +00:00
|
|
|
EngineID engine;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
DrawNewsBorder(w);
|
|
|
|
|
|
|
|
engine = WP(w,news_d).ni->string_id;
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, GetEngineCategoryName(engine));
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawStringMultiCenter(w->width >> 1, 20, STR_8859_NEW_NOW_AVAILABLE, w->width - 2);
|
|
|
|
|
|
|
|
GfxFillRect(25, 56, w->width - 25, w->height - 2, 10);
|
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, GetCustomEngineName(engine));
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawStringMultiCenter(w->width >> 1, 57, STR_885A, w->width - 2);
|
|
|
|
|
|
|
|
DrawTrainEngine(w->width >> 1, 88, engine, 0);
|
2005-07-28 09:17:32 +00:00
|
|
|
GfxFillRect(25, 56, w->width - 56, 112, 0x323 | USE_COLORTABLE);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawTrainEngineInfo(engine, w->width >> 1, 129, w->width - 52);
|
|
|
|
}
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
StringID GetNewsStringNewTrainAvail(const NewsItem *ni)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-10-01 12:43:34 +00:00
|
|
|
EngineID engine = ni->string_id;
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, STR_8859_NEW_NOW_AVAILABLE);
|
|
|
|
SetDParam(1, GetEngineCategoryName(engine));
|
|
|
|
SetDParam(2, GetCustomEngineName(engine));
|
2004-08-09 17:04:08 +00:00
|
|
|
return STR_02B6;
|
|
|
|
}
|
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
static void DrawAircraftEngineInfo(EngineID engine, int x, int y, int maxw)
|
2005-07-01 14:05:44 +00:00
|
|
|
{
|
|
|
|
const AircraftVehicleInfo *avi = AircraftVehInfo(engine);
|
|
|
|
SetDParam(0, (_price.aircraft_base >> 3) * avi->base_cost >> 5);
|
2006-04-08 12:04:23 +00:00
|
|
|
SetDParam(1, avi->max_speed * 128 / 10);
|
2005-07-01 14:05:44 +00:00
|
|
|
SetDParam(2, avi->passenger_capacity);
|
|
|
|
SetDParam(3, avi->mail_capacity);
|
|
|
|
SetDParam(4, avi->running_cost * _price.aircraft_running >> 8);
|
|
|
|
|
|
|
|
DrawStringMultiCenter(x, y, STR_A02E_COST_MAX_SPEED_CAPACITY, maxw);
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
void DrawNewsNewAircraftAvail(Window *w)
|
|
|
|
{
|
2005-10-01 12:43:34 +00:00
|
|
|
EngineID engine;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
DrawNewsBorder(w);
|
|
|
|
|
|
|
|
engine = WP(w,news_d).ni->string_id;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawStringMultiCenter(w->width >> 1, 20, STR_A02C_NEW_AIRCRAFT_NOW_AVAILABLE, w->width - 2);
|
|
|
|
GfxFillRect(25, 56, w->width - 25, w->height - 2, 10);
|
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, GetCustomEngineName(engine));
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawStringMultiCenter(w->width >> 1, 57, STR_A02D, w->width - 2);
|
|
|
|
|
|
|
|
DrawAircraftEngine(w->width >> 1, 93, engine, 0);
|
2005-07-28 09:17:32 +00:00
|
|
|
GfxFillRect(25, 56, w->width - 56, 110, 0x323 | USE_COLORTABLE);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawAircraftEngineInfo(engine, w->width >> 1, 131, w->width - 52);
|
|
|
|
}
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
StringID GetNewsStringNewAircraftAvail(const NewsItem *ni)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-10-01 12:43:34 +00:00
|
|
|
EngineID engine = ni->string_id;
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, STR_A02C_NEW_AIRCRAFT_NOW_AVAILABLE);
|
|
|
|
SetDParam(1, GetCustomEngineName(engine));
|
2004-08-09 17:04:08 +00:00
|
|
|
return STR_02B6;
|
|
|
|
}
|
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
static void DrawRoadVehEngineInfo(EngineID engine, int x, int y, int maxw)
|
2005-07-01 14:05:44 +00:00
|
|
|
{
|
|
|
|
const RoadVehicleInfo *rvi = RoadVehInfo(engine);
|
|
|
|
|
|
|
|
SetDParam(0, (_price.roadveh_base >> 3) * rvi->base_cost >> 5);
|
2006-04-08 12:04:23 +00:00
|
|
|
SetDParam(1, rvi->max_speed / 2);
|
2005-07-01 14:05:44 +00:00
|
|
|
SetDParam(2, rvi->running_cost * _price.roadveh_running >> 8);
|
2006-10-20 11:53:29 +00:00
|
|
|
SetDParam(3, rvi->cargo_type);
|
2005-07-01 14:05:44 +00:00
|
|
|
SetDParam(4, rvi->capacity);
|
|
|
|
|
|
|
|
DrawStringMultiCenter(x, y, STR_902A_COST_SPEED_RUNNING_COST, maxw);
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
void DrawNewsNewRoadVehAvail(Window *w)
|
|
|
|
{
|
2005-10-01 12:43:34 +00:00
|
|
|
EngineID engine;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
DrawNewsBorder(w);
|
|
|
|
|
|
|
|
engine = WP(w,news_d).ni->string_id;
|
|
|
|
DrawStringMultiCenter(w->width >> 1, 20, STR_9028_NEW_ROAD_VEHICLE_NOW_AVAILABLE, w->width - 2);
|
|
|
|
GfxFillRect(25, 56, w->width - 25, w->height - 2, 10);
|
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, GetCustomEngineName(engine));
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawStringMultiCenter(w->width >> 1, 57, STR_9029, w->width - 2);
|
|
|
|
|
|
|
|
DrawRoadVehEngine(w->width >> 1, 88, engine, 0);
|
2005-07-28 09:17:32 +00:00
|
|
|
GfxFillRect(25, 56, w->width - 56, 112, 0x323 | USE_COLORTABLE);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawRoadVehEngineInfo(engine, w->width >> 1, 129, w->width - 52);
|
|
|
|
}
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
StringID GetNewsStringNewRoadVehAvail(const NewsItem *ni)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-10-01 12:43:34 +00:00
|
|
|
EngineID engine = ni->string_id;
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, STR_9028_NEW_ROAD_VEHICLE_NOW_AVAILABLE);
|
|
|
|
SetDParam(1, GetCustomEngineName(engine));
|
2004-08-09 17:04:08 +00:00
|
|
|
return STR_02B6;
|
|
|
|
}
|
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
static void DrawShipEngineInfo(EngineID engine, int x, int y, int maxw)
|
2005-07-01 14:05:44 +00:00
|
|
|
{
|
|
|
|
const ShipVehicleInfo *svi = ShipVehInfo(engine);
|
|
|
|
SetDParam(0, svi->base_cost * (_price.ship_base >> 3) >> 5);
|
2006-04-08 12:04:23 +00:00
|
|
|
SetDParam(1, svi->max_speed / 2);
|
2006-10-20 11:53:29 +00:00
|
|
|
SetDParam(2, svi->cargo_type);
|
2005-07-01 14:05:44 +00:00
|
|
|
SetDParam(3, svi->capacity);
|
|
|
|
SetDParam(4, svi->running_cost * _price.ship_running >> 8);
|
|
|
|
DrawStringMultiCenter(x, y, STR_982E_COST_MAX_SPEED_CAPACITY, maxw);
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
void DrawNewsNewShipAvail(Window *w)
|
|
|
|
{
|
2005-10-01 12:43:34 +00:00
|
|
|
EngineID engine;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
DrawNewsBorder(w);
|
|
|
|
|
|
|
|
engine = WP(w,news_d).ni->string_id;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawStringMultiCenter(w->width >> 1, 20, STR_982C_NEW_SHIP_NOW_AVAILABLE, w->width - 2);
|
|
|
|
GfxFillRect(25, 56, w->width - 25, w->height - 2, 10);
|
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, GetCustomEngineName(engine));
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawStringMultiCenter(w->width >> 1, 57, STR_982D, w->width - 2);
|
|
|
|
|
|
|
|
DrawShipEngine(w->width >> 1, 93, engine, 0);
|
2005-07-28 09:17:32 +00:00
|
|
|
GfxFillRect(25, 56, w->width - 56, 110, 0x323 | USE_COLORTABLE);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawShipEngineInfo(engine, w->width >> 1, 131, w->width - 52);
|
|
|
|
}
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
StringID GetNewsStringNewShipAvail(const NewsItem *ni)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-10-01 12:43:34 +00:00
|
|
|
EngineID engine = ni->string_id;
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, STR_982C_NEW_SHIP_NOW_AVAILABLE);
|
|
|
|
SetDParam(1, GetCustomEngineName(engine));
|
2004-08-09 17:04:08 +00:00
|
|
|
return STR_02B6;
|
|
|
|
}
|