diff --git a/.gitignore b/.gitignore
index b40d932..eef5d36 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,11 @@
 Makefile*
+gitmake-all
+gitmake-origin
+gitmake-build
 bin/*
 bundle/*
+bundles/
+save
 !bin/data/chars.grf
 !bin/data/openttdd.grf
 !bin/data/openttdw.grf
@@ -10,3 +15,11 @@ bundle/*
 config.*
 objs/*
 src/rev.cpp
+.cproject
+.project
+data/
+media/openttd.desktop
+patches/
+old/
+grf/
+docs/own
diff --git a/config.lib b/config.lib
index 2d84ca4..bd72f6a 100644
--- a/config.lib
+++ b/config.lib
@@ -2303,16 +2303,6 @@ detect_library() {
 		eval "res=\$$2"
 		if [ -z "$res" ]; then
 			log 2 "  trying /usr/local/include/$4$5... no"
-			eval "$2=`ls -1 /mingw/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
-		fi
-		eval "res=\$$2"
-		if [ -z "$res" ]; then
-			log 2 "  trying /usr/local/include/$4$5... no"
-			eval "$2=`ls -1 /opt/local/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`"
-		fi
-		eval "res=\$$2"
-		if [ -z "$res" ]; then
-			log 2 "  trying /opt/local/include/$4$5... no"
 		fi
 
 		eval "res=\$$2"
@@ -2334,11 +2324,6 @@ detect_library() {
 			eval "res=\$$2"
 			if [ -z "$res" ]; then
 				log 2 "  trying /usr/local/lib/$3... no"
-				eval "$2=`ls /mingw/lib/*.a 2>/dev/null | egrep \"\/$3\$\"`"
-			fi
-			eval "res=\$$2"
-			if [ -z "$res" ]; then
-				log 2 "  trying /mingw/lib/$3... no"
 				log 1 "configure: error: $2 couldn't be found"
 				log 1 "configure: error: you requested a static link, but I can't find $3"
 
diff --git a/gitmake b/gitmake
new file mode 100644
index 0000000..46a2efb
--- /dev/null
+++ b/gitmake
@@ -0,0 +1,80 @@
+
+VPATH=.:./.git/refs/heads/
+
+gitmake-all: cargodist diaglvl alteconomy
+	touch gitmake-all
+
+check: clean gitmake-origin
+	echo "check OK"
+
+clean:
+	rm -f gitmake-origin
+	rm -f patches/current/*
+
+%:
+	git checkout ${@}-tmp
+	for branch in $(^F); do git merge $${branch}; done 
+	git checkout $@
+	git merge ${@}-tmp
+	test -e gitmake-build && make -j`cat gitmake-build` || true
+	./make_diffs
+
+gitmake-origin:
+	git fetch git://git.openttd.org/openttd/trunk.git master:trunk
+	git log trunk | grep -m 1 '(svn r[0-9]*)' | awk '{print $$2}' | sed -e 's/)//' > gitmake-origin
+	cp gitmake-origin patches/current/TRUNK_VERSION.txt
+	git diff --numstat trunk master | grep -v .gitignore | grep -v gitmake | grep -v make_diffs && touch gitmake-origin || touch -t 197001010100 gitmake-origin
+
+master: gitmake-origin
+	git checkout $@
+	git merge trunk
+	test -e gitmake-build && make -j`cat gitmake-build` || true
+
+smallmap-zoom-in: master 
+
+supplyscale: components
+
+cargodist: station-gui smallmap-stats warning-sign supplyscale
+
+station-gui: cargomap
+
+smallmap-stats: smallmap-zoom-in cargomap
+
+texteff: master
+
+flowmapping-core: mcf
+
+mcf: demands
+
+demands: components
+
+components: capacities
+
+capacities: moving-average
+
+diaglvl: tileiter
+
+tileiter: master
+
+cargomap: flowmapping-core texteff multimap reservation
+
+reservation: master
+
+multimap: master
+
+warning-sign: demands
+
+moving-average: master
+
+delivery-rating: master
+
+rating-weight: delivery-rating
+
+rating-payment: delivery-rating
+
+alteconomy: rating-payment rating-weight
+
+push: master cargodist station-gui smallmap-stats flowmapping-core mcf demands components capacities smallmap-zoom-in diaglvl tileiter texteff cargomap multimap reservation warning-sign moving-average supplyscale delivery-rating rating-weight rating-payment alteconomy
+	git push ulf@laramies.com:~/fonsinchen/openttd.git $(^F)
+	rsync -av --delete patches ulf@laramies.com:~/fonsinchen/
+
diff --git a/make_diffs b/make_diffs
new file mode 100755
index 0000000..00e7aed
--- /dev/null
+++ b/make_diffs
@@ -0,0 +1,6 @@
+#!/bin/sh
+BRANCH=`git status | grep "On branch" | awk '{print $4}'`
+git diff ${BRANCH}-tmp > patches/${BRANCH}_`cat gitmake-origin`.diff
+git diff master > patches/against_trunk/${BRANCH}_`cat gitmake-origin`.diff
+ln -sf ../${BRANCH}_`cat gitmake-origin`.diff patches/current/${BRANCH}.diff
+ln -sf ../against_trunk/${BRANCH}_`cat gitmake-origin`.diff patches/current/trunk-${BRANCH}.diff
diff --git a/src/core/math_func.cpp b/src/core/math_func.cpp
index 7f0630a..0289144 100644
--- a/src/core/math_func.cpp
+++ b/src/core/math_func.cpp
@@ -46,3 +46,12 @@ int GreatestCommonDivisor(int a, int b)
 	return a;
 
 }
+
+/**
+ * check if the parameter "check" is inside the interval between begin an end,
+ * including both begin and end.
+ */
+bool IsInRangeInclusive(int begin, int end, int check) {
+	if (begin > end) Swap(begin, end);
+	return begin <= check && check <= end;
+}
diff --git a/src/core/math_func.hpp b/src/core/math_func.hpp
index e0b9dbc..86363f1 100644
--- a/src/core/math_func.hpp
+++ b/src/core/math_func.hpp
@@ -317,5 +317,6 @@ static FORCEINLINE uint ToPercent16(uint i)
 
 int LeastCommonMultiple(int a, int b);
 int GreatestCommonDivisor(int a, int b);
+bool IsInRangeInclusive(int begin, int end, int check);
 
 #endif /* MATH_FUNC_HPP */
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index 36c8ecc..d07c135 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -1366,7 +1366,7 @@ static CommandCost CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTil
 				/* Clear the tiles as OWNER_TOWN to not affect town rating, and to not clear protected buildings */
 				CompanyID old_company = _current_company;
 				_current_company = OWNER_TOWN;
-				CommandCost ret = DoCommand(cur_tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR);
+				CommandCost ret = DoCommand(cur_tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR).Failed();
 				_current_company = old_company;
 
 				if (ret.Failed()) return ret;
diff --git a/src/landscape.cpp b/src/landscape.cpp
index f122c0c..3ce90c4 100644
--- a/src/landscape.cpp
+++ b/src/landscape.cpp
@@ -606,7 +606,7 @@ CommandCost CmdLandscapeClear(TileIndex tile, DoComm