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 "gui.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
|
|
|
{
|
2004-08-09 17:04:08 +00:00
|
|
|
Subsidy *s;
|
|
|
|
int num,offs;
|
|
|
|
TileIndex xy;
|
|
|
|
|
|
|
|
if (y < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
num = 0;
|
|
|
|
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;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DrawSubsidiesWindow(Window *w)
|
|
|
|
{
|
|
|
|
YearMonthDay ymd;
|
|
|
|
Subsidy *s;
|
|
|
|
int x,xt,y,num,x2;
|
|
|
|
Player *p;
|
|
|
|
|
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
|
|
ConvertDayToYMD(&ymd, _date);
|
|
|
|
|
|
|
|
y = 15;
|
|
|
|
x = 1;
|
|
|
|
DrawString(x, y, STR_2026_SUBSIDIES_ON_OFFER_FOR, 0);
|
|
|
|
y += 10;
|
|
|
|
num = 0;
|
|
|
|
|
|
|
|
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
|
|
|
SetupSubsidyDecodeParam(s, 1);
|
|
|
|
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) {
|
|
|
|
DrawString(x+2, y, STR_202A_NONE, 0);
|
|
|
|
y += 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawString(x, y+1, STR_202B_SERVICES_ALREADY_SUBSIDISED, 0);
|
|
|
|
y += 10;
|
|
|
|
num = 0;
|
|
|
|
|
|
|
|
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
|
|
|
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
|
|
|
|
|
|
|
xt = DrawString(x+2, y, STR_202C_FROM_TO, 0);
|
|
|
|
|
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++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num == 0) {
|
|
|
|
DrawString(x+2, y, STR_202A_NONE, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SubsidiesListWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
|
|
|
switch(e->event) {
|
|
|
|
case WE_PAINT: DrawSubsidiesWindow(w); break;
|
|
|
|
case WE_CLICK: {
|
|
|
|
switch(e->click.widget) {
|
|
|
|
case 2: HandleSubsidyClick(e->click.pt.y - 25); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _subsidies_list_widgets[] = {
|
2005-01-03 19:45:18 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 13, 11, 629, 0, 13, STR_2025_SUBSIDIES, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 13, 0, 629, 14, 126, 0x0, 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,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
|
|
_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);
|
|
|
|
}
|