Changeset - r1434:b9a13b8c79f4
[Not reviewed]
master
0 2 0
tron - 20 years ago 2005-03-06 12:54:19
tron@openttd.org
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
2 files changed with 47 insertions and 68 deletions:
Makefile
12
32
0 comments (0 inline, 0 general)
Makefile
Show inline comments
 
@@ -684,45 +684,20 @@ LANGS = $(LANG_TXT:%.txt=%.lng)
 
##############################################################################
 
#
 
# Build commands
 
#
 

	
 
# If we are verbose, we will show commands prefixed by $(Q) (which acts as
 
# @ in the non-verbose mode), and we will show the "real" cmds instead of
 
# their quiet versions (which are used in the non-verbose mode).
 
# @ in the non-verbose mode)
 
# Inspired by the Linux kernel build system.
 
ifdef VERBOSE
 
	Q =
 
	quiet =
 
else
 
	Q = @
 
	quiet = quiet_
 
endif
 

	
 
# Show the command (quiet or non-quiet version based on the assignment
 
# just above) and then execute it.
 
cmd = @$(if $($(quiet)cmd_$(1)),echo $($(quiet)cmd_$(1)) &&) $(cmd_$(1))
 

	
 

	
 
# The build commands themselves. Note that if you omit the quiet version,
 
# nothing will be shown in the non-verbose mode.
 

	
 
quiet_cmd_compile_link = '===> Compiling and Linking $@'
 
      cmd_compile_link = $(CC) $(BASECFLAGS) $(CDEFS) $< -o $@
 

	
 
quiet_cmd_ttd_link = '===> Linking $@'
 
      cmd_ttd_link = $(CC) $(LDFLAGS) $(TTDLDFLAGS) $(OBJS) $(LIBS) -o $@
 

	
 
COMPILE_PARAMS=$(CFLAGS) $(CDEFS) -MD -c $< -o $@
 

	
 
quiet_cmd_c_compile = '===> Compiling $<'
 
      cmd_c_compile = $(CC) $(COMPILE_PARAMS)
 

	
 
quiet_cmd_cxx_compile = '===> Compiling $<'
 
      cmd_cxx_compile = $(CXX) $(COMPILE_PARAMS)
 

	
 

	
 
##############################################################################
 
#
 
# Targets
 
#
 

	
 
@@ -739,17 +714,19 @@ all: endian.h $(UPDATECONFIG) $(LANGS) $
 

	
 
endian.h: $(ENDIAN_CHECK)
 
	@echo '===> Testing endianness'
 
	$(Q)./$(ENDIAN_CHECK) > $@
 

	
 
$(ENDIAN_CHECK): endian_check.c
 
	$(call cmd,compile_link)
 
	@echo '===> Compiling and Linking $@'
 
	$(Q)$(CC) $(BASECFLAGS) $(CDEFS) $< -o $@
 

	
 

	
 
$(TTD): table/strings.h $(OBJS) $(MAKE_CONFIG)
 
	$(call cmd,ttd_link)
 
	@echo '===> Linking $@'
 
	$(Q)$(CC) $(LDFLAGS) $(TTDLDFLAGS) $(OBJS) $(LIBS) -o $@
 

	
 
$(OSX): $(TTD)
 
	$(Q)rm -fr "$(OSXAPP)"
 
	$(Q)mkdir -p "$(OSXAPP)"/Contents/MacOS
 
	$(Q)mkdir -p "$(OSXAPP)"/Contents/Resources
 
	$(Q)mkdir -p "$(OSXAPP)"/Contents/Data
 
@@ -769,13 +746,14 @@ endian.h: $(ENDIAN_CHECK)
 

	
 
$(64_bit_warnings):
 
	$(warning 64 bit CPUs will get some 64 bit specific bugs!)
 
	$(warning If you see any bugs, include in your bug report that you use a 64 bit CPU)
 

	
 
$(STRGEN): strgen/strgen.c endian.h
 
	$(call cmd,compile_link)
 
	@echo '===> Compiling and Linking $@'
 
	$(Q)$(CC) $(BASECFLAGS) $(CDEFS) $< -o $@
 

	
 
table/strings.h: lang/english.txt $(STRGEN)
 
	@echo '===> Generating $@'
 
	$(Q)$(STRGEN)
 

	
 
lang/%.lng: lang/%.txt $(STRGEN) lang/english.txt
 
