(svn r243) -Fix: [1022689] When destroying a part of a train with a 2 side engine the second engine was also deleted [Celestar]
This commit is contained in:
		
							
								
								
									
										14
									
								
								train_cmd.c
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								train_cmd.c
									
									
									
									
									
								
							| @@ -773,6 +773,16 @@ int32 CmdSellRailWagon(int x, int y, uint32 flags, uint32 p1, uint32 p2) | |||||||
| 	first = v; | 	first = v; | ||||||
| 	if (first->subtype != 0) { | 	if (first->subtype != 0) { | ||||||
| 		first = GetFirstVehicleInChain(first); | 		first = GetFirstVehicleInChain(first); | ||||||
|  | 		last = GetLastVehicleInChain(first); | ||||||
|  | 		//now if: | ||||||
|  | 		// 1) we delete a whole a chain, and | ||||||
|  | 		// 2) the first and the last vehicle of that train are of the same type, and | ||||||
|  | 		// 3) the first and the last vehicle of the chain are not identical, and | ||||||
|  | 		// 4) and of "engine" type (i.e. not a carriage) | ||||||
|  | 		// then let the last vehicle live | ||||||
|  | 		if ( (p2 == 1) && ( last->engine_type == first->engine_type ) && (last != first) && (first->subtype == 0) ) | ||||||
|  | 			last = GetPrevVehicleInChain(last); | ||||||
|  | 		else | ||||||
| 			last = NULL; | 			last = NULL; | ||||||
| 	} else { | 	} else { | ||||||
| 		if (p2 != 1) { | 		if (p2 != 1) { | ||||||
| @@ -825,7 +835,7 @@ int32 CmdSellRailWagon(int x, int y, uint32 flags, uint32 p1, uint32 p2) | |||||||
| 			tmp = v; | 			tmp = v; | ||||||
| 			v = v->next; | 			v = v->next; | ||||||
| 			DeleteVehicle(tmp); | 			DeleteVehicle(tmp); | ||||||
| 			if (v == NULL || p2 != 1) break; | 			if (v == last || p2 != 1) break; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		// delete last vehicle of multiheaded train? | 		// delete last vehicle of multiheaded train? | ||||||
| @@ -844,7 +854,7 @@ int32 CmdSellRailWagon(int x, int y, uint32 flags, uint32 p1, uint32 p2) | |||||||
| 		cost = 0; | 		cost = 0; | ||||||
| 		for(;;) { | 		for(;;) { | ||||||
| 			cost -= v->value; | 			cost -= v->value; | ||||||
| 			if ((v=v->next) == NULL || p2 != 1) break; | 			if ((v=v->next) == last || p2 != 1) break; | ||||||
| 		} | 		} | ||||||
| 		if (last) cost -= last->value; | 		if (last) cost -= last->value; | ||||||
| 	} | 	} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 signde
					signde