1 /* 2 * Copyright (c) 1997 - 2001 Hansj�rg Malthaner 3 * 4 * This file is part of the Simutrans project under the artistic licence. 5 * (see licence.txt) 6 */ 7 8 #ifndef boden_wege_schiene_h 9 #define boden_wege_schiene_h 10 11 12 #include "weg.h" 13 #include "../../convoihandle_t.h" 14 15 class vehicle_t; 16 17 /** 18 * Class for Rails in Simutrans. 19 * Trains can run over rails. 20 * Every rail belongs to a section block 21 * 22 * @author Hj. Malthaner 23 */ 24 class schiene_t : public weg_t 25 { 26 protected: 27 /** 28 * Bound when this block was successfully reserved by the convoi 29 * @author prissi 30 */ 31 convoihandle_t reserved; 32 33 public: 34 static const way_desc_t *default_schiene; 35 36 static bool show_reservations; 37 38 /** 39 * File loading constructor. 40 * @author Hj. Malthaner 41 */ 42 schiene_t(loadsave_t *file); 43 44 schiene_t(); 45 get_waytype()46 waytype_t get_waytype() const OVERRIDE {return track_wt;} 47 48 /** 49 * @return additional info is reservation! 50 * @author prissi 51 */ 52 void info(cbuffer_t & buf) const OVERRIDE; 53 54 /** 55 * true, if this rail can be reserved 56 * @author prissi 57 */ can_reserve(convoihandle_t c)58 bool can_reserve(convoihandle_t c) const { return !reserved.is_bound() || c==reserved; } 59 60 /** 61 * true, if this rail can be reserved 62 * @author prissi 63 */ is_reserved()64 bool is_reserved() const { return reserved.is_bound(); } 65 66 /** 67 * true, then this rail was reserved 68 * @author prissi 69 */ 70 bool reserve(convoihandle_t c, ribi_t::ribi dir); 71 72 /** 73 * releases previous reservation 74 * @author prissi 75 */ 76 virtual bool unreserve( convoihandle_t c); 77 78 /** 79 * releases previous reservation 80 * @author prissi 81 */ unreserve(vehicle_t *)82 bool unreserve( vehicle_t *) { return unreserve(reserved); } 83 84 /* called before deletion; 85 * last chance to unreserve tiles ... 86 */ 87 void cleanup(player_t *player) OVERRIDE; 88 89 /** 90 * gets the related convoi 91 * @author prissi 92 */ get_reserved_convoi()93 convoihandle_t get_reserved_convoi() const {return reserved;} 94 95 void rdwr(loadsave_t *file) OVERRIDE; 96 97 /** 98 * if a function return here a value with TRANSPARENT_FLAGS set 99 * then a transparent outline with the color form the lower 8 Bit is drawn 100 * @author kierongreen 101 */ get_outline_colour()102 FLAGGED_PIXVAL get_outline_colour() const OVERRIDE { return (show_reservations && reserved.is_bound()) ? TRANSPARENT75_FLAG | OUTLINE_FLAG | color_idx_to_rgb(COL_RED) : 0;} 103 104 /* 105 * to show reservations if needed 106 */ get_outline_image()107 image_id get_outline_image() const OVERRIDE { return weg_t::get_image(); } 108 }; 109 110 111 template<> inline schiene_t* obj_cast<schiene_t>(obj_t* const d) 112 { 113 return dynamic_cast<schiene_t*>(d); 114 } 115 116 #endif 117