# HG changeset patch # User peter1138 # Date 1149445352 0 # Node ID 0cfc02cf74023c3ca5cc408fd15260d858d861a4 # Parent c91e5bc727c6a4575ef5ac6a54f45773c72fba12 (svn r5105) - NewGRF: Move callbackmask from *VehicleInfo to EngineInfo. This simplifies code that works with more than one vehicle type. diff --git a/engine.h b/engine.h --- a/engine.h +++ b/engine.h @@ -21,7 +21,6 @@ byte capacity; CargoID cargo_type; byte ai_rank; - byte callbackmask; // see CallbackMask enum uint16 pow_wag_power; byte pow_wag_weight; byte visual_effect; // NOTE: this is not 100% implemented yet, at the moment it is only used as a 'fallback' value @@ -41,7 +40,6 @@ byte running_cost; byte sfx; byte refittable; - byte callbackmask; } ShipVehicleInfo; typedef struct AircraftVehicleInfo { @@ -54,7 +52,6 @@ byte max_speed; byte mail_capacity; uint16 passenger_capacity; - byte callbackmask; } AircraftVehicleInfo; typedef struct RoadVehicleInfo { @@ -65,7 +62,6 @@ byte max_speed; byte capacity; CargoID cargo_type; - byte callbackmask; } RoadVehicleInfo; /** Information about a vehicle @@ -80,6 +76,7 @@ byte climates:4; uint32 refit_mask; byte misc_flags; + byte callbackmask; } EngineInfo; typedef struct Engine { diff --git a/newgrf.c b/newgrf.c --- a/newgrf.c +++ b/newgrf.c @@ -411,7 +411,7 @@ break; case 0x1E: /* Callback */ - FOR_EACH_OBJECT rvi[i].callbackmask = grf_load_byte(&buf); + FOR_EACH_OBJECT ei[i].callbackmask = grf_load_byte(&buf); break; case 0x21: /* Shorter vehicle */ @@ -549,7 +549,7 @@ break; case 0x17: /* Callback mask */ - FOR_EACH_OBJECT rvi[i].callbackmask = grf_load_byte(&buf); + FOR_EACH_OBJECT ei[i].callbackmask = grf_load_byte(&buf); break; case 0x1C: /* Miscellaneous flags */ @@ -653,7 +653,7 @@ break; case 0x12: /* Callback mask */ - FOR_EACH_OBJECT svi[i].callbackmask = grf_load_byte(&buf); + FOR_EACH_OBJECT ei[i].callbackmask = grf_load_byte(&buf); break; case 0x17: /* Miscellaneous flags */ @@ -750,7 +750,7 @@ break; case 0x14: /* Callback mask */ - FOR_EACH_OBJECT avi[i].callbackmask = grf_load_byte(&buf); + FOR_EACH_OBJECT ei[i].callbackmask = grf_load_byte(&buf); break; case 0x17: /* Miscellaneous flags */ diff --git a/table/engines.h b/table/engines.h --- a/table/engines.h +++ b/table/engines.h @@ -15,7 +15,7 @@ * @param e Rail Type of the vehicle * @param f Bitmask of the climates */ -#define MK(a, b, c, d, e, f) { a, b, c, d, e, f, 0, 0 } +#define MK(a, b, c, d, e, f) { a, b, c, d, e, f, 0, 0, 0 } /** Writes the properties of a train carriage into the EngineInfo struct. * @see EngineInfo * @param a Introduction date @@ -23,7 +23,7 @@ * @param f Bitmask of the climates * @note the 0x80 in parameter b sets the "is carriage bit" */ -#define MW(a, b, c, d, e, f) { a, b | 0x80, c, d, e, f, 0, 0 } +#define MW(a, b, c, d, e, f) { a, b | 0x80, c, d, e, f, 0, 0, 0 } // Rail types // R = Conventional railway @@ -324,7 +324,7 @@ * @param j cargo_type * @param k ai_rank */ -#define RVI(a, b, c, d, e, f, g, h, i, j, k) { a, b, c, d, e, f, g, h, h, i, j, k, 0, 0, 0, 0, 0, 0 } +#define RVI(a, b, c, d, e, f, g, h, i, j, k) { a, b, c, d, e, f, g, h, h, i, j, k, 0, 0, 0, 0, 0 } #define M RVI_MULTIHEAD #define W RVI_WAGON #define S 0 @@ -471,7 +471,7 @@ * @param g sound effect * @param h refittable */ -#define SVI(a, b, c, d, e, f, g, h) { a, b, c, d, e, f, g, h, 0 } +#define SVI(a, b, c, d, e, f, g, h) { a, b, c, d, e, f, g, h } const ShipVehicleInfo orig_ship_vehicle_info[NUM_SHIP_ENGINES] = { // image_index cargo_type cargo_amount refittable // | base_cost | | running_cost | @@ -503,7 +503,7 @@ * @param h mail_capacity * @param i passenger_capacity */ -#define AVI(a, b, c, d, e, f, g, h, i) { a, b, c, d, e, f, g, h, i, 0 } +#define AVI(a, b, c, d, e, f, g, h, i) { a, b, c, d, e, f, g, h, i } #define H 0 #define P 1 #define J 3 @@ -570,7 +570,7 @@ * @param f capacity * @param g cargo_type */ -#define RVI(a, b, c, d, e, f, g) { a, b, c, d, e, f, g, 0 } +#define RVI(a, b, c, d, e, f, g) { a, b, c, d, e, f, g } const RoadVehicleInfo orig_road_vehicle_info[NUM_ROAD_ENGINES] = { // image_index sfx max_speed // | base_cost | | capacity diff --git a/train_cmd.c b/train_cmd.c --- a/train_cmd.c +++ b/train_cmd.c @@ -167,7 +167,7 @@ CLRBIT(u->u.rail.flags, VRF_POWEREDWAGON); /* Check powered wagon / visual effect callback */ - if (HASBIT(rvi_u->callbackmask, CBM_WAGON_POWER)) { + if (HASBIT(EngInfo(u->engine_type)->callbackmask, CBM_WAGON_POWER)) { uint16 callback = GetVehicleCallback(CBID_TRAIN_WAGON_POWER, 0, 0, u->engine_type, u); if (callback != CALLBACK_FAILED) u->u.rail.cached_vis_effect = callback; @@ -194,10 +194,10 @@ // check the vehicle length (callback) veh_len = CALLBACK_FAILED; - if (HASBIT(rvi_u->callbackmask, CBM_VEHICLE_LENGTH)) + if (HASBIT(EngInfo(u->engine_type)->callbackmask, CBM_VEHICLE_LENGTH)) { veh_len = GetVehicleCallback(CBID_TRAIN_VEHICLE_LENGTH, 0, 0, u->engine_type, u); - if (veh_len == CALLBACK_FAILED) - veh_len = rvi_u->shorten_factor; + } + if (veh_len == CALLBACK_FAILED) veh_len = rvi_u->shorten_factor; veh_len = clamp(veh_len, 0, u->next == NULL ? 7 : 5); // the clamp on vehicles not the last in chain is stricter, as too short wagons can break the 'follow next vehicle' code u->u.rail.cached_veh_length = 8 - veh_len; v->u.rail.cached_total_length += u->u.rail.cached_veh_length; @@ -474,12 +474,12 @@ DrawSprite(image | image_ormod, x, y); } -static uint CountArticulatedParts(const RailVehicleInfo *rvi, EngineID engine_type) +static uint CountArticulatedParts(EngineID engine_type) { uint16 callback; uint i; - if (!HASBIT(rvi->callbackmask, CBM_ARTIC_ENGINE)) return 0; + if (!HASBIT(EngInfo(engine_type)->callbackmask, CBM_ARTIC_ENGINE)) return 0; for (i = 1; i < 10; i++) { callback = GetVehicleCallback(CBID_TRAIN_ARTIC_ENGINE, i, 0, engine_type, NULL); @@ -489,7 +489,7 @@ return i - 1; } -static void AddArticulatedParts(const RailVehicleInfo *rvi, Vehicle **vl) +static void AddArticulatedParts(Vehicle **vl) { const RailVehicleInfo *rvi_artic; EngineID engine_type; @@ -499,7 +499,7 @@ bool flip_image; uint i; - if (!HASBIT(rvi->callbackmask, CBM_ARTIC_ENGINE)) return; + if (!HASBIT(EngInfo(v->engine_type)->callbackmask, CBM_ARTIC_ENGINE)) return; for (i = 1; i < 10; i++) { callback = GetVehicleCallback(CBID_TRAIN_ARTIC_ENGINE, i, 0, v->engine_type, NULL); @@ -557,7 +557,7 @@ rvi = RailVehInfo(engine); value = (rvi->base_cost * _price.build_railwagon) >> 8; - num_vehicles = 1 + CountArticulatedParts(rvi, engine); + num_vehicles = 1 + CountArticulatedParts(engine); if (!(flags & DC_QUERY_COST)) { Vehicle *vl[11]; // Allow for wagon and upto 10 artic parts. @@ -624,7 +624,7 @@ v->cur_image = 0xAC2; v->random_bits = VehicleRandomBits(); - AddArticulatedParts(rvi, vl); + AddArticulatedParts(vl); _new_vehicle_id = v->index; @@ -730,7 +730,7 @@ value = EstimateTrainCost(rvi); num_vehicles = (rvi->flags & RVI_MULTIHEAD) ? 2 : 1; - num_vehicles += CountArticulatedParts(rvi, p1); + num_vehicles += CountArticulatedParts(p1); if (!(flags & DC_QUERY_COST)) { Vehicle *vl[12]; // Allow for upto 10 artic parts and dual-heads @@ -800,7 +800,7 @@ vl[0]->u.rail.other_multiheaded_part = vl[1]; vl[1]->u.rail.other_multiheaded_part = vl[0]; } else { - AddArticulatedParts(rvi, vl); + AddArticulatedParts(vl); } TrainConsistChanged(v); @@ -1666,7 +1666,7 @@ // turn a single unit around Vehicle *front; - if (IsMultiheaded(v) || HASBIT(RailVehInfo(v->engine_type)->callbackmask, CBM_ARTIC_ENGINE)) { + if (IsMultiheaded(v) || HASBIT(EngInfo(v->engine_type)->callbackmask, CBM_ARTIC_ENGINE)) { return_cmd_error(STR_ONLY_TURN_SINGLE_UNIT); } @@ -1756,7 +1756,7 @@ const RailVehicleInfo *rvi = RailVehInfo(v->engine_type); uint16 amount = CALLBACK_FAILED; - if (HASBIT(rvi->callbackmask, CBM_REFIT_CAPACITY)) { + if (HASBIT(EngInfo(v->engine_type)->callbackmask, CBM_REFIT_CAPACITY)) { /* Check the 'refit capacity' callback */ CargoID temp_cid = v->cargo_type; v->cargo_type = new_cid;