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-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "window.h"
|
|
|
|
#include "station.h"
|
|
|
|
#include "industry.h"
|
|
|
|
#include "town.h"
|
|
|
|
#include "player.h"
|
|
|
|
#include "gfx.h"
|
|
|
|
#include "economy.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
static void HandleSubsidyClick(int y)
|
2004-09-10 19:02:27 +00:00
|
|
|
{
|
2006-07-26 03:33:12 +00:00
|
|
|
const Subsidy *s;
|
2005-11-14 19:48:04 +00:00
|
|
|
uint num;
|
|
|
|
int offs;
|
2004-08-09 17:04:08 +00:00
|
|
|
TileIndex xy;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (y < 0) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
num = 0;
|
2005-11-14 19:48:04 +00:00
|
|
|
for (s = _subsidies; s != endof(_subsidies); s++) {
|
2005-09-28 19:35:36 +00:00
|
|
|
if (s->cargo_type != CT_INVALID && s->age < 12) {
|
2004-08-09 17:04:08 +00:00
|
|
|
y -= 10;
|
|
|
|
if (y < 0) goto handle_click;
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num == 0) {
|
|
|
|
y -= 10;
|
|
|
|
if (y < 0) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
y -= 11;
|
|
|
|
if (y < 0) return;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
for (s = _subsidies; s != endof(_subsidies); s++) {
|
2005-09-28 19:35:36 +00:00
|
|
|
if (s->cargo_type != CT_INVALID && s->age >= 12) {
|
2004-08-09 17:04:08 +00:00
|
|
|
y -= 10;
|
|
|
|
if (y < 0) goto handle_click;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
handle_click:
|
|
|
|
|
|
|
|
/* determine from coordinate for subsidy and try to scroll to it */
|
|
|
|
offs = s->from;
|
|
|
|
if (s->age >= 12) {
|
2005-01-06 22:31:58 +00:00
|
|
|
xy = GetStation(offs)->xy;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else if (s->cargo_type == CT_PASSENGERS || s->cargo_type == CT_MAIL) {
|
2005-01-06 22:31:58 +00:00
|
|
|
xy = GetTown(offs)->xy;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2005-01-06 22:31:58 +00:00
|
|
|
xy = GetIndustry(offs)->xy;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
if (!ScrollMainWindowToTile(xy)) {
|
|
|
|
/* otherwise determine to coordinate for subsidy and scroll to it */
|
|
|
|
offs = s->to;
|
|
|
|
if (s->age >= 12) {
|
2005-01-06 22:31:58 +00:00
|
|
|
xy = GetStation(offs)->xy;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else if (s->cargo_type == CT_PASSENGERS || s->cargo_type == CT_MAIL || s->cargo_type == CT_GOODS || s->cargo_type == CT_FOOD) {
|
2005-01-06 22:31:58 +00:00
|
|
|
xy = GetTown(offs)->xy;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2005-01-06 22:31:58 +00:00
|
|
|
xy = GetIndustry(offs)->xy;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
ScrollMainWindowToTile(xy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-26 03:33:12 +00:00
|
|
|
static void DrawSubsidiesWindow(const Window *w)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
YearMonthDay ymd;
|
2006-07-26 03:33:12 +00:00
|
|
|
const Subsidy *s;
|
2005-11-14 19:48:04 +00:00
|
|
|
uint num;
|
|
|
|
int x;
|
|
|
|
int y;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
|
|
ConvertDayToYMD(&ymd, _date);
|
|
|
|
|
|
|
|
y = 15;
|
|
|
|
x = 1;
|
|
|
|
DrawString(x, y, STR_2026_SUBSIDIES_ON_OFFER_FOR, 0);
|
|
|
|
y += 10;
|
|
|
|
num = 0;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
for (s = _subsidies; s != endof(_subsidies); s++) {
|
2005-09-28 19:35:36 +00:00
|
|
|
if (s->cargo_type != CT_INVALID && s->age < 12) {
|
2005-11-14 19:48:04 +00:00
|
|
|
int x2;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
SetupSubsidyDecodeParam(s, 1);
|
2005-11-14 19:48:04 +00:00
|
|
|
x2 = DrawString(x + 2, y, STR_2027_FROM_TO, 0);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, _date - ymd.day + 384 - s->age * 32);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawString(x2, y, STR_2028_BY, 0);
|
|
|
|
y += 10;
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num == 0) {
|
2005-11-14 19:48:04 +00:00
|
|
|
DrawString(x + 2, y, STR_202A_NONE, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
y += 10;
|
|
|
|
}
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
DrawString(x, y + 1, STR_202B_SERVICES_ALREADY_SUBSIDISED, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
y += 10;
|
|
|
|
num = 0;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
for (s = _subsidies; s != endof(_subsidies); s++) {
|
2005-09-28 19:35:36 +00:00
|
|
|
if (s->cargo_type != CT_INVALID && s->age >= 12) {
|
2006-07-26 03:33:12 +00:00
|
|
|
const Player *p;
|
2005-11-14 19:48:04 +00:00
|
|
|
int xt;
|
2005-11-13 13:43:55 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
SetupSubsidyDecodeParam(s, 1);
|
|
|
|
|
2005-06-21 16:28:17 +00:00
|
|
|
p = GetPlayer(GetStation(s->to)->owner);
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(3, p->name_1);
|
|
|
|
SetDParam(4, p->name_2);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
xt = DrawString(x + 2, y, STR_202C_FROM_TO, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, _date - ymd.day + 768 - s->age * 32);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawString(xt, y, STR_202D_UNTIL, 0);
|
|
|
|
y += 10;
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (num == 0) DrawString(x + 2, y, STR_202A_NONE, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void SubsidiesListWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2005-11-14 19:48:04 +00:00
|
|
|
switch (e->event) {
|
|
|
|
case WE_PAINT: DrawSubsidiesWindow(w); break;
|
|
|
|
|
|
|
|
case WE_CLICK:
|
|
|
|
switch (e->click.widget) {
|
2006-01-18 18:12:49 +00:00
|
|
|
case 3: HandleSubsidyClick(e->click.pt.y - 25); break;
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _subsidies_list_widgets[] = {
|
2006-01-18 18:12:49 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 13, 11, 617, 0, 13, STR_2025_SUBSIDIES, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_STICKYBOX, RESIZE_NONE, 13, 618, 629, 0, 13, STR_NULL, STR_STICKY_BUTTON},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 13, 0, 629, 14, 126, STR_NULL, STR_01FD_CLICK_ON_SERVICE_TO_CENTER},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _subsidies_list_desc = {
|
|
|
|
-1, -1, 630, 127,
|
|
|
|
WC_SUBSIDIES_LIST,0,
|
2006-01-18 18:12:49 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
|
2004-08-09 17:04:08 +00:00
|
|
|
_subsidies_list_widgets,
|
|
|
|
SubsidiesListWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void ShowSubsidiesList(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
AllocateWindowDescFront(&_subsidies_list_desc, 0);
|
|
|
|
}
|