src/aircraft_gui.cpp
author rubidium
Fri, 28 Sep 2007 21:15:45 +0000
changeset 7653 dd252420d9c2
parent 7530 bfeada535347
child 7824 5a63d41b59ea
permissions -rw-r--r--
(svn r11184) -Codechange: cleanup the code related to backup orders.
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
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
     3
/** @file aircraft_gui.cpp */
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"
2163
b17b313113a0 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
     9
#include "functions.h"
1922
bda6f85eefaa (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1907
diff changeset
    10
#include "table/sprites.h"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 382
diff changeset
    11
#include "table/strings.h"
7266
b16e67e992b4 (svn r10587) -Codechange: move the string/dparam related stuff from variables.h to strings.h
rubidium
parents: 7134
diff changeset
    12
#include "strings.h"
679
04ca2cd69420 (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 588
diff changeset
    13
#include "map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "window.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "gui.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
#include "engine.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
#include "player.h"
1313
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
    22
#include "depot.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2113
diff changeset
    23
#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
    24
#include "newgrf_engine.h"
4787
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    25
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
    26
/**
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
* 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
    28
*
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
* @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
    30
* @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
    31
* @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
    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
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
    34
{
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
	int y_offset = (v->Next()->cargo_cap != 0) ? -11 : 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
    36
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
	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
    38
		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
    39
			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
    40
			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
    41
			SetDParam(2, u->value);
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
			DrawString(x, y, STR_A011_BUILT_VALUE, 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
    43
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    44
			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
    45
			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
    46
			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
    47
			SetDParam(3, u->Next()->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
    48
			DrawString(x, y + 10, (u->Next()->cargo_cap != 0) ? STR_A019_CAPACITY : STR_A01A_CAPACITY, 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
    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
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 (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
    52
			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
    53
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
			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
    55
			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
    56
				/* 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
    57
				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
    58
				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
    59
				SetDParam(2, u->cargo.Source());
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
				DrawString(x, y + 21 + y_offset, STR_8813_FROM, 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
    61
			}
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    62
		}
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    63
	}
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
	SetDParam(0, v->cargo.FeederShare());
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
	DrawString(x, y + 33 + y_offset, STR_FEEDER_CARGO_VALUE, 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
    67
}
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    68
bfeada535347 (svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents: 7492
diff changeset
    69
5780
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    70
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
    71
{
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    72
	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
    73
	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
    74
	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
    75
		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
    76
		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
    77
		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
    78
	}
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    79
	if (v->index == selection) {
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    80
		DrawFrameRect(x - 1, y - 1, x + 58, y + 21, 0xF, FR_BORDERONLY);
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    81
	}
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    82
}
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    83
6415
cb61e1346600 (svn r9551) -Documentation: Some more doxygen work
belugas
parents: 6198
diff changeset
    84
/**
cb61e1346600 (svn r9551) -Documentation: Some more doxygen work
belugas
parents: 6198
diff changeset
    85
 * 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
    86
 * @param success indicates completion (or not) of the operation
cb61e1346600 (svn r9551) -Documentation: Some more doxygen work
belugas
parents: 6198
diff changeset
    87
 * @param tile of depot where aircraft is built
cb61e1346600 (svn r9551) -Documentation: Some more doxygen work
belugas
parents: 6198
diff changeset
    88
 * @param p1 unused
cb61e1346600 (svn r9551) -Documentation: Some more doxygen work
belugas
parents: 6198
diff changeset
    89
 * @param p2 unused
cb61e1346600 (svn r9551) -Documentation: Some more doxygen work
belugas
parents: 6198
diff changeset
    90
 */
5780
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    91
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
    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 (success) {
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    94
		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
    95
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
    96
		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
    97
			_backup_orders_tile = 0;
7653
dd252420d9c2 (svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents: 7530
diff changeset
    98
			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
    99
		}
7486
bf6a94009823 (svn r10997) -Codechange: unify the vehicle view window. Patch by PhilSophus.
rubidium
parents: 7484
diff changeset
   100
		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
   101
	}
b16aec7650c2 (svn r8332) -Codechange: moved DrawAircraftImage() and CcBuildAircraft() from build_vehicle_gui.cpp to aircraft_gui.cpp
bjarni
parents: 5668
diff changeset
   102
}