author | celestar |
Wed, 21 Mar 2007 15:12:30 +0000 | |
branch | gamebalance |
changeset 9900 | 750202458d8b |
parent 9899 | cde52f745560 |
child 9902 | ed8f92929297 |
permissions | -rw-r--r-- |
9899
cde52f745560
(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.
celestar
parents:
diff
changeset
|
1 |
/* $Id */ |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
2 |
|
cde52f745560
(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.
celestar
parents:
diff
changeset
|
3 |
/** @file */ |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
4 |
|
cde52f745560
(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.
celestar
parents:
diff
changeset
|
5 |
#include "stdafx.h" |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
6 |
#include "openttd.h" |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
7 |
#include "road_map.h" |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
8 |
#include "town.h" |
9900
750202458d8b
(svn r9389) [gamebalance] -Fix(r9332): I should not use uninitialized variables and shall also find out why my g++ didn't warn me in the first place
celestar
parents:
9899
diff
changeset
|
9 |
#include "town_map.h" |
9899
cde52f745560
(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.
celestar
parents:
diff
changeset
|
10 |
|
cde52f745560
(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.
celestar
parents:
diff
changeset
|
11 |
/* static */ |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
12 |
const Town *Town::GetRadiusGroupForTile(TileIndex tile, uint &group) |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
13 |
{ |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
14 |
const Town *t; |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
15 |
group = 0; |
9900
750202458d8b
(svn r9389) [gamebalance] -Fix(r9332): I should not use uninitialized variables and shall also find out why my g++ didn't warn me in the first place
celestar
parents:
9899
diff
changeset
|
16 |
const Town *best_town = NULL; |
9899
cde52f745560
(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.
celestar
parents:
diff
changeset
|
17 |
|
cde52f745560
(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.
celestar
parents:
diff
changeset
|
18 |
DEBUG(eco, 7, "Obtaining highest town radius for tile 0x%x", tile); |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
19 |
|
cde52f745560
(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.
celestar
parents:
diff
changeset
|
20 |
/* We do have a tile that directly belongs to a town */ |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
21 |
if (IsTileType(tile, MP_HOUSE) || |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
22 |
(IsTileType(tile, MP_STREET) && |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
23 |
(IsLevelCrossing(tile) ? GetCrossingRoadOwner(tile) : GetTileOwner(tile)) == OWNER_TOWN)) { |
9900
750202458d8b
(svn r9389) [gamebalance] -Fix(r9332): I should not use uninitialized variables and shall also find out why my g++ didn't warn me in the first place
celestar
parents:
9899
diff
changeset
|
24 |
t = GetTownByTile(tile); |
9899
cde52f745560
(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.
celestar
parents:
diff
changeset
|
25 |
group = t->GetRadiusGroup(tile, true) + 1; |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
26 |
DEBUG(eco, 6, "Tile 0x%x belongs to town at 0x%x, level %d", tile, t->xy, group); |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
27 |
return t; |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
28 |
} |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
29 |
|
cde52f745560
(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.
celestar
parents:
diff
changeset
|
30 |
FOR_ALL_TOWNS(t) { |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
31 |
if (1 + t->GetRadiusGroup(tile, true) > group) { |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
32 |
group = t->GetRadiusGroup(tile, true) + 1; |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
33 |
DEBUG(eco, 7, "Higher group (%d) found for town at 0x%x", group, t->xy); |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
34 |
best_town = t; |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
35 |
} |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
36 |
} |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
37 |
|
9900
750202458d8b
(svn r9389) [gamebalance] -Fix(r9332): I should not use uninitialized variables and shall also find out why my g++ didn't warn me in the first place
celestar
parents:
9899
diff
changeset
|
38 |
assert(best_town != NULL); |
750202458d8b
(svn r9389) [gamebalance] -Fix(r9332): I should not use uninitialized variables and shall also find out why my g++ didn't warn me in the first place
celestar
parents:
9899
diff
changeset
|
39 |
|
9899
cde52f745560
(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.
celestar
parents:
diff
changeset
|
40 |
return best_town; |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
41 |
} |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
42 |
|
cde52f745560
(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.
celestar
parents:
diff
changeset
|
43 |
uint Town::GetRadiusGroup(TileIndex tile, bool ignore_funding) const |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
44 |
{ |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
45 |
uint dist = DistanceSquare(tile, xy); |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
46 |
uint smallest = 0; |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
47 |
|
cde52f745560
(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.
celestar
parents:
diff
changeset
|
48 |
if (!ignore_funding && fund_buildings_months > 0 && dist < 25) return 4; |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
49 |
|
cde52f745560
(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.
celestar
parents:
diff
changeset
|
50 |
for (uint i = 0; i != lengthof(radius); i++) if (dist < radius[i]) smallest = i; |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
51 |
|
cde52f745560
(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.
celestar
parents:
diff
changeset
|
52 |
return smallest; |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
53 |
} |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
54 |
|
cde52f745560
(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.
celestar
parents:
diff
changeset
|
55 |
void Town::UpdateActivity() |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
56 |
{ |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
57 |
if (new_act_pass == 0 && act_pass == 0) { |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
58 |
DEBUG(eco, 7, "Town is not connected, bailing out"); |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
59 |
return; |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
60 |
} |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
61 |
|
cde52f745560
(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.
celestar
parents:
diff
changeset
|
62 |
static const FixedT<int, 12> max_activity_change (1, 400); |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
63 |
static const FixedT<int, 12> min_activity_change = -max_activity_change; |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
64 |
FixedT<int, 12> activity_change (1, 200); |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
65 |
|
cde52f745560
(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.
celestar
parents:
diff
changeset
|
66 |
activity_change *= act_pass; |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
67 |
activity_change /= max_pass; |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
68 |
activity_change -= max_activity_change; |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
69 |
DEBUG(eco, 6, "Raw EAL change for town at 0x%x is %f", xy, (double)activity_change); |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
70 |
|
cde52f745560
(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.
celestar
parents:
diff
changeset
|
71 |
if (activity_change > max_activity_change) activity_change = max_activity_change; |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
72 |
if (activity_change < min_activity_change) activity_change = min_activity_change; |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
73 |
|
cde52f745560
(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.
celestar
parents:
diff
changeset
|
74 |
this->SetActivity(this->GetActivity() + activity_change); |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
75 |
|
cde52f745560
(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.
celestar
parents:
diff
changeset
|
76 |
DEBUG(eco, 5, "Modifying EAL for town at 0x%x by %f to %f", xy, (double)activity_change, (double)this->GetActivity()); |
cde52f745560
(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.
celestar
parents:
diff
changeset
|
77 |
} |