(svn r1418) -Feature: [1098254] (dis)Allow Shares. Add patch options to allow buying/selling of shares (Hackykid)
authordarkvater
Fri, 07 Jan 2005 23:59:59 +0000
changeset 930 524b02923ede
parent 929 1a071a06af3f
child 931 524393b0c842
(svn r1418) -Feature: [1098254] (dis)Allow Shares. Add patch options to allow buying/selling of shares (Hackykid)
economy.c
lang/english.txt
player_gui.c
settings.c
settings_gui.c
variables.h
--- a/economy.c	Fri Jan 07 18:13:56 2005 +0000
+++ b/economy.c	Fri Jan 07 23:59:59 2005 +0000
@@ -1533,13 +1533,18 @@
 	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 @@
 	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;
--- a/lang/english.txt	Fri Jan 07 18:13:56 2005 +0000
+++ b/lang/english.txt	Fri Jan 07 23:59:59 2005 +0000
@@ -1046,6 +1046,7 @@
 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
--- a/player_gui.c	Fri Jan 07 18:13:56 2005 +0000
+++ b/player_gui.c	Fri Jan 07 23:59:59 2005 +0000
@@ -506,14 +506,19 @@
 		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);
--- a/settings.c	Fri Jan 07 18:13:56 2005 +0000
+++ b/settings.c	Fri Jan 07 23:59:59 2005 +0000
@@ -898,6 +898,7 @@
 
 	{"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},
--- a/settings_gui.c	Fri Jan 07 18:13:56 2005 +0000
+++ b/settings_gui.c	Fri Jan 07 23:59:59 2005 +0000
@@ -685,6 +685,7 @@
 	{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[] = {
--- a/variables.h	Fri Jan 07 18:13:56 2005 +0000
+++ b/variables.h	Fri Jan 07 23:59:59 2005 +0000
@@ -172,6 +172,7 @@
 	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