--- a/disaster_cmd.c Wed Jan 17 00:51:04 2007 +0000
+++ b/disaster_cmd.c Wed Jan 17 01:02:51 2007 +0000
@@ -477,7 +477,7 @@
TileIndex tile;
uint ind;
- x = v->x_pos - 15 * TILE_SIZE;
+ x = v->x_pos + (15 * TILE_SIZE);
y = v->y_pos;
if ( (uint)x > MapMaxX() * TILE_SIZE - 1)
@@ -672,7 +672,7 @@
tile = v->tile + TileOffsByDiagDir(DirToDiagDir(v->direction));
if (IsValidTile(tile) &&
- (r=GetTileTrackStatus(tile,TRANSPORT_WATER),(byte)(r+(r >> 8)) == 0x3F) &&
+ (r=GetTileTrackStatus(tile,TRANSPORT_WATER),(byte)(r|(r >> 8)) == 0x3F) &&
!CHANCE16(1,90)) {
GetNewVehiclePos(v, &gp);
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
--- a/misc.c Wed Jan 17 00:51:04 2007 +0000
+++ b/misc.c Wed Jan 17 01:02:51 2007 +0000
@@ -266,16 +266,18 @@
int FindFirstBit(uint32 value)
{
- // This is much faster than the one that was before here.
- // Created by Darkvater.. blame him if it is wrong ;)
- // Btw, the macro FINDFIRSTBIT is better to use when your value is
- // not more than 128.
+ // The macro FIND_FIRST_BIT is better to use when your value is
+ // not more than 128.
byte i = 0;
- if (value & 0xffff0000) { value >>= 16; i += 16; }
- if (value & 0x0000ff00) { value >>= 8; i += 8; }
- if (value & 0x000000f0) { value >>= 4; i += 4; }
- if (value & 0x0000000c) { value >>= 2; i += 2; }
- if (value & 0x00000002) { i += 1; }
+
+ if (value == 0) return 0;
+
+ if ((value & 0x0000ffff) == 0) { value >>= 16; i += 16; }
+ if ((value & 0x000000ff) == 0) { value >>= 8; i += 8; }
+ if ((value & 0x0000000f) == 0) { value >>= 4; i += 4; }
+ if ((value & 0x00000003) == 0) { value >>= 2; i += 2; }
+ if ((value & 0x00000001) == 0) { i += 1; }
+
return i;
}
--- a/openttd.c Wed Jan 17 00:51:04 2007 +0000
+++ b/openttd.c Wed Jan 17 01:02:51 2007 +0000
@@ -253,9 +253,15 @@
_industry_sort = NULL;
}
-static void UnInitializeDynamicVariables(void)
+
+static void UnInitializeGame(void)
{
- /* Dynamic stuff needs to be free'd somewhere... */
+ UnInitWindowSystem();
+
+ /* Uninitialize airport state machines */
+ UnInitializeAirports();
+
+ /* Uninitialize variables that are allocated dynamically */
CleanPool(&_Town_pool);
CleanPool(&_Industry_pool);
CleanPool(&_Station_pool);
@@ -265,11 +271,6 @@
free((void*)_town_sort);
free((void*)_industry_sort);
-}
-
-static void UnInitializeGame(void)
-{
- UnInitWindowSystem();
free(_config_file);
}
@@ -518,18 +519,14 @@
SaveToConfig();
SaveToHighScore();
- // uninitialize airport state machines
- UnInitializeAirports();
-
- /* uninitialize variables that are allocated dynamic */
- UnInitializeDynamicVariables();
+ /* Reset windowing system and free config file */
+ UnInitializeGame();
/* stop the AI */
AI_Uninitialize();
/* Close all and any open filehandles */
FioCloseAll();
- UnInitializeGame();
return 0;
}
--- a/station_gui.c Wed Jan 17 00:51:04 2007 +0000
+++ b/station_gui.c Wed Jan 17 01:02:51 2007 +0000
@@ -264,6 +264,8 @@
const PlayerID owner = w->window_number;
static byte facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK;
static uint16 cargo_filter = CARGO_ALL_SELECTED;
+ static Listing station_sort = {0, 0};
+
plstations_d *sl = &WP(w, plstations_d);
switch (e->event) {
@@ -281,7 +283,8 @@
sl->sort_list = NULL;
sl->flags = SL_REBUILD;
- sl->sort_type = 0;
+ sl->sort_type = station_sort.criteria;
+ if (station_sort.order) sl->flags |= SL_ORDER;
sl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
break;
}
@@ -434,6 +437,7 @@
}
case STATIONLIST_WIDGET_SORTBY: /*flip sorting method asc/desc*/
TOGGLEBIT(sl->flags, 0); //DESC-flag
+ station_sort.order = GB(sl->flags, 0, 1);
sl->flags |= SL_RESORT;
w->flags4 |= 5 << WF_TIMEOUT_SHL;
LowerWindowWidget(w, STATIONLIST_WIDGET_SORTBY);
@@ -469,6 +473,7 @@
if (sl->sort_type != e->we.dropdown.index) {
// value has changed -> resort
sl->sort_type = e->we.dropdown.index;
+ station_sort.criteria = sl->sort_type;
sl->flags |= SL_RESORT;
}
SetWindowDirty(w);
--- a/window.c Wed Jan 17 00:51:04 2007 +0000
+++ b/window.c Wed Jan 17 01:02:51 2007 +0000
@@ -876,12 +876,19 @@
void UnInitWindowSystem(void)
{
Window* const *wz;
- // delete all malloced widgets
+
+restart_search:
+ /* Delete all windows, reset z-array.
+ *When we find the window to delete, we need to restart the search
+ * as deleting this window could cascade in deleting (many) others
+ * anywhere in the z-array. We call DeleteWindow() so that it can properly
+ * release own alloc'd memory, which otherwise could result in memleaks */
FOR_ALL_WINDOWS(wz) {
- free((*wz)->widget);
- (*wz)->widget = NULL;
- (*wz)->widget_count = 0;
+ DeleteWindow(*wz);
+ goto restart_search;
}
+
+ assert(_last_z_window == _z_windows);
}
void ResetWindowSystem(void)