summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2009-01-19 12:07:01 +0000
committerpeter1138 <peter1138@openttd.org>2009-01-19 12:07:01 +0000
commitb85389dca5bc9059e34ce035edd5e00b0f3e1a40 (patch)
treebce5d3e203e706fa510f4558be8963ee417bcc3d /src
parente84ff99a8bc1a0d0b4781cc7383f91bc1e2b5d63 (diff)
downloadopenttd-b85389dca5bc9059e34ce035edd5e00b0f3e1a40.tar.xz
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
Diffstat (limited to 'src')
-rw-r--r--src/ai/api/ai_town.cpp2
-rw-r--r--src/town.h1
-rw-r--r--src/town_cmd.cpp66
-rw-r--r--src/town_gui.cpp66
4 files changed, 66 insertions, 69 deletions
diff --git a/src/ai/api/ai_town.cpp b/src/ai/api/ai_town.cpp
index bb7dee9f2..ebb575e96 100644
--- a/src/ai/api/ai_town.cpp
+++ b/src/ai/api/ai_town.cpp
@@ -151,8 +151,6 @@
return ::GetTown(town_id)->exclusive_counter;
}
-extern uint GetMaskOfTownActions(int *nump, CompanyID cid, const Town *t);
-
/* static */ bool AITown::IsActionAvailable(TownID town_id, TownAction town_action)
{
if (!IsValidTown(town_id)) return false;
diff --git a/src/town.h b/src/town.h
index 91d83271c..6b80762bf 100644
--- a/src/town.h
+++ b/src/town.h
@@ -369,6 +369,7 @@ Town *ClosestTownFromTile(TileIndex tile, uint threshold);
void ChangeTownRating(Town *t, int add, int max);
HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile);
void SetTownRatingTestMode(bool mode);
+uint GetMaskOfTownActions(int *nump, CompanyID cid, const Town *t);
/**
* Calculate a hash value from a tile position
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 739e51b2d..b7c6709c8 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -2311,7 +2311,71 @@ static TownActionProc *const _town_action_proc[] = {
TownActionBribe
};
-extern uint GetMaskOfTownActions(int *nump, CompanyID cid, const Town *t);
+enum TownActions {
+ TACT_NONE = 0x00,
+
+ TACT_ADVERTISE_SMALL = 0x01,
+ TACT_ADVERTISE_MEDIUM = 0x02,
+ TACT_ADVERTISE_LARGE = 0x04,
+ TACT_ROAD_REBUILD = 0x08,
+ TACT_BUILD_STATUE = 0x10,
+ TACT_FOUND_BUILDINGS = 0x20,
+ TACT_BUY_RIGHTS = 0x40,
+ TACT_BRIBE = 0x80,
+
+ TACT_ADVERTISE = TACT_ADVERTISE_SMALL | TACT_ADVERTISE_MEDIUM | TACT_ADVERTISE_LARGE,
+ TACT_CONSTRUCTION = TACT_ROAD_REBUILD | TACT_BUILD_STATUE | TACT_FOUND_BUILDINGS,
+ TACT_FUNDS = TACT_BUY_RIGHTS | TACT_BRIBE,
+ TACT_ALL = TACT_ADVERTISE | TACT_CONSTRUCTION | TACT_FUNDS,
+};
+
+DECLARE_ENUM_AS_BIT_SET(TownActions);
+
+/** Get a list of available actions to do at a town.
+ * @param nump if not NULL add put the number of available actions in it
+ * @param cid the company that is querying the town
+ * @param t the town that is queried
+ * @return bitmasked value of enabled actions
+ */
+uint GetMaskOfTownActions(int *nump, CompanyID cid, const Town *t)
+{
+ int num = 0;
+ TownActions buttons = TACT_NONE;
+
+ /* Spectators and unwanted have no options */
+ if (cid != COMPANY_SPECTATOR && !(_settings_game.economy.bribe && t->unwanted[cid])) {
+
+ /* Things worth more than this are not shown */
+ Money avail = GetCompany(cid)->money + _price.station_value * 200;
+ Money ref = _price.build_industry >> 8;
+
+ /* Check the action bits for validity and
+ * if they are valid add them */
+ for (uint i = 0; i != lengthof(_town_action_costs); i++) {
+ const TownActions cur = (TownActions)(1 << i);
+
+ /* Is the company not able to bribe ? */
+ if (cur == TACT_BRIBE && (!_settings_game.economy.bribe || t->ratings[cid] >= RATING_BRIBE_MAXIMUM))
+ continue;
+
+ /* Is the company not able to buy exclusive rights ? */
+ if (cur == TACT_BUY_RIGHTS && !_settings_game.economy.exclusive_rights)
+ continue;
+
+ /* Is the company not able to build a statue ? */
+ if (cur == TACT_BUILD_STATUE && HasBit(t->statues, cid))
+ continue;
+
+ if (avail >= _town_action_costs[i] * ref) {
+ buttons |= cur;
+ num++;
+ }
+ }
+ }
+
+ if (nump != NULL) *nump = num;
+ return buttons;
+}
/** Do a town action.
* This performs an action such as advertising, building a statue, funding buildings,
diff --git a/src/town_gui.cpp b/src/town_gui.cpp
index 21713474f..9a97b0b9c 100644
--- a/src/town_gui.cpp
+++ b/src/town_gui.cpp
@@ -48,72 +48,6 @@ static const Widget _town_authority_widgets[] = {
extern const byte _town_action_costs[8];
-enum TownActions {
- TACT_NONE = 0x00,
-
- TACT_ADVERTISE_SMALL = 0x01,
- TACT_ADVERTISE_MEDIUM = 0x02,
- TACT_ADVERTISE_LARGE = 0x04,
- TACT_ROAD_REBUILD = 0x08,
- TACT_BUILD_STATUE = 0x10,
- TACT_FOUND_BUILDINGS = 0x20,
- TACT_BUY_RIGHTS = 0x40,
- TACT_BRIBE = 0x80,
-
- TACT_ADVERTISE = TACT_ADVERTISE_SMALL | TACT_ADVERTISE_MEDIUM | TACT_ADVERTISE_LARGE,
- TACT_CONSTRUCTION = TACT_ROAD_REBUILD | TACT_BUILD_STATUE | TACT_FOUND_BUILDINGS,
- TACT_FUNDS = TACT_BUY_RIGHTS | TACT_BRIBE,
- TACT_ALL = TACT_ADVERTISE | TACT_CONSTRUCTION | TACT_FUNDS,
-};
-
-DECLARE_ENUM_AS_BIT_SET(TownActions);
-
-/** Get a list of available actions to do at a town.
- * @param nump if not NULL add put the number of available actions in it
- * @param cid the company that is querying the town
- * @param t the town that is queried
- * @return bitmasked value of enabled actions
- */
-uint GetMaskOfTownActions(int *nump, CompanyID cid, const Town *t)
-{
- int num = 0;
- TownActions buttons = TACT_NONE;
-
- /* Spectators and unwanted have no options */
- if (cid != COMPANY_SPECTATOR && !(_settings_game.economy.bribe && t->unwanted[cid])) {
-
- /* Things worth more than this are not shown */
- Money avail = GetCompany(cid)->money + _price.station_value * 200;
- Money ref = _price.build_industry >> 8;
-
- /* Check the action bits for validity and
- * if they are valid add them */
- for (uint i = 0; i != lengthof(_town_action_costs); i++) {
- const TownActions cur = (TownActions)(1 << i);
-
- /* Is the company not able to bribe ? */
- if (cur == TACT_BRIBE && (!_settings_game.economy.bribe || t->ratings[cid] >= RATING_BRIBE_MAXIMUM))
- continue;
-
- /* Is the company not able to buy exclusive rights ? */
- if (cur == TACT_BUY_RIGHTS && !_settings_game.economy.exclusive_rights)
- continue;
-
- /* Is the company not able to build a statue ? */
- if (cur == TACT_BUILD_STATUE && HasBit(t->statues, cid))
- continue;
-
- if (avail >= _town_action_costs[i] * ref) {
- buttons |= cur;
- num++;
- }
- }
- }
-
- if (nump != NULL) *nump = num;
- return buttons;
-}
-
struct TownAuthorityWindow : Window {
private:
Town *town;