1 /*
2  * Copyright (c) 2007 prissi
3  *
4  * This file is part of the Simutrans project under the artistic licence.
5  * (see licence.txt)
6  */
7 
8 #ifndef obj_crossing_h
9 #define obj_crossing_h
10 
11 #include "../simtypes.h"
12 #include "../display/simimg.h"
13 #include "../descriptor/crossing_desc.h"
14 #include "../dataobj/crossing_logic.h"
15 
16 class vehicle_base_t;
17 
18 /**
19  * road sign for traffic (one way minimum speed, traffic lights)
20  * @author Hj. Malthaner
21  */
22 class crossing_t : public obj_no_info_t
23 {
24 protected:
25 	image_id foreground_image, image;
26 	uint8 ns;				// direction
27 	uint8 state;	// only needed for loading ...
28 	crossing_logic_t *logic;
29 	const crossing_desc_t *desc;
30 
31 public:
get_typ()32 	typ get_typ() const OVERRIDE { return crossing; }
get_name()33 	const char* get_name() const OVERRIDE { return "Kreuzung"; }
34 
35 	/**
36 	 * waytype associated with this object
37 	 * for crossings: return invalid_wt since they do not need a way
38 	 * if the way is deleted the crossing will be deleted, too
39 	 */
get_waytype()40 	waytype_t get_waytype() const OVERRIDE { return invalid_wt; }
41 
42 	crossing_t(loadsave_t *file);
43 	crossing_t(player_t *player, koord3d pos, const crossing_desc_t *desc, uint8 ns = 0);
44 
45 	/**
46 	 * crossing logic is removed here
47 	 * @author prissi
48 	 */
49 	virtual ~crossing_t();
50 
51 	void rotate90() OVERRIDE;
52 
get_desc()53 	const crossing_desc_t *get_desc() const { return desc; }
54 
55 	/**
56 	 * @return string (only used for debug at the moment)
57 	 * @author prissi
58 	 */
59 	void info(cbuffer_t & buf) const OVERRIDE;
60 
61 	/**
62 	 * @return NULL when OK, otherwise an error message
63 	 * @author Hj. Malthaner
64 	 */
65 	const char *is_deletable(const player_t *player) OVERRIDE;
66 
67 	// returns true, if the crossing can be passed by this vehicle
request_crossing(const vehicle_base_t * v)68 	bool request_crossing( const vehicle_base_t *v ) { return logic->request_crossing( v ); }
69 
70 	// adds to crossing
add_to_crossing(const vehicle_base_t * v)71 	void add_to_crossing( const vehicle_base_t *v ) { return logic->add_to_crossing( v ); }
72 
73 	// removes the vehicle from the crossing
release_crossing(const vehicle_base_t * v)74 	void release_crossing( const vehicle_base_t *v ) { return logic->release_crossing( v ); }
75 
get_state()76 	crossing_logic_t::crossing_state_t get_state() { return logic->get_state(); }
77 
78 	// called from the logic directly
79 	void state_changed();
80 
get_dir()81 	uint8 get_dir() { return ns; }
82 
set_logic(crossing_logic_t * l)83 	void set_logic( crossing_logic_t *l ) { logic = l; }
get_logic()84 	crossing_logic_t *get_logic() { return logic; }
85 
86 	/**
87 	 * Dient zur Neuberechnung des Bildes
88 	 * @author Hj. Malthaner
89 	 */
90 	void calc_image() OVERRIDE;
91 
92 	/**
93 	* Called whenever the season or snowline height changes
94 	* return false and the obj_t will be deleted
95 	*/
check_season(const bool calc_only_season_change)96 	bool check_season(const bool calc_only_season_change) OVERRIDE { if(  !calc_only_season_change  ) { calc_image(); } return true; }  // depends on snowline only
97 
98 	// changes the state of a traffic light
get_image()99 	image_id get_image() const OVERRIDE { return image; }
100 
101 	/**
102 	* For the front image hiding vehicles
103 	* @author prissi
104 	*/
get_front_image()105 	image_id get_front_image() const OVERRIDE { return foreground_image; }
106 
107 	void rdwr(loadsave_t *file) OVERRIDE;
108 
109 	void finish_rd() OVERRIDE;
110 };
111 
112 #endif
113