summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2006-06-04 18:22:32 +0000
committerpeter1138 <peter1138@openttd.org>2006-06-04 18:22:32 +0000
commit5e3dd8dd7852e2b4e5ae48eebc7472e73d1f7009 (patch)
tree06c53940c7ff507159a1ceb550728d33cea2dbd5
parent0a623bc333a54dba04271399b5d73a09498df8b2 (diff)
downloadopenttd-5e3dd8dd7852e2b4e5ae48eebc7472e73d1f7009.tar.xz
(svn r5105) - NewGRF: Move callbackmask from *VehicleInfo to EngineInfo. This simplifies code that works with more than one vehicle type.
-rw-r--r--engine.h5
-rw-r--r--newgrf.c8
-rw-r--r--table/engines.h12
-rw-r--r--train_cmd.c28
4 files changed, 25 insertions, 28 deletions
diff --git a/engine.h b/engine.h
index c7637f7f0..88429b2ab 100644
--- a/engine.h
+++ b/engine.h
@@ -21,7 +21,6 @@ typedef struct RailVehicleInfo {
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 @@ typedef struct ShipVehicleInfo {
byte running_cost;
byte sfx;
byte refittable;
- byte callbackmask;
} ShipVehicleInfo;
typedef struct AircraftVehicleInfo {
@@ -54,7 +52,6 @@ typedef struct AircraftVehicleInfo {
byte max_speed;
byte mail_capacity;
uint16 passenger_capacity;
- byte callbackmask;
} AircraftVehicleInfo;
typedef struct RoadVehicleInfo {
@@ -65,7 +62,6 @@ typedef struct RoadVehicleInfo {
byte max_speed;
byte capacity;
CargoID cargo_type;
- byte callbackmask;
} RoadVehicleInfo;
/** Information about a vehicle
@@ -80,6 +76,7 @@ typedef struct EngineInfo {
byte climates:4;
uint32 refit_mask;
byte misc_flags;
+ byte callbackmask;
} EngineInfo;
typedef struct Engine {
diff --git a/newgrf.c b/newgrf.c
index 7d6982994..7b1e84e95 100644
--- a/newgrf.c
+++ b/newgrf.c
@@ -411,7 +411,7 @@ static bool RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf
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 @@ static bool RoadVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf
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 @@ static bool ShipVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf
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 @@ static bool AircraftVehicleChangeInfo(uint engine, int numinfo, int prop, byte *
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
index 5a38b7f73..6d2487d5c 100644
--- 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 @@ const EngineInfo orig_engine_info[] = {
* @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 @@ const RailVehicleInfo orig_rail_vehicle_info[NUM_TRAIN_ENGINES] = {
* @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 @@ const ShipVehicleInfo orig_ship_vehicle_info[NUM_SHIP_ENGINES] = {
* @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 @@ const AircraftVehicleInfo orig_aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES] = {
* @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
index ad0aa8965..3a5300adc 100644
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -167,7 +167,7 @@ void TrainConsistChanged(Vehicle* v)
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 @@ void TrainConsistChanged(Vehicle* v)
// 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 @@ void DrawTrainEngine(int x, int y, EngineID engine, uint32 image_ormod)
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 @@ static uint CountArticulatedParts(const RailVehicleInfo *rvi, EngineID engine_ty
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 @@ static void AddArticulatedParts(const RailVehicleInfo *rvi, Vehicle **vl)
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 @@ static int32 CmdBuildRailWagon(EngineID engine, TileIndex tile, uint32 flags)
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 @@ static int32 CmdBuildRailWagon(EngineID engine, TileIndex tile, uint32 flags)
v->cur_image = 0xAC2;
v->random_bits = VehicleRandomBits();
- AddArticulatedParts(rvi, vl);
+ AddArticulatedParts(vl);
_new_vehicle_id = v->index;
@@ -730,7 +730,7 @@ int32 CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
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 @@ int32 CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
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 @@ int32 CmdReverseTrainDirection(TileIndex tile, uint32 flags, uint32 p1, uint32 p
// 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 @@ int32 CmdRefitRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
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;