roadveh_gui.cpp

Go to the documentation of this file.
00001 /* $Id: roadveh_gui.cpp 14267 2008-09-07 21:41:47Z rubidium $ */
00002 
00005 #include "stdafx.h"
00006 #include "openttd.h"
00007 #include "debug.h"
00008 #include "roadveh.h"
00009 #include "gui.h"
00010 #include "window_gui.h"
00011 #include "viewport_func.h"
00012 #include "gfx_func.h"
00013 #include "command_func.h"
00014 #include "depot.h"
00015 #include "vehicle_gui.h"
00016 #include "newgrf_engine.h"
00017 #include "strings_func.h"
00018 #include "vehicle_func.h"
00019 #include "string_func.h"
00020 
00021 #include "table/sprites.h"
00022 #include "table/strings.h"
00023 
00024 void DrawRoadVehDetails(const Vehicle *v, int x, int y)
00025 {
00026   uint y_offset = RoadVehHasArticPart(v) ? 15 : 0;
00027   StringID str;
00028   Money feeder_share = 0;
00029 
00030   SetDParam(0, v->engine_type);
00031   SetDParam(1, v->build_year);
00032   SetDParam(2, v->value);
00033   DrawString(x, y + y_offset, STR_9011_BUILT_VALUE, TC_FROMSTRING);
00034 
00035   if (RoadVehHasArticPart(v)) {
00036     AcceptedCargo max_cargo;
00037     char capacity[512];
00038 
00039     memset(max_cargo, 0, sizeof(max_cargo));
00040 
00041     for (const Vehicle *u = v; u != NULL; u = u->Next()) {
00042       max_cargo[u->cargo_type] += u->cargo_cap;
00043     }
00044 
00045     GetString(capacity, STR_ARTICULATED_RV_CAPACITY, lastof(capacity));
00046 
00047     bool first = true;
00048     for (CargoID i = 0; i < NUM_CARGO; i++) {
00049       if (max_cargo[i] > 0) {
00050         char buffer[128];
00051 
00052         SetDParam(0, i);
00053         SetDParam(1, max_cargo[i]);
00054         GetString(buffer, STR_BARE_CARGO, lastof(buffer));
00055 
00056         if (!first) strecat(capacity, ", ", lastof(capacity));
00057         strecat(capacity, buffer, lastof(capacity));
00058         first = false;
00059       }
00060     }
00061 
00062     SetDParamStr(0, capacity);
00063     DrawStringTruncated(x, y + 10 + y_offset, STR_JUST_STRING, TC_BLUE, 380 - x);
00064 
00065     for (const Vehicle *u = v; u != NULL; u = u->Next()) {
00066       if (u->cargo_cap == 0) continue;
00067 
00068       str = STR_8812_EMPTY;
00069       if (!u->cargo.Empty()) {
00070         SetDParam(0, u->cargo_type);
00071         SetDParam(1, u->cargo.Count());
00072         SetDParam(2, u->cargo.Source());
00073         str = STR_8813_FROM;
00074         feeder_share += u->cargo.FeederShare();
00075       }
00076       DrawString(x, y + 21 + y_offset, str, TC_FROMSTRING);
00077 
00078       y_offset += 11;
00079     }
00080 
00081     y_offset -= 11;
00082   } else {
00083     SetDParam(0, v->cargo_type);
00084     SetDParam(1, v->cargo_cap);
00085     DrawString(x, y + 10 + y_offset, STR_9012_CAPACITY, TC_FROMSTRING);
00086 
00087     str = STR_8812_EMPTY;
00088     if (!v->cargo.Empty()) {
00089       SetDParam(0, v->cargo_type);
00090       SetDParam(1, v->cargo.Count());
00091       SetDParam(2, v->cargo.Source());
00092       str = STR_8813_FROM;
00093       feeder_share += v->cargo.FeederShare();
00094     }
00095     DrawString(x, y + 21 + y_offset, str, TC_FROMSTRING);
00096   }
00097 
00098   /* Draw Transfer credits text */
00099   SetDParam(0, feeder_share);
00100   DrawString(x, y + 33 + y_offset, STR_FEEDER_CARGO_VALUE, TC_FROMSTRING);
00101 }
00102 
00103 
00104 static inline int RoadVehLengthToPixels(int length)
00105 {
00106   return (length * 28) / 8;
00107 }
00108 
00109 void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection, int count)
00110 {
00111   /* Road vehicle lengths are measured in eighths of the standard length, so
00112    * count is the number of standard vehicles that should be drawn. If it is
00113    * 0, we draw enough vehicles for 10 standard vehicle lengths. */
00114   int max_length = (count == 0) ? 80 : count * 8;
00115 
00116   for (int dx = 0 ; v != NULL && dx < max_length ; dx += v->u.road.cached_veh_length, v = v->Next()) {
00117     if (dx + v->u.road.cached_veh_length > 0 && dx <= max_length) {
00118       SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
00119       DrawSprite(v->GetImage(DIR_W), pal, x + 14 + RoadVehLengthToPixels(dx), y + 6);
00120 
00121       if (v->index == selection) {
00122         DrawFrameRect(x - 1, y - 1, x + 28, y + 12, 15, FR_BORDERONLY);
00123       }
00124     }
00125   }
00126 }
00127 
00128 void CcBuildRoadVeh(bool success, TileIndex tile, uint32 p1, uint32 p2)
00129 {
00130   const Vehicle *v;
00131 
00132   if (!success) return;
00133 
00134   v = GetVehicle(_new_vehicle_id);
00135   if (v->tile == _backup_orders_tile) {
00136     _backup_orders_tile = 0;
00137     RestoreVehicleOrders(v);
00138   }
00139   ShowVehicleViewWindow(v);
00140 }

Generated on Mon Sep 22 20:34:18 2008 for openttd by  doxygen 1.5.6