diff options
author | rubidium <rubidium@openttd.org> | 2007-05-01 16:35:14 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2007-05-01 16:35:14 +0000 |
commit | 5a46c763f0dffa6327f08a3ae3b26745e44ea10e (patch) | |
tree | 3af9b32e32882e876dac13b47e51e15d2bba5c06 | |
parent | fa244119b924a2fdeb42c83e094e221f0dee8927 (diff) | |
download | openttd-5a46c763f0dffa6327f08a3ae3b26745e44ea10e.tar.xz |
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
-rw-r--r-- | src/aircraft.h | 1 | ||||
-rw-r--r-- | src/aircraft_cmd.cpp | 60 | ||||
-rw-r--r-- | src/disaster_cmd.cpp | 16 | ||||
-rw-r--r-- | src/players.cpp | 2 | ||||
-rw-r--r-- | src/roadveh.h | 1 | ||||
-rw-r--r-- | src/roadveh_cmd.cpp | 31 | ||||
-rw-r--r-- | src/ship.h | 1 | ||||
-rw-r--r-- | src/ship_cmd.cpp | 42 | ||||
-rw-r--r-- | src/train.h | 1 | ||||
-rw-r--r-- | src/train_cmd.cpp | 26 | ||||
-rw-r--r-- | src/vehicle.cpp | 47 | ||||
-rw-r--r-- | src/vehicle.h | 13 |
12 files changed, 140 insertions, 101 deletions
diff --git a/src/aircraft.h b/src/aircraft.h index 1baad94c7..a66b3a177 100644 --- a/src/aircraft.h +++ b/src/aircraft.h @@ -132,6 +132,7 @@ struct Aircraft : public Vehicle { const char *GetTypeString() { return "aircraft"; } void MarkDirty(); + void UpdateDeltaXY(Direction direction); }; #endif /* AIRCRAFT_H */ diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index 88716c829..464113a6c 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -33,6 +33,35 @@ #include "spritecache.h" #include "cargotype.h" +void Aircraft::UpdateDeltaXY(Direction direction) +{ + uint32 x; +#define MKIT(a, b, c, d) ((a & 0xFF) << 24) | ((b & 0xFF) << 16) | ((c & 0xFF) << 8) | ((d & 0xFF) << 0) + switch (this->subtype) { + default: NOT_REACHED(); + case AIR_AIRCRAFT: + case AIR_HELICOPTER: + switch (this->u.air.state) { + case ENDTAKEOFF: + case LANDING: + case HELILANDING: + case FLYING: x = MKIT(24, 24, -1, -1); break; + default: x = MKIT( 2, 2, -1, -1); break; + } + this->z_height = 5; + break; + case AIR_SHADOW: this->z_height = 1; x = MKIT(2, 2, 0, 0); break; + case AIR_ROTOR: this->z_height = 1; x = MKIT(2, 2, -1, -1); break; + } +#undef MKIT + + this->x_offs = GB(x, 0, 8); + this->y_offs = GB(x, 8, 8); + this->sprite_width = GB(x, 16, 8); + this->sprite_height = GB(x, 24, 8); +} + + /** this maps the terminal to its corresponding state and block flag * currently set for 10 terms, 4 helipads */ static const byte _airport_terminal_state[] = {2, 3, 4, 5, 6, 7, 19, 20, 0, 0, 8, 9, 21, 22}; @@ -287,15 +316,8 @@ int32 CmdBuildAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) u->z_pos = GetSlopeZ(x, y); v->z_pos = u->z_pos + 1; - v->x_offs = v->y_offs = -1; // u->delta_x = u->delta_y = 0; - v->sprite_width = v->sprite_height = 2; - v->z_height = 5; - - u->sprite_width = u->sprite_height = 2; - u->z_height = 1; - v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL; u->vehstatus = VS_HIDDEN | VS_UNCLICKABLE | VS_SHADOW; @@ -323,9 +345,11 @@ int32 CmdBuildAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) v->engine_type = p1; v->subtype = (avi->subtype & AIR_CTOL ? AIR_AIRCRAFT : AIR_HELICOPTER); + v->UpdateDeltaXY(INVALID_DIR); v->value = value; u->subtype = AIR_SHADOW; + u->UpdateDeltaXY(INVALID_DIR); /* Danger, Will Robinson! * If the aircraft is refittable, but cannot be refitted to @@ -411,9 +435,6 @@ int32 CmdBuildAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) w->x_pos = v->x_pos; w->y_pos = v->y_pos; w->z_pos = v->z_pos + 5; - w->x_offs = w->y_offs = -1; - w->sprite_width = w->sprite_height = 2; - w->z_height = 1; w->vehstatus = VS_HIDDEN | VS_UNCLICKABLE; w->spritenum = 0xFF; w->subtype = AIR_ROTOR; @@ -421,6 +442,7 @@ int32 CmdBuildAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) w->random_bits = VehicleRandomBits(); /* Use rotor's air.state to store the rotor animation frame */ w->u.air.state = HRS_ROTOR_STOPPED; + w->UpdateDeltaXY(INVALID_DIR); VehiclePositionChanged(w); } @@ -1510,14 +1532,10 @@ static void AircraftEntersTerminal(Vehicle *v) v->BeginLoading(); } -static void AircraftLand(Vehicle *v) -{ - v->sprite_width = v->sprite_height = 2; -} - static void AircraftLandAirplane(Vehicle *v) { - AircraftLand(v); + v->UpdateDeltaXY(INVALID_DIR); + if (!PlayVehicleSound(v, VSE_TOUCHDOWN)) { SndPlayVehicleFx(SND_17_SKID_PLANE, v); } @@ -1676,8 +1694,8 @@ static void AircraftEventHandler_TakeOff(Vehicle *v, const AirportFTAClass *apc) static void AircraftEventHandler_StartTakeOff(Vehicle *v, const AirportFTAClass *apc) { - v->sprite_width = v->sprite_height = 24; // ??? no idea what this is v->u.air.state = ENDTAKEOFF; + v->UpdateDeltaXY(INVALID_DIR); } static void AircraftEventHandler_EndTakeOff(Vehicle *v, const AirportFTAClass *apc) @@ -1690,8 +1708,9 @@ static void AircraftEventHandler_EndTakeOff(Vehicle *v, const AirportFTAClass *a static void AircraftEventHandler_HeliTakeOff(Vehicle *v, const AirportFTAClass *apc) { const Player* p = GetPlayer(v->owner); - v->sprite_width = v->sprite_height = 24; // ??? no idea what this is v->u.air.state = FLYING; + v->UpdateDeltaXY(INVALID_DIR); + /* get the next position to go to, differs per airport */ AircraftNextAirportPos_and_Order(v); @@ -1749,8 +1768,9 @@ static void AircraftEventHandler_Flying(Vehicle *v, const AirportFTAClass *apc) static void AircraftEventHandler_Landing(Vehicle *v, const AirportFTAClass *apc) { - AircraftLandAirplane(v); // maybe crash airplane v->u.air.state = ENDLANDING; + AircraftLandAirplane(v); // maybe crash airplane + /* check if the aircraft needs to be replaced or renewed and send it to a hangar if needed */ if (v->current_order.type != OT_GOTO_DEPOT && v->owner == _local_player) { /* only the vehicle owner needs to calculate the rest (locally) */ @@ -1767,8 +1787,8 @@ static void AircraftEventHandler_Landing(Vehicle *v, const AirportFTAClass *apc) static void AircraftEventHandler_HeliLanding(Vehicle *v, const AirportFTAClass *apc) { - AircraftLand(v); // helicopters don't crash v->u.air.state = HELIENDLANDING; + v->UpdateDeltaXY(INVALID_DIR); } static void AircraftEventHandler_EndLanding(Vehicle *v, const AirportFTAClass *apc) diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp index c6cc16a05..6b940aed2 100644 --- a/src/disaster_cmd.cpp +++ b/src/disaster_cmd.cpp @@ -116,7 +116,6 @@ static void DisasterVehicleUpdateImage(Vehicle *v) v->cur_image = img; } - /** Initialize a disaster vehicle. These vehicles are of type VEH_DISASTER, are unclickable * and owned by nobody */ static void InitializeDisasterVehicle(Vehicle *v, int x, int y, byte z, Direction direction, byte subtype) @@ -128,11 +127,7 @@ static void InitializeDisasterVehicle(Vehicle *v, int x, int y, byte z, Directio v->tile = TileVirtXY(x, y); v->direction = direction; v->subtype = subtype; - v->x_offs = -1; - v->y_offs = -1; - v->sprite_width = 2; - v->sprite_height = 2; - v->z_height = 5; + v->UpdateDeltaXY(INVALID_DIR); v->owner = OWNER_NONE; v->vehstatus = VS_UNCLICKABLE; v->u.disaster.image_override = 0; @@ -1065,3 +1060,12 @@ void StartupDisasters() { ResetDisasterDelay(); } + +void DisasterVehicle::UpdateDeltaXY(Direction direction) +{ + this->x_offs = -1; + this->y_offs = -1; + this->sprite_width = 2; + this->sprite_height = 2; + this->z_height = 5; +} diff --git a/src/players.cpp b/src/players.cpp index eb4bd1712..1a7487ce9 100644 --- a/src/players.cpp +++ b/src/players.cpp @@ -1109,7 +1109,7 @@ static const SaveLoad _player_desc[] = { SLE_VAR(Player, player_color, SLE_UINT8), SLE_VAR(Player, player_money_fraction, SLE_UINT8), - SLE_VAR(Player, avail_railtypes, SLE_UINT8), + SLE_CONDVAR(Player, avail_railtypes, SLE_UINT8, 0, 57), SLE_VAR(Player, block_preview, SLE_UINT8), SLE_VAR(Player, cargo_types, SLE_UINT16), diff --git a/src/roadveh.h b/src/roadveh.h index ec1e0354f..340a74076 100644 --- a/src/roadveh.h +++ b/src/roadveh.h @@ -40,6 +40,7 @@ struct RoadVehicle : public Vehicle { const char *GetTypeString() { return "road vehicle"; } void MarkDirty(); + void UpdateDeltaXY(Direction direction); }; #endif /* ROADVEH_H */ diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index c6ca01265..a4525d2d1 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -169,7 +169,6 @@ int32 CmdBuildRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) v->x_pos = x; v->y_pos = y; v->z_pos = GetSlopeZ(x, y); - v->z_height = 6; v->u.road.state = RVSB_IN_DEPOT; v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL; @@ -492,9 +491,9 @@ void RoadVehicle::MarkDirty() MarkAllViewportsDirty(this->left_coord, this->top_coord, this->right_coord + 1, this->bottom_coord + 1); } -static void UpdateRoadVehDeltaXY(Vehicle *v) +void RoadVehicle::UpdateDeltaXY(Direction direction) { -#define MKIT(a,b,c,d) ((a&0xFF)<<24) | ((b&0xFF)<<16) | ((c&0xFF)<<8) | ((d&0xFF)<<0) +#define MKIT(a, b, c, d) ((a & 0xFF) << 24) | ((b & 0xFF) << 16) | ((c & 0xFF) << 8) | ((d & 0xFF) << 0) static const uint32 _delta_xy_table[8] = { MKIT(3, 3, -1, -1), MKIT(3, 7, -1, -3), @@ -506,11 +505,13 @@ static void UpdateRoadVehDeltaXY(Vehicle *v) MKIT(7, 3, -3, -1), }; #undef MKIT - uint32 x = _delta_xy_table[v->direction]; - v->x_offs = GB(x, 0, 8); - v->y_offs = GB(x, 8, 8); - v->sprite_width = GB(x, 16, 8); - v->sprite_height = GB(x, 24, 8); + + uint32 x = _delta_xy_table[direction]; + this->x_offs = GB(x, 0, 8); + this->y_offs = GB(x, 8, 8); + this->sprite_width = GB(x, 16, 8); + this->sprite_height = GB(x, 24, 8); + this->z_height = 6; } static void ClearCrashedStation(Vehicle *v) @@ -566,7 +567,7 @@ static void RoadVehSetRandomDirection(Vehicle *v) v->direction = ChangeDir(v->direction, delta[r & 3]); BeginVehicleMove(v); - UpdateRoadVehDeltaXY(v); + v->UpdateDeltaXY(v->direction); v->cur_image = GetRoadVehImage(v, v->direction); SetRoadVehPosition(v, v->x_pos, v->y_pos); } @@ -1345,7 +1346,7 @@ static void RoadVehController(Vehicle *v) v->u.road.frame = RVC_DEPOT_START_FRAME; v->cur_image = GetRoadVehImage(v, v->direction); - UpdateRoadVehDeltaXY(v); + v->UpdateDeltaXY(v->direction); SetRoadVehPosition(v,x,y); InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); @@ -1381,7 +1382,7 @@ static void RoadVehController(Vehicle *v) if ((IsTunnelTile(gp.new_tile) || IsBridgeTile(gp.new_tile)) && HASBIT(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y), VETS_ENTERED_WORMHOLE)) { /* Vehicle has just entered a bridge or tunnel */ v->cur_image = GetRoadVehImage(v, v->direction); - UpdateRoadVehDeltaXY(v); + v->UpdateDeltaXY(v->direction); SetRoadVehPosition(v,gp.x,gp.y); return; } @@ -1469,7 +1470,7 @@ again: } v->cur_image = GetRoadVehImage(v, newdir); - UpdateRoadVehDeltaXY(v); + v->UpdateDeltaXY(v->direction); RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); return; } @@ -1509,7 +1510,7 @@ again: } v->cur_image = GetRoadVehImage(v, newdir); - UpdateRoadVehDeltaXY(v); + v->UpdateDeltaXY(v->direction); RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); return; } @@ -1539,7 +1540,7 @@ again: if (old_dir != v->u.road.state) { /* The vehicle is in a road stop */ v->cur_image = GetRoadVehImage(v, new_dir); - UpdateRoadVehDeltaXY(v); + v->UpdateDeltaXY(v->direction); SetRoadVehPosition(v, v->x_pos, v->y_pos); /* Note, return here means that the frame counter is not incremented * for vehicles changing direction in a road stop. This causes frames to @@ -1659,7 +1660,7 @@ again: if (!HASBIT(r, VETS_ENTERED_WORMHOLE)) v->u.road.frame++; v->cur_image = GetRoadVehImage(v, v->direction); - UpdateRoadVehDeltaXY(v); + v->UpdateDeltaXY(v->direction); RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); } diff --git a/src/ship.h b/src/ship.h index 6e696f088..e277f91c4 100644 --- a/src/ship.h +++ b/src/ship.h @@ -41,6 +41,7 @@ struct Ship: public Vehicle { const char *GetTypeString() { return "ship"; } void MarkDirty(); + void UpdateDeltaXY(Direction direction); }; #endif /* SHIP_H */ diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp index 6ce767649..9878e7cd9 100644 --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -334,30 +334,32 @@ static void HandleShipLoading(Vehicle *v) InvalidateVehicleOrder(v); } -static void UpdateShipDeltaXY(Vehicle *v, int dir) +void Ship::UpdateDeltaXY(Direction direction) { -#define MKIT(d,c,b,a) ((a&0xFF)<<24) | ((b&0xFF)<<16) | ((c&0xFF)<<8) | ((d&0xFF)<<0) +#define MKIT(a, b, c, d) ((a & 0xFF) << 24) | ((b & 0xFF) << 16) | ((c & 0xFF) << 8) | ((d & 0xFF) << 0) static const uint32 _delta_xy_table[8] = { - MKIT( -3, -3, 6, 6), - MKIT(-16, -3, 32, 6), - MKIT( -3, -3, 6, 6), - MKIT( -3, -16, 6, 32), - MKIT( -3, -3, 6, 6), - MKIT(-16, -3, 32, 6), - MKIT( -3, -3, 6, 6), - MKIT( -3, -16, 6, 32), + MKIT( 6, 6, -3, -3), + MKIT( 6, 32, -3, -16), + MKIT( 6, 6, -3, -3), + MKIT(32, 6, -16, -3), + MKIT( 6, 6, -3, -3), + MKIT( 6, 32, -3, -16), + MKIT( 6, 6, -3, -3), + MKIT(32, 6, -16, -3), }; #undef MKIT - uint32 x = _delta_xy_table[dir]; - v->x_offs = GB(x, 0, 8); - v->y_offs = GB(x, 8, 8); - v->sprite_width = GB(x, 16, 8); - v->sprite_height = GB(x, 24, 8); + + uint32 x = _delta_xy_table[direction]; + this->x_offs = GB(x, 0, 8); + this->y_offs = GB(x, 8, 8); + this->sprite_width = GB(x, 16, 8); + this->sprite_height = GB(x, 24, 8); + this->z_height = 6; } void RecalcShipStuff(Vehicle *v) { - UpdateShipDeltaXY(v, v->direction); + v->UpdateDeltaXY(v->direction); v->cur_image = GetShipImage(v, v->direction); v->MarkDirty(); InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); @@ -788,7 +790,7 @@ static void ShipController(Vehicle *v) v->z_pos = GetSlopeZ(gp.x, gp.y); getout: - UpdateShipDeltaXY(v, dir); + v->UpdateDeltaXY(dir); v->cur_image = GetShipImage(v, dir); VehiclePositionChanged(v); EndVehicleMove(v); @@ -873,11 +875,7 @@ int32 CmdBuildShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) v->y_pos = y; v->z_pos = GetSlopeZ(x, y); - v->z_height = 6; - v->sprite_width = 6; - v->sprite_height = 6; - v->x_offs = -3; - v->y_offs = -3; + v->UpdateDeltaXY(v->direction); v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL; v->spritenum = svi->image_index; diff --git a/src/train.h b/src/train.h index 8d67c4a18..317d93c2d 100644 --- a/src/train.h +++ b/src/train.h @@ -245,6 +245,7 @@ struct Train : public Vehicle { const char *GetTypeString() { return "train"; } void MarkDirty(); + void UpdateDeltaXY(Direction direction); }; #endif /* TRAIN_H */ diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 0a990d87f..4e1d2064c 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -535,7 +535,6 @@ static void AddArticulatedParts(Vehicle **vl) u->x_pos = v->x_pos; u->y_pos = v->y_pos; u->z_pos = v->z_pos; - u->z_height = v->z_height; u->u.rail.track = v->u.rail.track; u->u.rail.railtype = v->u.rail.railtype; u->build_year = v->build_year; @@ -608,7 +607,6 @@ static int32 CmdBuildRailWagon(EngineID engine, TileIndex tile, uint32 flags) v->y_pos = y; v->z_pos = GetSlopeZ(x, y); v->owner = _current_player; - v->z_height = 6; v->u.rail.track = TRACK_BIT_DEPOT; v->vehstatus = VS_HIDDEN | VS_DEFPAL; @@ -681,7 +679,6 @@ static void AddRearEngineToMultiheadedTrain(Vehicle* v, Vehicle* u, bool buildin u->x_pos = v->x_pos; u->y_pos = v->y_pos; u->z_pos = v->z_pos; - u->z_height = 6; u->u.rail.track = TRACK_BIT_DEPOT; u->vehstatus = v->vehstatus & ~VS_STOPPED; u->subtype = 0; @@ -763,7 +760,6 @@ int32 CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) v->x_pos = x; v->y_pos = y; v->z_pos = GetSlopeZ(x, y); - v->z_height = 6; v->u.rail.track = TRACK_BIT_DEPOT; v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL; v->spritenum = rvi->image_index; @@ -1463,9 +1459,9 @@ int32 CmdSellRailWagon(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) return cost; } -static void UpdateTrainDeltaXY(Vehicle *v, Direction direction) +void Train::UpdateDeltaXY(Direction direction) { -#define MKIT(a,b,c,d) ((a&0xFF)<<24) | ((b&0xFF)<<16) | ((c&0xFF)<<8) | ((d&0xFF)<<0) +#define MKIT(a, b, c, d) ((a & 0xFF) << 24) | ((b & 0xFF) << 16) | ((c & 0xFF) << 8) | ((d & 0xFF) << 0) static const uint32 _delta_xy_table[8] = { MKIT(3, 3, -1, -1), MKIT(3, 7, -1, -3), @@ -1479,16 +1475,16 @@ static void UpdateTrainDeltaXY(Vehicle *v, Direction direction) #undef MKIT uint32 x = _delta_xy_table[direction]; - - v->x_offs = GB(x, 0, 8); - v->y_offs = GB(x, 8, 8); - v->sprite_width = GB(x, 16, 8); - v->sprite_height = GB(x, 24, 8); + this->x_offs = GB(x, 0, 8); + this->y_offs = GB(x, 8, 8); + this->sprite_width = GB(x, 16, 8); + this->sprite_height = GB(x, 24, 8); + this->z_height = 6; } static void UpdateVarsAfterSwap(Vehicle *v) { - UpdateTrainDeltaXY(v, v->direction); + v->UpdateDeltaXY(v->direction); v->cur_image = GetTrainImage(v, v->direction); BeginVehicleMove(v); VehiclePositionChanged(v); @@ -2149,7 +2145,7 @@ static bool CheckTrainStayInDepot(Vehicle *v) v->vehstatus &= ~VS_HIDDEN; v->cur_speed = 0; - UpdateTrainDeltaXY(v, v->direction); + v->UpdateDeltaXY(v->direction); v->cur_image = GetTrainImage(v, v->direction); VehiclePositionChanged(v); UpdateSignalsOnSegment(v->tile, DirToDiagDir(v->direction)); @@ -3061,7 +3057,7 @@ static void TrainController(Vehicle *v, bool update_image) /* update image of train, as well as delta XY */ Direction newdir = GetNewVehicleDirection(v, gp.x, gp.y); - UpdateTrainDeltaXY(v, newdir); + v->UpdateDeltaXY(newdir); if (update_image) v->cur_image = GetTrainImage(v, newdir); v->x_pos = gp.x; @@ -3157,7 +3153,7 @@ static void ChangeTrainDirRandomly(Vehicle *v) if (!(v->vehstatus & VS_HIDDEN)) { v->direction = ChangeDir(v->direction, delta[GB(Random(), 0, 2)]); BeginVehicleMove(v); - UpdateTrainDeltaXY(v, v->direction); + v->UpdateDeltaXY(v->direction); v->cur_image = GetTrainImage(v, v->direction); /* Refrain from updating the z position of the vehicle when on a bridge, because AfterSetTrainPos will put the vehicle under diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 5ec8c1c5f..4cbb4887f 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -224,6 +224,8 @@ void AfterLoadVehicles() Vehicle *v; FOR_ALL_VEHICLES(v) { + v->UpdateDeltaXY(v->direction); + v->first = NULL; if (v->type == VEH_TRAIN) v->u.rail.first_engine = INVALID_ENGINE; } @@ -1443,9 +1445,8 @@ Vehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicle type) v->x_pos = x; v->y_pos = y; v->z_pos = z; - v->z_height = v->sprite_width = v->sprite_height = 1; - v->x_offs = v->y_offs = 0; v->tile = 0; + v->UpdateDeltaXY(INVALID_DIR); v->vehstatus = VS_UNCLICKABLE; _effect_init_procs[type](v); @@ -2644,13 +2645,13 @@ extern const SaveLoad _common_veh_desc[] = { SLE_VAR(Vehicle, z_pos, SLE_UINT8), SLE_VAR(Vehicle, direction, SLE_UINT8), - SLE_VAR(Vehicle, cur_image, SLE_UINT16), + SLE_CONDVAR(Vehicle, cur_image, SLE_UINT16, 0, 57), SLE_VAR(Vehicle, spritenum, SLE_UINT8), - SLE_VAR(Vehicle, sprite_width, SLE_UINT8), - SLE_VAR(Vehicle, sprite_height, SLE_UINT8), - SLE_VAR(Vehicle, z_height, SLE_UINT8), - SLE_VAR(Vehicle, x_offs, SLE_INT8), - SLE_VAR(Vehicle, y_offs, SLE_INT8), + SLE_CONDVAR(Vehicle, sprite_width, SLE_UINT8, 0, 57), + SLE_CONDVAR(Vehicle, sprite_height, SLE_UINT8, 0, 57), + SLE_CONDVAR(Vehicle, z_height, SLE_UINT8, 0, 57), + SLE_CONDVAR(Vehicle, x_offs, SLE_INT8, 0, 57), + SLE_CONDVAR(Vehicle, y_offs, SLE_INT8, 0, 57), SLE_VAR(Vehicle, engine_type, SLE_UINT16), SLE_VAR(Vehicle, max_speed, SLE_UINT16), @@ -2818,11 +2819,11 @@ static const SaveLoad _special_desc[] = { SLE_VAR(Vehicle, z_pos, SLE_UINT8), SLE_VAR(Vehicle, cur_image, SLE_UINT16), - SLE_VAR(Vehicle, sprite_width, SLE_UINT8), - SLE_VAR(Vehicle, sprite_height, SLE_UINT8), - SLE_VAR(Vehicle, z_height, SLE_UINT8), - SLE_VAR(Vehicle, x_offs, SLE_INT8), - SLE_VAR(Vehicle, y_offs, SLE_INT8), + SLE_CONDVAR(Vehicle, sprite_width, SLE_UINT8, 0, 57), + SLE_CONDVAR(Vehicle, sprite_height, SLE_UINT8, 0, 57), + SLE_CONDVAR(Vehicle, z_height, SLE_UINT8, 0, 57), + SLE_CONDVAR(Vehicle, x_offs, SLE_INT8, 0, 57), + SLE_CONDVAR(Vehicle, y_offs, SLE_INT8, 0, 57), SLE_VAR(Vehicle, progress, SLE_UINT8), SLE_VAR(Vehicle, vehstatus, SLE_UINT8), @@ -2853,11 +2854,11 @@ static const SaveLoad _disaster_desc[] = { SLE_VAR(Vehicle, z_pos, SLE_UINT8), SLE_VAR(Vehicle, direction, SLE_UINT8), - SLE_VAR(Vehicle, x_offs, SLE_INT8), - SLE_VAR(Vehicle, y_offs, SLE_INT8), - SLE_VAR(Vehicle, sprite_width, SLE_UINT8), - SLE_VAR(Vehicle, sprite_height, SLE_UINT8), - SLE_VAR(Vehicle, z_height, SLE_UINT8), + SLE_CONDVAR(Vehicle, x_offs, SLE_INT8, 0, 57), + SLE_CONDVAR(Vehicle, y_offs, SLE_INT8, 0, 57), + SLE_CONDVAR(Vehicle, sprite_width, SLE_UINT8, 0, 57), + SLE_CONDVAR(Vehicle, sprite_height, SLE_UINT8, 0, 57), + SLE_CONDVAR(Vehicle, z_height, SLE_UINT8, 0, 57), SLE_VAR(Vehicle, owner, SLE_UINT8), SLE_VAR(Vehicle, vehstatus, SLE_UINT8), SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, dest), SLE_FILE_U8 | SLE_VAR_U16, 0, 4), @@ -3000,3 +3001,13 @@ void Vehicle::LeaveStation() current_order.flags = 0; GetStation(this->last_station_visited)->loading_vehicles.remove(this); } + + +void SpecialVehicle::UpdateDeltaXY(Direction direction) +{ + this->x_offs = 0; + this->y_offs = 0; + this->sprite_width = 1; + this->sprite_height = 1; + this->z_height = 1; +} diff --git a/src/vehicle.h b/src/vehicle.h index 2a1b75d25..dd9ca71ba 100644 --- a/src/vehicle.h +++ b/src/vehicle.h @@ -358,6 +358,13 @@ struct Vehicle { * Marks the vehicles to be redrawn and updates cached variables */ virtual void MarkDirty() {} + + /** + * Updates the x and y offsets and the size of the sprite used + * for this vehicle. + * @param direction the direction the vehicle is facing + */ + virtual void UpdateDeltaXY(Direction direction) {} }; /** @@ -383,6 +390,7 @@ struct SpecialVehicle : public Vehicle { virtual ~SpecialVehicle() {} const char *GetTypeString() { return "special vehicle"; } + void UpdateDeltaXY(Direction direction); }; /** @@ -401,6 +409,7 @@ struct DisasterVehicle : public Vehicle { virtual ~DisasterVehicle() {} const char *GetTypeString() { return "disaster vehicle"; } + void UpdateDeltaXY(Direction direction); }; /** @@ -410,9 +419,6 @@ struct DisasterVehicle : public Vehicle { * v = new (v) Train(); * * As side-effect the vehicle type is set correctly. - * - * An invalid vehicle must never be used; all (virtual) functions from - * Vehicle should assert (NOT_REACHED). */ struct InvalidVehicle : public Vehicle { /** Initializes the Vehicle to a invalid vehicle */ @@ -422,7 +428,6 @@ struct InvalidVehicle : public Vehicle { virtual ~InvalidVehicle() {} const char *GetTypeString() { return "invalid vehicle"; } - void MarkDirty() { NOT_REACHED(); } }; #define is_custom_sprite(x) (x >= 0xFD) |