--- a/src/settings.cpp Fri Apr 25 02:15:34 2008 +0000
+++ b/src/settings.cpp Mon May 26 20:45:25 2008 +0000
@@ -44,6 +44,7 @@
#include "sound_func.h"
#include "core/alloc_func.hpp"
#include "player_func.h"
+#include "rev.h"
#ifdef WITH_FREETYPE
#include "fontcache.h"
#endif
@@ -52,6 +53,7 @@
#include "textbuf_gui.h"
#include "string_func.h"
#include "rail_gui.h"
+#include "elrail_func.h"
#include "gui.h"
#include "town.h"
#include "video/video_driver.hpp"
@@ -77,18 +79,18 @@
typedef void SettingDescProcList(IniFile *ini, const char *grpname, char **list, uint len, SettingListCallbackProc proc);
static void pool_init(SettingsMemoryPool **pool);
-static void *pool_alloc(SettingsMemoryPool **pool, uint size);
-static void *pool_strdup(SettingsMemoryPool **pool, const char *mem, uint size);
+static void *pool_alloc(SettingsMemoryPool **pool, size_t size);
+static void *pool_strdup(SettingsMemoryPool **pool, const char *mem, size_t size);
static void pool_free(SettingsMemoryPool **pool);
static bool IsSignedVarMemType(VarType vt);
struct SettingsMemoryPool {
- uint pos, size;
+ size_t pos, size;
SettingsMemoryPool *next;
byte mem[1];
};
-static SettingsMemoryPool *pool_new(uint minsize)
+static SettingsMemoryPool *pool_new(size_t minsize)
{
SettingsMemoryPool *p;
if (minsize < 4096 - 12) minsize = 4096 - 12;
@@ -105,9 +107,9 @@
*pool = pool_new(0);
}
-static void *pool_alloc(SettingsMemoryPool **pool, uint size)
+static void *pool_alloc(SettingsMemoryPool **pool, size_t size)
{
- uint pos;
+ size_t pos;
SettingsMemoryPool *p = *pool;
size = Align(size, sizeof(void*));
@@ -128,7 +130,7 @@
return p->mem + pos;
}
-static void *pool_strdup(SettingsMemoryPool **pool, const char *mem, uint size)
+static void *pool_strdup(SettingsMemoryPool **pool, const char *mem, size_t size)
{
byte *p = (byte*)pool_alloc(pool, size + 1);
p[size] = 0;
@@ -185,7 +187,7 @@
}
/** allocate an ini group object */
-static IniGroup *ini_group_alloc(IniFile *ini, const char *grpt, int len)
+static IniGroup *ini_group_alloc(IniFile *ini, const char *grpt, size_t len)
{
IniGroup *grp = (IniGroup*)pool_alloc(&ini->pool, sizeof(IniGroup));
grp->ini = ini;
@@ -204,7 +206,7 @@
return grp;
}
-static IniItem *ini_item_alloc(IniGroup *group, const char *name, int len)
+static IniItem *ini_item_alloc(IniGroup *group, const char *name, size_t len)
{
IniItem *item = (IniItem*)pool_alloc(&group->ini->pool, sizeof(IniItem));
item->name = (char*)pool_strdup(&group->ini->pool, name, len);
@@ -323,11 +325,11 @@
}
/** lookup a group or make a new one */
-static IniGroup *ini_getgroup(IniFile *ini, const char *name, int len)
+static IniGroup *ini_getgroup(IniFile *ini, const char *name, size_t len = 0)
{
IniGroup *group;
- if (len == -1) len = strlen(name);
+ if (len == 0) len = strlen(name);
/* does it exist already? */
for (group = ini->group; group; group = group->next)
@@ -344,7 +346,7 @@
static IniItem *ini_getitem(IniGroup *group, const char *name, bool create)
{
IniItem *item;
- uint len = strlen(name);
+ size_t len = strlen(name);
for (item = group->item; item; item = item->next)
if (strcmp(item->name, name) == 0) return item;
@@ -403,12 +405,12 @@
* @param one the current value of the setting for which a value needs found
* @param onelen force calculation of the *one parameter
* @return the integer index of the full-list, or -1 if not found */
-static int lookup_oneofmany(const char *many, const char *one, int onelen)
+static int lookup_oneofmany(const char *many, const char *one, size_t onelen = 0)
{
const char *s;
int idx;
- if (onelen == -1) onelen = strlen(one);
+ if (onelen == 0) onelen = strlen(one);
/* check if it's an integer */
if (*one >= '0' && *one <= '9')
@@ -419,7 +421,7 @@
/* find end of item */
s = many;
while (*s != '|' && *s != 0) s++;
- if (s - many == onelen && !memcmp(one, many, onelen)) return idx;
+ if ((size_t)(s - many) == onelen && !memcmp(one, many, onelen)) return idx;
if (*s == 0) return -1;
many = s + 1;
idx++;
@@ -614,7 +616,7 @@
return (void*)val;
}
case SDT_ONEOFMANY: {
- long r = lookup_oneofmany(desc->many, str, -1);
+ long r = lookup_oneofmany(desc->many, str);
/* if the first attempt of conversion from string to the appropriate value fails,
* look if we have defined a converter from old value to new value. */
if (r == -1 && desc->proc_cnvt != NULL) r = desc->proc_cnvt(str);
@@ -704,7 +706,7 @@
static void ini_load_settings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object)
{
IniGroup *group;
- IniGroup *group_def = ini_getgroup(ini, grpname, -1);
+ IniGroup *group_def = ini_getgroup(ini, grpname);
IniItem *item;
const void *p;
void *ptr;
@@ -799,7 +801,7 @@
group = ini_getgroup(ini, sdb->name, s - sdb->name);
s++;
} else {
- if (group_def == NULL) group_def = ini_getgroup(ini, grpname, -1);
+ if (group_def == NULL) group_def = ini_getgroup(ini, grpname);
s = sdb->name;
group = group_def;
}
@@ -894,7 +896,7 @@
* inside the list */
static void ini_load_setting_list(IniFile *ini, const char *grpname, char **list, uint len, SettingListCallbackProc proc)
{
- IniGroup *group = ini_getgroup(ini, grpname, -1);
+ IniGroup *group = ini_getgroup(ini, grpname);
IniItem *item;
const char *entry;
uint i, j;
@@ -922,7 +924,7 @@
* @param proc callback function that can will provide the source data if defined */
static void ini_save_setting_list(IniFile *ini, const char *grpname, char **list, uint len, SettingListCallbackProc proc)
{
- IniGroup *group = ini_getgroup(ini, grpname, -1);
+ IniGroup *group = ini_getgroup(ini, grpname);
IniItem *item = NULL;
const char *entry;
uint i;
@@ -1145,6 +1147,20 @@
return 0;
}
+static int32 InvalidateBuildIndustryWindow(int32 p1)
+{
+ InvalidateWindowData(WC_BUILD_INDUSTRY, 0);
+ return 0;
+}
+
+static int32 CloseSignalGUI(int32 p1)
+{
+ if (p1 == 0) {
+ DeleteWindowByClass(WC_BUILD_SIGNAL);
+ }
+ return 0;
+}
+
static int32 UpdateConsists(int32 p1)
{
Vehicle *v;
@@ -1210,9 +1226,7 @@
static int32 DragSignalsDensityChanged(int32)
{
- const Window *w = FindWindowById(WC_BUILD_SIGNAL, 0);
-
- if (w != NULL) SetWindowDirty(w);
+ SetWindowDirty(FindWindowById(WC_BUILD_SIGNAL, 0));
return 0;
}
@@ -1243,7 +1257,7 @@
static int32 ConvertLandscape(const char *value)
{
/* try with the old values */
- return lookup_oneofmany("normal|hilly|desert|candy", value, -1);
+ return lookup_oneofmany("normal|hilly|desert|candy", value);
}
/* End - Callback Functions */
@@ -1414,7 +1428,7 @@
SDT_BOOL(Patches, longbridges, 0,NN, true, STR_CONFIG_PATCHES_LONGBRIDGES, NULL),
SDT_BOOL(Patches, signal_side, N,NN, true, STR_CONFIG_PATCHES_SIGNALSIDE, RedrawScreen),
SDT_BOOL(Patches, always_small_airport, 0,NN, false, STR_CONFIG_PATCHES_SMALL_AIRPORTS, NULL),
- SDT_BOOL(Patches, enable_signal_gui, S, 0, false, STR_CONFIG_PATCHES_ENABLE_SIGNAL_GUI, NULL),
+ SDT_BOOL(Patches, enable_signal_gui, S, 0, false, STR_CONFIG_PATCHES_ENABLE_SIGNAL_GUI, CloseSignalGUI),
SDT_VAR(Patches, drag_signals_density,SLE_UINT8,S, 0, 4, 1, 20, 0, STR_CONFIG_PATCHES_DRAG_SIGNALS_DENSITY,DragSignalsDensityChanged),
SDT_VAR(Patches, semaphore_build_before,SLE_INT32, S, NC, 1975, MIN_YEAR, MAX_YEAR, 1, STR_CONFIG_PATCHES_SEMAPHORE_BUILD_BEFORE_DATE, ResetSignalVariant),
SDT_CONDVAR(Patches, town_layout, SLE_UINT8, 59, SL_MAX_VERSION, 0, MS, TL_ORIGINAL, TL_NO_ROADS, NUM_TLS - 1, 1, STR_CONFIG_PATCHES_TOWN_LAYOUT, CheckTownLayout),
@@ -1459,6 +1473,7 @@
SDT_CONDVAR(Patches, freight_trains, SLE_UINT8, 39, SL_MAX_VERSION, 0,NN, 1, 1, 255, 1, STR_CONFIG_PATCHES_FREIGHT_TRAINS, NULL),
SDT_CONDBOOL(Patches, timetabling, 67, SL_MAX_VERSION, 0, 0, true, STR_CONFIG_PATCHES_TIMETABLE_ALLOW, NULL),
SDT_CONDVAR(Patches, plane_speed, SLE_UINT8, 90, SL_MAX_VERSION, 0, 0, 4, 1, 4, 0, STR_CONFIG_PATCHES_PLANE_SPEED, NULL),
+ SDT_CONDBOOL(Patches, dynamic_engines, 95, SL_MAX_VERSION, 0,NN, false, STR_CONFIG_PATCHES_DYNAMIC_ENGINES, NULL),
/***************************************************************************/
/* Station section of the GUI-configure patches window */
@@ -1479,7 +1494,7 @@
/***************************************************************************/
/* Economy section of the GUI-configure patches window */
SDT_BOOL(Patches, inflation, 0, 0, true, STR_CONFIG_PATCHES_INFLATION, NULL),
- SDT_VAR(Patches, raw_industry_construction,SLE_UINT8,0,MS,0,0, 2, 0, STR_CONFIG_PATCHES_RAW_INDUSTRY_CONSTRUCTION_METHOD, NULL),
+ SDT_VAR(Patches, raw_industry_construction,SLE_UINT8,0,MS,0,0, 2, 0, STR_CONFIG_PATCHES_RAW_INDUSTRY_CONSTRUCTION_METHOD, InvalidateBuildIndustryWindow),
SDT_BOOL(Patches, multiple_industry_per_town, 0, 0, false, STR_CONFIG_PATCHES_MULTIPINDTOWN, NULL),
SDT_BOOL(Patches, same_industry_close, 0, 0, false, STR_CONFIG_PATCHES_SAMEINDCLOSE, NULL),
SDT_BOOL(Patches, bribe, 0, 0, true, STR_CONFIG_PATCHES_BRIBE, NULL),
@@ -1656,7 +1671,7 @@
static void NewsDisplayLoadConfig(IniFile *ini, const char *grpname)
{
- IniGroup *group = ini_getgroup(ini, grpname, -1);
+ IniGroup *group = ini_getgroup(ini, grpname);
IniItem *item;
/* If no group exists, return */
@@ -1691,7 +1706,7 @@
/* Load a GRF configuration from the given group name */
static GRFConfig *GRFLoadConfig(IniFile *ini, const char *grpname, bool is_static)
{
- IniGroup *group = ini_getgroup(ini, grpname, -1);
+ IniGroup *group = ini_getgroup(ini, grpname);
IniItem *item;
GRFConfig *first = NULL;
GRFConfig **curr = &first;
@@ -1743,7 +1758,7 @@
static void NewsDisplaySaveConfig(IniFile *ini, const char *grpname)
{
- IniGroup *group = ini_getgroup(ini, grpname, -1);
+ IniGroup *group = ini_getgroup(ini, grpname);
IniItem **item;
if (group == NULL) return;
@@ -1768,10 +1783,7 @@
*/
static void SaveVersionInConfig(IniFile *ini)
{
- extern const char _openttd_revision[];
- extern uint32 _openttd_newgrf_version;
-
- IniGroup *group = ini_getgroup(ini, "version", -1);
+ IniGroup *group = ini_getgroup(ini, "version");
if (group == NULL) return;
group->item = NULL;
@@ -1795,7 +1807,7 @@
/* Save a GRF configuration to the given group name */
static void GRFSaveConfig(IniFile *ini, const char *grpname, const GRFConfig *list)
{
- IniGroup *group = ini_getgroup(ini, grpname, -1);
+ IniGroup *group = ini_getgroup(ini, grpname);
IniItem **item;
const GRFConfig *c;