mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r1938) Miscellaneous cleanups: const correctness, kill a goto, ...
This commit is contained in:
parent
9973e97b84
commit
aee2b0c50a
44
Makefile
44
Makefile
|
@ -687,39 +687,14 @@ LANGS = $(LANG_TXT:%.txt=%.lng)
|
||||||
#
|
#
|
||||||
|
|
||||||
# If we are verbose, we will show commands prefixed by $(Q) (which acts as
|
# 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
|
# @ in the non-verbose mode)
|
||||||
# their quiet versions (which are used in the non-verbose mode).
|
|
||||||
# Inspired by the Linux kernel build system.
|
# Inspired by the Linux kernel build system.
|
||||||
ifdef VERBOSE
|
ifdef VERBOSE
|
||||||
Q =
|
Q =
|
||||||
quiet =
|
|
||||||
else
|
else
|
||||||
Q = @
|
Q = @
|
||||||
quiet = quiet_
|
|
||||||
endif
|
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)
|
|
||||||
|
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
|
@ -742,11 +717,13 @@ endian.h: $(ENDIAN_CHECK)
|
||||||
$(Q)./$(ENDIAN_CHECK) > $@
|
$(Q)./$(ENDIAN_CHECK) > $@
|
||||||
|
|
||||||
$(ENDIAN_CHECK): endian_check.c
|
$(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)
|
$(TTD): table/strings.h $(OBJS) $(MAKE_CONFIG)
|
||||||
$(call cmd,ttd_link)
|
@echo '===> Linking $@'
|
||||||
|
$(Q)$(CC) $(LDFLAGS) $(TTDLDFLAGS) $(OBJS) $(LIBS) -o $@
|
||||||
|
|
||||||
$(OSX): $(TTD)
|
$(OSX): $(TTD)
|
||||||
$(Q)rm -fr "$(OSXAPP)"
|
$(Q)rm -fr "$(OSXAPP)"
|
||||||
|
@ -772,7 +749,8 @@ $(64_bit_warnings):
|
||||||
$(warning If you see any bugs, include in your bug report that you use a 64 bit CPU)
|
$(warning If you see any bugs, include in your bug report that you use a 64 bit CPU)
|
||||||
|
|
||||||
$(STRGEN): strgen/strgen.c endian.h
|
$(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)
|
table/strings.h: lang/english.txt $(STRGEN)
|
||||||
@echo '===> Generating $@'
|
@echo '===> Generating $@'
|
||||||
|
@ -957,11 +935,13 @@ DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
|
||||||
# therefore we do not need to watch deps.
|
# therefore we do not need to watch deps.
|
||||||
|
|
||||||
%.o: %.c $(MAKE_CONFIG) endian.h table/strings.h
|
%.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)
|
@mv $(<:%.c=%.d) $(<:%.c=.deps/%.d)
|
||||||
|
|
||||||
%.o: %.cpp $(MAKE_CONFIG) endian.h table/strings.h
|
%.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)
|
@mv $(<:%.c=%.d) $(<:%.c=.deps/%.d)
|
||||||
|
|
||||||
# Silence stale header dependencies
|
# Silence stale header dependencies
|
||||||
|
@ -970,6 +950,6 @@ DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
|
||||||
|
|
||||||
|
|
||||||
info:
|
info:
|
||||||
@echo 'CFLAGS = $(CFLAGS)'
|
@echo 'CFLAGS = $(CFLAGS) $(CDEFS)'
|
||||||
@echo 'LDFLAGS = $(LDFLAGS)'
|
@echo 'LDFLAGS = $(LDFLAGS)'
|
||||||
@echo 'LIBS = $(LIBS)'
|
@echo 'LIBS = $(LIBS)'
|
||||||
|
|
67
train_cmd.c
67
train_cmd.c
|
@ -2270,20 +2270,25 @@ static void TrainMovedChangeSignals(uint tile, int dir)
|
||||||
|
|
||||||
|
|
||||||
typedef struct TrainCollideChecker {
|
typedef struct TrainCollideChecker {
|
||||||
Vehicle *v, *v_skip;
|
const Vehicle *v;
|
||||||
|
const Vehicle *v_skip;
|
||||||
} TrainCollideChecker;
|
} 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)
|
const TrainCollideChecker* tcc = data;
|
||||||
return 0;
|
|
||||||
|
|
||||||
if ( myabs(v->z_pos - tcc->v->z_pos) > 6 ||
|
if (v != tcc->v &&
|
||||||
myabs(v->x_pos - tcc->v->x_pos) >= 6 ||
|
v != tcc->v_skip &&
|
||||||
myabs(v->y_pos - tcc->v->y_pos) >= 6)
|
v->type == VEH_Train &&
|
||||||
return NULL;
|
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;
|
return v;
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SetVehicleCrashed(Vehicle *v)
|
static void SetVehicleCrashed(Vehicle *v)
|
||||||
|
@ -2303,7 +2308,7 @@ static void SetVehicleCrashed(Vehicle *v)
|
||||||
InvalidateWindowWidget(WC_VEHICLE_VIEW, u->index, STATUS_BAR);
|
InvalidateWindowWidget(WC_VEHICLE_VIEW, u->index, STATUS_BAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int CountPassengersInTrain(Vehicle *v)
|
static int CountPassengersInTrain(const Vehicle *v)
|
||||||
{
|
{
|
||||||
int num = 0;
|
int num = 0;
|
||||||
BEGIN_ENUM_WAGONS(v)
|
BEGIN_ENUM_WAGONS(v)
|
||||||
|
@ -2313,7 +2318,7 @@ static int CountPassengersInTrain(Vehicle *v)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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).
|
* 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
|
* Reports the incident in a flashy news item, modifies station ratings and
|
||||||
* plays a sound.
|
* plays a sound.
|
||||||
|
@ -2321,34 +2326,35 @@ static int CountPassengersInTrain(Vehicle *v)
|
||||||
static void CheckTrainCollision(Vehicle *v)
|
static void CheckTrainCollision(Vehicle *v)
|
||||||
{
|
{
|
||||||
TrainCollideChecker tcc;
|
TrainCollideChecker tcc;
|
||||||
Vehicle *coll,*realcoll;
|
Vehicle *coll;
|
||||||
|
Vehicle *realcoll;
|
||||||
int num;
|
int num;
|
||||||
|
|
||||||
/* can't collide in depot */
|
/* can't collide in depot */
|
||||||
if (v->u.rail.track == 0x80)
|
if (v->u.rail.track == 0x80)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( !(v->u.rail.track == 0x40) )
|
assert(v->u.rail.track == 0x40 || TILE_FROM_XY(v->x_pos, v->y_pos) == v->tile);
|
||||||
assert((uint)TILE_FROM_XY(v->x_pos, v->y_pos) == v->tile);
|
|
||||||
|
|
||||||
tcc.v = v;
|
tcc.v = v;
|
||||||
tcc.v_skip = v->next;
|
tcc.v_skip = v->next;
|
||||||
|
|
||||||
/* find colliding vehicle */
|
/* find colliding vehicle */
|
||||||
realcoll = coll = VehicleFromPos(TILE_FROM_XY(v->x_pos, v->y_pos), &tcc, (VehicleFromPosProc*)FindTrainCollideEnum);
|
realcoll = VehicleFromPos(TILE_FROM_XY(v->x_pos, v->y_pos), &tcc, FindTrainCollideEnum);
|
||||||
if (coll == NULL)
|
if (realcoll == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
coll = GetFirstVehicleInChain(coll);
|
coll = GetFirstVehicleInChain(realcoll);
|
||||||
|
|
||||||
/* it can't collide with its own wagons */
|
/* 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;
|
return;
|
||||||
|
|
||||||
//two drivers + passangers killed in train v
|
//two drivers + passangers killed in train v
|
||||||
num = 2 + CountPassengersInTrain(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)
|
//two drivers + passangers killed in train coll (if it was not crashed already)
|
||||||
num += 2 + CountPassengersInTrain(coll);
|
num += 2 + CountPassengersInTrain(coll);
|
||||||
|
|
||||||
|
@ -2360,9 +2366,10 @@ static void CheckTrainCollision(Vehicle *v)
|
||||||
SetDParam(0, num);
|
SetDParam(0, num);
|
||||||
|
|
||||||
AddNewsItem(STR_8868_TRAIN_CRASH_DIE_IN_FIREBALL,
|
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,
|
v->index,
|
||||||
0);
|
0
|
||||||
|
);
|
||||||
|
|
||||||
ModifyStationRatingAround(v->tile, v->owner, -160, 30);
|
ModifyStationRatingAround(v->tile, v->owner, -160, 30);
|
||||||
SndPlayVehicleFx(SND_13_BIG_CRASH, v);
|
SndPlayVehicleFx(SND_13_BIG_CRASH, v);
|
||||||
|
@ -2398,7 +2405,7 @@ static void TrainController(Vehicle *v)
|
||||||
byte old_z;
|
byte old_z;
|
||||||
|
|
||||||
/* For every vehicle after and including the given vehicle */
|
/* For every vehicle after and including the given vehicle */
|
||||||
for(;;) {
|
for (; v != NULL; prev = v, v = v->next) {
|
||||||
BeginVehicleMove(v);
|
BeginVehicleMove(v);
|
||||||
|
|
||||||
if (v->u.rail.track != 0x40) {
|
if (v->u.rail.track != 0x40) {
|
||||||
|
@ -2536,7 +2543,7 @@ static void TrainController(Vehicle *v)
|
||||||
VehiclePositionChanged(v);
|
VehiclePositionChanged(v);
|
||||||
if (prev == NULL)
|
if (prev == NULL)
|
||||||
CheckTrainCollision(v);
|
CheckTrainCollision(v);
|
||||||
goto next_vehicle;
|
continue;
|
||||||
}
|
}
|
||||||
common:;
|
common:;
|
||||||
|
|
||||||
|
@ -2556,12 +2563,6 @@ common:;
|
||||||
AffectSpeedByZChange(v, old_z);
|
AffectSpeedByZChange(v, old_z);
|
||||||
CheckTrainCollision(v);
|
CheckTrainCollision(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
next_vehicle:;
|
|
||||||
/* continue with next vehicle */
|
|
||||||
prev = v;
|
|
||||||
if ((v=v->next) == NULL)
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
invalid_rail:
|
invalid_rail:
|
||||||
|
@ -2625,10 +2626,7 @@ static void DeleteLastWagon(Vehicle *v)
|
||||||
/* Go to the last wagon and delete the link pointing there
|
/* Go to the last wagon and delete the link pointing there
|
||||||
* *u is then the one-before-last wagon, and *v the last
|
* *u is then the one-before-last wagon, and *v the last
|
||||||
* one which will physicially be removed */
|
* one which will physicially be removed */
|
||||||
while (v->next != NULL) {
|
for (; v->next != NULL; v = v->next) u = v;
|
||||||
u = v;
|
|
||||||
v = v->next;
|
|
||||||
}
|
|
||||||
u->next = NULL;
|
u->next = NULL;
|
||||||
|
|
||||||
InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
|
InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
|
||||||
|
@ -2643,7 +2641,8 @@ static void DeleteLastWagon(Vehicle *v)
|
||||||
if (!(v->u.rail.track & 0xC0))
|
if (!(v->u.rail.track & 0xC0))
|
||||||
SetSignalsOnBothDir(v->tile, FIND_FIRST_BIT(v->u.rail.track));
|
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);
|
DisableTrainCrossing(v->tile);
|
||||||
|
|
||||||
if (v->u.rail.track == 0x40) { // inside a tunnel
|
if (v->u.rail.track == 0x40) { // inside a tunnel
|
||||||
|
|
Loading…
Reference in New Issue