(svn r9386) [gamebalance] -Feature: Selling and buying land costs now take proximity to town centers into account. Move some code around while I'm at it. Also selling land gives as much money as buying land costs. gamebalance
authorcelestar
Wed, 21 Mar 2007 11:46:54 +0000
branchgamebalance
changeset 9899 cde52f745560
parent 9898 324dad59eb35
child 9900 750202458d8b
(svn r9386) [gamebalance] -Feature: Selling and buying land costs now take proximity to town centers into account. Move some code around while I'm at it. Also selling land gives as much money as buying land costs.
projects/openttd.vcproj
projects/openttd_vs80.vcproj
source.list
src/clear_cmd.cpp
src/command.cpp
src/town.cpp
src/town.h
--- a/projects/openttd.vcproj	Mon Mar 19 19:52:26 2007 +0000
+++ b/projects/openttd.vcproj	Wed Mar 21 11:46:54 2007 +0000
@@ -359,6 +359,9 @@
 				RelativePath=".\..\src\tile.cpp">
 			</File>
 			<File
+				RelativePath=".\..\src\town.cpp">
+			</File>
+			<File
 				RelativePath=".\..\src\vehicle.cpp">
 			</File>
 			<File
--- a/projects/openttd_vs80.vcproj	Mon Mar 19 19:52:26 2007 +0000
+++ b/projects/openttd_vs80.vcproj	Wed Mar 21 11:46:54 2007 +0000
@@ -708,6 +708,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\..\src\town.cpp"
+				>
+			</File>
+			<File
 				RelativePath=".\..\src\vehicle.cpp"
 				>
 			</File>
--- a/source.list	Mon Mar 19 19:52:26 2007 +0000
+++ b/source.list	Wed Mar 21 11:46:54 2007 +0000
@@ -72,6 +72,7 @@
 tgp.cpp
 thread.cpp
 tile.cpp
+town.cpp
 #if WIN32
 #else
 	#if WINCE
--- a/src/clear_cmd.cpp	Mon Mar 19 19:52:26 2007 +0000
+++ b/src/clear_cmd.cpp	Wed Mar 21 11:46:54 2007 +0000
@@ -21,6 +21,7 @@
 #include "unmovable_map.h"
 #include "genworld.h"
 #include "industry.h"
+#include "town.h"
 
 struct TerraformerHeightMod {
 	TileIndex tile;
@@ -409,15 +410,15 @@
 	return (cost == 0) ? CMD_ERROR : cost;
 }
 
-/** Purchase a land area. Actually you only purchase one tile, so
- * the name is a bit confusing ;p
+/**
+ * Purchase a single tile
  * @param tile the tile the player is purchasing
  * @param flags for this command type
  * @param p1 unused
  * @param p2 unused
  * @return error of cost of operation
  */
-int32 CmdPurchaseLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+int32 CmdPurchaseTile(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
 	int32 cost;
 
@@ -437,7 +438,9 @@
 		MarkTileDirtyByTile(tile);
 	}
 
-	return cost + _price.purchase_land * 10;
+	uint rad;
+	Town::GetRadiusGroupForTile(tile, rad);
+	return cost + (_price.purchase_land * 10) * rad * rad;
 }
 
 
@@ -465,15 +468,15 @@
 	return price;
 }
 
-/** Sell a land area. Actually you only sell one tile, so
- * the name is a bit confusing ;p
+/**
+ * Sell a tile
  * @param tile the tile the player is selling
  * @param flags for this command type
  * @param p1 unused
  * @param p2 unused
  * @return error or cost of operation
  */
-int32 CmdSellLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+int32 CmdSellTile(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 
@@ -485,7 +488,9 @@
 
 	if (flags & DC_EXEC) DoClearSquare(tile);
 
-	return - _price.purchase_land * 2;
+	uint rad;
+	Town::GetRadiusGroupForTile(tile, rad);
+	return -(_price.purchase_land * 10) * rad * rad;
 }
 
 
--- a/src/command.cpp	Mon Mar 19 19:52:26 2007 +0000
+++ b/src/command.cpp	Wed Mar 21 11:46:54 2007 +0000
@@ -36,8 +36,8 @@
 
 DEF_COMMAND(CmdTerraformLand);
 
-DEF_COMMAND(CmdPurchaseLandArea);
-DEF_COMMAND(CmdSellLandArea);
+DEF_COMMAND(CmdPurchaseTile);
+DEF_COMMAND(CmdSellTile);
 
 DEF_COMMAND(CmdBuildTunnel);
 
@@ -180,8 +180,8 @@
 	{CmdBuildSingleSignal,                   0}, /*   8 */
 	{CmdRemoveSingleSignal,                  0}, /*   9 */
 	{CmdTerraformLand,                       0}, /*  10 */
-	{CmdPurchaseLandArea,                    0}, /*  11 */
-	{CmdSellLandArea,                        0}, /*  12 */
+	{CmdPurchaseTile,                        0}, /*  11 */
+	{CmdSellTile,                            0}, /*  12 */
 	{CmdBuildTunnel,                         0}, /*  13 */
 	{CmdRemoveFromRailroadStation,           0}, /*  14 */
 	{CmdConvertRail,                         0}, /*  15 */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/town.cpp	Wed Mar 21 11:46:54 2007 +0000
