mirror of https://github.com/OpenTTD/OpenTTD
(svn r10008) -Codechange: Move a couple of functions related to articulated vehicles to a file of their own.
parent
dce1101039
commit
ab8503f5a5
|
@ -163,6 +163,9 @@
|
||||||
<File
|
<File
|
||||||
RelativePath=".\..\src\airport.cpp">
|
RelativePath=".\..\src\airport.cpp">
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\..\src\articulated_vehicles.cpp">
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\..\src\autoreplace_cmd.cpp">
|
RelativePath=".\..\src\autoreplace_cmd.cpp">
|
||||||
</File>
|
</File>
|
||||||
|
@ -386,6 +389,9 @@
|
||||||
<File
|
<File
|
||||||
RelativePath=".\..\src\airport_movement.h">
|
RelativePath=".\..\src\airport_movement.h">
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\..\src\autoreplace_cmd.h">
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\..\src\aystar.h">
|
RelativePath=".\..\src\aystar.h">
|
||||||
</File>
|
</File>
|
||||||
|
|
|
@ -447,6 +447,10 @@
|
||||||
RelativePath=".\..\src\airport.cpp"
|
RelativePath=".\..\src\airport.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\..\src\articulated_vehicles.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\..\src\autoreplace_cmd.cpp"
|
RelativePath=".\..\src\autoreplace_cmd.cpp"
|
||||||
>
|
>
|
||||||
|
@ -743,6 +747,10 @@
|
||||||
RelativePath=".\..\src\airport_movement.h"
|
RelativePath=".\..\src\airport_movement.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\..\src\autoreplace_cmd.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\..\src\aystar.h"
|
RelativePath=".\..\src\aystar.h"
|
||||||
>
|
>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# Source Files
|
# Source Files
|
||||||
airport.cpp
|
airport.cpp
|
||||||
|
articulated_vehicles.cpp
|
||||||
autoreplace_cmd.cpp
|
autoreplace_cmd.cpp
|
||||||
aystar.cpp
|
aystar.cpp
|
||||||
bmp.cpp
|
bmp.cpp
|
||||||
|
@ -96,6 +97,7 @@ window.cpp
|
||||||
aircraft.h
|
aircraft.h
|
||||||
airport.h
|
airport.h
|
||||||
airport_movement.h
|
airport_movement.h
|
||||||
|
autoreplace_cmd.h
|
||||||
aystar.h
|
aystar.h
|
||||||
bmp.h
|
bmp.h
|
||||||
cargotype.h
|
cargotype.h
|
||||||
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/** @file train_cmd.cpp */
|
||||||
|
|
||||||
|
#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 "newgrf_callbacks.h"
|
||||||
|
#include "newgrf_engine.h"
|
||||||
|
|
||||||
|
uint CountArticulatedParts(EngineID engine_type)
|
||||||
|
{
|
||||||
|
if (!HASBIT(EngInfo(engine_type)->callbackmask, CBM_ARTIC_ENGINE)) return 0;
|
||||||
|
|
||||||
|
uint i;
|
||||||
|
for (i = 1; i < 10; i++) {
|
||||||
|
uint16 callback = GetVehicleCallback(CBID_TRAIN_ARTIC_ENGINE, i, 0, engine_type, NULL);
|
||||||
|
if (callback == CALLBACK_FAILED || callback == 0xFF) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return i - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddArticulatedParts(Vehicle **vl)
|
||||||
|
{
|
||||||
|
const Vehicle *v = vl[0];
|
||||||
|
Vehicle *u = vl[0];
|
||||||
|
|
||||||
|
if (!HASBIT(EngInfo(v->engine_type)->callbackmask, CBM_ARTIC_ENGINE)) return;
|
||||||
|
|
||||||
|
for (uint i = 1; i < 10; i++) {
|
||||||
|
uint16 callback = GetVehicleCallback(CBID_TRAIN_ARTIC_ENGINE, i, 0, v->engine_type, v);
|
||||||
|
if (callback == CALLBACK_FAILED || callback == 0xFF) return;
|
||||||
|
|
||||||
|
/* Attempt to use pre-allocated vehicles until they run out. This can happen
|
||||||
|
* if the callback returns different values depending on the cargo type. */
|
||||||
|
u->next = vl[i];
|
||||||
|
if (u->next == NULL) u->next = AllocateVehicle();
|
||||||
|
if (u->next == NULL) return;
|
||||||
|
|
||||||
|
u = u->next;
|
||||||
|
|
||||||
|
EngineID engine_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;
|
||||||
|
u->owner = v->owner;
|
||||||
|
u->tile = v->tile;
|
||||||
|
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();
|
||||||
|
|
||||||
|
VehiclePositionChanged(u);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/** @file articulated_vehicles.h */
|
||||||
|
|
||||||
|
#ifndef ARTICULATED_VEHICLES_H
|
||||||
|
#define ARTICULATED_VEHICLES_H
|
||||||
|
|
||||||
|
uint CountArticulatedParts(EngineID engine_type);
|
||||||
|
void AddArticulatedParts(Vehicle **vl);
|
||||||
|
|
||||||
|
#endif /* ARTICULATED_VEHICLES_H */
|
|
@ -15,6 +15,7 @@
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
#include "gui.h"
|
#include "gui.h"
|
||||||
#include "vehicle.h"
|
#include "vehicle.h"
|
||||||
|
#include "articulated_vehicles.h"
|
||||||
#include "gfx.h"
|
#include "gfx.h"
|
||||||
#include "station.h"
|
#include "station.h"
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include "tile.h"
|
#include "tile.h"
|
||||||
#include "tunnel_map.h"
|
#include "tunnel_map.h"
|
||||||
#include "vehicle.h"
|
#include "vehicle.h"
|
||||||
|
#include "articulated_vehicles.h"
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
#include "pathfind.h"
|
#include "pathfind.h"
|
||||||
#include "npf.h"
|
#include "npf.h"
|
||||||
|
@ -501,75 +502,6 @@ void DrawTrainEngine(int x, int y, EngineID engine, SpriteID pal)
|
||||||
DrawSprite(image, pal, x, y);
|
DrawSprite(image, pal, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint CountArticulatedParts(EngineID engine_type)
|
|
||||||
{
|
|
||||||
if (!HASBIT(EngInfo(engine_type)->callbackmask, CBM_ARTIC_ENGINE)) return 0;
|
|
||||||
|
|
||||||
uint i;
|
|
||||||
for (i = 1; i < 10; i++) {
|
|
||||||
uint16 callback = GetVehicleCallback(CBID_TRAIN_ARTIC_ENGINE, i, 0, engine_type, NULL);
|
|
||||||
if (callback == CALLBACK_FAILED || callback == 0xFF) break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return i - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void AddArticulatedParts(Vehicle **vl)
|
|
||||||
{
|
|
||||||
const Vehicle *v = vl[0];
|
|
||||||
Vehicle *u = vl[0];
|
|
||||||
|
|
||||||
if (!HASBIT(EngInfo(v->engine_type)->callbackmask, CBM_ARTIC_ENGINE)) return;
|
|
||||||
|
|
||||||
for (uint i = 1; i < 10; i++) {
|
|
||||||
uint16 callback = GetVehicleCallback(CBID_TRAIN_ARTIC_ENGINE, i, 0, v->engine_type, v);
|
|
||||||
if (callback == CALLBACK_FAILED || callback == 0xFF) return;
|
|
||||||
|
|
||||||
/* Attempt to use pre-allocated vehicles until they run out. This can happen
|
|
||||||
* if the callback returns different values depending on the cargo type. */
|
|
||||||
u->next = vl[i];
|
|
||||||
if (u->next == NULL) u->next = AllocateVehicle();
|
|
||||||
if (u->next == NULL) return;
|
|
||||||
|
|
||||||
u = u->next;
|
|
||||||
|
|
||||||
EngineID engine_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;
|
|
||||||
u->owner = v->owner;
|
|
||||||
u->tile = v->tile;
|
|
||||||
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();
|
|
||||||
|
|
||||||
VehiclePositionChanged(u);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32 CmdBuildRailWagon(EngineID engine, TileIndex tile, uint32 flags)
|
static int32 CmdBuildRailWagon(EngineID engine, TileIndex tile, uint32 flags)
|
||||||
{
|
{
|
||||||
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
|
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
|
||||||
|
|
Loading…
Reference in New Issue