File diff r11916:e3a8d08bf479 → r11917:612c11f7ab47
src/economy.cpp
Show inline comments
 
@@ -291,13 +291,13 @@ void ChangeOwnershipOfCompanyItems(Owner
 
					SubtractMoneyFromCompany(res);
 
				}
 
			}
 
		}
 

	
 
		/* Sell all the shares that people have on this company */
 
		c = GetCompany(old_owner);
 
		c = Company::Get(old_owner);
 
		for (i = 0; i < 4; i++) {
 
			_current_company = c->share_owners[i];
 
			if (_current_company != INVALID_OWNER) {
 
				/* Sell the shares */
 
				CommandCost res = DoCommand(0, old_owner, 0, DC_EXEC, CMD_SELL_SHARE_IN_COMPANY);
 
				/* Because we are in a DoCommand, we can't just execute an other one and
 
@@ -310,21 +310,21 @@ void ChangeOwnershipOfCompanyItems(Owner
 
	_current_company = old_owner;
 

	
 
	/* Temporarily increase the company's money, to be sure that
 
	 * removing his/her property doesn't fail because of lack of money.
 
	 * Not too drastically though, because it could overflow */
 
	if (new_owner == INVALID_OWNER) {
 
		GetCompany(old_owner)->money = UINT64_MAX >> 2; // jackpot ;p
 
		Company::Get(old_owner)->money = UINT64_MAX >> 2; // jackpot ;p
 
	}
 

	
 
	if (new_owner == INVALID_OWNER) {
 
		Subsidy *s;
 

	
 
		for (s = _subsidies; s != endof(_subsidies); s++) {
 
			if (s->cargo_type != CT_INVALID && s->age >= 12) {
 
				if (GetStation(s->to)->owner == old_owner) s->cargo_type = CT_INVALID;
 
				if (Station::Get(s->to)->owner == old_owner) s->cargo_type = CT_INVALID;
 
			}
 
		}
 
	}
 

	
 
	/* Take care of rating in towns */
 
	FOR_ALL_TOWNS(t) {
 
@@ -357,13 +357,13 @@ void ChangeOwnershipOfCompanyItems(Owner
 
			if (v->owner == old_owner && IsCompanyBuildableVehicleType(v->type)) {
 
				if (new_owner == INVALID_OWNER) {
 
					if (v->Previous() == NULL) delete v;
 
				} else {
 
					v->owner = new_owner;
 
					v->colourmap = PAL_NONE;
 
					if (IsEngineCountable(v)) GetCompany(new_owner)->num_engines[v->engine_type]++;
 
					if (IsEngineCountable(v)) Company::Get(new_owner)->num_engines[v->engine_type]++;
 
					if (v->IsPrimaryVehicle()) v->unitnumber = unitidgen[v->type].NextID();
 
				}
 
			}
 
		}
 
	}
 

	
 
@@ -415,13 +415,13 @@ void ChangeOwnershipOfCompanyItems(Owner
 
			wp->owner = new_owner == INVALID_OWNER ? OWNER_NONE : new_owner;
 
		}
 
	}
 

	
 
	/* In all cases clear replace engine rules.
 
	 * Even if it was copied, it could interfere with new owner's rules */
 
	RemoveAllEngineReplacementForCompany(GetCompany(old_owner));
 
	RemoveAllEngineReplacementForCompany(Company::Get(old_owner));
 

	
 
	if (new_owner == INVALID_OWNER) {
 
		RemoveAllGroupsForCompany(old_owner);
 
	} else {
 
		Group *g;
 
		FOR_ALL_GROUPS(g) {
 
@@ -869,38 +869,38 @@ Pair SetupSubsidyDecodeParam(const Subsi
 
	SetDParam(0, mode ? cs->name : cs->name_single);
 

	
 
	if (s->age < 12) {
 
		if (cs->town_effect != TE_PASSENGERS && cs->town_effect != TE_MAIL) {
 
			SetDParam(1, STR_INDUSTRY);
 
			SetDParam(2, s->from);
 
			tile = GetIndustry(s->from)->xy;
 
			tile = Industry::Get(s->from)->xy;
 

	
 
			if (cs->town_effect != TE_GOODS && cs->town_effect != TE_FOOD) {
 
				SetDParam(4, STR_INDUSTRY);
 
				SetDParam(5, s->to);
 
				tile2 = GetIndustry(s->to)->xy;
 
				tile2 = Industry::Get(s->to)->xy;
 
			} else {
 
				SetDParam(4, STR_TOWN);
 
				SetDParam(5, s->to);
 
				tile2 = GetTown(s->to)->xy;
 
				tile2 = Town::Get(s->to)->xy;
 
			}
 
		} else {
 
			SetDParam(1, STR_TOWN);
 
			SetDParam(2, s->from);
 
			tile = GetTown(s->from)->xy;
 
			tile = Town::Get(s->from)->xy;
 

	
 
			SetDParam(4, STR_TOWN);
 
			SetDParam(5, s->to);
 
			tile2 = GetTown(s->to)->xy;
 
			tile2 = Town::Get(s->to)->xy;
 
		}
 
	} else {
 
		SetDParam(1, s->from);
 
		tile = GetStation(s->from)->xy;
 
		tile = Station::Get(s->from)->xy;
 

	
 
		SetDParam(2, s->to);
 
		tile2 = GetStation(s->to)->xy;
 
		tile2 = Station::Get(s->to)->xy;
 
	}
 

	
 
	tp.a = tile;
 
	tp.b = tile2;
 

	
 
	return tp;
 
@@ -1066,13 +1066,13 @@ static void SubsidyMonthlyHandler()
 
			pair = SetupSubsidyDecodeParam(s, 1);
 
			AddNewsItem(STR_NEWS_OFFER_OF_SUBSIDY_EXPIRED, NS_SUBSIDIES, pair.a, pair.b);
 
			s->cargo_type = CT_INVALID;
 
			modified = true;
 
			AI::BroadcastNewEvent(new AIEventSubsidyOfferExpired(s - _subsidies));
 
		} else if (s->age == 2 * 12 - 1) {
 
			st = GetStation(s->to);
 
			st = Station::Get(s->to);
 
			if (st->owner == _local_company) {
 
				pair = SetupSubsidyDecodeParam(s, 1);
 
				AddNewsItem(STR_NEWS_SUBSIDY_WITHDRAWN_SERVICE, NS_SUBSIDIES, pair.a, pair.b);
 
			}
 
			s->cargo_type = CT_INVALID;
 
			modified = true;
 
@@ -1292,29 +1292,29 @@ static bool CheckSubsidised(Station *fro
 
	/* check if there's a new subsidy that applies.. */
 
	for (s = _subsidies; s != endof(_subsidies); s++) {
 
		if (s->cargo_type == cargo_type && s->age < 12) {
 
			/* Check distance from source */
 
			const CargoSpec *cs = GetCargo(cargo_type);
 
			if (cs->town_effect == TE_PASSENGERS || cs->town_effect == TE_MAIL) {
 
				xy = GetTown(s->from)->xy;
 
				xy = Town::Get(s->from)->xy;
 
			} else {
 
				xy = GetIndustry(s->from)->xy;
 
				xy = Industry::Get(s->from)->xy;
 
			}
 
			if (DistanceMax(xy, from->xy) > 9) continue;
 

	
 
			/* Check distance from dest */
 
			switch (cs->town_effect) {
 
				case TE_PASSENGERS:
 
				case TE_MAIL:
 
				case TE_GOODS:
 
				case TE_FOOD:
 
					xy = GetTown(s->to)->xy;
 
					xy = Town::Get(s->to)->xy;
 
					break;
 

	
 
				default:
 
					xy = GetIndustry(s->to)->xy;
 
					xy = Industry::Get(s->to)->xy;
 
					break;
 
			}
 
			if (DistanceMax(xy, to->xy) > 9) continue;
 

	
 
			/* Found a subsidy, change the values to indicate that it's in use */
 
			s->age = 12;
 
@@ -1357,20 +1357,20 @@ static Money DeliverGoods(int num_pieces
 
	Money profit;
 

	
 
	assert(num_pieces > 0);
 

	
 
	/* Update company statistics */
 
	{
 
		Company *c = GetCompany(_current_company);
 
		Company *c = Company::Get(_current_company);
 
		c->cur_economy.delivered_cargo += num_pieces;
 
		SetBit(c->cargo_types, cargo_type);
 
	}
 

	
 
	/* Get station pointers. */
 
	s_from = GetStation(source);
 
	s_to = GetStation(dest);
 
	s_from = Station::Get(source);
 
	s_to = Station::Get(dest);
 

	
 
	/* Check if a subsidy applies. */
 
	subsidised = CheckSubsidised(s_from, s_to, cargo_type);
 

	
 
	/* Increase town's counter for some special goods types */
 
	const CargoSpec *cs = GetCargo(cargo_type);
 
@@ -1441,13 +1441,13 @@ void VehiclePayment(Vehicle *front_v)
 

	
 
	Money vehicle_profit = 0; // Money paid to the train
 
	Money route_profit   = 0; // The grand total amount for the route. A-D of transfer chain A-B-C-D
 
	Money virtual_profit = 0; // The virtual profit for entire vehicle chain
 

	
 
	StationID last_visited = front_v->last_station_visited;
 
	Station *st = GetStation(last_visited);
 
	Station *st = Station::Get(last_visited);
 

	
 
	/* The owner of the train wants to be paid */
 
	CompanyID old_company = _current_company;
 
	_current_company = front_v->owner;
 

	
 
	/* At this moment loading cannot be finished */
 
@@ -1493,13 +1493,13 @@ void VehiclePayment(Vehicle *front_v)
 
				SetBit(v->vehicle_flags, VF_CARGO_UNLOADING);
 
			} else if (front_v->current_order.GetUnloadType() & (OUFB_UNLOAD | OUFB_TRANSFER)) {
 
				if (!cp->paid_for && (front_v->current_order.GetUnloadType() & OUFB_TRANSFER) != 0) {
 
					Money profit = GetTransportedGoodsIncome(
 
						cp->count,
 
						/* pay transfer vehicle for only the part of transfer it has done: ie. cargo_loaded_at_xy to here */
 
						DistanceManhattan(cp->loaded_at_xy, GetStation(last_visited)->xy),
 
						DistanceManhattan(cp->loaded_at_xy, Station::Get(last_visited)->xy),
 
						cp->days_in_transit,
 
						v->cargo_type);
 

	
 
					front_v->profit_this_year += profit << 8;
 
					virtual_profit   += profit; // accumulate transfer profits for whole vehicle
 
					cp->feeder_share += profit; // account for the (virtual) profit already made for the cargo packet
 
@@ -1559,13 +1559,13 @@ static void LoadUnloadVehicle(Vehicle *v
 
			}
 
		}
 
		return;
 
	}
 

	
 
	StationID last_visited = v->last_station_visited;
 
	Station *st = GetStation(last_visited);
 
	Station *st = Station::Get(last_visited);
 

	
 
	if (v->type == VEH_TRAIN && (!IsTileType(v->tile, MP_STATION) || GetStationIndex(v->tile) != st->index)) {
 
		/* The train reversed in the station. Take the "easy" way
 
		 * out and let the train just leave as it always did. */
 
		SetBit(v->vehicle_flags, VF_LOADING_FINISHED);
 
		return;
 
@@ -1834,13 +1834,13 @@ static void DoAcquireCompany(Company *c)
 
	Company *owner;
 
	int i;
 
	Money value;
 
	CompanyID ci = c->index;
 

	
 
	CompanyNewsInformation *cni = MallocT<CompanyNewsInformation>(1);
 
	cni->FillData(c, GetCompany(_current_company));
 
	cni->FillData(c, Company::Get(_current_company));
 

	
 
	SetDParam(0, STR_NEWS_COMPANY_MERGER_TITLE);
 
	SetDParam(1, c->bankrupt_value == 0 ? STR_NEWS_MERGER_TAKEOVER_TITLE : STR_NEWS_COMPANY_MERGER_DESCRIPTION);
 
	SetDParamStr(2, cni->company_name);
 
	SetDParamStr(3, cni->other_company_name);
 
	SetDParam(4, c->bankrupt_value);
 
@@ -1849,13 +1849,13 @@ static void DoAcquireCompany(Company *c)
 

	
 
	/* original code does this a little bit differently */
 
	ChangeNetworkOwner(ci, _current_company);
 
	ChangeOwnershipOfCompanyItems(ci, _current_company);
 

	
 
	if (c->bankrupt_value == 0) {
 
		owner = GetCompany(_current_company);
 
		owner = Company::Get(_current_company);
 
		owner->current_loan += c->current_loan;
 
	}
 

	
 
	value = CalculateCompanyValue(c) >> 2;
 
	CompanyID old_company = _current_company;
 
	for (i = 0; i != 4; i++) {
 
@@ -1890,13 +1890,13 @@ CommandCost CmdBuyShareInCompany(TileInd
 
	CommandCost cost(EXPENSES_OTHER);
 

	
 
	/* Check if buying shares is allowed (protection against modified clients)
 
	 * Cannot buy own shares */
 
	if (!IsValidCompanyID((CompanyID)p1) || !_settings_game.economy.allow_shares || _current_company == (CompanyID)p1) return CMD_ERROR;
 

	
 
	Company *c = GetCompany((CompanyID)p1);
 
	Company *c = Company::Get((CompanyID)p1);
 

	
 
	/* Protect new companies from hostile takeovers */
 
	if (_cur_year - c->inaugurated_year < 6) return_cmd_error(STR_PROTECTED);
 

	
 
	/* Those lines are here for network-protection (clients can be slow) */
 
	if (GetAmountOwnedBy(c, COMPANY_SPECTATOR) == 0) return cost;
 
@@ -1933,13 +1933,13 @@ CommandCost CmdBuyShareInCompany(TileInd
 
CommandCost CmdSellShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	/* Check if selling shares is allowed (protection against modified clients)
 
	 * Cannot sell own shares */
 
	if (!IsValidCompanyID((CompanyID)p1) || !_settings_game.economy.allow_shares || _current_company == (CompanyID)p1) return CMD_ERROR;
 

	
 
	Company *c = GetCompany((CompanyID)p1);
 
	Company *c = Company::Get((CompanyID)p1);
 

	
 
	/* Those lines are here for network-protection (clients can be slow) */
 
	if (GetAmountOwnedBy(c, _current_company) == 0) return CommandCost();
 

	
 
	/* adjust it a little to make it less profitable to sell and buy */
 
	Money cost = CalculateCompanyValue(c) >> 2;
 
@@ -1970,13 +1970,13 @@ CommandCost CmdBuyCompany(TileIndex tile
 
	/* Disable takeovers in multiplayer games */
 
	if (!IsValidCompanyID(cid) || _networking) return CMD_ERROR;
 

	
 
	/* Do not allow companies to take over themselves */
 
	if (cid == _current_company) return CMD_ERROR;
 

	
 
	Company *c = GetCompany(cid);
 
	Company *c = Company::Get(cid);
 

	
 
	if (!c->is_ai) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		DoAcquireCompany(c);
 
	}