Index: unmovable_cmd.c
===================================================================
--- unmovable_cmd.c	(revision 808)
+++ unmovable_cmd.c	(working copy)
@@ -4,6 +4,7 @@
 #include "viewport.h"
 #include "player.h"
 #include "gui.h"
+#include "economy.h"
 
 typedef struct DrawTileUnmovableStruct {
 	uint16 image;
@@ -125,7 +116,32 @@
 
 static void GetAcceptedCargo_Unmovable(uint tile, AcceptedCargo *ac)
 {
-	/* not used */
+	byte m5 = _map5[tile];
+	byte level; // HQ level (depends on company performance) in the range 1..5.
+
+	if (!(m5 & 0x80)) {
+		/* not used */
+		return;
+	}
+
+	/* HQ accepts passenger and mail; but we have to divide the values
+	 * between 4 tiles it occupies! */
+
+	level = (m5 & ~0x80) / 4 + 1;
+
+	// Top town building generates 10, so to make HQ interesting, the top
+	// type makes 20.
+	ac->type_1 = CT_PASSENGERS;
+	ac->amount_1 = level;
+	if (!ac->amount_1) ac->amount_1 = 1;
+
+	// Top town building generates 4, HQ can make up to 8. The
+	// proportion passengers:mail is different because such a huge
+	// commercial building generates unusually high amount of mail
+	// correspondence per physical visitor.
+	ac->type_2 = CT_MAIL;
+	ac->amount_2 = level / 2;
+	if (!ac->amount_2) ac->amount_2 = 1;
 }
 
 static const StringID _unmovable_tile_str[] = {
@@ -151,7 +167,38 @@
 
 static void TileLoop_Unmovable(uint tile)
 {
-	/* not used */
+	byte m5 = _map5[tile];
+	byte level; // HQ level (depends on company performance) in the range 1..5.
+	uint32 r;
+
+	if (!(m5 & 0x80)) {
+		/* not used */
+		return;
+	}
+
+	/* HQ accepts passenger and mail; but we have to divide the values
+	 * between 4 tiles it occupies! */
+
+	level = (m5 & ~0x80) / 4 + 1;
+	assert(level < 6);
+
+	r = Random();
+	// Top town buildings generate 250, so the top HQ type makes 256.
+	if ((byte) r < (256 / (6 - level)) / 4) {
+		uint amt = ((byte) r >> 3) / 4 + 1;
+		if (_economy.fluct <= 0) amt = (amt + 1) >> 1;
+		MoveGoodsToStation(tile, 2, 2, CT_PASSENGERS, amt);
+	}
+
+	r >>= 8;
+	// Top town building generates 90, HQ can make up to 196. The
+	// proportion passengers:mail is about the same as in the acceptance
+	// equations.
+	if ((byte) r < (196 / (6 - level)) / 4) {
+		uint amt = ((byte) r >> 3) / 4 + 1;
+		if (_economy.fluct <= 0) amt = (amt + 1) >> 1;
+		MoveGoodsToStation(tile, 2, 2, CT_MAIL, amt);
+	}
 }
 
 