@@ -954,22 +932,24 @@ DEPS_MAGIC := $(shell mkdir .deps > /dev
 
# This compiles the object file as well as silently updating its dependencies
 
# list at the same time. It is not an issue that they aren't around during the
 
# first compilation round as we just build everything at that time anyway,
 
# therefore we do not need to watch deps.
 

	
 
%.o: %.c $(MAKE_CONFIG) endian.h table/strings.h
 
	$(call cmd,c_compile)
 
	@echo '===> Compiling $<'
 
	$(Q)$(CC) $(CFLAGS) $(CDEFS) -MD -c $< -o $@
 
	@mv $(<:%.c=%.d) $(<:%.c=.deps/%.d)
 

	
 
%.o: %.cpp  $(MAKE_CONFIG) endian.h table/strings.h
 
	$(call cmd,cxx_compile)
 
	@echo '===> Compiling $<'
 
	$(Q)$(CXX) $(CFLAGS) $(CDEFS) -MD -c $< -o $@
 
	@mv $(<:%.c=%.d) $(<:%.c=.deps/%.d)
 

	
 
# Silence stale header dependencies
 
%.h:
 
	@true
 

	
 

	
 
info:
 
	@echo 'CFLAGS  = $(CFLAGS)'
 
	@echo 'CFLAGS  = $(CFLAGS) $(CDEFS)'
 
	@echo 'LDFLAGS = $(LDFLAGS)'
 
	@echo 'LIBS    = $(LIBS)'
train_cmd.c
Show inline comments
 
@@ -2267,26 +2267,31 @@ static void TrainMovedChangeSignals(uint
 
		UpdateSignalsOnSegment(tile, _otherside_signal_directions[i]);
 
	}
 
}
 

	
 

	
 
typedef struct TrainCollideChecker {
 
	Vehicle *v, *v_skip;
 

	
 
	const Vehicle *v;
 
	const Vehicle *v_skip;
 
} TrainCollideChecker;
 

	
 
static void *FindTrainCollideEnum(Vehicle *v, TrainCollideChecker *tcc)
 
static void *FindTrainCollideEnum(Vehicle *v, void *data)
 
{
 
	if (v == tcc->v || v == tcc->v_skip || v->type != VEH_Train || v->u.rail.track==0x80)
 
		return 0;
 

	
 
	if ( myabs(v->z_pos - tcc->v->z_pos) > 6 ||
 
			 myabs(v->x_pos - tcc->v->x_pos) >= 6 ||
 
			 myabs(v->y_pos - tcc->v->y_pos) >= 6)
 
				return NULL;
 
	return v;
 
	const TrainCollideChecker* tcc = data;
 

	
 
	if (v != tcc->v &&
 
			v != tcc->v_skip &&
 
			v->type == VEH_Train &&
 
			v->u.rail.track != 0x80 &&
 
			myabs(v->z_pos - tcc->v->z_pos) <= 6 &&
 
			myabs(v->x_pos - tcc->v->x_pos) < 6 &&
 
			myabs(v->y_pos - tcc->v->y_pos) < 6) {
 
		return v;
 
	} else {
 
		return NULL;
 
	}
 
}
 

	
 
static void SetVehicleCrashed(Vehicle *v)
 
{
 
	Vehicle *u;
 

	
 
@@ -2300,72 +2305,74 @@ static void SetVehicleCrashed(Vehicle *v
 
		v->vehstatus |= VS_CRASHED;
 
	END_ENUM_WAGONS(v)
 

	
 
	InvalidateWindowWidget(WC_VEHICLE_VIEW, u->index, STATUS_BAR);
 
}
 

	
 
static int CountPassengersInTrain(Vehicle *v)
 
static int CountPassengersInTrain(const Vehicle *v)
 
{
 
	int num = 0;
 
	BEGIN_ENUM_WAGONS(v)
 
		if (v->cargo_type == CT_PASSENGERS) num += v->cargo_count;
 
	END_ENUM_WAGONS(v)
 
	return num;
 
}
 

	
 
/*
 
 * Checks whether the specified tried has a collision with another vehicle. If
 
 * Checks whether the specified train has a collision with another vehicle. If
 
 * so, destroys this vehicle, and the other vehicle if its subtype is 0 (TS_Front_Engine).
 
 * Reports the incident in a flashy news item, modifies station ratings and
 
 * plays a sound.
 
 */
 
static void CheckTrainCollision(Vehicle *v)
 
{
 
	TrainCollideChecker tcc;
 
	Vehicle *coll,*realcoll;
 
	Vehicle *coll;
 
	Vehicle *realcoll;
 
	int num;
 

	
 
	/* can't collide in depot */
 
	if (v->u.rail.track == 0x80)
 
		return;
 

	
 
	if ( !(v->u.rail.track == 0x40) )
 
		assert((uint)TILE_FROM_XY(v->x_pos, v->y_pos) == v->tile);
 
	assert(v->u.rail.track == 0x40 || TILE_FROM_XY(v->x_pos, v->y_pos) == v->tile);
 

	
 
	tcc.v = v;
 
	tcc.v_skip = v->next;
 

	
 
	/* find colliding vehicle */
 
	realcoll = coll = VehicleFromPos(TILE_FROM_XY(v->x_pos, v->y_pos), &tcc, (VehicleFromPosProc*)FindTrainCollideEnum);
 
	if (coll == NULL)
 
	realcoll = VehicleFromPos(TILE_FROM_XY(v->x_pos, v->y_pos), &tcc, FindTrainCollideEnum);
 
	if (realcoll == NULL)
 
		return;
 

	
 

	
 
	coll = GetFirstVehicleInChain(coll);
 
	coll = GetFirstVehicleInChain(realcoll);
 

	
 
	/* it can't collide with its own wagons */
 
	if ( (v == coll) || ( (v->u.rail.track & 0x40) && ( (v->direction & 2) != (realcoll->direction & 2) ) ) )
 
	if (v == coll ||
 
			(v->u.rail.track & 0x40 && (v->direction & 2) != (realcoll->direction & 2)))
 
		return;
 

	
 
	//two drivers + passangers killed in train v
 
	num = 2 + CountPassengersInTrain(v);
 
	if(!(coll->vehstatus&VS_CRASHED))
 
	if (!(coll->vehstatus & VS_CRASHED))
 
		//two drivers + passangers killed in train coll (if it was not crashed already)
 
		num += 2 + CountPassengersInTrain(coll);
 

	
 
	SetVehicleCrashed(v);
 
	if (coll->subtype == TS_Front_Engine)
 
		SetVehicleCrashed(coll);
 

	
 

	
 
	SetDParam(0, num);
 

	
 
	AddNewsItem(STR_8868_TRAIN_CRASH_DIE_IN_FIREBALL,
 
		NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0),
 
		NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_VEHICLE, NT_ACCIDENT, 0),
 
		v->index,
 
		0);
 
		0
 
	);
 

	
 
	ModifyStationRatingAround(v->tile, v->owner, -160, 30);
 
	SndPlayVehicleFx(SND_13_BIG_CRASH, v);
 
}
 

	
 
