src/aircraft_gui.cpp
author rubidium
Wed, 17 Dec 2008 23:08:11 +0000
changeset 10434 3659467c844c
parent 9943 ccea23aec951
permissions -rw-r--r--
(svn r14687) -Change: log all configure errors to config.log
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 8962
diff changeset
     3
/** @file aircraft_gui.cpp The GUI of aircraft. */
6117
6507b2a7e71d (svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents: 5893
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1820
diff changeset
     6
#include "openttd.h"
3963
6cab57074a9a (svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar()
tron
parents: 3948
diff changeset
     7
#include "aircraft.h"
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1294
diff changeset
     8
#include "debug.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     9
#include "gui.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2113
diff changeset
    10
#include "vehicle_gui.h"
2962
f0a49b646c48 (svn r3524) - Split newgrf features from engine.[ch] into newgrf_engine.[ch], and add the new files to project files.
peter1138
parents: 2958
diff changeset
    11
#include "newgrf_engine.h"
8114
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8106
diff changeset
    12
#include "strings_func.h"
8144
65cec0877b78 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8139
diff changeset
    13
#include "vehicle_func.h"
8224
c5a64d87cc54 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8144
diff changeset
    14
#include "gfx_func.h"
8784
c2e9d649a9ce (svn r12488) -Codechange: split order.h into order_base.h and order_func.h.
rubidium
parents: 8264
diff changeset
    15
#include "order_func.h"
9274
42b67e65f1c2 (svn r13140) -Codechange: move the gui-list-sorting out of window_gui.h so window_gui.h only needs to be included in *_gui.cpp.
rubidium
parents: 9111
diff changeset
    16
#include "window_gui.h"
4787
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    17
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    18
#include "table/sprites.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    19
#include "table/strings.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    20
7530
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    21
/**
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    22
* Draw the details for the given vehicle at the position (x,y)
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    23
*
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    24
* @param v current vehicle
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    25
* @param x The x coordinate
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    26
* @param y The y coordinate
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    27
*/
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    28
void DrawAircraftDetails(const Vehicle *v, int x, int y)
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    29
{
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    30
	int y_offset = (v->Next()->cargo_cap != 0) ? -11 : 0;
9943
ccea23aec951 (svn r14098) -Fix: Make the 'Transfer Credit' display aware of the entire consist, not only the first vehicle
celestar
parents: 9770
diff changeset
    31
	Money feeder_share = 0;
7530
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    32
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    33
	for (const Vehicle *u = v ; u != NULL ; u = u->Next()) {
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    34
		if (IsNormalAircraft(u)) {
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    35
			SetDParam(0, u->engine_type);
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    36
			SetDParam(1, u->build_year);
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    37
			SetDParam(2, u->value);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7653
diff changeset
    38
			DrawString(x, y, STR_A011_BUILT_VALUE, TC_FROMSTRING);
7530
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    39
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    40
			SetDParam(0, u->cargo_type);
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    41
			SetDParam(1, u->cargo_cap);
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    42
			SetDParam(2, u->Next()->cargo_type);
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    43
			SetDParam(3, u->Next()->cargo_cap);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7653
diff changeset
    44
			DrawString(x, y + 10, (u->Next()->cargo_cap != 0) ? STR_A019_CAPACITY : STR_A01A_CAPACITY, TC_FROMSTRING);
7530
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    45
		}
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    46
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    47
		if (u->cargo_cap != 0) {
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    48
			uint cargo_count = u->cargo.Count();
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    49
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    50
			y_offset += 11;
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    51
			if (cargo_count != 0) {
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    52
				/* Cargo names (fix pluralness) */
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    53
				SetDParam(0, u->cargo_type);
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    54
				SetDParam(1, cargo_count);
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    55
				SetDParam(2, u->cargo.Source());
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7653
diff changeset
    56
				DrawString(x, y + 21 + y_offset, STR_8813_FROM, TC_FROMSTRING);
9943
ccea23aec951 (svn r14098) -Fix: Make the 'Transfer Credit' display aware of the entire consist, not only the first vehicle
celestar
parents: 9770
diff changeset
    57
				feeder_share += u->cargo.FeederShare();
7530
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    58
			}
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    59
		}
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    60
	}
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    61
9943
ccea23aec951 (svn r14098) -Fix: Make the 'Transfer Credit' display aware of the entire consist, not only the first vehicle
celestar
parents: 9770
diff changeset
    62
	SetDParam(0, feeder_share);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7653
diff changeset
    63
	DrawString(x, y + 33 + y_offset, STR_FEEDER_CARGO_VALUE, TC_FROMSTRING);
7530
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    64
}
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    65
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    66
5780
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    67
void DrawAircraftImage(const Vehicle *v, int x, int y, VehicleID selection)
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    68
{
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    69
	SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
7134
5b2d47128d05 (svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium
parents: 7063
diff changeset
    70
	DrawSprite(v->GetImage(DIR_W), pal, x + 25, y + 10);
5854
9eee280920f0 (svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents: 5780
diff changeset
    71
	if (v->subtype == AIR_HELICOPTER) {
5780
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    72
		SpriteID rotor_sprite = GetCustomRotorSprite(v, true);
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    73
		if (rotor_sprite == 0) rotor_sprite = SPR_ROTOR_STOPPED;
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    74
		DrawSprite(rotor_sprite, PAL_NONE, x + 25, y + 5);
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    75
	}
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    76
	if (v->index == selection) {
9770
8c260fb382f8 (svn r13907) -Codechange: Replace a number with Colours enum on DrawFrameRect usage
belugas
parents: 9274
diff changeset
    77
		DrawFrameRect(x - 1, y - 1, x + 58, y + 21, COLOUR_WHITE, FR_BORDERONLY);
5780
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    78
	}
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    79
}
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    80
6415
cb61e1346600 (svn r9551) -Documentation: Some more doxygen work
belugas
parents: 6198
diff changeset
    81
/**
cb61e1346600 (svn r9551) -Documentation: Some more doxygen work
belugas
parents: 6198
diff changeset
    82
 * This is the Callback method after the construction attempt of an aircraft
cb61e1346600 (svn r9551) -Documentation: Some more doxygen work
belugas
parents: 6198
diff changeset
    83
 * @param success indicates completion (or not) of the operation
cb61e1346600 (svn r9551) -Documentation: Some more doxygen work
belugas
parents: 6198
diff changeset
    84
 * @param tile of depot where aircraft is built
cb61e1346600 (svn r9551) -Documentation: Some more doxygen work
belugas
parents: 6198
diff changeset
    85
 * @param p1 unused
cb61e1346600 (svn r9551) -Documentation: Some more doxygen work
belugas
parents: 6198
diff changeset
    86
 * @param p2 unused
cb61e1346600 (svn r9551) -Documentation: Some more doxygen work
belugas
parents: 6198
diff changeset
    87
 */
5780
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    88
void CcBuildAircraft(bool success, TileIndex tile, uint32 p1, uint32 p2)
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    89
{
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    90
	if (success) {
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    91
		const Vehicle *v = GetVehicle(_new_vehicle_id);
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    92
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    93
		if (v->tile == _backup_orders_tile) {
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    94
			_backup_orders_tile = 0;
7653
dd252420d9c2 (svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents: 7530
diff changeset
    95
			RestoreVehicleOrders(v);
5780
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    96
		}
7486
bf6a94009823 (svn r10997) -Codechange: unify the vehicle view window. Patch by PhilSophus.
rubidium
parents: 7484
diff changeset
    97
		ShowVehicleViewWindow(v);
5780
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    98
	}
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    99
}