1 #ifndef SIMROADTRAFFIC_H
2 #define SIMROADTRAFFIC_H
3 
4 /**
5  * Moving objects for Simutrans.
6  * Transport vehicles are defined in simvehicle.h, because they greatly
7  * differ from the vehicles defined herein for the individual traffic
8  * (pedestrians, citycars, movingobj aka flock of sheep).
9  *
10  * Hj. Malthaner
11  *
12  * April 2000
13  */
14 
15 #include "simvehicle.h"
16 #include "overtaker.h"
17 
18 #include "../tpl/stringhashtable_tpl.h"
19 #include "../ifc/sync_steppable.h"
20 
21 class citycar_desc_t;
22 class karte_t;
23 
24 /**
25  * Base class for traffic participants with random movement
26  * @author Hj. Malthaner
27  */
28 class road_user_t : public vehicle_base_t, public sync_steppable
29 {
30 protected:
31 	/**
32 	 * Distance count
33 	 * @author Hj. Malthaner
34 	 */
35 	uint32 weg_next;
36 
37 	/* ms until destruction
38 	 */
39 	sint32 time_to_life;
40 
41 protected:
get_waytype()42 	waytype_t get_waytype() const OVERRIDE { return road_wt; }
43 
44 	road_user_t();
45 
46 	/**
47 	 * Creates thing at position given by @p gr.
48 	 * Does not add it to the tile!
49 	 * @param random number to compute initial direction.
50 	 */
51 	road_user_t(grund_t* gr, uint16 random);
52 
53 public:
54 	virtual ~road_user_t();
55 
56 	const char *get_name() const OVERRIDE = 0;
57 	typ get_typ() const OVERRIDE  = 0;
58 
59 	/**
60 	 * Open a new observation window for the object.
61 	 * @author Hj. Malthaner
62 	 */
63 	void show_info() OVERRIDE;
64 
65 	void rdwr(loadsave_t *file) OVERRIDE;
66 
67 	// finalizes direction
68 	void finish_rd() OVERRIDE;
69 
70 	// we allow to remove all cars etc.
is_deletable(const player_t *)71 	const char *is_deletable(const player_t *) OVERRIDE { return NULL; }
72 };
73 
74 
75 class private_car_t : public road_user_t, public overtaker_t
76 {
77 private:
78 	static stringhashtable_tpl<const citycar_desc_t *> table;
79 
80 	const citycar_desc_t *desc;
81 
82 	// prissi: time to life in blocks
83 #ifdef DESTINATION_CITYCARS
84 	koord target;
85 #endif
86 	koord3d pos_next_next;
87 
88 	/**
89 	 * Actual speed
90 	 * @author Hj. Malthaner
91 	 */
92 	uint16 current_speed;
93 
94 	uint32 ms_traffic_jam;
95 
96 	grund_t* hop_check() OVERRIDE;
97 
98 	void calc_disp_lane();
99 
100 protected:
101 	void rdwr(loadsave_t *file) OVERRIDE;
102 
103 	void calc_image() OVERRIDE;
104 
105 public:
106 	private_car_t(loadsave_t *file);
107 
108 	/**
109 	 * Creates citycar at position given by @p gr.
110 	 * Does not add car to the tile!
111 	 */
112 	private_car_t(grund_t* gr, koord target);
113 
114 	virtual ~private_car_t();
115 
116 	void rotate90() OVERRIDE;
117 
get_desc()118 	const citycar_desc_t *get_desc() const { return desc; }
119 
120 	sync_result sync_step(uint32 delta_t) OVERRIDE;
121 
122 	void hop(grund_t *gr) OVERRIDE;
123 	bool ist_weg_frei(grund_t *gr);
124 
125 	void enter_tile(grund_t* gr) OVERRIDE;
126 
127 	void calc_current_speed(grund_t*);
get_current_speed()128 	uint16 get_current_speed() const {return current_speed;}
129 
get_name()130 	const char *get_name() const OVERRIDE {return "Verkehrsteilnehmer";}
get_typ()131 	typ get_typ() const OVERRIDE { return road_user; }
132 
133 	/**
134 	 * @return a description string for the object
135 	 * e.g. for the observation window/dialog
136 	 * @author Hj. Malthaner
137 	 * @see simwin
138 	 */
139 	void info(cbuffer_t & buf) const OVERRIDE;
140 
141 	// true, if this vehicle did not moved for some time
is_stuck()142 	bool is_stuck() OVERRIDE { return current_speed==0;}
143 
144 	/* this function builds the list of the allowed citycars
145 	 * it should be called every month and in the beginning of a new game
146 	 * @author prissi
147 	 */
148 	static void build_timeline_list(karte_t *welt);
149 	static bool list_empty();
150 
151 	static bool register_desc(const citycar_desc_t *desc);
152 	static bool successfully_loaded();
153 
154 	// since we must consider overtaking, we use this for offset calculation
155 	void get_screen_offset( int &xoff, int &yoff, const sint16 raster_width ) const OVERRIDE;
156 
get_overtaker()157 	overtaker_t *get_overtaker() OVERRIDE { return this; }
158 
159 	// Overtaking for city cars
160 	bool can_overtake(overtaker_t *other_overtaker, sint32 other_speed, sint16 steps_other) OVERRIDE;
161 };
162 
163 #endif
164