12 #include "engine.h" |
12 #include "engine.h" |
13 |
13 |
14 |
14 |
15 int _traininfo_vehicle_pitch = 0; |
15 int _traininfo_vehicle_pitch = 0; |
16 |
16 |
17 static Engine * const _rail_engines[3] = { |
|
18 &_engines[0], |
|
19 &_engines[NUM_NORMAL_RAIL_ENGINES], |
|
20 &_engines[NUM_MONORAIL_ENGINES + NUM_NORMAL_RAIL_ENGINES], |
|
21 }; |
|
22 |
|
23 const byte _rail_engines_count[3] = { |
|
24 NUM_NORMAL_RAIL_ENGINES, |
|
25 NUM_MONORAIL_ENGINES, |
|
26 NUM_MAGLEV_ENGINES, |
|
27 }; |
|
28 |
|
29 const byte _rail_engines_start[3] = { |
|
30 0, |
|
31 NUM_NORMAL_RAIL_ENGINES, |
|
32 NUM_MONORAIL_ENGINES + NUM_NORMAL_RAIL_ENGINES, |
|
33 }; |
|
34 |
17 |
35 static void CcBuildWagon(bool success, uint tile, uint32 p1, uint32 p2) |
18 static void CcBuildWagon(bool success, uint tile, uint32 p1, uint32 p2) |
36 { |
19 { |
37 Vehicle *v,*found; |
20 Vehicle *v,*found; |
38 |
21 |
83 if (w->window_number == 0) |
66 if (w->window_number == 0) |
84 SETBIT(w->disabled_state, 5); |
67 SETBIT(w->disabled_state, 5); |
85 |
68 |
86 { |
69 { |
87 int count = 0; |
70 int count = 0; |
88 int num = _rail_engines_count[WP(w,buildtrain_d).railtype]; |
71 byte railtype = WP(w,buildtrain_d).railtype; |
89 Engine *e = _rail_engines[WP(w,buildtrain_d).railtype]; |
72 int i; |
90 do { |
73 |
91 if (HASBIT(e->player_avail, _local_player)) |
74 for (i = 0; i < NUM_TRAIN_ENGINES; i++) { |
|
75 Engine *e = &_engines[i]; |
|
76 if (e->railtype == railtype |
|
77 && HASBIT(e->player_avail, _local_player)) |
92 count++; |
78 count++; |
93 } while (++e,--num); |
79 } |
94 SetVScrollCount(w, count); |
80 SetVScrollCount(w, count); |
95 } |
81 } |
96 |
82 |
97 SET_DPARAM16(0, WP(w,buildtrain_d).railtype + STR_881C_NEW_RAIL_VEHICLES); |
83 SET_DPARAM16(0, WP(w,buildtrain_d).railtype + STR_881C_NEW_RAIL_VEHICLES); |
98 DrawWindowWidgets(w); |
84 DrawWindowWidgets(w); |
99 |
85 |
100 { |
86 { |
101 int num = _rail_engines_count[WP(w,buildtrain_d).railtype]; |
87 byte railtype = WP(w,buildtrain_d).railtype; |
102 Engine *e = _rail_engines[WP(w,buildtrain_d).railtype]; |
|
103 int sel = WP(w,buildtrain_d).sel_index; |
88 int sel = WP(w,buildtrain_d).sel_index; |
104 int pos = w->vscroll.pos; |
89 int pos = w->vscroll.pos; |
105 int x = 1; |
90 int x = 1; |
106 int y = 15; |
91 int y = 15; |
107 int engine_id = _rail_engines_start[WP(w,buildtrain_d).railtype]; |
|
108 int selected_id = -1; |
92 int selected_id = -1; |
109 |
93 int i; |
110 do { |
94 |
111 if (HASBIT(e->player_avail, _local_player)) { |
95 /* Ensure that custom engines which substituted wagons |
112 if (sel==0) selected_id = engine_id; |
96 * are sorted correctly. */ |
113 if (IS_INT_INSIDE(--pos, -8, 0)) { |
97 #define engine_drawing_loop(cmp_) \ |
114 DrawString(x+59, y+2, GetCustomEngineName(engine_id), sel==0 ? 0xC : 0x10); |
98 for (i = 0; i < NUM_TRAIN_ENGINES; i++) { \ |
115 DrawTrainEngine(x+29, y+6+_traininfo_vehicle_pitch, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player))); |
99 Engine *e = DEREF_ENGINE(i); \ |
116 y += 14; |
100 RailVehicleInfo *rvi = &rail_vehinfo(i); \ |
117 } |
101 \ |
118 sel--; |
102 if (e->railtype != railtype || (rvi->flags & RVI_WAGON) cmp_ 0 \ |
119 } |
103 || !HASBIT(e->player_avail, _local_player)) \ |
120 } while (++engine_id, ++e,--num); |
104 continue; \ |
|
105 \ |
|
106 if (sel == 0) selected_id = i; \ |
|
107 if (IS_INT_INSIDE(--pos, -8, 0)) { \ |
|
108 DrawString(x+59, y+2, GetCustomEngineName(i), sel == 0 ? 0xC : 0x10); \ |
|
109 DrawTrainEngine(x+29, y+6+_traininfo_vehicle_pitch, i, \ |
|
110 SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player))); \ |
|
111 y += 14; \ |
|
112 } \ |
|
113 sel--; \ |
|
114 } |
|
115 |
|
116 engine_drawing_loop(!=); // True engines |
|
117 engine_drawing_loop(==); // Feeble wagons |
121 |
118 |
122 WP(w,buildtrain_d).sel_engine = selected_id; |
119 WP(w,buildtrain_d).sel_engine = selected_id; |
123 |
120 |
124 if (selected_id != -1) { |
121 if (selected_id != -1) { |
125 const RailVehicleInfo *rvi = &_rail_vehicle_info[selected_id]; |
122 const RailVehicleInfo *rvi = &_rail_vehicle_info[selected_id]; |