(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for

road vehicles for those who prefer the technical explanation.
This commit is contained in:
maedhros
2007-06-11 14:00:16 +00:00
parent be0f5cf877
commit 3e326085fa
21 changed files with 570 additions and 212 deletions

View File

@@ -4,16 +4,17 @@
#include "stdafx.h"
#include "openttd.h"
#include "debug.h"
#include "functions.h"
#include "command.h"
#include "vehicle.h"
#include "articulated_vehicles.h"
#include "engine.h"
#include "train.h"
#include "roadveh.h"
#include "newgrf_callbacks.h"
#include "newgrf_engine.h"
uint CountArticulatedParts(EngineID engine_type)
{
if (!HASBIT(EngInfo(engine_type)->callbackmask, CBM_ARTIC_ENGINE)) return 0;
@@ -27,7 +28,7 @@ uint CountArticulatedParts(EngineID engine_type)
return i - 1;
}
void AddArticulatedParts(Vehicle **vl)
void AddArticulatedParts(Vehicle **vl, VehicleType type)
{
const Vehicle *v = vl[0];
Vehicle *u = vl[0];
@@ -46,9 +47,8 @@ void AddArticulatedParts(Vehicle **vl)
u = u->next;
EngineID engine_type = GB(callback, 0, 7);
EngineID engine_type = GetFirstEngineOfType(type) + GB(callback, 0, 7);
bool flip_image = HASBIT(callback, 7);
const RailVehicleInfo *rvi_artic = RailVehInfo(engine_type);
/* get common values from first engine */
u->direction = v->direction;
@@ -57,28 +57,57 @@ void AddArticulatedParts(Vehicle **vl)
u->x_pos = v->x_pos;
u->y_pos = v->y_pos;
u->z_pos = v->z_pos;
u->u.rail.track = v->u.rail.track;
u->u.rail.railtype = v->u.rail.railtype;
u->build_year = v->build_year;
u->vehstatus = v->vehstatus & ~VS_STOPPED;
u->u.rail.first_engine = v->engine_type;
/* get more settings from rail vehicle info */
u->spritenum = rvi_artic->image_index;
if (flip_image) u->spritenum++;
u->cargo_type = rvi_artic->cargo_type;
u->cargo_subtype = 0;
u->cargo_cap = rvi_artic->capacity;
u->max_speed = 0;
u->max_age = 0;
u->engine_type = engine_type;
u->value = 0;
u = new (u) Train();
u->subtype = 0;
SetArticulatedPart(u);
u->cur_image = 0xAC2;
u->random_bits = VehicleRandomBits();
switch (type) {
default: NOT_REACHED();
case VEH_TRAIN: {
const RailVehicleInfo *rvi_artic = RailVehInfo(engine_type);
u = new (u) Train();
u->u.rail.track = v->u.rail.track;
u->u.rail.railtype = v->u.rail.railtype;
u->u.rail.first_engine = v->engine_type;
u->spritenum = rvi_artic->image_index;
u->cargo_type = rvi_artic->cargo_type;
u->cargo_cap = rvi_artic->capacity;
SetArticulatedPart(u);
} break;
case VEH_ROAD: {
const RoadVehicleInfo *rvi_artic = RoadVehInfo(engine_type);
u = new (u) RoadVehicle();
u->u.road.first_engine = v->engine_type;
u->u.road.cached_veh_length = GetRoadVehLength(u);
u->u.road.state = RVSB_IN_DEPOT;
u->u.road.roadtype = v->u.road.roadtype;
u->u.road.compatible_roadtypes = v->u.road.compatible_roadtypes;
u->spritenum = rvi_artic->image_index;
u->cargo_type = rvi_artic->cargo_type;
u->cargo_cap = rvi_artic->capacity;
SetRoadVehArticPart(u);
} break;
}
if (flip_image) u->spritenum++;
VehiclePositionChanged(u);
}
}