ship_cmd.c
changeset 3157 3f35e2d9c8e3
parent 3147 fc76d566a68e
child 3186 4317b5b295c4
equal deleted inserted replaced
3156:f4caf4197189 3157:3f35e2d9c8e3
    42 		spritenum = orig_ship_vehicle_info[engine - SHIP_ENGINES_INDEX].image_index;
    42 		spritenum = orig_ship_vehicle_info[engine - SHIP_ENGINES_INDEX].image_index;
    43 	}
    43 	}
    44 	DrawSprite((6 + _ship_sprites[spritenum]) | image_ormod, x, y);
    44 	DrawSprite((6 + _ship_sprites[spritenum]) | image_ormod, x, y);
    45 }
    45 }
    46 
    46 
    47 int GetShipImage(const Vehicle *v, byte direction)
    47 int GetShipImage(const Vehicle* v, Direction direction)
    48 {
    48 {
    49 	int spritenum = v->spritenum;
    49 	int spritenum = v->spritenum;
    50 
    50 
    51 	if (is_custom_sprite(spritenum)) {
    51 	if (is_custom_sprite(spritenum)) {
    52 		int sprite = GetCustomVehicleSprite(v, direction);
    52 		int sprite = GetCustomVehicleSprite(v, direction);
   577 			return -1;
   577 			return -1;
   578 		return track;
   578 		return track;
   579 	}
   579 	}
   580 }
   580 }
   581 
   581 
   582 static const byte _new_vehicle_direction_table[11] = {
   582 static const Direction _new_vehicle_direction_table[] = {
   583 	0, 7, 6, 0,
   583 	DIR_N , DIR_NW, DIR_W , 0,
   584 	1, 0, 5, 0,
   584 	DIR_NE, DIR_N , DIR_SW, 0,
   585 	2, 3, 4,
   585 	DIR_E , DIR_SE, DIR_S
   586 };
   586 };
   587 
   587 
   588 static int ShipGetNewDirectionFromTiles(TileIndex new_tile, TileIndex old_tile)
   588 static int ShipGetNewDirectionFromTiles(TileIndex new_tile, TileIndex old_tile)
   589 {
   589 {
   590 	uint offs = (TileY(new_tile) - TileY(old_tile) + 1) * 4 +
   590 	uint offs = (TileY(new_tile) - TileY(old_tile) + 1) * 4 +
   644 static void ShipController(Vehicle *v)
   644 static void ShipController(Vehicle *v)
   645 {
   645 {
   646 	GetNewVehiclePosResult gp;
   646 	GetNewVehiclePosResult gp;
   647 	uint32 r;
   647 	uint32 r;
   648 	const byte *b;
   648 	const byte *b;
   649 	int dir,track,tracks;
   649 	Direction dir;
       
   650 	int track;
       
   651 	int tracks;
   650 
   652 
   651 	v->tick_counter++;
   653 	v->tick_counter++;
   652 
   654 
   653 	if (v->breakdown_ctr != 0) {
   655 	if (v->breakdown_ctr != 0) {
   654 		if (v->breakdown_ctr <= 2) {
   656 		if (v->breakdown_ctr <= 2) {
   734 					}
   736 					}
   735 				}
   737 				}
   736 			}
   738 			}
   737 		}
   739 		}
   738 	} else {
   740 	} else {
       
   741 		DiagDirection diagdir;
   739 		// new tile
   742 		// new tile
   740 		if (TileX(gp.new_tile) >= MapMaxX() || TileY(gp.new_tile) >= MapMaxY())
   743 		if (TileX(gp.new_tile) >= MapMaxX() || TileY(gp.new_tile) >= MapMaxY())
   741 			goto reverse_direction;
   744 			goto reverse_direction;
   742 
   745 
   743 		dir = ShipGetNewDirectionFromTiles(gp.new_tile, gp.old_tile);
   746 		dir = ShipGetNewDirectionFromTiles(gp.new_tile, gp.old_tile);
   744 		assert(dir == 1 || dir == 3 || dir == 5 || dir == 7);
   747 		assert(dir == DIR_NE || dir == DIR_SE || dir == DIR_SW || dir == DIR_NW);
   745 		dir>>=1;
   748 		diagdir = DirToDiagDir(dir);
   746 		tracks = GetAvailShipTracks(gp.new_tile, dir);
   749 		tracks = GetAvailShipTracks(gp.new_tile, diagdir);
   747 		if (tracks == 0)
   750 		if (tracks == 0)
   748 			goto reverse_direction;
   751 			goto reverse_direction;
   749 
   752 
   750 		// Choose a direction, and continue if we find one
   753 		// Choose a direction, and continue if we find one
   751 		track = ChooseShipTrack(v, gp.new_tile, dir, tracks);
   754 		track = ChooseShipTrack(v, gp.new_tile, diagdir, tracks);
   752 		if (track < 0)
   755 		if (track < 0)
   753 			goto reverse_direction;
   756 			goto reverse_direction;
   754 
   757 
   755 		b = _ship_subcoord[dir][track];
   758 		b = _ship_subcoord[diagdir][track];
   756 
   759 
   757 		gp.x = (gp.x&~0xF) | b[0];
   760 		gp.x = (gp.x&~0xF) | b[0];
   758 		gp.y = (gp.y&~0xF) | b[1];
   761 		gp.y = (gp.y&~0xF) | b[1];
   759 
   762 
   760 		/* Call the landscape function and tell it that the vehicle entered the tile */
   763 		/* Call the landscape function and tell it that the vehicle entered the tile */
   781 	VehiclePositionChanged(v);
   784 	VehiclePositionChanged(v);
   782 	EndVehicleMove(v);
   785 	EndVehicleMove(v);
   783 	return;
   786 	return;
   784 
   787 
   785 reverse_direction:
   788 reverse_direction:
   786 	dir = v->direction ^ 4;
   789 	dir = ReverseDir(v->direction);
   787 	v->direction = dir;
   790 	v->direction = dir;
   788 	goto getout;
   791 	goto getout;
   789 }
   792 }
   790 
   793 
   791 static void AgeShipCargo(Vehicle *v)
   794 static void AgeShipCargo(Vehicle *v)