src/town_cmd.cpp
changeset 9387 ede823d445f5
parent 9358 2e1e4d2f71dd
child 9413 7042a8ec3fa8
equal deleted inserted replaced
9386:f3fd0650f9d5 9387:ede823d445f5
    53 #include "table/town_land.h"
    53 #include "table/town_land.h"
    54 
    54 
    55 uint _total_towns;
    55 uint _total_towns;
    56 HouseSpec _house_specs[HOUSE_MAX];
    56 HouseSpec _house_specs[HOUSE_MAX];
    57 
    57 
    58 bool _town_sort_dirty;
       
    59 byte _town_sort_order;
       
    60 const Town **_town_sort;
       
    61 
       
    62 Town *_cleared_town;
    58 Town *_cleared_town;
    63 int _cleared_town_rating;
    59 int _cleared_town_rating;
    64 
    60 
    65 /* Initialize the town-pool */
    61 /* Initialize the town-pool */
    66 DEFINE_OLD_POOL_GENERIC(Town, Town)
    62 DEFINE_OLD_POOL_GENERIC(Town, Town)
    80 	Industry *i;
    76 	Industry *i;
    81 
    77 
    82 	/* Delete town authority window
    78 	/* Delete town authority window
    83 	 * and remove from list of sorted towns */
    79 	 * and remove from list of sorted towns */
    84 	DeleteWindowById(WC_TOWN_VIEW, this->index);
    80 	DeleteWindowById(WC_TOWN_VIEW, this->index);
    85 	_town_sort_dirty = true;
    81 	InvalidateWindowData(WC_TOWN_DIRECTORY, 0, 0);
    86 	_total_towns--;
    82 	_total_towns--;
    87 
    83 
    88 	/* Delete all industries belonging to the town */
    84 	/* Delete all industries belonging to the town */
    89 	FOR_ALL_INDUSTRIES(i) if (i->town == this) delete i;
    85 	FOR_ALL_INDUSTRIES(i) if (i->town == this) delete i;
    90 
    86 
   346 {
   342 {
   347 	t->population += mod;
   343 	t->population += mod;
   348 	InvalidateWindow(WC_TOWN_VIEW, t->index);
   344 	InvalidateWindow(WC_TOWN_VIEW, t->index);
   349 	UpdateTownVirtCoord(t);
   345 	UpdateTownVirtCoord(t);
   350 
   346 
   351 	if (_town_sort_order & 2) _town_sort_dirty = true;
   347 	InvalidateWindowData(WC_TOWN_DIRECTORY, 0, 1);
   352 }
   348 }
   353 
   349 
   354 /**
   350 /**
   355  * Determines the world population
   351  * Determines the world population
   356  * Basically, count population of all towns, one by one
   352  * Basically, count population of all towns, one by one
  1463 		t->townnametype  = GetGRFTownNameType(_settings.game_creation.town_name - _nb_orig_names);
  1459 		t->townnametype  = GetGRFTownNameType(_settings.game_creation.town_name - _nb_orig_names);
  1464 	}
  1460 	}
  1465 	t->townnameparts = townnameparts;
  1461 	t->townnameparts = townnameparts;
  1466 
  1462 
  1467 	UpdateTownVirtCoord(t);
  1463 	UpdateTownVirtCoord(t);
  1468 	_town_sort_dirty = true;
  1464 	InvalidateWindowData(WC_TOWN_DIRECTORY, 0, 0);
  1469 
  1465 
  1470 	t->InitializeLayout();
  1466 	t->InitializeLayout();
  1471 
  1467 
  1472 	/* Random town size. */
  1468 	/* Random town size. */
  1473 	int x = (Random() & 0xF) + 8;
  1469 	int x = (Random() & 0xF) + 8;
  2097 
  2093 
  2098 		free(t->name);
  2094 		free(t->name);
  2099 		t->name = strdup(_cmd_text);
  2095 		t->name = strdup(_cmd_text);
  2100 
  2096 
  2101 		UpdateTownVirtCoord(t);
  2097 		UpdateTownVirtCoord(t);
  2102 		_town_sort_dirty = true;
  2098 		InvalidateWindowData(WC_TOWN_DIRECTORY, 0, 1);
  2103 		UpdateAllStationVirtCoord();
  2099 		UpdateAllStationVirtCoord();
  2104 		UpdateAllWaypointSigns();
  2100 		UpdateAllWaypointSigns();
  2105 		MarkWholeScreenDirty();
  2101 		MarkWholeScreenDirty();
  2106 	}
  2102 	}
  2107 	return CommandCost();
  2103 	return CommandCost();
  2563 	}
  2559 	}
  2564 
  2560 
  2565 	_cur_town_ctr = 0;
  2561 	_cur_town_ctr = 0;
  2566 	_cur_town_iter = 0;
  2562 	_cur_town_iter = 0;
  2567 	_total_towns = 0;
  2563 	_total_towns = 0;
  2568 	_town_sort_dirty = true;
       
  2569 }
  2564 }
  2570 
  2565 
  2571 static CommandCost TerraformTile_Town(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
  2566 static CommandCost TerraformTile_Town(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
  2572 {
  2567 {
  2573 	if (AutoslopeEnabled()) {
  2568 	if (AutoslopeEnabled()) {
  2734 		_cur_town_ctr = 0;
  2729 		_cur_town_ctr = 0;
  2735 }
  2730 }
  2736 
  2731 
  2737 void AfterLoadTown()
  2732 void AfterLoadTown()
  2738 {
  2733 {
  2739 	_town_sort_dirty = true;
       
  2740 
       
  2741 	Town *t;
  2734 	Town *t;
  2742 	FOR_ALL_TOWNS(t) t->InitializeLayout();
  2735 	FOR_ALL_TOWNS(t) t->InitializeLayout();
  2743 }
  2736 }
  2744 
  2737 
  2745 extern const ChunkHandler _town_chunk_handlers[] = {
  2738 extern const ChunkHandler _town_chunk_handlers[] = {