src/settings.cpp
changeset 9739 9cf125da8789
parent 9704 54123af5f9a5
child 9785 2005c34d0811
equal deleted inserted replaced
9738:404c804ac68a 9739:9cf125da8789
  1888 		void *var = GetVariableAddress(savegame ? &_settings_game : &_settings_newgame, &sd->save);
  1888 		void *var = GetVariableAddress(savegame ? &_settings_game : &_settings_newgame, &sd->save);
  1889 		Write_ValidateSetting(var, sd, (int32)((i == 4 ? 1000 : 1) * _old_diff_custom[i]));
  1889 		Write_ValidateSetting(var, sd, (int32)((i == 4 ? 1000 : 1) * _old_diff_custom[i]));
  1890 	}
  1890 	}
  1891 }
  1891 }
  1892 
  1892 
       
  1893 /** tries to convert newly introduced news settings based on old ones
       
  1894  * @param name pointer to the string defining name of the old news config
       
  1895  * @param value pointer to the string defining value of the old news config
       
  1896  * @returns true if conversion could have been made */
       
  1897 bool ConvertOldNewsSetting(const char *name, const char *value)
       
  1898 {
       
  1899 	if (strcasecmp(name, "openclose") == 0) {
       
  1900 		/* openclose has been split in "open" and "close".
       
  1901 		 * So the job is now to decrypt the value of the old news config
       
  1902 		 * and give it to the two newly introduced ones*/
       
  1903 
       
  1904 		NewsDisplay display = ND_OFF;  //default
       
  1905 		if (strcasecmp(value, "full") == 0) {
       
  1906 			display = ND_FULL;
       
  1907 		} else if (strcasecmp(value, "summarized") == 0) {
       
  1908 			display = ND_SUMMARY;
       
  1909 		}
       
  1910 		/* tranfert of values */
       
  1911 		_news_type_data[NT_INDUSTRY_OPEN].display = display;
       
  1912 		_news_type_data[NT_INDUSTRY_CLOSE].display = display;
       
  1913 		return true;
       
  1914 	}
       
  1915 	return false;
       
  1916 }
  1893 
  1917 
  1894 static void NewsDisplayLoadConfig(IniFile *ini, const char *grpname)
  1918 static void NewsDisplayLoadConfig(IniFile *ini, const char *grpname)
  1895 {
  1919 {
  1896 	IniGroup *group = ini_getgroup(ini, grpname);
  1920 	IniGroup *group = ini_getgroup(ini, grpname);
  1897 	IniItem *item;
  1921 	IniItem *item;
  1905 			if (strcasecmp(item->name, _news_type_data[i].name) == 0) {
  1929 			if (strcasecmp(item->name, _news_type_data[i].name) == 0) {
  1906 				news_item = i;
  1930 				news_item = i;
  1907 				break;
  1931 				break;
  1908 			}
  1932 			}
  1909 		}
  1933 		}
       
  1934 
       
  1935 		/* the config been read is not within current aceptable config */
  1910 		if (news_item == -1) {
  1936 		if (news_item == -1) {
  1911 			DEBUG(misc, 0, "Invalid display option: %s", item->name);
  1937 			/* if the conversion function cannot process it, advice by a debug warning*/
       
  1938 			if (!ConvertOldNewsSetting(item->name, item->value)) {
       
  1939 				DEBUG(misc, 0, "Invalid display option: %s", item->name);
       
  1940 			}
       
  1941 			/* in all cases, there is nothing left to do */
  1912 			continue;
  1942 			continue;
  1913 		}
  1943 		}
  1914 
  1944 
  1915 		if (strcasecmp(item->value, "full") == 0) {
  1945 		if (strcasecmp(item->value, "full") == 0) {
  1916 			_news_type_data[news_item].display = ND_FULL;
  1946 			_news_type_data[news_item].display = ND_FULL;