@@ -0,0 +1,73 @@
+/* $Id */
+
+/** @file */
+
+#include "stdafx.h"
+#include "openttd.h"
+#include "road_map.h"
+#include "town.h"
+
+/* static */
+const Town *Town::GetRadiusGroupForTile(TileIndex tile, uint &group)
+{
+	const Town *t;
+	group = 0;
+	const Town *best_town;
+
+	DEBUG(eco, 7, "Obtaining highest town radius for tile 0x%x", tile);
+
+	/* We do have a tile that directly belongs to a town */
+	if (IsTileType(tile, MP_HOUSE) ||
+			(IsTileType(tile, MP_STREET) &&
+			(IsLevelCrossing(tile) ? GetCrossingRoadOwner(tile) : GetTileOwner(tile)) == OWNER_TOWN)) {
+		group = t->GetRadiusGroup(tile, true) + 1;
+		DEBUG(eco, 6, "Tile 0x%x belongs to town at 0x%x, level %d", tile, t->xy, group);
+		return t;
+	}
+
+	FOR_ALL_TOWNS(t) {
+		if (1 + t->GetRadiusGroup(tile, true) > group) {
+			group = t->GetRadiusGroup(tile, true) + 1;
+			DEBUG(eco, 7, "Higher group (%d) found for town at 0x%x", group, t->xy);
+			best_town = t;
+		}
+	}
+
+	return best_town;
+}
+
+uint Town::GetRadiusGroup(TileIndex tile, bool ignore_funding) const
+{
+	uint dist = DistanceSquare(tile, xy);
+	uint smallest = 0;
+
+	if (!ignore_funding && fund_buildings_months > 0 && dist < 25) return 4;
+
+	for (uint i = 0; i != lengthof(radius); i++) if (dist < radius[i]) smallest = i;
+
+	return smallest;
+}
+
+void Town::UpdateActivity()
+{
+	if (new_act_pass == 0 && act_pass == 0) {
+		DEBUG(eco, 7, "Town is not connected, bailing out");
+		return;
+	}
+
+	static const FixedT<int, 12> max_activity_change   (1, 400);
+	static const FixedT<int, 12> min_activity_change = -max_activity_change;
+	FixedT<int, 12>              activity_change       (1, 200);
+
+	activity_change *= act_pass;
+	activity_change /= max_pass;
+	activity_change -= max_activity_change;
+	DEBUG(eco, 6, "Raw EAL change for town at 0x%x is %f", xy, (double)activity_change);
+
+	if (activity_change > max_activity_change) activity_change = max_activity_change;
+	if (activity_change < min_activity_change) activity_change = min_activity_change;
+
+	this->SetActivity(this->GetActivity() + activity_change);
+
+	DEBUG(eco, 5, "Modifying EAL for town at 0x%x by %f to %f", xy, (double)activity_change, (double)this->GetActivity());
+}
--- a/src/town.h	Mon Mar 19 19:52:26 2007 +0000
+++ b/src/town.h	Wed Mar 21 11:46:54 2007 +0000
@@ -179,29 +179,7 @@
 	 * will be untouched.
 	 * @pre Must be called BEFORE UpdateAmounts
 	 */
-	void UpdateActivity()
-	{
-		if (new_act_pass == 0 && act_pass == 0) {
-			DEBUG(eco, 7, "Town is not connected, bailing out");
-			return;
-		}
-
-		static const FixedT<int, 12> max_activity_change   (1, 400);
-		static const FixedT<int, 12> min_activity_change = -max_activity_change;
-		FixedT<int, 12>              activity_change       (1, 200);
-
-		activity_change *= act_pass;
-		activity_change /= max_pass;
-		activity_change -= max_activity_change;
-		DEBUG(eco, 6, "Raw EAL change for town at 0x%x is %f", xy, (double)activity_change);
-
-		if (activity_change > max_activity_change) activity_change = max_activity_change;
-		if (activity_change < min_activity_change) activity_change = min_activity_change;
-
-		this->SetActivity(this->GetActivity() + activity_change);
-
-		DEBUG(eco, 5, "Modifying EAL for town at 0x%x by %f to %f", xy, (double)activity_change, (double)this->GetActivity());
-	}
+	void UpdateActivity();
 
 	/**
 	 * Gets the so ralled "town radius group" of a tile which is a
@@ -212,18 +190,15 @@
 	 *                        appropriate group unless this flag is set.
 	 * @return                The town radius group
 	 */
-	uint GetRadiusGroup(TileIndex tile, bool ignore_funding = false) const
-	{
-		uint dist = DistanceSquare(tile, xy);
-		uint smallest = 0;
+	uint GetRadiusGroup(TileIndex tile, bool ignore_funding = false) const;
 
-		if (!ignore_funding && fund_buildings_months > 0 && dist < 25) return 4;
-
-		for (uint i = 0; i != lengthof(radius); i++) if (dist < radius[i]) smallest = i;
-
-		return smallest;
-	}
-
+	/**
+	 * Obtains the highest Town Radius Group a town is in.
+	 * @param [in]  tile  The tile which to find the radius group for
+	 * @param [out] group The group for in which tile is located
+	 * @return            The town to which 'group' belongs
+	 */
+	static const Town *GetRadiusGroupForTile(TileIndex tile, uint &group);
 };
 
 struct HouseSpec {