src/economy.cpp
changeset 6950 14ecb0acdfb4
parent 6943 1914f26aee04
child 6952 b19643469024
equal deleted inserted replaced
6949:5de26c8fe2ef 6950:14ecb0acdfb4
   708 		if (!p->is_active) continue;
   708 		if (!p->is_active) continue;
   709 
   709 
   710 		_current_player = p->index;
   710 		_current_player = p->index;
   711 		SET_EXPENSES_TYPE(EXPENSES_LOAN_INT);
   711 		SET_EXPENSES_TYPE(EXPENSES_LOAN_INT);
   712 
   712 
   713 		SubtractMoneyFromPlayer(BIGMULUS(p->current_loan, interest, 16));
   713 		SubtractMoneyFromPlayer(CommandCost(BIGMULUS(p->current_loan, interest, 16)));
   714 
   714 
   715 		SET_EXPENSES_TYPE(EXPENSES_OTHER);
   715 		SET_EXPENSES_TYPE(EXPENSES_OTHER);
   716 		SubtractMoneyFromPlayer(_price.station_value >> 2);
   716 		SubtractMoneyFromPlayer(_price.station_value >> 2);
   717 	}
   717 	}
   718 }
   718 }
  1821 
  1821 
  1822 	/* Protect new companies from hostile takeovers */
  1822 	/* Protect new companies from hostile takeovers */
  1823 	if (_cur_year - p->inaugurated_year < 6) return_cmd_error(STR_7080_PROTECTED);
  1823 	if (_cur_year - p->inaugurated_year < 6) return_cmd_error(STR_7080_PROTECTED);
  1824 
  1824 
  1825 	/* Those lines are here for network-protection (clients can be slow) */
  1825 	/* Those lines are here for network-protection (clients can be slow) */
  1826 	if (GetAmountOwnedBy(p, PLAYER_SPECTATOR) == 0) return 0;
  1826 	if (GetAmountOwnedBy(p, PLAYER_SPECTATOR) == 0) return cost;
  1827 
  1827 
  1828 	/* We can not buy out a real player (temporarily). TODO: well, enable it obviously */
  1828 	/* We can not buy out a real player (temporarily). TODO: well, enable it obviously */
  1829 	if (GetAmountOwnedBy(p, PLAYER_SPECTATOR) == 1 && !p->is_ai) return 0;
  1829 	if (GetAmountOwnedBy(p, PLAYER_SPECTATOR) == 1 && !p->is_ai) return cost;
  1830 
  1830 
  1831 	cost = CalculateCompanyValue(p) >> 2;
  1831 	cost.AddCost(CalculateCompanyValue(p) >> 2);
  1832 	if (flags & DC_EXEC) {
  1832 	if (flags & DC_EXEC) {
  1833 		PlayerByte* b = p->share_owners;
  1833 		PlayerByte* b = p->share_owners;
  1834 		int i;
  1834 		int i;
  1835 
  1835 
  1836 		while (*b != PLAYER_SPECTATOR) b++; /* share owners is guaranteed to contain at least one PLAYER_SPECTATOR */
  1836 		while (*b != PLAYER_SPECTATOR) b++; /* share owners is guaranteed to contain at least one PLAYER_SPECTATOR */
  1864 
  1864 
  1865 	SET_EXPENSES_TYPE(EXPENSES_OTHER);
  1865 	SET_EXPENSES_TYPE(EXPENSES_OTHER);
  1866 	p = GetPlayer((PlayerID)p1);
  1866 	p = GetPlayer((PlayerID)p1);
  1867 
  1867 
  1868 	/* Those lines are here for network-protection (clients can be slow) */
  1868 	/* Those lines are here for network-protection (clients can be slow) */
  1869 	if (GetAmountOwnedBy(p, _current_player) == 0) return 0;
  1869 	if (GetAmountOwnedBy(p, _current_player) == 0) return CommandCost();
  1870 
  1870 
  1871 	/* adjust it a little to make it less profitable to sell and buy */
  1871 	/* adjust it a little to make it less profitable to sell and buy */
  1872 	cost = CalculateCompanyValue(p) >> 2;
  1872 	cost = CalculateCompanyValue(p) >> 2;
  1873 	cost = -(cost - (cost >> 7));
  1873 	cost = -(cost - (cost >> 7));
  1874 
  1874 
  1876 		PlayerByte* b = p->share_owners;
  1876 		PlayerByte* b = p->share_owners;
  1877 		while (*b != _current_player) b++; // share owners is guaranteed to contain player
  1877 		while (*b != _current_player) b++; // share owners is guaranteed to contain player
  1878 		*b = PLAYER_SPECTATOR;
  1878 		*b = PLAYER_SPECTATOR;
  1879 		InvalidateWindow(WC_COMPANY, p1);
  1879 		InvalidateWindow(WC_COMPANY, p1);
  1880 	}
  1880 	}
  1881 	return cost;
  1881 	return CommandCost((int32)cost);
  1882 }
  1882 }
  1883 
  1883 
  1884 /** Buy up another company.
  1884 /** Buy up another company.
  1885  * When a competing company is gone bankrupt you get the chance to purchase
  1885  * When a competing company is gone bankrupt you get the chance to purchase
  1886  * that company.
  1886  * that company.
  1907 	if (!p->is_ai) return CMD_ERROR;
  1907 	if (!p->is_ai) return CMD_ERROR;
  1908 
  1908 
  1909 	if (flags & DC_EXEC) {
  1909 	if (flags & DC_EXEC) {
  1910 		DoAcquireCompany(p);
  1910 		DoAcquireCompany(p);
  1911 	}
  1911 	}
  1912 	return p->bankrupt_value;
  1912 	return CommandCost(p->bankrupt_value);
  1913 }
  1913 }
  1914 
  1914 
  1915 /** Prices */
  1915 /** Prices */
  1916 static void SaveLoad_PRIC()
  1916 static void SaveLoad_PRIC()
  1917 {
  1917 {