waypoint.cpp

Go to the documentation of this file.
00001 /* $Id: waypoint.cpp 15704 2009-03-13 23:48:07Z smatz $ */
00002 
00005 #include "stdafx.h"
00006 
00007 #include "strings_type.h"
00008 #include "rail.h"
00009 #include "station_base.h"
00010 #include "town.h"
00011 #include "waypoint.h"
00012 #include "window_func.h"
00013 #include "newgrf_station.h"
00014 #include "oldpool_func.h"
00015 #include "order_func.h"
00016 
00017 DEFINE_OLD_POOL_GENERIC(Waypoint, Waypoint)
00018 
00019 
00022 void UpdateAllWaypointSigns()
00023 {
00024   Waypoint *wp;
00025 
00026   FOR_ALL_WAYPOINTS(wp) {
00027     UpdateWaypointSign(wp);
00028   }
00029 }
00030 
00034 void WaypointsDailyLoop()
00035 {
00036   Waypoint *wp;
00037 
00038   /* Check if we need to delete a waypoint */
00039   FOR_ALL_WAYPOINTS(wp) {
00040     if (wp->deleted != 0 && --wp->deleted == 0) delete wp;
00041   }
00042 }
00043 
00049 Station *ComposeWaypointStation(TileIndex tile)
00050 {
00051   Waypoint *wp = GetWaypointByTile(tile);
00052 
00053   /* instead of 'static Station stat' use byte array to avoid Station's destructor call upon exit. As
00054    * a side effect, the station is not constructed now. */
00055   static byte stat_raw[sizeof(Station)];
00056   static Station &stat = *(Station*)stat_raw;
00057 
00058   stat.train_tile = stat.xy = wp->xy;
00059   stat.town = GetTown(wp->town_index);
00060   stat.build_date = wp->build_date;
00061 
00062   return &stat;
00063 }
00064 
00072 void DrawWaypointSprite(int x, int y, int stat_id, RailType railtype)
00073 {
00074   x += 33;
00075   y += 17;
00076 
00077   if (!DrawStationTile(x, y, railtype, AXIS_X, STAT_CLASS_WAYP, stat_id)) {
00078     DrawDefaultWaypointSprite(x, y, railtype);
00079   }
00080 }
00081 
00082 Waypoint::Waypoint(TileIndex tile)
00083 {
00084   this->xy = tile;
00085 }
00086 
00087 Waypoint::~Waypoint()
00088 {
00089   free(this->name);
00090 
00091   if (CleaningPool()) return;
00092   DeleteWindowById(WC_WAYPOINT_VIEW, this->index);
00093   RemoveOrderFromAllVehicles(OT_GOTO_WAYPOINT, this->index);
00094 
00095   RedrawWaypointSign(this);
00096   this->xy = INVALID_TILE;
00097 }
00098 
00099 void InitializeWaypoints()
00100 {
00101   _Waypoint_pool.CleanPool();
00102   _Waypoint_pool.AddBlockToPool();
00103 }

Generated on Wed Jul 15 20:36:04 2009 for OpenTTD by  doxygen 1.5.6