(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
--- a/docs/landscape.html Thu Apr 17 08:40:01 2008 +0000
+++ b/docs/landscape.html Fri Apr 18 23:33:51 2008 +0000
@@ -899,6 +899,7 @@
<li>m6 bits 5..3: the station type (rail, airport, truck, bus, oilrig, dock, buoy)</li>
<li>m6 bit 2: 1 when a drive through road stop is built over a town owned road, otherwise 0</li>
<li>m6 bits 1..0 : <a href="#tropic_zone">Tropic zone definition</a></li>
+ <li>m7: animation frame</li>
</ul>
</td>
</tr>
--- a/docs/landscape_grid.html Thu Apr 17 08:40:01 2008 +0000
+++ b/docs/landscape_grid.html Fri Apr 18 23:33:51 2008 +0000
@@ -198,7 +198,7 @@
<td class="bits">XXXX XXXX</td>
<td class="bits">XXXX XXXX</td>
<td class="bits"><span class="free">OO</span>XX X<span class="free">O</span>XX</td>
- <td class="bits"><span class="free">OOOO OOOO</span></td>
+ <td class="bits">XXXX XXXX</td>
</tr>
<tr>
<td class="caption">road stop</td>
--- a/projects/generate Thu Apr 17 08:40:01 2008 +0000
+++ b/projects/generate Fri Apr 18 23:33:51 2008 +0000
@@ -55,6 +55,15 @@
done
}
+grep '\.h' "$ROOT_DIR/source.list" | grep -v '../objs/langs/table/strings.h' | sort > tmp.headers.source.list
+find "$ROOT_DIR/src" -iname "*.h*" -and -not -iname "*svn*" -and -not -iname "*.hpp.sq" | sed "s@$ROOT_DIR/src/@@" | sort > tmp.headers.src
+if [ -n "`diff tmp.headers.source.list tmp.headers.src`" ]; then
+ echo "The following headers are missing in source.list and not in /src/ or vice versa."
+ diff tmp.headers.source.list tmp.headers.src | grep '[<>]' | sort
+ echo ""
+fi
+rm tmp.headers.*
+
load_main_data() {
# Read the source.list and process it
RES="`cat $1 | tr '\r' '\n' | awk '
--- a/projects/generate.vbs Thu Apr 17 08:40:01 2008 +0000
+++ b/projects/generate.vbs Fri Apr 18 23:33:51 2008 +0000
@@ -46,6 +46,85 @@
file.Close
End Sub
+Sub get_files(srcdir, dir, list)
+ Dim file, filename
+ Dim rekeep, reskip
+
+ ' pattern for files to keep
+ Set rekeep = New RegExp
+ rekeep.Pattern = "\.h"
+ rekeep.Global = True
+
+ ' pattern for files to exclude
+ Set reskip = New RegExp
+ reskip.Pattern = "\.svn|\.hpp\.sq"
+ reskip.Global = True
+
+ For Each file in dir.Files
+ filename = Replace(file.path, srcdir, "") ' Remove */src/
+ filename = Replace(filename, "\", "/") ' Replace separators
+ If rekeep.Test(filename) And Not reskip.Test(filename) Then
+ list.Add filename, filename
+ End If
+ Next
+End Sub
+
+Sub get_dir_files(srcdir, dir, list)
+ Dim folder
+ ' Get files
+ get_files srcdir, dir, list
+
+ ' Recurse in subfolders
+ For Each folder in dir.SubFolders
+ get_dir_files srcdir, folder, list
+ Next
+End Sub
+
+Sub headers_check(filename, dir)
+ Dim source_list_headers, src_dir_headers, regexp, line, file, str
+
+ ' Define regexp for source.list parsing
+ Set regexp = New RegExp
+ regexp.Pattern = "\.h"
+ regexp.Global = True
+
+ ' Parse source.list and store headers in a dictionary
+ Set source_list_headers = CreateObject("Scripting.Dictionary")
+ Set file = FSO.OpenTextFile(filename, 1, 0, 0)
+ While Not file.AtEndOfStream
+ line = Replace(file.ReadLine, Chr(9), "") ' Remove tabs
+ If Len(line) > 0 And regexp.Test(line) And line <> "../objs/langs/table/strings.h" Then
+ source_list_headers.Add line, line
+ End If
+ Wend
+ file.Close()
+
+ ' Get header files in /src/
+ Set src_dir_headers = CreateObject("Scripting.Dictionary")
+ get_dir_files dir, FSO.GetFolder(dir), src_dir_headers
+
+ ' Finding files in source.list but not in /src/
+ For Each line In source_list_headers
+ If Not src_dir_headers.Exists(line) Then
+ str = str & "< " & line & vbCrLf
+ End If
+ Next
+
+ ' Finding files in /src/ but not in source.list
+ For Each line In src_dir_headers
+ If Not source_list_headers.Exists(line) Then
+ str = str & "> " & line & vbCrLf
+ End If
+ Next
+
+ ' Display the missing files if any
+ If str <> "" Then
+ str = "The following headers are missing in source.list and not in /src/ or vice versa." _
+ & vbCrLf & str
+ WScript.Echo str
+ End If
+End Sub
+
Function load_main_data(filename)
Dim res, file, line, deep, skip, first_time
res = ""
@@ -171,6 +250,7 @@
End If
safety_check ROOT_DIR & "/source.list"
+headers_check ROOT_DIR & "/source.list", ROOT_DIR & "\src\" ' Backslashes needed for DoFiles
Dim openttd
openttd = load_main_data(ROOT_DIR &"/source.list")
--- a/projects/openttd_vs80.vcproj Thu Apr 17 08:40:01 2008 +0000
+++ b/projects/openttd_vs80.vcproj Fri Apr 18 23:33:51 2008 +0000
@@ -492,6 +492,14 @@
>
</File>
<File
+ RelativePath=".\..\src\cheat.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\..\src\cheat_gui.cpp"
+ >
+ </File>
+ <File
RelativePath=".\..\src\command.cpp"
>
</File>
@@ -720,6 +728,10 @@
>
</File>
<File
+ RelativePath=".\..\src\statusbar_gui.cpp"
+ >
+ </File>
+ <File
RelativePath=".\..\src\string.cpp"
>
</File>
@@ -876,6 +888,14 @@
>
</File>
<File
+ RelativePath=".\..\src\cheat_func.h"
+ >
+ </File>
+ <File
+ RelativePath=".\..\src\cheat_type.h"
+ >
+ </File>
+ <File
RelativePath=".\..\src\currency.h"
>
</File>
@@ -896,7 +916,15 @@
>
</File>
<File
- RelativePath=".\..\src\depot.h"
+ RelativePath=".\..\src\depot_base.h"
+ >
+ </File>
+ <File
+ RelativePath=".\..\src\depot_func.h"
+ >
+ </File>
+ <File
+ RelativePath=".\..\src\depot_map.h"
>
</File>
<File
@@ -1156,10 +1184,6 @@
>
</File>
<File
- RelativePath=".\..\src\newgrf_string_type.h"
- >
- </File>
- <File
RelativePath=".\..\src\newgrf_text.h"
>
</File>
@@ -1176,6 +1200,10 @@
>
</File>
<File
+ RelativePath=".\..\src\news_gui.h"
+ >
+ </File>
+ <File
RelativePath=".\..\src\news_type.h"
>
</File>
@@ -2804,6 +2832,10 @@
>
</File>
<File
+ RelativePath=".\..\src\misc\smallvec.h"
+ >
+ </File>
+ <File
RelativePath=".\..\src\misc\str.hpp"
>
</File>
--- a/projects/openttd_vs90.vcproj Thu Apr 17 08:40:01 2008 +0000
+++ b/projects/openttd_vs90.vcproj Fri Apr 18 23:33:51 2008 +0000
@@ -489,6 +489,14 @@
>
</File>
<File
+ RelativePath=".\..\src\cheat.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\..\src\cheat_gui.cpp"
+ >
+ </File>
+ <File
RelativePath=".\..\src\command.cpp"
>
</File>
@@ -717,6 +725,10 @@
>
</File>
<File
+ RelativePath=".\..\src\statusbar_gui.cpp"
+ >
+ </File>
+ <File
RelativePath=".\..\src\string.cpp"
>
</File>
@@ -873,6 +885,14 @@
>
</File>
<File
+ RelativePath=".\..\src\cheat_func.h"
+ >
+ </File>
+ <File
+ RelativePath=".\..\src\cheat_type.h"
+ >
+ </File>
+ <File
RelativePath=".\..\src\currency.h"
>
</File>
@@ -893,7 +913,15 @@
>
</File>
<File
- RelativePath=".\..\src\depot.h"
+ RelativePath=".\..\src\depot_base.h"
+ >
+ </File>
+ <File
+ RelativePath=".\..\src\depot_func.h"
+ >
+ </File>
+ <File
+ RelativePath=".\..\src\depot_map.h"
>
</File>
<File
@@ -1153,10 +1181,6 @@
>
</File>
<File
- RelativePath=".\..\src\newgrf_string_type.h"
- >
- </File>
- <File
RelativePath=".\..\src\newgrf_text.h"
>
</File>
@@ -1173,6 +1197,10 @@
>
</File>
<File
+ RelativePath=".\..\src\news_gui.h"
+ >
+ </File>
+ <File
RelativePath=".\..\src\news_type.h"
>
</File>
@@ -2801,6 +2829,10 @@
>
</File>
<File
+ RelativePath=".\..\src\misc\smallvec.h"
+ >
+ </File>
+ <File
RelativePath=".\..\src\misc\str.hpp"
>
</File>
--- a/source.list Thu Apr 17 08:40:01 2008 +0000
+++ b/source.list Fri Apr 18 23:33:51 2008 +0000
@@ -9,6 +9,8 @@
callback_table.cpp
cargopacket.cpp
cargotype.cpp
+cheat.cpp
+cheat_gui.cpp
command.cpp
console.cpp
console_cmds.cpp
@@ -73,6 +75,7 @@
sound.cpp
spritecache.cpp
station.cpp
+statusbar_gui.cpp
string.cpp
strings.cpp
squirrel.cpp
@@ -140,12 +143,16 @@
command_func.h
command_type.h
console.h
+cheat_func.h
+cheat_type.h
currency.h
date_func.h
date_type.h
debug.h
video/dedicated_v.h
-depot.h
+depot_base.h
+depot_func.h
+depot_map.h
depot_type.h
direction_func.h
direction_type.h
@@ -210,11 +217,11 @@
newgrf_spritegroup.h
newgrf_station.h
newgrf_storage.h
-newgrf_string_type.h
newgrf_text.h
newgrf_town.h
newgrf_townname.h
news_func.h
+news_gui.h
news_type.h
npf.h
music/null_m.h
@@ -654,6 +661,7 @@
misc/dbg_helpers.h
misc/fixedsizearray.hpp
misc/hashtable.hpp
+misc/smallvec.h
misc/str.hpp
misc/strapi.hpp
--- a/src/ai/api/ai_order.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/ai/api/ai_order.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -7,7 +7,7 @@
#include "ai_vehicle.hpp"
#include "../../command_type.h"
#include "../../vehicle_base.h"
-#include "../../depot.h"
+#include "../../depot_base.h"
#include "../../landscape.h"
#include "../../rail_map.h"
#include "../../road_map.h"
--- a/src/ai/api/ai_tunnel.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/ai/api/ai_tunnel.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -8,7 +8,7 @@
#include "../../tunnel_map.h"
#include "../../road_type.h"
#include "../../command_func.h"
-#include "../../variables.h"
+#include "../../tunnelbridge.h"
/* static */ bool AITunnel::IsTunnelTile(TileIndex tile)
{
--- a/src/ai/api/ai_vehicle.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/ai/api/ai_vehicle.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -6,7 +6,6 @@
#include "ai_engine.hpp"
#include "ai_cargo.hpp"
#include "ai_order.hpp"
-#include "../../depot.h"
#include "../../player_func.h"
#include "../../aircraft.h"
#include "../../string_func.h"
--- a/src/aircraft_cmd.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/aircraft_cmd.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -10,7 +10,7 @@
#include "landscape.h"
#include "station_map.h"
#include "timetable.h"
-#include "depot.h"
+#include "depot_func.h"
#include "news_func.h"
#include "aircraft.h"
#include "airport.h"
@@ -29,6 +29,7 @@
#include "sound_func.h"
#include "functions.h"
#include "variables.h"
+#include "cheat_func.h"
#include "autoreplace_func.h"
#include "autoreplace_gui.h"
#include "gfx_func.h"
--- a/src/aircraft_gui.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/aircraft_gui.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -7,7 +7,6 @@
#include "aircraft.h"
#include "debug.h"
#include "gui.h"
-#include "depot.h"
#include "vehicle_gui.h"
#include "newgrf_engine.h"
#include "strings_func.h"
--- a/src/airport_gui.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/airport_gui.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -10,7 +10,6 @@
#include "terraform_gui.h"
#include "command_func.h"
#include "airport.h"
-#include "depot.h"
#include "sound_func.h"
#include "window_func.h"
#include "settings_type.h"
@@ -18,6 +17,7 @@
#include "gfx_func.h"
#include "player_func.h"
#include "order_func.h"
+#include "station_type.h"
#include "table/sprites.h"
#include "table/strings.h"
--- a/src/autoreplace_cmd.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/autoreplace_cmd.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -8,7 +8,6 @@
#include "player_func.h"
#include "debug.h"
#include "vehicle_gui.h"
-#include "depot.h"
#include "train.h"
#include "aircraft.h"
#include "cargotype.h"
--- a/src/autoslope.h Thu Apr 17 08:40:01 2008 +0000
+++ b/src/autoslope.h Fri Apr 18 23:33:51 2008 +0000
@@ -5,9 +5,9 @@
#ifndef AUTOSLOPE_H
#define AUTOSLOPE_H
-#include "depot.h"
#include "settings_type.h"
#include "player_func.h"
+#include "depot_func.h"
/**
* Autoslope check for tiles with an entrance on an edge.
--- a/src/blitter/32bpp_base.hpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/blitter/32bpp_base.hpp Fri Apr 18 23:33:51 2008 +0000
@@ -104,7 +104,7 @@
}
/**
- * Make a colour grey-based.
+ * Make a colour grey - based.
* @param colour the colour to make grey.
* @return the new colour, now grey.
*/
--- a/src/build_vehicle_gui.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/build_vehicle_gui.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -14,7 +14,6 @@
#include "textbuf_gui.h"
#include "command_func.h"
#include "player_func.h"
-#include "depot.h"
#include "airport.h"
#include "vehicle_gui.h"
#include "newgrf_engine.h"
--- a/src/cargotype.h Thu Apr 17 08:40:01 2008 +0000
+++ b/src/cargotype.h Fri Apr 18 23:33:51 2008 +0000
@@ -7,7 +7,7 @@
#include "cargo_type.h"
#include "gfx_type.h"
-#include "newgrf_string_type.h"
+#include "strings_type.h"
typedef uint32 CargoLabel;
@@ -36,11 +36,11 @@
uint16 multipliertowngrowth;
uint8 callback_mask;
- GRFMappedStringID name;
- GRFMappedStringID name_single;
- GRFMappedStringID units_volume;
- GRFMappedStringID quantifier;
- GRFMappedStringID abbrev;
+ StringID name;
+ StringID name_single;
+ StringID units_volume;
+ StringID quantifier;
+ StringID abbrev;
SpriteID sprite;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/cheat.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -0,0 +1,57 @@
+/* $Id$ */
+
+/** @file misc.cpp */
+
+#include "stdafx.h"
+#include "saveload.h"
+#include "cheat_type.h"
+
+Cheats _cheats;
+
+void InitializeCheats()
+{
+ memset(&_cheats, 0, sizeof(Cheats));
+}
+
+static void Save_CHTS()
+{
+ /* Cannot use lengthof because _cheats is of type Cheats, not Cheat */
+ byte count = sizeof(_cheats) / sizeof(Cheat);
+ Cheat *cht = (Cheat*) &_cheats;
+ Cheat *cht_last = &cht[count];
+
+ SlSetLength(count * 2);
+ for (; cht != cht_last; cht++) {
+ SlWriteByte(cht->been_used);
+ SlWriteByte(cht->value);
+ }
+}
+
+static void Load_CHTS()
+{
+ Cheat *cht = (Cheat*)&_cheats;
+ uint count = SlGetFieldLength() / 2;
+
+ for (uint i = 0; i < count; i++) {
+ cht[i].been_used = (SlReadByte() != 0);
+ cht[i].value = (SlReadByte() != 0);
+ }
+}
+
+bool CheatHasBeenUsed()
+{
+ /* Cannot use lengthof because _cheats is of type Cheats, not Cheat */
+ const Cheat* cht = (Cheat*)&_cheats;
+ const Cheat* cht_last = &cht[sizeof(_cheats) / sizeof(Cheat)];
+
+ for (; cht != cht_last; cht++) {
+ if (cht->been_used) return true;
+ }
+
+ return false;
+}
+
+
+extern const ChunkHandler _cheat_chunk_handlers[] = {
+ { 'CHTS', Save_CHTS, Load_CHTS, CH_RIFF | CH_LAST}
+};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/cheat_func.h Fri Apr 18 23:33:51 2008 +0000
@@ -0,0 +1,20 @@
+/* $Id$ */
+
+/** @file cheat_func.h Functions related to cheating. */
+
+#ifndef CHEAT_FUNC_H
+#define CHEAT_FUNC_H
+
+#include "cheat_type.h"
+
+extern Cheats _cheats;
+
+void ShowCheatWindow();
+
+/**
+ * Return true if any cheat has been used, false otherwise
+ * @return has a cheat been used?
+ */
+bool CheatHasBeenUsed();
+
+#endif /* CHEAT_FUNC_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/cheat_gui.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -0,0 +1,233 @@
+/* $Id$ */
+
+/** @file misc_gui.cpp */
+
+#include "stdafx.h"
+#include "openttd.h"
+#include "command_func.h"
+#include "cheat_func.h"
+#include "player_base.h"
+#include "player_func.h"
+#include "gfx_func.h"
+#include "date_func.h"
+#include "saveload.h"
+#include "window_gui.h"
+#include "newgrf.h"
+#include "settings_type.h"
+#include "strings_func.h"
+#include "window_func.h"
+#include "rail_gui.h"
+#include "gui.h"
+#include "player_gui.h"
+
+#include "table/strings.h"
+#include "table/sprites.h"
+
+
+/**
+ * The 'amount' to cheat with.
+ * This variable is semantically a constant value, but because the cheat
+ * code requires to be able to write to the variable it is not constified.
+ */
+static int32 _money_cheat_amount = 10000000;
+
+static int32 ClickMoneyCheat(int32 p1, int32 p2)
+{
+ DoCommandP(0, (uint32)(p2 * _money_cheat_amount), 0, NULL, CMD_MONEY_CHEAT);
+ return _money_cheat_amount;
+}
+
+/**
+ * @param p1 player to set to
+ * @param p2 is -1 or +1 (down/up)
+ */
+static int32 ClickChangePlayerCheat(int32 p1, int32 p2)
+{
+ while (IsValidPlayer((PlayerID)p1)) {
+ if (_players[p1].is_active) {
+ SetLocalPlayer((PlayerID)p1);
+
+ MarkWholeScreenDirty();
+ return _local_player;
+ }
+ p1 += p2;
+ }
+
+ return _local_player;
+}
+
+/**
+ * @param p1 -1 or +1 (down/up)
+ * @param p2 unused
+ */
+static int32 ClickChangeClimateCheat(int32 p1, int32 p2)
+{
+ if (p1 == -1) p1 = 3;
+ if (p1 == 4) p1 = 0;
+ _opt.landscape = p1;
+ ReloadNewGRFData();
+ return _opt.landscape;
+}
+
+extern void EnginesMonthlyLoop();
+
+/**
+ * @param p1 unused
+ * @param p2 1 (increase) or -1 (decrease)
+ */
+static int32 ClickChangeDateCheat(int32 p1, int32 p2)
+{
+ YearMonthDay ymd;
+ ConvertDateToYMD(_date, &ymd);
+
+ if ((ymd.year == MIN_YEAR && p2 == -1) || (ymd.year == MAX_YEAR && p2 == 1)) return _cur_year;
+
+ SetDate(ConvertYMDToDate(_cur_year + p2, ymd.month, ymd.day));
+ EnginesMonthlyLoop();
+ SetWindowDirty(FindWindowById(WC_STATUS_BAR, 0));
+ ResetSignalVariant();
+ return _cur_year;
+}
+
+typedef int32 CheckButtonClick(int32, int32);
+
+struct CheatEntry {
+ VarType type; ///< type of selector
+ StringID str; ///< string with descriptive text
+ void *variable; ///< pointer to the variable
+ bool *been_used; ///< has this cheat been used before?
+ CheckButtonClick *proc;///< procedure
+};
+
+static const CheatEntry _cheats_ui[] = {
+ {SLE_INT32, STR_CHEAT_MONEY, &_money_cheat_amount, &_cheats.money.been_used, &ClickMoneyCheat },
+ {SLE_UINT8, STR_CHEAT_CHANGE_PLAYER, &_local_player, &_cheats.switch_player.been_used, &ClickChangePlayerCheat },
+ {SLE_BOOL, STR_CHEAT_EXTRA_DYNAMITE, &_cheats.magic_bulldozer.value, &_cheats.magic_bulldozer.been_used, NULL },
+ {SLE_BOOL, STR_CHEAT_CROSSINGTUNNELS, &_cheats.crossing_tunnels.value, &_cheats.crossing_tunnels.been_used, NULL },
+ {SLE_BOOL, STR_CHEAT_BUILD_IN_PAUSE, &_cheats.build_in_pause.value, &_cheats.build_in_pause.been_used, NULL },
+ {SLE_BOOL, STR_CHEAT_NO_JETCRASH, &_cheats.no_jetcrash.value, &_cheats.no_jetcrash.been_used, NULL },
+ {SLE_BOOL, STR_CHEAT_SETUP_PROD, &_cheats.setup_prod.value, &_cheats.setup_prod.been_used, NULL },
+ {SLE_UINT8, STR_CHEAT_SWITCH_CLIMATE, &_opt.landscape, &_cheats.switch_climate.been_used, &ClickChangeClimateCheat},
+ {SLE_INT32, STR_CHEAT_CHANGE_DATE, &_cur_year, &_cheats.change_date.been_used, &ClickChangeDateCheat },
+};
+
+
+static const Widget _cheat_widgets[] = {
+{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
+{ WWT_CAPTION, RESIZE_NONE, 14, 11, 399, 0, 13, STR_CHEATS, STR_018C_WINDOW_TITLE_DRAG_THIS},
+{ WWT_PANEL, RESIZE_NONE, 14, 0, 399, 14, 169, 0x0, STR_NULL},
+{ WWT_PANEL, RESIZE_NONE, 14, 0, 399, 14, 169, 0x0, STR_CHEATS_TIP},
+{ WIDGETS_END},
+};
+
+static void CheatsWndProc(Window *w, WindowEvent *e)
+{
+ switch (e->event) {
+ case WE_PAINT: {
+ int clk = WP(w, def_d).data_1;
+
+ DrawWindowWidgets(w);
+ DrawStringMultiCenter(200, 25, STR_CHEATS_WARNING, w->width - 50);
+
+ for (int i = 0, x = 0, y = 45; i != lengthof(_cheats_ui); i++) {
+ const CheatEntry *ce = &_cheats_ui[i];
+
+ DrawSprite((*ce->been_used) ? SPR_BOX_CHECKED : SPR_BOX_EMPTY, PAL_NONE, x + 5, y + 2);
+
+ switch (ce->type) {
+ case SLE_BOOL: {
+ bool on = (*(bool*)ce->variable);
+
+ DrawFrameRect(x + 20, y + 1, x + 30 + 9, y + 9, on ? 6 : 4, on ? FR_LOWERED : FR_NONE);
+ SetDParam(0, on ? STR_CONFIG_PATCHES_ON : STR_CONFIG_PATCHES_OFF);
+ } break;
+
+ default: {
+ int32 val = (int32)ReadValue(ce->variable, ce->type);
+ char buf[512];
+
+ /* Draw [<][>] boxes for settings of an integer-type */
+ DrawArrowButtons(x + 20, y, 3, clk - (i * 2), true, true);
+
+ switch (ce->str) {
+ /* Display date for change date cheat */
+ case STR_CHEAT_CHANGE_DATE: SetDParam(0, _date); break;
+
+ /* Draw colored flag for change player cheat */
+ case STR_CHEAT_CHANGE_PLAYER:
+ SetDParam(0, val);
+ GetString(buf, STR_CHEAT_CHANGE_PLAYER, lastof(buf));
+ DrawPlayerIcon(_current_player, 60 + GetStringBoundingBox(buf).width, y + 2);
+ break;
+
+ /* Set correct string for switch climate cheat */
+ case STR_CHEAT_SWITCH_CLIMATE: val += STR_TEMPERATE_LANDSCAPE;
+
+ /* Fallthrough */
+ default: SetDParam(0, val);
+ }
+ } break;
+ }
+
+ DrawString(50, y + 1, ce->str, TC_FROMSTRING);
+
+ y += 12;
+ }
+ break;
+ }
+
+ case WE_CLICK: {
+ uint btn = (e->we.click.pt.y - 46) / 12;
+ uint x = e->we.click.pt.x;
+
+ /* Not clicking a button? */
+ if (!IsInsideMM(x, 20, 40) || btn >= lengthof(_cheats_ui)) break;
+
+ const CheatEntry *ce = &_cheats_ui[btn];
+ int value = (int32)ReadValue(ce->variable, ce->type);
+ int oldvalue = value;
+
+ *ce->been_used = true;
+
+ switch (ce->type) {
+ case SLE_BOOL:
+ value ^= 1;
+ if (ce->proc != NULL) ce->proc(value, 0);
+ break;
+
+ default:
+ /* Take whatever the function returns */
+ value = ce->proc(value + ((x >= 30) ? 1 : -1), (x >= 30) ? 1 : -1);
+
+ if (value != oldvalue) WP(w, def_d).data_1 = btn * 2 + 1 + ((x >= 30) ? 1 : 0);
+ break;
+ }
+
+ if (value != oldvalue) WriteValue(ce->variable, ce->type, (int64)value);
+
+ w->flags4 |= 5 << WF_TIMEOUT_SHL;
+
+ SetWindowDirty(w);
+ } break;
+
+ case WE_TIMEOUT:
+ WP(w, def_d).data_1 = 0;
+ SetWindowDirty(w);
+ break;
+ }
+}
+
+static const WindowDesc _cheats_desc = {
+ 240, 22, 400, 170, 400, 170,
+ WC_CHEATS, WC_NONE,
+ WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
+ _cheat_widgets,
+ CheatsWndProc
+};
+
+
+void ShowCheatWindow()
+{
+ DeleteWindowById(WC_CHEATS, 0);
+ AllocateWindowDesc(&_cheats_desc);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/cheat_type.h Fri Apr 18 23:33:51 2008 +0000
@@ -0,0 +1,36 @@
+/* $Id$ */
+
+/** @file cheat_type.h Types related to cheating. */
+
+#ifndef CHEAT_TYPE_H
+#define CHEAT_TYPE_H
+
+/**
+ * Info about each of the cheats.
+ */
+struct Cheat {
+ bool been_used; ///< has this cheat been used before?
+ bool value; ///< tells if the bool cheat is active or not
+};
+
+/**
+ * WARNING! Do _not_ remove entries in Cheats struct or change the order
+ * of the existing ones! Would break downward compatibility.
+ * Only add new entries at the end of the struct!
+ */
+struct Cheats {
+ Cheat magic_bulldozer; ///< dynamite industries, unmovables
+ Cheat switch_player; ///< change to another player
+ Cheat money; ///< get rich or poor
+ Cheat crossing_tunnels; ///< allow tunnels that cross each other
+ Cheat build_in_pause; ///< build while in pause mode
+ Cheat no_jetcrash; ///< no jet will crash on small airports anymore
+ Cheat switch_climate; ///< change the climate of the map
+ Cheat change_date; ///< changes date ingame
+ Cheat setup_prod; ///< setup raw-material production in game
+ Cheat dummy; ///< empty cheat (enable running el-engines on normal rail)
+};
+
+extern Cheats _cheats;
+
+#endif /* CHEAT_TYPE_H */
--- a/src/core/alloc_func.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/core/alloc_func.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -9,7 +9,7 @@
* Function to exit with an error message after malloc() or calloc() have failed
* @param size number of bytes we tried to allocate
*/
-void MallocError(size_t size)
+void NORETURN MallocError(size_t size)
{
error("Out of memory. Cannot allocate %i bytes", size);
}
@@ -18,7 +18,7 @@
* Function to exit with an error message after realloc() have failed
* @param size number of bytes we tried to allocate
*/
-void ReallocError(size_t size)
+void NORETURN ReallocError(size_t size)
{
error("Out of memory. Cannot reallocate %i bytes", size);
}
--- a/src/core/alloc_func.hpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/core/alloc_func.hpp Fri Apr 18 23:33:51 2008 +0000
@@ -11,8 +11,8 @@
* duplicated in each object file making the final
* binary needlessly large.
*/
-void MallocError(size_t size);
-void ReallocError(size_t size);
+void NORETURN MallocError(size_t size);
+void NORETURN ReallocError(size_t size);
/**
* Simplified allocation function that allocates the specified number of
--- a/src/core/alloc_type.hpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/core/alloc_type.hpp Fri Apr 18 23:33:51 2008 +0000
@@ -88,6 +88,9 @@
* Memory release for a single class instance.
* @param ptr the memory to free.
* @param size the amount of allocated memory (unused).
+ *
+ * @warning The value of the \a size parameter can only be trusted for
+ * classes that have their own (virtual) destructor method.
*/
void operator delete(void *ptr, size_t size) { free(ptr); }
@@ -95,6 +98,9 @@
* Memory release for an array of class instances.
* @param ptr the memory to free.
* @param size the amount of allocated memory (unused).
+ *
+ * @warning The value of the \a size parameter can only be trusted for
+ * classes that have their own (virtual) destructor method.
*/
void operator delete[](void *ptr, size_t size) { free(ptr); }
};
--- a/src/core/enum_type.hpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/core/enum_type.hpp Fri Apr 18 23:33:51 2008 +0000
@@ -66,7 +66,7 @@
/** In some cases we use byte or uint16 to store values that are defined as enum. It is
* necessary in order to control the sizeof() such values. Some compilers make enum
* the same size as int (4 or 8 bytes instead of 1 or 2). As a consequence the strict
- * compiler type-checking causes errors like:
+ * compiler type - checking causes errors like:
* 'HasPowerOnRail' : cannot convert parameter 1 from 'byte' to 'RailType' when
* u->u.rail.railtype is passed as argument or type RailType. In such cases it is better
* to teach the compiler that u->u.rail.railtype is to be treated as RailType. */
--- a/src/depot.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/depot.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -4,7 +4,7 @@
#include "stdafx.h"
#include "openttd.h"
-#include "depot.h"
+#include "depot_base.h"
#include "landscape.h"
#include "saveload.h"
#include "order_func.h"
--- a/src/depot.h Thu Apr 17 08:40:01 2008 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,100 +0,0 @@
-/* $Id$ */
-
-/** @file depot.h Header files for depots (not hangars) */
-
-#ifndef DEPOT_H
-#define DEPOT_H
-
-#include "direction_type.h"
-#include "depot_type.h"
-#include "oldpool.h"
-#include "road_map.h"
-#include "rail_map.h"
-#include "water_map.h"
-#include "station_map.h"
-
-DECLARE_OLD_POOL(Depot, Depot, 3, 8000)
-
-struct Depot : PoolItem<Depot, DepotID, &_Depot_pool> {
- TileIndex xy;
- TownID town_index;
-
- Depot(TileIndex xy = 0) : xy(xy) {}
- ~Depot();
-
- inline bool IsValid() const { return this->xy != 0; }
-};
-
-static inline bool IsValidDepotID(DepotID index)
-{
- return index < GetDepotPoolSize() && GetDepot(index)->IsValid();
-}
-
-void ShowDepotWindow(TileIndex tile, VehicleType type);
-
-#define FOR_ALL_DEPOTS_FROM(d, start) for (d = GetDepot(start); d != NULL; d = (d->index + 1U < GetDepotPoolSize()) ? GetDepot(d->index + 1U) : NULL) if (d->IsValid())
-#define FOR_ALL_DEPOTS(d) FOR_ALL_DEPOTS_FROM(d, 0)
-
-/**
- * Check if a tile is a depot of the given type.
- */
-static inline bool IsTileDepotType(TileIndex tile, TransportType type)
-{
- switch (type) {
- case TRANSPORT_RAIL:
- return IsTileType(tile, MP_RAILWAY) && GetRailTileType(tile) == RAIL_TILE_DEPOT;
-
- case TRANSPORT_ROAD:
- return IsRoadDepotTile(tile);
-
- case TRANSPORT_WATER:
- return IsTileType(tile, MP_WATER) && GetWaterTileType(tile) == WATER_TILE_DEPOT;
-
- default:
- NOT_REACHED();
- return false;
- }
-}
-
-/**
- * Is the given tile a tile with a depot on it?
- * @param tile the tile to check
- * @return true if and only if there is a depot on the tile.
- */
-static inline bool IsDepotTile(TileIndex tile)
-{
- switch (GetTileType(tile)) {
- case MP_ROAD: return IsRoadDepot(tile);
- case MP_WATER: return GetWaterTileType(tile) == WATER_TILE_DEPOT;
- case MP_RAILWAY: return GetRailTileType(tile) == RAIL_TILE_DEPOT;
- case MP_STATION: return IsHangar(tile);
- default: return false;
- }
-}
-
-/**
- * Find out if the slope of the tile is suitable to build a depot of given direction
- * @param direction The direction in which the depot's exit points
- * @param tileh The slope of the tile in question
- * @return true if the construction is possible
-
- * This is checked by the ugly 0x4C >> direction magic, which does the following:
- * 0x4C is 0100 1100 and tileh has only bits 0..3 set (steep tiles are ruled out)
- * So: for direction (only the significant bits are shown)<p>
- * 00 (exit towards NE) we need either bit 2 or 3 set in tileh: 0x4C >> 0 = 1100<p>
- * 01 (exit towards SE) we need either bit 1 or 2 set in tileh: 0x4C >> 1 = 0110<p>
- * 02 (exit towards SW) we need either bit 0 or 1 set in tileh: 0x4C >> 2 = 0011<p>
- * 03 (exit towards NW) we need either bit 0 or 4 set in tileh: 0x4C >> 3 = 1001<p>
- * So ((0x4C >> direction) & tileh) determines whether the depot can be built on the current tileh
- */
-static inline bool CanBuildDepotByTileh(DiagDirection direction, Slope tileh)
-{
- return ((0x4C >> direction) & tileh) != 0;
-}
-
-Depot *GetDepotByTile(TileIndex tile);
-void InitializeDepots();
-
-void DeleteDepotHighlightOfVehicle(const Vehicle *v);
-
-#endif /* DEPOT_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/depot_base.h Fri Apr 18 23:33:51 2008 +0000
@@ -0,0 +1,35 @@
+/* $Id$ */
+
+/** @file depot.h Base for all depots (except hangars) */
+
+#ifndef DEPOT_BASE_H
+#define DEPOT_BASE_H
+
+#include "tile_type.h"
+#include "depot_type.h"
+#include "oldpool.h"
+#include "town_type.h"
+
+DECLARE_OLD_POOL(Depot, Depot, 3, 8000)
+
+struct Depot : PoolItem<Depot, DepotID, &_Depot_pool> {
+ TileIndex xy;
+ TownID town_index;
+
+ Depot(TileIndex xy = 0) : xy(xy) {}
+ ~Depot();
+
+ inline bool IsValid() const { return this->xy != 0; }
+};
+
+static inline bool IsValidDepotID(DepotID index)
+{
+ return index < GetDepotPoolSize() && GetDepot(index)->IsValid();
+}
+
+Depot *GetDepotByTile(TileIndex tile);
+
+#define FOR_ALL_DEPOTS_FROM(d, start) for (d = GetDepot(start); d != NULL; d = (d->index + 1U < GetDepotPoolSize()) ? GetDepot(d->index + 1U) : NULL) if (d->IsValid())
+#define FOR_ALL_DEPOTS(d) FOR_ALL_DEPOTS_FROM(d, 0)
+
+#endif /* DEPOT_BASE_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/depot_func.h Fri Apr 18 23:33:51 2008 +0000
@@ -0,0 +1,39 @@
+/* $Id$ */
+
+/** @file depot_func.h Functions related to depots. */
+
+#ifndef DEPOT_FUNC_H
+#define DEPOT_FUNC_H
+
+#include "depot_type.h"
+#include "tile_type.h"
+#include "vehicle_type.h"
+#include "direction_type.h"
+#include "slope_type.h"
+
+void ShowDepotWindow(TileIndex tile, VehicleType type);
+void InitializeDepots();
+
+void DeleteDepotHighlightOfVehicle(const Vehicle *v);
+
+/**
+ * Find out if the slope of the tile is suitable to build a depot of given direction
+ * @param direction The direction in which the depot's exit points
+ * @param tileh The slope of the tile in question
+ * @return true if the construction is possible
+
+ * This is checked by the ugly 0x4C >> direction magic, which does the following:
+ * 0x4C is 0100 1100 and tileh has only bits 0..3 set (steep tiles are ruled out)
+ * So: for direction (only the significant bits are shown)<p>
+ * 00 (exit towards NE) we need either bit 2 or 3 set in tileh: 0x4C >> 0 = 1100<p>
+ * 01 (exit towards SE) we need either bit 1 or 2 set in tileh: 0x4C >> 1 = 0110<p>
+ * 02 (exit towards SW) we need either bit 0 or 1 set in tileh: 0x4C >> 2 = 0011<p>
+ * 03 (exit towards NW) we need either bit 0 or 4 set in tileh: 0x4C >> 3 = 1001<p>
+ * So ((0x4C >> direction) & tileh) determines whether the depot can be built on the current tileh
+ */
+static inline bool CanBuildDepotByTileh(DiagDirection direction, Slope tileh)
+{
+ return ((0x4C >> direction) & tileh) != 0;
+}
+
+#endif /* DEPOT_FUNC_H */
--- a/src/depot_gui.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/depot_gui.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -13,7 +13,7 @@
#include "viewport_func.h"
#include "gfx_func.h"
#include "command_func.h"
-#include "depot.h"
+#include "depot_base.h"
#include "vehicle_gui.h"
#include "station_map.h"
#include "newgrf_engine.h"
@@ -23,6 +23,7 @@
#include "vehicle_func.h"
#include "player_func.h"
#include "order_func.h"
+#include "depot_base.h"
#include "table/strings.h"
#include "table/sprites.h"
@@ -204,7 +205,7 @@
DrawSprite((v->vehstatus & VS_STOPPED) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, PAL_NONE, x + diff_x, y + diff_y);
SetDParam(0, v->unitnumber);
- DrawString(x, y + 2, (uint16)(v->max_age-366) >= v->age ? STR_00E2 : STR_00E3, TC_FROMSTRING);
+ DrawString(x, y + 2, (uint16)(v->max_age - 366) >= v->age ? STR_00E2 : STR_00E3, TC_FROMSTRING);
}
static void DrawDepotWindow(Window *w)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/depot_map.h Fri Apr 18 23:33:51 2008 +0000
@@ -0,0 +1,41 @@
+/* $Id$ */
+
+/** @file depot_map.h Map related accessors for depots. */
+
+#ifndef DEPOT_MAP_H
+#define DEPOT_MAP_H
+
+#include "road_map.h"
+#include "rail_map.h"
+#include "water_map.h"
+#include "station_map.h"
+
+/**
+ * Check if a tile is a depot and it is a depot of the given type.
+ */
+static inline bool IsDepotTypeTile(TileIndex tile, TransportType type)
+{
+ switch (type) {
+ default: NOT_REACHED();
+ case TRANSPORT_RAIL:
+ return IsRailDepotTile(tile);
+
+ case TRANSPORT_ROAD:
+ return IsRoadDepotTile(tile);
+
+ case TRANSPORT_WATER:
+ return IsShipDepotTile(tile);
+ }
+}
+
+/**
+ * Is the given tile a tile with a depot on it?
+ * @param tile the tile to check
+ * @return true if and only if there is a depot on the tile.
+ */
+static inline bool IsDepotTile(TileIndex tile)
+{
+ return IsRailDepotTile(tile) || IsRoadDepotTile(tile) || IsShipDepotTile(tile) || IsHangarTile(tile);
+}
+
+#endif /* DEPOT_MAP_H */
--- a/src/genworld.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/genworld.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -86,85 +86,89 @@
*/
static void * CDECL _GenerateWorld(void *arg)
{
- _generating_world = true;
- if (_network_dedicated) DEBUG(net, 0, "Generating map, please wait...");
- /* Set the Random() seed to generation_seed so we produce the same map with the same seed */
- if (_patches.generation_seed == GENERATE_NEW_SEED) _patches.generation_seed = _patches_newgame.generation_seed = InteractiveRandom();
- _random.SetSeed(_patches.generation_seed);
- SetGeneratingWorldProgress(GWP_MAP_INIT, 2);
- SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, VHM_NONE, WC_MAIN_WINDOW, 0);
-
- IncreaseGeneratingWorldProgress(GWP_MAP_INIT);
- /* Must start economy early because of the costs. */
- StartupEconomy();
-
- /* Don't generate landscape items when in the scenario editor. */
- if (_gw.mode == GW_EMPTY) {
- SetGeneratingWorldProgress(GWP_UNMOVABLE, 1);
-
- /* Make the map the height of the patch setting */
- if (_game_mode != GM_MENU) FlatEmptyWorld(_patches.se_flat_world_height);
-
- ConvertGroundTilesIntoWaterTiles();
- IncreaseGeneratingWorldProgress(GWP_UNMOVABLE);
- } else {
- GenerateLandscape(_gw.mode);
- GenerateClearTile();
-
- /* only generate towns, tree and industries in newgame mode. */
- if (_game_mode != GM_EDITOR) {
- GenerateTowns();
- GenerateIndustries();
- GenerateUnmovables();
- GenerateTrees();
- }
- }
-
- ClearStorageChanges(true);
+ try {
+ _generating_world = true;
+ if (_network_dedicated) DEBUG(net, 0, "Generating map, please wait...");
+ /* Set the Random() seed to generation_seed so we produce the same map with the same seed */
+ if (_patches.generation_seed == GENERATE_NEW_SEED) _patches.generation_seed = _patches_newgame.generation_seed = InteractiveRandom();
+ _random.SetSeed(_patches.generation_seed);
+ SetGeneratingWorldProgress(GWP_MAP_INIT, 2);
+ SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, VHM_NONE, WC_MAIN_WINDOW, 0);
- /* These are probably pointless when inside the scenario editor. */
- SetGeneratingWorldProgress(GWP_GAME_INIT, 3);
- StartupPlayers();
- IncreaseGeneratingWorldProgress(GWP_GAME_INIT);
- StartupEngines();
- IncreaseGeneratingWorldProgress(GWP_GAME_INIT);
- StartupDisasters();
- _generating_world = false;
-
- /* No need to run the tile loop in the scenario editor. */
- if (_gw.mode != GW_EMPTY) {
- uint i;
-
- SetGeneratingWorldProgress(GWP_RUNTILELOOP, 0x500);
- for (i = 0; i < 0x500; i++) {
- RunTileLoop();
- IncreaseGeneratingWorldProgress(GWP_RUNTILELOOP);
- }
- }
+ IncreaseGeneratingWorldProgress(GWP_MAP_INIT);
+ /* Must start economy early because of the costs. */
+ StartupEconomy();
- ResetObjectToPlace();
- SetLocalPlayer(_gw.lp);
-
- SetGeneratingWorldProgress(GWP_GAME_START, 1);
- /* Call any callback */
- if (_gw.proc != NULL) _gw.proc();
- IncreaseGeneratingWorldProgress(GWP_GAME_START);
+ /* Don't generate landscape items when in the scenario editor. */
+ if (_gw.mode == GW_EMPTY) {
+ SetGeneratingWorldProgress(GWP_UNMOVABLE, 1);
- if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE);
- /* Show all vital windows again, because we have hidden them */
- if (_gw.threaded && _game_mode != GM_MENU) ShowVitalWindows();
- _gw.active = false;
- _gw.thread = NULL;
- _gw.proc = NULL;
- _gw.threaded = false;
+ /* Make the map the height of the patch setting */
+ if (_game_mode != GM_MENU) FlatEmptyWorld(_patches.se_flat_world_height);
- DeleteWindowById(WC_GENERATE_PROGRESS_WINDOW, 0);
- MarkWholeScreenDirty();
+ ConvertGroundTilesIntoWaterTiles();
+ IncreaseGeneratingWorldProgress(GWP_UNMOVABLE);
+ } else {
+ GenerateLandscape(_gw.mode);
+ GenerateClearTile();
- if (_network_dedicated) DEBUG(net, 0, "Map generated, starting game");
+ /* only generate towns, tree and industries in newgame mode. */
+ if (_game_mode != GM_EDITOR) {
+ GenerateTowns();
+ GenerateIndustries();
+ GenerateUnmovables();
+ GenerateTrees();
+ }
+ }
- if (_patches.pause_on_newgame && _game_mode == GM_NORMAL) DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
+ ClearStorageChanges(true);
+ /* These are probably pointless when inside the scenario editor. */
+ SetGeneratingWorldProgress(GWP_GAME_INIT, 3);
+ StartupPlayers();
+ IncreaseGeneratingWorldProgress(GWP_GAME_INIT);
+ StartupEngines();
+ IncreaseGeneratingWorldProgress(GWP_GAME_INIT);
+ StartupDisasters();
+ _generating_world = false;
+
+ /* No need to run the tile loop in the scenario editor. */
+ if (_gw.mode != GW_EMPTY) {
+ uint i;
+
+ SetGeneratingWorldProgress(GWP_RUNTILELOOP, 0x500);
+ for (i = 0; i < 0x500; i++) {
+ RunTileLoop();
+ IncreaseGeneratingWorldProgress(GWP_RUNTILELOOP);
+ }
+ }
+
+ ResetObjectToPlace();
+ SetLocalPlayer(_gw.lp);
+
+ SetGeneratingWorldProgress(GWP_GAME_START, 1);
+ /* Call any callback */
+ if (_gw.proc != NULL) _gw.proc();
+ IncreaseGeneratingWorldProgress(GWP_GAME_START);
+
+ if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE);
+ /* Show all vital windows again, because we have hidden them */
+ if (_gw.threaded && _game_mode != GM_MENU) ShowVitalWindows();
+ _gw.active = false;
+ _gw.thread = NULL;
+ _gw.proc = NULL;
+ _gw.threaded = false;
+
+ DeleteWindowById(WC_GENERATE_PROGRESS_WINDOW, 0);
+ MarkWholeScreenDirty();
+
+ if (_network_dedicated) DEBUG(net, 0, "Map generated, starting game");
+
+ if (_patches.pause_on_newgame && _game_mode == GM_NORMAL) DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
+ } catch (...) {
+ _generating_world = false;
+ throw;
+ }
return NULL;
}
--- a/src/gfx.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/gfx.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -17,6 +17,7 @@
#include "strings_func.h"
#include "core/math_func.hpp"
#include "settings_type.h"
+#include "core/alloc_func.hpp"
#include "table/palettes.h"
#include "table/sprites.h"
@@ -64,8 +65,12 @@
static const byte *_color_remap_ptr;
static byte _string_colorremap[3];
-#define DIRTY_BYTES_PER_LINE (MAX_SCREEN_WIDTH / 64)
-static byte _dirty_blocks[DIRTY_BYTES_PER_LINE * MAX_SCREEN_HEIGHT / 8];
+enum {
+ DIRTY_BLOCK_HEIGHT = 8,
+ DIRTY_BLOCK_WIDTH = 64,
+};
+static uint _dirty_bytes_per_line = 0;
+static byte *_dirty_blocks = NULL;
void GfxScroll(int left, int top, int width, int height, int xo, int yo)
{
@@ -930,6 +935,9 @@
void ScreenSizeChanged()
{
+ _dirty_bytes_per_line = (_screen.width + DIRTY_BLOCK_WIDTH - 1) / DIRTY_BLOCK_WIDTH;
+ _dirty_blocks = ReallocT<byte>(_dirty_blocks, _dirty_bytes_per_line * ((_screen.height + DIRTY_BLOCK_HEIGHT - 1) / DIRTY_BLOCK_HEIGHT));
+
/* check the dirty rect */
if (_invalid_rect.right >= _screen.width) _invalid_rect.right = _screen.width;
if (_invalid_rect.bottom >= _screen.height) _invalid_rect.bottom = _screen.height;
@@ -1033,8 +1041,8 @@
void DrawDirtyBlocks()
{
byte *b = _dirty_blocks;
- const int w = Align(_screen.width, 64);
- const int h = Align(_screen.height, 8);
+ const int w = Align(_screen.width, DIRTY_BLOCK_WIDTH);
+ const int h = Align(_screen.height, DIRTY_BLOCK_HEIGHT);
int x;
int y;
@@ -1047,7 +1055,7 @@
if (*b != 0) {
int left;
int top;
- int right = x + 64;
+ int right = x + DIRTY_BLOCK_WIDTH;
int bottom = y;
byte *p = b;
int h2;
@@ -1055,12 +1063,12 @@
/* First try coalescing downwards */
do {
*p = 0;
- p += DIRTY_BYTES_PER_LINE;
- bottom += 8;
+ p += _dirty_bytes_per_line;
+ bottom += DIRTY_BLOCK_HEIGHT;
} while (bottom != h && *p != 0);
/* Try coalescing to the right too. */
- h2 = (bottom - y) >> 3;
+ h2 = (bottom - y) / DIRTY_BLOCK_HEIGHT;
assert(h2 > 0);
p = b;
@@ -1070,18 +1078,18 @@
/* Check if a full line of dirty flags is set. */
do {
if (!*p2) goto no_more_coalesc;
- p2 += DIRTY_BYTES_PER_LINE;
+ p2 += _dirty_bytes_per_line;
} while (--h != 0);
/* Wohoo, can combine it one step to the right!
* Do that, and clear the bits. */
- right += 64;
+ right += DIRTY_BLOCK_WIDTH;
h = h2;
p2 = p;
do {
*p2 = 0;
- p2 += DIRTY_BYTES_PER_LINE;
+ p2 += _dirty_bytes_per_line;
} while (--h != 0);
}
no_more_coalesc:
@@ -1099,8 +1107,8 @@
}
}
- } while (b++, (x += 64) != w);
- } while (b += -(w >> 6) + DIRTY_BYTES_PER_LINE, (y += 8) != h);
+ } while (b++, (x += DIRTY_BLOCK_WIDTH) != w);
+ } while (b += -(w / DIRTY_BLOCK_WIDTH) + _dirty_bytes_per_line, (y += DIRTY_BLOCK_HEIGHT) != h);
_invalid_rect.left = w;
_invalid_rect.top = h;
@@ -1147,13 +1155,13 @@
if (right > _invalid_rect.right ) _invalid_rect.right = right;
if (bottom > _invalid_rect.bottom) _invalid_rect.bottom = bottom;
- left >>= 6;
- top >>= 3;
+ left /= DIRTY_BLOCK_WIDTH;
+ top /= DIRTY_BLOCK_HEIGHT;
- b = _dirty_blocks + top * DIRTY_BYTES_PER_LINE + left;
+ b = _dirty_blocks + top * _dirty_bytes_per_line + left;
- width = ((right - 1) >> 6) - left + 1;
- height = ((bottom - 1) >> 3) - top + 1;
+ width = ((right - 1) / DIRTY_BLOCK_WIDTH) - left + 1;
+ height = ((bottom - 1) / DIRTY_BLOCK_HEIGHT) - top + 1;
assert(width > 0 && height > 0);
@@ -1162,7 +1170,7 @@
do b[--i] = 0xFF; while (i);
- b += DIRTY_BYTES_PER_LINE;
+ b += _dirty_bytes_per_line;
} while (--height != 0);
}
--- a/src/group_cmd.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/group_cmd.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -39,7 +39,7 @@
/* Decrease the num engines of EngineID i of the old group if it's not the default one */
if (!IsDefaultGroupID(old_g) && IsValidGroupID(old_g)) GetGroup(old_g)->num_engines[i]--;
- /* Increase the num engines of EngineID i of the new group if it's not the new one */
+ /* Increase the num engines of EngineID i of the new group if it's not the default one */
if (!IsDefaultGroupID(new_g) && IsValidGroupID(new_g)) GetGroup(new_g)->num_engines[i]++;
}
}
--- a/src/group_gui.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/group_gui.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -9,7 +9,6 @@
#include "textbuf_gui.h"
#include "command_func.h"
#include "vehicle_gui.h"
-#include "depot.h"
#include "train.h"
#include "group.h"
#include "debug.h"
@@ -207,7 +206,7 @@
w->widget[GRP_WIDGET_LIST_VEHICLE].data = (w->vscroll2.cap << 8) + 1;
switch (gv->vehicle_type) {
- default: NOT_REACHED(); break;
+ default: NOT_REACHED();
case VEH_TRAIN: gv->_sorting = &_sorting.train; break;
case VEH_ROAD: gv->_sorting = &_sorting.roadveh; break;
case VEH_SHIP: gv->_sorting = &_sorting.ship; break;
@@ -218,11 +217,11 @@
gv->vehicle_type = (VehicleType)GB(w->window_number, 11, 5);
gv->l.sort_type = gv->_sorting->criteria;
gv->l.flags = VL_REBUILD | (gv->_sorting->order ? VL_DESC : VL_NONE);
- gv->l.resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; // Set up resort timer
+ gv->l.resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; // Set up resort timer
gl->sort_list = NULL;
gl->l.flags = VL_REBUILD | VL_NONE;
- gl->l.resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; // Set up resort timer
+ gl->l.resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; // Set up resort timer
gv->group_sel = ALL_GROUP;
gv->vehicle_sel = INVALID_VEHICLE;
@@ -399,7 +398,7 @@
w->widget[GRP_WIDGET_CAPTION].data = STR_A009_AIRCRAFT;
w->widget[GRP_WIDGET_REPLACE_PROTECTION].data = SPR_GROUP_REPLACE_OFF_AIRCRAFT;
break;
- default: NOT_REACHED(); break;
+ default: NOT_REACHED();
}
} else {
const Group *g = GetGroup(gv->group_sel);
@@ -424,7 +423,7 @@
w->widget[GRP_WIDGET_CAPTION].data = STR_GROUP_AIRCRAFTS_CAPTION;
w->widget[GRP_WIDGET_REPLACE_PROTECTION].data = (g->replace_protection) ? SPR_GROUP_REPLACE_ON_AIRCRAFT : SPR_GROUP_REPLACE_OFF_AIRCRAFT;
break;
- default: NOT_REACHED(); break;
+ default: NOT_REACHED();
}
}
@@ -454,7 +453,7 @@
str_all_veh = STR_GROUP_ALL_AIRCRAFTS;
str_no_group_veh = STR_GROUP_DEFAULT_AIRCRAFTS;
break;
- default: NOT_REACHED(); break;
+ default: NOT_REACHED();
}
DrawString(10, y1, str_all_veh, IsAllGroupID(gv->group_sel) ? TC_WHITE : TC_BLACK);
@@ -524,7 +523,7 @@
break;
case GRP_WIDGET_SORT_BY_DROPDOWN: // Select sorting criteria dropdown menu
- ShowDropDownMenu(w, _vehicle_sort_listing, gv->l.sort_type, GRP_WIDGET_SORT_BY_DROPDOWN, 0, 0);
+ ShowDropDownMenu(w, _vehicle_sort_listing, gv->l.sort_type, GRP_WIDGET_SORT_BY_DROPDOWN, 0, (gv->vehicle_type == VEH_TRAIN || gv->vehicle_type == VEH_ROAD) ? 0 : (1 << 10));
return;
case GRP_WIDGET_ALL_VEHICLES: // All vehicles button
@@ -601,7 +600,7 @@
SetDParam(0, g->index);
ShowQueryString(STR_GROUP_NAME, STR_GROUP_RENAME_CAPTION, 31, 150, w, CS_ALPHANUMERAL);
- } break;
+ } break;
case GRP_WIDGET_AVAILABLE_VEHICLES:
--- a/src/gui.h Thu Apr 17 08:40:01 2008 +0000
+++ b/src/gui.h Fri Apr 18 23:33:51 2008 +0000
@@ -17,8 +17,6 @@
void CcBuildCanal(bool success, TileIndex tile, uint32 p1, uint32 p2);
void HandleOnEditText(const char *str);
void InitializeGUI();
-Window *PopupMainPlayerToolbMenu(Window *w, int main_button, int gray);
-Window *PopupMainToolbMenu(Window *w, uint16 parent_button, StringID base_string, byte item_count, byte disabled_mask);
/* settings_gui.cpp */
void ShowGameOptions();
@@ -36,11 +34,6 @@
void ShowCompanyLeagueTable();
void ShowPerformanceRatingDetail();
-/* news_gui.cpp */
-void ShowLastNewsMessage();
-void ShowMessageOptions();
-void ShowMessageHistory();
-
/* train_gui.cpp */
void ShowOrdersWindow(const Vehicle *v);
@@ -104,8 +97,6 @@
void SetVScroll2Count(Window *w, int num);
void SetHScrollCount(Window *w, int num);
-void ShowCheatWindow();
-
void BuildFileList();
void SetFiosType(const byte fiostype);
--- a/src/industry.h Thu Apr 17 08:40:01 2008 +0000
+++ b/src/industry.h Fri Apr 18 23:33:51 2008 +0000
@@ -15,7 +15,6 @@
#include "date_type.h"
#include "town_type.h"
#include "industry_type.h"
-#include "newgrf_string_type.h"
enum {
INVALID_INDUSTRY = 0xFFFF,
@@ -174,12 +173,12 @@
byte climate_availability; ///< Bitmask, giving landscape enums as bit position
IndustryBehaviour behaviour; ///< How this industry will behave, and how others entities can use it
byte map_colour; ///< colour used for the small map
- GRFMappedStringID name; ///< Displayed name of the industry
- GRFMappedStringID new_industry_text; ///< Message appearing when the industry is built
- GRFMappedStringID closure_text; ///< Message appearing when the industry closes
- GRFMappedStringID production_up_text; ///< Message appearing when the industry's production is increasing
- GRFMappedStringID production_down_text; ///< Message appearing when the industry's production is decreasing
- GRFMappedStringID station_name; ///< Default name for nearby station
+ StringID name; ///< Displayed name of the industry
+ StringID new_industry_text; ///< Message appearing when the industry is built
+ StringID closure_text; ///< Message appearing when the industry closes
+ StringID production_up_text; ///< Message appearing when the industry's production is increasing
+ StringID production_down_text; ///< Message appearing when the industry's production is decreasing
+ StringID station_name; ///< Default name for nearby station
byte appear_ingame[NUM_LANDSCAPE]; ///< Probability of appearance in game
byte appear_creation[NUM_LANDSCAPE]; ///< Probability of appearance during map creation
uint8 number_of_sounds; ///< Number of sounds available in the sounds array
--- a/src/industry_cmd.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/industry_cmd.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -16,6 +16,7 @@
#include "news_func.h"
#include "saveload.h"
#include "variables.h"
+#include "cheat_func.h"
#include "genworld.h"
#include "water_map.h"
#include "tree_map.h"
--- a/src/industry_gui.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/industry_gui.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -14,6 +14,7 @@
#include "industry.h"
#include "town.h"
#include "variables.h"
+#include "cheat_func.h"
#include "cargotype.h"
#include "newgrf.h"
#include "newgrf_callbacks.h"
--- a/src/intro_gui.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/intro_gui.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -106,7 +106,7 @@
}
break;
- case SGI_TEMPERATE_LANDSCAPE: case SGI_ARCTIC_LANDSCAPE:
+ case SGI_TEMPERATE_LANDSCAPE: case SGI_ARCTIC_LANDSCAPE:
case SGI_TROPIC_LANDSCAPE: case SGI_TOYLAND_LANDSCAPE:
w->RaiseWidget(_opt_newgame.landscape + SGI_TEMPERATE_LANDSCAPE);
SetNewLandscapeType(e->we.click.widget - SGI_TEMPERATE_LANDSCAPE);
--- a/src/landscape.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/landscape.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -610,6 +610,7 @@
}
+TileIndex _cur_tileloop_tile;
#define TILELOOP_BITS 4
#define TILELOOP_SIZE (1 << TILELOOP_BITS)
#define TILELOOP_ASSERTMASK ((TILELOOP_SIZE - 1) + ((TILELOOP_SIZE - 1) << MapLogX()))
--- a/src/lang/english.txt Thu Apr 17 08:40:01 2008 +0000
+++ b/src/lang/english.txt Fri Apr 18 23:33:51 2008 +0000
@@ -378,6 +378,7 @@
STR_SORT_BY_MAX_SPEED :Maximum speed
STR_SORT_BY_MODEL :Model
STR_SORT_BY_VALUE :Value
+STR_SORT_BY_LENGTH :Length
STR_SORT_BY_FACILITY :Station type
STR_SORT_BY_WAITING :Waiting cargo value
STR_SORT_BY_RATING_MAX :Cargo rating
--- a/src/main_gui.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/main_gui.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -4,7 +4,6 @@
#include "stdafx.h"
#include "openttd.h"
-#include "heightmap.h"
#include "currency.h"
#include "spritecache.h"
#include "gui.h"
@@ -13,29 +12,14 @@
#include "textbuf_gui.h"
#include "viewport_func.h"
#include "command_func.h"
-#include "news_func.h"
-#include "town.h"
+#include "news_gui.h"
#include "console.h"
-#include "signs_func.h"
#include "waypoint.h"
-#include "variables.h"
-#include "train.h"
-#include "roadveh.h"
-#include "bridge_map.h"
-#include "screenshot.h"
#include "genworld.h"
-#include "vehicle_gui.h"
#include "transparency_gui.h"
-#include "newgrf_config.h"
-#include "rail_gui.h"
-#include "road_gui.h"
#include "date_func.h"
#include "functions.h"
-#include "vehicle_func.h"
#include "sound_func.h"
-#include "fios.h"
-#include "terraform_gui.h"
-#include "industry.h"
#include "transparency.h"
#include "strings_func.h"
#include "zoom_func.h"
@@ -46,6 +30,7 @@
#include "settings_type.h"
#include "toolbar_gui.h"
#include "ai/ai_gui.hpp"
+#include "variables.h"
#include "network/network.h"
#include "network/network_data.h"
@@ -59,11 +44,6 @@
static int _rename_id = 1;
static int _rename_what = -1;
-RailType _last_built_railtype;
-RoadType _last_built_roadtype;
-bool _draw_bounding_boxes = false;
-
-
void CcGiveMoney(bool success, TileIndex tile, uint32 p1, uint32 p2)
{
#ifdef ENABLE_NETWORK
@@ -143,167 +123,6 @@
if (success) SndPlayTileFx(SND_12_EXPLOSION, tile);
}
-
-static void MenuClickSettings(int index)
-{
- switch (index) {
- case 0: ShowGameOptions(); return;
- case 1: ShowGameDifficulty(); return;
- case 2: ShowPatchesSelection(); return;
- case 3: ShowNewGRFSettings(!_networking, true, true, &_grfconfig); return;
- case 4: ShowTransparencyToolbar(); break;
-
- case 6: ToggleBit(_display_opt, DO_SHOW_TOWN_NAMES); break;
- case 7: ToggleBit(_display_opt, DO_SHOW_STATION_NAMES); break;
- case 8: ToggleBit(_display_opt, DO_SHOW_SIGNS); break;
- case 9: ToggleBit(_display_opt, DO_WAYPOINTS); break;
- case 10: ToggleBit(_display_opt, DO_FULL_ANIMATION); break;
- case 11: ToggleBit(_display_opt, DO_FULL_DETAIL); break;
- case 12: ToggleTransparency(TO_HOUSES); break;
- case 13: ToggleTransparency(TO_SIGNS); break;
- }
- MarkWholeScreenDirty();
-}
-
-void MenuClickSaveLoad(int index)
-{
- if (_game_mode == GM_EDITOR) {
- switch (index) {
- case 0: ShowSaveLoadDialog(SLD_SAVE_SCENARIO); break;
- case 1: ShowSaveLoadDialog(SLD_LOAD_SCENARIO); break;
- case 2: ShowSaveLoadDialog(SLD_LOAD_HEIGHTMAP); break;
- case 3: AskExitToGameMenu(); break;
- case 5: HandleExitGameRequest(); break;
- }
- } else {
- switch (index) {
- case 0: ShowSaveLoadDialog(SLD_SAVE_GAME); break;
- case 1: ShowSaveLoadDialog(SLD_LOAD_GAME); break;
- case 2: AskExitToGameMenu(); break;
- case 3: HandleExitGameRequest(); break;
- }
- }
-}
-
-static void MenuClickMap(int index)
-{
- switch (index) {
- case 0: ShowSmallMap(); break;
- case 1: ShowExtraViewPortWindow(); break;
- case 2: ShowSignList(); break;
- }
-}
-
-static void MenuClickTown(int index)
-{
- ShowTownDirectory();
-}
-
-static void MenuClickScenMap(int index)
-{
- switch (index) {
- case 0: ShowSmallMap(); break;
- case 1: ShowExtraViewPortWindow(); break;
- case 2: ShowSignList(); break;
- case 3: ShowTownDirectory(); break;
- }
-}
-
-static void MenuClickSubsidies(int index)
-{
- ShowSubsidiesList();
-}
-
-static void MenuClickStations(int index)
-{
- ShowPlayerStations((PlayerID)index);
-}
-
-static void MenuClickFinances(int index)
-{
- ShowPlayerFinances((PlayerID)index);
-}
-
-static void MenuClickCompany(int index)
-{
- if (_networking && index == 0) {
- ShowClientList();
- } else {
- if (_networking) index--;
- ShowPlayerCompany((PlayerID)index);
- }
-}
-
-static void MenuClickGraphs(int index)
-{
- switch (index) {
- case 0: ShowOperatingProfitGraph(); break;
- case 1: ShowIncomeGraph(); break;
- case 2: ShowDeliveredCargoGraph(); break;
- case 3: ShowPerformanceHistoryGraph(); break;
- case 4: ShowCompanyValueGraph(); break;
- case 5: ShowCargoPaymentRates(); break;
- }
-}
-
-static void MenuClickLeague(int index)
-{
- switch (index) {
- case 0: ShowCompanyLeagueTable(); break;
- case 1: ShowPerformanceRatingDetail(); break;
- }
-}
-
-static void MenuClickIndustry(int index)
-{
- switch (index) {
- case 0: ShowIndustryDirectory(); break;
- case 1: ShowBuildIndustryWindow(); break;
- }
-}
-
-static void MenuClickShowTrains(int index)
-{
- ShowVehicleListWindow((PlayerID)index, VEH_TRAIN);
-}
-
-static void MenuClickShowRoad(int index)
-{
- ShowVehicleListWindow((PlayerID)index, VEH_ROAD);
-}
-
-static void MenuClickShowShips(int index)
-{
- ShowVehicleListWindow((PlayerID)index, VEH_SHIP);
-}
-
-static void MenuClickShowAir(int index)
-{
- ShowVehicleListWindow((PlayerID)index, VEH_AIRCRAFT);
-}
-
-static void MenuClickBuildRail(int index)
-{
- _last_built_railtype = (RailType)index;
- ShowBuildRailToolbar(_last_built_railtype, -1);
-}
-
-static void MenuClickBuildRoad(int index)
-{
- _last_built_roadtype = (RoadType)index;
- ShowBuildRoadToolbar(_last_built_roadtype);
-}
-
-static void MenuClickBuildWater(int index)
-{
- ShowBuildDocksToolbar();
-}
-
-static void MenuClickBuildAir(int index)
-{
- ShowBuildAirToolbar();
-}
-
#ifdef ENABLE_NETWORK
void ShowNetworkGiveMoneyWindow(PlayerID player)
{
@@ -330,419 +149,6 @@
ShowQueryString(STR_WAYPOINT_RAW, STR_EDIT_WAYPOINT_NAME, 30, 180, NULL, CS_ALPHANUMERAL);
}
-void SelectSignTool()
-{
- if (_cursor.sprite == SPR_CURSOR_SIGN) {
- ResetObjectToPlace();
- } else {
- SetObjectToPlace(SPR_CURSOR_SIGN, PAL_NONE, VHM_RECT, WC_MAIN_TOOLBAR, 0);
- _place_proc = PlaceProc_Sign;
- }
-}
-
-static void MenuClickForest(int index)
-{
- switch (index) {
- case 0: ShowTerraformToolbar(); break;
- case 1: ShowBuildTreesToolbar(); break;
- case 2: SelectSignTool(); break;
- }
-}
-
-static void MenuClickMusicWindow(int index)
-{
- ShowMusicWindow();
-}
-
-static void MenuClickNewspaper(int index)
-{
- switch (index) {
- case 0: ShowLastNewsMessage(); break;
- case 1: ShowMessageOptions(); break;
- case 2: ShowMessageHistory(); break;
- }
-}
-
-void MenuClickSmallScreenshot()
-{
- SetScreenshotType(SC_VIEWPORT);
-}
-
-void MenuClickWorldScreenshot()
-{
- SetScreenshotType(SC_WORLD);
-}
-
-static void MenuClickHelp(int index)
-{
- switch (index) {
- case 0: PlaceLandBlockInfo(); break;
- case 2: IConsoleSwitch(); break;
- case 3: ShowAIDebugWindow(); break;
- case 4: MenuClickSmallScreenshot(); break;
- case 5: MenuClickWorldScreenshot(); break;
- case 6: ShowAboutWindow(); break;
- }
-}
-
-
-typedef void MenuClickedProc(int index);
-
-static MenuClickedProc * const _menu_clicked_procs[] = {
- NULL, /* 0 */
- NULL, /* 1 */
- MenuClickSettings, /* 2 */
- MenuClickSaveLoad, /* 3 */
- MenuClickMap, /* 4 */
- MenuClickTown, /* 5 */
- MenuClickSubsidies, /* 6 */
- MenuClickStations, /* 7 */
- MenuClickFinances, /* 8 */
- MenuClickCompany, /* 9 */
- MenuClickGraphs, /* 10 */
- MenuClickLeague, /* 11 */
- MenuClickIndustry, /* 12 */
- MenuClickShowTrains, /* 13 */
- MenuClickShowRoad, /* 14 */
- MenuClickShowShips, /* 15 */
- MenuClickShowAir, /* 16 */
- MenuClickScenMap, /* 17 */
- NULL, /* 18 */
- MenuClickBuildRail, /* 19 */
- MenuClickBuildRoad, /* 20 */
- MenuClickBuildWater, /* 21 */
- MenuClickBuildAir, /* 22 */
- MenuClickForest, /* 23 */
- MenuClickMusicWindow, /* 24 */
- MenuClickNewspaper, /* 25 */
- MenuClickHelp, /* 26 */
-};
-
-static void MenuWndProc(Window *w, WindowEvent *e)
-{
- switch (e->event) {
- case WE_CREATE: w->widget[0].right = w->width - 1; break;
-
- case WE_PAINT: {
- int x, y;
-
- byte count = WP(w, menu_d).item_count;
- byte sel = WP(w, menu_d).sel_index;
- uint16 chk = WP(w, menu_d).checked_items;
- StringID string = WP(w, menu_d).string_id;
- byte dis = WP(w, menu_d).disabled_items;
-
- DrawWindowWidgets(w);
-
- x = 1;
- y = 1;
-
- for (; count != 0; count--, string++, sel--) {
- TextColour color = HasBit(dis, 0) ? TC_GREY : (sel == 0) ? TC_WHITE : TC_BLACK;
- if (sel == 0) GfxFillRect(x, y, x + w->width - 3, y + 9, 0);
-
- if (HasBit(chk, 0)) DrawString(x + 2, y, STR_CHECKMARK, color);
- DrawString(x + 2, y, string, color);
-
- y += 10;
- chk >>= 1;
- dis >>= 1;
- }
- } break;
-
- case WE_DESTROY: {
- Window *v = FindWindowById(WC_MAIN_TOOLBAR, 0);
- v->RaiseWidget(WP(w, menu_d).main_button);
- SetWindowDirty(v);
- return;
- }
-
- case WE_POPUPMENU_SELECT: {
- int index = GetMenuItemIndex(w, e->we.popupmenu.pt.x, e->we.popupmenu.pt.y);
- int action_id;
-
-
- if (index < 0) {
- Window *w2 = FindWindowById(WC_MAIN_TOOLBAR,0);
- if (GetWidgetFromPos(w2, e->we.popupmenu.pt.x - w2->left, e->we.popupmenu.pt.y - w2->top) == WP(w, menu_d).main_button)
- index = WP(w, menu_d).sel_index;
- }
-
- action_id = WP(w, menu_d).action_id;
- DeleteWindow(w);
-
- if (index >= 0) {
- assert((uint)index <= lengthof(_menu_clicked_procs));
- _menu_clicked_procs[action_id](index);
- }
-
- break;
- }
-
- case WE_POPUPMENU_OVER: {
- int index = GetMenuItemIndex(w, e->we.popupmenu.pt.x, e->we.popupmenu.pt.y);
-
- if (index == -1 || index == WP(w, menu_d).sel_index) return;
-
- WP(w, menu_d).sel_index = index;
- SetWindowDirty(w);
- return;
- }
- }
-}
-
-/* Dynamic widget length determined by toolbar-string length.
- * See PopupMainToolbMenu en MenuWndProc */
-static const Widget _menu_widgets[] = {
-{ WWT_PANEL, RESIZE_NONE, 14, 0, 0, 0, 0, 0x0, STR_NULL},
-{ WIDGETS_END},
-};
-
-
-static const Widget _player_menu_widgets[] = {
-{ WWT_PANEL, RESIZE_NONE, 14, 0, 240, 0, 81, 0x0, STR_NULL},
-{ WIDGETS_END},
-};
-
-
-static int GetPlayerIndexFromMenu(int index)
-{
- if (index >= 0) {
- const Player *p;
-
- FOR_ALL_PLAYERS(p) {
- if (p->is_active && --index < 0) return p->index;
- }
- }
- return -1;
-}
-
-static void UpdatePlayerMenuHeight(Window *w)
-{
- byte num = ActivePlayerCount();
-
- /* Increase one to fit in PlayerList in the menu when in network */
- if (_networking && WP(w, menu_d).main_button == 9) num++;
-
- if (WP(w, menu_d).item_count != num) {
- WP(w, menu_d).item_count = num;
- SetWindowDirty(w);
- num = num * 10 + 2;
- w->height = num;
- w->widget[0].bottom = w->widget[0].top + num - 1;
- w->top = GetToolbarDropdownPos(0, w->width, w->height).y;
- SetWindowDirty(w);
- }
-}
-
-static void PlayerMenuWndProc(Window *w, WindowEvent *e)
-{
- switch (e->event) {
- case WE_PAINT: {
- int x,y;
- byte sel;
- TextColour color;
- Player *p;
- uint16 chk;
-
- UpdatePlayerMenuHeight(w);
- DrawWindowWidgets(w);
-
- x = 1;
- y = 1;
- sel = WP(w, menu_d).sel_index;
- chk = WP(w, menu_d).checked_items; // let this mean gray items.
-
- /* 9 = playerlist */
- if (_networking && WP(w, menu_d).main_button == 9) {
- if (sel == 0) {
- GfxFillRect(x, y, x + 238, y + 9, 0);
- }
- DrawString(x + 19, y, STR_NETWORK_CLIENT_LIST, TC_FROMSTRING);
- y += 10;
- sel--;
- }
-
- FOR_ALL_PLAYERS(p) {
- if (p->is_active) {
- if (p->index == sel) {
- GfxFillRect(x, y, x + 238, y + 9, 0);
- }
-
- DrawPlayerIcon(p->index, x + 2, y + 1);
-
- SetDParam(0, p->index);
- SetDParam(1, p->index);
-
- color = (p->index == sel) ? TC_WHITE : TC_BLACK;
- if (chk&1) color = TC_GREY;
- DrawString(x + 19, y, STR_7021, color);
-
- y += 10;
- }
- chk >>= 1;
- }
-
- break;
- }
-
- case WE_DESTROY: {
- Window *v = FindWindowById(WC_MAIN_TOOLBAR, 0);
- v->RaiseWidget(WP(w, menu_d).main_button);
- SetWindowDirty(v);
- return;
- }
-
- case WE_POPUPMENU_SELECT: {
- int index = GetMenuItemIndex(w, e->we.popupmenu.pt.x, e->we.popupmenu.pt.y);
- int action_id = WP(w, menu_d).action_id;
-
- /* We have a new entry at the top of the list of menu 9 when networking
- * so keep that in count */
- if (_networking && WP(w, menu_d).main_button == 9) {
- if (index > 0) index = GetPlayerIndexFromMenu(index - 1) + 1;
- } else {
- index = GetPlayerIndexFromMenu(index);
- }
-
- if (index < 0) {
- Window *w2 = FindWindowById(WC_MAIN_TOOLBAR,0);
- if (GetWidgetFromPos(w2, e->we.popupmenu.pt.x - w2->left, e->we.popupmenu.pt.y - w2->top) == WP(w, menu_d).main_button)
- index = WP(w, menu_d).sel_index;
- }
-
- DeleteWindow(w);
-
- if (index >= 0) {
- assert(index >= 0 && index < 30);
- _menu_clicked_procs[action_id](index);
- }
- break;
- }
- case WE_POPUPMENU_OVER: {
- int index;
- UpdatePlayerMenuHeight(w);
- index = GetMenuItemIndex(w, e->we.popupmenu.pt.x, e->we.popupmenu.pt.y);
-
- /* We have a new entry at the top of the list of menu 9 when networking
- * so keep that in count */
- if (_networking && WP(w, menu_d).main_button == 9) {
- if (index > 0) index = GetPlayerIndexFromMenu(index - 1) + 1;
- } else {
- index = GetPlayerIndexFromMenu(index);
- }
-
- if (index == -1 || index == WP(w, menu_d).sel_index) return;
-
- WP(w, menu_d).sel_index = index;
- SetWindowDirty(w);
- return;
- }
- }
-}
-
-/** Get the maximum length of a given string in a string-list. This is an
- * implicit string-list where the ID's are consecutive
- * @param base_string StringID of the first string in the list
- * @param count amount of StringID's in the list
- * @return the length of the longest string */
-static int GetStringListMaxWidth(StringID base_string, byte count)
-{
- char buffer[512];
- int width, max_width;
- byte i;
-
- max_width = 0;
- for (i = 0; i != count; i++) {
- GetString(buffer, base_string + i, lastof(buffer));
- width = GetStringBoundingBox(buffer).width;
- if (width > max_width) max_width = width;
- }
-
- return max_width;
-}
-
-/** Show a general dropdown menu. The positioning of the dropdown menu
- * defaults to the left side of the parent_button, eg the button that caused
- * this window to appear. The only exceptions are when the right side of this
- * dropdown would fall outside the main toolbar window, in that case it is
- * aligned with the toolbar's right side.
- * Since the disable-mask is only 8 bits right now, these dropdowns are
- * restricted to 8 items max if any bits of disabled_mask are active.
- * @param w Pointer to a window this dropdown menu belongs to. Has no effect
- * whatsoever, only graphically for positioning.
- * @param parent_button The widget identifier of the button that was clicked for
- * this dropdown. The created dropdown then knows what button to raise (button) on
- * action and whose function to execute (action).
- * It is possible to appoint another button for an action event by setting the
- * upper 8 bits of this parameter. If non is set, action is presumed to be the same
- * as button. So<br>
- * button bits 0 - 7 - widget clicked to get dropdown
- * action bits 8 - 15 - function of widget to execute on select (defaults to bits 0 - 7)
- * @param base_string The first StringID shown in the dropdown list. All others are
- * consecutive indeces from the language file. XXX - fix? Use ingame-string tables?
- * @param item_count Number of strings in the list, see previous parameter
- * @param disabled_mask Bitmask of disabled strings in the list
- * @return Return a pointer to the newly created dropdown window */
- Window *PopupMainToolbMenu(Window *w, uint16 parent_button, StringID base_string, byte item_count, byte disabled_mask)
-{
- assert(disabled_mask == 0 || item_count <= 8);
- w->LowerWidget(parent_button);
- w->InvalidateWidget(parent_button);
-
- DeleteWindowById(WC_TOOLBAR_MENU, 0);
-
- // Extend the dropdown toolbar to the longest string in the list
- int width = max(GetStringListMaxWidth(base_string, item_count) + 6, 140);
- int height = item_count * 10 + 2;
-
- Point pos = GetToolbarDropdownPos(parent_button, width, height);
-
- w = AllocateWindow(pos.x, pos.y, width, height, MenuWndProc, WC_TOOLBAR_MENU, _menu_widgets);
- w->widget[0].bottom = item_count * 10 + 1;
- w->flags4 &= ~WF_WHITE_BORDER_MASK;
-
- WP(w, menu_d).item_count = item_count;
- WP(w, menu_d).sel_index = 0;
- WP(w, menu_d).main_button = GB(parent_button, 0, 8);
- WP(w, menu_d).action_id = (GB(parent_button, 8, 8) != 0) ? GB(parent_button, 8, 8) : parent_button;
- WP(w, menu_d).string_id = base_string;
- WP(w, menu_d).checked_items = 0;
- WP(w, menu_d).disabled_items = disabled_mask;
-
- _popup_menu_active = true;
-
- SndPlayFx(SND_15_BEEP);
- return w;
-}
-
-Window *PopupMainPlayerToolbMenu(Window *w, int main_button, int gray)
-{
- w->LowerWidget(main_button);
- w->InvalidateWidget(main_button);
-
- DeleteWindowById(WC_TOOLBAR_MENU, 0);
- Point pos = GetToolbarDropdownPos(main_button, 241, 82);
- w = AllocateWindow(pos.x, pos.y, 241, 82, PlayerMenuWndProc, WC_TOOLBAR_MENU, _player_menu_widgets);
- w->flags4 &= ~WF_WHITE_BORDER_MASK;
- WP(w, menu_d).item_count = 0;
- WP(w, menu_d).sel_index = (_local_player != PLAYER_SPECTATOR) ? _local_player : GetPlayerIndexFromMenu(0);
- if (_networking && main_button == 9) {
- if (_local_player != PLAYER_SPECTATOR) {
- WP(w, menu_d).sel_index++;
- } else {
- /* Select client list by default for spectators */
- WP(w, menu_d).sel_index = 0;
- }
- }
- WP(w, menu_d).action_id = main_button;
- WP(w, menu_d).main_button = main_button;
- WP(w, menu_d).checked_items = gray;
- WP(w, menu_d).disabled_items = 0;
- _popup_menu_active = true;
- SndPlayFx(SND_15_BEEP);
- return w;
-}
/* Zooms a viewport in a window in or out */
/* No button handling or what so ever */
@@ -806,331 +212,165 @@
}
}
-
-extern GetNewsStringCallbackProc * const _get_news_string_callback[];
-
-
-static bool DrawScrollingStatusText(const NewsItem *ni, int pos, int width)
-{
- char buf[512];
- StringID str;
- const char *s, *last;
- char *d;
- DrawPixelInfo tmp_dpi, *old_dpi;
- int x;
- char buffer[256];
-
- if (ni->display_mode == NM_CALLBACK) {
- str = _get_news_string_callback[ni->callback](ni);
- } else {
- CopyInDParam(0, ni->params, lengthof(ni->params));
- str = ni->string_id;
- }
-
- GetString(buf, str, lastof(buf));
-
- s = buf;
- d = buffer;
- last = lastof(buffer);
-
- for (;;) {
- WChar c = Utf8Consume(&s);
- if (c == 0) {
- break;
- } else if (c == 0x0D) {
- if (d + 4 >= last) break;
- d[0] = d[1] = d[2] = d[3] = ' ';
- d += 4;
- } else if (IsPrintable(c)) {
- if (d + Utf8CharLen(c) >= last) break;
- d += Utf8Encode(d, c);
- }
- }
- *d = '\0';
-
- if (!FillDrawPixelInfo(&tmp_dpi, 141, 1, width, 11)) return true;
-
- old_dpi = _cur_dpi;
- _cur_dpi = &tmp_dpi;
-
- x = DoDrawString(buffer, pos, 0, TC_LIGHT_BLUE);
- _cur_dpi = old_dpi;
-
- return x > 0;
-}
-
-static void StatusBarWndProc(Window *w, WindowEvent *e)
-{
- switch (e->event) {
- case WE_PAINT: {
- const Player *p = (_local_player == PLAYER_SPECTATOR) ? NULL : GetPlayer(_local_player);
-
- DrawWindowWidgets(w);
- SetDParam(0, _date);
- DrawStringCentered(
- 70, 1, (_pause_game || _patches.status_long_date) ? STR_00AF : STR_00AE, TC_FROMSTRING
- );
-
- if (p != NULL) {
- /* Draw player money */
- SetDParam(0, p->player_money);
- DrawStringCentered(w->widget[2].left + 70, 1, STR_0004, TC_FROMSTRING);
- }
-
- /* Draw status bar */
- if (w->message.msg) { // true when saving is active
- DrawStringCenteredTruncated(w->widget[1].left + 1, w->widget[1].right - 1, 1, STR_SAVING_GAME, TC_FROMSTRING);
- } else if (_do_autosave) {
- DrawStringCenteredTruncated(w->widget[1].left + 1, w->widget[1].right - 1, 1, STR_032F_AUTOSAVE, TC_FROMSTRING);
- } else if (_pause_game) {
- DrawStringCenteredTruncated(w->widget[1].left + 1, w->widget[1].right - 1, 1, STR_0319_PAUSED, TC_FROMSTRING);
- } else if (WP(w, def_d).data_1 > -1280 && FindWindowById(WC_NEWS_WINDOW,0) == NULL && _statusbar_news_item.string_id != 0) {
- /* Draw the scrolling news text */
- if (!DrawScrollingStatusText(&_statusbar_news_item, WP(w, def_d).data_1, w->widget[1].right - w->widget[1].left - 2)) {
- WP(w, def_d).data_1 = -1280;
- if (p != NULL) {
- /* This is the default text */
- SetDParam(0, p->index);
- DrawStringCenteredTruncated(w->widget[1].left + 1, w->widget[1].right - 1, 1, STR_02BA, TC_FROMSTRING);
- }
- }
- } else {
- if (p != NULL) {
- /* This is the default text */
- SetDParam(0, p->index);
- DrawStringCenteredTruncated(w->widget[1].left + 1, w->widget[1].right - 1, 1, STR_02BA, TC_FROMSTRING);
- }
- }
-
- if (WP(w, def_d).data_2 > 0) DrawSprite(SPR_BLOT, PALETTE_TO_RED, w->widget[1].right - 11, 2);
- } break;
-
- case WE_MESSAGE:
- w->message.msg = e->we.message.msg;
- SetWindowDirty(w);
- break;
-
- case WE_CLICK:
- switch (e->we.click.widget) {
- case 1: ShowLastNewsMessage(); break;
- case 2: if (_local_player != PLAYER_SPECTATOR) ShowPlayerFinances(_local_player); break;
- default: ResetObjectToPlace();
- }
- break;
-
- case WE_TICK: {
- if (_pause_game) return;
-
- if (WP(w, def_d).data_1 > -1280) { // Scrolling text
- WP(w, def_d).data_1 -= 2;
- w->InvalidateWidget(1);
- }
-
- if (WP(w, def_d).data_2 > 0) { // Red blot to show there are new unread newsmessages
- WP(w, def_d).data_2 -= 2;
- } else if (WP(w, def_d).data_2 < 0) {
- WP(w, def_d).data_2 = 0;
- w->InvalidateWidget(1);
- }
-
- break;
- }
- }
-}
-
-static const Widget _main_status_widgets[] = {
-{ WWT_PANEL, RESIZE_NONE, 14, 0, 139, 0, 11, 0x0, STR_NULL},
-{ WWT_PUSHBTN, RESIZE_RIGHT, 14, 140, 179, 0, 11, 0x0, STR_02B7_SHOW_LAST_MESSAGE_OR_NEWS},
-{ WWT_PUSHBTN, RESIZE_LR, 14, 180, 319, 0, 11, 0x0, STR_NULL},
-{ WIDGETS_END},
-};
-
-static WindowDesc _main_status_desc = {
- WDP_CENTER, 0, 320, 12, 640, 12,
- WC_STATUS_BAR, WC_NONE,
- WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
- _main_status_widgets,
- StatusBarWndProc
-};
-
extern void UpdateAllStationVirtCoord();
static void MainWindowWndProc(Window *w, WindowEvent *e)
{
- int off_x;
-
switch (e->event) {
- case WE_PAINT:
- DrawWindowViewport(w);
- if (_game_mode == GM_MENU) {
- off_x = _screen.width / 2;
-
- DrawSprite(SPR_OTTD_O, PAL_NONE, off_x - 120, 50);
- DrawSprite(SPR_OTTD_P, PAL_NONE, off_x - 86, 50);
- DrawSprite(SPR_OTTD_E, PAL_NONE, off_x - 53, 50);
- DrawSprite(SPR_OTTD_N, PAL_NONE, off_x - 22, 50);
-
- DrawSprite(SPR_OTTD_T, PAL_NONE, off_x + 34, 50);
- DrawSprite(SPR_OTTD_T, PAL_NONE, off_x + 65, 50);
- DrawSprite(SPR_OTTD_D, PAL_NONE, off_x + 96, 50);
-
- /*
- DrawSprite(SPR_OTTD_R, off_x + 119, 50);
- DrawSprite(SPR_OTTD_A, off_x + 148, 50);
- DrawSprite(SPR_OTTD_N, off_x + 181, 50);
- DrawSprite(SPR_OTTD_S, off_x + 215, 50);
- DrawSprite(SPR_OTTD_P, off_x + 246, 50);
- DrawSprite(SPR_OTTD_O, off_x + 275, 50);
- DrawSprite(SPR_OTTD_R, off_x + 307, 50);
- DrawSprite(SPR_OTTD_T, off_x + 337, 50);
-
- DrawSprite(SPR_OTTD_T, off_x + 390, 50);
- DrawSprite(SPR_OTTD_Y, off_x + 417, 50);
- DrawSprite(SPR_OTTD_C, off_x + 447, 50);
- DrawSprite(SPR_OTTD_O, off_x + 478, 50);
- DrawSprite(SPR_OTTD_O, off_x + 509, 50);
- DrawSprite(SPR_OTTD_N, off_x + 541, 50);
- */
- }
- break;
+ case WE_PAINT:
+ DrawWindowViewport(w);
+ if (_game_mode == GM_MENU) {
+ int off_x = _screen.width / 2;
- case WE_KEYPRESS:
- switch (e->we.keypress.keycode) {
- case 'Q' | WKC_CTRL:
- case 'Q' | WKC_META:
- HandleExitGameRequest();
- break;
- }
+ DrawSprite(SPR_OTTD_O, PAL_NONE, off_x - 120, 50);
+ DrawSprite(SPR_OTTD_P, PAL_NONE, off_x - 86, 50);
+ DrawSprite(SPR_OTTD_E, PAL_NONE, off_x - 53, 50);
+ DrawSprite(SPR_OTTD_N, PAL_NONE, off_x - 22, 50);
- /* Disable all key shortcuts, except quit shortcuts when
- * generating the world, otherwise they create threading
- * problem during the generating, resulting in random
- * assertions that are hard to trigger and debug */
- if (IsGeneratingWorld()) break;
-
- if (e->we.keypress.keycode == WKC_BACKQUOTE) {
- IConsoleSwitch();
- e->we.keypress.cont = false;
+ DrawSprite(SPR_OTTD_T, PAL_NONE, off_x + 34, 50);
+ DrawSprite(SPR_OTTD_T, PAL_NONE, off_x + 65, 50);
+ DrawSprite(SPR_OTTD_D, PAL_NONE, off_x + 96, 50);
+ }
break;
- }
-
- if (e->we.keypress.keycode == ('B' | WKC_CTRL)) {
- e->we.keypress.cont = false;
- _draw_bounding_boxes = !_draw_bounding_boxes;
- MarkWholeScreenDirty();
- break;
- }
- if (_game_mode == GM_MENU) break;
+ case WE_KEYPRESS:
+ switch (e->we.keypress.keycode) {
+ case 'Q' | WKC_CTRL:
+ case 'Q' | WKC_META:
+ HandleExitGameRequest();
+ break;
+ }
- switch (e->we.keypress.keycode) {
- case 'C':
- case 'Z': {
- Point pt = GetTileBelowCursor();
- if (pt.x != -1) {
- if (e->we.keypress.keycode == 'Z') MaxZoomInOut(ZOOM_IN, w);
- ScrollMainWindowTo(pt.x, pt.y);
- }
+ /* Disable all key shortcuts, except quit shortcuts when
+ * generating the world, otherwise they create threading
+ * problem during the generating, resulting in random
+ * assertions that are hard to trigger and debug */
+ if (IsGeneratingWorld()) break;
+
+ if (e->we.keypress.keycode == WKC_BACKQUOTE) {
+ IConsoleSwitch();
+ e->we.keypress.cont = false;
break;
}
- case WKC_ESC: ResetObjectToPlace(); break;
- case WKC_DELETE: DeleteNonVitalWindows(); break;
- case WKC_DELETE | WKC_SHIFT: DeleteAllNonVitalWindows(); break;
- case 'R' | WKC_CTRL: MarkWholeScreenDirty(); break;
-
-#if defined(_DEBUG)
- case '0' | WKC_ALT: // Crash the game
- *(byte*)0 = 0;
- break;
-
- case '1' | WKC_ALT: // Gimme money
- /* Server can not cheat in advertise mode either! */
- if (!_networking || !_network_server || !_network_advertise)
- DoCommandP(0, 10000000, 0, NULL, CMD_MONEY_CHEAT);
- break;
-
- case '2' | WKC_ALT: // Update the coordinates of all station signs
- UpdateAllStationVirtCoord();
- break;
-#endif
-
- case '1' | WKC_CTRL:
- case '2' | WKC_CTRL:
- case '3' | WKC_CTRL:
- case '4' | WKC_CTRL:
- case '5' | WKC_CTRL:
- case '6' | WKC_CTRL:
- case '7' | WKC_CTRL:
- case '8' | WKC_CTRL:
- case '9' | WKC_CTRL:
- /* Transparency toggle hot keys */
- ToggleTransparency((TransparencyOption)(e->we.keypress.keycode - ('1' | WKC_CTRL)));
- MarkWholeScreenDirty();
- break;
-
- case '1' | WKC_CTRL | WKC_SHIFT:
- case '2' | WKC_CTRL | WKC_SHIFT:
- case '3' | WKC_CTRL | WKC_SHIFT:
- case '4' | WKC_CTRL | WKC_SHIFT:
- case '5' | WKC_CTRL | WKC_SHIFT:
- case '6' | WKC_CTRL | WKC_SHIFT:
- case '7' | WKC_CTRL | WKC_SHIFT:
- case '8' | WKC_CTRL | WKC_SHIFT:
- /* Invisibility toggle hot keys */
- ToggleInvisibilityWithTransparency((TransparencyOption)(e->we.keypress.keycode - ('1' | WKC_CTRL | WKC_SHIFT)));
+ if (e->we.keypress.keycode == ('B' | WKC_CTRL)) {
+ e->we.keypress.cont = false;
+ extern bool _draw_bounding_boxes;
+ _draw_bounding_boxes = !_draw_bounding_boxes;
MarkWholeScreenDirty();
break;
+ }
- case 'X' | WKC_CTRL:
- ShowTransparencyToolbar();
- break;
+ if (_game_mode == GM_MENU) break;
- case 'X':
- ResetRestoreAllTransparency();
- break;
+ switch (e->we.keypress.keycode) {
+ case 'C':
+ case 'Z': {
+ Point pt = GetTileBelowCursor();
+ if (pt.x != -1) {
+ if (e->we.keypress.keycode == 'Z') MaxZoomInOut(ZOOM_IN, w);
+ ScrollMainWindowTo(pt.x, pt.y);
+ }
+ break;
+ }
+
+ case WKC_ESC: ResetObjectToPlace(); break;
+ case WKC_DELETE: DeleteNonVitalWindows(); break;
+ case WKC_DELETE | WKC_SHIFT: DeleteAllNonVitalWindows(); break;
+ case 'R' | WKC_CTRL: MarkWholeScreenDirty(); break;
+
+#if defined(_DEBUG)
+ case '0' | WKC_ALT: // Crash the game
+ *(byte*)0 = 0;
+ break;
+
+ case '1' | WKC_ALT: // Gimme money
+ /* Server can not cheat in advertise mode either! */
+ if (!_networking || !_network_server || !_network_advertise)
+ DoCommandP(0, 10000000, 0, NULL, CMD_MONEY_CHEAT);
+ break;
+
+ case '2' | WKC_ALT: // Update the coordinates of all station signs
+ UpdateAllStationVirtCoord();
+ break;
+#endif
+
+ case '1' | WKC_CTRL:
+ case '2' | WKC_CTRL:
+ case '3' | WKC_CTRL:
+ case '4' | WKC_CTRL:
+ case '5' | WKC_CTRL:
+ case '6' | WKC_CTRL:
+ case '7' | WKC_CTRL:
+ case '8' | WKC_CTRL:
+ case '9' | WKC_CTRL:
+ /* Transparency toggle hot keys */
+ ToggleTransparency((TransparencyOption)(e->we.keypress.keycode - ('1' | WKC_CTRL)));
+ MarkWholeScreenDirty();
+ break;
+
+ case '1' | WKC_CTRL | WKC_SHIFT:
+ case '2' | WKC_CTRL | WKC_SHIFT:
+ case '3' | WKC_CTRL | WKC_SHIFT:
+ case '4' | WKC_CTRL | WKC_SHIFT:
+ case '5' | WKC_CTRL | WKC_SHIFT:
+ case '6' | WKC_CTRL | WKC_SHIFT:
+ case '7' | WKC_CTRL | WKC_SHIFT:
+ case '8' | WKC_CTRL | WKC_SHIFT:
+ /* Invisibility toggle hot keys */
+ ToggleInvisibilityWithTransparency((TransparencyOption)(e->we.keypress.keycode - ('1' | WKC_CTRL | WKC_SHIFT)));
+ MarkWholeScreenDirty();
+ break;
+
+ case 'X' | WKC_CTRL:
+ ShowTransparencyToolbar();
+ break;
+
+ case 'X':
+ ResetRestoreAllTransparency();
+ break;
#ifdef ENABLE_NETWORK
- case WKC_RETURN: case 'T': // smart chat; send to team if any, otherwise to all
- if (_networking) {
- const NetworkClientInfo *cio = NetworkFindClientInfoFromIndex(_network_own_client_index);
- bool teamchat = false;
-
- if (cio == NULL) break;
+ case WKC_RETURN: case 'T': // smart chat; send to team if any, otherwise to all
+ if (_networking) {
+ const NetworkClientInfo *cio = NetworkFindClientInfoFromIndex(_network_own_client_index);
+ bool teamchat = false;
- /* Only players actually playing can speak to team. Eg spectators cannot */
- if (_patches.prefer_teamchat && IsValidPlayer(cio->client_playas)) {
- const NetworkClientInfo *ci;
- FOR_ALL_ACTIVE_CLIENT_INFOS(ci) {
- if (ci->client_playas == cio->client_playas && ci != cio) {
- teamchat = true;
- break;
+ if (cio == NULL) break;
+
+ /* Only players actually playing can speak to team. Eg spectators cannot */
+ if (_patches.prefer_teamchat && IsValidPlayer(cio->client_playas)) {
+ const NetworkClientInfo *ci;
+ FOR_ALL_ACTIVE_CLIENT_INFOS(ci) {
+ if (ci->client_playas == cio->client_playas && ci != cio) {
+ teamchat = true;
+ break;
+ }
}
}
- }
-
- ShowNetworkChatQueryWindow(teamchat ? DESTTYPE_TEAM : DESTTYPE_BROADCAST, cio->client_playas);
- }
- break;
- case WKC_SHIFT | WKC_RETURN: case WKC_SHIFT | 'T': // send text message to all players
- if (_networking) ShowNetworkChatQueryWindow(DESTTYPE_BROADCAST, 0);
- break;
+ ShowNetworkChatQueryWindow(teamchat ? DESTTYPE_TEAM : DESTTYPE_BROADCAST, cio->client_playas);
+ }
+ break;
- case WKC_CTRL | WKC_RETURN: case WKC_CTRL | 'T': // send text to all team mates
- if (_networking) {
- const NetworkClientInfo *cio = NetworkFindClientInfoFromIndex(_network_own_client_index);
- if (cio == NULL) break;
+ case WKC_SHIFT | WKC_RETURN: case WKC_SHIFT | 'T': // send text message to all players
+ if (_networking) ShowNetworkChatQueryWindow(DESTTYPE_BROADCAST, 0);
+ break;
- ShowNetworkChatQueryWindow(DESTTYPE_TEAM, cio->client_playas);
- }
- break;
+ case WKC_CTRL | WKC_RETURN: case WKC_CTRL | 'T': // send text to all team mates
+ if (_networking) {
+ const NetworkClientInfo *cio = NetworkFindClientInfoFromIndex(_network_own_client_index);
+ if (cio == NULL) break;
+
+ ShowNetworkChatQueryWindow(DESTTYPE_TEAM, cio->client_playas);
+ }
+ break;
#endif
- default: return;
- }
- e->we.keypress.cont = false;
- break;
+ default: return;
+ }
+ e->we.keypress.cont = false;
+ break;
case WE_SCROLL: {
ViewPort *vp = IsPtInWindowViewport(w, _cursor.pos.x, _cursor.pos.y);
@@ -1162,21 +402,17 @@
void SetupColorsAndInitialWindow()
{
- uint i;
- Window *w;
- int width, height;
-
- for (i = 0; i != 16; i++) {
+ for (uint i = 0; i != 16; i++) {
const byte *b = GetNonSprite(PALETTE_RECOLOR_START + i);
assert(b);
memcpy(_colour_gradient[i], b + 0xC6, sizeof(_colour_gradient[i]));
}
- width = _screen.width;
- height = _screen.height;
+ int width = _screen.width;
+ int height = _screen.height;
- w = AllocateWindow(0, 0, width, height, MainWindowWndProc, WC_MAIN_WINDOW, NULL);
+ Window *w = AllocateWindow(0, 0, width, height, MainWindowWndProc, WC_MAIN_WINDOW, NULL);
AssignWindowViewport(w, 0, 0, width, height, TileXY(32, 32), ZOOM_LVL_VIEWPORT);
/* XXX: these are not done */
@@ -1193,27 +429,17 @@
}
}
+extern void ShowStatusBar();
+
void ShowVitalWindows()
{
Window *w = AllocateToolbar();
DoZoomInOutWindow(ZOOM_NONE, w);
- CLRBITS(w->flags4, WF_WHITE_BORDER_MASK);
-
- w->SetWidgetDisabledState(0, _networking && !_network_server); // if not server, disable pause button
- w->SetWidgetDisabledState(1, _networking); // if networking, disable fast-forward button
-
- /* 'w' is for sure a WC_MAIN_TOOLBAR */
- PositionMainToolbar(w);
-
/* Status bad only for normal games */
if (_game_mode == GM_EDITOR) return;
- _main_status_desc.top = _screen.height - 12;
- w = AllocateWindowDesc(&_main_status_desc);
- CLRBITS(w->flags4, WF_WHITE_BORDER_MASK);
-
- WP(w, def_d).data_1 = -1280;
+ ShowStatusBar();
}
/**
@@ -1224,19 +450,7 @@
{
_cur_resolution[0] = _screen.width;
_cur_resolution[1] = _screen.height;
+ ScreenSizeChanged();
RelocateAllWindows(_screen.width, _screen.height);
- ScreenSizeChanged();
MarkWholeScreenDirty();
}
-
-void InitializeMainGui()
-{
- /* Clean old GUI values */
- _last_built_railtype = RAILTYPE_RAIL;
- _last_built_roadtype = ROADTYPE_ROAD;
-}
-
-
-
-
-
--- a/src/misc.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/misc.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -10,6 +10,7 @@
#include "saveload.h"
#include "vehicle_gui.h"
#include "variables.h"
+#include "cheat_func.h"
#include "ai/ai.h"
#include "newgrf_house.h"
#include "cargotype.h"
@@ -31,6 +32,7 @@
#include "table/sprites.h"
char _name_array[512][32];
+extern TileIndex _cur_tileloop_tile;
void InitializeVehicles();
void InitializeWaypoints();
@@ -43,7 +45,6 @@
void InitializeAirportGui();
void InitializeDockGui();
void InitializeIndustries();
-void InitializeMainGui();
void InitializeTowns();
void InitializeTrees();
void InitializeSigns();
@@ -51,7 +52,7 @@
void InitializeCargoPackets();
static void InitializeNameMgr();
void InitializePlayers();
-static void InitializeCheats();
+void InitializeCheats();
void InitializeNPF();
void InitializeGame(int mode, uint size_x, uint size_y)
@@ -92,7 +93,6 @@
InitializeCargoPackets();
InitializeIndustries();
InitializeBuildingCounts();
- InitializeMainGui();
InitializeNameMgr();
InitializeVehiclesGuiList();
@@ -118,12 +118,6 @@
}
-static void InitializeCheats()
-{
- memset(&_cheats, 0, sizeof(Cheats));
-}
-
-
static void InitializeNameMgr()
{
memset(_name_array, 0, sizeof(_name_array));
@@ -465,31 +459,6 @@
}
}
-static void Save_CHTS()
-{
- byte count = sizeof(_cheats)/sizeof(Cheat);
- Cheat* cht = (Cheat*) &_cheats;
- Cheat* cht_last = &cht[count];
-
- SlSetLength(count * 2);
- for (; cht != cht_last; cht++) {
- SlWriteByte(cht->been_used);
- SlWriteByte(cht->value);
- }
-}
-
-static void Load_CHTS()
-{
- Cheat* cht = (Cheat*)&_cheats;
- uint count = SlGetFieldLength() / 2;
-
- for (uint i = 0; i < count; i++) {
- cht[i].been_used = (SlReadByte() != 0);
- cht[i].value = (SlReadByte() != 0);
- }
-}
-
-
extern const ChunkHandler _misc_chunk_handlers[] = {
{ 'MAPS', Save_MAPS, Load_MAPS, CH_RIFF },
{ 'MAPT', Save_MAPT, Load_MAPT, CH_RIFF },
@@ -503,6 +472,5 @@
{ 'NAME', NULL, Load_NAME, CH_ARRAY},
{ 'DATE', SaveLoad_DATE, SaveLoad_DATE, CH_RIFF},
- { 'VIEW', SaveLoad_VIEW, SaveLoad_VIEW, CH_RIFF},
- { 'CHTS', Save_CHTS, Load_CHTS, CH_RIFF | CH_LAST}
+ { 'VIEW', SaveLoad_VIEW, SaveLoad_VIEW, CH_RIFF | CH_LAST},
};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/misc/smallvec.h Fri Apr 18 23:33:51 2008 +0000
@@ -0,0 +1,64 @@
+/* $Id$ */
+
+/* @file smallvec.h */
+
+#ifndef SMALLVEC_H
+#define SMALLVEC_H
+
+template <typename T, uint S> struct SmallVector {
+ T *data;
+ uint items;
+ uint capacity;
+
+ SmallVector() : data(NULL), items(0), capacity(0) { }
+
+ ~SmallVector()
+ {
+ free(data);
+ }
+
+ /**
+ * Append an item and return it.
+ */
+ T *Append()
+ {
+ if (items == capacity) {
+ capacity += S;
+ data = ReallocT(data, capacity);
+ }
+
+ return &data[items++];
+ }
+
+ const T *Begin() const
+ {
+ return data;
+ }
+
+ T *Begin()
+ {
+ return data;
+ }
+
+ const T *End() const
+ {
+ return &data[items];
+ }
+
+ T *End()
+ {
+ return &data[items];
+ }
+
+ const T *Get(size_t index) const
+ {
+ return &data[index];
+ }
+
+ T *Get(size_t index)
+ {
+ return &data[index];
+ }
+};
+
+#endif /* SMALLVEC_H */
--- a/src/misc_gui.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/misc_gui.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -24,6 +24,7 @@
#include "town.h"
#include "network/network.h"
#include "variables.h"
+#include "cheat_func.h"
#include "train.h"
#include "tgp.h"
#include "cargotype.h"
@@ -566,6 +567,7 @@
case WE_DESTROY:
SetRedErrorSquare(0);
+ extern StringID _switch_mode_errorstr;
_switch_mode_errorstr = INVALID_STRING_ID;
break;
@@ -1393,7 +1395,7 @@
{ WWT_INSET, RESIZE_RB, 14, 2, 243, 50, 150, 0x0, STR_400A_LIST_OF_DRIVES_DIRECTORIES},
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 245, 256, 60, 151, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
{ WWT_PANEL, RESIZE_RTB, 14, 0, 256, 152, 167, 0x0, STR_NULL},
-{ WWT_EDITBOX, RESIZE_RTB, 14, 2, 254, 154, 165, STR_SAVE_OSKTITLE,STR_400B_CURRENTLY_SELECTED_NAME},
+{ WWT_EDITBOX, RESIZE_RTB, 14, 2, 254, 154, 165, STR_SAVE_OSKTITLE, STR_400B_CURRENTLY_SELECTED_NAME},
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 127, 168, 179, STR_4003_DELETE, STR_400C_DELETE_THE_CURRENTLY_SELECTED},
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 128, 244, 168, 179, STR_4002_SAVE, STR_400D_SAVE_THE_CURRENT_GAME_USING},
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 245, 256, 168, 179, 0x0, STR_RESIZE_BUTTON},
@@ -1788,211 +1790,3 @@
break;
}
}
-
-/**
- * The 'amount' to cheat with.
- * This variable is semantically a constant value, but because the cheat
- * code requires to be able to write to the variable it is not constified.
- */
-static int32 _money_cheat_amount = 10000000;
-
-static int32 ClickMoneyCheat(int32 p1, int32 p2)
-{
- DoCommandP(0, (uint32)(p2 * _money_cheat_amount), 0, NULL, CMD_MONEY_CHEAT);
- return _money_cheat_amount;
-}
-
-/**
- * @param p1 player to set to
- * @param p2 is -1 or +1 (down/up)
- */
-static int32 ClickChangePlayerCheat(int32 p1, int32 p2)
-{
- while (IsValidPlayer((PlayerID)p1)) {
- if (_players[p1].is_active) {
- SetLocalPlayer((PlayerID)p1);
-
- MarkWholeScreenDirty();
- return _local_player;
- }
- p1 += p2;
- }
-
- return _local_player;
-}
-
-/**
- * @param p1 -1 or +1 (down/up)
- * @param p2 unused
- */
-static int32 ClickChangeClimateCheat(int32 p1, int32 p2)
-{
- if (p1 == -1) p1 = 3;
- if (p1 == 4) p1 = 0;
- _opt.landscape = p1;
- ReloadNewGRFData();
- return _opt.landscape;
-}
-
-extern void EnginesMonthlyLoop();
-
-/**
- * @param p1 unused
- * @param p2 1 (increase) or -1 (decrease)
- */
-static int32 ClickChangeDateCheat(int32 p1, int32 p2)
-{
- YearMonthDay ymd;
- ConvertDateToYMD(_date, &ymd);
-
- if ((ymd.year == MIN_YEAR && p2 == -1) || (ymd.year == MAX_YEAR && p2 == 1)) return _cur_year;
-
- SetDate(ConvertYMDToDate(_cur_year + p2, ymd.month, ymd.day));
- EnginesMonthlyLoop();
- SetWindowDirty(FindWindowById(WC_STATUS_BAR, 0));
- ResetSignalVariant();
- return _cur_year;
-}
-
-typedef int32 CheckButtonClick(int32, int32);
-
-struct CheatEntry {
- VarType type; ///< type of selector
- StringID str; ///< string with descriptive text
- void *variable; ///< pointer to the variable
- bool *been_used; ///< has this cheat been used before?
- CheckButtonClick *proc;///< procedure
-};
-
-static const CheatEntry _cheats_ui[] = {
- {SLE_INT32, STR_CHEAT_MONEY, &_money_cheat_amount, &_cheats.money.been_used, &ClickMoneyCheat },
- {SLE_UINT8, STR_CHEAT_CHANGE_PLAYER, &_local_player, &_cheats.switch_player.been_used, &ClickChangePlayerCheat },
- {SLE_BOOL, STR_CHEAT_EXTRA_DYNAMITE, &_cheats.magic_bulldozer.value, &_cheats.magic_bulldozer.been_used, NULL },
- {SLE_BOOL, STR_CHEAT_CROSSINGTUNNELS, &_cheats.crossing_tunnels.value, &_cheats.crossing_tunnels.been_used, NULL },
- {SLE_BOOL, STR_CHEAT_BUILD_IN_PAUSE, &_cheats.build_in_pause.value, &_cheats.build_in_pause.been_used, NULL },
- {SLE_BOOL, STR_CHEAT_NO_JETCRASH, &_cheats.no_jetcrash.value, &_cheats.no_jetcrash.been_used, NULL },
- {SLE_BOOL, STR_CHEAT_SETUP_PROD, &_cheats.setup_prod.value, &_cheats.setup_prod.been_used, NULL },
- {SLE_UINT8, STR_CHEAT_SWITCH_CLIMATE, &_opt.landscape, &_cheats.switch_climate.been_used, &ClickChangeClimateCheat},
- {SLE_INT32, STR_CHEAT_CHANGE_DATE, &_cur_year, &_cheats.change_date.been_used, &ClickChangeDateCheat },
-};
-
-
-static const Widget _cheat_widgets[] = {
-{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
-{ WWT_CAPTION, RESIZE_NONE, 14, 11, 399, 0, 13, STR_CHEATS, STR_018C_WINDOW_TITLE_DRAG_THIS},
-{ WWT_PANEL, RESIZE_NONE, 14, 0, 399, 14, 169, 0x0, STR_NULL},
-{ WWT_PANEL, RESIZE_NONE, 14, 0, 399, 14, 169, 0x0, STR_CHEATS_TIP},
-{ WIDGETS_END},
-};
-
-static void CheatsWndProc(Window *w, WindowEvent *e)
-{
- switch (e->event) {
- case WE_PAINT: {
- int clk = WP(w, def_d).data_1;
-
- DrawWindowWidgets(w);
- DrawStringMultiCenter(200, 25, STR_CHEATS_WARNING, w->width - 50);
-
- for (int i = 0, x = 0, y = 45; i != lengthof(_cheats_ui); i++) {
- const CheatEntry *ce = &_cheats_ui[i];
-
- DrawSprite((*ce->been_used) ? SPR_BOX_CHECKED : SPR_BOX_EMPTY, PAL_NONE, x + 5, y + 2);
-
- switch (ce->type) {
- case SLE_BOOL: {
- bool on = (*(bool*)ce->variable);
-
- DrawFrameRect(x + 20, y + 1, x + 30 + 9, y + 9, on ? 6 : 4, on ? FR_LOWERED : FR_NONE);
- SetDParam(0, on ? STR_CONFIG_PATCHES_ON : STR_CONFIG_PATCHES_OFF);
- } break;
-
- default: {
- int32 val = (int32)ReadValue(ce->variable, ce->type);
- char buf[512];
-
- /* Draw [<][>] boxes for settings of an integer-type */
- DrawArrowButtons(x + 20, y, 3, clk - (i * 2), true, true);
-
- switch (ce->str) {
- /* Display date for change date cheat */
- case STR_CHEAT_CHANGE_DATE: SetDParam(0, _date); break;
-
- /* Draw colored flag for change player cheat */
- case STR_CHEAT_CHANGE_PLAYER:
- SetDParam(0, val);
- GetString(buf, STR_CHEAT_CHANGE_PLAYER, lastof(buf));
- DrawPlayerIcon(_current_player, 60 + GetStringBoundingBox(buf).width, y + 2);
- break;
-
- /* Set correct string for switch climate cheat */
- case STR_CHEAT_SWITCH_CLIMATE: val += STR_TEMPERATE_LANDSCAPE;
-
- /* Fallthrough */
- default: SetDParam(0, val);
- }
- } break;
- }
-
- DrawString(50, y + 1, ce->str, TC_FROMSTRING);
-
- y += 12;
- }
- break;
- }
-
- case WE_CLICK: {
- uint btn = (e->we.click.pt.y - 46) / 12;
- uint x = e->we.click.pt.x;
-
- /* Not clicking a button? */
- if (!IsInsideMM(x, 20, 40) || btn >= lengthof(_cheats_ui)) break;
-
- const CheatEntry *ce = &_cheats_ui[btn];
- int value = (int32)ReadValue(ce->variable, ce->type);
- int oldvalue = value;
-
- *ce->been_used = true;
-
- switch (ce->type) {
- case SLE_BOOL:
- value ^= 1;
- if (ce->proc != NULL) ce->proc(value, 0);
- break;
-
- default:
- /* Take whatever the function returns */
- value = ce->proc(value + ((x >= 30) ? 1 : -1), (x >= 30) ? 1 : -1);
-
- if (value != oldvalue) WP(w, def_d).data_1 = btn * 2 + 1 + ((x >= 30) ? 1 : 0);
- break;
- }
-
- if (value != oldvalue) WriteValue(ce->variable, ce->type, (int64)value);
-
- w->flags4 |= 5 << WF_TIMEOUT_SHL;
-
- SetWindowDirty(w);
- } break;
-
- case WE_TIMEOUT:
- WP(w, def_d).data_1 = 0;
- SetWindowDirty(w);
- break;
- }
-}
-
-static const WindowDesc _cheats_desc = {
- 240, 22, 400, 170, 400, 170,
- WC_CHEATS, WC_NONE,
- WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
- _cheat_widgets,
- CheatsWndProc
-};
-
-
-void ShowCheatWindow()
-{
- DeleteWindowById(WC_CHEATS, 0);
- AllocateWindowDesc(&_cheats_desc);
-}
--- a/src/namegen.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/namegen.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -305,7 +305,7 @@
uint sel = SeedChance(2,
lengthof(name_finnish_1) + lengthof(name_finnish_2), seed);
if (sel >= lengthof(name_finnish_1)) {
- strecat(buf, name_finnish_2[sel-lengthof(name_finnish_1)], last);
+ strecat(buf, name_finnish_2[sel - lengthof(name_finnish_1)], last);
} else {
strecat(buf, name_finnish_1[sel], last);
}
--- a/src/network/core/packet.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/network/core/packet.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -11,10 +11,6 @@
#include "packet.h"
-
-/* Do not want to include functions.h and all required headers */
-extern void NORETURN CDECL error(const char *str, ...);
-
/**
* Create a packet that is used to read from a network socket
* @param cs the socket handler associated with the socket we are reading from
--- a/src/network/core/tcp.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/network/core/tcp.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -75,6 +75,7 @@
if (!_network_server && _networking) {
_switch_mode = SM_MENU;
_networking = false;
+ extern StringID _switch_mode_errorstr;
_switch_mode_errorstr = STR_NETWORK_ERR_LOSTCONNECTION;
return NETWORK_RECV_STATUS_CONN_LOST;
--- a/src/network/network.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/network/network.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -224,6 +224,7 @@
static void NetworkError(StringID error_string)
{
_switch_mode = SM_MENU;
+ extern StringID _switch_mode_errorstr;
_switch_mode_errorstr = error_string;
}
@@ -391,7 +392,7 @@
uint32 netmask;
fields = sscanf(*output, "%u: %hhu.%hhu.%hhu.%hhu, netmask %hhu.%hhu.%hhu.%hhu%n",
- &n, &i1,&i2,&i3,&i4, &j1,&j2,&j3,&j4, &read);
+ &n, &i1, &i2, &i3, &i4, &j1, &j2, &j3, &j4, &read);
read += 1;
if (fields != 9) {
break;
--- a/src/network/network_client.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/network/network_client.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -328,6 +328,7 @@
// **********
extern bool SafeSaveOrLoad(const char *filename, int mode, int newgm, Subdirectory subdir);
+extern StringID _switch_mode_errorstr;
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_FULL)
{
--- a/src/network/network_udp.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/network/network_udp.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -293,7 +293,7 @@
for (c = item->info.grfconfig; c != NULL; c = c->next) {
if (c->status == GCS_NOT_FOUND) item->info.compatible = false;
- if (c->status != GCS_NOT_FOUND || strcmp(c->name, UNKNOWN_GRF_NAME_PLACEHOLDER) != 0) continue;
+ if (c->status != GCS_NOT_FOUND || strcmp(c->name, UNKNOWN_GRF_NAME_PLACEHOLDER) != 0) continue;
in_request[in_request_count] = c;
in_request_count++;
}
--- a/src/newgrf.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/newgrf.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -46,6 +46,8 @@
#include "settings_type.h"
#include "map_func.h"
+#include <map>
+
#include "table/strings.h"
#include "table/sprites.h"
#include "table/town_land.h"
@@ -225,6 +227,9 @@
}
+typedef std::map<StringID *, uint32> StringIDToGRFIDMapping;
+StringIDToGRFIDMapping _string_to_grf_mapping;
+
/** Used when setting an object's property to map to the GRF's strings
* while taking in consideration the "drift" between TTDPatch string system and OpenTTD's one
* @param grfid Id of the grf file
@@ -1387,7 +1392,8 @@
break;
case 0x12: // Building name ID
- housespec->building_name = GRFMappedStringID(grf_load_word(&buf), _cur_grffile->grfid);
+ housespec->building_name = grf_load_word(&buf);
+ _string_to_grf_mapping[&housespec->building_name] = _cur_grffile->grfid;
break;
case 0x13: // Building availability mask
@@ -1630,25 +1636,30 @@
break;
case 0x09: /* String ID for cargo type name */
- cs->name = GRFMappedStringID(grf_load_word(&buf), _cur_grffile->grfid);
+ cs->name = grf_load_word(&buf);
+ _string_to_grf_mapping[&cs->name] = _cur_grffile->grfid;
break;
case 0x0A: /* String for 1 unit of cargo */
- cs->name_single = GRFMappedStringID(grf_load_word(&buf), _cur_grffile->grfid);
+ cs->name_single = grf_load_word(&buf);
+ _string_to_grf_mapping[&cs->name_single] = _cur_grffile->grfid;
break;
case 0x0B:
/* String for units of cargo. This is different in OpenTTD to TTDPatch
* (e.g. 10 tonnes of coal) */
- cs->units_volume = GRFMappedStringID(grf_load_word(&buf), _cur_grffile->grfid);
+ cs->units_volume = grf_load_word(&buf);
+ _string_to_grf_mapping[&cs->units_volume] = _cur_grffile->grfid;
break;
case 0x0C: /* String for quantity of cargo (e.g. 10 tonnes of coal) */
- cs->quantifier = GRFMappedStringID(grf_load_word(&buf), _cur_grffile->grfid);
+ cs->quantifier = grf_load_word(&buf);
+ _string_to_grf_mapping[&cs->quantifier] = _cur_grffile->grfid;
break;
case 0x0D: /* String for two letter cargo abbreviation */
- cs->abbrev = GRFMappedStringID(grf_load_word(&buf), _cur_grffile->grfid);
+ cs->abbrev = grf_load_word(&buf);
+ _string_to_grf_mapping[&cs->abbrev] = _cur_grffile->grfid;
break;
case 0x0E: /* Sprite ID for cargo icon */
@@ -2032,15 +2043,18 @@
break;
case 0x0C: // Industry closure message
- indsp->closure_text = GRFMappedStringID(grf_load_word(&buf), _cur_grffile->grfid);
+ indsp->closure_text = grf_load_word(&buf);
+ _string_to_grf_mapping[&indsp->closure_text] = _cur_grffile->grfid;
break;
case 0x0D: // Production increase message
- indsp->production_up_text = GRFMappedStringID(grf_load_word(&buf), _cur_grffile->grfid);
+ indsp->production_up_text = grf_load_word(&buf);
+ _string_to_grf_mapping[&indsp->production_up_text] = _cur_grffile->grfid;
break;
case 0x0E: // Production decrease message
- indsp->production_down_text = GRFMappedStringID(grf_load_word(&buf), _cur_grffile->grfid);
+ indsp->production_down_text = grf_load_word(&buf);
+ _string_to_grf_mapping[&indsp->production_down_text] = _cur_grffile->grfid;
break;
case 0x0F: // Fund cost multiplier
@@ -2099,19 +2113,21 @@
break;
case 0x1B: // New industry text ID
- indsp->new_industry_text = GRFMappedStringID(grf_load_word(&buf), _cur_grffile->grfid);
+ indsp->new_industry_text = grf_load_word(&buf);
+ _string_to_grf_mapping[&indsp->new_industry_text] = _cur_grffile->grfid;
break;
case 0x1C: // Input cargo multipliers for the three input cargo types
case 0x1D:
case 0x1E: {
uint32 multiples = grf_load_dword(&buf);
- indsp->input_cargo_multiplier[prop - 0x1C][0] = GB(multiples, 0,15);
- indsp->input_cargo_multiplier[prop - 0x1C][1] = GB(multiples, 15,15);
+ indsp->input_cargo_multiplier[prop - 0x1C][0] = GB(multiples, 0, 15);
+ indsp->input_cargo_multiplier[prop - 0x1C][1] = GB(multiples, 15, 15);
} break;
case 0x1F: // Industry name
- indsp->name = GRFMappedStringID(grf_load_word(&buf), _cur_grffile->grfid);
+ indsp->name = grf_load_word(&buf);
+ _string_to_grf_mapping[&indsp->name] = _cur_grffile->grfid;
break;
case 0x20: // Prospecting success chance
@@ -2129,7 +2145,8 @@
break;
case 0x24: // name for nearby station
- indsp->station_name = GRFMappedStringID(grf_load_word(&buf), _cur_grffile->grfid);
+ indsp->station_name = grf_load_word(&buf);
+ _string_to_grf_mapping[&indsp->station_name] = _cur_grffile->grfid;
break;
default:
@@ -3254,7 +3271,7 @@
if (_cur_grffile->housespec == NULL || _cur_grffile->housespec[GB(id, 0, 8)] == NULL) {
grfmsg(1, "FeatureNewName: Attempt to name undefined house 0x%X, ignoring.", GB(id, 0, 8));
} else {
- _cur_grffile->housespec[GB(id, 0, 8)]->building_name = GRFMappedStringID(AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED), 0);
+ _cur_grffile->housespec[GB(id, 0, 8)]->building_name = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
}
break;
@@ -5487,7 +5504,6 @@
for (int i = 0; i < HOUSE_MAX; i++) {
HouseSpec *hs = file->housespec[i];
if (hs != NULL) {
- hs->building_name.MapString();
_house_mngr.SetEntitySpec(hs);
if (hs->min_date < min_date) min_date = hs->min_date;
}
@@ -5518,27 +5534,21 @@
/* process the conversion of text at the end, so to be sure everything will be fine
* and available. Check if it does not return undefind marker, which is a very good sign of a
* substitute industry who has not changed the string been examined, thus using it as such */
- indsp->name.MapString();
strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->name);
if (strid != STR_UNDEFINED) indsp->name = strid;
- indsp->closure_text.MapString();
strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->closure_text);
if (strid != STR_UNDEFINED) indsp->closure_text = strid;
- indsp->production_up_text.MapString();
strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->production_up_text);
if (strid != STR_UNDEFINED) indsp->production_up_text = strid;
- indsp->production_down_text.MapString();
strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->production_down_text);
if (strid != STR_UNDEFINED) indsp->production_down_text = strid;
- indsp->new_industry_text.MapString();
strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->new_industry_text);
if (strid != STR_UNDEFINED) indsp->new_industry_text = strid;
- indsp->station_name.MapString();
if (indsp->station_name != STR_NULL) {
/* STR_NULL (0) can be set by grf. It has a meaning regarding assignation of the
* station's name. Don't wont to loose the value, therefor, do not process. */
@@ -5581,12 +5591,6 @@
CargoSpec *cs = &_cargo[c];
/* Don't map if the cargo is unavailable or not from NewGRF */
if (cs->grfid == 0) continue;
-
- cs->name.MapString();
- cs->name_single.MapString();
- cs->units_volume.MapString();
- cs->quantifier.MapString();
- cs->abbrev.MapString();
}
}
@@ -5811,6 +5815,11 @@
static void AfterLoadGRFs()
{
+ for (StringIDToGRFIDMapping::iterator it = _string_to_grf_mapping.begin(); it != _string_to_grf_mapping.end(); it++) {
+ *((*it).first) = MapGRFStringID((*it).second, *((*it).first));
+ }
+ _string_to_grf_mapping.clear();
+
/* Update the bitmasks for the vehicle lists */
Player *p;
FOR_ALL_PLAYERS(p) {
@@ -5903,11 +5912,3 @@
{
return HasBit(_misc_grf_features, bit);
}
-
-void GRFMappedStringID::MapString()
-{
- if (this->grfid == 0) return;
-
- this->string = MapGRFStringID(this->grfid, this->string);
- this->grfid = 0;
-}
--- a/src/newgrf_industries.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/newgrf_industries.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -287,7 +287,7 @@
/* Distance of nearest industry of given type */
case 0x64: return GetClosestIndustry(tile, MapNewGRFIndustryType(parameter, indspec->grf_prop.grffile->grfid), industry);
/* Get town zone and Manhattan distance of closest town */
- case 0x65: return GetTownRadiusGroup(industry->town, tile) << 16 | min(DistanceManhattan(tile, industry->town->xy), 0xFFFF);
+ case 0x65: return GetTownRadiusGroup(industry->town, tile) << 16 | min(DistanceManhattan(tile, industry->town->xy), 0xFFFF);
/* Get square of Euclidian distance of closes town */
case 0x66: return GetTownRadiusGroup(industry->town, tile) << 16 | min(DistanceSquare(tile, industry->town->xy), 0xFFFF);
--- a/src/newgrf_industrytiles.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/newgrf_industrytiles.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -279,7 +279,7 @@
return !IsSlopeRefused(GetTileSlope(ind_tile, NULL), its->slopes_refused);
}
if (its->grf_prop.grffile->grf_version < 7) {
- return (callback_res & 0xFF) != 0; // mask to 8 bit callback result
+ return callback_res != 0;
}
/* Copy some parameters from the registers to the error message text ref. stack */
--- a/src/newgrf_spritegroup.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/newgrf_spritegroup.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -97,7 +97,7 @@
case CBID_INDTILE_ACCEPT_CARGO:
case CBID_VEHICLE_COLOUR_MAPPING:
case CBID_HOUSE_PRODUCE_CARGO:
- case CBID_INDTILE_SHAPE_CHECK: // depends on grf version, masked to 8 bit in PerformIndustryTileSlopeCheck() if needed
+ case CBID_INDTILE_SHAPE_CHECK:
case CBID_VEHICLE_SOUND_EFFECT:
case CBID_VEHICLE_MODIFY_PROPERTY: // depends on queried property
case CBID_CARGO_PROFIT_CALC:
--- a/src/newgrf_station.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/newgrf_station.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -420,9 +420,16 @@
if (!HasBit(_svc.valid, 5)) { _svc.v49 = GetPlatformInfoHelper(tile, false, true, false); SetBit(_svc.valid, 5); }
return _svc.v49;
+ case 0x4A: // Animation frame of tile
+ return GetStationAnimationFrame(tile);
+
/* Variables which use the parameter */
/* Variables 0x60 to 0x65 are handled separately below */
- case 0x67: { // Land info of nearby tiles
+ case 0x66: // Animation frame of nearby tile
+ if (parameter != 0) tile = GetNearbyTile(parameter, tile);
+ return st->TileBelongsToRailStation(tile) ? GetStationAnimationFrame(tile) : UINT_MAX;
+
+ case 0x67: { // Land info of nearby tile
Axis axis = GetRailStationAxis(tile);
if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required
--- a/src/newgrf_string_type.h Thu Apr 17 08:40:01 2008 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-/* $Id$ */
-
-/** @file newgrf_string_type.h */
-
-#ifndef NEWGRF_STRING_TYPE_H
-#define NEWGRF_STRING_TYPE_H
-
-#include "strings_type.h"
-
-/**
- * A string with the required information to perform a GRF string remapping.
- */
-struct GRFMappedStringID
-{
-private:
- /** The GRF ID associated to the to-be-remapped string */
- uint32 grfid;
- /** The string; when grfid != 0 it should be remapped */
- StringID string;
-
-public:
- /**
- * Create the struct.
- * @param str the string to store (or remap)
- * @param grf_id the GRF to remap it with
- */
- GRFMappedStringID(StringID str, uint32 grf_id) : grfid(grf_id), string(str) {}
-
- /**
- * An empty string.
- */
- GRFMappedStringID() {}
-
- /** Cast operator, returns the string */
- inline operator StringID() const
- {
- return string;
- }
-
- /** Assigns the string and resets the GRF ID. */
- GRFMappedStringID& operator = (StringID str)
- {
- string = str;
- grfid = 0;
- return *this;
- }
-
- /**
- * Map the string.
- */
- void MapString();
-};
-
-#endif /* NEWGRF_STRING_TYPE_H */
--- a/src/newgrf_town.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/newgrf_town.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -36,16 +36,16 @@
case 0x8A: return t->grow_counter;
case 0x92: return t->flags12; // In original game, 0x92 and 0x93 are really one word. Since flags12 is a byte, this is to adjust
case 0x93: return 0;
- case 0x94: return t->radius[0];
- case 0x95: return GB(t->radius[0], 8, 8);
- case 0x96: return t->radius[1];
- case 0x97: return GB(t->radius[1], 8, 8);
- case 0x98: return t->radius[2];
- case 0x99: return GB(t->radius[2], 8, 8);
- case 0x9A: return t->radius[3];
- case 0x9B: return GB(t->radius[3], 8, 8);
- case 0x9C: return t->radius[4];
- case 0x9D: return GB(t->radius[4], 8, 8);
+ case 0x94: return ClampToU16(t->squared_town_zone_radius[0]);
+ case 0x95: return GB(ClampToU16(t->squared_town_zone_radius[0]), 8, 8);
+ case 0x96: return ClampToU16(t->squared_town_zone_radius[1]);
+ case 0x97: return GB(ClampToU16(t->squared_town_zone_radius[1]), 8, 8);
+ case 0x98: return ClampToU16(t->squared_town_zone_radius[2]);
+ case 0x99: return GB(ClampToU16(t->squared_town_zone_radius[2]), 8, 8);
+ case 0x9A: return ClampToU16(t->squared_town_zone_radius[3]);
+ case 0x9B: return GB(ClampToU16(t->squared_town_zone_radius[3]), 8, 8);
+ case 0x9C: return ClampToU16(t->squared_town_zone_radius[4]);
+ case 0x9D: return GB(ClampToU16(t->squared_town_zone_radius[4]), 8, 8);
case 0x9E: return t->ratings[0];
case 0x9F: return GB(t->ratings[0], 8, 8);
case 0xA0: return t->ratings[1];
--- a/src/news_gui.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/news_gui.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -60,7 +60,7 @@
static NewsID _oldest_news = 0; ///< points to first item in fifo queue
static NewsID _latest_news = INVALID_NEWS; ///< points to last item in fifo queue
-struct news_d {
+struct news_d : vp_d {
uint16 follow_vehicle;
int32 scrollpos_x;
int32 scrollpos_y;
@@ -402,20 +402,20 @@
};
static const SoundFx _news_sounds[NT_END] = {
- SND_1D_APPLAUSE, ///< NT_ARRIVAL_PLAYER
- SND_1D_APPLAUSE, ///< NT_ARRIVAL_OTHER
- SND_BEGIN, ///< NT_ACCIDENT
- SND_BEGIN, ///< NT_COMPANY_INFO
- SND_BEGIN, ///< NT_OPENCLOSE
- SND_BEGIN, ///< NT_ECONOMY
- SND_BEGIN, ///< NT_INDUSTRY_PLAYER
- SND_BEGIN, ///< NT_INDUSTRY_OTHER
- SND_BEGIN, ///< NT_INDUSTRY_NOBODY
- SND_BEGIN, ///< NT_ADVICE
- SND_1E_OOOOH, ///< NT_NEW_VEHICLES
- SND_BEGIN, ///< NT_ACCEPTANCE
- SND_BEGIN, ///< NT_SUBSIDIES
- SND_BEGIN, ///< NT_GENERAL
+ SND_1D_APPLAUSE, ///< NT_ARRIVAL_PLAYER
+ SND_1D_APPLAUSE, ///< NT_ARRIVAL_OTHER
+ SND_BEGIN, ///< NT_ACCIDENT
+ SND_BEGIN, ///< NT_COMPANY_INFO
+ SND_BEGIN, ///< NT_OPENCLOSE
+ SND_BEGIN, ///< NT_ECONOMY
+ SND_BEGIN, ///< NT_INDUSTRY_PLAYER
+ SND_BEGIN, ///< NT_INDUSTRY_OTHER
+ SND_BEGIN, ///< NT_INDUSTRY_NOBODY
+ SND_BEGIN, ///< NT_ADVICE
+ SND_1E_OOOOH, ///< NT_NEW_VEHICLES
+ SND_BEGIN, ///< NT_ACCEPTANCE
+ SND_BEGIN, ///< NT_SUBSIDIES
+ SND_BEGIN, ///< NT_GENERAL
};
const char *_news_display_name[NT_END] = {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/news_gui.h Fri Apr 18 23:33:51 2008 +0000
@@ -0,0 +1,12 @@
+/* $Id$ */
+
+/** @file news_gui.h GUI functions related to the news. */
+
+#ifndef NEWS_GUI_H
+#define NEWS_GUI_H
+
+void ShowLastNewsMessage();
+void ShowMessageOptions();
+void ShowMessageHistory();
+
+#endif /* NEWS_GUI_H */
--- a/src/npf.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/npf.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -14,7 +14,8 @@
#include "pathfind.h"
#include "station_base.h"
#include "station_map.h"
-#include "depot.h"
+#include "depot_base.h"
+#include "depot_map.h"
#include "tunnel_map.h"
#include "network/network.h"
#include "water_map.h"
@@ -231,14 +232,14 @@
switch (GetTileType(tile)) {
case MP_RAILWAY:
/* DEBUG: mark visited tiles by mowing the grass under them ;-) */
- if (!IsTileDepotType(tile, TRANSPORT_RAIL)) {
+ if (!IsRailDepot(tile)) {
SetRailGroundType(tile, RAIL_GROUND_BARREN);
MarkTileDirtyByTile(tile);
}
break;
case MP_ROAD:
- if (!IsTileDepotType(tile, TRANSPORT_ROAD)) {
+ if (!IsRoadDepot(tile)) {
SetRoadside(tile, ROADSIDE_BARREN);
MarkTileDirtyByTile(tile);
}
@@ -397,7 +398,7 @@
* curves should be taken into account, as this affects the speed limit. */
/* Check for reverse in depot */
- if (IsTileDepotType(tile, TRANSPORT_RAIL) && as->EndNodeCheck(as, &new_node) != AYSTAR_FOUND_END_NODE) {
+ if (IsRailDepotTile(tile) && as->EndNodeCheck(as, &new_node) != AYSTAR_FOUND_END_NODE) {
/* Penalise any depot tile that is not the last tile in the path. This
* _should_ penalise every occurence of reversing in a depot (and only
* that) */
@@ -417,7 +418,7 @@
{
/* It's not worth caching the result with NPF_FLAG_IS_TARGET here as below,
* since checking the cache not that much faster than the actual check */
- return IsTileDepotType(current->path.node.tile, (TransportType)as->user_data[NPF_TYPE]) ?
+ return IsDepotTypeTile(current->path.node.tile, (TransportType)as->user_data[NPF_TYPE]) ?
AYSTAR_FOUND_END_NODE : AYSTAR_DONE;
}
@@ -464,9 +465,9 @@
*/
static bool CanEnterTileOwnerCheck(Owner owner, TileIndex tile, DiagDirection enterdir)
{
- if (IsTileType(tile, MP_RAILWAY) || /* Rail tile (also rail depot) */
- IsRailwayStationTile(tile) || /* Rail station tile */
- IsTileDepotType(tile, TRANSPORT_ROAD) || /* Road depot tile */
+ if (IsTileType(tile, MP_RAILWAY) || /* Rail tile (also rail depot) */
+ IsRailwayStationTile(tile) || /* Rail station tile */
+ IsRoadDepotTile(tile) || /* Road depot tile */
IsStandardRoadStopTile(tile)) { /* Road station tile (but not drive-through stops) */
return IsTileOwner(tile, owner); /* You need to own these tiles entirely to use them */
}
@@ -499,7 +500,7 @@
*/
static DiagDirection GetDepotDirection(TileIndex tile, TransportType type)
{
- assert(IsTileDepotType(tile, type));
+ assert(IsDepotTypeTile(tile, type));
switch (type) {
case TRANSPORT_RAIL: return GetRailDepotDirection(tile);
@@ -537,7 +538,7 @@
*/
static DiagDirection GetTileSingleEntry(TileIndex tile, TransportType type, uint subtype)
{
- if (type != TRANSPORT_WATER && IsTileDepotType(tile, type)) return GetDepotDirection(tile, type);
+ if (type != TRANSPORT_WATER && IsDepotTypeTile(tile, type)) return GetDepotDirection(tile, type);
if (type == TRANSPORT_ROAD) {
if (IsStandardRoadStopTile(tile)) return GetRoadStopDir(tile);
@@ -879,7 +880,7 @@
FOR_ALL_DEPOTS(depot) {
/* Check if this is really a valid depot, it is of the needed type and
* owner */
- if (IsTileDepotType(depot->xy, type) && IsTileOwner(depot->xy, owner))
+ if (IsDepotTypeTile(depot->xy, type) && IsTileOwner(depot->xy, owner))
/* If so, let's add it to the queue, sorted by distance */
depots.push(&depots, depot, DistanceManhattan(tile, depot->xy));
}
--- a/src/oldloader.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/oldloader.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -15,7 +15,7 @@
#include "train.h"
#include "signs_base.h"
#include "debug.h"
-#include "depot.h"
+#include "depot_base.h"
#include "newgrf_config.h"
#include "ai/ai.h"
#include "zoom_func.h"
@@ -1326,6 +1326,7 @@
return !ls->failed;
}
+extern TileIndex _cur_tileloop_tile;
static uint32 _old_cur_town_ctr;
static const OldChunks main_chunk[] = {
OCL_ASSERT( 0 ),
--- a/src/openttd.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/openttd.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -47,7 +47,6 @@
#include "network/network.h"
#include "signs_base.h"
#include "signs_func.h"
-#include "depot.h"
#include "waypoint.h"
#include "ai/ai.h"
#include "train.h"
@@ -59,6 +58,7 @@
#include "strings_func.h"
#include "date_func.h"
#include "vehicle_func.h"
+#include "cheat_func.h"
#include "newgrf.h"
#include "newgrf_config.h"
@@ -86,6 +86,8 @@
#include "table/strings.h"
+StringID _switch_mode_errorstr;
+
void CallLandscapeTick();
void IncreaseDate();
void DoPaletteAnimations();
@@ -264,8 +266,8 @@
return;
}
- res[0] = Clamp(strtoul(s, NULL, 0), 64, MAX_SCREEN_WIDTH);
- res[1] = Clamp(strtoul(t + 1, NULL, 0), 64, MAX_SCREEN_HEIGHT);
+ res[0] = max(strtoul(s, NULL, 0), 64UL);
+ res[1] = max(strtoul(t + 1, NULL, 0), 64UL);
}
static void InitializeDynamicVariables()
@@ -1884,7 +1886,7 @@
}
/* Clear PBS reservation on track */
- if (!IsTileDepotType(t, TRANSPORT_RAIL)) {
+ if (!IsRailDepotTile(t)) {
SB(_m[t].m4, 4, 4, 0);
} else {
ClrBit(_m[t].m3, 6);
--- a/src/openttd.h Thu Apr 17 08:40:01 2008 +0000
+++ b/src/openttd.h Fri Apr 18 23:33:51 2008 +0000
@@ -97,11 +97,6 @@
extern byte _savegame_sort_order;
-enum {
- MAX_SCREEN_WIDTH = 2048,
- MAX_SCREEN_HEIGHT = 1200,
-};
-
/* In certain windows you navigate with the arrow keys. Do not scroll the
* gameview when here. Bitencoded variable that only allows scrolling if all
* elements are zero */
--- a/src/order_cmd.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/order_cmd.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -7,7 +7,7 @@
#include "order_base.h"
#include "order_func.h"
#include "airport.h"
-#include "depot.h"
+#include "order_base.h"
#include "waypoint.h"
#include "command_func.h"
#include "player_func.h"
@@ -26,6 +26,7 @@
#include "timetable.h"
#include "vehicle_func.h"
#include "oldpool_func.h"
+#include "depot_base.h"
#include "table/strings.h"
@@ -392,15 +393,15 @@
switch (v->type) {
case VEH_TRAIN:
- if (!IsTileDepotType(dp->xy, TRANSPORT_RAIL)) return CMD_ERROR;
+ if (!IsRailDepotTile(dp->xy)) return CMD_ERROR;
break;
case VEH_ROAD:
- if (!IsTileDepotType(dp->xy, TRANSPORT_ROAD)) return CMD_ERROR;
+ if (!IsRoadDepotTile(dp->xy)) return CMD_ERROR;
break;
case VEH_SHIP:
- if (!IsTileDepotType(dp->xy, TRANSPORT_WATER)) return CMD_ERROR;
+ if (!IsShipDepotTile(dp->xy)) return CMD_ERROR;
break;
default: return CMD_ERROR;
@@ -1614,7 +1615,7 @@
}
/* Check if we've reached a non-stop station.. */
- if ((v->current_order.GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) &&
+ if (v->current_order.IsType(OT_GOTO_STATION) && (v->current_order.GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) &&
IsTileType(v->tile, MP_STATION) &&
v->current_order.GetDestination() == GetStationIndex(v->tile)) {
v->last_station_visited = v->current_order.GetDestination();
@@ -1742,10 +1743,11 @@
*/
bool Order::ShouldStopAtStation(const Vehicle *v, StationID station) const
{
+ bool is_dest_station = this->IsType(OT_GOTO_STATION) && this->dest == station;
return
v->last_station_visited != station && // Do stop only when we've not just been there
/* Finally do stop when there is no non-stop flag set for this type of station. */
- !(this->GetNonStopType() & ((this->dest == station) ? ONSF_NO_STOP_AT_DESTINATION_STATION : ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS));
+ !(this->GetNonStopType() & (is_dest_station ? ONSF_NO_STOP_AT_DESTINATION_STATION : ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS));
}
void InitializeOrders()
--- a/src/order_gui.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/order_gui.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -13,7 +13,7 @@
#include "command_func.h"
#include "viewport_func.h"
#include "gfx_func.h"
-#include "depot.h"
+#include "depot_base.h"
#include "waypoint.h"
#include "train.h"
#include "water_map.h"
@@ -29,6 +29,7 @@
#include "widgets/dropdown_func.h"
#include "textbuf_gui.h"
#include "string_func.h"
+#include "depot_base.h"
#include "table/sprites.h"
#include "table/strings.h"
@@ -462,8 +463,7 @@
case MP_WATER:
if (v->type != VEH_SHIP) break;
- if (IsTileDepotType(tile, TRANSPORT_WATER) &&
- IsTileOwner(tile, _local_player)) {
+ if (IsShipDepot(tile) && IsTileOwner(tile, _local_player)) {
TileIndex tile2 = GetOtherShipDepotTile(tile);
order.MakeGoToDepot(GetDepotByTile(tile < tile2 ? tile : tile2)->index, ODTFB_PART_OF_ORDERS);
@@ -541,7 +541,7 @@
if (!cmd.IsValid()) return;
if (DoCommandP(v->tile, v->index + (OrderGetSel(w) << 16), cmd.Pack(), NULL, CMD_INSERT_ORDER | CMD_MSG(STR_8833_CAN_T_INSERT_NEW_ORDER))) {
- if (WP(w, order_d).sel != -1) WP(w,order_d).sel++;
+ if (WP(w, order_d).sel != -1) WP(w, order_d).sel++;
ResetObjectToPlace();
}
}
@@ -1087,7 +1087,7 @@
static const WindowDesc _orders_train_desc = {
WDP_AUTO, WDP_AUTO, 386, 100, 386, 100,
- WC_VEHICLE_ORDERS,WC_VEHICLE_VIEW,
+ WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_RESIZABLE,
_orders_train_widgets,
OrdersWndProc
@@ -1128,7 +1128,7 @@
static const WindowDesc _orders_desc = {
WDP_AUTO, WDP_AUTO, 386, 100, 386, 100,
- WC_VEHICLE_ORDERS,WC_VEHICLE_VIEW,
+ WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_RESIZABLE,
_orders_widgets,
OrdersWndProc
@@ -1169,7 +1169,7 @@
static const WindowDesc _other_orders_desc = {
WDP_AUTO, WDP_AUTO, 386, 88, 386, 88,
- WC_VEHICLE_ORDERS,WC_VEHICLE_VIEW,
+ WC_VEHICLE_ORDERS, WC_VEHICLE_VIEW,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
_other_orders_widgets,
OrdersWndProc
--- a/src/pathfind.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/pathfind.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -6,7 +6,6 @@
#include "openttd.h"
#include "bridge_map.h"
#include "station_map.h"
-#include "depot.h"
#include "tile_cmd.h"
#include "landscape.h"
#include "pathfind.h"
@@ -14,7 +13,6 @@
#include "debug.h"
#include "tunnel_map.h"
#include "settings_type.h"
-#include "depot.h"
#include "tunnelbridge_map.h"
#include "core/random_func.hpp"
#include "core/alloc_type.hpp"
@@ -170,10 +168,10 @@
{
if (tracktype == TRANSPORT_RAIL) {
/* depot from wrong side */
- if (IsTileDepotType(tile, TRANSPORT_RAIL) && GetRailDepotDirection(tile) != side) return false;
+ if (IsRailDepotTile(tile) && GetRailDepotDirection(tile) != side) return false;
} else if (tracktype == TRANSPORT_ROAD) {
/* depot from wrong side */
- if (IsTileDepotType(tile, TRANSPORT_ROAD) && GetRoadDepotDirection(tile) != side) return false;
+ if (IsRoadDepotTile(tile) && GetRoadDepotDirection(tile) != side) return false;
/* non-driverthrough road station from wrong side */
if (IsStandardRoadStopTile(tile) && GetRoadStopDir(tile) != side) return false;
}
--- a/src/player_gui.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/player_gui.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -58,9 +58,9 @@
if (!(mode & 1)) { // normal sized economics window (mode&1) is minimized status
/* draw categories */
DrawStringCenterUnderline(61, 15, STR_700F_EXPENDITURE_INCOME, TC_FROMSTRING);
- for (i = 0; i != 13; i++)
+ for (i = 0; i != EXPENSES_END; i++)
DrawString(2, 27 + i * 10, STR_7011_CONSTRUCTION + i, TC_FROMSTRING);
- DrawStringRightAligned(111, 27 + 10 * 13 + 2, STR_7020_TOTAL, TC_FROMSTRING);
+ DrawStringRightAligned(111, 27 + 10 * EXPENSES_END + 2, STR_7020_TOTAL, TC_FROMSTRING);
/* draw the price columns */
year = _cur_year - 2;
@@ -72,7 +72,7 @@
SetDParam(0, year);
DrawStringRightAlignedUnderline(x, 15, STR_7010, TC_FROMSTRING);
sum = 0;
- for (i = 0; i != 13; i++) {
+ for (i = 0; i != EXPENSES_END; i++) {
/* draw one row in the price column */
cost = (*tbl)[i];
if (cost != 0) {
@@ -88,16 +88,16 @@
str = STR_701E;
if (sum < 0) { sum = -sum; str++; }
SetDParam(0, sum);
- DrawStringRightAligned(x, 27 + 13 * 10 + 2, str, TC_FROMSTRING);
+ DrawStringRightAligned(x, 27 + EXPENSES_END * 10 + 2, str, TC_FROMSTRING);
- GfxFillRect(x - 75, 27 + 10 * 13, x, 27 + 10 * 13, 215);
+ GfxFillRect(x - 75, 27 + 10 * EXPENSES_END, x, 27 + 10 * EXPENSES_END, 215);
x += 95;
}
year++;
tbl--;
} while (--j != 0);
- y = 171;
+ y = 27 + 10 * EXPENSES_END + 14;
/* draw max loan aligned to loan below (y += 10) */
SetDParam(0, _economy.max_loan);
@@ -135,10 +135,10 @@
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 379, 0, 13, STR_700E_FINANCES, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_IMGBTN, RESIZE_NONE, 14, 380, 394, 0, 13, SPR_LARGE_SMALL_WINDOW, STR_7075_TOGGLE_LARGE_SMALL_WINDOW},
{ WWT_STICKYBOX, RESIZE_NONE, 14, 395, 406, 0, 13, 0x0, STR_STICKY_BUTTON},
-{ WWT_PANEL, RESIZE_NONE, 14, 0, 406, 14, 169, 0x0, STR_NULL},
-{ WWT_PANEL, RESIZE_NONE, 14, 0, 406, 170, 203, 0x0, STR_NULL},
-{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 202, 204, 215, STR_7029_BORROW, STR_7035_INCREASE_SIZE_OF_LOAN},
-{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 203, 406, 204, 215, STR_702A_REPAY, STR_7036_REPAY_PART_OF_LOAN},
+{ WWT_PANEL, RESIZE_NONE, 14, 0, 406, 14, 39 + 10 * EXPENSES_END, 0x0, STR_NULL},
+{ WWT_PANEL, RESIZE_NONE, 14, 0, 406, 40 + 10 * EXPENSES_END, 73 + 10 * EXPENSES_END, 0x0, STR_NULL},
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 202, 74 + 10 * EXPENSES_END, 85 + 10 * EXPENSES_END, STR_7029_BORROW, STR_7035_INCREASE_SIZE_OF_LOAN},
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 203, 406, 74 + 10 * EXPENSES_END, 85 + 10 * EXPENSES_END, STR_702A_REPAY, STR_7036_REPAY_PART_OF_LOAN},
{ WIDGETS_END},
};
@@ -163,7 +163,7 @@
const Player *p = GetPlayer(player);
/* Recheck the size of the window as it might need to be resized due to the local player changing */
- int new_height = ((player != _local_player) ? 0 : 12) + ((WP(w, def_d).data_1 != 0) ? 48 : 204);
+ int new_height = ((player != _local_player) ? 0 : 12) + ((WP(w, def_d).data_1 != 0) ? 48 : 74 + 10 * EXPENSES_END);
if (w->height != new_height) {
/* Make window dirty before and after resizing */
SetWindowDirty(w);
@@ -216,7 +216,7 @@
}
static const WindowDesc _player_finances_desc = {
- WDP_AUTO, WDP_AUTO, 407, 216, 407, 216,
+ WDP_AUTO, WDP_AUTO, 407, 86 + 10 * EXPENSES_END, 407, 86 + 10 * EXPENSES_END,
WC_FINANCES, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
_player_finances_widgets,
--- a/src/players.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/players.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -14,6 +14,7 @@
#include "network/network.h"
#include "network/network_internal.h"
#include "variables.h"
+#include "cheat_func.h"
#include "ai/ai.h"
#include "player_face.h"
#include "group.h"
@@ -312,7 +313,7 @@
t = ClosestTownFromTile(tile, (uint)-1);
- if (IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST+1)) {
+ if (IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST + 1)) {
str = t->townnametype - SPECSTR_TOWNNAME_START + SPECSTR_PLAYERNAME_START;
strp = t->townnameparts;
@@ -351,7 +352,7 @@
}
}
-#define COLOR_SWAP(i,j) do { byte t=colors[i];colors[i]=colors[j];colors[j]=t; } while(0)
+#define COLOR_SWAP(i, j) do { byte t = colors[i];colors[i] = colors[j];colors[j] = t; } while(0)
static const byte _color_sort[16] = {2, 2, 3, 2, 3, 2, 3, 2, 3, 2, 2, 2, 3, 1, 1, 1};
static const byte _color_similar_1[16] = {8, 6, 255, 12, 255, 0, 1, 1, 0, 13, 11, 10, 3, 9, 15, 14};
@@ -360,7 +361,7 @@
static byte GeneratePlayerColor()
{
byte colors[16], pcolor, t2;
- int i,j,n;
+ int i, j, n;
uint32 r;
Player *p;
@@ -387,14 +388,14 @@
/* Move the colors that look similar to each player's color to the side */
FOR_ALL_PLAYERS(p) if (p->is_active) {
pcolor = p->player_color;
- for (i=0; i!=16; i++) if (colors[i] == pcolor) {
+ for (i = 0; i != 16; i++) if (colors[i] == pcolor) {
colors[i] = 0xFF;
t2 = _color_similar_1[pcolor];
if (t2 == 0xFF) break;
- for (i=0; i!=15; i++) {
+ for (i = 0; i != 15; i++) {
if (colors[i] == t2) {
- do COLOR_SWAP(i,i+1); while (++i != 15);
+ do COLOR_SWAP(i, i + 1); while (++i != 15);
break;
}
}
@@ -716,7 +717,7 @@
cost = AddEngineReplacementForPlayer(p, old_engine_type, new_engine_type, id_g, flags);
} else {
- cost = RemoveEngineReplacementForPlayer(p, old_engine_type,id_g, flags);
+ cost = RemoveEngineReplacementForPlayer(p, old_engine_type, id_g, flags);
}
if (IsLocalPlayer()) InvalidateAutoreplaceWindow(old_engine_type, id_g);
@@ -951,19 +952,6 @@
return _endgame_perf_titles[value];
}
-/** Return true if any cheat has been used, false otherwise */
-static bool CheatHasBeenUsed()
-{
- const Cheat* cht = (Cheat*)&_cheats;
- const Cheat* cht_last = &cht[sizeof(_cheats) / sizeof(Cheat)];
-
- for (; cht != cht_last; cht++) {
- if (cht->been_used) return true;
- }
-
- return false;
-}
-
/** Save the highscore for the player */
int8 SaveHighScoreValue(const Player *p)
{
@@ -1096,8 +1084,8 @@
SLE_VAR(Player, name_1, SLE_STRINGID),
SLE_CONDSTR(Player, name, SLE_STR, 0, 84, SL_MAX_VERSION),
- SLE_VAR(Player, president_name_1,SLE_UINT16),
- SLE_VAR(Player, president_name_2,SLE_UINT32),
+ SLE_VAR(Player, president_name_1, SLE_UINT16),
+ SLE_VAR(Player, president_name_2, SLE_UINT32),
SLE_CONDSTR(Player, president_name, SLE_STR, 0, 84, SL_MAX_VERSION),
SLE_VAR(Player, face, SLE_UINT32),
--- a/src/rail_cmd.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/rail_cmd.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -20,7 +20,8 @@
#include "engine_func.h"
#include "town.h"
#include "sprite.h"
-#include "depot.h"
+#include "depot_base.h"
+#include "depot_func.h"
#include "waypoint.h"
#include "rail.h"
#include "newgrf.h"
@@ -40,6 +41,8 @@
#include "sound_func.h"
#include "signal_func.h"
#include "tunnelbridge.h"
+#include "station_map.h"
+#include "water_map.h"
#include "table/sprites.h"
#include "table/strings.h"
@@ -2267,7 +2270,7 @@
int length;
/* this routine applies only to trains in depot tiles */
- if (v->type != VEH_TRAIN || !IsTileDepotType(tile, TRANSPORT_RAIL)) return VETSB_CONTINUE;
+ if (v->type != VEH_TRAIN || !IsRailDepotTile(tile)) return VETSB_CONTINUE;
/* depot direction */
dir = GetRailDepotDirection(tile);
--- a/src/rail_gui.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/rail_gui.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -29,6 +29,7 @@
#include "settings_type.h"
#include "widgets/dropdown_type.h"
#include "widgets/dropdown_func.h"
+#include "tunnelbridge.h"
#include "bridge_map.h"
#include "rail_map.h"
--- a/src/rail_map.h Thu Apr 17 08:40:01 2008 +0000
+++ b/src/rail_map.h Fri Apr 18 23:33:51 2008 +0000
@@ -72,7 +72,18 @@
}
/**
- * Is this tile a rail depot?
+ * Is this rail tile a rail waypoint?
+ * @param t the tile to get the information from
+ * @pre IsTileType(t, MP_RAILWAY)
+ * @return true if and only if the tile is a rail waypoint
+ */
+static inline bool IsRailWaypoint(TileIndex t)
+{
+ return GetRailTileType(t) == RAIL_TILE_WAYPOINT;
+}
+
+/**
+ * Is this rail tile a rail depot?
* @param t the tile to get the information from
* @pre IsTileType(t, MP_RAILWAY)
* @return true if and only if the tile is a rail depot
@@ -83,17 +94,16 @@
}
/**
- * Is this tile a rail waypoint?
+ * Is this tile rail tile and a rail depot?
* @param t the tile to get the information from
* @pre IsTileType(t, MP_RAILWAY)
- * @return true if and only if the tile is a rail waypoint
+ * @return true if and only if the tile is a rail depot
*/
-static inline bool IsRailWaypoint(TileIndex t)
+static inline bool IsRailDepotTile(TileIndex t)
{
- return GetRailTileType(t) == RAIL_TILE_WAYPOINT;
+ return IsTileType(t, MP_RAILWAY) && IsRailDepot(t);
}
-
/**
* Gets the rail type of the given tile
* @param t the tile to get the rail type from
--- a/src/road_cmd.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/road_cmd.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -18,7 +18,8 @@
#include "command_func.h"
#include "town.h"
#include "yapf/yapf.h"
-#include "depot.h"
+#include "depot_base.h"
+#include "depot_func.h"
#include "newgrf.h"
#include "station_map.h"
#include "tunnel_map.h"
@@ -34,6 +35,7 @@
#include "sound_func.h"
#include "road_func.h"
#include "tunnelbridge.h"
+#include "cheat_func.h"
#include "table/sprites.h"
#include "table/strings.h"
--- a/src/road_gui.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/road_gui.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -22,6 +22,7 @@
#include "sound_func.h"
#include "player_func.h"
#include "settings_type.h"
+#include "tunnelbridge.h"
#include "table/sprites.h"
#include "table/strings.h"
--- a/src/road_map.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/road_map.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -9,7 +9,6 @@
#include "road_map.h"
#include "tunnel_map.h"
#include "station_map.h"
-#include "depot.h"
#include "tunnelbridge_map.h"
--- a/src/roadveh_cmd.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/roadveh_cmd.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -17,7 +17,6 @@
#include "npf.h"
#include "player_func.h"
#include "player_base.h"
-#include "depot.h"
#include "bridge.h"
#include "tunnel_map.h"
#include "bridge_map.h"
@@ -42,6 +41,8 @@
#include "ai/ai.h"
#include "settings_type.h"
#include "order_func.h"
+#include "depot_base.h"
+#include "depot_func.h"
#include "table/strings.h"
@@ -179,7 +180,7 @@
/* The ai_new queries the vehicle cost before building the route,
* so we must check against cheaters no sooner than now. --pasky */
- if (!IsTileDepotType(tile, TRANSPORT_ROAD)) return CMD_ERROR;
+ if (!IsRoadDepotTile(tile)) return CMD_ERROR;
if (!IsTileOwner(tile, _current_player)) return CMD_ERROR;
if (HasTileRoadType(tile, ROADTYPE_TRAM) != HasBit(EngInfo(p1)->misc_flags, EF_ROAD_TRAM)) return_cmd_error(STR_DEPOT_WRONG_DEPOT_TYPE);
@@ -341,7 +342,7 @@
{
TileIndex tile = v->tile;
- if (!IsTileDepotType(tile, TRANSPORT_ROAD)) return false;
+ if (!IsRoadDepotTile(tile)) return false;
if (IsRoadVehFront(v) && !(v->vehstatus & VS_STOPPED)) return false;
for (; v != NULL; v = v->Next()) {
@@ -1295,7 +1296,7 @@
v->cur_image = v->GetImage(v->direction);
v->UpdateDeltaXY(v->direction);
- SetRoadVehPosition(v,x,y);
+ SetRoadVehPosition(v, x, y);
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
@@ -1392,7 +1393,7 @@
Direction new_dir;
Direction old_dir;
RoadDriveEntry rd;
- int x,y;
+ int x, y;
uint32 r;
if (v->u.road.overtaking != 0) {
@@ -1433,7 +1434,7 @@
/* Vehicle has just entered a bridge or tunnel */
v->cur_image = v->GetImage(v->direction);
v->UpdateDeltaXY(v->direction);
- SetRoadVehPosition(v,gp.x,gp.y);
+ SetRoadVehPosition(v, gp.x, gp.y);
return true;
}
--- a/src/roadveh_gui.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/roadveh_gui.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -11,7 +11,6 @@
#include "viewport_func.h"
#include "gfx_func.h"
#include "command_func.h"
-#include "depot.h"
#include "vehicle_gui.h"
#include "newgrf_engine.h"
#include "strings_func.h"
--- a/src/saveload.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/saveload.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -343,7 +343,7 @@
/* Ugly encoding of >16M RIFF chunks
* The lower 24 bits are normal
* The uppermost 4 bits are bits 24:27 */
- assert(length < (1<<28));
+ assert(length < (1 << 28));
SlWriteUint32((length & 0xFFFFFF) | ((length >> 24) << 28));
break;
case CH_ARRAY:
@@ -1218,7 +1218,7 @@
z->avail_out = sizeof(buf);
r = deflate(z, mode);
/* bytes were emitted? */
- if ((n=sizeof(buf) - z->avail_out) != 0) {
+ if ((n = sizeof(buf) - z->avail_out) != 0) {
if (fwrite(buf, n, 1, _sl.fh) != 1) SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE);
}
if (r == Z_STREAM_END)
@@ -1248,6 +1248,7 @@
/* these define the chunks */
extern const ChunkHandler _misc_chunk_handlers[];
+extern const ChunkHandler _cheat_chunk_handlers[] ;
extern const ChunkHandler _setting_chunk_handlers[];
extern const ChunkHandler _player_chunk_handlers[];
extern const ChunkHandler _engine_chunk_handlers[];
@@ -1267,6 +1268,7 @@
static const ChunkHandler * const _chunk_handlers[] = {
_misc_chunk_handlers,
+ _cheat_chunk_handlers,
_setting_chunk_handlers,
_veh_chunk_handlers,
_waypoint_chunk_handlers,
--- a/src/settings.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/settings.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -83,7 +83,7 @@
static bool IsSignedVarMemType(VarType vt);
struct SettingsMemoryPool {
- uint pos,size;
+ uint pos, size;
SettingsMemoryPool *next;
byte mem[1];
};
@@ -242,7 +242,7 @@
/* trim whitespace from right side. */
e = s + strlen(s);
- while (e > s && ((c=e[-1]) == '\n' || c == '\r' || c == ' ' || c == '\t')) e--;
+ while (e > s && ((c = e[-1]) == '\n' || c == '\r' || c == ' ' || c == '\t')) e--;
*e = '\0';
/* skip comments and empty lines */
@@ -253,7 +253,7 @@
/* add to comment */
if (ns > a) {
a = max(a, 128U);
- do a*=2; while (a < ns);
+ do a *= 2; while (a < ns);
comment = ReallocT(comment, comment_alloc = a);
}
pos = comment_size;
--- a/src/settings_gui.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/settings_gui.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -64,7 +64,7 @@
{
static StringID buf[32 + 1];
StringID *p = buf;
- while (--num>=0) *p++ = base++;
+ while (--num >= 0) *p++ = base++;
*p = INVALID_STRING_ID;
return buf;
}
@@ -308,7 +308,7 @@
break;
case GAMEOPT_RESOLUTION_BTN: /* Change resolution */
- if (e->we.dropdown.index < _num_resolutions && ChangeResInGame(_resolutions[e->we.dropdown.index][0],_resolutions[e->we.dropdown.index][1]))
+ if (e->we.dropdown.index < _num_resolutions && ChangeResInGame(_resolutions[e->we.dropdown.index][0], _resolutions[e->we.dropdown.index][1]))
SetWindowDirty(w);
break;
@@ -340,7 +340,7 @@
if (flags & DC_EXEC) {
_opt_ptr->road_side = p1;
- InvalidateWindow(WC_GAME_OPTIONS,0);
+ InvalidateWindow(WC_GAME_OPTIONS, 0);
}
return CommandCost();
}
@@ -1058,7 +1058,7 @@
case WE_ON_EDIT_TEXT:
if (e->we.edittext.str != NULL) {
- const PatchEntry *pe = &_patches_page[WP(w, def_d).data_1].entries[WP(w,def_d).data_3];
+ const PatchEntry *pe = &_patches_page[WP(w, def_d).data_1].entries[WP(w, def_d).data_3];
const SettingDesc *sd = pe->setting;
int32 value = atoi(e->we.edittext.str);
--- a/src/ship_cmd.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/ship_cmd.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -17,7 +17,8 @@
#include "player_func.h"
#include "player_base.h"
#include "npf.h"
-#include "depot.h"
+#include "depot_base.h"
+#include "depot_func.h"
#include "vehicle_gui.h"
#include "newgrf_engine.h"
#include "water_map.h"
@@ -130,7 +131,7 @@
FOR_ALL_DEPOTS(depot) {
TileIndex tile = depot->xy;
- if (IsTileDepotType(tile, TRANSPORT_WATER) && IsTileOwner(tile, v->owner)) {
+ if (IsShipDepotTile(tile) && IsTileOwner(tile, v->owner)) {
uint dist = DistanceManhattan(tile, v->tile);
if (dist < best_dist) {
best_dist = dist;
@@ -762,7 +763,7 @@
/* The ai_new queries the vehicle cost before building the route,
* so we must check against cheaters no sooner than now. --pasky */
- if (!IsTileDepotType(tile, TRANSPORT_WATER)) return CMD_ERROR;
+ if (!IsShipDepotTile(tile)) return CMD_ERROR;
if (!IsTileOwner(tile, _current_player)) return CMD_ERROR;
unit_num = HasBit(p2, 0) ? 0 : GetFreeUnitNumber(VEH_SHIP);
--- a/src/ship_gui.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/ship_gui.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -10,7 +10,6 @@
#include "window_gui.h"
#include "viewport_func.h"
#include "gfx_func.h"
-#include "depot.h"
#include "vehicle_gui.h"
#include "newgrf_engine.h"
#include "strings_func.h"
--- a/src/signal.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/signal.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -422,11 +422,11 @@
/* train in the segment */
newstate = SIGNAL_STATE_RED;
} else {
- /* is it a bidir combo? - then do not count its other signal direction as exit */
+ /* is it a bidir combo? - then do not count its other signal direction as exit */
if (sig == SIGTYPE_COMBO && HasSignalOnTrackdir(tile, ReverseTrackdir(trackdir))) {
/* at least one more exit */
if (flags & SF_EXIT2 &&
- /* no green exit */
+ /* no green exit */
(!(flags & SF_GREEN) ||
/* only one green exit, and it is this one - so all other exits are red */
(!(flags & SF_GREEN2) && GetSignalStateByTrackdir(tile, ReverseTrackdir(trackdir)) == SIGNAL_STATE_GREEN))) {
@@ -507,7 +507,7 @@
case MP_STATION:
case MP_ROAD:
if ((TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_RAIL, 0)) & _enterdir_to_trackbits[dir]) != TRACK_BIT_NONE) {
- /* only add to set when there is some 'interesting' track */
+ /* only add to set when there is some 'interesting' track */
_tbdset.Add(tile, dir);
_tbdset.Add(tile + TileOffsByDiagDir(dir), ReverseDiagDir(dir));
break;
--- a/src/signs_gui.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/signs_gui.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -219,7 +219,7 @@
case QUERY_EDIT_SIGN_WIDGET_NEXT:
if (_sign_sort_dirty) GlobalSortSignList();
sign_index = _sign_sort[0]->index;
- for (uint i = 0; i < _num_sign_sort-1; i++) {
+ for (uint i = 0; i < _num_sign_sort - 1; i++) {
if (qs->cur_sign == _sign_sort[i]->index) {
sign_index = _sign_sort[i + 1]->index;
break;
--- a/src/smallmap_gui.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/smallmap_gui.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -1,4 +1,3 @@
-
/* $Id$ */
/** @file smallmap_gui.cpp */
--- a/src/station.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/station.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -13,7 +13,6 @@
#include "player_func.h"
#include "airport.h"
#include "sprite.h"
-#include "depot.h"
#include "train.h"
#include "water_map.h"
#include "industry_map.h"
--- a/src/station_cmd.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/station_cmd.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -18,7 +18,6 @@
#include "saveload.h"
#include "airport.h"
#include "sprite.h"
-#include "depot.h"
#include "train.h"
#include "roadveh.h"
#include "water_map.h"
@@ -71,9 +70,9 @@
return false;
}
-RoadStop* GetRoadStopByTile(TileIndex tile, RoadStopType type)
+RoadStop *GetRoadStopByTile(TileIndex tile, RoadStopType type)
{
- const Station* st = GetStationByTile(tile);
+ const Station *st = GetStationByTile(tile);
for (RoadStop *rs = st->GetPrimaryRoadStop(type);; rs = rs->next) {
if (rs->xy == tile) return rs;
@@ -82,7 +81,7 @@
}
-static uint GetNumRoadStopsInStation(const Station* st, RoadStopType type)
+static uint GetNumRoadStopsInStation(const Station *st, RoadStopType type)
{
uint num = 0;
@@ -100,7 +99,7 @@
* @param st Station to query
* @return the so calculated radius
*/
-static uint FindCatchmentRadius(const Station* st)
+static uint FindCatchmentRadius(const Station *st)
{
uint ret = CA_NONE;
@@ -115,7 +114,7 @@
#define CHECK_STATIONS_ERR ((Station*)-1)
-static Station* GetStationAround(TileIndex tile, int w, int h, StationID closest_station)
+static Station *GetStationAround(TileIndex tile, int w, int h, StationID closest_station)
{
/* check around to see if there's any stations there */
BEGIN_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
@@ -250,20 +249,19 @@
1 << M(STR_SV_STNAME_HELIPORT), /* 5 */
};
- Town *t = st->town;
- uint32 free_names = (uint32)-1;
- int found;
- unsigned long tmp;
+ const Town *t = st->town;
+ uint32 free_names = UINT32_MAX;
{
- Station *s;
+ const Station *s;
FOR_ALL_STATIONS(s) {
if (s != st && s->town == t) {
uint str = M(s->string_id);
if (str <= 0x20) {
- if (str == M(STR_SV_STNAME_FOREST))
+ if (str == M(STR_SV_STNAME_FOREST)) {
str = M(STR_SV_STNAME_WOODS);
+ }
ClrBit(free_names, str);
}
}
@@ -271,7 +269,8 @@
}
/* check default names */
- tmp = free_names & _gen_station_name_bits[flag];
+ uint32 tmp = free_names & _gen_station_name_bits[flag];
+ int found;
if (tmp != 0) {
found = FindFirstBit(tmp);
goto done;
@@ -348,11 +347,11 @@
}
#undef M
-static Station* GetClosestStationFromTile(TileIndex tile)
+static Station *GetClosestStationFromTile(TileIndex tile)
{
uint threshold = 8;
- Station* best_station = NULL;
- Station* st;
+ Station *best_station = NULL;
+ Station *st;
FOR_ALL_STATIONS(st) {
if (st->facilities == 0 && st->owner == _current_player) {
@@ -386,7 +385,7 @@
/** Update the virtual coords needed to draw the station sign for all stations. */
void UpdateAllStationVirtCoord()
{
- Station* st;
+ Station *st;
FOR_ALL_STATIONS(st) {
UpdateStationVirtCoord(st);
@@ -436,13 +435,13 @@
}
/**
-* Get a list of the cargo types being produced around the tile (in a rectangle).
-* @param produced: Destination array of produced cargo
-* @param tile: Center of the search area
-* @param w: Width of the center
-* @param h: Height of the center
-* @param rad: Radius of the search area
-*/
+ * Get a list of the cargo types being produced around the tile (in a rectangle).
+ * @param produced: Destination array of produced cargo
+ * @param tile: Center of the search area
+ * @param w: Width of the center
+ * @param h: Height of the center
+ * @param rad: Radius of the search area
+ */
void GetProductionAroundTiles(AcceptedCargo produced, TileIndex tile,
int w, int h, int rad)
{
@@ -485,13 +484,13 @@
}
/**
-* Get a list of the cargo types that are accepted around the tile.
-* @param accepts: Destination array of accepted cargo
-* @param tile: Center of the search area
-* @param w: Width of the center
-* @param h: Height of the center
-* @param rad: Radius of the rectangular search area
-*/
+ * Get a list of the cargo types that are accepted around the tile.
+ * @param accepts: Destination array of accepted cargo
+ * @param tile: Center of the search area
+ * @param w: Width of the center
+ * @param h: Height of the center
+ * @param rad: Radius of the rectangular search area
+ */
void GetAcceptanceAroundTiles(AcceptedCargo accepts, TileIndex tile,
int w, int h, int rad)
{
@@ -533,7 +532,7 @@
uint max_y;
};
-static inline void MergePoint(ottd_Rectangle* rect, TileIndex tile)
+static inline void MergePoint(ottd_Rectangle *rect, TileIndex tile)
{
uint x = TileX(tile);
uint y = TileY(tile);
@@ -565,18 +564,14 @@
/* Put all the tiles that span an area in the table. */
if (st->train_tile != 0) {
MergePoint(&rect, st->train_tile);
- MergePoint(&rect,
- st->train_tile + TileDiffXY(st->trainst_w - 1, st->trainst_h - 1)
- );
+ MergePoint(&rect, st->train_tile + TileDiffXY(st->trainst_w - 1, st->trainst_h - 1));
}
if (st->airport_tile != 0) {
- const AirportFTAClass* afc = st->Airport();
+ const AirportFTAClass *afc = st->Airport();
MergePoint(&rect, st->airport_tile);
- MergePoint(&rect,
- st->airport_tile + TileDiffXY(afc->size_x - 1, afc->size_y - 1)
- );
+ MergePoint(&rect, st->airport_tile + TileDiffXY(afc->size_x - 1, afc->size_y - 1));
}
if (st->dock_tile != 0) MergePoint(&rect, st->dock_tile);
@@ -610,16 +605,16 @@
/* Make sure the station can accept the goods type. */
bool is_passengers = IsCargoInClass(i, CC_PASSENGERS);
if ((!is_passengers && !(st->facilities & (byte)~FACIL_BUS_STOP)) ||
- (is_passengers && !(st->facilities & (byte)~FACIL_TRUCK_STOP)))
+ (is_passengers && !(st->facilities & (byte)~FACIL_TRUCK_STOP))) {
amt = 0;
+ }
SB(st->goods[i].acceptance_pickup, GoodsEntry::ACCEPTANCE, 1, amt >= 8);
}
/* Only show a message in case the acceptance was actually changed. */
uint new_acc = GetAcceptanceMask(st);
- if (old_acc == new_acc)
- return;
+ if (old_acc == new_acc) return;
/* show a message to report that the acceptance was changed? */
if (show_msg && st->owner == _local_player && st->facilities) {
@@ -777,7 +772,7 @@
return cost;
}
-static bool CanExpandRailroadStation(const Station* st, uint* fin, Axis axis)
+static bool CanExpandRailroadStation(const Station *st, uint *fin, Axis axis)
{
uint curw = st->trainst_w;
uint curh = st->trainst_h;
@@ -900,9 +895,6 @@
*/
CommandCost CmdBuildRailroadStation(TileIndex tile_org, uint32 flags, uint32 p1, uint32 p2)
{
- int w_org, h_org;
- CommandCost ret;
-
/* Does the authority allow this? */
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile_org)) return CMD_ERROR;
if (!ValParamRailtype((RailType)(p2 & 0xF))) return CMD_ERROR;
@@ -911,6 +903,8 @@
Axis axis = Extract<Axis, 0>(p1);
uint numtracks = GB(p1, 8, 8);
uint plat_len = GB(p1, 16, 8);
+
+ int w_org, h_org;
if (axis == AXIS_X) {
w_org = plat_len;
h_org = numtracks;
@@ -932,7 +926,7 @@
/* If DC_EXEC is in flag, do not want to pass it to CheckFlatLandBelow, because of a nice bug
* for detail info, see:
* https://sourceforge.net/tracker/index.php?func=detail&aid=1029064&group_id=103924&atid=636365 */
- ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags & ~DC_EXEC, 5 << axis, _patches.nonuniform_stations ? &est : NULL);
+ CommandCost ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags & ~DC_EXEC, 5 << axis, _patches.nonuniform_stations ? &est : NULL);
if (CmdFailed(ret)) return ret;
CommandCost cost(EXPENSES_CONSTRUCTION, ret.GetCost() + (numtracks * _price.train_station_track + _price.train_station_length) * plat_len);
@@ -1194,7 +1188,7 @@
/* Do not allow removing from stations if non-uniform stations are not enabled
* The check must be here to give correct error message
- */
+ */
if (!_patches.nonuniform_stations) return_cmd_error(STR_NONUNIFORM_STATIONS_DISALLOWED);
/* If we reached here, the tile is valid so increase the quantity of tiles we will remove */
@@ -1240,12 +1234,12 @@
static CommandCost RemoveRailroadStation(Station *st, TileIndex tile, uint32 flags)
{
/* if there is flooding and non-uniform stations are enabled, remove platforms tile by tile */
- if (_current_player == OWNER_WATER && _patches.nonuniform_stations)
+ if (_current_player == OWNER_WATER && _patches.nonuniform_stations) {
return DoCommand(tile, 0, 0, DC_EXEC, CMD_REMOVE_FROM_RAILROAD_STATION);
+ }
/* Current player owns the station? */
- if (_current_player != OWNER_WATER && !CheckOwnership(st->owner))
- return CMD_ERROR;
+ if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) return CMD_ERROR;
/* determine width and height of platforms */
tile = st->train_tile;
@@ -1303,7 +1297,7 @@
* @param st The Station to do the whole procedure for
* @return a pointer to where to link a new RoadStop*
*/
-static RoadStop **FindRoadStopSpot(bool truck_station, Station* st)
+static RoadStop **FindRoadStopSpot(bool truck_station, Station *st)
{
RoadStop **primary_stop = (truck_station) ? &st->truck_stops : &st->bus_stops;
@@ -1349,8 +1343,6 @@
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) return CMD_ERROR;
- CommandCost cost;
-
/* Not allowed to build over this road */
if (build_over_road) {
if (IsTileOwner(tile, OWNER_TOWN) && !_patches.road_stop_on_town_road) return_cmd_error(STR_DRIVE_THROUGH_ERROR_ON_TOWN_ROAD);
@@ -1375,7 +1367,8 @@
/* Do not remove roadtypes! */
rts |= cur_rts;
}
- cost = CheckFlatLandBelow(tile, 1, 1, flags, is_drive_through ? 5 << p1 : 1 << p1, NULL, !build_over_road);
+
+ CommandCost cost = CheckFlatLandBelow(tile, 1, 1, flags, is_drive_through ? 5 << p1 : 1 << p1, NULL, !build_over_road);
if (CmdFailed(cost)) return cost;
Station *st = NULL;
@@ -1671,18 +1664,18 @@
/* Check if a valid, buildable airport was chosen for construction */
if (p1 > lengthof(_airport_sections) || !HasBit(GetValidAirports(), p1)) return CMD_ERROR;
- if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile))
+ if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) {
return CMD_ERROR;
-
- Town *t = ClosestTownFromTile(tile, (uint)-1);
+ }
+
+ Town *t = ClosestTownFromTile(tile, UINT_MAX);
/* Check if local auth refuses a new airport */
{
uint num = 0;
const Station *st;
FOR_ALL_STATIONS(st) {
- if (st->town == t && st->facilities&FACIL_AIRPORT && st->airport_type != AT_OILRIG)
- num++;
+ if (st->town == t && st->facilities & FACIL_AIRPORT && st->airport_type != AT_OILRIG) num++;
}
if (num >= 2) {
SetDParam(0, t->index);
@@ -1717,13 +1710,15 @@
AutoPtrT<Station> st_auto_delete;
if (st != NULL) {
- if (st->owner != _current_player)
+ if (st->owner != _current_player) {
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
+ }
if (!st->rect.BeforeAddRect(tile, w, h, StationRect::ADD_TEST)) return CMD_ERROR;
- if (st->airport_tile != 0)
+ if (st->airport_tile != 0) {
return_cmd_error(STR_300D_TOO_CLOSE_TO_ANOTHER_AIRPORT);
+ }
} else {
airport_upgrade = false;
@@ -1791,8 +1786,9 @@
static CommandCost RemoveAirport(Station *st, uint32 flags)
{
- if (_current_player != OWNER_WATER && !CheckOwnership(st->owner))
+ if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) {
return CMD_ERROR;
+ }
TileIndex tile = st->airport_tile;
@@ -1802,7 +1798,7 @@
CommandCost cost(EXPENSES_CONSTRUCTION, w * h * _price.remove_airport);
- Vehicle *v;
+ const Vehicle *v;
FOR_ALL_VEHICLES(v) {
if (!(v->type == VEH_AIRCRAFT && IsNormalAircraft(v))) continue;
@@ -1912,7 +1908,7 @@
static CommandCost RemoveBuoy(Station *st, uint32 flags)
{
/* XXX: strange stuff */
- if (!IsValidPlayer(_current_player)) return_cmd_error(INVALID_STRING_ID);
+ if (!IsValidPlayer(_current_player)) return_cmd_error(INVALID_STRING_ID);
TileIndex tile = st->dock_tile;
@@ -1959,8 +1955,6 @@
*/
CommandCost CmdBuildDock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
- CommandCost cost;
-
DiagDirection direction = GetInclinedSlopeDirection(GetTileSlope(tile, NULL));
if (direction == INVALID_DIAGDIR) return_cmd_error(STR_304B_SITE_UNSUITABLE);
direction = ReverseDiagDir(direction);
@@ -1972,8 +1966,7 @@
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
- cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
- if (CmdFailed(cost)) return CMD_ERROR;
+ if (CmdFailed(DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR))) return CMD_ERROR;
TileIndex tile_cur = tile + TileOffsByDiagDir(direction);
@@ -1986,8 +1979,7 @@
/* Get the water class of the water tile before it is cleared.*/
WaterClass wc = GetWaterClass(tile_cur);
- cost = DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
- if (CmdFailed(cost)) return CMD_ERROR;
+ if (CmdFailed(DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR))) return CMD_ERROR;
tile_cur += TileOffsByDiagDir(direction);
if (!IsTileType(tile_cur, MP_WATER) || GetTileSlope(tile_cur, NULL) != SLOPE_FLAT) {
@@ -2012,8 +2004,9 @@
AutoPtrT<Station> st_auto_delete;
if (st != NULL) {
- if (st->owner != _current_player)
+ if (st->owner != _current_player) {
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
+ }
if (!st->rect.BeforeAddRect(tile, _dock_w_chk[direction], _dock_h_chk[direction], StationRect::ADD_TEST)) return CMD_ERROR;
@@ -2053,6 +2046,7 @@
/* success, so don't delete the new station */
st_auto_delete.Detach();
}
+
return CommandCost(EXPENSES_CONSTRUCTION, _price.build_dock);
}
@@ -2132,8 +2126,6 @@
st = GetStationByTile(ti->tile);
statspec = st->speclist[GetCustomStationSpecIndex(ti->tile)].spec;
- //debug("Cust-o-mized %p", statspec);
-
if (statspec != NULL) {
uint tile = GetStationGfx(ti->tile);
@@ -2485,7 +2477,11 @@
}
-static inline void byte_inc_sat(byte *p) { byte b = *p + 1; if (b != 0) *p = b; }
+static inline void byte_inc_sat(byte *p)
+{
+ byte b = *p + 1;
+ if (b != 0) *p = b;
+}
static void UpdateStationRating(Station *st)
{
@@ -2511,7 +2507,7 @@
{
int b = ge->last_speed;
- if ((b-=85) >= 0)
+ if ((b -= 85) >= 0)
rating += b >> 2;
}
@@ -2623,6 +2619,7 @@
void StationMonthlyLoop()
{
+ /* not used */
}
@@ -2634,7 +2631,7 @@
if (st->owner == owner &&
DistanceManhattan(tile, st->xy) <= radius) {
for (CargoID i = 0; i < NUM_CARGO; i++) {
- GoodsEntry* ge = &st->goods[i];
+ GoodsEntry *ge = &st->goods[i];
if (ge->acceptance_pickup != 0) {
ge->rating = Clamp(ge->rating + amount, 0, 255);
@@ -2695,14 +2692,14 @@
}
/**
-* Find all (non-buoy) stations around an industry tile
-*
-* @param tile: Center tile to search from
-* @param w: Width of the center
-* @param h: Height of the center
-*
-* @return: Set of found stations
-*/
+ * Find all (non-buoy) stations around an industry tile
+ *
+ * @param tile: Center tile to search from
+ * @param w: Width of the center
+ * @param h: Height of the center
+ *
+ * @return: Set of found stations
+ */
StationSet FindStationsAroundIndustryTile(TileIndex tile, int w, int h)
{
StationSet station_set;
@@ -2773,10 +2770,10 @@
uint MoveGoodsToStation(TileIndex tile, int w, int h, CargoID type, uint amount)
{
- Station *st1 = NULL; // Station with best rating
- Station *st2 = NULL; // Second best station
- uint best_rating1 = 0; // rating of st1
- uint best_rating2 = 0; // rating of st2
+ Station *st1 = NULL; // Station with best rating
+ Station *st2 = NULL; // Second best station
+ uint best_rating1 = 0; // rating of st1
+ uint best_rating2 = 0; // rating of st2
StationSet all_stations = FindStationsAroundIndustryTile(tile, w, h);
for (StationSet::iterator st_iter = all_stations.begin(); st_iter != all_stations.end(); ++st_iter) {
@@ -2891,7 +2888,7 @@
void DeleteOilRig(TileIndex tile)
{
- Station* st = GetStationByTile(tile);
+ Station *st = GetStationByTile(tile);
MakeWater(tile);
@@ -2908,7 +2905,7 @@
if (!IsTileOwner(tile, old_player)) return;
if (new_player != PLAYER_SPECTATOR) {
- Station* st = GetStationByTile(tile);
+ Station *st = GetStationByTile(tile);
SetTileOwner(tile, new_player);
if (!IsBuoy(tile)) st->owner = new_player; // do not set st->owner for buoys
@@ -2996,7 +2993,6 @@
_RoadStop_pool.AddBlockToPool();
_station_tick_ctr = 0;
-
}
@@ -3069,15 +3065,15 @@
};
static const SaveLoad _roadstop_desc[] = {
- SLE_VAR(RoadStop,xy, SLE_UINT32),
+ SLE_VAR(RoadStop, xy, SLE_UINT32),
SLE_CONDNULL(1, 0, 44),
- SLE_VAR(RoadStop,status, SLE_UINT8),
+ SLE_VAR(RoadStop, status, SLE_UINT8),
/* Index was saved in some versions, but this is not needed */
SLE_CONDNULL(4, 0, 8),
SLE_CONDNULL(2, 0, 44),
SLE_CONDNULL(1, 0, 25),
- SLE_REF(RoadStop,next, REF_ROADSTOPS),
+ SLE_REF(RoadStop, next, REF_ROADSTOPS),
SLE_CONDNULL(2, 0, 44),
SLE_CONDNULL(4, 0, 24),
@@ -3089,7 +3085,7 @@
static const SaveLoad _station_desc[] = {
SLE_CONDVAR(Station, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
SLE_CONDVAR(Station, xy, SLE_UINT32, 6, SL_MAX_VERSION),
- SLE_CONDNULL(4, 0, 5), // bus/lorry tile
+ SLE_CONDNULL(4, 0, 5), ///< bus/lorry tile
SLE_CONDVAR(Station, train_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
SLE_CONDVAR(Station, train_tile, SLE_UINT32, 6, SL_MAX_VERSION),
SLE_CONDVAR(Station, airport_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
@@ -3100,8 +3096,7 @@
SLE_VAR(Station, trainst_w, SLE_UINT8),
SLE_CONDVAR(Station, trainst_h, SLE_UINT8, 2, SL_MAX_VERSION),
- /* alpha_order was stored here in savegame format 0 - 3 */
- SLE_CONDNULL(1, 0, 3),
+ SLE_CONDNULL(1, 0, 3), ///< alpha_order
SLE_VAR(Station, string_id, SLE_STRINGID),
SLE_CONDSTR(Station, name, SLE_STR, 0, 84, SL_MAX_VERSION),
@@ -3114,18 +3109,17 @@
SLE_VAR(Station, facilities, SLE_UINT8),
SLE_VAR(Station, airport_type, SLE_UINT8),
- SLE_CONDNULL(2, 0, 5), // Truck/bus stop status
- SLE_CONDNULL(1, 0, 4), // Blocked months
+ SLE_CONDNULL(2, 0, 5), ///< Truck/bus stop status
+ SLE_CONDNULL(1, 0, 4), ///< Blocked months
SLE_CONDVAR(Station, airport_flags, SLE_VAR_U64 | SLE_FILE_U16, 0, 2),
SLE_CONDVAR(Station, airport_flags, SLE_VAR_U64 | SLE_FILE_U32, 3, 45),
SLE_CONDVAR(Station, airport_flags, SLE_UINT64, 46, SL_MAX_VERSION),
- SLE_CONDNULL(2, 0, 25), /* Ex last-vehicle */
+ SLE_CONDNULL(2, 0, 25), ///< last-vehicle
SLE_CONDVAR(Station, last_vehicle_type, SLE_UINT8, 26, SL_MAX_VERSION),
- /* Was custom station class and id */
- SLE_CONDNULL(2, 3, 25),
+ SLE_CONDNULL(2, 3, 25), ///< custom station class and id
SLE_CONDVAR(Station, build_date, SLE_FILE_U16 | SLE_VAR_I32, 3, 30),
SLE_CONDVAR(Station, build_date, SLE_INT32, 31, SL_MAX_VERSION),
--- a/src/station_gui.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/station_gui.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -94,15 +94,14 @@
};
static char _bufcache[64];
-static const Station* _last_station;
+static const Station *_last_station;
static int _internal_sort_order;
static int CDECL StationNameSorter(const void *a, const void *b)
{
- const Station* st1 = *(const Station**)a;
- const Station* st2 = *(const Station**)b;
+ const Station *st1 = *(const Station**)a;
+ const Station *st2 = *(const Station**)b;
char buf1[64];
- int r;
SetDParam(0, st1->index);
GetString(buf1, STR_STATION, lastof(buf1));
@@ -113,24 +112,24 @@
GetString(_bufcache, STR_STATION, lastof(_bufcache));
}
- r = strcmp(buf1, _bufcache); // sort by name
+ int r = strcmp(buf1, _bufcache); // sort by name
return (_internal_sort_order & 1) ? -r : r;
}
static int CDECL StationTypeSorter(const void *a, const void *b)
{
- const Station* st1 = *(const Station**)a;
- const Station* st2 = *(const Station**)b;
+ const Station *st1 = *(const Station**)a;
+ const Station *st2 = *(const Station**)b;
return (_internal_sort_order & 1) ? st2->facilities - st1->facilities : st1->facilities - st2->facilities;
}
-static const uint32 _cargo_filter_max = ~0;
+static const uint32 _cargo_filter_max = UINT32_MAX;
static uint32 _cargo_filter = _cargo_filter_max;
static int CDECL StationWaitingSorter(const void *a, const void *b)
{
- const Station* st1 = *(const Station**)a;
- const Station* st2 = *(const Station**)b;
+ const Station *st1 = *(const Station**)a;
+ const Station *st2 = *(const Station**)b;
Money sum1 = 0, sum2 = 0;
for (CargoID j = 0; j < NUM_CARGO; j++) {
@@ -152,8 +151,8 @@
*/
static int CDECL StationRatingMaxSorter(const void *a, const void *b)
{
- const Station* st1 = *(const Station**)a;
- const Station* st2 = *(const Station**)b;
+ const Station *st1 = *(const Station**)a;
+ const Station *st2 = *(const Station**)b;
byte maxr1 = 0;
byte maxr2 = 0;
@@ -176,7 +175,7 @@
/** Information about station list */
struct plstations_d {
- const Station** sort_list; ///< Pointer to list of stations
+ const Station **sort_list; ///< Pointer to list of stations
uint16 list_length; ///< Number of stations in list
uint16 resort_timer; ///< Tick counter to resort the list
byte sort_type; ///< Sort type - name, waiting, ...
@@ -189,7 +188,7 @@
*/
void RebuildStationLists()
{
- Window* const *wz;
+ Window *const *wz;
FOR_ALL_WINDOWS(wz) {
Window *w = *wz;
@@ -205,7 +204,7 @@
*/
void ResortStationLists()
{
- Window* const *wz;
+ Window *const *wz;
FOR_ALL_WINDOWS(wz) {
Window *w = *wz;
@@ -225,7 +224,7 @@
* @param cargo_filter bitmap of cargo types to include
* @param include_empty whether we should include stations without waiting cargo
*/
-static void BuildStationsList(plstations_d* sl, PlayerID owner, byte facilities, uint32 cargo_filter, bool include_empty)
+static void BuildStationsList(plstations_d *sl, PlayerID owner, byte facilities, uint32 cargo_filter, bool include_empty)
{
uint n = 0;
const Station *st;
@@ -233,7 +232,7 @@
if (!(sl->flags & SL_REBUILD)) return;
/* Create array for sorting */
- const Station** station_sort = MallocT<const Station*>(GetMaxStationIndex() + 1);
+ const Station **station_sort = MallocT<const Station*>(GetMaxStationIndex() + 1);
DEBUG(misc, 3, "Building station list for player %d", owner);
@@ -277,7 +276,7 @@
*/
static void SortStationsList(plstations_d *sl)
{
- static StationSortListingTypeFunction* const _station_sorter[] = {
+ static StationSortListingTypeFunction *const _station_sorter[] = {
&StationNameSorter,
&StationTypeSorter,
&StationWaitingSorter,
@@ -749,10 +748,7 @@
static void DrawStationViewWindow(Window *w)
{
StationID station_id = w->window_number;
- const Station* st = GetStation(station_id);
- int x, y; ///< coordinates used for printing waiting/accepted/rating of cargo
- int pos; ///< = w->vscroll.pos
- StringID str;
+ const Station *st = GetStation(station_id);
CargoDataList cargolist;
uint32 transfers = 0;
@@ -808,13 +804,15 @@
SetDParam(1, st->facilities);
DrawWindowWidgets(w);
- x = 2;
- y = 15;
- pos = w->vscroll.pos;
+ int x = 2; ///< coordinates used for printing waiting/accepted/rating of cargo
+ int y = 15;
+ int pos = w->vscroll.pos; ///< = w->vscroll.pos
uint width = w->widget[SVW_WAITING].right - w->widget[SVW_WAITING].left - 4;
int maxrows = w->vscroll.cap;
+ StringID str;
+
if (--pos < 0) {
str = STR_00D0_NOTHING;
for (CargoID i = 0; i < NUM_CARGO; i++) {
--- a/src/station_map.h Thu Apr 17 08:40:01 2008 +0000
+++ b/src/station_map.h Fri Apr 18 23:33:51 2008 +0000
@@ -68,6 +68,18 @@
_m[t].m5 = gfx;
}
+static inline uint8 GetStationAnimationFrame(TileIndex t)
+{
+ assert(IsTileType(t, MP_STATION));
+ return _me[t].m7;
+}
+
+static inline void SetStationAnimationFrame(TileIndex t, uint8 frame)
+{
+ assert(IsTileType(t, MP_STATION));
+ _me[t].m7 = frame;
+}
+
static inline bool IsRailwayStation(TileIndex t)
{
return GetStationType(t) == STATION_RAIL;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/statusbar_gui.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -0,0 +1,170 @@
+/* $Id$ */
+
+/** @file main_gui.cpp */
+
+#include "stdafx.h"
+#include "openttd.h"
+#include "settings_type.h"
+#include "date_func.h"
+#include "gfx_func.h"
+#include "news_func.h"
+#include "player_func.h"
+#include "string_func.h"
+#include "strings_func.h"
+#include "player_base.h"
+#include "viewport_func.h"
+#include "news_gui.h"
+#include "player_gui.h"
+#include "window_gui.h"
+#include "variables.h"
+
+#include "table/strings.h"
+#include "table/sprites.h"
+
+extern GetNewsStringCallbackProc * const _get_news_string_callback[];
+
+static bool DrawScrollingStatusText(const NewsItem *ni, int pos, int width)
+{
+ StringID str;
+ if (ni->display_mode == NM_CALLBACK) {
+ str = _get_news_string_callback[ni->callback](ni);
+ } else {
+ CopyInDParam(0, ni->params, lengthof(ni->params));
+ str = ni->string_id;
+ }
+
+ char buf[512];
+ GetString(buf, str, lastof(buf));
+ const char *s = buf;
+
+ char buffer[256];
+ char *d = buffer;
+ const char *last = lastof(buffer);
+
+ for (;;) {
+ WChar c = Utf8Consume(&s);
+ if (c == 0) {
+ break;
+ } else if (c == 0x0D) {
+ if (d + 4 >= last) break;
+ d[0] = d[1] = d[2] = d[3] = ' ';
+ d += 4;
+ } else if (IsPrintable(c)) {
+ if (d + Utf8CharLen(c) >= last) break;
+ d += Utf8Encode(d, c);
+ }
+ }
+ *d = '\0';
+
+ DrawPixelInfo tmp_dpi;
+ if (!FillDrawPixelInfo(&tmp_dpi, 141, 1, width, 11)) return true;
+
+ DrawPixelInfo *old_dpi = _cur_dpi;
+ _cur_dpi = &tmp_dpi;
+
+ int x = DoDrawString(buffer, pos, 0, TC_LIGHT_BLUE);
+ _cur_dpi = old_dpi;
+
+ return x > 0;
+}
+
+static void StatusBarWndProc(Window *w, WindowEvent *e)
+{
+ switch (e->event) {
+ case WE_PAINT: {
+ const Player *p = (_local_player == PLAYER_SPECTATOR) ? NULL : GetPlayer(_local_player);
+
+ DrawWindowWidgets(w);
+ SetDParam(0, _date);
+ DrawStringCentered(70, 1, (_pause_game || _patches.status_long_date) ? STR_00AF : STR_00AE, TC_FROMSTRING);
+
+ if (p != NULL) {
+ /* Draw player money */
+ SetDParam(0, p->player_money);
+ DrawStringCentered(w->widget[2].left + 70, 1, STR_0004, TC_FROMSTRING);
+ }
+
+ /* Draw status bar */
+ if (w->message.msg) { // true when saving is active
+ DrawStringCenteredTruncated(w->widget[1].left + 1, w->widget[1].right - 1, 1, STR_SAVING_GAME, TC_FROMSTRING);
+ } else if (_do_autosave) {
+ DrawStringCenteredTruncated(w->widget[1].left + 1, w->widget[1].right - 1, 1, STR_032F_AUTOSAVE, TC_FROMSTRING);
+ } else if (_pause_game) {
+ DrawStringCenteredTruncated(w->widget[1].left + 1, w->widget[1].right - 1, 1, STR_0319_PAUSED, TC_FROMSTRING);
+ } else if (WP(w, def_d).data_1 > -1280 && FindWindowById(WC_NEWS_WINDOW,0) == NULL && _statusbar_news_item.string_id != 0) {
+ /* Draw the scrolling news text */
+ if (!DrawScrollingStatusText(&_statusbar_news_item, WP(w, def_d).data_1, w->widget[1].right - w->widget[1].left - 2)) {
+ WP(w, def_d).data_1 = -1280;
+ if (p != NULL) {
+ /* This is the default text */
+ SetDParam(0, p->index);
+ DrawStringCenteredTruncated(w->widget[1].left + 1, w->widget[1].right - 1, 1, STR_02BA, TC_FROMSTRING);
+ }
+ }
+ } else {
+ if (p != NULL) {
+ /* This is the default text */
+ SetDParam(0, p->index);
+ DrawStringCenteredTruncated(w->widget[1].left + 1, w->widget[1].right - 1, 1, STR_02BA, TC_FROMSTRING);
+ }
+ }
+
+ if (WP(w, def_d).data_2 > 0) DrawSprite(SPR_BLOT, PALETTE_TO_RED, w->widget[1].right - 11, 2);
+ } break;
+
+ case WE_MESSAGE:
+ w->message.msg = e->we.message.msg;
+ SetWindowDirty(w);
+ break;
+
+ case WE_CLICK:
+ switch (e->we.click.widget) {
+ case 1: ShowLastNewsMessage(); break;
+ case 2: if (_local_player != PLAYER_SPECTATOR) ShowPlayerFinances(_local_player); break;
+ default: ResetObjectToPlace();
+ }
+ break;
+
+ case WE_TICK: {
+ if (_pause_game) return;
+
+ if (WP(w, def_d).data_1 > -1280) { // Scrolling text
+ WP(w, def_d).data_1 -= 2;
+ w->InvalidateWidget(1);
+ }
+
+ if (WP(w, def_d).data_2 > 0) { // Red blot to show there are new unread newsmessages
+ WP(w, def_d).data_2 -= 2;
+ } else if (WP(w, def_d).data_2 < 0) {
+ WP(w, def_d).data_2 = 0;
+ w->InvalidateWidget(1);
+ }
+
+ } break;
+ }
+}
+
+static const Widget _main_status_widgets[] = {
+{ WWT_PANEL, RESIZE_NONE, 14, 0, 139, 0, 11, 0x0, STR_NULL},
+{ WWT_PUSHBTN, RESIZE_RIGHT, 14, 140, 179, 0, 11, 0x0, STR_02B7_SHOW_LAST_MESSAGE_OR_NEWS},
+{ WWT_PUSHBTN, RESIZE_LR, 14, 180, 319, 0, 11, 0x0, STR_NULL},
+{ WIDGETS_END},
+};
+
+static WindowDesc _main_status_desc = {
+ WDP_CENTER, 0, 320, 12, 640, 12,
+ WC_STATUS_BAR, WC_NONE,
+ WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
+ _main_status_widgets,
+ StatusBarWndProc
+};
+
+void ShowStatusBar()
+{
+ _main_status_desc.top = _screen.height - 12;
+ Window *w = AllocateWindowDesc(&_main_status_desc);
+ if (w != NULL) {
+ CLRBITS(w->flags4, WF_WHITE_BORDER_MASK);
+ WP(w, def_d).data_1 = -1280;
+ }
+}
--- a/src/stdafx.h Thu Apr 17 08:40:01 2008 +0000
+++ b/src/stdafx.h Fri Apr 18 23:33:51 2008 +0000
@@ -296,9 +296,9 @@
#define endof(x) (&x[lengthof(x)])
#define lastof(x) (&x[lengthof(x) - 1])
-#define cpp_offsetof(s,m) (((size_t)&reinterpret_cast<const volatile char&>((((s*)(char*)8)->m))) - 8)
+#define cpp_offsetof(s, m) (((size_t)&reinterpret_cast<const volatile char&>((((s*)(char*)8)->m))) - 8)
#if !defined(offsetof)
- #define offsetof(s,m) cpp_offsetof(s, m)
+ #define offsetof(s, m) cpp_offsetof(s, m)
#endif /* offsetof */
@@ -309,13 +309,7 @@
#define CloseConnection OTTD_CloseConnection
#endif /* __APPLE__ */
-#if !defined(STRGEN)
- /* In strgen error is not fatal and returns */
- void NORETURN CDECL error(const char *str, ...);
-#else
- void CDECL error(const char *str, ...);
-#endif
-
+void NORETURN CDECL error(const char *str, ...);
#define NOT_REACHED() error("NOT_REACHED triggered at line %i of %s", __LINE__, __FILE__)
#if defined(MORPHOS) || defined(__NDS__)
--- a/src/strgen/strgen.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/strgen/strgen.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -155,7 +155,7 @@
# define LINE_NUM_FMT ":%d"
#endif
-static void CDECL warning(const char *s, ...)
+static void CDECL strgen_warning(const char *s, ...)
{
char buf[1024];
va_list va;
@@ -166,7 +166,7 @@
_warnings++;
}
-void CDECL error(const char *s, ...)
+static void CDECL strgen_error(const char *s, ...)
{
char buf[1024];
va_list va;
@@ -177,8 +177,7 @@
_errors++;
}
-
-static void NORETURN CDECL fatal(const char *s, ...)
+void NORETURN CDECL error(const char *s, ...)
{
char buf[1024];
va_list va;
@@ -191,7 +190,7 @@
static void PutByte(byte c)
{
- if (_put_pos == lengthof(_put_buf)) fatal("Put buffer too small");
+ if (_put_pos == lengthof(_put_buf)) error("Put buffer too small");
_put_buf[_put_pos++] = c;
}
@@ -213,7 +212,7 @@
PutByte(0x80 + GB(value, 6, 6));
PutByte(0x80 + GB(value, 0, 6));
} else {
- warning("Invalid unicode value U+0x%X", value);
+ strgen_warning("Invalid unicode value U+0x%X", value);
}
}
@@ -245,7 +244,7 @@
static void EmitSingleChar(char *buf, int value)
{
- if (*buf != '\0') warning("Ignoring trailing letters in command");
+ if (*buf != '\0') strgen_warning("Ignoring trailing letters in command");
PutUtf8(value);
}
@@ -254,7 +253,7 @@
{
char *err;
int x = strtol(buf, &err, 0);
- if (*err != 0) fatal("SetX param invalid");
+ if (*err != 0) error("SetX param invalid");
PutUtf8(SCC_SETX);
PutByte((byte)x);
}
@@ -267,9 +266,9 @@
int y;
x = strtol(buf, &err, 0);
- if (*err != ' ') fatal("SetXY param invalid");
+ if (*err != ' ') error("SetXY param invalid");
y = strtol(err + 1, &err, 0);
- if (*err != 0) fatal("SetXY param invalid");
+ if (*err != 0) error("SetXY param invalid");
PutUtf8(SCC_SETXY);
PutByte((byte)x);
@@ -371,14 +370,14 @@
}
if (nw == 0)
- fatal("%s: No plural words", _cur_ident);
+ error("%s: No plural words", _cur_ident);
if (_plural_form_counts[_lang_pluralform] != nw) {
if (_translated) {
- fatal("%s: Invalid number of plural forms. Expecting %d, found %d.", _cur_ident,
+ error("%s: Invalid number of plural forms. Expecting %d, found %d.", _cur_ident,
_plural_form_counts[_lang_pluralform], nw);
} else {
- if ((_show_todo & 2) != 0) warning("'%s' is untranslated. Tweaking english string to allow compilation for plural forms", _cur_ident);
+ if ((_show_todo & 2) != 0) strgen_warning("'%s' is untranslated. Tweaking english string to allow compilation for plural forms", _cur_ident);
if (nw > _plural_form_counts[_lang_pluralform]) {
nw = _plural_form_counts[_lang_pluralform];
} else {
@@ -405,7 +404,7 @@
// This is a {G=DER} command
for (nw = 0; ; nw++) {
- if (nw >= 8) fatal("G argument '%s' invalid", buf);
+ if (nw >= 8) error("G argument '%s' invalid", buf);
if (strcmp(buf, _genders[nw]) == 0) break;
}
// now nw contains the gender index
@@ -422,7 +421,7 @@
words[nw] = ParseWord(&buf);
if (words[nw] == NULL) break;
}
- if (nw != _numgenders) fatal("Bad # of arguments for gender command");
+ if (nw != _numgenders) error("Bad # of arguments for gender command");
PutUtf8(SCC_GENDER_LIST);
PutByte(TranslateArgumentIdx(argidx));
EmitWordList(words, nw);
@@ -553,7 +552,7 @@
for (i = 0; i < MAX_NUM_CASES; i++) {
if (memcmp(_cases[i], str, len) == 0 && _cases[i][len] == 0) return i + 1;
}
- fatal("Invalid case-name '%s'", str);
+ error("Invalid case-name '%s'", str);
}
@@ -578,7 +577,7 @@
char *end;
*argno = strtoul(s, &end, 0);
- if (*end != ':') fatal("missing arg #");
+ if (*end != ':') error("missing arg #");
s = end + 1;
}
@@ -590,7 +589,7 @@
cmd = FindCmd(start, s - start - 1);
if (cmd == NULL) {
- error("Undefined command '%.*s'", s - start - 1, start);
+ strgen_error("Undefined command '%.*s'", s - start - 1, start);
return NULL;
}
@@ -598,14 +597,14 @@
const char *casep = s;
if (!(cmd->flags & C_CASE))
- fatal("Command '%s' can't have a case", cmd->cmd);
+ error("Command '%s' can't have a case", cmd->cmd);
do c = *s++; while (c != '}' && c != ' ' && c != '\0');
*casei = ResolveCaseName(casep, s - casep - 1);
}
if (c == '\0') {
- error("Missing } from command '%s'", start);
+ strgen_error("Missing } from command '%s'", start);
return NULL;
}
@@ -618,10 +617,10 @@
c = *s++;
if (c == '}') break;
if (c == '\0') {
- error("Missing } from command '%s'", start);
+ strgen_error("Missing } from command '%s'", start);
return NULL;
}
- if (s - start == 250) fatal("param command too long");
+ if (s - start == 250) error("param command too long");
*param++ = c;
}
}
@@ -646,7 +645,7 @@
} else if (!memcmp(str, "plural ", 7)) {
_lang_pluralform = atoi(str + 7);
if (_lang_pluralform >= lengthof(_plural_form_counts))
- fatal("Invalid pluralform %d", _lang_pluralform);
+ error("Invalid pluralform %d", _lang_pluralform);
} else if (!memcmp(str, "gender ", 7)) {
char* buf = str + 7;
@@ -654,7 +653,7 @@
const char* s = ParseWord(&buf);
if (s == NULL) break;
- if (_numgenders >= MAX_NUM_GENDER) fatal("Too many genders, max %d", MAX_NUM_GENDER);
+ if (_numgenders >= MAX_NUM_GENDER) error("Too many genders, max %d", MAX_NUM_GENDER);
ttd_strlcpy(_genders[_numgenders], s, sizeof(_genders[_numgenders]));
_numgenders++;
}
@@ -665,12 +664,12 @@
const char* s = ParseWord(&buf);
if (s == NULL) break;
- if (_numcases >= MAX_NUM_CASES) fatal("Too many cases, max %d", MAX_NUM_CASES);
+ if (_numcases >= MAX_NUM_CASES) error("Too many cases, max %d", MAX_NUM_CASES);
ttd_strlcpy(_cases[_numcases], s, sizeof(_cases[_numcases]));
_numcases++;
}
} else {
- fatal("unknown pragma '%s'", str);
+ error("unknown pragma '%s'", str);
}
}
@@ -690,16 +689,16 @@
if (ar == NULL) break;
// Sanity checking
- if (argno != -1 && ar->consumes == 0) fatal("Non consumer param can't have a paramindex");
+ if (argno != -1 && ar->consumes == 0) error("Non consumer param can't have a paramindex");
if (ar->consumes) {
if (argno != -1) argidx = argno;
- if (argidx < 0 || argidx >= lengthof(p->cmd)) fatal("invalid param idx %d", argidx);
- if (p->cmd[argidx] != NULL && p->cmd[argidx] != ar) fatal("duplicate param idx %d", argidx);
+ if (argidx < 0 || argidx >= lengthof(p->cmd)) error("invalid param idx %d", argidx);
+ if (p->cmd[argidx] != NULL && p->cmd[argidx] != ar) error("duplicate param idx %d", argidx);
p->cmd[argidx++] = ar;
} else if (!(ar->flags & C_DONTCOUNT)) { // Ignore some of them
- if (p->np >= lengthof(p->pairs)) fatal("too many commands in string, max %d", lengthof(p->pairs));
+ if (p->np >= lengthof(p->pairs)) error("too many commands in string, max %d", lengthof(p->pairs));
p->pairs[p->np].a = ar;
p->pairs[p->np].v = param[0] != '\0' ? strdup(param) : "";
p->np++;
@@ -738,7 +737,7 @@
// For each string in templ, see if we find it in lang
if (templ.np != lang.np) {
- warning("%s: template string and language string have a different # of commands", name);
+ strgen_warning("%s: template string and language string have a different # of commands", name);
result = false;
}
@@ -756,7 +755,7 @@
}
if (!found) {
- warning("%s: command '%s' exists in template file but not in language file", name, templ.pairs[i].a->cmd);
+ strgen_warning("%s: command '%s' exists in template file but not in language file", name, templ.pairs[i].a->cmd);
result = false;
}
}
@@ -765,7 +764,7 @@
// Check if the non consumer commands match up also.
for (i = 0; i < lengthof(templ.cmd); i++) {
if (TranslateCmdForCompare(templ.cmd[i]) != TranslateCmdForCompare(lang.cmd[i])) {
- warning("%s: Param idx #%d '%s' doesn't match with template command '%s'", name, i,
+ strgen_warning("%s: Param idx #%d '%s' doesn't match with template command '%s'", name, i,
lang.cmd[i] == NULL ? "<empty>" : lang.cmd[i]->cmd,
templ.cmd[i] == NULL ? "<empty>" : templ.cmd[i]->cmd);
result = false;
@@ -777,7 +776,7 @@
static void HandleString(char *str, bool master)
{
- char *s,*t;
+ char *s, *t;
LangString *ent;
char *casep;
@@ -791,7 +790,7 @@
s = strchr(str, ':');
if (s == NULL) {
- error("Line has no ':' delimiter");
+ strgen_error("Line has no ':' delimiter");
return;
}
@@ -806,7 +805,7 @@
const char *tmp;
for (tmp = s; *tmp != '\0';) {
size_t len = Utf8Validate(tmp);
- if (len == 0) fatal("Invalid UTF-8 sequence in '%s'", s);
+ if (len == 0) error("Invalid UTF-8 sequence in '%s'", s);
tmp += len;
}
}
@@ -821,18 +820,18 @@
if (master) {
if (ent != NULL && casep == NULL) {
- error("String name '%s' is used multiple times", str);
+ strgen_error("String name '%s' is used multiple times", str);
return;
}
if (ent == NULL && casep != NULL) {
- error("Base string name '%s' doesn't exist yet. Define it before defining a case.", str);
+ strgen_error("Base string name '%s' doesn't exist yet. Define it before defining a case.", str);
return;
}
if (ent == NULL) {
if (_strings[_next_string_id]) {
- error("String ID 0x%X for '%s' already in use by '%s'", ent, str, _strings[_next_string_id]->name);
+ strgen_error("String ID 0x%X for '%s' already in use by '%s'", ent, str, _strings[_next_string_id]->name);
return;
}
@@ -859,12 +858,12 @@
} else {
if (ent == NULL) {
- warning("String name '%s' does not exist in master file", str);
+ strgen_warning("String name '%s' does not exist in master file", str);
return;
}
if (ent->translated && casep == NULL) {
- error("String name '%s' is used multiple times", str);
+ strgen_error("String name '%s' is used multiple times", str);
return;
}
@@ -912,7 +911,7 @@
// derive some strings from english....
in = fopen(file, "r");
- if (in == NULL) fatal("Cannot open file");
+ if (in == NULL) error("Cannot open file");
_cur_line = 1;
while (fgets(buf, sizeof(buf), in) != NULL) {
rstrip(buf);
@@ -922,7 +921,7 @@
fclose(in);
if (StrEmpty(_lang_name) || StrEmpty(_lang_ownname) || StrEmpty(_lang_isocode)) {
- fatal("Language must include ##name, ##ownname and ##isocode");
+ error("Language must include ##name, ##ownname and ##isocode");
}
}
@@ -991,7 +990,7 @@
if (f2 == NULL) return false;
f1 = fopen(n1, "rb");
- if (f1 == NULL) fatal("can't open %s", n1);
+ if (f1 == NULL) error("can't open %s", n1);
do {
l1 = fread(b1, 1, sizeof(b1), f1);
@@ -1017,7 +1016,7 @@
int next = -1;
out = fopen("tmp.xxx", "w");
- if (out == NULL) fatal("can't open tmp.xxx");
+ if (out == NULL) error("can't open tmp.xxx");
fprintf(out, "/* This file is automatically generated. Do not modify */\n\n");
fprintf(out, "#ifndef TABLE_STRINGS_H\n");
@@ -1052,7 +1051,7 @@
#if defined(WIN32) || defined(WIN64)
unlink(filename);
#endif
- if (rename("tmp.xxx", filename) == -1) fatal("rename() failed");
+ if (rename("tmp.xxx", filename) == -1) error("rename() failed");
}
}
@@ -1061,7 +1060,7 @@
int i, sum;
if (argidx < 0 || argidx >= lengthof(_cur_pcs.cmd))
- fatal("invalid argidx %d", argidx);
+ error("invalid argidx %d", argidx);
for (i = sum = 0; i < argidx; i++) {
const CmdStruct *cs = _cur_pcs.cmd[i];
@@ -1112,7 +1111,7 @@
// Output the one from the master string... it's always accurate.
cs = _cur_pcs.cmd[_cur_argidx++];
if (cs == NULL) {
- fatal("%s: No argument exists at position %d", _cur_ident, _cur_argidx - 1);
+ error("%s: No argument exists at position %d", _cur_ident, _cur_argidx - 1);
}
}
@@ -1128,7 +1127,7 @@
fputc((length >> 8) | 0xC0, f);
fputc(length & 0xFF, f);
} else {
- fatal("string too long");
+ error("string too long");
}
}
@@ -1142,7 +1141,7 @@
uint j;
f = fopen(filename, "wb");
- if (f == NULL) fatal("can't open %s", filename);
+ if (f == NULL) error("can't open %s", filename);
memset(&hdr, 0, sizeof(hdr));
for (i = 0; i != 32; i++) {
@@ -1180,7 +1179,7 @@
// Produce a message if a string doesn't have a translation.
if (_show_todo > 0 && ls->translated == NULL) {
if ((_show_todo & 2) != 0) {
- warning("'%s' is untranslated", ls->name);
+ strgen_warning("'%s' is untranslated", ls->name);
}
if ((_show_todo & 1) != 0) {
const char *s = "<TODO> ";
--- a/src/strings.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/strings.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -1195,7 +1195,7 @@
}
/* town name? */
- if (IsInsideMM(ind - 6, 0, SPECSTR_TOWNNAME_LAST-SPECSTR_TOWNNAME_START + 1)) {
+ if (IsInsideMM(ind - 6, 0, SPECSTR_TOWNNAME_LAST - SPECSTR_TOWNNAME_START + 1)) {
buff = GetSpecialTownNameString(buff, ind - 6, GetInt32(&argv), last);
return strecpy(buff, " Transport", last);
}
--- a/src/table/build_industry.h Thu Apr 17 08:40:01 2008 +0000
+++ b/src/table/build_industry.h Fri Apr 18 23:33:51 2008 +0000
@@ -1176,7 +1176,7 @@
#define MI(tbl, sndc, snd, d, pc, ai1, ai2, ai3, ai4, ag1, ag2, ag3, ag4, col, \
c1, c2, c3, proc, p1, r1, p2, r2, m, a1, im1, a2, im2, a3, im3, pr, clim, bev, in, intx, s1, s2, s3) \
{tbl, lengthof(tbl), min(255, d), 0, d, pc, {c1, c2, c3}, proc, {p1, p2}, {r1, r2}, m, \
- {a1, a2, a3}, {{im1, 0}, {im2, 0}, {im3, 0}}, pr, clim, bev, col, GRFMappedStringID(in, 0), GRFMappedStringID(intx, 0), GRFMappedStringID(s1, 0), GRFMappedStringID(s2, 0), GRFMappedStringID(s3, 0), GRFMappedStringID(STR_UNDEFINED, 0), {ai1, ai2, ai3, ai4}, {ag1, ag2, ag3, ag4}, \
+ {a1, a2, a3}, {{im1, 0}, {im2, 0}, {im3, 0}}, pr, clim, bev, col, in, intx, s1, s2, s3, STR_UNDEFINED, {ai1, ai2, ai3, ai4}, {ag1, ag2, ag3, ag4}, \
sndc, snd, 0, 0, true, {INVALID_INDUSTRYTYPE, 0, NULL, NULL, INVALID_INDUSTRYTYPE}}
/* Format:
tile table count and sounds table
--- a/src/table/cargo_const.h Thu Apr 17 08:40:01 2008 +0000
+++ b/src/table/cargo_const.h Fri Apr 18 23:33:51 2008 +0000
@@ -3,7 +3,7 @@
/* Table of all default cargo types */
#define MK(bt, label, c, e, f, g, h, fr, te, ks1, ks2, ks3, ks4, ks5, l, m) \
- {bt, label, 0, c, c, e, f, {g, h}, fr, te, 0, 0, GRFMappedStringID(ks1, 0), GRFMappedStringID(ks2, 0), GRFMappedStringID(ks3, 0), GRFMappedStringID(ks4, 0), GRFMappedStringID(ks5, 0), l, m, NULL}
+ {bt, label, 0, c, c, e, f, {g, h}, fr, te, 0, 0, ks1, ks2, ks3, ks4, ks5, l, m, NULL}
static const CargoSpec _default_cargo[] = {
MK( 0, 'PASS', 152, 1, 3185, 0, 24, false, TE_PASSENGERS,
STR_000F_PASSENGERS, STR_002F_PASSENGER, STR_PASSENGERS, STR_QUANTITY_PASSENGERS, STR_ABBREV_PASSENGERS,
--- a/src/table/town_land.h Thu Apr 17 08:40:01 2008 +0000
+++ b/src/table/town_land.h Fri Apr 18 23:33:51 2008 +0000
@@ -1803,7 +1803,7 @@
* @see HouseSpec
*/
#define MS(mnd, mxd, p, rc, bn, rr, mg, ca1, ca2, ca3, bf, ba, cg1, cg2, cg3) \
- {mnd, mxd, p, rc, GRFMappedStringID(bn, 0), rr, mg, {ca1, ca2, ca3}, {cg1, cg2, cg3}, bf, ba, true, \
+ {mnd, mxd, p, rc, bn, rr, mg, {ca1, ca2, ca3}, {cg1, cg2, cg3}, bf, ba, true, \
0, NULL, 0, 0, {0, 0, 0, 0}, 16, NO_EXTRA_FLAG, HOUSE_NO_CLASS, 0, 2, 0, 0, 0, NULL}
/** House specifications from original data */
static const HouseSpec _original_house_specs[] = {
--- a/src/timetable_cmd.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/timetable_cmd.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -160,15 +160,15 @@
if (!_patches.timetabling) return;
/* Make sure the timetable only starts when the vehicle reaches the first
- * order, not when travelling from the depot to the first station. */
- if (v->cur_order_index == 0 && !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) {
- SetBit(v->vehicle_flags, VF_TIMETABLE_STARTED);
- return;
- }
+ * order, not when travelling from the depot to the first station. */
+ if (v->cur_order_index == 0 && !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) {
+ SetBit(v->vehicle_flags, VF_TIMETABLE_STARTED);
+ return;
+ }
if (!HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) return;
- if (HasBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE)) {
+ if (HasBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE)) {
if (timetabled == 0) {
/* Round the time taken up to the nearest day, as this will avoid
* confusion for people who are timetabling in days, and can be
@@ -182,7 +182,7 @@
* assume that autofill is finished and turn it off again. */
ClrBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE);
}
- }
+ }
/* Vehicles will wait at stations if they arrive early even if they are not
* timetabled to wait there, so make sure the lateness counter is updated
--- a/src/timetable_gui.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/timetable_gui.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -10,7 +10,6 @@
#include "window_gui.h"
#include "textbuf_gui.h"
#include "cargotype.h"
-#include "depot.h"
#include "strings_func.h"
#include "vehicle_base.h"
#include "string_func.h"
--- a/src/toolbar_gui.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/toolbar_gui.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -28,24 +28,47 @@
#include "toolbar_gui.h"
#include "vehicle_base.h"
#include "gfx_func.h"
+#include "cheat_func.h"
+#include "transparency_gui.h"
+#include "screenshot.h"
+#include "newgrf_config.h"
+#include "signs_func.h"
+#include "fios.h"
+#include "functions.h"
+#include "console.h"
+#include "news_gui.h"
+#include "ai/ai_gui.hpp"
#include "network/network.h"
+#include "network/network_gui.h"
#include "table/strings.h"
#include "table/sprites.h"
-extern void SelectSignTool();
-extern RailType _last_built_railtype;
-extern RoadType _last_built_roadtype;
+static Window *PopupMainToolbMenu(Window *w, uint16 parent_button, StringID base_string, byte item_count, byte disabled_mask);
+static Window *PopupMainPlayerToolbMenu(Window *w, int main_button, int gray);
-/* Returns the position where the toolbar wants the menu to appear.
+RailType _last_built_railtype;
+RoadType _last_built_roadtype;
+
+static void SelectSignTool()
+{
+ if (_cursor.sprite == SPR_CURSOR_SIGN) {
+ ResetObjectToPlace();
+ } else {
+ SetObjectToPlace(SPR_CURSOR_SIGN, PAL_NONE, VHM_RECT, WC_MAIN_TOOLBAR, 0);
+ _place_proc = PlaceProc_Sign;
+ }
+}
+
+/** Returns the position where the toolbar wants the menu to appear.
* Make sure the dropdown is fully visible within the window.
* x + w->left because x is supposed to be the offset of the toolbar-button
* we clicked on and w->left the toolbar window itself. So meaning that
* the default position is aligned with the left side of the clicked button */
-Point GetToolbarDropdownPos(uint16 parent_button, int width, int height)
+static Point GetToolbarDropdownPos(uint16 parent_button, int width, int height)
{
- const Window *w = FindWindowById(WC_MAIN_TOOLBAR,0);
+ const Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0);
Point pos;
pos.x = w->widget[GB(parent_button, 0, 8)].left;
pos.x = w->left + Clamp(pos.x, 0, w->width - width);
@@ -54,6 +77,7 @@
return pos;
}
+/* --- Pausing --- */
static void ToolbarPauseClick(Window *w)
{
@@ -62,168 +86,15 @@
if (DoCommandP(0, _pause_game ? 0 : 1, 0, NULL, CMD_PAUSE)) SndPlayFx(SND_15_BEEP);
}
+/* --- Fast forwarding --- */
+
static void ToolbarFastForwardClick(Window *w)
{
_fast_forward ^= true;
SndPlayFx(SND_15_BEEP);
}
-static void ToolbarSaveClick(Window *w)
-{
- PopupMainToolbMenu(w, 3, STR_015C_SAVE_GAME, 4, 0);
-}
-
-static void ToolbarMapClick(Window *w)
-{
- PopupMainToolbMenu(w, 4, STR_02DE_MAP_OF_WORLD, 3, 0);
-}
-
-static void ToolbarTownClick(Window *w)
-{
- PopupMainToolbMenu(w, 5, STR_02BB_TOWN_DIRECTORY, 1, 0);
-}
-
-static void ToolbarSubsidiesClick(Window *w)
-{
- PopupMainToolbMenu(w, 6, STR_02DD_SUBSIDIES, 1, 0);
-}
-
-static void ToolbarStationsClick(Window *w)
-{
- PopupMainPlayerToolbMenu(w, 7, 0);
-}
-
-static void ToolbarMoneyClick(Window *w)
-{
- PopupMainPlayerToolbMenu(w, 8, 0);
-}
-
-static void ToolbarPlayersClick(Window *w)
-{
- PopupMainPlayerToolbMenu(w, 9, 0);
-}
-
-static void ToolbarGraphsClick(Window *w)
-{
- PopupMainToolbMenu(w, 10, STR_0154_OPERATING_PROFIT_GRAPH, 6, 0);
-}
-
-static void ToolbarLeagueClick(Window *w)
-{
- PopupMainToolbMenu(w, 11, STR_015A_COMPANY_LEAGUE_TABLE, 2, 0);
-}
-
-static void ToolbarIndustryClick(Window *w)
-{
- /* Disable build-industry menu if we are a spectator */
- PopupMainToolbMenu(w, 12, STR_INDUSTRY_DIR, 2, (_current_player == PLAYER_SPECTATOR) ? (1 << 1) : 0);
-}
-
-static void ToolbarTrainClick(Window *w)
-{
- const Vehicle *v;
- int dis = -1;
-
- FOR_ALL_VEHICLES(v) {
- if (v->type == VEH_TRAIN && IsFrontEngine(v)) ClrBit(dis, v->owner);
- }
- PopupMainPlayerToolbMenu(w, 13, dis);
-}
-
-static void ToolbarRoadClick(Window *w)
-{
- const Vehicle *v;
- int dis = -1;
-
- FOR_ALL_VEHICLES(v) {
- if (v->type == VEH_ROAD && IsRoadVehFront(v)) ClrBit(dis, v->owner);
- }
- PopupMainPlayerToolbMenu(w, 14, dis);
-}
-
-static void ToolbarShipClick(Window *w)
-{
- const Vehicle *v;
- int dis = -1;
-
- FOR_ALL_VEHICLES(v) {
- if (v->type == VEH_SHIP) ClrBit(dis, v->owner);
- }
- PopupMainPlayerToolbMenu(w, 15, dis);
-}
-
-static void ToolbarAirClick(Window *w)
-{
- const Vehicle *v;
- int dis = -1;
-
- FOR_ALL_VEHICLES(v) {
- if (v->type == VEH_AIRCRAFT) ClrBit(dis, v->owner);
- }
- PopupMainPlayerToolbMenu(w, 16, dis);
-}
-
-
-static void ToolbarZoomInClick(Window *w)
-{
- if (DoZoomInOutWindow(ZOOM_IN, FindWindowById(WC_MAIN_WINDOW, 0))) {
- w->HandleButtonClick(17);
- SndPlayFx(SND_15_BEEP);
- }
-}
-
-static void ToolbarZoomOutClick(Window *w)
-{
- if (DoZoomInOutWindow(ZOOM_OUT,FindWindowById(WC_MAIN_WINDOW, 0))) {
- w->HandleButtonClick(18);
- SndPlayFx(SND_15_BEEP);
- }
-}
-
-static void ToolbarBuildRailClick(Window *w)
-{
- const Player *p = GetPlayer(_local_player);
- Window *w2 = PopupMainToolbMenu(w, 19, STR_1015_RAILROAD_CONSTRUCTION, RAILTYPE_END, ~p->avail_railtypes);
- WP(w2, menu_d).sel_index = _last_built_railtype;
-}
-
-static void ToolbarBuildRoadClick(Window *w)
-{
- const Player *p = GetPlayer(_local_player);
- /* The standard road button is *always* available */
- Window *w2 = PopupMainToolbMenu(w, 20, STR_180A_ROAD_CONSTRUCTION, 2, ~(p->avail_roadtypes | ROADTYPES_ROAD));
- WP(w2, menu_d).sel_index = _last_built_roadtype;
-}
-
-static void ToolbarBuildWaterClick(Window *w)
-{
- PopupMainToolbMenu(w, 21, STR_9800_DOCK_CONSTRUCTION, 1, 0);
-}
-
-static void ToolbarBuildAirClick(Window *w)
-{
- PopupMainToolbMenu(w, 22, STR_A01D_AIRPORT_CONSTRUCTION, 1, 0);
-}
-
-static void ToolbarForestClick(Window *w)
-{
- PopupMainToolbMenu(w, 23, STR_LANDSCAPING, 3, 0);
-}
-
-static void ToolbarMusicClick(Window *w)
-{
- PopupMainToolbMenu(w, 24, STR_01D3_SOUND_MUSIC, 1, 0);
-}
-
-static void ToolbarNewspaperClick(Window *w)
-{
- PopupMainToolbMenu(w, 25, STR_0200_LAST_MESSAGE_NEWS_REPORT, 3, 0);
-}
-
-static void ToolbarHelpClick(Window *w)
-{
- PopupMainToolbMenu(w, 26, STR_02D5_LAND_BLOCK_INFO, 7, 0);
-}
+/* --- Options button menu --- */
static void ToolbarOptionsClick(Window *w)
{
@@ -242,12 +113,413 @@
WP(w, menu_d).checked_items = x;
}
+static void MenuClickSettings(int index)
+{
+ switch (index) {
+ case 0: ShowGameOptions(); return;
+ case 1: ShowGameDifficulty(); return;
+ case 2: ShowPatchesSelection(); return;
+ case 3: ShowNewGRFSettings(!_networking, true, true, &_grfconfig); return;
+ case 4: ShowTransparencyToolbar(); break;
+
+ case 6: ToggleBit(_display_opt, DO_SHOW_TOWN_NAMES); break;
+ case 7: ToggleBit(_display_opt, DO_SHOW_STATION_NAMES); break;
+ case 8: ToggleBit(_display_opt, DO_SHOW_SIGNS); break;
+ case 9: ToggleBit(_display_opt, DO_WAYPOINTS); break;
+ case 10: ToggleBit(_display_opt, DO_FULL_ANIMATION); break;
+ case 11: ToggleBit(_display_opt, DO_FULL_DETAIL); break;
+ case 12: ToggleTransparency(TO_HOUSES); break;
+ case 13: ToggleTransparency(TO_SIGNS); break;
+ }
+ MarkWholeScreenDirty();
+}
+
+/* --- Saving/loading button menu --- */
+
+static void ToolbarSaveClick(Window *w)
+{
+ PopupMainToolbMenu(w, 3, STR_015C_SAVE_GAME, 4, 0);
+}
static void ToolbarScenSaveOrLoad(Window *w)
{
PopupMainToolbMenu(w, 3, STR_0292_SAVE_SCENARIO, 6, 0);
}
+static void MenuClickSaveLoad(int index)
+{
+ if (_game_mode == GM_EDITOR) {
+ switch (index) {
+ case 0: ShowSaveLoadDialog(SLD_SAVE_SCENARIO); break;
+ case 1: ShowSaveLoadDialog(SLD_LOAD_SCENARIO); break;
+ case 2: ShowSaveLoadDialog(SLD_LOAD_HEIGHTMAP); break;
+ case 3: AskExitToGameMenu(); break;
+ case 5: HandleExitGameRequest(); break;
+ }
+ } else {
+ switch (index) {
+ case 0: ShowSaveLoadDialog(SLD_SAVE_GAME); break;
+ case 1: ShowSaveLoadDialog(SLD_LOAD_GAME); break;
+ case 2: AskExitToGameMenu(); break;
+ case 3: HandleExitGameRequest(); break;
+ }
+ }
+}
+
+/* --- Map button menu --- */
+
+static void ToolbarMapClick(Window *w)
+{
+ PopupMainToolbMenu(w, 4, STR_02DE_MAP_OF_WORLD, 3, 0);
+}
+
+static void MenuClickMap(int index)
+{
+ switch (index) {
+ case 0: ShowSmallMap(); break;
+ case 1: ShowExtraViewPortWindow(); break;
+ case 2: ShowSignList(); break;
+ }
+}
+
+static void MenuClickScenMap(int index)
+{
+ switch (index) {
+ case 0: ShowSmallMap(); break;
+ case 1: ShowExtraViewPortWindow(); break;
+ case 2: ShowSignList(); break;
+ case 3: ShowTownDirectory(); break;
+ }
+}
+
+/* --- Town button menu --- */
+
+static void ToolbarTownClick(Window *w)
+{
+ PopupMainToolbMenu(w, 5, STR_02BB_TOWN_DIRECTORY, 1, 0);
+}
+
+static void MenuClickTown(int index)
+{
+ ShowTownDirectory();
+}
+
+/* --- Subidies button menu --- */
+
+static void ToolbarSubsidiesClick(Window *w)
+{
+ PopupMainToolbMenu(w, 6, STR_02DD_SUBSIDIES, 1, 0);
+}
+
+static void MenuClickSubsidies(int index)
+{
+ ShowSubsidiesList();
+}
+
+/* --- Stations button menu --- */
+
+static void ToolbarStationsClick(Window *w)
+{
+ PopupMainPlayerToolbMenu(w, 7, 0);
+}
+
+static void MenuClickStations(int index)
+{
+ ShowPlayerStations((PlayerID)index);
+}
+
+/* --- Finances button menu --- */
+
+static void ToolbarFinancesClick(Window *w)
+{
+ PopupMainPlayerToolbMenu(w, 8, 0);
+}
+
+static void MenuClickFinances(int index)
+{
+ ShowPlayerFinances((PlayerID)index);
+}
+
+/* --- Company's button menu --- */
+
+static void ToolbarPlayersClick(Window *w)
+{
+ PopupMainPlayerToolbMenu(w, 9, 0);
+}
+
+static void MenuClickCompany(int index)
+{
+ if (_networking && index == 0) {
+ ShowClientList();
+ } else {
+ if (_networking) index--;
+ ShowPlayerCompany((PlayerID)index);
+ }
+}
+
+/* --- Graphs button menu --- */
+
+static void ToolbarGraphsClick(Window *w)
+{
+ PopupMainToolbMenu(w, 10, STR_0154_OPERATING_PROFIT_GRAPH, 6, 0);
+}
+
+static void MenuClickGraphs(int index)
+{
+ switch (index) {
+ case 0: ShowOperatingProfitGraph(); break;
+ case 1: ShowIncomeGraph(); break;
+ case 2: ShowDeliveredCargoGraph(); break;
+ case 3: ShowPerformanceHistoryGraph(); break;
+ case 4: ShowCompanyValueGraph(); break;
+ case 5: ShowCargoPaymentRates(); break;
+ }
+}
+
+/* --- League button menu --- */
+
+static void ToolbarLeagueClick(Window *w)
+{
+ PopupMainToolbMenu(w, 11, STR_015A_COMPANY_LEAGUE_TABLE, 2, 0);
+}
+
+static void MenuClickLeague(int index)
+{
+ switch (index) {
+ case 0: ShowCompanyLeagueTable(); break;
+ case 1: ShowPerformanceRatingDetail(); break;
+ }
+}
+
+/* --- Industries button menu --- */
+
+static void ToolbarIndustryClick(Window *w)
+{
+ /* Disable build-industry menu if we are a spectator */
+ PopupMainToolbMenu(w, 12, STR_INDUSTRY_DIR, 2, (_current_player == PLAYER_SPECTATOR) ? (1 << 1) : 0);
+}
+
+static void MenuClickIndustry(int index)
+{
+ switch (index) {
+ case 0: ShowIndustryDirectory(); break;
+ case 1: ShowBuildIndustryWindow(); break;
+ }
+}
+
+/* --- Trains button menu + 1 helper function for all vehicles. --- */
+
+static void ToolbarVehicleClick(Window *w, VehicleType veh)
+{
+ const Vehicle *v;
+ int dis = ~0;
+
+ FOR_ALL_VEHICLES(v) {
+ if (v->type == veh && v->IsPrimaryVehicle()) {
+ ClrBit(dis, v->owner);
+ break;
+ }
+ }
+ PopupMainPlayerToolbMenu(w, 13 + veh, dis);
+}
+
+
+static void ToolbarTrainClick(Window *w)
+{
+ ToolbarVehicleClick(w, VEH_TRAIN);
+}
+
+static void MenuClickShowTrains(int index)
+{
+ ShowVehicleListWindow((PlayerID)index, VEH_TRAIN);
+}
+
+/* --- Road vehicle button menu --- */
+
+static void ToolbarRoadClick(Window *w)
+{
+ ToolbarVehicleClick(w, VEH_ROAD);
+}
+
+static void MenuClickShowRoad(int index)
+{
+ ShowVehicleListWindow((PlayerID)index, VEH_ROAD);
+}
+
+/* --- Ship button menu --- */
+
+static void ToolbarShipClick(Window *w)
+{
+ ToolbarVehicleClick(w, VEH_SHIP);
+}
+
+static void MenuClickShowShips(int index)
+{
+ ShowVehicleListWindow((PlayerID)index, VEH_SHIP);
+}
+
+/* --- Aircraft button menu --- */
+
+static void ToolbarAirClick(Window *w)
+{
+ ToolbarVehicleClick(w, VEH_AIRCRAFT);
+}
+
+static void MenuClickShowAir(int index)
+{
+ ShowVehicleListWindow((PlayerID)index, VEH_AIRCRAFT);
+}
+
+/* --- Zoom in button --- */
+
+static void ToolbarZoomInClick(Window *w)
+{
+ if (DoZoomInOutWindow(ZOOM_IN, FindWindowById(WC_MAIN_WINDOW, 0))) {
+ w->HandleButtonClick(17);
+ SndPlayFx(SND_15_BEEP);
+ }
+}
+
+/* --- Zoom out button --- */
+
+static void ToolbarZoomOutClick(Window *w)
+{
+ if (DoZoomInOutWindow(ZOOM_OUT, FindWindowById(WC_MAIN_WINDOW, 0))) {
+ w->HandleButtonClick(18);
+ SndPlayFx(SND_15_BEEP);
+ }
+}
+
+/* --- Rail button menu --- */
+
+static void ToolbarBuildRailClick(Window *w)
+{
+ const Player *p = GetPlayer(_local_player);
+ Window *w2 = PopupMainToolbMenu(w, 19, STR_1015_RAILROAD_CONSTRUCTION, RAILTYPE_END, ~p->avail_railtypes);
+ WP(w2, menu_d).sel_index = _last_built_railtype;
+}
+
+static void MenuClickBuildRail(int index)
+{
+ _last_built_railtype = (RailType)index;
+ ShowBuildRailToolbar(_last_built_railtype, -1);
+}
+
+/* --- Road button menu --- */
+
+static void ToolbarBuildRoadClick(Window *w)
+{
+ const Player *p = GetPlayer(_local_player);
+ /* The standard road button is *always* available */
+ Window *w2 = PopupMainToolbMenu(w, 20, STR_180A_ROAD_CONSTRUCTION, 2, ~(p->avail_roadtypes | ROADTYPES_ROAD));
+ WP(w2, menu_d).sel_index = _last_built_roadtype;
+}
+
+static void MenuClickBuildRoad(int index)
+{
+ _last_built_roadtype = (RoadType)index;
+ ShowBuildRoadToolbar(_last_built_roadtype);
+}
+
+/* --- Water button menu --- */
+
+static void ToolbarBuildWaterClick(Window *w)
+{
+ PopupMainToolbMenu(w, 21, STR_9800_DOCK_CONSTRUCTION, 1, 0);
+}
+
+static void MenuClickBuildWater(int index)
+{
+ ShowBuildDocksToolbar();
+}
+
+/* --- Airport button menu --- */
+
+static void ToolbarBuildAirClick(Window *w)
+{
+ PopupMainToolbMenu(w, 22, STR_A01D_AIRPORT_CONSTRUCTION, 1, 0);
+}
+
+static void MenuClickBuildAir(int index)
+{
+ ShowBuildAirToolbar();
+}
+
+/* --- Forest button menu --- */
+
+static void ToolbarForestClick(Window *w)
+{
+ PopupMainToolbMenu(w, 23, STR_LANDSCAPING, 3, 0);
+}
+
+static void MenuClickForest(int index)
+{
+ switch (index) {
+ case 0: ShowTerraformToolbar(); break;
+ case 1: ShowBuildTreesToolbar(); break;
+ case 2: SelectSignTool(); break;
+ }
+}
+
+/* --- Music button menu --- */
+
+static void ToolbarMusicClick(Window *w)
+{
+ PopupMainToolbMenu(w, 24, STR_01D3_SOUND_MUSIC, 1, 0);
+}
+
+static void MenuClickMusicWindow(int index)
+{
+ ShowMusicWindow();
+}
+
+/* --- Newspaper button menu --- */
+
+static void ToolbarNewspaperClick(Window *w)
+{
+ PopupMainToolbMenu(w, 25, STR_0200_LAST_MESSAGE_NEWS_REPORT, 3, 0);
+}
+
+static void MenuClickNewspaper(int index)
+{
+ switch (index) {
+ case 0: ShowLastNewsMessage(); break;
+ case 1: ShowMessageOptions(); break;
+ case 2: ShowMessageHistory(); break;
+ }
+}
+
+/* --- Help button menu --- */
+
+static void ToolbarHelpClick(Window *w)
+{
+ PopupMainToolbMenu(w, 26, STR_02D5_LAND_BLOCK_INFO, 7, 0);
+}
+
+static void MenuClickSmallScreenshot()
+{
+ SetScreenshotType(SC_VIEWPORT);
+}
+
+static void MenuClickWorldScreenshot()
+{
+ SetScreenshotType(SC_WORLD);
+}
+
+static void MenuClickHelp(int index)
+{
+ switch (index) {
+ case 0: PlaceLandBlockInfo(); break;
+ case 2: IConsoleSwitch(); break;
+ case 3: ShowAIDebugWindow(); break;
+ case 4: MenuClickSmallScreenshot(); break;
+ case 5: MenuClickWorldScreenshot(); break;
+ case 6: ShowAboutWindow(); break;
+ }
+}
+
+/* --- Scenario editor specific handlers. */
+
static void ToolbarScenDateBackward(Window *w)
{
/* don't allow too fast scrolling */
@@ -345,6 +617,8 @@
}
+/* --- Toolbar handling for the 'normal' case */
+
typedef void ToolbarButtonProc(Window *w);
static ToolbarButtonProc * const _toolbar_button_procs[] = {
@@ -356,7 +630,7 @@
ToolbarTownClick,
ToolbarSubsidiesClick,
ToolbarStationsClick,
- ToolbarMoneyClick,
+ ToolbarFinancesClick,
ToolbarPlayersClick,
ToolbarGraphsClick,
ToolbarLeagueClick,
@@ -377,17 +651,13 @@
ToolbarHelpClick,
};
-extern void MenuClickSmallScreenshot();
-extern void MenuClickWorldScreenshot();
-extern void MenuClickSaveLoad(int index);
-
-void MainToolbarWndProc(Window *w, WindowEvent *e)
+static void MainToolbarWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
case WE_PAINT:
/* Draw brown-red toolbar bg. */
- GfxFillRect(0, 0, w->width-1, w->height-1, 0xB2);
- GfxFillRect(0, 0, w->width-1, w->height-1, 0xB4 | (1 << PALETTE_MODIFIER_GREYOUT));
+ GfxFillRect(0, 0, w->width - 1, w->height - 1, 0xB2);
+ GfxFillRect(0, 0, w->width - 1, w->height - 1, 0xB4 | (1 << PALETTE_MODIFIER_GREYOUT));
/* If spectator, disable all construction buttons
* ie : Build road, rail, ships, airports and landscaping
@@ -403,8 +673,7 @@
break;
case WE_CLICK:
- if (_game_mode != GM_MENU && !w->IsWidgetDisabled(e->we.click.widget))
- _toolbar_button_procs[e->we.click.widget](w);
+ if (_game_mode != GM_MENU && !w->IsWidgetDisabled(e->we.click.widget)) _toolbar_button_procs[e->we.click.widget](w);
break;
case WE_KEYPRESS:
@@ -560,6 +829,8 @@
};
+/* --- Toolbar handling for the scenario editor */
+
static ToolbarButtonProc * const _scen_toolbar_button_procs[] = {
ToolbarPauseClick,
ToolbarFastForwardClick,
@@ -590,7 +861,7 @@
ToolbarHelpClick,
};
-void ScenEditToolbarWndProc(Window *w, WindowEvent *e)
+static void ScenEditToolbarWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
case WE_PAINT:
@@ -598,8 +869,8 @@
w->SetWidgetDisabledState(7, _patches_newgame.starting_year >= MAX_YEAR);
/* Draw brown-red toolbar bg. */
- GfxFillRect(0, 0, w->width-1, w->height-1, 0xB2);
- GfxFillRect(0, 0, w->width-1, w->height-1, 0xB4 | (1 << PALETTE_MODIFIER_GREYOUT));
+ GfxFillRect(0, 0, w->width - 1, w->height - 1, 0xB2);
+ GfxFillRect(0, 0, w->width - 1, w->height - 1, 0xB4 | (1 << PALETTE_MODIFIER_GREYOUT));
DrawWindowWidgets(w);
@@ -666,7 +937,7 @@
case WE_RESIZE: {
/* There are 15 buttons plus some spacings if the space allows it.
- * Furthermore there are two panels of which one is non-essential
+ * Furthermore there are two panels of which one is non - essential
* and that one can be removed is the space is too small. */
uint buttons_width;
uint spacing;
@@ -793,7 +1064,375 @@
ScenEditToolbarWndProc
};
+/* --- Rendering/handling the drop down menus --- */
+
+typedef void MenuClickedProc(int index);
+
+static MenuClickedProc * const _menu_clicked_procs[] = {
+ NULL, /* 0 */
+ NULL, /* 1 */
+ MenuClickSettings, /* 2 */
+ MenuClickSaveLoad, /* 3 */
+ MenuClickMap, /* 4 */
+ MenuClickTown, /* 5 */
+ MenuClickSubsidies, /* 6 */
+ MenuClickStations, /* 7 */
+ MenuClickFinances, /* 8 */
+ MenuClickCompany, /* 9 */
+ MenuClickGraphs, /* 10 */
+ MenuClickLeague, /* 11 */
+ MenuClickIndustry, /* 12 */
+ MenuClickShowTrains, /* 13 */
+ MenuClickShowRoad, /* 14 */
+ MenuClickShowShips, /* 15 */
+ MenuClickShowAir, /* 16 */
+ MenuClickScenMap, /* 17 */
+ NULL, /* 18 */
+ MenuClickBuildRail, /* 19 */
+ MenuClickBuildRoad, /* 20 */
+ MenuClickBuildWater, /* 21 */
+ MenuClickBuildAir, /* 22 */
+ MenuClickForest, /* 23 */
+ MenuClickMusicWindow, /* 24 */
+ MenuClickNewspaper, /* 25 */
+ MenuClickHelp, /* 26 */
+};
+
+static void MenuWndProc(Window *w, WindowEvent *e)
+{
+ switch (e->event) {
+ case WE_CREATE:
+ w->widget[0].right = w->width - 1;
+ break;
+
+ case WE_PAINT: {
+ byte count = WP(w, menu_d).item_count;
+ byte sel = WP(w, menu_d).sel_index;
+ uint16 chk = WP(w, menu_d).checked_items;
+ StringID string = WP(w, menu_d).string_id;
+ byte dis = WP(w, menu_d).disabled_items;
+
+ DrawWindowWidgets(w);
+
+ int x = 1;
+ int y = 1;
+
+ for (; count != 0; count--, string++, sel--) {
+ TextColour color = HasBit(dis, 0) ? TC_GREY : (sel == 0) ? TC_WHITE : TC_BLACK;
+ if (sel == 0) GfxFillRect(x, y, x + w->width - 3, y + 9, 0);
+
+ if (HasBit(chk, 0)) DrawString(x + 2, y, STR_CHECKMARK, color);
+ DrawString(x + 2, y, string, color);
+
+ y += 10;
+ chk >>= 1;
+ dis >>= 1;
+ }
+ } break;
+
+ case WE_DESTROY: {
+ Window *v = FindWindowById(WC_MAIN_TOOLBAR, 0);
+ v->RaiseWidget(WP(w, menu_d).main_button);
+ SetWindowDirty(v);
+ return;
+ }
+
+ case WE_POPUPMENU_SELECT: {
+ int index = GetMenuItemIndex(w, e->we.popupmenu.pt.x, e->we.popupmenu.pt.y);
+
+ if (index < 0) {
+ Window *w2 = FindWindowById(WC_MAIN_TOOLBAR,0);
+ if (GetWidgetFromPos(w2, e->we.popupmenu.pt.x - w2->left, e->we.popupmenu.pt.y - w2->top) == WP(w, menu_d).main_button)
+ index = WP(w, menu_d).sel_index;
+ }
+
+ int action_id = WP(w, menu_d).action_id;
+ DeleteWindow(w);
+
+ if (index >= 0) {
+ assert((uint)index <= lengthof(_menu_clicked_procs));
+ _menu_clicked_procs[action_id](index);
+ }
+
+ } break;
+
+ case WE_POPUPMENU_OVER: {
+ int index = GetMenuItemIndex(w, e->we.popupmenu.pt.x, e->we.popupmenu.pt.y);
+
+ if (index == -1 || index == WP(w, menu_d).sel_index) return;
+
+ WP(w, menu_d).sel_index = index;
+ SetWindowDirty(w);
+ return;
+ }
+ }
+}
+
+/* Dynamic widget length determined by toolbar-string length.
+ * See PopupMainToolbMenu en MenuWndProc */
+static const Widget _menu_widgets[] = {
+{ WWT_PANEL, RESIZE_NONE, 14, 0, 0, 0, 0, 0x0, STR_NULL},
+{ WIDGETS_END},
+};
+
+
+/**
+ * Get the maximum length of a given string in a string-list. This is an
+ * implicit string-list where the ID's are consecutive
+ * @param base_string StringID of the first string in the list
+ * @param count amount of StringID's in the list
+ * @return the length of the longest string
+ */
+static int GetStringListMaxWidth(StringID base_string, byte count)
+{
+ char buffer[512];
+ int width, max_width = 0;
+
+ for (byte i = 0; i != count; i++) {
+ GetString(buffer, base_string + i, lastof(buffer));
+ width = GetStringBoundingBox(buffer).width;
+ if (width > max_width) max_width = width;
+ }
+
+ return max_width;
+}
+
+/**
+ * Show a general dropdown menu. The positioning of the dropdown menu
+ * defaults to the left side of the parent_button, eg the button that caused
+ * this window to appear. The only exceptions are when the right side of this
+ * dropdown would fall outside the main toolbar window, in that case it is
+ * aligned with the toolbar's right side.
+ * Since the disable-mask is only 8 bits right now, these dropdowns are
+ * restricted to 8 items max if any bits of disabled_mask are active.
+ * @param w Pointer to a window this dropdown menu belongs to. Has no effect
+ * whatsoever, only graphically for positioning.
+ * @param parent_button The widget identifier of the button that was clicked for
+ * this dropdown. The created dropdown then knows what button to raise (button) on
+ * action and whose function to execute (action).
+ * It is possible to appoint another button for an action event by setting the
+ * upper 8 bits of this parameter. If non is set, action is presumed to be the same
+ * as button. So<br>
+ * button bits 0 - 7 - widget clicked to get dropdown
+ * action bits 8 - 15 - function of widget to execute on select (defaults to bits 0 - 7)
+ * @param base_string The first StringID shown in the dropdown list. All others are
+ * consecutive indeces from the language file. XXX - fix? Use ingame-string tables?
+ * @param item_count Number of strings in the list, see previous parameter
+ * @param disabled_mask Bitmask of disabled strings in the list
+ * @return Return a pointer to the newly created dropdown window */
+static Window *PopupMainToolbMenu(Window *w, uint16 parent_button, StringID base_string, byte item_count, byte disabled_mask)
+{
+ assert(disabled_mask == 0 || item_count <= 8);
+ w->LowerWidget(parent_button);
+ w->InvalidateWidget(parent_button);
+
+ DeleteWindowById(WC_TOOLBAR_MENU, 0);
+
+ /* Extend the dropdown toolbar to the longest string in the list */
+ int width = max(GetStringListMaxWidth(base_string, item_count) + 6, 140);
+ int height = item_count * 10 + 2;
+
+ Point pos = GetToolbarDropdownPos(parent_button, width, height);
+
+ w = AllocateWindow(pos.x, pos.y, width, height, MenuWndProc, WC_TOOLBAR_MENU, _menu_widgets);
+ w->widget[0].bottom = item_count * 10 + 1;
+ w->flags4 &= ~WF_WHITE_BORDER_MASK;
+
+ WP(w, menu_d).item_count = item_count;
+ WP(w, menu_d).sel_index = 0;
+ WP(w, menu_d).main_button = GB(parent_button, 0, 8);
+ WP(w, menu_d).action_id = (GB(parent_button, 8, 8) != 0) ? GB(parent_button, 8, 8) : parent_button;
+ WP(w, menu_d).string_id = base_string;
+ WP(w, menu_d).checked_items = 0;
+ WP(w, menu_d).disabled_items = disabled_mask;
+
+ _popup_menu_active = true;
+
+ SndPlayFx(SND_15_BEEP);
+ return w;
+}
+
+/* --- Rendering/drawing the player menu --- */
+static int GetPlayerIndexFromMenu(int index)
+{
+ if (index >= 0) {
+ const Player *p;
+
+ FOR_ALL_PLAYERS(p) {
+ if (p->is_active && --index < 0) return p->index;
+ }
+ }
+ return -1;
+}
+
+static void UpdatePlayerMenuHeight(Window *w)
+{
+ byte num = ActivePlayerCount();
+
+ /* Increase one to fit in PlayerList in the menu when in network */
+ if (_networking && WP(w, menu_d).main_button == 9) num++;
+
+ if (WP(w, menu_d).item_count != num) {
+ WP(w, menu_d).item_count = num;
+ SetWindowDirty(w);
+ num = num * 10 + 2;
+ w->height = num;
+ w->widget[0].bottom = w->widget[0].top + num - 1;
+ w->top = GetToolbarDropdownPos(0, w->width, w->height).y;
+ SetWindowDirty(w);
+ }
+}
+
+static void PlayerMenuWndProc(Window *w, WindowEvent *e)
+{
+ switch (e->event) {
+ case WE_PAINT: {
+ UpdatePlayerMenuHeight(w);
+ DrawWindowWidgets(w);
+
+ int x = 1;
+ int y = 1;
+ int sel = WP(w, menu_d).sel_index;
+ int chk = WP(w, menu_d).checked_items; // let this mean gray items.
+
+ /* 9 = playerlist */
+ if (_networking && WP(w, menu_d).main_button == 9) {
+ if (sel == 0) {
+ GfxFillRect(x, y, x + 238, y + 9, 0);
+ }
+ DrawString(x + 19, y, STR_NETWORK_CLIENT_LIST, TC_FROMSTRING);
+ y += 10;
+ sel--;
+ }
+
+ const Player *p;
+ FOR_ALL_PLAYERS(p) {
+ if (p->is_active) {
+ if (p->index == sel) {
+ GfxFillRect(x, y, x + 238, y + 9, 0);
+ }
+
+ DrawPlayerIcon(p->index, x + 2, y + 1);
+
+ SetDParam(0, p->index);
+ SetDParam(1, p->index);
+
+ TextColour color = (p->index == sel) ? TC_WHITE : TC_BLACK;
+ if (chk & 1) color = TC_GREY;
+ DrawString(x + 19, y, STR_7021, color);
+
+ y += 10;
+ }
+ chk >>= 1;
+ }
+ } break;
+
+ case WE_DESTROY: {
+ Window *v = FindWindowById(WC_MAIN_TOOLBAR, 0);
+ v->RaiseWidget(WP(w, menu_d).main_button);
+ SetWindowDirty(v);
+ return;
+ }
+
+ case WE_POPUPMENU_SELECT: {
+ int index = GetMenuItemIndex(w, e->we.popupmenu.pt.x, e->we.popupmenu.pt.y);
+ int action_id = WP(w, menu_d).action_id;
+
+ /* We have a new entry at the top of the list of menu 9 when networking
+ * so keep that in count */
+ if (_networking && WP(w, menu_d).main_button == 9) {
+ if (index > 0) index = GetPlayerIndexFromMenu(index - 1) + 1;
+ } else {
+ index = GetPlayerIndexFromMenu(index);
+ }
+
+ if (index < 0) {
+ Window *w2 = FindWindowById(WC_MAIN_TOOLBAR,0);
+ if (GetWidgetFromPos(w2, e->we.popupmenu.pt.x - w2->left, e->we.popupmenu.pt.y - w2->top) == WP(w, menu_d).main_button)
+ index = WP(w, menu_d).sel_index;
+ }
+
+ DeleteWindow(w);
+
+ if (index >= 0) {
+ assert(index >= 0 && index < 30);
+ _menu_clicked_procs[action_id](index);
+ }
+ } break;
+
+ case WE_POPUPMENU_OVER: {
+ int index;
+ UpdatePlayerMenuHeight(w);
+ index = GetMenuItemIndex(w, e->we.popupmenu.pt.x, e->we.popupmenu.pt.y);
+
+ /* We have a new entry at the top of the list of menu 9 when networking
+ * so keep that in count */
+ if (_networking && WP(w, menu_d).main_button == 9) {
+ if (index > 0) index = GetPlayerIndexFromMenu(index - 1) + 1;
+ } else {
+ index = GetPlayerIndexFromMenu(index);
+ }
+
+ if (index == -1 || index == WP(w, menu_d).sel_index) return;
+
+ WP(w, menu_d).sel_index = index;
+ SetWindowDirty(w);
+ return;
+ }
+ }
+}
+
+static const Widget _player_menu_widgets[] = {
+{ WWT_PANEL, RESIZE_NONE, 14, 0, 240, 0, 81, 0x0, STR_NULL},
+{ WIDGETS_END},
+};
+
+static Window *PopupMainPlayerToolbMenu(Window *w, int main_button, int gray)
+{
+ w->LowerWidget(main_button);
+ w->InvalidateWidget(main_button);
+
+ DeleteWindowById(WC_TOOLBAR_MENU, 0);
+ Point pos = GetToolbarDropdownPos(main_button, 241, 82);
+ w = AllocateWindow(pos.x, pos.y, 241, 82, PlayerMenuWndProc, WC_TOOLBAR_MENU, _player_menu_widgets);
+ w->flags4 &= ~WF_WHITE_BORDER_MASK;
+ WP(w, menu_d).item_count = 0;
+ WP(w, menu_d).sel_index = (_local_player != PLAYER_SPECTATOR) ? _local_player : GetPlayerIndexFromMenu(0);
+ if (_networking && main_button == 9) {
+ if (_local_player != PLAYER_SPECTATOR) {
+ WP(w, menu_d).sel_index++;
+ } else {
+ /* Select client list by default for spectators */
+ WP(w, menu_d).sel_index = 0;
+ }
+ }
+ WP(w, menu_d).action_id = main_button;
+ WP(w, menu_d).main_button = main_button;
+ WP(w, menu_d).checked_items = gray;
+ WP(w, menu_d).disabled_items = 0;
+ _popup_menu_active = true;
+ SndPlayFx(SND_15_BEEP);
+ return w;
+}
+
+/* --- Allocating the toolbar --- */
+
Window *AllocateToolbar()
{
- return AllocateWindowDesc((_game_mode != GM_EDITOR) ? &_toolb_normal_desc : &_toolb_scen_desc);
+ /* Clean old GUI values */
+ _last_built_railtype = RAILTYPE_RAIL;
+ _last_built_roadtype = ROADTYPE_ROAD;
+
+ Window *w = AllocateWindowDesc((_game_mode != GM_EDITOR) ? &_toolb_normal_desc : &_toolb_scen_desc);
+ if (w == NULL) return NULL;
+
+ CLRBITS(w->flags4, WF_WHITE_BORDER_MASK);
+
+ w->SetWidgetDisabledState(0, _networking && !_network_server); // if not server, disable pause button
+ w->SetWidgetDisabledState(1, _networking); // if networking, disable fast-forward button
+
+ /* 'w' is for sure a WC_MAIN_TOOLBAR */
+ PositionMainToolbar(w);
+
+ return w;
}
--- a/src/toolbar_gui.h Thu Apr 17 08:40:01 2008 +0000
+++ b/src/toolbar_gui.h Fri Apr 18 23:33:51 2008 +0000
@@ -7,7 +7,6 @@
#include "window_type.h"
-Point GetToolbarDropdownPos(uint16 parent_button, int width, int height);
Window *AllocateToolbar();
#endif /*TOOLBAR_GUI_H*/
--- a/src/town.h Thu Apr 17 08:40:01 2008 +0000
+++ b/src/town.h Fri Apr 18 23:33:51 2008 +0000
@@ -13,8 +13,8 @@
#include "date_type.h"
#include "town_type.h"
#include "player_type.h"
-#include "newgrf_string_type.h"
#include "settings_type.h"
+#include "strings_type.h"
enum {
HOUSE_NO_CLASS = 0,
@@ -163,7 +163,7 @@
bool larger_town;
/* NOSAVE: UpdateTownRadius updates this given the house count. */
- uint16 radius[HZB_END];
+ uint32 squared_town_zone_radius[HZB_END];
/* NOSAVE: The number of each type of building in the town. */
BuildingCounts building_counts;
@@ -201,7 +201,7 @@
Year max_date; ///< last year it can be built
byte population; ///< population (Zero on other tiles in multi tile house.)
byte removal_cost; ///< cost multiplier for removing it
- GRFMappedStringID building_name; ///< building name
+ StringID building_name; ///< building name
uint16 remove_rating_decrease; ///< rating decrease if removed
byte mail_generation; ///< mail generation multiplier (tile based, as the acceptances below)
byte cargo_acceptance[3]; ///< acceptance level for the cargo slots
--- a/src/town_cmd.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/town_cmd.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -41,6 +41,10 @@
#include "string_func.h"
#include "newgrf_cargo.h"
#include "oldpool_func.h"
+#include "sprite.h"
+#include "economy_func.h"
+#include "station_func.h"
+#include "cheat_func.h"
#include "table/strings.h"
#include "table/sprites.h"
@@ -1060,7 +1064,7 @@
case TL_3X3_GRID:
case TL_2X2_GRID:
- rcmd = GetTownRoadGridElement(t1, tile, target_dir);
+ rcmd = GetTownRoadGridElement(t1, tile, target_dir);
break;
case TL_BETTER_ROADS:
@@ -1301,7 +1305,7 @@
void UpdateTownRadius(Town *t)
{
- static const uint16 _town_radius_data[23][5] = {
+ static const uint32 _town_squared_town_zone_radius_data[23][5] = {
{ 4, 0, 0, 0, 0}, // 0
{ 16, 0, 0, 0, 0},
{ 25, 0, 0, 0, 0},
@@ -1328,19 +1332,17 @@
};
if (t->num_houses < 92) {
- memcpy(t->radius, _town_radius_data[t->num_houses / 4], sizeof(t->radius));
+ memcpy(t->squared_town_zone_radius, _town_squared_town_zone_radius_data[t->num_houses / 4], sizeof(t->squared_town_zone_radius));
} else {
int mass = t->num_houses / 8;
- /* At least very roughly extrapolate. Empirical numbers dancing between
- * overwhelming by cottages and skyscrapers outskirts. */
- t->radius[0] = mass * mass;
- /* Actually we are proportional to sqrt() but that's right because
- * we are covering an area. */
- t->radius[1] = mass * 7;
- t->radius[2] = 0;
- t->radius[3] = mass * 4;
- t->radius[4] = mass * 3;
- //debug("%d (->%d): %d %d %d %d\n", t->num_houses, mass, t->radius[0], t->radius[1], t->radius[3], t->radius[4]);
+ /* Actually we are proportional to sqrt() but that's right because we are covering an area.
+ * The offsets are to make sure the radii do not decrease in size when going from the table
+ * to the calculated value.*/
+ t->squared_town_zone_radius[0] = mass * 15 - 40;
+ t->squared_town_zone_radius[1] = mass * 9 - 15;
+ t->squared_town_zone_radius[2] = 0;
+ t->squared_town_zone_radius[3] = mass * 5 - 5;
+ t->squared_town_zone_radius[4] = mass * 3 + 5;
}
}
@@ -1603,8 +1605,8 @@
/** Returns the bit corresponding to the town zone of the specified tile
- * @param t Town on which radius is to be found
- * @param tile TileIndex where radius needs to be found
+ * @param t Town on which town zone is to be found
+ * @param tile TileIndex where town zone needs to be found
* @return the bit position of the given zone, as defined in HouseZones
*/
HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile)
@@ -1615,7 +1617,7 @@
HouseZonesBits smallest = HZB_TOWN_EDGE;
for (HouseZonesBits i = HZB_BEGIN; i < HZB_END; i++) {
- if (dist < t->radius[i]) smallest = i;
+ if (dist < t->squared_town_zone_radius[i]) smallest = i;
}
return smallest;
@@ -1992,6 +1994,33 @@
DeleteAnimatedTile(tile);
}
+/**
+ * Determines if a given HouseID is part of a multitile house.
+ * The given ID is set to the ID of the north tile and the TileDiff to the north tile is returned.
+ *
+ * @param house Is changed to the HouseID of the north tile of the same house
+ * @return TileDiff from the tile of the given HouseID to the north tile
+ */
+static TileIndex GetHouseNorthPart(HouseID &house)
+{
+ if (house >= 3) { // house id 0,1,2 MUST be single tile houses, or this code breaks.
+ if (GetHouseSpecs(house - 1)->building_flags & TILE_SIZE_2x1) {
+ house--;
+ return TileDiffXY(-1, 0);
+ } else if (GetHouseSpecs(house - 1)->building_flags & BUILDING_2_TILES_Y) {
+ house--;
+ return TileDiffXY(0, -1);
+ } else if (GetHouseSpecs(house - 2)->building_flags & BUILDING_HAS_4_TILES) {
+ house -= 2;
+ return TileDiffXY(-1, 0);
+ } else if (GetHouseSpecs(house - 3)->building_flags & BUILDING_HAS_4_TILES) {
+ house -= 3;
+ return TileDiffXY(-1, -1);
+ }
+ }
+ return 0;
+}
+
void ClearTownHouse(Town *t, TileIndex tile)
{
assert(IsTileType(tile, MP_HOUSE));
@@ -1999,21 +2028,7 @@
HouseID house = GetHouseType(tile);
/* need to align the tile to point to the upper left corner of the house */
- if (house >= 3) { // house id 0,1,2 MUST be single tile houses, or this code breaks.
- if (GetHouseSpecs(house-1)->building_flags & TILE_SIZE_2x1) {
- house--;
- tile += TileDiffXY(-1, 0);
- } else if (GetHouseSpecs(house-1)->building_flags & BUILDING_2_TILES_Y) {
- house--;
- tile += TileDiffXY(0, -1);
- } else if (GetHouseSpecs(house-2)->building_flags & BUILDING_HAS_4_TILES) {
- house-=2;
- tile += TileDiffXY(-1, 0);
- } else if (GetHouseSpecs(house-3)->building_flags & BUILDING_HAS_4_TILES) {
- house-=3;
- tile += TileDiffXY(-1, -1);
- }
- }
+ tile += GetHouseNorthPart(house); // modifies house to the ID of the north tile
const HouseSpec *hs = GetHouseSpecs(house);
@@ -2285,7 +2300,7 @@
const Station *st;
FOR_ALL_STATIONS(st) {
- if (DistanceSquare(st->xy, t->xy) <= t->radius[0]) {
+ if (DistanceSquare(st->xy, t->xy) <= t->squared_town_zone_radius[0]) {
if (st->time_since_load <= 20 || st->time_since_unload <= 20) {
n++;
if (IsValidPlayer(st->owner)) {
@@ -2330,7 +2345,7 @@
if (TilePixelHeight(t->xy) >= GetSnowLine() && t->act_food == 0 && t->population > 90)
return;
} else if (_opt.landscape == LT_TROPIC) {
- if (GetTropicZone(t->xy) == TROPICZONE_DESERT && (t->act_food==0 || t->act_water==0) && t->population > 60)
+ if (GetTropicZone(t->xy) == TROPICZONE_DESERT && (t->act_food == 0 || t->act_water == 0) && t->population > 60)
return;
}
@@ -2536,6 +2551,7 @@
{
if (AutoslopeEnabled()) {
HouseID house = GetHouseType(tile);
+ GetHouseNorthPart(house); // modifies house to the ID of the north tile
const HouseSpec *hs = GetHouseSpecs(house);
/* Here we differ from TTDP by checking TILE_NOT_SLOPED */
--- a/src/town_gui.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/town_gui.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -149,7 +149,7 @@
SetVScrollCount(w, numact + 1);
- if (WP(w, def_d).data_1 != -1 && !HasBit(buttons, WP(w,def_d).data_1))
+ if (WP(w, def_d).data_1 != -1 && !HasBit(buttons, WP(w, def_d).data_1))
WP(w, def_d).data_1 = -1;
w->SetWidgetDisabledState(6, WP(w, def_d).data_1 == -1);
@@ -278,6 +278,7 @@
enum TownViewWidget {
TVW_CAPTION = 1,
+ TVW_STICKY,
TVW_CENTERVIEW = 6,
TVW_SHOWAUTORITY,
TVW_CHANGENAME,
@@ -290,9 +291,22 @@
Town *t = GetTown(w->window_number);
switch (e->event) {
- case WE_CREATE:
+ case WE_CREATE: {
+ bool ingame = _game_mode != GM_EDITOR;
if (t->larger_town) w->widget[TVW_CAPTION].data = STR_CITY;
- break;
+ w->SetWidgetHiddenState(TVW_DELETE, ingame); // hide delete button on game mode
+ w->SetWidgetHiddenState(TVW_EXPAND, ingame); // hide expand button on game mode
+ w->SetWidgetHiddenState(TVW_SHOWAUTORITY, !ingame); // hide autority button on editor mode
+
+ if (ingame) {
+ /* resize caption bar */
+ w->widget[TVW_CAPTION].right = w->widget[TVW_STICKY].left -1;
+ /* move the rename from top on scenario to bottom in game */
+ w->widget[TVW_CHANGENAME].top = w->widget[TVW_EXPAND].top;
+ w->widget[TVW_CHANGENAME].bottom = w->widget[TVW_EXPAND].bottom;
+ w->widget[TVW_CHANGENAME].right = w->widget[TVW_STICKY].right;
+ }
+ } break;
case WE_PAINT:
/* disable renaming town in network games if you are not the server */
@@ -353,14 +367,16 @@
static const Widget _town_view_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
-{ WWT_CAPTION, RESIZE_NONE, 13, 11, 247, 0, 13, STR_2005, STR_018C_WINDOW_TITLE_DRAG_THIS},
+{ WWT_CAPTION, RESIZE_NONE, 13, 11, 172, 0, 13, STR_2005, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_STICKYBOX, RESIZE_NONE, 13, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON},
{ WWT_PANEL, RESIZE_NONE, 13, 0, 259, 14, 105, 0x0, STR_NULL},
{ WWT_INSET, RESIZE_NONE, 13, 2, 257, 16, 103, 0x0, STR_NULL},
{ WWT_PANEL, RESIZE_NONE, 13, 0, 259, 106, 137, 0x0, STR_NULL},
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 0, 85, 138, 149, STR_00E4_LOCATION, STR_200B_CENTER_THE_MAIN_VIEW_ON},
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 86, 171, 138, 149, STR_2020_LOCAL_AUTHORITY, STR_2021_SHOW_INFORMATION_ON_LOCAL},
-{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 172, 259, 138, 149, STR_0130_RENAME, STR_200C_CHANGE_TOWN_NAME},
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 172, 247, 0, 13, STR_0130_RENAME, STR_200C_CHANGE_TOWN_NAME},
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 86, 171, 138, 149, STR_023C_EXPAND, STR_023B_INCREASE_SIZE_OF_TOWN},
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 172, 259, 138, 149, STR_0290_DELETE, STR_0291_DELETE_THIS_TOWN_COMPLETELY},
{ WIDGETS_END},
};
@@ -372,38 +388,11 @@
TownViewWndProc
};
-static const Widget _town_view_scen_widgets[] = {
-{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
-{ WWT_CAPTION, RESIZE_NONE, 13, 11, 172, 0, 13, STR_2005, STR_018C_WINDOW_TITLE_DRAG_THIS},
-{ WWT_STICKYBOX, RESIZE_NONE, 13, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON},
-{ WWT_PANEL, RESIZE_NONE, 13, 0, 259, 14, 105, 0x0, STR_NULL},
-{ WWT_INSET, RESIZE_NONE, 13, 2, 257, 16, 103, 0x0, STR_NULL},
-{ WWT_PANEL, RESIZE_NONE, 13, 0, 259, 106, 137, 0x0, STR_NULL},
-{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 0, 85, 138, 149, STR_00E4_LOCATION, STR_200B_CENTER_THE_MAIN_VIEW_ON},
-{ WWT_EMPTY, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL},
-{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 173, 247, 0, 13, STR_0130_RENAME, STR_200C_CHANGE_TOWN_NAME},
-{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 86, 171, 138, 149, STR_023C_EXPAND, STR_023B_INCREASE_SIZE_OF_TOWN},
-{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 172, 259, 138, 149, STR_0290_DELETE, STR_0291_DELETE_THIS_TOWN_COMPLETELY},
-{ WIDGETS_END},
-};
-
-static const WindowDesc _town_view_scen_desc = {
- WDP_AUTO, WDP_AUTO, 260, 150, 260, 150,
- WC_TOWN_VIEW, WC_NONE,
- WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
- _town_view_scen_widgets,
- TownViewWndProc
-};
-
void ShowTownViewWindow(TownID town)
{
Window *w;
- if (_game_mode != GM_EDITOR) {
- w = AllocateWindowDescFront(&_town_view_desc, town);
- } else {
- w = AllocateWindowDescFront(&_town_view_scen_desc, town);
- }
+ w = AllocateWindowDescFront(&_town_view_desc, town);
if (w != NULL) {
w->flags4 |= WF_DISABLE_VP_SCROLL;
--- a/src/train_cmd.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/train_cmd.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -20,7 +20,8 @@
#include "engine_func.h"
#include "player_func.h"
#include "player_base.h"
-#include "depot.h"
+#include "depot_base.h"
+#include "depot_func.h"
#include "waypoint.h"
#include "vehicle_gui.h"
#include "train.h"
@@ -679,7 +680,7 @@
/* Check if the train is actually being built in a depot belonging
* to the player. Doesn't matter if only the cost is queried */
if (!(flags & DC_QUERY_COST)) {
- if (!IsTileDepotType(tile, TRANSPORT_RAIL)) return CMD_ERROR;
+ if (!IsRailDepotTile(tile)) return CMD_ERROR;
if (!IsTileOwner(tile, _current_player)) return CMD_ERROR;
}
@@ -807,7 +808,7 @@
TileIndex tile = v->tile;
/* check if stopped in a depot */
- if (!IsTileDepotType(tile, TRANSPORT_RAIL) || v->cur_speed != 0) return -1;
+ if (!IsRailDepotTile(tile) || v->cur_speed != 0) return -1;
int count = 0;
for (; v != NULL; v = v->Next()) {
@@ -1304,7 +1305,7 @@
* @param p2 the selling mode
* - p2 = 0: only sell the single dragged wagon/engine (and any belonging rear-engines)
* - p2 = 1: sell the vehicle and all vehicles following it in the chain
- if the wagon is dragged, don't delete the possibly belonging rear-engine to some front
+ * if the wagon is dragged, don't delete the possibly belonging rear-engine to some front
* - p2 = 2: when selling attached locos, rearrange all vehicles after it to separate lines;
* all wagons of the same type will go on the same line. Used by the AI currently
*/
@@ -1788,7 +1789,7 @@
static void ReverseTrainDirection(Vehicle *v)
{
- if (IsTileDepotType(v->tile, TRANSPORT_RAIL)) {
+ if (IsRailDepotTile(v->tile)) {
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
}
@@ -1808,7 +1809,7 @@
AdvanceWagonsAfterSwap(v);
- if (IsTileDepotType(v->tile, TRANSPORT_RAIL)) {
+ if (IsRailDepotTile(v->tile)) {
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
}
@@ -2036,7 +2037,7 @@
tfdd.reverse = false;
TileIndex tile = v->tile;
- if (IsTileDepotType(tile, TRANSPORT_RAIL)) {
+ if (IsRailDepotTile(tile)) {
tfdd.tile = tile;
tfdd.best_length = 0;
return tfdd;
@@ -2155,7 +2156,7 @@
}
/* No smoke in depots or tunnels */
- if (IsTileDepotType(v->tile, TRANSPORT_RAIL) || IsTunnelTile(v->tile)) continue;
+ if (IsRailDepotTile(v->tile) || IsTunnelTile(v->tile)) continue;
/* No sparks for electric vehicles on nonelectrified tracks */
if (!HasPowerOnRail(v->u.rail.railtype, GetTileRailType(v->tile))) continue;
@@ -3151,7 +3152,7 @@
if (IsLevelCrossingTile(tile)) UpdateLevelCrossing(tile);
/* Update signals */
- if (IsTileType(tile, MP_TUNNELBRIDGE) || IsTileDepotType(tile, TRANSPORT_RAIL)) {
+ if (IsTileType(tile, MP_TUNNELBRIDGE) || IsRailDepotTile(tile)) {
UpdateSignalsOnSegment(tile, INVALID_DIAGDIR, owner);
} else {
SetSignalsOnBothDir(tile, (Track)(FIND_FIRST_BIT(track)), owner);
@@ -3208,7 +3209,7 @@
if (state <= 240 && !(v->tick_counter & 3)) ChangeTrainDirRandomly(v);
- if (state >= 4440 && !(v->tick_counter&0x1F)) {
+ if (state >= 4440 && !(v->tick_counter & 0x1F)) {
DeleteLastWagon(v);
InvalidateWindow(WC_REPLACE_VEHICLE, (v->group_id << 16) | VEH_TRAIN);
}
@@ -3313,7 +3314,7 @@
}
/* entering a depot? */
- if (IsTileDepotType(tile, TRANSPORT_RAIL)) {
+ if (IsRailDepotTile(tile)) {
DiagDirection dir = ReverseDiagDir(GetRailDepotDirection(tile));
if (DiagDirToDir(dir) == v->direction) return false;
}
--- a/src/train_gui.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/train_gui.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -10,7 +10,6 @@
#include "gfx_func.h"
#include "command_func.h"
#include "vehicle_gui.h"
-#include "depot.h"
#include "train.h"
#include "newgrf_engine.h"
#include "strings_func.h"
--- a/src/tunnelbridge.h Thu Apr 17 08:40:01 2008 +0000
+++ b/src/tunnelbridge.h Fri Apr 18 23:33:51 2008 +0000
@@ -6,8 +6,6 @@
#define TUNNELBRIDGE_H
#include "tile_type.h"
-#include "map_func.h"
-#include "tunnelbridge_map.h"
/**
* Calculates the length of a tunnel or a bridge (without end tiles)
@@ -23,4 +21,6 @@
return abs(x2 + y2 - x1 - y1) - 1;
}
+extern TileIndex _build_tunnel_endtile;
+
#endif /* TUNNELBRIDGE_H */
--- a/src/tunnelbridge_cmd.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/tunnelbridge_cmd.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -35,12 +35,16 @@
#include "tunnelbridge.h"
#include "player_base.h"
#include "engine_func.h"
+#include "economy_func.h"
+#include "rail.h"
+#include "cheat_func.h"
#include "table/sprites.h"
#include "table/strings.h"
#include "table/bridge_land.h"
BridgeSpec _bridge[MAX_BRIDGES];
+TileIndex _build_tunnel_endtile;
/** Reset the data been eventually changed by the grf loaded. */
void ResetBridges()
--- a/src/unmovable_cmd.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/unmovable_cmd.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -24,6 +24,9 @@
#include "window_func.h"
#include "vehicle_func.h"
#include "player_gui.h"
+#include "station_type.h"
+#include "economy_func.h"
+#include "cheat_func.h"
#include "table/strings.h"
#include "table/sprites.h"
@@ -155,7 +158,7 @@
if (flags & DC_EXEC) DoClearSquare(tile);
- return CommandCost(EXPENSES_CONSTRUCTION,- _price.clear_roughland * 2);
+ return CommandCost(EXPENSES_CONSTRUCTION, - _price.clear_roughland * 2);
}
static Foundation GetFoundation_Unmovable(TileIndex tile, Slope tileh);
--- a/src/variables.h Thu Apr 17 08:40:01 2008 +0000
+++ b/src/variables.h Fri Apr 18 23:33:51 2008 +0000
@@ -5,18 +5,12 @@
#ifndef VARIABLES_H
#define VARIABLES_H
-#include "tile_type.h"
-#include "strings_type.h"
-
/* Amount of game ticks */
VARDEF uint16 _tick_counter;
/* Skip aging of cargo? */
VARDEF byte _age_cargo_skip_counter;
-/* Position in tile loop */
-VARDEF TileIndex _cur_tileloop_tile;
-
/* Also save scrollpos_x, scrollpos_y and zoom */
VARDEF uint16 _disaster_delay;
@@ -39,31 +33,6 @@
VARDEF int _saved_scrollpos_x;
VARDEF int _saved_scrollpos_y;
-struct Cheat {
- bool been_used; // has this cheat been used before?
- bool value; // tells if the bool cheat is active or not
-};
-
-
-/* WARNING! Do _not_ remove entries in Cheats struct or change the order
- * of the existing ones! Would break downward compatibility.
- * Only add new entries at the end of the struct! */
-
-struct Cheats {
- Cheat magic_bulldozer; // dynamite industries, unmovables
- Cheat switch_player; // change to another player
- Cheat money; // get rich
- Cheat crossing_tunnels; // allow tunnels that cross each other
- Cheat build_in_pause; // build while in pause mode
- Cheat no_jetcrash; // no jet will crash on small airports anymore
- Cheat switch_climate;
- Cheat change_date; // changes date ingame
- Cheat setup_prod; // setup raw-material production in game
- Cheat dummy; // empty cheat (enable running el-engines on normal rail)
-};
-
-VARDEF Cheats _cheats;
-
/* NOSAVE: Used in palette animations only, not really important. */
VARDEF int _palette_animation_counter;
@@ -80,12 +49,10 @@
VARDEF bool _rightclick_emulate;
/* IN/OUT parameters to commands */
-VARDEF TileIndex _build_tunnel_endtile;
VARDEF bool _generating_world;
/* Used when switching from the intro menu. */
VARDEF byte _switch_mode;
-VARDEF StringID _switch_mode_errorstr;
VARDEF char _savegame_format[8];
@@ -96,8 +63,6 @@
/* landscape.cpp */
extern const byte _tileh_to_sprite[32];
-extern bool _draw_bounding_boxes;
-
/* misc */
VARDEF char _screenshot_name[128];
VARDEF byte _vehicle_design_names;
--- a/src/vehicle.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/vehicle.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -19,7 +19,6 @@
#include "player_func.h"
#include "debug.h"
#include "vehicle_gui.h"
-#include "depot.h"
#include "rail_type.h"
#include "train.h"
#include "aircraft.h"
@@ -47,6 +46,7 @@
#include "string_func.h"
#include "settings_type.h"
#include "oldpool_func.h"
+#include "depot_map.h"
#include "table/sprites.h"
#include "table/strings.h"
@@ -835,11 +835,9 @@
if (v->progress > 0) {
v->progress--;
} else {
- TileIndex tile;
-
BeginVehicleMove(v);
- tile = TileVirtXY(v->x_pos, v->y_pos);
+ TileIndex tile = TileVirtXY(v->x_pos, v->y_pos);
if (!IsTileType(tile, MP_INDUSTRY)) {
EndVehicleMove(v);
delete v;
@@ -1487,10 +1485,10 @@
/* decrease reliability */
v->reliability = rel = max((rel_old = v->reliability) - v->reliability_spd_dec, 0);
- if ((rel_old >> 8) != (rel >> 8))
- InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
+ if ((rel_old >> 8) != (rel >> 8)) InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
if (v->breakdown_ctr != 0 || v->vehstatus & VS_STOPPED ||
+ _opt.diff.vehicle_breakdowns < 1 ||
v->cur_speed < 5 || _game_mode == GM_MENU) {
return;
}
@@ -1499,16 +1497,13 @@
/* increase chance of failure */
int chance = v->breakdown_chance + 1;
- if (Chance16I(1,25,r)) chance += 25;
+ if (Chance16I(1, 25, r)) chance += 25;
v->breakdown_chance = min(255, chance);
/* calculate reliability value to use in comparison */
rel = v->reliability;
if (v->type == VEH_SHIP) rel += 0x6666;
- /* disabled breakdowns? */
- if (_opt.diff.vehicle_breakdowns < 1) return;
-
/* reduced breakdowns? */
if (_opt.diff.vehicle_breakdowns == 1) rel += 0x6666;
@@ -2074,7 +2069,7 @@
break;
}
- case VLW_GROUP_LIST:
+ case VLW_GROUP_LIST:
FOR_ALL_VEHICLES(v) {
if (v->type == type && v->IsPrimaryVehicle() &&
v->owner == owner && v->group_id == index) {
@@ -3217,7 +3212,7 @@
/* check if at a standstill (not stopped only) in a depot
* the check is down here to make it possible to alter stop/service for trains entering the depot */
- if (this->type == VEH_TRAIN && IsTileDepotType(this->tile, TRANSPORT_RAIL) && this->cur_speed == 0) return CMD_ERROR;
+ if (this->type == VEH_TRAIN && IsRailDepotTile(this->tile) && this->cur_speed == 0) return CMD_ERROR;
TileIndex location;
DestinationID destination;
--- a/src/vehicle_gui.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/vehicle_gui.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -21,7 +21,7 @@
#include "ship.h"
#include "aircraft.h"
#include "roadveh.h"
-#include "depot.h"
+#include "depot_base.h"
#include "cargotype.h"
#include "group.h"
#include "group_gui.h"
@@ -35,6 +35,7 @@
#include "settings_type.h"
#include "widgets/dropdown_func.h"
#include "order_func.h"
+#include "depot_base.h"
#include "table/sprites.h"
#include "table/strings.h"
@@ -71,6 +72,7 @@
static VehicleSortListingTypeFunction VehicleMaxSpeedSorter;
static VehicleSortListingTypeFunction VehicleModelSorter;
static VehicleSortListingTypeFunction VehicleValueSorter;
+static VehicleSortListingTypeFunction VehicleLengthSorter;
static VehicleSortListingTypeFunction* const _vehicle_sorter[] = {
&VehicleNumberSorter,
@@ -83,6 +85,7 @@
&VehicleMaxSpeedSorter,
&VehicleModelSorter,
&VehicleValueSorter,
+ &VehicleLengthSorter,
};
const StringID _vehicle_sort_listing[] = {
@@ -96,6 +99,7 @@
STR_SORT_BY_MAX_SPEED,
STR_SORT_BY_MODEL,
STR_SORT_BY_VALUE,
+ STR_SORT_BY_LENGTH,
INVALID_STRING_ID
};
@@ -697,6 +701,30 @@
return (_internal_sort_order & 1) ? -r : r;
}
+static int CDECL VehicleLengthSorter(const void *a, const void *b)
+{
+ const Vehicle *va = *(const Vehicle**)a;
+ const Vehicle *vb = *(const Vehicle**)b;
+ int r = 0;
+
+ switch (va->type) {
+ case VEH_TRAIN:
+ r = va->u.rail.cached_total_length - vb->u.rail.cached_total_length;
+ break;
+
+ case VEH_ROAD:
+ for (const Vehicle *u = va; u != NULL; u = u->Next()) r += u->u.road.cached_veh_length;
+ for (const Vehicle *u = vb; u != NULL; u = u->Next()) r -= u->u.road.cached_veh_length;
+ break;
+
+ default: NOT_REACHED();
+ }
+
+ VEHICLEUNITNUMBERSORTER(r, va, vb);
+
+ return (_internal_sort_order & 1) ? -r : r;
+}
+
void InitializeGUI()
{
memset(&_sorting, 0, sizeof(_sorting));
@@ -1060,7 +1088,7 @@
SetWindowDirty(w);
break;
case VLW_WIDGET_SORT_BY_PULLDOWN:/* Select sorting criteria dropdown menu */
- ShowDropDownMenu(w, _vehicle_sort_listing, vl->l.sort_type, VLW_WIDGET_SORT_BY_PULLDOWN, 0, 0);
+ ShowDropDownMenu(w, _vehicle_sort_listing, vl->l.sort_type, VLW_WIDGET_SORT_BY_PULLDOWN, 0, (vl->vehicle_type == VEH_TRAIN || vl->vehicle_type == VEH_ROAD) ? 0 : (1 << 10));
return;
case VLW_WIDGET_LIST: { /* Matrix to show vehicles */
uint32 id_v = (e->we.click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / w->resize.step_height;
@@ -1436,7 +1464,7 @@
extern void DrawAircraftDetails(const Vehicle *v, int x, int y);
/**
-* Draw the details for the given vehicle at the position (x,y) of the Details windows
+* Draw the details for the given vehicle at the position (x, y) of the Details windows
*
* @param v current vehicle
* @param x The x coordinate
--- a/src/video/cocoa/wnd_quartz.mm Thu Apr 17 08:40:01 2008 +0000
+++ b/src/video/cocoa/wnd_quartz.mm Fri Apr 18 23:33:51 2008 +0000
@@ -175,7 +175,8 @@
CMCloseProfile(sysProfile);
}
- assert(colorSpace != NULL);
+ if (colorSpace == NULL)
+ error("Could not get system colour space. You might need to recalibrate your monitor.");
}
return colorSpace;
--- a/src/video/null_v.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/video/null_v.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -15,6 +15,8 @@
this->ticks = GetDriverParamInt(parm, "ticks", 1000);
_screen.width = _screen.pitch = _cur_resolution[0];
_screen.height = _cur_resolution[1];
+ ScreenSizeChanged();
+
/* Do not render, nor blit */
DEBUG(misc, 1, "Forcing blitter 'null'...");
BlitterFactoryBase::SelectBlitter("null");
--- a/src/video/sdl_v.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/video/sdl_v.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -127,8 +127,7 @@
for (i = 0; modes[i]; i++) {
int w = modes[i]->w;
int h = modes[i]->h;
- if (IsInsideMM(w, 640, MAX_SCREEN_WIDTH + 1) &&
- IsInsideMM(h, 480, MAX_SCREEN_HEIGHT + 1)) {
+ if (w >= 640 && h >= 480) {
int j;
for (j = 0; j < n; j++) {
if (_resolutions[j][0] == w && _resolutions[j][1] == h) break;
@@ -419,8 +418,8 @@
break;
case SDL_VIDEORESIZE: {
- int w = Clamp(ev.resize.w, 64, MAX_SCREEN_WIDTH);
- int h = Clamp(ev.resize.h, 64, MAX_SCREEN_HEIGHT);
+ int w = max(ev.resize.w, 64);
+ int h = max(ev.resize.h, 64);
ChangeResInGame(w, h);
break;
}
--- a/src/video/win32_v.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/video/win32_v.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -308,7 +308,7 @@
case WM_PAINT: {
PAINTSTRUCT ps;
- HDC dc,dc2;
+ HDC dc, dc2;
HBITMAP old_bmp;
HPALETTE old_palette;
@@ -545,8 +545,8 @@
w = r->right - r->left - (r2.right - r2.left);
h = r->bottom - r->top - (r2.bottom - r2.top);
- w = Clamp(w, 64, MAX_SCREEN_WIDTH);
- h = Clamp(h, 64, MAX_SCREEN_HEIGHT);
+ w = max(w, 64);
+ h = max(h, 64);
SetRect(&r2, 0, 0, w, h);
AdjustWindowRect(&r2, GetWindowLong(hwnd, GWL_STYLE), FALSE);
@@ -677,8 +677,8 @@
HDC dc;
int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
- w = Clamp(w, 64, MAX_SCREEN_WIDTH);
- h = Clamp(h, 64, MAX_SCREEN_HEIGHT);
+ w = max(w, 64);
+ h = max(h, 64);
if (bpp == 0) error("Can't use a blitter that blits 0 bpp for normal visuals");
@@ -737,8 +737,8 @@
* Doesn't really matter since we don't pass a string anyways, but still
* a letdown */
for (i = 0; EnumDisplaySettingsA(NULL, i, &dm) != 0; i++) {
- if (dm.dmBitsPerPel == BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() && IsInsideMM(dm.dmPelsWidth, 640, MAX_SCREEN_WIDTH + 1) &&
- IsInsideMM(dm.dmPelsHeight, 480, MAX_SCREEN_HEIGHT + 1)) {
+ if (dm.dmBitsPerPel == BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() &&
+ dm.dmPelsWidth >= 640 && dm.dmPelsHeight >= 480) {
uint j;
for (j = 0; j < n; j++) {
@@ -787,10 +787,10 @@
_wnd.height_org = _cur_resolution[1];
AllocateDibSection(_cur_resolution[0], _cur_resolution[1]);
+ MakeWindow(_fullscreen);
+
MarkWholeScreenDirty();
- MakeWindow(_fullscreen);
-
return NULL;
}
--- a/src/viewport.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/viewport.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -1,6 +1,22 @@
/* $Id$ */
-/** @file viewport.cpp */
+/** @file viewport.cpp
+ *
+ * \verbatim
+ * The in-game coordinate system looks like this *
+ * *
+ * ^ Z *
+ * | *
+ * | *
+ * | *
+ * | *
+ * / \ *
+ * / \ *
+ * / \ *
+ * / \ *
+ * X < > Y *
+ * \endverbatim
+ */
#include "stdafx.h"
#include "openttd.h"
@@ -28,56 +44,18 @@
#include "settings_type.h"
#include "station_func.h"
#include "core/alloc_type.hpp"
+#include "misc/smallvec.h"
#include "table/sprites.h"
#include "table/strings.h"
-enum {
- VIEWPORT_DRAW_MEM = (65536 * 2),
- PARENT_LIST_SIZE = 6144,
-};
-
PlaceProc *_place_proc;
Point _tile_fract_coords;
ZoomLevel _saved_scrollpos_zoom;
-/**
- * The maximum number of viewports depends on the maximum number
- * of windows. Technically is could be the maximum number of
- * windows, but there is always at least one window that does
- * not need a viewport. Not having 'support' for that viewport
- * saves some time and memory.
- * For the introduction GUI and create game GUIs there is no
- * need for more than one viewport, however in the normal game
- * and scenario editor one can make a lot of viewports. For the
- * normal game one always has a main toolbar and a status bar,
- * however the statusbar does not exist on the scenario editor.
- *
- * This means that we can only safely assume that there is one
- * window without viewport.
- */
-static ViewPort _viewports[MAX_NUMBER_OF_WINDOWS - 1];
-static uint32 _active_viewports; ///< bitmasked variable where each bit signifies if a viewport is in use or not
-assert_compile(lengthof(_viewports) < sizeof(_active_viewports) * 8);
-
-/* The in-game coordiante system looks like this *
- * *
- * ^ Z *
- * | *
- * | *
- * | *
- * | *
- * / \ *
- * / \ *
- * / \ *
- * / \ *
- * X < > Y *
- */
-
struct StringSpriteToDraw {
uint16 string;
uint16 color;
- StringSpriteToDraw *next;
int32 x;
int32 y;
uint64 params[2];
@@ -88,7 +66,6 @@
SpriteID image;
SpriteID pal;
const SubSprite *sub; ///< only draw a rectangular part of the sprite
- TileSpriteToDraw *next;
int32 x;
int32 y;
byte z;
@@ -121,18 +98,11 @@
int zmin; ///< minimal world Z coordinate of bounding box
int zmax; ///< maximal world Z coordinate of bounding box
- ChildScreenSpriteToDraw *child; ///< head of child list;
+ int first_child; ///< the first child to draw.
+ int last_child; ///< the last sprite to draw.
bool comparison_done; ///< Used during sprite sorting: true if sprite has been compared with all other sprites
};
-/* Quick hack to know how much memory to reserve when allocating from the spritelist
- * to prevent a buffer overflow. */
-#define LARGEST_SPRITELIST_STRUCT ParentSpriteToDraw
-assert_compile(sizeof(LARGEST_SPRITELIST_STRUCT) >= sizeof(StringSpriteToDraw));
-assert_compile(sizeof(LARGEST_SPRITELIST_STRUCT) >= sizeof(TileSpriteToDraw));
-assert_compile(sizeof(LARGEST_SPRITELIST_STRUCT) >= sizeof(ChildScreenSpriteToDraw));
-assert_compile(sizeof(LARGEST_SPRITELIST_STRUCT) >= sizeof(ParentSpriteToDraw));
-
/* Enumeration of multi-part foundations */
enum FoundationPart {
FOUNDATION_PART_NONE = 0xFF, ///< Neither foundation nor groundsprite drawn yet.
@@ -141,32 +111,36 @@
FOUNDATION_PART_END
};
+typedef SmallVector<TileSpriteToDraw, 64> TileSpriteToDrawVector;
+typedef SmallVector<StringSpriteToDraw, 4> StringSpriteToDrawVector;
+typedef SmallVector<ParentSpriteToDraw, 64> ParentSpriteToDrawVector;
+typedef SmallVector<ParentSpriteToDraw*, 64> ParentSpriteToSortVector;
+typedef SmallVector<ChildScreenSpriteToDraw, 16> ChildScreenSpriteToDrawVector;
+
struct ViewportDrawer {
DrawPixelInfo dpi;
- byte *spritelist_mem;
- const byte *eof_spritelist_mem;
-
- StringSpriteToDraw **last_string, *first_string;
- TileSpriteToDraw **last_tile, *first_tile;
-
- ChildScreenSpriteToDraw **last_child;
-
- ParentSpriteToDraw **parent_list;
- ParentSpriteToDraw * const *eof_parent_list;
+ StringSpriteToDrawVector string_sprites_to_draw;
+ TileSpriteToDrawVector tile_sprites_to_draw;
+ ParentSpriteToDrawVector parent_sprites_to_draw;
+ ParentSpriteToSortVector parent_sprites_to_sort;
+ ChildScreenSpriteToDrawVector child_screen_sprites_to_draw;
+
+ int *last_child;
byte combine_sprites;
- ParentSpriteToDraw *foundation[FOUNDATION_PART_END]; ///< Foundation sprites.
- FoundationPart foundation_part; ///< Currently active foundation for ground sprite drawing.
- ChildScreenSpriteToDraw **last_foundation_child[FOUNDATION_PART_END]; ///< Tail of ChildSprite list of the foundations.
- Point foundation_offset[FOUNDATION_PART_END]; ///< Pixeloffset for ground sprites on the foundations.
+ int foundation[FOUNDATION_PART_END]; ///< Foundation sprites (index into parent_sprites_to_draw).
+ FoundationPart foundation_part; ///< Currently active foundation for ground sprite drawing.
+ int *last_foundation_child[FOUNDATION_PART_END]; ///< Tail of ChildSprite list of the foundations. (index into child_screen_sprites_to_draw)
+ Point foundation_offset[FOUNDATION_PART_END]; ///< Pixeloffset for ground sprites on the foundations.
};
-static ViewportDrawer *_cur_vd;
+static ViewportDrawer _vd;
TileHighlightData _thd;
static TileInfo *_cur_ti;
+bool _draw_bounding_boxes = false;
extern void SmallMapCenterOnCurrentPos(Window *w);
@@ -178,15 +152,8 @@
return p;
}
-void InitViewports()
-{
- memset(_viewports, 0, sizeof(_viewports));
- _active_viewports = 0;
-}
-
void DeleteWindowViewport(Window *w)
{
- ClrBit(_active_viewports, w->viewport - _viewports);
w->viewport->width = 0;
w->viewport = NULL;
}
@@ -194,15 +161,9 @@
void AssignWindowViewport(Window *w, int x, int y,
int width, int height, uint32 follow_flags, ZoomLevel zoom)
{
- ViewPort *vp;
- Point pt;
- uint32 bit;
-
- for (vp = _viewports, bit = 0; ; vp++, bit++) {
- assert(vp != endof(_viewports));
- if (vp->width == 0) break;
- }
- SetBit(_active_viewports, bit);
+ assert(w->viewport == NULL);
+
+ ViewPort *vp = &(WP(w, vp_d).vp_data);
vp->left = x + w->left;
vp->top = y + w->top;
@@ -214,6 +175,8 @@
vp->virtual_width = ScaleByZoom(width, zoom);
vp->virtual_height = ScaleByZoom(height, zoom);
+ Point pt;
+
if (follow_flags & 0x80000000) {
const Vehicle *veh;
@@ -485,28 +448,15 @@
*/
void DrawGroundSpriteAt(SpriteID image, SpriteID pal, int32 x, int32 y, byte z, const SubSprite *sub)
{
- ViewportDrawer *vd = _cur_vd;
- TileSpriteToDraw *ts;
-
assert((image & SPRITE_MASK) < MAX_SPRITES);
- if (vd->spritelist_mem >= vd->eof_spritelist_mem) {
- DEBUG(sprite, 0, "Out of sprite memory");
- return;
- }
- ts = (TileSpriteToDraw*)vd->spritelist_mem;
-
- vd->spritelist_mem += sizeof(TileSpriteToDraw);
-
+ TileSpriteToDraw *ts = _vd.tile_sprites_to_draw.Append();
ts->image = image;
ts->pal = pal;
ts->sub = sub;
- ts->next = NULL;
ts->x = x;
ts->y = y;
ts->z = z;
- *vd->last_tile = ts;
- vd->last_tile = &ts->next;
}
/**
@@ -523,19 +473,18 @@
*/
static void AddChildSpriteToFoundation(SpriteID image, SpriteID pal, const SubSprite *sub, FoundationPart foundation_part, int extra_offs_x, int extra_offs_y)
{
- ViewportDrawer *vd = _cur_vd;
assert(IsInsideMM(foundation_part, 0, FOUNDATION_PART_END));
- assert(vd->foundation[foundation_part] != NULL);
- Point offs = vd->foundation_offset[foundation_part];
+ assert(_vd.foundation[foundation_part] != -1);
+ Point offs = _vd.foundation_offset[foundation_part];
/* Change the active ChildSprite list to the one of the foundation */
- ChildScreenSpriteToDraw **old_child = vd->last_child;
- vd->last_child = vd->last_foundation_child[foundation_part];
+ int *old_child = _vd.last_child;
+ _vd.last_child = _vd.last_foundation_child[foundation_part];
AddChildSpriteScreen(image, pal, offs.x + extra_offs_x, offs.y + extra_offs_y, false, sub);
/* Switch back to last ChildSprite list */
- vd->last_child = old_child;
+ _vd.last_child = old_child;
}
/**
@@ -548,12 +497,11 @@
*/
void DrawGroundSprite(SpriteID image, SpriteID pal, const SubSprite *sub)
{
- ViewportDrawer *vd = _cur_vd;
/* Switch to first foundation part, if no foundation was drawn */
- if (vd->foundation_part == FOUNDATION_PART_NONE) vd->foundation_part = FOUNDATION_PART_NORMAL;
-
- if (vd->foundation[vd->foundation_part] != NULL) {
- AddChildSpriteToFoundation(image, pal, sub, vd->foundation_part, 0, 0);
+ if (_vd.foundation_part == FOUNDATION_PART_NONE) _vd.foundation_part = FOUNDATION_PART_NORMAL;
+
+ if (_vd.foundation[_vd.foundation_part] != -1) {
+ AddChildSpriteToFoundation(image, pal, sub, _vd.foundation_part, 0, 0);
} else {
DrawGroundSpriteAt(image, pal, _cur_ti->x, _cur_ti->y, _cur_ti->z, sub);
}
@@ -569,24 +517,23 @@
*/
void OffsetGroundSprite(int x, int y)
{
- ViewportDrawer *vd = _cur_vd;
/* Switch to next foundation part */
- switch (vd->foundation_part) {
+ switch (_vd.foundation_part) {
case FOUNDATION_PART_NONE:
- vd->foundation_part = FOUNDATION_PART_NORMAL;
+ _vd.foundation_part = FOUNDATION_PART_NORMAL;
break;
case FOUNDATION_PART_NORMAL:
- vd->foundation_part = FOUNDATION_PART_HALFTILE;
+ _vd.foundation_part = FOUNDATION_PART_HALFTILE;
break;
default: NOT_REACHED();
}
- /* vd->last_child == NULL if foundation sprite was clipped by the viewport bounds */
- if (vd->last_child != NULL) vd->foundation[vd->foundation_part] = vd->parent_list[-1];
-
- vd->foundation_offset[vd->foundation_part].x = x;
- vd->foundation_offset[vd->foundation_part].y = y;
- vd->last_foundation_child[vd->foundation_part] = vd->last_child;
+ /* _vd.last_child == NULL if foundation sprite was clipped by the viewport bounds */
+ if (_vd.last_child != NULL) _vd.foundation[_vd.foundation_part] = _vd.parent_sprites_to_draw.items - 1;
+
+ _vd.foundation_offset[_vd.foundation_part].x = x;
+ _vd.foundation_offset[_vd.foundation_part].y = y;
+ _vd.last_foundation_child[_vd.foundation_part] = _vd.last_child;
}
/**
@@ -602,17 +549,17 @@
*/
static void AddCombinedSprite(SpriteID image, SpriteID pal, int x, int y, byte z, const SubSprite *sub)
{
- const ViewportDrawer *vd = _cur_vd;
Point pt = RemapCoords(x, y, z);
const Sprite* spr = GetSprite(image & SPRITE_MASK);
- if (pt.x + spr->x_offs >= vd->dpi.left + vd->dpi.width ||
- pt.x + spr->x_offs + spr->width <= vd->dpi.left ||
- pt.y + spr->y_offs >= vd->dpi.top + vd->dpi.height ||
- pt.y + spr->y_offs + spr->height <= vd->dpi.top)
+ if (pt.x + spr->x_offs >= _vd.dpi.left + _vd.dpi.width ||
+ pt.x + spr->x_offs + spr->width <= _vd.dpi.left ||
+ pt.y + spr->y_offs >= _vd.dpi.top + _vd.dpi.height ||
+ pt.y + spr->y_offs + spr->height <= _vd.dpi.top)
return;
- AddChildSpriteScreen(image, pal, pt.x - vd->parent_list[-1]->left, pt.y - vd->parent_list[-1]->top, false, sub);
+ const ParentSpriteToDraw *pstd = _vd.parent_sprites_to_draw.End() - 1;
+ AddChildSpriteScreen(image, pal, pt.x - pstd->left, pt.y - pstd->top, false, sub);
}
/** Draw a (transparent) sprite at given coordinates with a given bounding box.
@@ -641,9 +588,6 @@
*/
void AddSortableSpriteToDraw(SpriteID image, SpriteID pal, int x, int y, int w, int h, int dz, int z, bool transparent, int bb_offset_x, int bb_offset_y, int bb_offset_z, const SubSprite *sub)
{
- ViewportDrawer *vd = _cur_vd;
- ParentSpriteToDraw *ps;
- Point pt;
int32 left, right, top, bottom;
assert((image & SPRITE_MASK) < MAX_SPRITES);
@@ -654,45 +598,27 @@
pal = PALETTE_TO_TRANSPARENT;
}
- if (vd->combine_sprites == 2) {
+ if (_vd.combine_sprites == 2) {
AddCombinedSprite(image, pal, x, y, z, sub);
return;
}
- vd->last_child = NULL;
-
- if (vd->spritelist_mem >= vd->eof_spritelist_mem) {
- DEBUG(sprite, 0, "Out of sprite memory");
- return;
- }
- ps = (ParentSpriteToDraw*)vd->spritelist_mem;
-
- if (vd->parent_list >= vd->eof_parent_list) {
- /* This can happen rarely, mostly when you zoom out completely
- * and have a lot of stuff that moves (and is added to the
- * sort-list, this function). To solve it, increase
- * parent_list somewhere below to a higher number.
- * This can not really hurt you, it just gives some black
- * spots on the screen ;) */
- DEBUG(sprite, 0, "Out of sprite memory (parent_list)");
- return;
- }
-
- pt = RemapCoords(x, y, z);
- ps->x = pt.x;
- ps->y = pt.y;
+ _vd.last_child = NULL;
+
+ Point pt = RemapCoords(x, y, z);
+ int tmp_left, tmp_top, tmp_x = pt.x, tmp_y = pt.y;
/* Compute screen extents of sprite */
if (image == SPR_EMPTY_BOUNDING_BOX) {
- left = ps->left = RemapCoords(x + w , y + bb_offset_y, z + bb_offset_z).x;
+ left = tmp_left = RemapCoords(x + w , y + bb_offset_y, z + bb_offset_z).x;
right = RemapCoords(x + bb_offset_x, y + h , z + bb_offset_z).x + 1;
- top = ps->top = RemapCoords(x + bb_offset_x, y + bb_offset_y, z + dz ).y;
+ top = tmp_top = RemapCoords(x + bb_offset_x, y + bb_offset_y, z + dz ).y;
bottom = RemapCoords(x + w , y + h , z + bb_offset_z).y + 1;
} else {
const Sprite *spr = GetSprite(image & SPRITE_MASK);
- left = ps->left = (pt.x += spr->x_offs);
+ left = tmp_left = (pt.x += spr->x_offs);
right = (pt.x + spr->width );
- top = ps->top = (pt.y += spr->y_offs);
+ top = tmp_top = (pt.y += spr->y_offs);
bottom = (pt.y + spr->height);
}
@@ -705,14 +631,19 @@
}
/* Do not add the sprite to the viewport, if it is outside */
- if (left >= vd->dpi.left + vd->dpi.width ||
- right <= vd->dpi.left ||
- top >= vd->dpi.top + vd->dpi.height ||
- bottom <= vd->dpi.top) {
+ if (left >= _vd.dpi.left + _vd.dpi.width ||
+ right <= _vd.dpi.left ||
+ top >= _vd.dpi.top + _vd.dpi.height ||
+ bottom <= _vd.dpi.top) {
return;
}
- vd->spritelist_mem += sizeof(ParentSpriteToDraw);
+ ParentSpriteToDraw *ps = _vd.parent_sprites_to_draw.Append();
+ ps->x = tmp_x;
+ ps->y = tmp_y;
+
+ ps->left = tmp_left;
+ ps->top = tmp_top;
ps->image = image;
ps->pal = pal;
@@ -727,22 +658,22 @@
ps->zmax = z + max(bb_offset_z, dz) - 1;
ps->comparison_done = false;
- ps->child = NULL;
- vd->last_child = &ps->child;
-
- *vd->parent_list++ = ps;
-
- if (vd->combine_sprites == 1) vd->combine_sprites = 2;
+ ps->first_child = _vd.child_screen_sprites_to_draw.items;
+ ps->last_child = _vd.child_screen_sprites_to_draw.items;
+
+ _vd.last_child = &ps->last_child;
+
+ if (_vd.combine_sprites == 1) _vd.combine_sprites = 2;
}
void StartSpriteCombine()
{
- _cur_vd->combine_sprites = 1;
+ _vd.combine_sprites = 1;
}
void EndSpriteCombine()
{
- _cur_vd->combine_sprites = 0;
+ _vd.combine_sprites = 0;
}
/**
@@ -757,69 +688,41 @@
*/
void AddChildSpriteScreen(SpriteID image, SpriteID pal, int x, int y, bool transparent, const SubSprite *sub)
{
- ViewportDrawer *vd = _cur_vd;
- ChildScreenSpriteToDraw *cs;
-
assert((image & SPRITE_MASK) < MAX_SPRITES);
+ /* If the ParentSprite was clipped by the viewport bounds, do not draw the ChildSprites either */
+ if (_vd.last_child == NULL) return;
+
/* make the sprites transparent with the right palette */
if (transparent) {
SetBit(image, PALETTE_MODIFIER_TRANSPARENT);
pal = PALETTE_TO_TRANSPARENT;
}
- if (vd->spritelist_mem >= vd->eof_spritelist_mem) {
- DEBUG(sprite, 0, "Out of sprite memory");
- return;
- }
- cs = (ChildScreenSpriteToDraw*)vd->spritelist_mem;
-
- /* If the ParentSprite was clipped by the viewport bounds, do not draw the ChildSprites either */
- if (vd->last_child == NULL) return;
-
- vd->spritelist_mem += sizeof(ChildScreenSpriteToDraw);
-
/* Append the sprite to the active ChildSprite list.
* If the active ParentSprite is a foundation, update last_foundation_child as well. */
- *vd->last_child = cs;
- if (vd->last_foundation_child[0] == vd->last_child) vd->last_foundation_child[0] = &cs->next;
- if (vd->last_foundation_child[1] == vd->last_child) vd->last_foundation_child[1] = &cs->next;
- vd->last_child = &cs->next;
-
+ ChildScreenSpriteToDraw *cs = _vd.child_screen_sprites_to_draw.Append();
cs->image = image;
cs->pal = pal;
cs->sub = sub;
cs->x = x;
cs->y = y;
cs->next = NULL;
+
+ *_vd.last_child = _vd.child_screen_sprites_to_draw.items;
}
/* Returns a StringSpriteToDraw */
-void *AddStringToDraw(int x, int y, StringID string, uint64 params_1, uint64 params_2)
+void AddStringToDraw(int x, int y, StringID string, uint64 params_1, uint64 params_2, uint16 color, uint16 width)
{
- ViewportDrawer *vd = _cur_vd;
- StringSpriteToDraw *ss;
-
- if (vd->spritelist_mem >= vd->eof_spritelist_mem) {
- DEBUG(sprite, 0, "Out of sprite memory");
- return NULL;
- }
- ss = (StringSpriteToDraw*)vd->spritelist_mem;
-
- vd->spritelist_mem += sizeof(StringSpriteToDraw);
-
+ StringSpriteToDraw *ss = _vd.string_sprites_to_draw.Append();
ss->string = string;
- ss->next = NULL;
ss->x = x;
ss->y = y;
ss->params[0] = params_1;
ss->params[1] = params_2;
- ss->width = 0;
-
- *vd->last_string = ss;
- vd->last_string = &ss->next;
-
- return ss;
+ ss->width = width;
+ ss->color = color;
}
@@ -837,7 +740,7 @@
static void DrawSelectionSprite(SpriteID image, SpriteID pal, const TileInfo *ti, int z_offset, FoundationPart foundation_part)
{
/* FIXME: This is not totally valid for some autorail highlights, that extent over the edges of the tile. */
- if (_cur_vd->foundation[foundation_part] == NULL) {
+ if (_vd.foundation[foundation_part] == -1) {
/* draw on real ground */
DrawGroundSpriteAt(image, pal, ti->x, ti->y, ti->z + z_offset);
} else {
@@ -1010,7 +913,6 @@
static void ViewportAddLandscape()
{
- ViewportDrawer *vd = _cur_vd;
int x, y, width, height;
TileInfo ti;
bool direction;
@@ -1018,14 +920,14 @@
_cur_ti = &ti;
/* Transform into tile coordinates and round to closest full tile */
- x = ((vd->dpi.top >> 1) - (vd->dpi.left >> 2)) & ~0xF;
- y = ((vd->dpi.top >> 1) + (vd->dpi.left >> 2) - 0x10) & ~0xF;
+ x = ((_vd.dpi.top >> 1) - (_vd.dpi.left >> 2)) & ~0xF;
+ y = ((_vd.dpi.top >> 1) + (_vd.dpi.left >> 2) - 0x10) & ~0xF;
/* determine size of area */
{
Point pt = RemapCoords(x, y, 241);
- width = (vd->dpi.left + vd->dpi.width - pt.x + 95) >> 6;
- height = (vd->dpi.top + vd->dpi.height - pt.y) >> 5 << 1;
+ width = (_vd.dpi.left + _vd.dpi.width - pt.x + 95) >> 6;
+ height = (_vd.dpi.top + _vd.dpi.height - pt.y) >> 5 << 1;
}
assert(width > 0);
@@ -1060,11 +962,11 @@
y_cur += 0x10;
x_cur -= 0x10;
- vd->foundation_part = FOUNDATION_PART_NONE;
- vd->foundation[0] = NULL;
- vd->foundation[1] = NULL;
- vd->last_foundation_child[0] = NULL;
- vd->last_foundation_child[1] = NULL;
+ _vd.foundation_part = FOUNDATION_PART_NONE;
+ _vd.foundation[0] = -1;
+ _vd.foundation[1] = -1;
+ _vd.last_foundation_child[0] = NULL;
+ _vd.last_foundation_child[1] = NULL;
_tile_type_procs[tt]->draw_tile_proc(&ti);
DrawTileSelection(&ti);
@@ -1114,7 +1016,7 @@
if (bottom > t->sign.top &&
top < t->sign.top + 24 &&
right > t->sign.left &&
- left < t->sign.left + t->sign.width_1*2) {
+ left < t->sign.left + t->sign.width_1 * 2) {
AddStringToDraw(t->sign.left + 1, t->sign.top + 1,
_patches.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL,
t->index, t->population);
@@ -1145,13 +1047,7 @@
static void AddStation(const Station *st, StringID str, uint16 width)
{
- StringSpriteToDraw *sstd;
-
- sstd = (StringSpriteToDraw*)AddStringToDraw(st->sign.left + 1, st->sign.top + 1, str, st->index, st->facilities);
- if (sstd != NULL) {
- sstd->color = (st->owner == OWNER_NONE || st->facilities == 0) ? 0xE : _player_colors[st->owner];
- sstd->width = width;
- }
+ AddStringToDraw(st->sign.left + 1, st->sign.top + 1, str, st->index, st->facilities, (st->owner == OWNER_NONE || st->facilities == 0) ? 0xE : _player_colors[st->owner], width);
}
@@ -1187,7 +1083,7 @@
if (bottom > st->sign.top &&
top < st->sign.top + 24 &&
right > st->sign.left &&
- left < st->sign.left + st->sign.width_1*2) {
+ left < st->sign.left + st->sign.width_1 * 2) {
AddStation(st, STR_305C_0, st->sign.width_1);
}
}
@@ -1215,13 +1111,7 @@
static void AddSign(const Sign *si, StringID str, uint16 width)
{
- StringSpriteToDraw *sstd;
-
- sstd = (StringSpriteToDraw*)AddStringToDraw(si->sign.left + 1, si->sign.top + 1, str, si->index, 0);
- if (sstd != NULL) {
- sstd->color = (si->owner == OWNER_NONE) ? 14 : _player_colors[si->owner];
- sstd->width = width;
- }
+ AddStringToDraw(si->sign.left + 1, si->sign.top + 1, str, si->index, 0, (si->owner == OWNER_NONE) ? 14 : _player_colors[si->owner], width);
}
@@ -1285,13 +1175,7 @@
static void AddWaypoint(const Waypoint *wp, StringID str, uint16 width)
{
- StringSpriteToDraw *sstd;
-
- sstd = (StringSpriteToDraw*)AddStringToDraw(wp->sign.left + 1, wp->sign.top + 1, str, wp->index, 0);
- if (sstd != NULL) {
- sstd->color = (wp->deleted ? 0xE : 11);
- sstd->width = width;
- }
+ AddStringToDraw(wp->sign.left + 1, wp->sign.top + 1, str, wp->index, 0, (wp->deleted ? 0xE : 11), width);
}
@@ -1327,7 +1211,7 @@
if (bottom > wp->sign.top &&
top < wp->sign.top + 24 &&
right > wp->sign.left &&
- left < wp->sign.left + wp->sign.width_1*2) {
+ left < wp->sign.left + wp->sign.width_1 * 2) {
AddWaypoint(wp, STR_WAYPOINT_VIEWPORT, wp->sign.width_1);
}
}
@@ -1372,84 +1256,84 @@
}
-static void ViewportDrawTileSprites(TileSpriteToDraw *ts)
+static void ViewportDrawTileSprites(const TileSpriteToDrawVector *tstdv)
{
- do {
+ const TileSpriteToDraw *tsend = tstdv->End();
+ for (const TileSpriteToDraw *ts = tstdv->Begin(); ts != tsend; ++ts) {
Point pt = RemapCoords(ts->x, ts->y, ts->z);
DrawSprite(ts->image, ts->pal, pt.x, pt.y, ts->sub);
- ts = ts->next;
- } while (ts != NULL);
+ }
}
-static void ViewportSortParentSprites(ParentSpriteToDraw *psd[])
+static void ViewportSortParentSprites(ParentSpriteToSortVector *psdv)
{
- while (*psd != NULL) {
- ParentSpriteToDraw* ps = *psd;
-
- if (!ps->comparison_done) {
- ParentSpriteToDraw** psd2 = psd;
-
- ps->comparison_done = true;
-
- while (*++psd2 != NULL) {
- ParentSpriteToDraw* ps2 = *psd2;
- ParentSpriteToDraw** psd3;
-
- if (ps2->comparison_done) continue;
-
- /* Decide which comparator to use, based on whether the bounding
- * boxes overlap
+ ParentSpriteToDraw **psdvend = psdv->End();
+ ParentSpriteToDraw **psd = psdv->Begin();
+ while (psd != psdvend) {
+ ParentSpriteToDraw *ps = *psd;
+
+ if (ps->comparison_done) {
+ psd++;
+ continue;
+ }
+
+ ps->comparison_done = true;
+
+ for (ParentSpriteToDraw **psd2 = psd + 1; psd2 != psdvend; psd2++) {
+ ParentSpriteToDraw *ps2 = *psd2;
+
+ if (ps2->comparison_done) continue;
+
+ /* Decide which comparator to use, based on whether the bounding
+ * boxes overlap
+ */
+ if (ps->xmax >= ps2->xmin && ps->xmin <= ps2->xmax && // overlap in X?
+ ps->ymax >= ps2->ymin && ps->ymin <= ps2->ymax && // overlap in Y?
+ ps->zmax >= ps2->zmin && ps->zmin <= ps2->zmax) { // overlap in Z?
+ /* Use X+Y+Z as the sorting order, so sprites closer to the bottom of
+ * the screen and with higher Z elevation, are drawn in front.
+ * Here X,Y,Z are the coordinates of the "center of mass" of the sprite,
+ * i.e. X=(left+right)/2, etc.
+ * However, since we only care about order, don't actually divide / 2
*/
- if (ps->xmax >= ps2->xmin && ps->xmin <= ps2->xmax && // overlap in X?
- ps->ymax >= ps2->ymin && ps->ymin <= ps2->ymax && // overlap in Y?
- ps->zmax >= ps2->zmin && ps->zmin <= ps2->zmax) { // overlap in Z?
- /* Use X+Y+Z as the sorting order, so sprites closer to the bottom of
- * the screen and with higher Z elevation, are drawn in front.
- * Here X,Y,Z are the coordinates of the "center of mass" of the sprite,
- * i.e. X=(left+right)/2, etc.
- * However, since we only care about order, don't actually divide / 2
- */
- if (ps->xmin + ps->xmax + ps->ymin + ps->ymax + ps->zmin + ps->zmax <=
- ps2->xmin + ps2->xmax + ps2->ymin + ps2->ymax + ps2->zmin + ps2->zmax) {
- continue;
- }
- } else {
- /* We only change the order, if it is definite.
- * I.e. every single order of X, Y, Z says ps2 is behind ps or they overlap.
- * That is: If one partial order says ps behind ps2, do not change the order.
- */
- if (ps->xmax < ps2->xmin ||
- ps->ymax < ps2->ymin ||
- ps->zmax < ps2->zmin) {
- continue;
- }
+ if (ps->xmin + ps->xmax + ps->ymin + ps->ymax + ps->zmin + ps->zmax <=
+ ps2->xmin + ps2->xmax + ps2->ymin + ps2->ymax + ps2->zmin + ps2->zmax) {
+ continue;
}
-
- /* Swap the two sprites ps and ps2 using bubble-sort algorithm. */
- psd3 = psd;
- do {
- ParentSpriteToDraw* temp = *psd3;
- *psd3 = ps2;
- ps2 = temp;
-
- psd3++;
- } while (psd3 <= psd2);
+ } else {
+ /* We only change the order, if it is definite.
+ * I.e. every single order of X, Y, Z says ps2 is behind ps or they overlap.
+ * That is: If one partial order says ps behind ps2, do not change the order.
+ */
+ if (ps->xmax < ps2->xmin ||
+ ps->ymax < ps2->ymin ||
+ ps->zmax < ps2->zmin) {
+ continue;
+ }
}
- } else {
- psd++;
+
+ /* Swap the two sprites ps and ps2 using bubble-sort algorithm. */
+ ParentSpriteToDraw **psd3 = psd;
+ do {
+ ParentSpriteToDraw *temp = *psd3;
+ *psd3 = ps2;
+ ps2 = temp;
+
+ psd3++;
+ } while (psd3 <= psd2);
}
}
}
-static void ViewportDrawParentSprites(ParentSpriteToDraw *psd[])
+static void ViewportDrawParentSprites(const ParentSpriteToSortVector *psd, const ChildScreenSpriteToDrawVector *csstdv)
{
- for (; *psd != NULL; psd++) {
- const ParentSpriteToDraw* ps = *psd;
- const ChildScreenSpriteToDraw* cs;
-
+ const ParentSpriteToDraw * const *psd_end = psd->End();
+ for (const ParentSpriteToDraw * const *it = psd->Begin(); it != psd_end; it++) {
+ const ParentSpriteToDraw *ps = *it;
if (ps->image != SPR_EMPTY_BOUNDING_BOX) DrawSprite(ps->image, ps->pal, ps->x, ps->y, ps->sub);
- for (cs = ps->child; cs != NULL; cs = cs->next) {
+ const ChildScreenSpriteToDraw *last = csstdv->Get(ps->last_child);
+ for (const ChildScreenSpriteToDraw *cs = csstdv->Get(ps->first_child); cs != last; cs++) {
DrawSprite(cs->image, cs->pal, ps->left + cs->x, ps->top + cs->y, cs->sub);
}
}
@@ -1459,10 +1343,11 @@
* Draws the bounding boxes of all ParentSprites
* @param psd Array of ParentSprites
*/
-static void ViewportDrawBoundingBoxes(ParentSpriteToDraw *psd[])
+static void ViewportDrawBoundingBoxes(const ParentSpriteToSortVector *psd)
{
- for (; *psd != NULL; psd++) {
- const ParentSpriteToDraw* ps = *psd;
+ const ParentSpriteToDraw * const *psd_end = psd->End();
+ for (const ParentSpriteToDraw * const *it = psd->Begin(); it != psd_end; it++) {
+ const ParentSpriteToDraw *ps = *it;
Point pt1 = RemapCoords(ps->xmax + 1, ps->ymax + 1, ps->zmax + 1); // top front corner
Point pt2 = RemapCoords(ps->xmin , ps->ymax + 1, ps->zmax + 1); // top left corner
Point pt3 = RemapCoords(ps->xmax + 1, ps->ymin , ps->zmax + 1); // top right corner
@@ -1475,7 +1360,7 @@
}
}
-static void ViewportDrawStrings(DrawPixelInfo *dpi, const StringSpriteToDraw *ss)
+static void ViewportDrawStrings(DrawPixelInfo *dpi, const StringSpriteToDrawVector *sstdv)
{
DrawPixelInfo dp;
ZoomLevel zoom;
@@ -1491,15 +1376,13 @@
dp.width = UnScaleByZoom(dp.width, zoom);
dp.height = UnScaleByZoom(dp.height, zoom);
- do {
+ const StringSpriteToDraw *ssend = sstdv->End();
+ for (const StringSpriteToDraw *ss = sstdv->Begin(); ss != ssend; ++ss) {
uint16 colour;
if (ss->width != 0) {
/* Do not draw signs nor station names if they are set invisible */
- if (IsInvisibilitySet(TO_SIGNS) && ss->string != STR_2806) {
- ss = ss->next;
- continue;
- }
+ if (IsInvisibilitySet(TO_SIGNS) && ss->string != STR_2806) continue;
int x = UnScaleByZoom(ss->x, zoom) - 1;
int y = UnScaleByZoom(ss->y, zoom) - 1;
@@ -1538,78 +1421,61 @@
UnScaleByZoom(ss->x, zoom), UnScaleByZoom(ss->y, zoom) - (ss->width & 0x8000 ? 2 : 0),
ss->string, colour
);
-
- ss = ss->next;
- } while (ss != NULL);
+ }
}
void ViewportDoDraw(const ViewPort *vp, int left, int top, int right, int bottom)
{
- ViewportDrawer vd;
- int mask;
- int x;
- int y;
- DrawPixelInfo *old_dpi;
-
- SmallStackSafeStackAlloc<byte, VIEWPORT_DRAW_MEM> mem;
- SmallStackSafeStackAlloc<ParentSpriteToDraw*, PARENT_LIST_SIZE> parent_list;
-
- _cur_vd = &vd;
-
- old_dpi = _cur_dpi;
- _cur_dpi = &vd.dpi;
-
- vd.dpi.zoom = vp->zoom;
- mask = ScaleByZoom(-1, vp->zoom);
-
- vd.combine_sprites = 0;
-
- vd.dpi.width = (right - left) & mask;
- vd.dpi.height = (bottom - top) & mask;
- vd.dpi.left = left & mask;
- vd.dpi.top = top & mask;
- vd.dpi.pitch = old_dpi->pitch;
-
- x = UnScaleByZoom(vd.dpi.left - (vp->virtual_left & mask), vp->zoom) + vp->left;
- y = UnScaleByZoom(vd.dpi.top - (vp->virtual_top & mask), vp->zoom) + vp->top;
-
- vd.dpi.dst_ptr = BlitterFactoryBase::GetCurrentBlitter()->MoveTo(old_dpi->dst_ptr, x - old_dpi->left, y - old_dpi->top);
-
- vd.parent_list = parent_list;
- vd.eof_parent_list = parent_list.EndOf();
- vd.spritelist_mem = mem;
- vd.eof_spritelist_mem = mem.EndOf() - sizeof(LARGEST_SPRITELIST_STRUCT);
- vd.last_string = &vd.first_string;
- vd.first_string = NULL;
- vd.last_tile = &vd.first_tile;
- vd.first_tile = NULL;
+ DrawPixelInfo *old_dpi = _cur_dpi;
+ _cur_dpi = &_vd.dpi;
+
+ _vd.dpi.zoom = vp->zoom;
+ int mask = ScaleByZoom(-1, vp->zoom);
+
+ _vd.combine_sprites = 0;
+
+ _vd.dpi.width = (right - left) & mask;
+ _vd.dpi.height = (bottom - top) & mask;
+ _vd.dpi.left = left & mask;
+ _vd.dpi.top = top & mask;
+ _vd.dpi.pitch = old_dpi->pitch;
+ _vd.last_child = NULL;
+
+ int x = UnScaleByZoom(_vd.dpi.left - (vp->virtual_left & mask), vp->zoom) + vp->left;
+ int y = UnScaleByZoom(_vd.dpi.top - (vp->virtual_top & mask), vp->zoom) + vp->top;
+
+ _vd.dpi.dst_ptr = BlitterFactoryBase::GetCurrentBlitter()->MoveTo(old_dpi->dst_ptr, x - old_dpi->left, y - old_dpi->top);
ViewportAddLandscape();
- ViewportAddVehicles(&vd.dpi);
- DrawTextEffects(&vd.dpi);
-
- ViewportAddTownNames(&vd.dpi);
- ViewportAddStationNames(&vd.dpi);
- ViewportAddSigns(&vd.dpi);
- ViewportAddWaypoints(&vd.dpi);
-
- /* This assert should never happen (because the length of the parent_list
- * is checked) */
- assert(vd.parent_list <= endof(parent_list));
-
- if (vd.first_tile != NULL) ViewportDrawTileSprites(vd.first_tile);
-
- /* null terminate parent sprite list */
- *vd.parent_list = NULL;
-
- ViewportSortParentSprites(parent_list);
- ViewportDrawParentSprites(parent_list);
-
- if (_draw_bounding_boxes) ViewportDrawBoundingBoxes(parent_list);
-
- if (vd.first_string != NULL) ViewportDrawStrings(&vd.dpi, vd.first_string);
+ ViewportAddVehicles(&_vd.dpi);
+ DrawTextEffects(&_vd.dpi);
+
+ ViewportAddTownNames(&_vd.dpi);
+ ViewportAddStationNames(&_vd.dpi);
+ ViewportAddSigns(&_vd.dpi);
+ ViewportAddWaypoints(&_vd.dpi);
+
+ if (_vd.tile_sprites_to_draw.items != 0) ViewportDrawTileSprites(&_vd.tile_sprites_to_draw);
+
+ ParentSpriteToDraw *psd_end = _vd.parent_sprites_to_draw.End();
+ for (ParentSpriteToDraw *it = _vd.parent_sprites_to_draw.Begin(); it != psd_end; it++) {
+ *_vd.parent_sprites_to_sort.Append() = it;
+ }
+
+ ViewportSortParentSprites(&_vd.parent_sprites_to_sort);
+ ViewportDrawParentSprites(&_vd.parent_sprites_to_sort, &_vd.child_screen_sprites_to_draw);
+
+ if (_draw_bounding_boxes) ViewportDrawBoundingBoxes(&_vd.parent_sprites_to_sort);
+
+ if (_vd.string_sprites_to_draw.items != 0) ViewportDrawStrings(&_vd.dpi, &_vd.string_sprites_to_draw);
_cur_dpi = old_dpi;
+
+ _vd.string_sprites_to_draw.items = 0;
+ _vd.tile_sprites_to_draw.items = 0;
+ _vd.parent_sprites_to_draw.items = 0;
+ _vd.parent_sprites_to_sort.items = 0;
+ _vd.child_screen_sprites_to_draw.items = 0;
}
/** Make sure we don't draw a too big area at a time.
@@ -1758,14 +1624,15 @@
void MarkAllViewportsDirty(int left, int top, int right, int bottom)
{
- const ViewPort *vp = _viewports;
- uint32 act = _active_viewports;
- do {
- if (act & 1) {
+ Window **wz;
+
+ FOR_ALL_WINDOWS(wz) {
+ ViewPort *vp = (*wz)->viewport;
+ if (vp != NULL) {
assert(vp->width != 0);
MarkViewportDirty(vp, left, top, right, bottom);
}
- } while (vp++,act>>=1);
+ }
}
void MarkTileDirtyByTile(TileIndex tile)
--- a/src/viewport_func.h Thu Apr 17 08:40:01 2008 +0000
+++ b/src/viewport_func.h Fri Apr 18 23:33:51 2008 +0000
@@ -12,7 +12,6 @@
void SetSelectionRed(bool);
-void InitViewports();
void DeleteWindowViewport(Window *w);
void AssignWindowViewport(Window *w, int x, int y, int width, int height, uint32 follow_flags, ZoomLevel zoom);
ViewPort *IsPtInWindowViewport(const Window *w, int x, int y);
@@ -34,7 +33,7 @@
void DrawGroundSprite(SpriteID image, SpriteID pal, const SubSprite *sub = NULL);
void DrawGroundSpriteAt(SpriteID image, SpriteID pal, int32 x, int32 y, byte z, const SubSprite *sub = NULL);
void AddSortableSpriteToDraw(SpriteID image, SpriteID pal, int x, int y, int w, int h, int dz, int z, bool transparent = false, int bb_offset_x = 0, int bb_offset_y = 0, int bb_offset_z = 0, const SubSprite *sub = NULL);
-void *AddStringToDraw(int x, int y, StringID string, uint64 params_1, uint64 params_2);
+void AddStringToDraw(int x, int y, StringID string, uint64 params_1, uint64 params_2, uint16 color = 0, uint16 width = 0);
void AddChildSpriteScreen(SpriteID image, SpriteID pal, int x, int y, bool transparent = false, const SubSprite *sub = NULL);
--- a/src/water_cmd.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/water_cmd.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -14,7 +14,8 @@
#include "command_func.h"
#include "town.h"
#include "news_func.h"
-#include "depot.h"
+#include "depot_base.h"
+#include "depot_func.h"
#include "vehicle_gui.h"
#include "train.h"
#include "roadveh.h"
--- a/src/water_map.h Thu Apr 17 08:40:01 2008 +0000
+++ b/src/water_map.h Fri Apr 18 23:33:51 2008 +0000
@@ -91,11 +91,16 @@
return t + (HasBit(_m[t].m5, 0) ? -1 : 1) * (HasBit(_m[t].m5, 1) ? TileDiffXY(0, 1) : TileDiffXY(1, 0));
}
-static inline TileIndex IsShipDepot(TileIndex t)
+static inline bool IsShipDepot(TileIndex t)
{
return IsInsideMM(_m[t].m5, DEPOT_NORTH, DEPOT_END);
}
+static inline bool IsShipDepotTile(TileIndex t)
+{
+ return IsTileType(t, MP_WATER) && IsShipDepot(t);
+}
+
static inline Axis GetShipDepotAxis(TileIndex t)
{
return (Axis)GB(_m[t].m5, 1, 1);
--- a/src/waypoint.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/waypoint.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -100,7 +100,7 @@
Waypoint *lwp = GetWaypoint(cid);
/* check only valid waypoints... */
- if (lwp->IsValid() && wp != lwp) {
+ if (lwp->IsValid() && wp != lwp) {
/* only waypoints with 'generic' name within the same city */
if (lwp->name == NULL && lwp->town_index == wp->town_index) {
/* if lwp->town_cn < next, uint will overflow to '+inf' */
--- a/src/waypoint.h Thu Apr 17 08:40:01 2008 +0000
+++ b/src/waypoint.h Fri Apr 18 23:33:51 2008 +0000
@@ -10,6 +10,7 @@
#include "rail_map.h"
#include "command_type.h"
#include "station_type.h"
+#include "town_type.h"
DECLARE_OLD_POOL(Waypoint, Waypoint, 3, 8000)
--- a/src/widget.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/widget.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -86,7 +86,7 @@
default: NOT_REACHED();
}
- if (pos <= mi+9) {
+ if (pos <= mi + 9) {
/* Pressing the upper button? */
w->flags4 |= WF_SCROLL_UP;
if (_scroller_click_timeout == 0) {
--- a/src/win32.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/win32.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -249,7 +249,7 @@
#if 0
struct WinInetProcs {
- HINTERNET (WINAPI *InternetOpen)(LPCTSTR,DWORD, LPCTSTR, LPCTSTR, DWORD);
+ HINTERNET (WINAPI *InternetOpen)(LPCTSTR, DWORD, LPCTSTR, LPCTSTR, DWORD);
HINTERNET (WINAPI *InternetConnect)(HINTERNET, LPCTSTR, INTERNET_PORT, LPCTSTR, LPCTSTR, DWORD, DWORD, DWORD);
HINTERNET (WINAPI *HttpOpenRequest)(HINTERNET, LPCTSTR, LPCTSTR, LPCTSTR, LPCTSTR, LPCTSTR *, DWORD, DWORD);
BOOL (WINAPI *HttpSendRequest)(HINTERNET, LPCTSTR, DWORD, LPVOID, DWORD);
@@ -1021,7 +1021,7 @@
char *getcwd(char *buf, size_t size)
{
#if defined(WINCE)
- TCHAR path[MAX_PATH];
+ TCHAR path[MAX_PATH];
GetModuleFileName(NULL, path, MAX_PATH);
convert_from_fs(path, buf, size);
/* GetModuleFileName returns dir with file, so remove everything behind latest '\\' */
--- a/src/window.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/window.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -19,6 +19,7 @@
#include "map_func.h"
#include "vehicle_base.h"
#include "settings_type.h"
+#include "cheat_func.h"
#include "table/sprites.h"
@@ -1037,7 +1038,6 @@
IConsoleClose();
_last_z_window = _z_windows;
- InitViewports();
_no_scroll = 0;
}
@@ -2316,7 +2316,7 @@
const Window *wt = FindWindowById(WC_MAIN_TOOLBAR, 0);
if (wt != NULL) {
- if (top < wt->height) top = wt->height;
+ if (top < wt->height && wt->left < (w->left + w->width) && (wt->left + wt->width) > w->left) top = wt->height;
if (top >= newh) top = newh - 1;
} else {
if (top < 0) top = 0;
--- a/src/window_gui.h Thu Apr 17 08:40:01 2008 +0000
+++ b/src/window_gui.h Fri Apr 18 23:33:51 2008 +0000
@@ -42,7 +42,7 @@
Now the window will only change in height in steps of 10.
You can also give a minimum width and height. The default value is
the default height/width of the window itself. You can change this
- AFTER window-creation, with:
+ AFTER window - creation, with:
w->resize.width or w->resize.height.
That was all.. good luck, and enjoy :) -- TrueLight */
@@ -409,6 +409,7 @@
int32 scrollpos_y;
int32 dest_scrollpos_x;
int32 dest_scrollpos_y;
+ ViewPort vp_data; ///< Screen position and zoom of the viewport
};
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(vp_d));
--- a/src/yapf/follow_track.hpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/yapf/follow_track.hpp Fri Apr 18 23:33:51 2008 +0000
@@ -6,7 +6,7 @@
#define FOLLOW_TRACK_HPP
#include "yapf.hpp"
-
+#include "../depot_map.h"
/** Track follower helper template class (can serve pathfinders and vehicle
* controllers). See 6 different typedefs below for 3 different transport
@@ -196,7 +196,7 @@
}
// road depots can be also left in one direction only
- if (IsRoadTT() && IsTileDepotType(m_old_tile, TT())) {
+ if (IsRoadTT() && IsDepotTypeTile(m_old_tile, TT())) {
DiagDirection exitdir = GetRoadDepotDirection(m_old_tile);
if (exitdir != m_exitdir) {
m_err = EC_NO_WAY;
@@ -226,7 +226,7 @@
}
// road and rail depots can also be entered from one direction only
- if (IsRoadTT() && IsTileDepotType(m_new_tile, TT())) {
+ if (IsRoadTT() && IsDepotTypeTile(m_new_tile, TT())) {
DiagDirection exitdir = GetRoadDepotDirection(m_new_tile);
if (ReverseDiagDir(exitdir) != m_exitdir) {
m_err = EC_NO_WAY;
@@ -238,7 +238,7 @@
return false;
}
}
- if (IsRailTT() && IsTileDepotType(m_new_tile, TT())) {
+ if (IsRailTT() && IsDepotTypeTile(m_new_tile, TT())) {
DiagDirection exitdir = GetRailDepotDirection(m_new_tile);
if (ReverseDiagDir(exitdir) != m_exitdir) {
m_err = EC_NO_WAY;
@@ -305,7 +305,7 @@
FORCEINLINE bool ForcedReverse()
{
// rail and road depots cause reversing
- if (!IsWaterTT() && IsTileDepotType(m_old_tile, TT())) {
+ if (!IsWaterTT() && IsDepotTypeTile(m_old_tile, TT())) {
DiagDirection exitdir = IsRailTT() ? GetRailDepotDirection(m_old_tile) : GetRoadDepotDirection(m_old_tile);
if (exitdir != m_exitdir) {
// reverse
--- a/src/yapf/yapf.hpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/yapf/yapf.hpp Fri Apr 18 23:33:51 2008 +0000
@@ -8,7 +8,6 @@
#include "track_dir.hpp"
#include "../vehicle_base.h"
-#include "../depot.h"
#include "../road_map.h"
#include "../tunnel_map.h"
#include "../bridge_map.h"
--- a/src/yapf/yapf_destrail.hpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/yapf/yapf_destrail.hpp Fri Apr 18 23:33:51 2008 +0000
@@ -43,7 +43,7 @@
/// Called by YAPF to detect if node ends in the desired destination
FORCEINLINE bool PfDetectDestination(TileIndex tile, Trackdir td)
{
- bool bDest = IsTileDepotType(tile, TRANSPORT_RAIL);
+ bool bDest = IsRailDepotTile(tile);
return bDest;
}
--- a/src/yapf/yapf_road.cpp Thu Apr 17 08:40:01 2008 +0000
+++ b/src/yapf/yapf_road.cpp Fri Apr 18 23:33:51 2008 +0000
@@ -3,6 +3,7 @@
/** @file yapf_road.cpp */
#include "../stdafx.h"
+#include "../depot_base.h"
#include "yapf.hpp"
#include "yapf_node_road.hpp"
@@ -87,7 +88,7 @@
if (v->current_order.IsType(OT_GOTO_STATION) && tile == v->dest_tile) break;
// stop if we have just entered the depot
- if (IsTileDepotType(tile, TRANSPORT_ROAD) && trackdir == DiagdirToDiagTrackdir(ReverseDiagDir(GetRoadDepotDirection(tile)))) {
+ if (IsRoadDepotTile(tile) && trackdir == DiagdirToDiagTrackdir(ReverseDiagDir(GetRoadDepotDirection(tile)))) {
// next time we will reverse and leave the depot
break;
}
@@ -148,7 +149,7 @@
/// Called by YAPF to detect if node ends in the desired destination
FORCEINLINE bool PfDetectDestination(Node& n)
{
- bool bDest = IsTileDepotType(n.m_segment_last_tile, TRANSPORT_ROAD);
+ bool bDest = IsRoadDepotTile(n.m_segment_last_tile);
return bDest;
}
@@ -370,7 +371,7 @@
// get found depot tile
Node *n = Yapf().GetBestNode();
TileIndex depot_tile = n->m_segment_last_tile;
- assert(IsTileDepotType(depot_tile, TRANSPORT_ROAD));
+ assert(IsRoadDepotTile(depot_tile));
Depot* ret = GetDepotByTile(depot_tile);
return ret;
}
@@ -439,7 +440,7 @@
return NULL;
// handle the case when our vehicle is already in the depot tile
- if (IsTileType(tile, MP_ROAD) && IsTileDepotType(tile, TRANSPORT_ROAD)) {
+ if (IsRoadDepotTile(tile)) {
// only what we need to return is the Depot*
return GetDepotByTile(tile);
}