OCONFIG.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. /*
  2. * Seven Kingdoms: Ancient Adversaries
  3. *
  4. * Copyright 1997,1998 Enlight Software Ltd.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. //Filename : OCONFIG.CPP
  21. //Description : Config Object
  22. #include <OSYS.h>
  23. #include <OHELP.h>
  24. #include <ONATION.h>
  25. #include <OUNITRES.h>
  26. #include <OFIRMRES.h>
  27. #include <OCONFIG.h>
  28. // ------- define difficult table ---------//
  29. static char table_ai_nation_count[5] = { 2, 4, 6, 6, 6 };
  30. static short table_start_up_cash[5] = { OPTION_HIGH, OPTION_HIGH, OPTION_MODERATE, OPTION_MODERATE, OPTION_LOW };
  31. static short table_ai_start_up_cash[5] = { OPTION_LOW, OPTION_MODERATE, OPTION_MODERATE, OPTION_HIGH, OPTION_VERY_HIGH };
  32. static char table_ai_aggressiveness[5] = { OPTION_LOW, OPTION_LOW, OPTION_MODERATE, OPTION_HIGH, OPTION_VERY_HIGH };
  33. static short table_start_up_independent_town[5] = { 30, 30, 15, 15, 7 };
  34. static short table_start_up_raw_site[5] = { 7, 6, 6, 4, 3, };
  35. static char table_explore_whole_map[5] = { 1, 1, 1, 1, 0 };
  36. static char table_fog_of_war[5] = { 0, 0, 0, 1, 1 };
  37. static char table_new_independent_town_emerge[5] = { 1, 1, 1, 1, 1 };
  38. static char table_independent_town_resistance[5] = { OPTION_LOW, OPTION_LOW, OPTION_MODERATE, OPTION_HIGH, OPTION_HIGH };
  39. static char table_random_event_frequency[5] = { OPTION_NONE, OPTION_LOW, OPTION_MODERATE, OPTION_MODERATE, OPTION_MODERATE };
  40. static char table_new_nation_emerge[5] = { 0, 0, 0, 1, 1 };
  41. static char table_monster_type[5] = { OPTION_MONSTER_DEFENSIVE, OPTION_MONSTER_DEFENSIVE, OPTION_MONSTER_DEFENSIVE, OPTION_MONSTER_OFFENSIVE, OPTION_MONSTER_OFFENSIVE };
  42. static char table_start_up_has_mine_nearby[5] = { 1, 1, 0, 0, 0 };
  43. static char table_random_start_up[5] = { 0, 0, 0, 1, 1 };
  44. //--------- Begin of function Config::init -----------//
  45. void Config::init()
  46. {
  47. err_when( Config::PLAYER_NAME_LEN != NationArray::HUMAN_NAME_LEN );
  48. default_game_setting();
  49. default_cheat_setting();
  50. default_local_game_setting();
  51. default_preference();
  52. }
  53. //--------- End of function Config::init --------//
  54. //--------- Begin of function Config::deinit -----------//
  55. void Config::deinit()
  56. {
  57. config.save("CONFIG.DAT"); // save the config when the game quits
  58. default_game_setting();
  59. default_local_game_setting();
  60. default_preference();
  61. }
  62. //--------- End of function Config::deinit --------//
  63. //--------- Begin of function Config::default_game_setting ---------//
  64. void Config::default_game_setting()
  65. {
  66. // -------- GLOBAL GAME SETTING -------- //
  67. ai_nation_count = 6 ;
  68. start_up_cash = OPTION_MODERATE;
  69. // start_up_food = MEDIUM_STARTUP_RESOURCE;
  70. ai_start_up_cash = OPTION_MODERATE;
  71. // ai_start_up_food = MEDIUM_STARTUP_RESOURCE;
  72. ai_aggressiveness = OPTION_MODERATE;
  73. start_up_independent_town = 15;
  74. start_up_raw_site = 6;
  75. difficulty_level = OPTION_CUSTOM;
  76. explore_whole_map = 1;
  77. fog_of_war = 0;
  78. terrain_set = 1;
  79. latitude = 45;
  80. weather_effect = 1; // damage done by weather
  81. land_mass = OPTION_MODERATE;
  82. new_independent_town_emerge = 1;
  83. independent_town_resistance = OPTION_MODERATE;
  84. random_event_frequency = OPTION_NONE;
  85. monster_type = OPTION_MONSTER_DEFENSIVE;
  86. new_nation_emerge = 1;
  87. start_up_has_mine_nearby = 0;
  88. random_start_up = 0;
  89. change_difficulty(OPTION_VERY_EASY);
  90. //-------- goal --------//
  91. goal_destroy_monster = 0;
  92. goal_population_flag = 0;
  93. goal_economic_score_flag = 0;
  94. goal_total_score_flag = 0;
  95. goal_year_limit_flag = 0;
  96. goal_population = 300;
  97. goal_economic_score = 300;
  98. goal_total_score = 600;
  99. goal_year_limit = 20;
  100. // game setting on fire
  101. fire_spread_rate = 0; // 0 to disable, 10 for normal
  102. wind_spread_fire_rate = 5; // 0 to disable, 5 for normal
  103. fire_fade_rate = 2; // 1 for slow, 2 for fast
  104. fire_restore_prob = 80; // 0 to 100, 5 for normal (with spreading)
  105. rain_reduce_fire_rate = 5; // 0 to 20, 5 for normal
  106. fire_damage = 2; // 0 to disable 2 for normal
  107. }
  108. //--------- End of function Config::default_game_setting ---------//
  109. //--------- Begin of function Config::default_game_setting ---------//
  110. void Config::default_cheat_setting()
  111. {
  112. show_ai_info = sys.debug_session;
  113. fast_build = sys.debug_session;
  114. disable_ai_flag = 0;
  115. king_undie_flag = sys.testing_session;
  116. }
  117. //--------- End of function Config::default_game_setting ---------//
  118. //--------- Begin of function Config::default_local_game_setting ---------//
  119. void Config::default_local_game_setting()
  120. {
  121. race_id = 1;
  122. #if(defined(SPANISH))
  123. strcpy(player_name, "Nuevo Jugador");
  124. #elif(defined(FRENCH))
  125. strcpy(player_name, "Nouveau Joueur");
  126. #elif(defined(GERMAN))
  127. strcpy(player_name, "Neuer Spieler");
  128. #else
  129. strcpy(player_name, "New Player");
  130. #endif
  131. player_nation_color = 1;
  132. expired_flag = 0;
  133. }
  134. //--------- End of function Config::default_local_game_setting ---------//
  135. //--------- Begin of function Config::default_preference ---------//
  136. void Config::default_preference()
  137. {
  138. opaque_report = 0; // opaque report instead of transparent report
  139. disp_news_flag = OPTION_DISPLAY_ALL_NEWS;
  140. scroll_speed = 5;
  141. frame_speed = 12;
  142. help_mode = DETAIL_HELP;
  143. disp_town_name = 1;
  144. disp_spy_sign = 1;
  145. show_all_unit_icon = 1; // 0:show icon when pointed, 1:always
  146. show_unit_path = 3; // bit 0 show unit path on ZoomMatrix, bit 1 for MapMatrix
  147. // music setting
  148. music_flag = 1;
  149. cd_music_volume = 100;
  150. wav_music_volume = 100;
  151. // sound effect setting
  152. sound_effect_flag = 1;
  153. sound_effect_volume = 100;
  154. pan_control = 1;
  155. // weather visual effect flags
  156. lightning_visual = 1;
  157. earthquake_visual = 1;
  158. rain_visual = 1;
  159. snow_visual = 1;
  160. snow_ground = 0; // 0=disable, 1=i_snow, 2=snow_res
  161. // weather audio effect flags
  162. lightning_audio = 1;
  163. earthquake_audio = 1;
  164. rain_audio = 1;
  165. snow_audio = 0; // not used
  166. wind_audio = 1;
  167. // weather visual effect parameters
  168. lightning_brightness = 20;
  169. cloud_darkness = 5;
  170. // weather audio effect parameters
  171. lightning_volume = 100;
  172. earthquake_volume = 100;
  173. rain_volume = 90;
  174. snow_volume = 100;
  175. wind_volume = 70;
  176. // other
  177. blacken_map = 1;
  178. explore_mask_method = 2;
  179. fog_mask_method = 2;
  180. enable_weather_visual();
  181. enable_weather_audio();
  182. cloud_darkness = 0;
  183. }
  184. //--------- End of function Config::default_preference ---------//
  185. //--------- Begin of function Config::change_game_setting --------//
  186. // for synchronize the game setting with the host before a multiplayer game
  187. void Config::change_game_setting( Config &c )
  188. {
  189. //-------- game settings ---------//
  190. ai_nation_count = c.ai_nation_count;
  191. start_up_cash = c.start_up_cash;
  192. // start_up_food = c.start_up_food;
  193. ai_start_up_cash = c.ai_start_up_cash;
  194. // ai_start_up_food = c.ai_start_up_food;
  195. ai_aggressiveness = c.ai_aggressiveness;
  196. start_up_independent_town = c.start_up_independent_town;
  197. start_up_raw_site = c.start_up_raw_site;
  198. difficulty_level = c.difficulty_level;
  199. explore_whole_map = c.explore_whole_map;
  200. fog_of_war = c.fog_of_war;
  201. terrain_set = c.terrain_set;
  202. latitude = c.latitude;
  203. weather_effect = c.weather_effect;
  204. land_mass = c.land_mass;
  205. new_independent_town_emerge = c.new_independent_town_emerge;
  206. independent_town_resistance = c.independent_town_resistance;
  207. random_event_frequency = c.random_event_frequency;
  208. monster_type = c.monster_type;
  209. new_nation_emerge = c.new_nation_emerge;
  210. start_up_has_mine_nearby = c.start_up_has_mine_nearby;
  211. random_start_up = c.random_start_up;
  212. // --------- goal ---------//
  213. goal_destroy_monster = c.goal_destroy_monster;
  214. goal_population_flag = c.goal_population_flag;
  215. goal_economic_score_flag = c.goal_economic_score_flag;
  216. goal_total_score_flag = c.goal_total_score_flag;
  217. goal_year_limit_flag = c.goal_year_limit_flag;
  218. goal_population = c.goal_population;
  219. goal_economic_score = c.goal_economic_score;
  220. goal_total_score = c.goal_total_score;
  221. goal_year_limit = c.goal_year_limit;
  222. // ------- game setting on fire ---------//
  223. fire_spread_rate = c.fire_spread_rate;
  224. wind_spread_fire_rate = c.wind_spread_fire_rate;
  225. fire_fade_rate = c.fire_fade_rate;
  226. fire_restore_prob = c.fire_restore_prob;
  227. rain_reduce_fire_rate = c.rain_reduce_fire_rate;
  228. fire_damage = c.fire_damage;
  229. }
  230. //--------- End of function Config::change_game_setting --------//
  231. //--------- Begin of function Config::change_game_setting --------//
  232. // for saving config after changing option
  233. void Config::change_preference( Config &c )
  234. {
  235. opaque_report = c.opaque_report;
  236. disp_news_flag = c.disp_news_flag;
  237. scroll_speed = c.scroll_speed;
  238. frame_speed = c.frame_speed;
  239. help_mode = c.help_mode;
  240. disp_town_name = c.disp_town_name;
  241. disp_spy_sign = c.disp_spy_sign;
  242. show_all_unit_icon = c.show_all_unit_icon;
  243. show_unit_path = c.show_unit_path;
  244. //------- sound effect --------//
  245. music_flag = c.music_flag;
  246. cd_music_volume = c.cd_music_volume;
  247. wav_music_volume = c.wav_music_volume;
  248. sound_effect_flag = c.sound_effect_flag;
  249. sound_effect_volume = c.sound_effect_volume;
  250. pan_control = c.pan_control;
  251. //------- weather visual effect flags -------//
  252. lightning_visual = c.lightning_visual;
  253. earthquake_visual = c.earthquake_visual;
  254. rain_visual = c.rain_visual;
  255. snow_visual = c.snow_visual;
  256. snow_ground = c.snow_ground;
  257. //-------- weather audio effect flags -------//
  258. lightning_audio = c.lightning_audio;
  259. earthquake_audio = c.earthquake_audio;
  260. rain_audio = c.rain_audio;
  261. snow_audio = c.snow_audio;
  262. wind_audio = c.wind_audio;
  263. //--------- weather visual effect parameters --------//
  264. lightning_brightness = c.lightning_brightness;
  265. cloud_darkness = c.cloud_darkness;
  266. //-------- weather audio effect parameters ----------//
  267. lightning_volume = c.lightning_volume;
  268. earthquake_volume = c.earthquake_volume;
  269. rain_volume = c.rain_volume;
  270. snow_volume = c.snow_volume;
  271. wind_volume = c.wind_volume;
  272. //------------ map prefernce -------------//
  273. blacken_map = c.blacken_map;
  274. explore_mask_method = c.explore_mask_method;
  275. fog_mask_method = c.fog_mask_method;
  276. }
  277. //--------- Begin of function Config::enable_weather_visual --------//
  278. void Config::enable_weather_visual()
  279. {
  280. lightning_visual = 1;
  281. earthquake_visual = 1;
  282. rain_visual = 1;
  283. snow_visual = 1;
  284. snow_ground = 0; // 0=disable, 1=i_snow, 2=snow_res
  285. cloud_darkness = 1;
  286. }
  287. //--------- End of function Config::enable_weather_visual --------//
  288. //--------- Begin of function Config::disable_weather_visual --------//
  289. void Config::disable_weather_visual()
  290. {
  291. lightning_visual = 0;
  292. earthquake_visual = 0;
  293. rain_visual = 0;
  294. snow_visual = 0;
  295. snow_ground = 0; // 0=disable, 1=i_snow, 2=snow_res
  296. cloud_darkness = 0;
  297. }
  298. //--------- End of function Config::disable_weather_visual --------//
  299. //--------- Begin of function Config::enable_weather_audio --------//
  300. void Config::enable_weather_audio()
  301. {
  302. lightning_audio = 1;
  303. earthquake_audio = 1;
  304. rain_audio = 1;
  305. snow_audio = 1; // not used
  306. wind_audio = 1;
  307. }
  308. //--------- End of function Config::enable_weather_audio --------//
  309. //--------- Begin of function Config::disable_weather_audio --------//
  310. void Config::disable_weather_audio()
  311. {
  312. lightning_audio = 0;
  313. earthquake_audio = 0;
  314. rain_audio = 0;
  315. snow_audio = 0; // not used
  316. wind_audio = 0;
  317. }
  318. //--------- End of function Config::disable_weather_audio --------//
  319. //--------- Begin of function Config::save -------------//
  320. int Config::save(char *filename)
  321. {
  322. File configFile;
  323. if( !configFile.file_create(filename) )
  324. return 0;
  325. int retFlag = write_file(&configFile);
  326. configFile.file_close();
  327. return retFlag;
  328. }
  329. //--------- End of function Config::save -------------//
  330. //--------- Begin of function Config::load -------------//
  331. //
  332. // if load() fails, call init to re-initialize it
  333. //
  334. int Config::load(char *filename)
  335. {
  336. File configFile;
  337. if( !m.is_file_exist(filename) || !configFile.file_open(filename) )
  338. return 0;
  339. int retFlag = 0;
  340. // check file size is the same
  341. if( configFile.file_size() == sizeof(Config) )
  342. {
  343. retFlag = read_file(&configFile);
  344. }
  345. configFile.file_close();
  346. return retFlag;
  347. }
  348. //--------- End of function Config::load -------------//
  349. //--------- Begin of function Config::reset_game_setting ---------//
  350. void Config::reset_cheat_setting()
  351. {
  352. show_ai_info = 0;
  353. fast_build = 0;
  354. disable_ai_flag = 0;
  355. king_undie_flag = 0;
  356. }
  357. //--------- End of function Config::reset_game_setting ---------//
  358. //------- Begin of function Config::single_player_difficulty --------//
  359. int Config::single_player_difficulty()
  360. {
  361. int score = 10;
  362. score += ai_nation_count * 6;
  363. if( !explore_whole_map)
  364. score += 7;
  365. if( fog_of_war )
  366. score += 7;
  367. score += (7 - start_up_raw_site) * 5;
  368. // if( start_up_cash <= SMALL_STARTUP_RESOURCE )
  369. // score += 16;
  370. // else if( start_up_cash < LARGE_STARTUP_RESOURCE )
  371. // score += 8;
  372. // else
  373. // score += 0;
  374. score += (4 - start_up_cash) * 6;
  375. // if( ai_start_up_cash <= SMALL_STARTUP_RESOURCE )
  376. // score += 0;
  377. // else if( ai_start_up_cash < LARGE_STARTUP_RESOURCE )
  378. // score += 8;
  379. // else
  380. // score += 16;
  381. score += (ai_start_up_cash - 1 ) * 6;
  382. score += (ai_aggressiveness -1) * 10;
  383. score += (independent_town_resistance -1) * 5;
  384. if( new_nation_emerge )
  385. score += 6;
  386. score += random_event_frequency * 2;
  387. switch( monster_type )
  388. {
  389. case OPTION_MONSTER_NONE:
  390. break;
  391. case OPTION_MONSTER_DEFENSIVE:
  392. score += 6;
  393. break;
  394. case OPTION_MONSTER_OFFENSIVE:
  395. score += 16;
  396. break;
  397. default:
  398. err_here();
  399. }
  400. if( !start_up_has_mine_nearby )
  401. score += 6;
  402. return score;
  403. }
  404. //------- End of function Config::single_player_difficulty --------//
  405. //------- Begin of function Config::multi_player_difficulty --------//
  406. int Config::multi_player_difficulty(int remotePlayers)
  407. {
  408. short totalOpp = ai_nation_count + remotePlayers;
  409. if( totalOpp > MAX_NATION-1 )
  410. totalOpp = MAX_NATION-1;
  411. return single_player_difficulty() + (totalOpp - ai_nation_count) * 6;
  412. }
  413. //------- End of function Config::multi_player_difficulty --------//
  414. //------- Begin of function Config::multi_player_difficulty --------//
  415. void Config::change_difficulty(int difficulty)
  416. {
  417. err_when( difficulty < OPTION_VERY_EASY || difficulty > OPTION_VERY_HARD );
  418. difficulty_level = difficulty;
  419. ai_nation_count = table_ai_nation_count[difficulty];
  420. start_up_cash = table_start_up_cash[difficulty];
  421. // start_up_food = table_start_up_food[difficulty];
  422. ai_start_up_cash = table_ai_start_up_cash[difficulty];
  423. // ai_start_up_food = table_ai_start_up_food[difficulty];
  424. ai_aggressiveness = table_ai_aggressiveness[difficulty];
  425. start_up_independent_town = table_start_up_independent_town[difficulty];
  426. start_up_raw_site = table_start_up_raw_site[difficulty];
  427. explore_whole_map = table_explore_whole_map[difficulty];
  428. fog_of_war = table_fog_of_war[difficulty];
  429. new_independent_town_emerge = table_new_independent_town_emerge[difficulty];
  430. independent_town_resistance = table_independent_town_resistance[difficulty];
  431. random_event_frequency = table_random_event_frequency[difficulty];
  432. new_nation_emerge = table_new_nation_emerge[difficulty];
  433. monster_type = table_monster_type[difficulty];
  434. start_up_has_mine_nearby = table_start_up_has_mine_nearby[difficulty];
  435. random_start_up = table_random_start_up[difficulty];
  436. }
  437. //------- End of function Config::change_difficulty --------//