train_cmd.c
changeset 4244 d40c73c55357
parent 4242 5738cbc9b2bd
child 4251 e8f69de723e1
equal deleted inserted replaced
4243:b0361faa4dfd 4244:d40c73c55357
  1225  * @param p2 unused
  1225  * @param p2 unused
  1226  */
  1226  */
  1227 int32 CmdStartStopTrain(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
  1227 int32 CmdStartStopTrain(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
  1228 {
  1228 {
  1229 	Vehicle *v;
  1229 	Vehicle *v;
       
  1230 	uint16 callback;
  1230 
  1231 
  1231 	if (!IsVehicleIndex(p1)) return CMD_ERROR;
  1232 	if (!IsVehicleIndex(p1)) return CMD_ERROR;
  1232 
  1233 
  1233 	v = GetVehicle(p1);
  1234 	v = GetVehicle(p1);
  1234 
  1235 
  1235 	if (v->type != VEH_Train || !CheckOwnership(v->owner)) return CMD_ERROR;
  1236 	if (v->type != VEH_Train || !CheckOwnership(v->owner)) return CMD_ERROR;
       
  1237 
       
  1238 	/* Check if this train can be started/stopped. The callback will fail or
       
  1239 	 * return 0xFF if it can. */
       
  1240 	callback = GetVehicleCallback(CBID_VEHICLE_START_STOP_CHECK, 0, 0, v->engine_type, v);
       
  1241 	if (callback != CALLBACK_FAILED && callback != 0xFF) {
       
  1242 		StringID error = GetGRFStringID(GetEngineGRFID(v->engine_type), 0xD000 + callback);
       
  1243 		return_cmd_error(error);
       
  1244 	}
  1236 
  1245 
  1237 	if (flags & DC_EXEC) {
  1246 	if (flags & DC_EXEC) {
  1238 		if (v->vehstatus & VS_STOPPED && v->u.rail.track == 0x80) {
  1247 		if (v->vehstatus & VS_STOPPED && v->u.rail.track == 0x80) {
  1239 			DeleteVehicleNews(p1, STR_8814_TRAIN_IS_WAITING_IN_DEPOT);
  1248 			DeleteVehicleNews(p1, STR_8814_TRAIN_IS_WAITING_IN_DEPOT);
  1240 		}
  1249 		}