src/autoreplace_gui.cpp
branchnoai
changeset 9631 8a2d1c2ceb88
parent 9629 66dde6412125
child 9686 d3c195c226f9
equal deleted inserted replaced
9630:550db5cefcc2 9631:8a2d1c2ceb88
    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 {