summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2005-01-08 10:38:07 +0000
committerbjarni <bjarni@openttd.org>2005-01-08 10:38:07 +0000
commit4068eba111b9e3873366f1372fb17d889a4b48a1 (patch)
treedad0e4354efe906c9351f426f87e89d1f2b55d90
parent1d9d128f65d6bad85bf8fcc44766e6db3f6dbca1 (diff)
downloadopenttd-4068eba111b9e3873366f1372fb17d889a4b48a1.tar.xz
(svn r1427) fixed issue where the wrong sprite could be used if autoreplacing between single and multiheaded trains
-rw-r--r--vehicle.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/vehicle.c b/vehicle.c
index 7b59272aa..e6dd72922 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -1505,8 +1505,12 @@ int32 CmdReplaceVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
/* rvi->image_index is the new sprite for the engine. Adding +1 makes the engine head the other way
if it is a multiheaded engine (rear engine)
- (sprite - rvi2->image_index) is 1 if the engine is heading the other way, otherwise 0*/
- v->spritenum = rvi->image_index + (sprite - rvi2->image_index);
+ (rvi->flags & RVI_MULTIHEAD && sprite - rvi2->image_index) is true if the engine is heading the other way, otherwise 0*/
+ v->spritenum = rvi->image_index + (( rvi->flags & RVI_MULTIHEAD && sprite - rvi2->image_index) ? 1 : 0);
+
+ // turn the last engine in a multiheaded train if needed
+ if ( v->next == NULL && rvi->flags & RVI_MULTIHEAD && v->spritenum == rvi->image_index )
+ v->spritenum++;
v->cargo_type = rvi->cargo_type;
v->cargo_cap = rvi->capacity;