src/aircraft_gui.cpp
author convert-repo
Mon, 07 Apr 2008 16:21:55 +0000
changeset 10076 dfd70e42c4ae
parent 9282 2bb9703aeb39
child 10222 b6919c94cc77
permissions -rw-r--r--
update tags
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6443
b8f06d8eb7be (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: 6144
diff changeset
     3
/** @file aircraft_gui.cpp */
b8f06d8eb7be (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: 6144
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1820
diff changeset
     6
#include "openttd.h"
3963
d7d284c2f1f7 (svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar()
tron
parents: 3948
diff changeset
     7
#include "aircraft.h"
1299
0a6510cc889b (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"
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
    10
#include "depot.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2113
diff changeset
    11
#include "vehicle_gui.h"
2962
dbd168a4703a (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
    12
#include "newgrf_engine.h"
8610
17cc343a23dd (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8602
diff changeset
    13
#include "strings_func.h"
8640
1e93b81e96d2 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8635
diff changeset
    14
#include "vehicle_func.h"
8720
4e60c30e2006 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8640
diff changeset
    15
#include "gfx_func.h"
9280
9c03416d26b1 (svn r12488) -Codechange: split order.h into order_base.h and order_func.h.
rubidium
parents: 8760
diff changeset
    16
#include "order_func.h"
4787
fbf6f00ba6c6 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    17
8760
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8750
diff changeset
    18
#include "table/sprites.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8750
diff changeset
    19
#include "table/strings.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8750
diff changeset
    20
8026
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    21
/**
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    22
* Draw the details for the given vehicle at the position (x,y)
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    23
*
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    24
* @param v current vehicle
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    25
* @param x The x coordinate
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    26
* @param y The y coordinate
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    27
*/
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    28
void DrawAircraftDetails(const Vehicle *v, int x, int y)
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    29
{
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    30
	int y_offset = (v->Next()->cargo_cap != 0) ? -11 : 0;
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    31
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    32
	for (const Vehicle *u = v ; u != NULL ; u = u->Next()) {
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    33
		if (IsNormalAircraft(u)) {
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    34
			SetDParam(0, u->engine_type);
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    35
			SetDParam(1, u->build_year);
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    36
			SetDParam(2, u->value);
8320
6ffad7a5d242 (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 8149
diff changeset
    37
			DrawString(x, y, STR_A011_BUILT_VALUE, TC_FROMSTRING);
8026
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    38
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    39
			SetDParam(0, u->cargo_type);
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    40
			SetDParam(1, u->cargo_cap);
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    41
			SetDParam(2, u->Next()->cargo_type);
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    42
			SetDParam(3, u->Next()->cargo_cap);
8320
6ffad7a5d242 (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 8149
diff changeset
    43
			DrawString(x, y + 10, (u->Next()->cargo_cap != 0) ? STR_A019_CAPACITY : STR_A01A_CAPACITY, TC_FROMSTRING);
8026
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    44
		}
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    45
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    46
		if (u->cargo_cap != 0) {
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    47
			uint cargo_count = u->cargo.Count();
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    48
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    49
			y_offset += 11;
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    50
			if (cargo_count != 0) {
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    51
				/* Cargo names (fix pluralness) */
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    52
				SetDParam(0, u->cargo_type);
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    53
				SetDParam(1, cargo_count);
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    54
				SetDParam(2, u->cargo.Source());
8320
6ffad7a5d242 (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 8149
diff changeset
    55
				DrawString(x, y + 21 + y_offset, STR_8813_FROM, TC_FROMSTRING);
8026
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    56
			}
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    57
		}
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    58
	}
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    59
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    60
	SetDParam(0, v->cargo.FeederShare());
8320
6ffad7a5d242 (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 8149
diff changeset
    61
	DrawString(x, y + 33 + y_offset, STR_FEEDER_CARGO_VALUE, TC_FROMSTRING);
8026
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    62
}
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    63
269979f5319d (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7988
diff changeset
    64
6031
f6d1eef3fa24 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5919
diff changeset
    65
void DrawAircraftImage(const Vehicle *v, int x, int y, VehicleID selection)
f6d1eef3fa24 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5919
diff changeset
    66
{
f6d1eef3fa24 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5919
diff changeset
    67
	SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
7630
2cd754d7dfa4 (svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium
parents: 7559
diff changeset
    68
	DrawSprite(v->GetImage(DIR_W), pal, x + 25, y + 10);
6105
761d393829d6 (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: 6031
diff changeset
    69
	if (v->subtype == AIR_HELICOPTER) {
6031
f6d1eef3fa24 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5919
diff changeset
    70
		SpriteID rotor_sprite = GetCustomRotorSprite(v, true);
f6d1eef3fa24 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5919
diff changeset
    71
		if (rotor_sprite == 0) rotor_sprite = SPR_ROTOR_STOPPED;
f6d1eef3fa24 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5919
diff changeset
    72
		DrawSprite(rotor_sprite, PAL_NONE, x + 25, y + 5);
f6d1eef3fa24 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5919
diff changeset
    73
	}
f6d1eef3fa24 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5919
diff changeset
    74
	if (v->index == selection) {
f6d1eef3fa24 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5919
diff changeset
    75
		DrawFrameRect(x - 1, y - 1, x + 58, y + 21, 0xF, FR_BORDERONLY);
f6d1eef3fa24 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5919
diff changeset
    76
	}
f6d1eef3fa24 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5919
diff changeset
    77
}
f6d1eef3fa24 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5919
diff changeset
    78
6911
ee97929ba49e (svn r9551) -Documentation: Some more doxygen work
belugas
parents: 6524
diff changeset
    79
/**
ee97929ba49e (svn r9551) -Documentation: Some more doxygen work
belugas
parents: 6524
diff changeset
    80
 * This is the Callback method after the construction attempt of an aircraft
ee97929ba49e (svn r9551) -Documentation: Some more doxygen work
belugas
parents: 6524
diff changeset
    81
 * @param success indicates completion (or not) of the operation
ee97929ba49e (svn r9551) -Documentation: Some more doxygen work
belugas
parents: 6524
diff changeset
    82
 * @param tile of depot where aircraft is built
ee97929ba49e (svn r9551) -Documentation: Some more doxygen work
belugas
parents: 6524
diff changeset
    83
 * @param p1 unused
ee97929ba49e (svn r9551) -Documentation: Some more doxygen work
belugas
parents: 6524
diff changeset
    84
 * @param p2 unused
ee97929ba49e (svn r9551) -Documentation: Some more doxygen work
belugas
parents: 6524
diff changeset
    85
 */
6031
f6d1eef3fa24 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5919
diff changeset
    86
void CcBuildAircraft(bool success, TileIndex tile, uint32 p1, uint32 p2)
f6d1eef3fa24 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5919
diff changeset
    87
{
f6d1eef3fa24 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5919
diff changeset
    88
	if (success) {
f6d1eef3fa24 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5919
diff changeset
    89
		const Vehicle *v = GetVehicle(_new_vehicle_id);
f6d1eef3fa24 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5919
diff changeset
    90
f6d1eef3fa24 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5919
diff changeset
    91
		if (v->tile == _backup_orders_tile) {
f6d1eef3fa24 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5919
diff changeset
    92
			_backup_orders_tile = 0;
8149
eb78fb69096f (svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents: 8026
diff changeset
    93
			RestoreVehicleOrders(v);
6031
f6d1eef3fa24 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5919
diff changeset
    94
		}
7982
539e32cc37ce (svn r10997) -Codechange: unify the vehicle view window. Patch by PhilSophus.
rubidium
parents: 7980
diff changeset
    95
		ShowVehicleViewWindow(v);
6031
f6d1eef3fa24 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5919
diff changeset
    96
	}
f6d1eef3fa24 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5919
diff changeset
    97
}