summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordarkvater <darkvater@openttd.org>2005-01-07 23:59:59 +0000
committerdarkvater <darkvater@openttd.org>2005-01-07 23:59:59 +0000
commit116789022c70f8f34c839ef85db8701472b3d634 (patch)
treec343b9a28596934c1b2104f657c6c1fe13651e5b
parentb78b576b214512a66dde9b59eea141824d162690 (diff)
downloadopenttd-116789022c70f8f34c839ef85db8701472b3d634.tar.xz
(svn r1418) -Feature: [1098254] (dis)Allow Shares. Add patch options to allow buying/selling of shares (Hackykid)
-rw-r--r--economy.c11
-rw-r--r--lang/english.txt1
-rw-r--r--player_gui.c19
-rw-r--r--settings.c1
-rw-r--r--settings_gui.c1
-rw-r--r--variables.h1
6 files changed, 26 insertions, 8 deletions
diff --git a/economy.c b/economy.c
index e15b3bc67..d7a58a749 100644
--- a/economy.c
+++ b/economy.c
@@ -1533,13 +1533,18 @@ int32 CmdBuyShareInCompany(int x, int y, uint32 flags, uint32 p1, uint32 p2)
SET_EXPENSES_TYPE(EXPENSES_OTHER);
p = DEREF_PLAYER(p1);
+ /* Check if buying shares is allowed (protection against modified clients */
+ if (!_patches.allow_shares)
+ return CMD_ERROR;
+
/* Those lines are here for network-protection (clients can be slow) */
if (GetAmountOwnedBy(p, OWNER_SPECTATOR) == 0)
return 0;
+
/* We can not buy out a real player in networking */
if (GetAmountOwnedBy(p, OWNER_SPECTATOR) == 1 && !p->is_ai)
return 0;
-
+
cost = CalculateCompanyValue(p) >> 2;
if (flags & DC_EXEC) {
b = p->share_owners;
@@ -1567,6 +1572,10 @@ int32 CmdSellShareInCompany(int x, int y, uint32 flags, uint32 p1, uint32 p2)
SET_EXPENSES_TYPE(EXPENSES_OTHER);
p = DEREF_PLAYER(p1);
+ /* Check if selling shares is allowed (protection against modified clients */
+ if (!_patches.allow_shares)
+ return CMD_ERROR;
+
/* Those lines are here for network-protection (clients can be slow) */
if (GetAmountOwnedBy(p, _current_player) == 0)
return 0;
diff --git a/lang/english.txt b/lang/english.txt
index 812b046a7..968ff678a 100644
--- a/lang/english.txt
+++ b/lang/english.txt
@@ -1046,6 +1046,7 @@ STR_CONFIG_PATCHES_SERVINT_SHIPS_DISABLED :{LTBLUE}Default service interval fo
STR_CONFIG_PATCHES_COLORED_NEWS_DATE :{LTBLUE}Coloured news appears in: {ORANGE}{STRING}
STR_CONFIG_PATCHES_STARTING_DATE :{LTBLUE}Starting date: {ORANGE}{STRING}
STR_CONFIG_PATCHES_SMOOTH_ECONOMY :{LTBLUE}Enable smooth economy (more, smaller changes)
+STR_CONFIG_PATCHES_ALLOW_SHARES :{LTBLUE}Allow buying shares from other companies
STR_CONFIG_PATCHES_DRAG_SIGNALS_DENSITY :{LTBLUE}When dragging, place signals every: {ORANGE}{STRING} tile(s)
STR_CONFIG_PATCHES_TOOLBAR_POS :{LTBLUE}Position of main toolbar: {ORANGE}{STRING}
STR_CONFIG_PATCHES_TOOLBAR_POS_LEFT :Left
diff --git a/player_gui.c b/player_gui.c
index 74cb7c817..3cd0380ef 100644
--- a/player_gui.c
+++ b/player_gui.c
@@ -506,14 +506,19 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
if (!IsWindowOfPrototype(w, _other_player_company_widgets)) {
AssignWidgetToWindow(w, (p->location_of_house != 0) ? _my_player_company_bh_widgets : _my_player_company_widgets);
- if (!_networking) w->hidden_state |= (1 << 11); // hide company-password widget
+ if (!_networking) SETBIT(w->hidden_state, 11); // hide company-password widget
} else {
- if (GetAmountOwnedBy(p, OWNER_SPECTATOR) == 0) dis |= 1 << 9;
- // Also disable the buy button if 25% is not-owned by someone
- // and the player is not an AI
- if (GetAmountOwnedBy(p, OWNER_SPECTATOR) == 1 && !p->is_ai) dis |= 1 << 9;
- if (GetAmountOwnedBy(p, _local_player) == 0) dis |= 1 << 10;
- if (_local_player == OWNER_SPECTATOR) dis |= (1 << 9) | (1 << 10);
+ if (_patches.allow_shares) { /* shares are allowed */
+ if (GetAmountOwnedBy(p, OWNER_SPECTATOR) == 0) SETBIT(dis, 9);
+
+ /* We cannot buy out real players in a network game */
+ if (GetAmountOwnedBy(p, OWNER_SPECTATOR) == 1 && !p->is_ai) SETBIT(dis, 9);
+
+ if (GetAmountOwnedBy(p, _local_player) == 0) SETBIT(dis, 10);
+
+ if (_local_player == OWNER_SPECTATOR) dis |= (1 << 9) | (1 << 10);
+ } else /* shares are not allowed, disable buy/sell buttons */
+ dis |= (1 << 9) | (1 << 10);
}
SetDParam(0, p->name_1);
diff --git a/settings.c b/settings.c
index 3ff3fecb1..552fc4ea5 100644
--- a/settings.c
+++ b/settings.c
@@ -898,6 +898,7 @@ const SettingDesc patch_settings[] = {
{"serviceathelipad", SDT_BOOL, (void*)true, &_patches.serviceathelipad, NULL},
{"smooth_economy", SDT_BOOL, (void*)true, &_patches.smooth_economy, NULL},
+ {"allow_shares", SDT_BOOL, (void*)true, &_patches.allow_shares, NULL},
{"dist_local_authority",SDT_UINT8, (void*)20, &_patches.dist_local_authority, NULL},
{"wait_oneway_signal", SDT_UINT8, (void*)15, &_patches.wait_oneway_signal, NULL},
diff --git a/settings_gui.c b/settings_gui.c
index 1ec1d6075..4d862f425 100644
--- a/settings_gui.c
+++ b/settings_gui.c
@@ -685,6 +685,7 @@ static const PatchEntry _patches_economy[] = {
{PE_INT32, PF_NOCOMMA, STR_CONFIG_PATCHES_STARTING_DATE, "starting_date", &_patches.starting_date, 1920,2100, 1, NULL},
{PE_BOOL, 0, STR_CONFIG_PATCHES_SMOOTH_ECONOMY, "smooth_economy", &_patches.smooth_economy, 0, 0, 0, NULL},
+ {PE_BOOL, 0, STR_CONFIG_PATCHES_ALLOW_SHARES, "allow_shares", &_patches.allow_shares, 0, 0, 0, NULL},
};
static const PatchEntry _patches_ai[] = {
diff --git a/variables.h b/variables.h
index 2532a6b67..c1c7c163e 100644
--- a/variables.h
+++ b/variables.h
@@ -172,6 +172,7 @@ typedef struct Patches {
bool auto_euro; // automatically switch to euro in 2002
bool serviceathelipad; // service helicopters at helipads automatically (no need to send to depot)
bool smooth_economy; // smooth economy
+ bool allow_shares; // allow the buying/selling of shares
byte dist_local_authority; // distance for town local authority, default 20
byte wait_oneway_signal; //waitingtime in days before a oneway signal