summaryrefslogtreecommitdiffstats
path: root/src/vehicles/Train.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/vehicles/Train.cpp')
-rw-r--r--src/vehicles/Train.cpp88
1 files changed, 22 insertions, 66 deletions
diff --git a/src/vehicles/Train.cpp b/src/vehicles/Train.cpp
index 5f0cf36a..3c3d45d7 100644
--- a/src/vehicles/Train.cpp
+++ b/src/vehicles/Train.cpp
@@ -15,6 +15,10 @@
#include "Train.h"
#include "AudioScriptObject.h"
+#define TRAIN_SPEED (15.0f)
+#define TRAIN_SLOWDOWN_DISTANCE (40.0f)
+#define TRAIN_TIME_STOPPED_AT_STATION (25.0f)
+
static CTrainNode* pTrackNodes;
static int16 NumTrackNodes;
static float StationDist[3] = { 873.0f, 1522.0f, 2481.0f };
@@ -459,11 +463,11 @@ CTrain::InitTrains(void)
CStreaming::LoadAllRequestedModels(false);
// El-Train wagons
- float wagonPositions[] = { 0.0f, 20.0f, 40.0f, 0.0f, 20.0f };
- int8 firstWagon[] = { 1, 0, 0, 1, 0 };
- int8 lastWagon[] = { 0, 0, 1, 0, 1 };
- int16 wagonGroup[] = { 0, 0, 0, 1, 1 };
- for(i = 0; i < 5; i++){
+ float wagonPositions[] = { 0.0f, 20.0f, 0.0f, 20.0f };
+ int8 firstWagon[] = { 1, 0, 1, 0 };
+ int8 lastWagon[] = { 0, 1, 0, 1 };
+ int16 wagonGroup[] = { 0, 0, 1, 1 };
+ for(i = 0; i < 4; i++){
train = new CTrain(MI_TRAIN, PERMANENT_VEHICLE);
train->GetMatrix().SetTranslate(0.0f, 0.0f, 0.0f);
train->SetStatus(STATUS_ABANDONED);
@@ -598,23 +602,23 @@ CTrain::ReadAndInterpretTrackFile(Const char *filename, CTrainNode **nodes, int1
interpLines[j].type = 1;
interpLines[j].time = time;
interpLines[j].position = position;
- interpLines[j].speed = 15.0f;
+ interpLines[j].speed = TRAIN_SPEED;
interpLines[j].acceleration = 0.0f;
j++;
// distance to next keyframe
- float dist = (stationDists[i]-40.0f) - position;
- time += dist/15.0f;
+ float dist = (stationDists[i]-TRAIN_SLOWDOWN_DISTANCE) - position;
+ time += dist/TRAIN_SPEED;
position += dist;
// Now slow down 40 units before stop
interpLines[j].type = 2;
interpLines[j].time = time;
interpLines[j].position = position;
- interpLines[j].speed = 15.0f;
- interpLines[j].acceleration = -45.0f/32.0f;
+ interpLines[j].speed = TRAIN_SPEED;
+ interpLines[j].acceleration = -(TRAIN_SPEED * TRAIN_SPEED) / (4 * TRAIN_SLOWDOWN_DISTANCE);
j++;
- time += 80.0f/15.0f;
- position += 40.0f; // at station
+ time += 2*TRAIN_SLOWDOWN_DISTANCE/TRAIN_SPEED;
+ position += TRAIN_SLOWDOWN_DISTANCE; // at station
// stopping
interpLines[j].type = 0;
@@ -623,26 +627,26 @@ CTrain::ReadAndInterpretTrackFile(Const char *filename, CTrainNode **nodes, int1
interpLines[j].speed = 0.0f;
interpLines[j].acceleration = 0.0f;
j++;
- time += 25.0f;
+ time += TRAIN_TIME_STOPPED_AT_STATION;
// accelerate again
interpLines[j].type = 2;
interpLines[j].time = time;
interpLines[j].position = position;
interpLines[j].speed = 0.0f;
- interpLines[j].acceleration = 45.0f/32.0f;
+ interpLines[j].acceleration = (TRAIN_SPEED * TRAIN_SPEED) / (4 * TRAIN_SLOWDOWN_DISTANCE);
j++;
- time += 80.0f/15.0f;
- position += 40.0f; // after station
+ time += 2*TRAIN_SLOWDOWN_DISTANCE /TRAIN_SPEED;
+ position += TRAIN_SLOWDOWN_DISTANCE; // after station
}
// last keyframe
interpLines[j].type = 1;
interpLines[j].time = time;
interpLines[j].position = position;
- interpLines[j].speed = 15.0f;
+ interpLines[j].speed = TRAIN_SPEED;
interpLines[j].acceleration = 0.0f;
j++;
- *totalDuration = time + (*totalLength - position)/15.0f;
+ *totalDuration = time + (*totalLength - position)/ TRAIN_SPEED;
// end
interpLines[j].time = *totalDuration;
@@ -650,52 +654,6 @@ CTrain::ReadAndInterpretTrackFile(Const char *filename, CTrainNode **nodes, int1
}
void
-PlayAnnouncement(uint8 sound, uint8 station)
-{
- // this was gone in a PC version but inlined on PS2
- cAudioScriptObject *obj = new cAudioScriptObject;
- obj->AudioId = sound;
- obj->Posn = CTrain::aStationCoors[station];
- obj->AudioEntity = AEHANDLE_NONE;
- DMAudio.CreateOneShotScriptObject(obj);
-}
-
-void
-ProcessTrainAnnouncements(void)
-{
-#ifdef GTA_TRAIN
- for (int i = 0; i < ARRAY_SIZE(StationDist); i++) {
- for (int j = 0; j < ARRAY_SIZE(EngineTrackPosition); j++) {
- if (!bTrainArrivalAnnounced[i]) {
- float preDist = StationDist[i] - 100.0f;
- if (preDist < 0.0f)
- preDist += TotalLengthOfTrack;
- if (EngineTrackPosition[j] > preDist && EngineTrackPosition[j] < StationDist[i]) {
- bTrainArrivalAnnounced[i] = true;
- PlayAnnouncement(SCRIPT_SOUND_TRAIN_ANNOUNCEMENT_1, i);
- break;
- }
- } else {
- float postDist = StationDist[i] + 10.0f;
-#ifdef FIX_BUGS
- if (postDist > TotalLengthOfTrack)
- postDist -= TotalLengthOfTrack;
-#else
- if (postDist < 0.0f) // does this even make sense here?
- postDist += TotalLengthOfTrack;
-#endif
- if (EngineTrackPosition[j] > StationDist[i] && EngineTrackPosition[j] < postDist) {
- bTrainArrivalAnnounced[i] = false;
- PlayAnnouncement(SCRIPT_SOUND_TRAIN_ANNOUNCEMENT_2, i);
- break;
- }
- }
- }
- }
-#endif
-}
-
-void
CTrain::UpdateTrains(void)
{
#ifdef GTA_TRAIN
@@ -732,8 +690,6 @@ CTrain::UpdateTrains(void)
// time offset for each train
time += 0x20000/2;
}
-
- ProcessTrainAnnouncements();
}
// Update Subway