diff --git a/config.lib b/config.lib index 15c541c1c6..36e0aacf04 100644 --- a/config.lib +++ b/config.lib @@ -164,7 +164,7 @@ set_default() { with_ccache with_grfcodec with_nforenum - CC CXX CFLAGS CXXFLAGS LDFLAGS" + CC CXX CFLAGS CXXFLAGS LDFLAGS CFLAGS_BUILD CXXFLAGS_BUILD LDFLAGS_BUILD" } detect_params() { @@ -442,6 +442,9 @@ detect_params() { CFLAGS=* | --CFLAGS=*) CFLAGS="$optarg";; CXXFLAGS=* | --CXXFLAGS=*) CXXFLAGS="$optarg";; LDFLAGS=* | --LDFLAGS=*) LDFLAGS="$optarg";; + CFLAGS_BUILD=* | --CFLAGS_BUILD=*) CFLAGS_BUILD="$optarg";; + CXXFLAGS_BUILD=* | --CXXFLAGS_BUILD=*) CXXFLAGS_BUILD="$optarg";; + LDFLAGS_BUILD=* | --LDFLAGS_BUILD=*) LDFLAGS_BUILD="$optarg";; --ignore-extra-parameters) ignore_extra_parameters="1";; @@ -1386,11 +1389,11 @@ make_compiler_cflags() { make_cflags_and_ldflags() { # General CFlags for BUILD - CFLAGS_BUILD="" + CFLAGS_BUILD="$CFLAGS_BUILD" # Special CXXFlags for BUILD - CXXFLAGS_BUILD="" + CXXFLAGS_BUILD="$CXXFLAGS_BUILD" # LDFLAGS for BUILD - LDFLAGS_BUILD="" + LDFLAGS_BUILD="$LDFLAGS_BUILD" # FEATURES for BUILD (lto) FEATURES_BUILD="" # General CFlags for HOST @@ -1807,6 +1810,9 @@ make_cflags_and_ldflags() { fi fi + log 1 "using CFLAGS_BUILD... $CFLAGS_BUILD" + log 1 "using CXXFLAGS_BUILD... $CXXFLAGS_BUILD" + log 1 "using LDFLAGS_BUILD... $LDFLAGS_BUILD" log 1 "using CFLAGS... $CFLAGS" log 1 "using CXXFLAGS... $CXXFLAGS" log 1 "using LDFLAGS... $LIBS $LDFLAGS" diff --git a/src/core/smallvec_type.hpp b/src/core/smallvec_type.hpp index c230b4750e..586eb9c5e2 100644 --- a/src/core/smallvec_type.hpp +++ b/src/core/smallvec_type.hpp @@ -39,21 +39,39 @@ public: * Copy constructor. * @param other The other vector to copy. */ + SmallVector(const SmallVector &other) : data(NULL), items(0), capacity(0) + { + this->Assign(other); + } + + /** + * Generic copy constructor. + * @param other The other vector to copy. + */ template SmallVector(const SmallVector &other) : data(NULL), items(0), capacity(0) { - MemCpyT(this->Append(other.Length()), other.Begin(), other.Length()); + this->Assign(other); } /** * Assignment. - * @param other The new vector that. + * @param other The other vector to assign. + */ + SmallVector &operator=(const SmallVector &other) + { + this->Assign(other); + return *this; + } + + /** + * Generic assignment. + * @param other The other vector to assign. */ template SmallVector &operator=(const SmallVector &other) { - this->Reset(); - MemCpyT(this->Append(other.Length()), other.Begin(), other.Length()); + this->Assign(other); return *this; } @@ -62,6 +80,18 @@ public: free(this->data); } + /** + * Assign items from other vector. + */ + template + inline void Assign(const SmallVector &other) + { + if ((const void *)&other == (void *)this) return; + + this->Clear(); + if (other.Length() > 0) MemCpyT(this->Append(other.Length()), other.Begin(), other.Length()); + } + /** * Remove all items from the list. */ diff --git a/src/depend/depend.cpp b/src/depend/depend.cpp index 67ceec25fe..1805e3286a 100644 --- a/src/depend/depend.cpp +++ b/src/depend/depend.cpp @@ -910,7 +910,10 @@ int main(int argc, char *argv[]) size = ftell(src); rewind(src); content = (char*)malloc(size * sizeof(*content)); - fread(content, 1, size, src); + if (fread(content, 1, size, src) != (size_t)size) { + fprintf(stderr, "Could not read %s\n", filename); + exit(-2); + } fclose(src); } @@ -919,7 +922,10 @@ int main(int argc, char *argv[]) if (size != 0) { src = fopen(backup, "wb"); - fwrite(content, 1, size, src); + if (fwrite(content, 1, size, src) != (size_t)size) { + fprintf(stderr, "Could not write %s\n", filename); + exit(-2); + } fclose(src); /* Then append it to the real file. */ diff --git a/src/newgrf.cpp b/src/newgrf.cpp index cf9cc5bbfa..eb7ea39f75 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -1041,7 +1041,7 @@ static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop } else if (_cur.grffile->grf_version >= 8) { /* Use translated cargo. Might result in CT_INVALID (first refittable), if cargo is not defined. */ ei->cargo_type = GetCargoTranslation(ctype, _cur.grffile); - } else if (ctype < NUM_CARGO && HasBit(_cargo_mask, ctype)) { + } else if (ctype < NUM_CARGO) { /* Use untranslated cargo. */ ei->cargo_type = ctype; } else { @@ -1276,7 +1276,7 @@ static ChangeInfoResult RoadVehicleChangeInfo(uint engine, int numinfo, int prop } else if (_cur.grffile->grf_version >= 8) { /* Use translated cargo. Might result in CT_INVALID (first refittable), if cargo is not defined. */ ei->cargo_type = GetCargoTranslation(ctype, _cur.grffile); - } else if (ctype < NUM_CARGO && HasBit(_cargo_mask, ctype)) { + } else if (ctype < NUM_CARGO) { /* Use untranslated cargo. */ ei->cargo_type = ctype; } else { @@ -1454,7 +1454,7 @@ static ChangeInfoResult ShipVehicleChangeInfo(uint engine, int numinfo, int prop } else if (_cur.grffile->grf_version >= 8) { /* Use translated cargo. Might result in CT_INVALID (first refittable), if cargo is not defined. */ ei->cargo_type = GetCargoTranslation(ctype, _cur.grffile); - } else if (ctype < NUM_CARGO && HasBit(_cargo_mask, ctype)) { + } else if (ctype < NUM_CARGO) { /* Use untranslated cargo. */ ei->cargo_type = ctype; } else { @@ -8205,6 +8205,9 @@ static void CalculateRefitMasks() only_defaultcargo = (ei->refit_mask == 0); } + /* Clear invalid cargoslots (from default vehicles or pre-NewCargo GRFs) */ + if (!HasBit(_cargo_mask, ei->cargo_type)) ei->cargo_type = CT_INVALID; + /* Ensure that the vehicle is either not refittable, or that the default cargo is one of the refittable cargoes. * Note: Vehicles refittable to no cargo are handle differently to vehicle refittable to a single cargo. The latter might have subtypes. */ if (!only_defaultcargo && (e->type != VEH_SHIP || e->u.ship.old_refittable) && ei->cargo_type != CT_INVALID && !HasBit(ei->refit_mask, ei->cargo_type)) { diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 1b60bfc6ef..db78734af0 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -2604,7 +2604,7 @@ set_ground: static TrackStatus GetTileTrackStatus_Track(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side) { /* Case of half tile slope with water. */ - if (mode == TRANSPORT_WATER && IsPlainRail(tile) && GetRailGroundType(tile) == RAIL_GROUND_WATER) { + if (mode == TRANSPORT_WATER && IsPlainRail(tile) && GetRailGroundType(tile) == RAIL_GROUND_WATER && IsSlopeWithOneCornerRaised(GetTileSlope(tile))) { TrackBits tb = GetTrackBits(tile); switch (tb) { default: NOT_REACHED(); @@ -2925,6 +2925,14 @@ static CommandCost TestAutoslopeOnRailTile(TileIndex tile, uint flags, int z_old return cost; } +/** + * Test-procedure for HasVehicleOnPos to check for a ship. + */ +static Vehicle *EnsureNoShipProc(Vehicle *v, void *data) +{ + return v->type == VEH_SHIP ? v : NULL; +} + static CommandCost TerraformTile_Track(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new) { int z_old; @@ -2934,6 +2942,9 @@ static CommandCost TerraformTile_Track(TileIndex tile, DoCommandFlag flags, int /* Is there flat water on the lower halftile that must be cleared expensively? */ bool was_water = (GetRailGroundType(tile) == RAIL_GROUND_WATER && IsSlopeWithOneCornerRaised(tileh_old)); + /* Allow clearing the water only if there is no ship */ + if (was_water && HasVehicleOnPos(tile, NULL, &EnsureNoShipProc)) return_cmd_error(STR_ERROR_SHIP_IN_THE_WAY); + /* First test autoslope. However if it succeeds we still have to test the rest, because non-autoslope terraforming is cheaper. */ CommandCost autoslope_result = TestAutoslopeOnRailTile(tile, flags, z_old, tileh_old, z_new, tileh_new, rail_bits);