(svn r12867) [0.6] -Backport from trunk r12706, r12642, r12622, r12572, r12542: 0.6
authorrubidium
Thu, 24 Apr 2008 12:15:24 +0000
branch0.6
changeset 10326 2820eb37d828
parent 10325 7065f9963266
child 10327 2274772a4424
(svn r12867) [0.6] -Backport from trunk r12706, r12642, r12622, r12572, r12542:
- Fix: Do not crash very hard on unrecognised savegames, just go back to the intro menu instead (r12706)
- Fix: Remove buggy buoys at tile 0 from old TTDP savegames (r12642)
- Fix: Infinite loop in case your compiler decides that enums are unsigned by default (r12622)
- Fix: min() has 32bit arguments, clamping of 64bit values did not work (r12572)
- Fix: Do not install scenarios into the current user's homedir when running 'make install', that is silly. Simply always install scenarios system wide instead (r12542)
Makefile.in
src/core/math_func.hpp
src/oldloader.cpp
src/road_cmd.cpp
src/saveload.cpp
--- a/Makefile.in	Thu Apr 24 12:05:36 2008 +0000
+++ b/Makefile.in	Thu Apr 24 12:15:24 2008 +0000
@@ -22,7 +22,6 @@
 INSTALL_BINARY_DIR = "$(INSTALL_DIR)/"!!BINARY_DIR!!
 INSTALL_ICON_DIR = "$(INSTALL_DIR)/"!!ICON_DIR!!
 INSTALL_DATA_DIR = "$(INSTALL_DIR)/"!!DATA_DIR!!
-INSTALL_PERSONAL_DIR = !!PERSONAL_DIR!!
 TTD = !!TTD!!
 TTDS = $(SRC_DIRS:%=%/$(TTD))
 OS = !!OS!!
@@ -271,10 +270,5 @@
 	$(Q)install -m 644 "$(BUNDLE_DIR)/data/"* "$(INSTALL_DATA_DIR)/data"
 	$(Q)install -m 644 "$(BUNDLE_DIR)/docs/"* "$(INSTALL_DATA_DIR)/docs"
 	$(Q)install -m 644 "$(BUNDLE_DIR)/media/"* "$(INSTALL_ICON_DIR)"
-ifdef INSTALL_PERSONAL_DIR
-	$(Q)mkdir -p ~/"$(INSTALL_PERSONAL_DIR)"
-	$(Q)cp -R "$(BUNDLE_DIR)/scenario" ~/"$(INSTALL_PERSONAL_DIR)"
-else
 	$(Q)cp -R "$(BUNDLE_DIR)/scenario" "$(INSTALL_DATA_DIR)"
-endif # INSTALL_PERSONAL_DIR
 endif # OSXAPP
--- a/src/core/math_func.hpp	Thu Apr 24 12:05:36 2008 +0000
+++ b/src/core/math_func.hpp	Thu Apr 24 12:15:24 2008 +0000
@@ -177,7 +177,7 @@
  */
 static inline uint16 ClampToU16(const uint64 a)
 {
-	return min(a, 0xFFFF);
+	return (uint16)(a <= 0xFFFFU ? a : 0xFFFFU);
 }
 
 /**
--- a/src/oldloader.cpp	Thu Apr 24 12:05:36 2008 +0000
+++ b/src/oldloader.cpp	Thu Apr 24 12:15:24 2008 +0000
@@ -1694,6 +1694,12 @@
 
 	fclose(ls.file);
 
+	/* Some old TTDP savegames could have buoys at tile 0
+	 * (without assigned station struct)
+	 * MakeWater() can be used as long as sea has the same
+	 * format as old savegames (eg. everything is zeroed) */
+	MakeWater(0);
+
 	_pause_game = 2;
 
 	return true;
--- a/src/road_cmd.cpp	Thu Apr 24 12:05:36 2008 +0000
+++ b/src/road_cmd.cpp	Thu Apr 24 12:15:24 2008 +0000
@@ -865,13 +865,14 @@
 
 			/* Must iterate over the roadtypes in a reverse manner because
 			 * tram tracks must be removed before the road bits. */
-			for (RoadType rt = ROADTYPE_HWAY; rt >= ROADTYPE_ROAD; rt--) {
+			RoadType rt = ROADTYPE_HWAY;
+			do {
 				if (HasBit(rts, rt)) {
 					CommandCost tmp_ret = RemoveRoad(tile, flags, GetCrossingRoadBits(tile), rt, false);
 					if (CmdFailed(tmp_ret)) return tmp_ret;
 					ret.AddCost(tmp_ret);
 				}
-			}
+			} while (rt-- != ROADTYPE_ROAD);
 
 			if (flags & DC_EXEC) {
 				DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
--- a/src/saveload.cpp	Thu Apr 24 12:05:36 2008 +0000
+++ b/src/saveload.cpp	Thu Apr 24 12:15:24 2008 +0000
@@ -76,13 +76,24 @@
 
 enum NeedLengthValues {NL_NONE = 0, NL_WANTLENGTH = 1, NL_CALCLENGTH = 2};
 
+/** Error handler, calls longjmp to simulate an exception.
+ * @todo this was used to have a central place to handle errors, but it is
+ * pretty ugly, and seriously interferes with any multithreaded approaches */
+static void NORETURN SlError(StringID string, const char *extra_msg = NULL)
+{
+	_sl.error_str = string;
+	free(_sl.extra_msg);
+	_sl.extra_msg = (extra_msg == NULL) ? NULL : strdup(extra_msg);
+	throw std::exception();
+}
+
 /**
  * Fill the input buffer by reading from the file with the given reader
  */
 static void SlReadFill()
 {
 	uint len = _sl.read_bytes();
-	assert(len != 0);
+	if (len == 0) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_SAVEGAME, "Unexpected end of chunk");
 
 	_sl.bufp = _sl.buf;
 	_sl.bufe = _sl.buf + len;
@@ -137,17 +148,6 @@
 	_sl.bufe = _sl.buf + _sl.bufsize;
 }
 
-/** Error handler, calls longjmp to simulate an exception.
- * @todo this was used to have a central place to handle errors, but it is
- * pretty ugly, and seriously interferes with any multithreaded approaches */
-static void NORETURN SlError(StringID string, const char *extra_msg = NULL)
-{
-	_sl.error_str = string;
-	free(_sl.extra_msg);
-	_sl.extra_msg = (extra_msg == NULL) ? NULL : strdup(extra_msg);
-	throw std::exception();
-}
-
 /** Read in a single byte from file. If the temporary buffer is full,
  * flush it to its final destination
  * @return return the read byte from file
@@ -1524,7 +1524,7 @@
 			uint i;
 			uint count = 1 << Savegame_POOL_BLOCK_SIZE_BITS;
 
-			assert(_ts.count == _sl.offs_base);
+			if (_ts.count != _sl.offs_base) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_SAVEGAME, "Unexpected size of chunk");
 			for (i = 0; i != _Savegame_pool.GetBlockCount() - 1; i++) {
 				_sl.buf = _Savegame_pool.blocks[i];
 				fmt->writer(count);
@@ -1537,7 +1537,7 @@
 		}
 
 		fmt->uninit_write();
-		assert(_ts.count == _sl.offs_base);
+		if (_ts.count != _sl.offs_base) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_SAVEGAME, "Unexpected size of chunk");
 		GetSavegameFormat("memory")->uninit_write(); // clean the memorypool
 		fclose(_sl.fh);