Changeset - r4648:90818f8d70ac
[Not reviewed]
master
0 3 0
bjarni - 18 years ago 2006-09-27 12:17:33
bjarni@openttd.org
(svn r6524) -Code cleanup r6515: cleaned up the command to start/stop all vehicles in a depot.
IsWholeTrainInDepot() is removed as CheckTrainInDepot() could be used instead
Cleaned up the check to see if a vehicle is valid for start/stop
3 files changed with 11 insertions and 13 deletions:
0 comments (0 inline, 0 general)
train.h
Show inline comments
 
@@ -215,15 +215,9 @@ static inline Vehicle *GetNextVehicle(co
 
	return v->next;
 
}
 

	
 
void ConvertOldMultiheadToNew(void);
 
void ConnectMultiheadedTrains(void);
 

	
 
static inline bool IsWholeTrainInDepot(const Vehicle *v)
 
{
 
	for (; v != NULL; v = v->next) {
 
		if (!(v->vehstatus & VS_HIDDEN)) return false;
 
	}
 
	return true;
 
}
 
int CheckTrainInDepot(const Vehicle *v, bool needs_to_be_stopped);
 

	
 
#endif /* TRAIN_H */
train_cmd.c
Show inline comments
 
@@ -829,13 +829,13 @@ int32 CmdBuildRailVehicle(TileIndex tile
 
	return value;
 
}
 

	
 

	
 
/* Check if all the wagons of the given train are in a depot, returns the
 
 * number of cars (including loco) then. If not it returns -1 */
 
static int CheckTrainInDepot(const Vehicle *v, bool needs_to_be_stopped)
 
int CheckTrainInDepot(const Vehicle *v, bool needs_to_be_stopped)
 
{
 
	int count;
 
	TileIndex tile = v->tile;
 

	
 
	/* check if stopped in a depot */
 
	if (!IsTileDepotType(tile, TRANSPORT_RAIL) || v->cur_speed != 0) return -1;
vehicle.c
Show inline comments
 
@@ -1567,14 +1567,14 @@ int32 CmdMassStartStopVehicle(TileIndex 
 
	Vehicle **vl = NULL;
 
	uint16 engine_list_length = 0;
 
	uint16 engine_count = 0;
 
	int32 return_value = CMD_ERROR;
 
	uint i;
 
	uint stop_command;
 
	byte vehicle_type = p1;
 
	byte start_stop = p2;
 
	byte vehicle_type = GB(p1, 0, 8);
 
	bool start_stop = HASBIT(p2, 0);
 

	
 
	switch (vehicle_type) {
 
		case VEH_Train:    stop_command = CMD_START_STOP_TRAIN;    break;
 
		case VEH_Road:     stop_command = CMD_START_STOP_ROADVEH;  break;
 
		case VEH_Ship:     stop_command = CMD_START_STOP_SHIP;     break;
 
		case VEH_Aircraft: stop_command = CMD_START_STOP_AIRCRAFT; break;
 
@@ -1586,25 +1586,29 @@ int32 CmdMassStartStopVehicle(TileIndex 
 

	
 
	for (i = 0; i < engine_count; i++) {
 
		const Vehicle *v = vl[i];
 
		int32 ret;
 

	
 
		if (!!(v->vehstatus & VS_STOPPED) != start_stop) continue;
 
		if (!(v->vehstatus & VS_HIDDEN)) continue;
 
		if (p1 == VEH_Train && !IsWholeTrainInDepot(v)) continue;
 
		if (vehicle_type == VEH_Train) {
 
			if (CheckTrainInDepot(v, false) == -1) continue;
 
		} else {
 
			if (!(v->vehstatus & VS_HIDDEN)) continue;
 
		}
 

	
 
		ret = DoCommand(tile, v->index, 0, flags, stop_command);
 

	
 
		if (!CmdFailed(ret)) {
 
			return_value = 0;
 
			/* We know that the command is valid for at least one vehicle.
 
			 * If we haven't set DC_EXEC, then there is no point in continueing because it will be valid */
 
			if (!(flags & DC_EXEC)) break;
 
		}
 
	}
 

	
 
	free((void*)vl);
 
	free(vl);
 
	return return_value;
 
}
 

	
 
/** Clone a vehicle. If it is a train, it will clone all the cars too
 
 * @param tile tile of the depot where the cloned vehicle is build
 
 * @param p1 the original vehicle's index
0 comments (0 inline, 0 general)