economy.c
changeset 3386 6d088afdabf4
parent 3347 0ddacd451b81
child 3421 7968a4b5ff0a
equal deleted inserted replaced
3385:18e4ca6d3ef4 3386:6d088afdabf4
    26 #include "variables.h"
    26 #include "variables.h"
    27 #include "vehicle_gui.h"
    27 #include "vehicle_gui.h"
    28 #include "ai/ai.h"
    28 #include "ai/ai.h"
    29 #include "train.h"
    29 #include "train.h"
    30 #include "newgrf_engine.h"
    30 #include "newgrf_engine.h"
       
    31 #include "unmovable.h"
    31 
    32 
    32 // Score info
    33 // Score info
    33 const ScoreInfo _score_info[] = {
    34 const ScoreInfo _score_info[] = {
    34     {SCORE_VEHICLES,		120, 			100},
    35     {SCORE_VEHICLES,		120, 			100},
    35     {SCORE_STATIONS,		80, 			100},
    36     {SCORE_STATIONS,		80, 			100},
    42     {SCORE_LOAN,				250000,		50},
    43     {SCORE_LOAN,				250000,		50},
    43     {SCORE_TOTAL,				0,				0}
    44     {SCORE_TOTAL,				0,				0}
    44 };
    45 };
    45 
    46 
    46 int _score_part[MAX_PLAYERS][NUM_SCORE];
    47 int _score_part[MAX_PLAYERS][NUM_SCORE];
    47 
       
    48 void UpdatePlayerHouse(Player *p, uint score)
       
    49 {
       
    50 	byte val;
       
    51 	TileIndex tile = p->location_of_house;
       
    52 
       
    53 	if (tile == 0)
       
    54 		return;
       
    55 
       
    56 	(val = 128, score < 170) ||
       
    57 	(val+= 4, score < 350) ||
       
    58 	(val+= 4, score < 520) ||
       
    59 	(val+= 4, score < 720) ||
       
    60 	(val+= 4, true);
       
    61 
       
    62 /* house is already big enough */
       
    63 	if (val <= _m[tile].m5)
       
    64 		return;
       
    65 
       
    66 	_m[tile + TileDiffXY(0, 0)].m5 =   val;
       
    67 	_m[tile + TileDiffXY(0, 1)].m5 = ++val;
       
    68 	_m[tile + TileDiffXY(1, 0)].m5 = ++val;
       
    69 	_m[tile + TileDiffXY(1, 1)].m5 = ++val;
       
    70 
       
    71 	MarkTileDirtyByTile(tile + TileDiffXY(0, 0));
       
    72 	MarkTileDirtyByTile(tile + TileDiffXY(0, 1));
       
    73 	MarkTileDirtyByTile(tile + TileDiffXY(1, 0));
       
    74 	MarkTileDirtyByTile(tile + TileDiffXY(1, 1));
       
    75 }
       
    76 
    48 
    77 int64 CalculateCompanyValue(const Player* p)
    49 int64 CalculateCompanyValue(const Player* p)
    78 {
    50 {
    79 	PlayerID owner = p->index;
    51 	PlayerID owner = p->index;
    80 	int64 value;
    52 	int64 value;
   256 		if (total_score != SCORE_MAX) score = score * SCORE_MAX / total_score;
   228 		if (total_score != SCORE_MAX) score = score * SCORE_MAX / total_score;
   257 	}
   229 	}
   258 
   230 
   259 	if (update) {
   231 	if (update) {
   260     	p->old_economy[0].performance_history = score;
   232     	p->old_economy[0].performance_history = score;
   261     	UpdatePlayerHouse(p, score);
   233     	UpdateCompanyHQ(p, score);
   262     	p->old_economy[0].company_value = CalculateCompanyValue(p);
   234     	p->old_economy[0].company_value = CalculateCompanyValue(p);
   263     }
   235     }
   264 
   236 
   265 	InvalidateWindow(WC_PERFORMANCE_DETAIL, 0);
   237 	InvalidateWindow(WC_PERFORMANCE_DETAIL, 0);
   266 	return score;
   238 	return score;