equal
deleted
inserted
replaced
46 */ |
46 */ |
47 void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g) |
47 void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g) |
48 { |
48 { |
49 Player *p = GetPlayer(_local_player); |
49 Player *p = GetPlayer(_local_player); |
50 byte type = GetEngine(e)->type; |
50 byte type = GetEngine(e)->type; |
51 uint num_engines = IsDefaultGroupID(id_g) ? p->num_engines[e] : GetGroup(id_g)->num_engines[e]; |
51 uint num_engines = GetGroupNumEngines(id_g, e); |
52 |
52 |
53 if (num_engines == 0 || p->num_engines[e] == 0) { |
53 if (num_engines == 0 || p->num_engines[e] == 0) { |
54 /* We don't have any of this engine type. |
54 /* We don't have any of this engine type. |
55 * Either we just sold the last one, we build a new one or we stopped replacing it. |
55 * Either we just sold the last one, we build a new one or we stopped replacing it. |
56 * In all cases, we need to update the left list */ |
56 * In all cases, we need to update the left list */ |
138 * @param w Window, that contains the list |
138 * @param w Window, that contains the list |
139 * @param draw_left true if generating the left list, otherwise false |
139 * @param draw_left true if generating the left list, otherwise false |
140 */ |
140 */ |
141 static void GenerateReplaceVehList(Window *w, bool draw_left) |
141 static void GenerateReplaceVehList(Window *w, bool draw_left) |
142 { |
142 { |
143 Player *p = GetPlayer(_local_player); |
|
144 EngineID e; |
143 EngineID e; |
145 EngineID selected_engine = INVALID_ENGINE; |
144 EngineID selected_engine = INVALID_ENGINE; |
146 byte type = w->window_number; |
145 byte type = w->window_number; |
147 byte i = draw_left ? 0 : 1; |
146 byte i = draw_left ? 0 : 1; |
148 |
147 |
152 FOR_ALL_ENGINEIDS_OF_TYPE(e, type) { |
151 FOR_ALL_ENGINEIDS_OF_TYPE(e, type) { |
153 if (type == VEH_TRAIN && !GenerateReplaceRailList(e, draw_left, WP(w, replaceveh_d).wagon_btnstate)) continue; // special rules for trains |
152 if (type == VEH_TRAIN && !GenerateReplaceRailList(e, draw_left, WP(w, replaceveh_d).wagon_btnstate)) continue; // special rules for trains |
154 |
153 |
155 if (draw_left) { |
154 if (draw_left) { |
156 const GroupID selected_group = WP(w, replaceveh_d).sel_group; |
155 const GroupID selected_group = WP(w, replaceveh_d).sel_group; |
157 const uint num_engines = IsDefaultGroupID(selected_group) ? p->num_engines[e] : GetGroup(selected_group)->num_engines[e]; |
156 const uint num_engines = GetGroupNumEngines(selected_group, e); |
158 |
157 |
159 /* Skip drawing the engines we don't have any of and haven't set for replacement */ |
158 /* Skip drawing the engines we don't have any of and haven't set for replacement */ |
160 if (num_engines == 0 && EngineReplacementForPlayer(GetPlayer(_local_player), e, selected_group) == INVALID_ENGINE) continue; |
159 if (num_engines == 0 && EngineReplacementForPlayer(GetPlayer(_local_player), e, selected_group) == INVALID_ENGINE) continue; |
161 } else { |
160 } else { |
162 /* This is for engines we can replace to and they should depend on what we selected to replace from */ |
161 /* This is for engines we can replace to and they should depend on what we selected to replace from */ |