Changeset - r18913:fd2dc944ef3a
[Not reviewed]
master
0 4 0
michi_cc - 12 years ago 2012-01-08 12:47:54
michi_cc@openttd.org
(svn r23773) -Change: [NewGRF] Update all cached train properties if a train vehicle enters a new railtype.
4 files changed with 5 insertions and 21 deletions:
0 comments (0 inline, 0 general)
src/rail_cmd.cpp
Show inline comments
 
@@ -1655,13 +1655,13 @@ CommandCost CmdConvertRail(TileIndex til
 
		}
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		/* Railtype changed, update trains as when entering different track */
 
		for (Train **v = affected_trains.Begin(); v != affected_trains.End(); v++) {
 
			(*v)->RailtypeChanged();
 
			(*v)->ConsistChanged(true);
 
		}
 
	}
 

	
 
	delete iter;
 
	return (cost.GetCost() == 0) ? error : cost;
 
}
src/saveload/vehicle_sl.cpp
Show inline comments
 
@@ -527,12 +527,15 @@ void FixupTrainLengths()
 
						next->vehstatus &= ~VS_HIDDEN;
 
						next->track = TrackToTrackBits(GetRailDepotTrack(next->tile));
 
						for (int i = 0; i >= d; i--) TrainController(next, NULL);
 
					}
 
				}
 
			}
 

	
 
			/* Update all cached properties after moving the vehicle chain around. */
 
			Train::From(v)->ConsistChanged(true);
 
		}
 
	}
 
}
 

	
 
static uint8  _cargo_days;
 
static uint16 _cargo_source;
src/train.h
Show inline comments
 
@@ -113,14 +113,12 @@ struct Train FINAL : public GroundVehicl
 
	void ReserveTrackUnderConsist() const;
 

	
 
	int GetCurveSpeedLimit() const;
 

	
 
	void ConsistChanged(bool same_length);
 

	
 
	void RailtypeChanged();
 

	
 
	int UpdateSpeed();
 

	
 
	void UpdateAcceleration();
 

	
 
	int GetCurrentMaxSpeed() const;
 

	
src/train_cmd.cpp
Show inline comments
 
@@ -110,26 +110,12 @@ void CheckTrainsLengths()
 
			}
 
		}
 
	}
 
}
 

	
 
/**
 
 * Update visual effect, power and acceleration caches.
 
 * Called when a vehicle in the consist enters a different railtype.
 
 */
 
void Train::RailtypeChanged()
 
{
 
	for (Train *u = this; u != NULL; u = u->Next()) {
 
		/* The wagon-is-powered-state should not change, so the weight does not change. */
 
		u->UpdateVisualEffect(false);
 
	}
 
	this->PowerChanged();
 
	if (this->IsFrontEngine()) this->UpdateAcceleration();
 
}
 

	
 
/**
 
 * Recalculates the cached stuff of a train. Should be called each time a vehicle is added
 
 * to/removed from the chain, and when the game is loaded.
 
 * Note: this needs to be called too for 'wagon chains' (in the depot, without an engine)
 
 * @param same_length should length of vehicles stay the same?
 
 */
 
void Train::ConsistChanged(bool same_length)
 
@@ -1586,15 +1572,12 @@ void ReverseTrainSwapVeh(Train *v, int l
 
		/* Swap GVF_GOINGUP_BIT/GVF_GOINGDOWN_BIT.
 
		 * This is a little bit redundant way, a->gv_flags will
 
		 * be (re)set twice, but it reduces code duplication */
 
		SwapTrainFlags(&a->gv_flags, &a->gv_flags);
 
		UpdateStatusAfterSwap(a);
 
	}
 

	
 
	/* Update power of the train in case tiles were different rail type. */
 
	v->RailtypeChanged();
 
}
 

	
 

	
 
/**
 
 * Check if the vehicle is a train
 
 * @param v vehicle on tile
 
@@ -3243,13 +3226,13 @@ bool TrainController(Train *v, Vehicle *
 
					/* Clear any track reservation when the last vehicle leaves the tile */
 
					if (v->Next() == NULL) ClearPathReservation(v, v->tile, v->GetVehicleTrackdir());
 

	
 
					v->tile = gp.new_tile;
 

	
 
					if (GetTileRailType(gp.new_tile) != GetTileRailType(gp.old_tile)) {
 
						v->First()->RailtypeChanged();
 
						v->First()->ConsistChanged(true);
 
					}
 

	
 
					v->track = chosen_track;
 
					assert(v->track);
 
				}
 

	
0 comments (0 inline, 0 general)