mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r15352) -Codechange: make the arguments passed around while founding a town a bit more readable
This commit is contained in:
parent
9d94c8f369
commit
aa692a99a9
|
@ -250,7 +250,7 @@ void UpdateAllTownVirtCoords();
|
||||||
void InitializeTown();
|
void InitializeTown();
|
||||||
void ShowTownViewWindow(TownID town);
|
void ShowTownViewWindow(TownID town);
|
||||||
void ExpandTown(Town *t);
|
void ExpandTown(Town *t);
|
||||||
Town *CreateRandomTown(uint attempts, TownSizeMode mode, uint size, TownLayout layout);
|
Town *CreateRandomTown(uint attempts, TownSize size, bool city, TownLayout layout);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
ROAD_REMOVE = 0,
|
ROAD_REMOVE = 0,
|
||||||
|
|
|
@ -1428,7 +1428,7 @@ void UpdateTownMaxPass(Town *t)
|
||||||
* @param size_mode How the size should be determined
|
* @param size_mode How the size should be determined
|
||||||
* @param size Parameter for size determination
|
* @param size Parameter for size determination
|
||||||
*/
|
*/
|
||||||
static void DoCreateTown(Town *t, TileIndex tile, uint32 townnameparts, TownSizeMode size_mode, uint size, TownLayout layout)
|
static void DoCreateTown(Town *t, TileIndex tile, uint32 townnameparts, TownSize size, bool city, TownLayout layout)
|
||||||
{
|
{
|
||||||
extern int _nb_orig_names;
|
extern int _nb_orig_names;
|
||||||
|
|
||||||
|
@ -1480,26 +1480,11 @@ static void DoCreateTown(Town *t, TileIndex tile, uint32 townnameparts, TownSize
|
||||||
|
|
||||||
t->InitializeLayout(layout);
|
t->InitializeLayout(layout);
|
||||||
|
|
||||||
/* Random town size. */
|
t->larger_town = city;
|
||||||
int x = (Random() & 0xF) + 8;
|
|
||||||
|
|
||||||
switch (size_mode) {
|
int x = (int)size * 16 + 3;
|
||||||
default: NOT_REACHED();
|
if (size == TS_RANDOM) x = (Random() & 0xF) + 8;
|
||||||
|
if (city) x *= _settings_game.economy.initial_city_size;
|
||||||
case TSM_RANDOM:
|
|
||||||
t->larger_town = false;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TSM_FIXED:
|
|
||||||
x = size * 16 + 3;
|
|
||||||
t->larger_town = false;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TSM_CITY:
|
|
||||||
x *= _settings_game.economy.initial_city_size;
|
|
||||||
t->larger_town = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
t->noise_reached = 0;
|
t->noise_reached = 0;
|
||||||
|
|
||||||
|
@ -1521,20 +1506,21 @@ static void DoCreateTown(Town *t, TileIndex tile, uint32 townnameparts, TownSize
|
||||||
* as it might be possible in the future to fund your own town :)
|
* as it might be possible in the future to fund your own town :)
|
||||||
* @param tile coordinates where town is built
|
* @param tile coordinates where town is built
|
||||||
* @param flags type of operation
|
* @param flags type of operation
|
||||||
* @param p1 0..15 size of the town (0 = small, 1 = medium, 2 = large)
|
* @param p1 0..1 size of the town (@see TownSize)
|
||||||
* 16..31 town road layout
|
* 2 true iff it should be a city
|
||||||
* @param p2 size mode (@see TownSizeMode)
|
* 3..5 town road layout (@see TownLayout)
|
||||||
|
* @param p2 unused
|
||||||
*/
|
*/
|
||||||
CommandCost CmdBuildTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
|
CommandCost CmdBuildTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text)
|
||||||
{
|
{
|
||||||
/* Only in the scenario editor */
|
/* Only in the scenario editor */
|
||||||
if (_game_mode != GM_EDITOR) return CMD_ERROR;
|
if (_game_mode != GM_EDITOR) return CMD_ERROR;
|
||||||
|
|
||||||
TownSizeMode tsm = (TownSizeMode)p2;
|
TownSize size = (TownSize)GB(p1, 0, 2);
|
||||||
uint size = GB(p1, 0, 16);
|
bool city = HasBit(p1, 2);
|
||||||
TownLayout layout = (TownLayout)GB(p1, 16, 16);
|
TownLayout layout = (TownLayout)GB(p1, 3, 3);
|
||||||
|
|
||||||
if (tsm > TSM_CITY) return CMD_ERROR;
|
if (size > TS_RANDOM) return CMD_ERROR;
|
||||||
if (layout > TL_RANDOM) return CMD_ERROR;
|
if (layout > TL_RANDOM) return CMD_ERROR;
|
||||||
|
|
||||||
/* Check if too close to the edge of map */
|
/* Check if too close to the edge of map */
|
||||||
|
@ -1564,14 +1550,14 @@ CommandCost CmdBuildTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, con
|
||||||
Town *t = new Town(tile);
|
Town *t = new Town(tile);
|
||||||
_generating_world = true;
|
_generating_world = true;
|
||||||
UpdateNearestTownForRoadTiles(true);
|
UpdateNearestTownForRoadTiles(true);
|
||||||
DoCreateTown(t, tile, townnameparts, tsm, size, layout);
|
DoCreateTown(t, tile, townnameparts, size, city, layout);
|
||||||
UpdateNearestTownForRoadTiles(false);
|
UpdateNearestTownForRoadTiles(false);
|
||||||
_generating_world = false;
|
_generating_world = false;
|
||||||
}
|
}
|
||||||
return CommandCost();
|
return CommandCost();
|
||||||
}
|
}
|
||||||
|
|
||||||
Town *CreateRandomTown(uint attempts, TownSizeMode mode, uint size, TownLayout layout)
|
Town *CreateRandomTown(uint attempts, TownSize size, bool city, TownLayout layout)
|
||||||
{
|
{
|
||||||
if (!Town::CanAllocateItem()) return NULL;
|
if (!Town::CanAllocateItem()) return NULL;
|
||||||
|
|
||||||
|
@ -1603,7 +1589,7 @@ Town *CreateRandomTown(uint attempts, TownSizeMode mode, uint size, TownLayout l
|
||||||
/* Allocate a town struct */
|
/* Allocate a town struct */
|
||||||
Town *t = new Town(tile);
|
Town *t = new Town(tile);
|
||||||
|
|
||||||
DoCreateTown(t, tile, townnameparts, mode, size, layout);
|
DoCreateTown(t, tile, townnameparts, size, city, layout);
|
||||||
return t;
|
return t;
|
||||||
} while (--attempts != 0);
|
} while (--attempts != 0);
|
||||||
|
|
||||||
|
@ -1623,13 +1609,12 @@ bool GenerateTowns(TownLayout layout)
|
||||||
do {
|
do {
|
||||||
IncreaseGeneratingWorldProgress(GWP_TOWN);
|
IncreaseGeneratingWorldProgress(GWP_TOWN);
|
||||||
/* try 20 times to create a random-sized town for the first loop. */
|
/* try 20 times to create a random-sized town for the first loop. */
|
||||||
TownSizeMode mode = num_cities > 0 ? TSM_CITY : TSM_RANDOM;
|
if (CreateRandomTown(20, TS_RANDOM, num_cities > 0, layout) != NULL) num++;
|
||||||
if (CreateRandomTown(20, mode, _settings_game.economy.initial_city_size, layout) != NULL) num++;
|
|
||||||
if (num_cities > 0) num_cities--;
|
if (num_cities > 0) num_cities--;
|
||||||
} while (--n);
|
} while (--n);
|
||||||
|
|
||||||
/* give it a last try, but now more aggressive */
|
/* give it a last try, but now more aggressive */
|
||||||
if (num == 0 && CreateRandomTown(10000, TSM_RANDOM, 0, layout) == NULL) {
|
if (num == 0 && CreateRandomTown(10000, TS_RANDOM, false, layout) == NULL) {
|
||||||
if (GetNumTowns() == 0) {
|
if (GetNumTowns() == 0) {
|
||||||
/* XXX - can we handle that more gracefully? */
|
/* XXX - can we handle that more gracefully? */
|
||||||
if (_game_mode != GM_EDITOR) usererror("Could not generate any town");
|
if (_game_mode != GM_EDITOR) usererror("Could not generate any town");
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
typedef GUIList<const Town*> GUITownList;
|
typedef GUIList<const Town*> GUITownList;
|
||||||
|
|
||||||
static int _scengen_town_size = 1; // depress medium-sized towns per default
|
static uint _scengen_town_size = 1; // select medium-sized towns per default
|
||||||
static TownLayout _scengen_town_layout;
|
static TownLayout _scengen_town_layout;
|
||||||
|
|
||||||
static const Widget _town_authority_widgets[] = {
|
static const Widget _town_authority_widgets[] = {
|
||||||
|
@ -603,10 +603,9 @@ void CcBuildTown(bool success, TileIndex tile, uint32 p1, uint32 p2)
|
||||||
|
|
||||||
static void PlaceProc_Town(TileIndex tile)
|
static void PlaceProc_Town(TileIndex tile)
|
||||||
{
|
{
|
||||||
uint32 size = min(_scengen_town_size, 2);
|
bool city = _scengen_town_size > (uint)TS_LARGE;
|
||||||
uint32 mode = _scengen_town_size > 2 ? TSM_CITY : TSM_FIXED;
|
TownSize size = city ? TS_RANDOM : (TownSize)_scengen_town_size;
|
||||||
uint32 layout = _scengen_town_layout;
|
DoCommandP(tile, size | city << 2 | (_scengen_town_layout << 3), 0, CMD_BUILD_TOWN | CMD_MSG(STR_0236_CAN_T_BUILD_TOWN_HERE), CcBuildTown);
|
||||||
DoCommandP(tile, size | (layout << 16), mode, CMD_BUILD_TOWN | CMD_MSG(STR_0236_CAN_T_BUILD_TOWN_HERE), CcBuildTown);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const Widget _scen_edit_town_gen_widgets[] = {
|
static const Widget _scen_edit_town_gen_widgets[] = {
|
||||||
|
@ -677,14 +676,14 @@ public:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TSEW_RANDOMTOWN: {
|
case TSEW_RANDOMTOWN: {
|
||||||
Town *t;
|
bool city = _scengen_town_size == 3;
|
||||||
uint size = min(_scengen_town_size, (int)TSM_CITY);
|
/* cities will always have 'large size' * initial_city_size */
|
||||||
TownSizeMode mode = _scengen_town_size > TSM_CITY ? TSM_CITY : TSM_FIXED;
|
TownSize size = city ? TS_RANDOM : (TownSize)_scengen_town_size;
|
||||||
|
|
||||||
this->HandleButtonClick(TSEW_RANDOMTOWN);
|
this->HandleButtonClick(TSEW_RANDOMTOWN);
|
||||||
_generating_world = true;
|
_generating_world = true;
|
||||||
UpdateNearestTownForRoadTiles(true);
|
UpdateNearestTownForRoadTiles(true);
|
||||||
t = CreateRandomTown(20, mode, size, _scengen_town_layout);
|
const Town *t = CreateRandomTown(20, size, city, _scengen_town_layout);
|
||||||
UpdateNearestTownForRoadTiles(false);
|
UpdateNearestTownForRoadTiles(false);
|
||||||
_generating_world = false;
|
_generating_world = false;
|
||||||
|
|
||||||
|
|
|
@ -14,10 +14,12 @@ typedef uint16 HouseClassID;
|
||||||
struct Town;
|
struct Town;
|
||||||
struct HouseSpec;
|
struct HouseSpec;
|
||||||
|
|
||||||
enum TownSizeMode {
|
/** Supported initial town sizes */
|
||||||
TSM_RANDOM,
|
enum TownSize {
|
||||||
TSM_FIXED,
|
TS_SMALL, ///< small town
|
||||||
TSM_CITY
|
TS_MEDIUM, ///< medium town
|
||||||
|
TS_LARGE, ///< large town
|
||||||
|
TS_RANDOM, ///< random size, bigger than small, smaller than large
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
|
Loading…
Reference in New Issue