Mercurial > hg > openttd
comparison src/industry_cmd.cpp @ 15292:e2c62d70dfcf draft
(svn r19931) -Fix (r19914): Convert assertion in Backup<> destructor into DEBUG() output. It was triggered on exceptions, especially when aborting world generation.
author | frosch <frosch@openttd.org> |
---|---|
date | Sat, 05 Jun 2010 12:16:12 +0000 |
parents | 4e1862aebea2 |
children | b6a87cffd56b |
comparison
equal
deleted
inserted
replaced
15291:90225375fccd | 15292:e2c62d70dfcf |
---|---|
1041 static bool SearchLumberMillTrees(TileIndex tile, void *user_data) | 1041 static bool SearchLumberMillTrees(TileIndex tile, void *user_data) |
1042 { | 1042 { |
1043 if (IsTileType(tile, MP_TREES) && GetTreeGrowth(tile) > 2) { ///< 3 and up means all fully grown trees | 1043 if (IsTileType(tile, MP_TREES) && GetTreeGrowth(tile) > 2) { ///< 3 and up means all fully grown trees |
1044 /* found a tree */ | 1044 /* found a tree */ |
1045 | 1045 |
1046 Backup<CompanyByte> cur_company(_current_company, OWNER_NONE); | 1046 Backup<CompanyByte> cur_company(_current_company, OWNER_NONE, FILE_LINE); |
1047 | 1047 |
1048 _industry_sound_ctr = 1; | 1048 _industry_sound_ctr = 1; |
1049 _industry_sound_tile = tile; | 1049 _industry_sound_tile = tile; |
1050 SndPlayTileFx(SND_38_CHAINSAW, tile); | 1050 SndPlayTileFx(SND_38_CHAINSAW, tile); |
1051 | 1051 |
1370 if (!IsTileType(cur_tile, MP_HOUSE)) { | 1370 if (!IsTileType(cur_tile, MP_HOUSE)) { |
1371 return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_IN_TOWNS); | 1371 return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_IN_TOWNS); |
1372 } | 1372 } |
1373 | 1373 |
1374 /* Clear the tiles as OWNER_TOWN to not affect town rating, and to not clear protected buildings */ | 1374 /* Clear the tiles as OWNER_TOWN to not affect town rating, and to not clear protected buildings */ |
1375 Backup<CompanyByte> cur_company(_current_company, OWNER_TOWN); | 1375 Backup<CompanyByte> cur_company(_current_company, OWNER_TOWN, FILE_LINE); |
1376 CommandCost ret = DoCommand(cur_tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR); | 1376 CommandCost ret = DoCommand(cur_tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR); |
1377 cur_company.Restore(); | 1377 cur_company.Restore(); |
1378 | 1378 |
1379 if (ret.Failed()) return ret; | 1379 if (ret.Failed()) return ret; |
1380 } else { | 1380 } else { |
1482 /* Check if we don't leave the map */ | 1482 /* Check if we don't leave the map */ |
1483 if (TileX(cur_tile) + size_x >= MapMaxX() || TileY(cur_tile) + size_y >= MapMaxY()) return false; | 1483 if (TileX(cur_tile) + size_x >= MapMaxX() || TileY(cur_tile) + size_y >= MapMaxY()) return false; |
1484 | 1484 |
1485 /* _current_company is OWNER_NONE for randomly generated industries and in editor, or the company who funded or prospected the industry. | 1485 /* _current_company is OWNER_NONE for randomly generated industries and in editor, or the company who funded or prospected the industry. |
1486 * Perform terraforming as OWNER_TOWN to disable autoslope and town ratings. */ | 1486 * Perform terraforming as OWNER_TOWN to disable autoslope and town ratings. */ |
1487 Backup<CompanyByte> cur_company(_current_company, OWNER_TOWN); | 1487 Backup<CompanyByte> cur_company(_current_company, OWNER_TOWN, FILE_LINE); |
1488 | 1488 |
1489 TILE_LOOP(tile_walk, size_x, size_y, cur_tile) { | 1489 TILE_LOOP(tile_walk, size_x, size_y, cur_tile) { |
1490 curh = TileHeight(tile_walk); | 1490 curh = TileHeight(tile_walk); |
1491 if (curh != h) { | 1491 if (curh != h) { |
1492 /* This tile needs terraforming. Check if we can do that without | 1492 /* This tile needs terraforming. Check if we can do that without |
1786 | 1786 |
1787 Industry *ind = NULL; | 1787 Industry *ind = NULL; |
1788 if (_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && indspec->IsRawIndustry()) { | 1788 if (_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && indspec->IsRawIndustry()) { |
1789 if (flags & DC_EXEC) { | 1789 if (flags & DC_EXEC) { |
1790 /* Prospected industries are build as OWNER_TOWN to not e.g. be build on owned land of the founder */ | 1790 /* Prospected industries are build as OWNER_TOWN to not e.g. be build on owned land of the founder */ |
1791 Backup<CompanyByte> cur_company(_current_company, OWNER_TOWN); | 1791 Backup<CompanyByte> cur_company(_current_company, OWNER_TOWN, FILE_LINE); |
1792 /* Prospecting has a chance to fail, however we cannot guarantee that something can | 1792 /* Prospecting has a chance to fail, however we cannot guarantee that something can |
1793 * be built on the map, so the chance gets lower when the map is fuller, but there | 1793 * be built on the map, so the chance gets lower when the map is fuller, but there |
1794 * is nothing we can really do about that. */ | 1794 * is nothing we can really do about that. */ |
1795 if (Random() <= indspec->prospecting_chance) { | 1795 if (Random() <= indspec->prospecting_chance) { |
1796 for (int i = 0; i < 5000; i++) { | 1796 for (int i = 0; i < 5000; i++) { |
1888 * @param type IndustryType of the desired industry | 1888 * @param type IndustryType of the desired industry |
1889 * @param try_hard Try very hard to find a place. (Used to place at least one industry per type) | 1889 * @param try_hard Try very hard to find a place. (Used to place at least one industry per type) |
1890 */ | 1890 */ |
1891 static void PlaceInitialIndustry(IndustryType type, bool try_hard) | 1891 static void PlaceInitialIndustry(IndustryType type, bool try_hard) |
1892 { | 1892 { |
1893 Backup<CompanyByte> cur_company(_current_company, OWNER_NONE); | 1893 Backup<CompanyByte> cur_company(_current_company, OWNER_NONE, FILE_LINE); |
1894 | 1894 |
1895 IncreaseGeneratingWorldProgress(GWP_INDUSTRY); | 1895 IncreaseGeneratingWorldProgress(GWP_INDUSTRY); |
1896 | 1896 |
1897 for (uint i = 0; i < (try_hard ? 10000u : 2000u); i++) { | 1897 for (uint i = 0; i < (try_hard ? 10000u : 2000u); i++) { |
1898 if (CreateNewIndustry(RandomTile(), type) != NULL) break; | 1898 if (CreateNewIndustry(RandomTile(), type) != NULL) break; |
2412 | 2412 |
2413 if (change_loop == 0) { | 2413 if (change_loop == 0) { |
2414 return; // Nothing to do? get out | 2414 return; // Nothing to do? get out |
2415 } | 2415 } |
2416 | 2416 |
2417 Backup<CompanyByte> cur_company(_current_company, OWNER_NONE); | 2417 Backup<CompanyByte> cur_company(_current_company, OWNER_NONE, FILE_LINE); |
2418 | 2418 |
2419 /* perform the required industry changes for the day */ | 2419 /* perform the required industry changes for the day */ |
2420 for (uint16 j = 0; j < change_loop; j++) { | 2420 for (uint16 j = 0; j < change_loop; j++) { |
2421 /* 3% chance that we start a new industry */ | 2421 /* 3% chance that we start a new industry */ |
2422 if (Chance16(3, 100)) { | 2422 if (Chance16(3, 100)) { |
2437 } | 2437 } |
2438 | 2438 |
2439 void IndustryMonthlyLoop() | 2439 void IndustryMonthlyLoop() |
2440 { | 2440 { |
2441 Industry *i; | 2441 Industry *i; |
2442 Backup<CompanyByte> cur_company(_current_company, OWNER_NONE); | 2442 Backup<CompanyByte> cur_company(_current_company, OWNER_NONE, FILE_LINE); |
2443 | 2443 |
2444 FOR_ALL_INDUSTRIES(i) { | 2444 FOR_ALL_INDUSTRIES(i) { |
2445 UpdateIndustryStatistics(i); | 2445 UpdateIndustryStatistics(i); |
2446 if (i->prod_level == PRODLEVEL_CLOSURE) { | 2446 if (i->prod_level == PRODLEVEL_CLOSURE) { |
2447 delete i; | 2447 delete i; |