economy.c
changeset 2639 8a7342eb3a78
parent 2630 35249d2ded3e
child 2642 cb99ff2e49a7
equal deleted inserted replaced
2638:0c9b00251fce 2639:8a7342eb3a78
    70 	MarkTileDirtyByTile(tile + TileDiffXY(0, 1));
    70 	MarkTileDirtyByTile(tile + TileDiffXY(0, 1));
    71 	MarkTileDirtyByTile(tile + TileDiffXY(1, 0));
    71 	MarkTileDirtyByTile(tile + TileDiffXY(1, 0));
    72 	MarkTileDirtyByTile(tile + TileDiffXY(1, 1));
    72 	MarkTileDirtyByTile(tile + TileDiffXY(1, 1));
    73 }
    73 }
    74 
    74 
    75 int64 CalculateCompanyValue(const Player *p)
    75 int64 CalculateCompanyValue(const Player* p)
    76 {
    76 {
    77 	PlayerID owner = p->index;
    77 	PlayerID owner = p->index;
    78 	int64 value;
    78 	int64 value;
    79 
    79 
    80 	{
    80 	{
   645 static void AddInflation(void)
   645 static void AddInflation(void)
   646 {
   646 {
   647 	int i;
   647 	int i;
   648 	int32 inf = _economy.infl_amount * 54;
   648 	int32 inf = _economy.infl_amount * 54;
   649 
   649 
   650 	for(i=0; i!=NUM_PRICES; i++) {
   650 	for (i = 0; i != NUM_PRICES; i++) {
   651 		AddSingleInflation( (int32*)&_price + i, _price_frac + i, inf );
   651 		AddSingleInflation((int32*)&_price + i, _price_frac + i, inf);
   652 	}
   652 	}
   653 
   653 
   654 	_economy.max_loan_unround += BIGMULUS(_economy.max_loan_unround, inf, 16);
   654 	_economy.max_loan_unround += BIGMULUS(_economy.max_loan_unround, inf, 16);
   655 
   655 
   656 	if (_economy.max_loan + 50000 <= _economy.max_loan_unround)
   656 	if (_economy.max_loan + 50000 <= _economy.max_loan_unround)
   657 		_economy.max_loan += 50000;
   657 		_economy.max_loan += 50000;
   658 
   658 
   659 	inf = _economy.infl_amount_pr * 54;
   659 	inf = _economy.infl_amount_pr * 54;
   660 	for(i=0; i!=NUM_CARGO; i++) {
   660 	for (i = 0; i != NUM_CARGO; i++) {
   661 		AddSingleInflation(
   661 		AddSingleInflation(
   662 			(int32*)_cargo_payment_rates + i,
   662 			(int32*)_cargo_payment_rates + i,
   663 			_cargo_payment_rates_frac + i,
   663 			_cargo_payment_rates_frac + i,
   664 			inf
   664 			inf
   665 		);
   665 		);
   675 {
   675 {
   676 	const Player* p;
   676 	const Player* p;
   677 	int interest = _economy.interest_rate * 54;
   677 	int interest = _economy.interest_rate * 54;
   678 
   678 
   679 	FOR_ALL_PLAYERS(p) {
   679 	FOR_ALL_PLAYERS(p) {
   680 		if (!p->is_active)
   680 		if (!p->is_active) continue;
   681 			continue;
       
   682 
   681 
   683 		_current_player = p->index;
   682 		_current_player = p->index;
   684 		SET_EXPENSES_TYPE(EXPENSES_LOAN_INT);
   683 		SET_EXPENSES_TYPE(EXPENSES_LOAN_INT);
   685 
   684 
   686 		SubtractMoneyFromPlayer(BIGMULUS(p->current_loan, interest, 16));
   685 		SubtractMoneyFromPlayer(BIGMULUS(p->current_loan, interest, 16));
   690 	}
   689 	}
   691 }
   690 }
   692 
   691 
   693 static void HandleEconomyFluctuations(void)
   692 static void HandleEconomyFluctuations(void)
   694 {
   693 {
   695 	if (_opt.diff.economy == 0)
   694 	if (_opt.diff.economy == 0) return;
   696 		return;
       
   697 
   695 
   698 	if (--_economy.fluct == 0) {
   696 	if (--_economy.fluct == 0) {
   699 		_economy.fluct = - (int)(Random()&3);
   697 		_economy.fluct = - (int)(Random()&3);
   700 		AddNewsItem(STR_7073_WORLD_RECESSION_FINANCIAL, NEWS_FLAGS(NM_NORMAL,0,NT_ECONOMY,0), 0, 0);
   698 		AddNewsItem(STR_7073_WORLD_RECESSION_FINANCIAL, NEWS_FLAGS(NM_NORMAL,0,NT_ECONOMY,0), 0, 0);
   701 	} else if (_economy.fluct == -12) {
   699 	} else if (_economy.fluct == -12) {
   983 
   981 
   984 static bool CheckSubsidyDuplicate(Subsidy *s)
   982 static bool CheckSubsidyDuplicate(Subsidy *s)
   985 {
   983 {
   986 	const Subsidy* ss;
   984 	const Subsidy* ss;
   987 
   985 
   988 	for(ss=_subsidies; ss != endof(_subsidies); ss++) {
   986 	for (ss = _subsidies; ss != endof(_subsidies); ss++) {
   989 		if (s != ss &&
   987 		if (s != ss &&
   990 //				ss->age < 12 &&
       
   991 				ss->from == s->from &&
   988 				ss->from == s->from &&
   992 				ss->to == s->to &&
   989 				ss->to == s->to &&
   993 				ss->cargo_type == s->cargo_type) {
   990 				ss->cargo_type == s->cargo_type) {
   994 			s->cargo_type = CT_INVALID;
   991 			s->cargo_type = CT_INVALID;
   995 			return true;
   992 			return true;
  1331 	int unloading_time = 20;
  1328 	int unloading_time = 20;
  1332 	Vehicle *u = v;
  1329 	Vehicle *u = v;
  1333 	int result = 0;
  1330 	int result = 0;
  1334 	uint16 last_visited;
  1331 	uint16 last_visited;
  1335 	Station *st;
  1332 	Station *st;
  1336 	GoodsEntry *ge;
       
  1337 	int t;
  1333 	int t;
  1338 	uint count, cap;
  1334 	uint count, cap;
  1339 	PlayerID old_player;
  1335 	PlayerID old_player;
  1340 	bool completely_empty = true;
  1336 	bool completely_empty = true;
  1341 
  1337 
  1347 	_current_player = v->owner;
  1343 	_current_player = v->owner;
  1348 
  1344 
  1349 	st = GetStation(last_visited = v->last_station_visited);
  1345 	st = GetStation(last_visited = v->last_station_visited);
  1350 
  1346 
  1351 	for (; v != NULL; v = v->next) {
  1347 	for (; v != NULL; v = v->next) {
       
  1348 		GoodsEntry* ge;
       
  1349 
  1352 		if (v->cargo_cap == 0) continue;
  1350 		if (v->cargo_cap == 0) continue;
  1353 
  1351 
  1354 		ge = &st->goods[v->cargo_type];
  1352 		ge = &st->goods[v->cargo_type];
  1355 
  1353 
  1356 		/* unload? */
  1354 		/* unload? */
  1357 		if (v->cargo_count != 0) {
  1355 		if (v->cargo_count != 0) {
  1358 			if ( v->cargo_source != last_visited && ge->waiting_acceptance & 0x8000 && !(u->current_order.flags & OF_TRANSFER) ) {
  1356 			if (v->cargo_source != last_visited && ge->waiting_acceptance & 0x8000 && !(u->current_order.flags & OF_TRANSFER)) {
  1359 				// deliver goods to the station
  1357 				// deliver goods to the station
  1360 				st->time_since_unload = 0;
  1358 				st->time_since_unload = 0;
  1361 
  1359 
  1362 				unloading_time += v->cargo_count; /* TTDBUG: bug in original TTD */
  1360 				unloading_time += v->cargo_count; /* TTDBUG: bug in original TTD */
  1363 				profit += DeliverGoods(v->cargo_count, v->cargo_type, v->cargo_source, last_visited, v->cargo_days);
  1361 				profit += DeliverGoods(v->cargo_count, v->cargo_type, v->cargo_source, last_visited, v->cargo_days);
  1364 				result |= 1;
  1362 				result |= 1;
  1365 				v->cargo_count = 0;
  1363 				v->cargo_count = 0;
  1366 			} else if (u->current_order.flags & ( OF_UNLOAD | OF_TRANSFER) ) {
  1364 			} else if (u->current_order.flags & (OF_UNLOAD | OF_TRANSFER)) {
  1367 				/* unload goods and let it wait at the station */
  1365 				/* unload goods and let it wait at the station */
  1368 				st->time_since_unload = 0;
  1366 				st->time_since_unload = 0;
  1369 
  1367 
  1370 				v_profit = GetTransportedGoodsIncome(
  1368 				v_profit = GetTransportedGoodsIncome(
  1371 						v->cargo_count,
  1369 						v->cargo_count,