src/economy.cpp
changeset 7486 d130c10f4dab
parent 7453 67ba4a6fc014
child 7487 9ef3bd32c2eb
equal deleted inserted replaced
7485:68e3df6c477e 7486:d130c10f4dab
   110 	memset(_score_part[owner], 0, sizeof(_score_part[owner]));
   110 	memset(_score_part[owner], 0, sizeof(_score_part[owner]));
   111 
   111 
   112 /* Count vehicles */
   112 /* Count vehicles */
   113 	{
   113 	{
   114 		Vehicle *v;
   114 		Vehicle *v;
   115 		int32 min_profit = 0;
   115 		Money min_profit = 0;
   116 		bool min_profit_first = true;
   116 		bool min_profit_first = true;
   117 		uint num = 0;
   117 		uint num = 0;
   118 
   118 
   119 		FOR_ALL_VEHICLES(v) {
   119 		FOR_ALL_VEHICLES(v) {
   120 			if (v->owner != owner) continue;
   120 			if (v->owner != owner) continue;
   133 		}
   133 		}
   134 
   134 
   135 		_score_part[owner][SCORE_VEHICLES] = num;
   135 		_score_part[owner][SCORE_VEHICLES] = num;
   136 		/* Don't allow negative min_profit to show */
   136 		/* Don't allow negative min_profit to show */
   137 		if (min_profit > 0)
   137 		if (min_profit > 0)
   138 			_score_part[owner][SCORE_MIN_PROFIT] = min_profit;
   138 			_score_part[owner][SCORE_MIN_PROFIT] = ClampToI32(min_profit);
   139 	}
   139 	}
   140 
   140 
   141 /* Count stations */
   141 /* Count stations */
   142 	{
   142 	{
   143 		uint num = 0;
   143 		uint num = 0;
   161 				min_income = min(min_income, pee->income + pee->expenses);
   161 				min_income = min(min_income, pee->income + pee->expenses);
   162 				max_income = max(max_income, pee->income + pee->expenses);
   162 				max_income = max(max_income, pee->income + pee->expenses);
   163 			} while (++pee,--numec);
   163 			} while (++pee,--numec);
   164 
   164 
   165 			if (min_income > 0)
   165 			if (min_income > 0)
   166 				_score_part[owner][SCORE_MIN_INCOME] = min_income;
   166 				_score_part[owner][SCORE_MIN_INCOME] = ClampToI32(min_income);
   167 
   167 
   168 			_score_part[owner][SCORE_MAX_INCOME] = max_income;
   168 			_score_part[owner][SCORE_MAX_INCOME] = ClampToI32(max_income);
   169 		}
   169 		}
   170 	}
   170 	}
   171 
   171 
   172 /* Generate score depending on amount of transported cargo */
   172 /* Generate score depending on amount of transported cargo */
   173 	{
   173 	{
   194 		if (update) p->cargo_types = 0;
   194 		if (update) p->cargo_types = 0;
   195 	}
   195 	}
   196 
   196 
   197 /* Generate score for player money */
   197 /* Generate score for player money */
   198 	{
   198 	{
   199 		int32 money = p->player_money;
   199 		if (p->player_money > 0) {
   200 		if (money > 0) {
   200 			_score_part[owner][SCORE_MONEY] = ClampToI32(p->player_money);
   201 			_score_part[owner][SCORE_MONEY] = money;
       
   202 		}
   201 		}
   203 	}
   202 	}
   204 
   203 
   205 /* Generate score for loan */
   204 /* Generate score for loan */
   206 	{
   205 	{
   207 		_score_part[owner][SCORE_LOAN] = _score_info[SCORE_LOAN].needed - p->current_loan;
   206 		_score_part[owner][SCORE_LOAN] = ClampToI32(_score_info[SCORE_LOAN].needed - p->current_loan);
   208 	}
   207 	}
   209 
   208 
   210 	/* Now we calculate the score for each item.. */
   209 	/* Now we calculate the score for each item.. */
   211 	{
   210 	{
   212 		int total_score = 0;
   211 		int total_score = 0;
   436 }
   435 }
   437 
   436 
   438 static void PlayersCheckBankrupt(Player *p)
   437 static void PlayersCheckBankrupt(Player *p)
   439 {
   438 {
   440 	PlayerID owner;
   439 	PlayerID owner;
   441 	int64 val;
       
   442 
   440 
   443 	/*  If the player has money again, it does not go bankrupt */
   441 	/*  If the player has money again, it does not go bankrupt */
   444 	if (p->player_money >= 0) {
   442 	if (p->player_money >= 0) {
   445 		p->quarters_of_bankrupcy = 0;
   443 		p->quarters_of_bankrupcy = 0;
   446 		return;
   444 		return;
   464 				break;
   462 				break;
   465 			}
   463 			}
   466 
   464 
   467 			/* Check if the company has any value.. if not, declare it bankrupt
   465 			/* Check if the company has any value.. if not, declare it bankrupt
   468 			 *  right now */
   466 			 *  right now */
   469 			val = CalculateCompanyValue(p);
   467 			Money val = CalculateCompanyValue(p);
   470 			if (val > 0) {
   468 			if (val > 0) {
   471 				p->bankrupt_value = val;
   469 				p->bankrupt_value = val;
   472 				p->bankrupt_asked = 1 << owner; // Don't ask the owner
   470 				p->bankrupt_asked = 1 << owner; // Don't ask the owner
   473 				p->bankrupt_timeout = 0;
   471 				p->bankrupt_timeout = 0;
   474 				break;
   472 				break;
  1317 		}
  1315 		}
  1318 	}
  1316 	}
  1319 	return false;
  1317 	return false;
  1320 }
  1318 }
  1321 
  1319 
  1322 static int32 DeliverGoods(int num_pieces, CargoID cargo_type, StationID source, StationID dest, TileIndex source_tile, byte days_in_transit)
  1320 static Money DeliverGoods(int num_pieces, CargoID cargo_type, StationID source, StationID dest, TileIndex source_tile, byte days_in_transit)
  1323 {
  1321 {
  1324 	bool subsidised;
  1322 	bool subsidised;
  1325 	Station *s_from, *s_to;
  1323 	Station *s_from, *s_to;
  1326 	int32 profit;
  1324 	Money profit;
  1327 
  1325 
  1328 	assert(num_pieces > 0);
  1326 	assert(num_pieces > 0);
  1329 
  1327 
  1330 	/* Update player statistics */
  1328 	/* Update player statistics */
  1331 	{
  1329 	{
  1509 	bool completely_empty  = true;
  1507 	bool completely_empty  = true;
  1510 	bool anything_unloaded = false;
  1508 	bool anything_unloaded = false;
  1511 	bool anything_loaded   = false;
  1509 	bool anything_loaded   = false;
  1512 	uint32 cargo_not_full  = 0;
  1510 	uint32 cargo_not_full  = 0;
  1513 	uint32 cargo_full      = 0;
  1511 	uint32 cargo_full      = 0;
  1514 	int total_cargo_feeder_share = 0; // the feeder cash amount for the goods being loaded/unloaded in this load step
  1512 	Money total_cargo_feeder_share = 0; // the feeder cash amount for the goods being loaded/unloaded in this load step
  1515 
  1513 
  1516 	v->cur_speed = 0;
  1514 	v->cur_speed = 0;
  1517 
  1515 
  1518 	StationID last_visited = v->last_station_visited;
  1516 	StationID last_visited = v->last_station_visited;
  1519 	Station *st = GetStation(last_visited);
  1517 	Station *st = GetStation(last_visited);
  1601 		}
  1599 		}
  1602 
  1600 
  1603 		/* if last speed is 0, we treat that as if no vehicle has ever visited the station. */
  1601 		/* if last speed is 0, we treat that as if no vehicle has ever visited the station. */
  1604 		ge->days_since_pickup = 0;
  1602 		ge->days_since_pickup = 0;
  1605 		ge->last_speed = min(t, 255);
  1603 		ge->last_speed = min(t, 255);
  1606 		ge->last_age = _cur_year - v->build_year;
  1604 		ge->last_age = _cur_year - u->build_year;
  1607 
  1605 
  1608 		/* If there's goods waiting at the station, and the vehicle
  1606 		/* If there's goods waiting at the station, and the vehicle
  1609 		 * has capacity for it, load it on the vehicle. */
  1607 		 * has capacity for it, load it on the vehicle. */
  1610 		if (count != 0 &&
  1608 		if (count != 0 &&
  1611 				(cap = v->cargo_cap - v->cargo_count) != 0) {
  1609 				(cap = v->cargo_cap - v->cargo_count) != 0) {
  1641 			 * Otherwise, with gradual loading, 100% of credits would be taken immediately,
  1639 			 * Otherwise, with gradual loading, 100% of credits would be taken immediately,
  1642 			 * even if the cargo volume represents a tiny percent of the whole.
  1640 			 * even if the cargo volume represents a tiny percent of the whole.
  1643 			 * ge->unload_pending holds the amount that has been credited, but has not yet been unloaded.
  1641 			 * ge->unload_pending holds the amount that has been credited, but has not yet been unloaded.
  1644 			 */
  1642 			 */
  1645 			int cargoshare = cap * 10000 / (ge->waiting_acceptance + ge->unload_pending);
  1643 			int cargoshare = cap * 10000 / (ge->waiting_acceptance + ge->unload_pending);
  1646 			int feeder_profit_share = ge->feeder_profit * cargoshare / 10000;
  1644 			Money feeder_profit_share = ge->feeder_profit * cargoshare / 10000;
  1647 			v->cargo_count += cap;
  1645 			v->cargo_count += cap;
  1648 			ge->waiting_acceptance -= cap;
  1646 			ge->waiting_acceptance -= cap;
  1649 
  1647 
  1650 			total_cargo_feeder_share += feeder_profit_share;    // store cost for later payment when cargo unloaded
  1648 			total_cargo_feeder_share += feeder_profit_share;    // store cost for later payment when cargo unloaded
  1651 			v->cargo_loaded_at_xy = st->xy;                     // retains location of where the cargo was picked up for intermediate payments
  1649 			v->cargo_loaded_at_xy = st->xy;                     // retains location of where the cargo was picked up for intermediate payments