typedef struct VehicleAtSignalData {
 
@@ -2395,13 +2402,13 @@ static void TrainController(Vehicle *v)
 
	int i, enterdir, newdir, dir;
 
	byte chosen_dir;
 
	byte chosen_track;
 
	byte old_z;
 

	
 
	/* For every vehicle after and including the given vehicle */
 
	for(;;) {
 
	for (; v != NULL; prev = v, v = v->next) {
 
		BeginVehicleMove(v);
 

	
 
		if (v->u.rail.track != 0x40) {
 
			/* Not inside tunnel */
 
			if (GetNewVehiclePos(v, &gp)) {
 
				/* Staying in the old tile */
 
@@ -2533,13 +2540,13 @@ static void TrainController(Vehicle *v)
 

	
 
			v->x_pos = gp.x;
 
			v->y_pos = gp.y;
 
			VehiclePositionChanged(v);
 
			if (prev == NULL)
 
				CheckTrainCollision(v);
 
			goto next_vehicle;
 
			continue;
 
		}
 
common:;
 

	
 
		/* update image of train, as well as delta XY */
 
		newdir = GetNewVehicleDirection(v, gp.x, gp.y);
 
		UpdateTrainDeltaXY(v, newdir);
 
@@ -2553,18 +2560,12 @@ common:;
 

	
 
		if (prev == NULL) {
 
			/* This is the first vehicle in the train */
 
			AffectSpeedByZChange(v, old_z);
 
			CheckTrainCollision(v);
 
		}
 

	
 
next_vehicle:;
 
		/* continue with next vehicle */
 
		prev = v;
 
		if ((v=v->next) == NULL)
 
			return;
 
	}
 

	
 
invalid_rail:
 
	/* We've reached end of line?? */
 
	if (prev != NULL) {
 
		error("!Disconnecting train");
 
@@ -2622,16 +2623,13 @@ static void DeleteLastWagon(Vehicle *v)
 
{
 
	Vehicle *u = v;
 

	
 
	/* Go to the last wagon and delete the link pointing there
 
	 * *u is then the one-before-last wagon, and *v the last
 
	 * one which will physicially be removed */
 
	while (v->next != NULL) {
 
		u = v;
 
		v = v->next;
 
	}
 
	for (; v->next != NULL; v = v->next) u = v;
 
	u->next = NULL;
 

	
 
	InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
 
	DeleteWindowById(WC_VEHICLE_VIEW, v->index);
 
	RebuildVehicleLists();
 
	InvalidateWindow(WC_COMPANY, v->owner);
 
@@ -2640,13 +2638,14 @@ static void DeleteLastWagon(Vehicle *v)
 
	EndVehicleMove(v);
 
	DeleteVehicle(v);
 

	
 
	if (!(v->u.rail.track & 0xC0))
 
		SetSignalsOnBothDir(v->tile, FIND_FIRST_BIT(v->u.rail.track));
 

	
 
	/* Check if the wagon was on a road/rail-crossing and disable it if no others are on it */
 
	/* Check if the wagon was on a road/rail-crossing and disable it if no
 
	 * others are on it */
 
	DisableTrainCrossing(v->tile);
 

	
 
	if (v->u.rail.track == 0x40) { // inside a tunnel
 
		TileIndex endtile = CheckTunnelBusy(v->tile, NULL);
 

	
 
		if (endtile == INVALID_TILE) // tunnel is busy (error returned)
0 comments (0 inline, 0 general)