29 #include "newgrf.h" |
29 #include "newgrf.h" |
30 #include "newgrf_callbacks.h" |
30 #include "newgrf_callbacks.h" |
31 #include "newgrf_house.h" |
31 #include "newgrf_house.h" |
32 #include "newgrf_commons.h" |
32 #include "newgrf_commons.h" |
33 #include "newgrf_townname.h" |
33 #include "newgrf_townname.h" |
34 #include "misc/autoptr.hpp" |
|
35 #include "autoslope.h" |
34 #include "autoslope.h" |
36 #include "waypoint.h" |
35 #include "waypoint.h" |
37 #include "transparency.h" |
36 #include "transparency.h" |
38 #include "tunnelbridge_map.h" |
37 #include "tunnelbridge_map.h" |
39 #include "strings_func.h" |
38 #include "strings_func.h" |
1536 /* Get a unique name for the town. */ |
1535 /* Get a unique name for the town. */ |
1537 if (!CreateTownName(&townnameparts)) |
1536 if (!CreateTownName(&townnameparts)) |
1538 return_cmd_error(STR_023A_TOO_MANY_TOWNS); |
1537 return_cmd_error(STR_023A_TOO_MANY_TOWNS); |
1539 |
1538 |
1540 /* Allocate town struct */ |
1539 /* Allocate town struct */ |
1541 Town *t = new Town(tile); |
1540 if (!Town::CanAllocateItem()) return_cmd_error(STR_023A_TOO_MANY_TOWNS); |
1542 if (t == NULL) return_cmd_error(STR_023A_TOO_MANY_TOWNS); |
|
1543 AutoPtrT<Town> t_auto_delete = t; |
|
1544 |
1541 |
1545 /* Create the town */ |
1542 /* Create the town */ |
1546 if (flags & DC_EXEC) { |
1543 if (flags & DC_EXEC) { |
|
1544 Town *t = new Town(tile); |
1547 _generating_world = true; |
1545 _generating_world = true; |
1548 DoCreateTown(t, tile, townnameparts, (TownSizeMode)p2, p1); |
1546 DoCreateTown(t, tile, townnameparts, (TownSizeMode)p2, p1); |
1549 _generating_world = false; |
1547 _generating_world = false; |
1550 t_auto_delete.Detach(); |
|
1551 } |
1548 } |
1552 return CommandCost(); |
1549 return CommandCost(); |
1553 } |
1550 } |
1554 |
1551 |
1555 Town *CreateRandomTown(uint attempts, TownSizeMode mode, uint size) |
1552 Town *CreateRandomTown(uint attempts, TownSizeMode mode, uint size) |