src/autoreplace_gui.cpp
branchNewGRF_ports
changeset 6725 23339968083f
parent 6720 35756db7e577
child 6743 cabfaa4a0295
equal deleted inserted replaced
6724:cfa62b4744d4 6725:23339968083f
     6 #include "openttd.h"
     6 #include "openttd.h"
     7 #include "debug.h"
     7 #include "debug.h"
     8 #include "functions.h"
     8 #include "functions.h"
     9 #include "table/sprites.h"
     9 #include "table/sprites.h"
    10 #include "table/strings.h"
    10 #include "table/strings.h"
       
    11 #include "strings.h"
    11 #include "window.h"
    12 #include "window.h"
    12 #include "gui.h"
    13 #include "gui.h"
    13 #include "command.h"
    14 #include "command.h"
    14 #include "variables.h"
    15 #include "variables.h"
    15 #include "vehicle_gui.h"
    16 #include "vehicle_gui.h"
    46  */
    47  */
    47 void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g)
    48 void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g)
    48 {
    49 {
    49 	Player *p = GetPlayer(_local_player);
    50 	Player *p = GetPlayer(_local_player);
    50 	byte type = GetEngine(e)->type;
    51 	byte type = GetEngine(e)->type;
    51 	uint num_engines = IsDefaultGroupID(id_g) ? p->num_engines[e] : GetGroup(id_g)->num_engines[e];
    52 	uint num_engines = GetGroupNumEngines(id_g, e);
    52 
    53 
    53 	if (num_engines == 0 || p->num_engines[e] == 0) {
    54 	if (num_engines == 0 || p->num_engines[e] == 0) {
    54 		/* We don't have any of this engine type.
    55 		/* 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.
    56 		 * 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 */
    57 		 * In all cases, we need to update the left list */
   138  * @param w Window, that contains the list
   139  * @param w Window, that contains the list
   139  * @param draw_left true if generating the left list, otherwise false
   140  * @param draw_left true if generating the left list, otherwise false
   140  */
   141  */
   141 static void GenerateReplaceVehList(Window *w, bool draw_left)
   142 static void GenerateReplaceVehList(Window *w, bool draw_left)
   142 {
   143 {
   143 	Player *p = GetPlayer(_local_player);
       
   144 	EngineID e;
   144 	EngineID e;
   145 	EngineID selected_engine = INVALID_ENGINE;
   145 	EngineID selected_engine = INVALID_ENGINE;
   146 	byte type = w->window_number;
   146 	byte type = w->window_number;
   147 	byte i = draw_left ? 0 : 1;
   147 	byte i = draw_left ? 0 : 1;
   148 
   148 
   152 	FOR_ALL_ENGINEIDS_OF_TYPE(e, type) {
   152 	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
   153 		if (type == VEH_TRAIN && !GenerateReplaceRailList(e, draw_left, WP(w, replaceveh_d).wagon_btnstate)) continue; // special rules for trains
   154 
   154 
   155 		if (draw_left) {
   155 		if (draw_left) {
   156 			const GroupID selected_group = WP(w, replaceveh_d).sel_group;
   156 			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];
   157 			const uint num_engines = GetGroupNumEngines(selected_group, e);
   158 
   158 
   159 			/* Skip drawing the engines we don't have any of and haven't set for replacement */
   159 			/* 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;
   160 			if (num_engines == 0 && EngineReplacementForPlayer(GetPlayer(_local_player), e, selected_group) == INVALID_ENGINE) continue;
   161 		} else {
   161 		} else {
   162 			/* This is for engines we can replace to and they should depend on what we selected to replace from */
   162 			/* This is for engines we can replace to and they should depend on what we selected to replace from */