1
0
Fork 0

(svn r20317) -Codechange: Move variable declaration to their first use.

release/1.1
alberth 2010-08-02 20:19:10 +00:00
parent 00dcb16760
commit 73f45d16d1
3 changed files with 15 additions and 25 deletions

View File

@ -317,28 +317,24 @@ CommandCost CheckTileOwnership(TileIndex tile)
*/ */
static void GenerateCompanyName(Company *c) static void GenerateCompanyName(Company *c)
{ {
TileIndex tile;
Town *t;
StringID str;
Company *cc;
uint32 strp;
/* Reserve space for extra unicode character. We need to do this to be able /* Reserve space for extra unicode character. We need to do this to be able
* to detect too long company name. */ * to detect too long company name. */
char buffer[MAX_LENGTH_COMPANY_NAME_BYTES + MAX_CHAR_LENGTH]; char buffer[MAX_LENGTH_COMPANY_NAME_BYTES + MAX_CHAR_LENGTH];
if (c->name_1 != STR_SV_UNNAMED) return; if (c->name_1 != STR_SV_UNNAMED) return;
if (c->last_build_coordinate == 0) return;
tile = c->last_build_coordinate; Town *t = ClosestTownFromTile(c->last_build_coordinate, UINT_MAX);
if (tile == 0) return;
t = ClosestTownFromTile(tile, UINT_MAX);
StringID str;
uint32 strp;
if (t->name == NULL && IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST + 1)) { if (t->name == NULL && IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST + 1)) {
str = t->townnametype - SPECSTR_TOWNNAME_START + SPECSTR_PLAYERNAME_START; str = t->townnametype - SPECSTR_TOWNNAME_START + SPECSTR_PLAYERNAME_START;
strp = t->townnameparts; strp = t->townnameparts;
verify_name:; verify_name:;
/* No companies must have this name already */ /* No companies must have this name already */
Company *cc;
FOR_ALL_COMPANIES(cc) { FOR_ALL_COMPANIES(cc) {
if (cc->name_1 == str && cc->name_2 == strp) goto bad_town_name; if (cc->name_1 == str && cc->name_2 == strp) goto bad_town_name;
} }

View File

@ -126,7 +126,6 @@ static PriceMultipliers _price_base_multiplier;
Money CalculateCompanyValue(const Company *c, bool including_loan) Money CalculateCompanyValue(const Company *c, bool including_loan)
{ {
Owner owner = c->index; Owner owner = c->index;
Money value = 0;
Station *st; Station *st;
uint num = 0; uint num = 0;
@ -135,7 +134,7 @@ Money CalculateCompanyValue(const Company *c, bool including_loan)
if (st->owner == owner) num += CountBits((byte)st->facilities); if (st->owner == owner) num += CountBits((byte)st->facilities);
} }
value += num * _price[PR_STATION_VALUE] * 25; Money value = num * _price[PR_STATION_VALUE] * 25;
Vehicle *v; Vehicle *v;
FOR_ALL_VEHICLES(v) { FOR_ALL_VEHICLES(v) {
@ -556,7 +555,6 @@ static void CompanyCheckBankrupt(Company *c)
static void CompaniesGenStatistics() static void CompaniesGenStatistics()
{ {
Station *st; Station *st;
Company *c;
Backup<CompanyByte> cur_company(_current_company, FILE_LINE); Backup<CompanyByte> cur_company(_current_company, FILE_LINE);
FOR_ALL_STATIONS(st) { FOR_ALL_STATIONS(st) {
@ -568,6 +566,7 @@ static void CompaniesGenStatistics()
if (!HasBit(1 << 0 | 1 << 3 | 1 << 6 | 1 << 9, _cur_month)) return; if (!HasBit(1 << 0 | 1 << 3 | 1 << 6 | 1 << 9, _cur_month)) return;
Company *c;
FOR_ALL_COMPANIES(c) { FOR_ALL_COMPANIES(c) {
memmove(&c->old_economy[1], &c->old_economy[0], sizeof(c->old_economy) - sizeof(c->old_economy[0])); memmove(&c->old_economy[1], &c->old_economy[0], sizeof(c->old_economy) - sizeof(c->old_economy[0]));
c->old_economy[0] = c->cur_economy; c->old_economy[0] = c->cur_economy;
@ -1441,9 +1440,6 @@ void CompaniesMonthlyLoop()
static void DoAcquireCompany(Company *c) static void DoAcquireCompany(Company *c)
{ {
Company *owner;
int i;
Money value;
CompanyID ci = c->index; CompanyID ci = c->index;
CompanyNewsInformation *cni = MallocT<CompanyNewsInformation>(1); CompanyNewsInformation *cni = MallocT<CompanyNewsInformation>(1);
@ -1460,13 +1456,13 @@ static void DoAcquireCompany(Company *c)
ChangeOwnershipOfCompanyItems(ci, _current_company); ChangeOwnershipOfCompanyItems(ci, _current_company);
if (c->bankrupt_value == 0) { if (c->bankrupt_value == 0) {
owner = Company::Get(_current_company); Company *owner = Company::Get(_current_company);
owner->current_loan += c->current_loan; owner->current_loan += c->current_loan;
} }
value = CalculateCompanyValue(c) >> 2; Money value = CalculateCompanyValue(c) >> 2;
Backup<CompanyByte> cur_company(_current_company, FILE_LINE); Backup<CompanyByte> cur_company(_current_company, FILE_LINE);
for (i = 0; i != 4; i++) { for (int i = 0; i != 4; i++) {
if (c->share_owners[i] != COMPANY_SPECTATOR) { if (c->share_owners[i] != COMPANY_SPECTATOR) {
cur_company.Change(c->share_owners[i]); cur_company.Change(c->share_owners[i]);
SubtractMoneyFromCompany(CommandCost(EXPENSES_OTHER, -value)); SubtractMoneyFromCompany(CommandCost(EXPENSES_OTHER, -value));
@ -1518,12 +1514,11 @@ CommandCost CmdBuyShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1,
cost.AddCost(CalculateCompanyValue(c) >> 2); cost.AddCost(CalculateCompanyValue(c) >> 2);
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
OwnerByte *b = c->share_owners; OwnerByte *b = c->share_owners;
int i;
while (*b != COMPANY_SPECTATOR) b++; // share owners is guaranteed to contain at least one COMPANY_SPECTATOR while (*b != COMPANY_SPECTATOR) b++; // share owners is guaranteed to contain at least one COMPANY_SPECTATOR
*b = _current_company; *b = _current_company;
for (i = 0; c->share_owners[i] == _current_company;) { for (int i = 0; c->share_owners[i] == _current_company;) {
if (++i == 4) { if (++i == 4) {
c->bankrupt_value = 0; c->bankrupt_value = 0;
DoAcquireCompany(c); DoAcquireCompany(c);

View File

@ -524,7 +524,6 @@ void SetYearEngineAgingStops()
void StartupOneEngine(Engine *e, Date aging_date) void StartupOneEngine(Engine *e, Date aging_date)
{ {
const EngineInfo *ei = &e->info; const EngineInfo *ei = &e->info;
uint32 r;
e->age = 0; e->age = 0;
e->flags = 0; e->flags = 0;
@ -533,7 +532,7 @@ void StartupOneEngine(Engine *e, Date aging_date)
/* Don't randomise the start-date in the first two years after gamestart to ensure availability /* Don't randomise the start-date in the first two years after gamestart to ensure availability
* of engines in early starting games. * of engines in early starting games.
* Note: TTDP uses fixed 1922 */ * Note: TTDP uses fixed 1922 */
r = Random(); uint32 r = Random();
e->intro_date = ei->base_intro <= ConvertYMDToDate(_settings_game.game_creation.starting_year + 2, 0, 1) ? ei->base_intro : (Date)GB(r, 0, 9) + ei->base_intro; e->intro_date = ei->base_intro <= ConvertYMDToDate(_settings_game.game_creation.starting_year + 2, 0, 1) ? ei->base_intro : (Date)GB(r, 0, 9) + ei->base_intro;
if (e->intro_date <= _date) { if (e->intro_date <= _date) {
e->age = (aging_date - e->intro_date) >> 5; e->age = (aging_date - e->intro_date) >> 5;
@ -601,14 +600,14 @@ static void AcceptEnginePreview(EngineID eid, CompanyID company)
static CompanyID GetBestCompany(uint8 pp) static CompanyID GetBestCompany(uint8 pp)
{ {
const Company *c;
int32 best_hist;
CompanyID best_company; CompanyID best_company;
CompanyMask mask = 0; CompanyMask mask = 0;
do { do {
best_hist = -1; int32 best_hist = -1;
best_company = INVALID_COMPANY; best_company = INVALID_COMPANY;
const Company *c;
FOR_ALL_COMPANIES(c) { FOR_ALL_COMPANIES(c) {
if (c->block_preview == 0 && !HasBit(mask, c->index) && if (c->block_preview == 0 && !HasBit(mask, c->index) &&
c->old_economy[0].performance_history > best_hist) { c->old_economy[0].performance_history > best_hist) {