src/autoreplace_gui.cpp
branchNewGRF_ports
changeset 6720 35756db7e577
parent 6719 4cc327ad39d5
child 6725 23339968083f
equal deleted inserted replaced
6719:4cc327ad39d5 6720:35756db7e577
    36 	_railtype_selected_in_replace_gui = RAILTYPE_RAIL;
    36 	_railtype_selected_in_replace_gui = RAILTYPE_RAIL;
    37 }
    37 }
    38 
    38 
    39 /** Rebuild the left autoreplace list if an engine is removed or added
    39 /** Rebuild the left autoreplace list if an engine is removed or added
    40  * @param e Engine to check if it is removed or added
    40  * @param e Engine to check if it is removed or added
       
    41  * @param id_g The group the engine belongs to
    41  *  Note: this function only works if it is called either
    42  *  Note: this function only works if it is called either
    42  *   - when a new vehicle is build, but before it's counted in num_engines
    43  *   - when a new vehicle is build, but before it's counted in num_engines
    43  *   - when a vehicle is deleted and after it's substracted from num_engines
    44  *   - when a vehicle is deleted and after it's substracted from num_engines
    44  *   - when not changing the count (used when changing replace orders)
    45  *   - when not changing the count (used when changing replace orders)
    45  */
    46  */
    46 void InvalidateAutoreplaceWindow(EngineID e)
    47 void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g)
    47 {
    48 {
    48 	Player *p = GetPlayer(_local_player);
    49 	Player *p = GetPlayer(_local_player);
    49 	byte type = GetEngine(e)->type;
    50 	byte type = GetEngine(e)->type;
    50 
    51 	uint num_engines = IsDefaultGroupID(id_g) ? p->num_engines[e] : GetGroup(id_g)->num_engines[e];
    51 	if (p->num_engines[e] == 0) {
    52 
       
    53 	if (num_engines == 0 || p->num_engines[e] == 0) {
    52 		/* We don't have any of this engine type.
    54 		/* We don't have any of this engine type.
    53 		 * 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.
    54 		 * In all cases, we need to update the left list */
    56 		 * In all cases, we need to update the left list */
    55 		_rebuild_left_list = true;
    57 		_rebuild_left_list = true;
    56 	} else {
    58 	} else {
   286 			/* sets up the string for the vehicle that is being replaced to */
   288 			/* sets up the string for the vehicle that is being replaced to */
   287 			if (selected_id[0] != INVALID_ENGINE) {
   289 			if (selected_id[0] != INVALID_ENGINE) {
   288 				if (!EngineHasReplacementForPlayer(p, selected_id[0], selected_group)) {
   290 				if (!EngineHasReplacementForPlayer(p, selected_id[0], selected_group)) {
   289 					SetDParam(0, STR_NOT_REPLACING);
   291 					SetDParam(0, STR_NOT_REPLACING);
   290 				} else {
   292 				} else {
   291 					SetDParam(0, GetCustomEngineName(EngineReplacementForPlayer(p, selected_id[0], selected_group)));
   293 					SetDParam(0, STR_ENGINE_NAME);
       
   294 					SetDParam(1, EngineReplacementForPlayer(p, selected_id[0], selected_group));
   292 				}
   295 				}
   293 			} else {
   296 			} else {
   294 				SetDParam(0, STR_NOT_REPLACING_VEHICLE_SELECTED);
   297 				SetDParam(0, STR_NOT_REPLACING_VEHICLE_SELECTED);
   295 			}
   298 			}
   296 
   299