~ubuntu-branches/debian/squeeze/openttd/squeeze

« back to all changes in this revision

Viewing changes to src/settings.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Matthijs Kooijman
  • Date: 2010-07-01 08:14:02 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20100701081402-98jmva0t3sqywxmi
Tags: 1.0.2-1
* [00c4efe] New upstream release 1.0.2.
* [c7b38fd] Break older openttd versions instead of Conflicting with
  them.
* [36bd61f] Bump standards version to 3.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: settings.cpp 19430 2010-03-15 22:52:39Z rubidium $ */
 
1
/* $Id: settings.cpp 19875 2010-05-21 16:03:29Z rubidium $ */
2
2
 
3
3
/*
4
4
 * This file is part of OpenTTD.
1643
1643
 * Set a setting value with a string.
1644
1644
 * @param index the settings index.
1645
1645
 * @param value the value to write
1646
 
 * @note CANNOT BE SAVED IN THE SAVEGAME.
 
1646
 * @param force_newgame force the newgame settings
 
1647
 * @note Strings WILL NOT be synced over the network
1647
1648
 */
1648
 
bool SetSettingValue(uint index, const char *value)
 
1649
bool SetSettingValue(uint index, const char *value, bool force_newgame)
1649
1650
{
1650
1651
        const SettingDesc *sd = &_settings[index];
1651
1652
        assert(sd->save.conv & SLF_NETWORK_NO);
1652
1653
 
1653
 
        char *var = (char*)GetVariableAddress(NULL, &sd->save);
1654
 
        ttd_strlcpy(var, value, sd->save.length);
 
1654
        if (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ) {
 
1655
                char **var = (char**)GetVariableAddress((_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game, &sd->save);
 
1656
                free(*var);
 
1657
                *var = strcmp(value, "(null)") == 0 ? NULL : strdup(value);
 
1658
        } else {
 
1659
                char *var = (char*)GetVariableAddress(NULL, &sd->save);
 
1660
                ttd_strlcpy(var, value, sd->save.length);
 
1661
        }
1655
1662
        if (sd->desc.proc != NULL) sd->desc.proc(0);
1656
1663
 
1657
1664
        return true;
1708
1715
 
1709
1716
        bool success;
1710
1717
        if (sd->desc.cmd == SDT_STRING) {
1711
 
                success = SetSettingValue(index, value);
 
1718
                success = SetSettingValue(index, value, force_newgame);
1712
1719
        } else {
1713
1720
                uint32 val;
1714
1721
                extern bool GetArgumentInteger(uint32 *value, const char *arg);
1758
1765
        ptr = GetVariableAddress((_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game, &sd->save);
1759
1766
 
1760
1767
        if (sd->desc.cmd == SDT_STRING) {
1761
 
                IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s'", name, (const char *)ptr);
 
1768
                IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s'", name, (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ) ? *(const char **)ptr : (const char *)ptr);
1762
1769
        } else {
1763
1770
                if (sd->desc.cmd == SDT_BOOLX) {
1764
1771
                        snprintf(value, sizeof(value), (*(bool*)ptr == 1) ? "on" : "off");
1789
1796
                if (sd->desc.cmd == SDT_BOOLX) {
1790
1797
                        snprintf(value, lengthof(value), (*(bool*)ptr == 1) ? "on" : "off");
1791
1798
                } else if (sd->desc.cmd == SDT_STRING) {
1792
 
                        snprintf(value, sizeof(value), "%s", (const char *)ptr);
 
1799
                        snprintf(value, sizeof(value), "%s", (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ) ? *(const char **)ptr : (const char *)ptr);
1793
1800
                } else {
1794
1801
                        snprintf(value, lengthof(value), "%d", (uint32)ReadValue(ptr, sd->save.conv));
1795
1802
                }