~ubuntu-branches/ubuntu/saucy/lordsawar/saucy

« back to all changes in this revision

Viewing changes to src/Configuration.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese, Barry deFreese
  • Date: 2008-12-20 13:52:12 UTC
  • mfrom: (1.1.6 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20081220135212-noeb2w3y98ebo7o9
Tags: 0.1.4-1
[ Barry deFreese ]
* New upstream release.
* Move 0.0.8-2.1 changelog entry to correct point in changelog.
* Make lordsawar-data suggest lordsawar.
* Update my e-mail address.
* Add build-depends on intltool, uuid-dev, and libboost-dev.
* Don't install locales since there are no translations currently.
* Add simple man page for new lordsawar-pbm binary.
* Drop gcc4.3 patches as they have been fixed upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
#include "Configuration.h"
30
30
 
31
 
#include "defs.h"
32
31
#include "string_tokenizer.h"
33
32
#include "xmlhelper.h"
 
33
#include "defs.h"
34
34
 
35
35
using namespace std;
36
36
 
75
75
bool Configuration::s_random_turns = false;
76
76
bool Configuration::s_quick_start = false;
77
77
bool Configuration::s_cusp_of_war = false;
 
78
bool Configuration::s_decorated = true;
 
79
bool Configuration::s_remember_recent_games = true;
78
80
 
79
81
Configuration::Configuration()
80
82
{
97
99
    ifstream in(fileName.c_str());
98
100
    if (in)
99
101
    {
100
 
        cout << _("Found configuration file: ") << fileName << endl;
 
102
        //cout << _("Found configuration file: ") << fileName << endl;
101
103
 
102
104
        //parse the file
103
105
        XML_Helper helper(fileName.c_str(), ios::in, false);
140
142
    retval &= helper.saveData("quests", s_play_with_quests);
141
143
    retval &= helper.saveData("hidden_map", s_hidden_map);
142
144
    retval &= helper.saveData("diplomacy", s_diplomacy);
143
 
    retval &= helper.saveData("neutral_cities", (int) s_neutral_cities);
144
 
    retval &= helper.saveData("razing_cities", (int) s_razing_cities);
 
145
    std::string neutral_cities_str = neutralCitiesToString(GameParameters::NeutralCities(s_neutral_cities));
 
146
    retval &= helper.saveData("neutral_cities", neutral_cities_str);
 
147
    std::string razing_cities_str = razingCitiesToString(GameParameters::RazingCities(s_razing_cities));
 
148
    retval &= helper.saveData("razing_cities", razing_cities_str);
145
149
    retval &= helper.saveData("intense_combat", s_intense_combat);
146
150
    retval &= helper.saveData("military_advisor", s_military_advisor);
147
151
    retval &= helper.saveData("random_turns", s_random_turns);
148
152
    retval &= helper.saveData("quick_start", s_quick_start);
149
153
    retval &= helper.saveData("cusp_of_war", s_cusp_of_war);
 
154
    retval &= helper.saveData("decorated", s_decorated);
 
155
    retval &= helper.saveData("remember_recent_games", s_remember_recent_games);
150
156
    retval &= helper.closeTag();
151
157
    
152
158
    if (!retval)
153
159
    {
154
 
        std::cerr <<_("Configuration: Something went wrong while saving.\n");
 
160
        std::cerr << "Configuration: Something went wrong while saving.\n";
155
161
        return false;
156
162
    }
157
163
    
186
192
            //            string orig = string(getenv("HOME"))+s_filename;
187
193
            //            string dest = string(getenv("HOME"))+s_filename+".OLD";
188
194
            //#endif
189
 
            cerr <<_("I make a backup copy from ") << orig << " to " << dest << endl;
 
195
            cerr << "I make a backup copy from " << orig << " to " << dest << endl;
190
196
 
191
197
            ofstream ofs(dest.c_str());
192
198
            ifstream ifs(orig.c_str());
268
274
    helper->getData(s_play_with_quests, "quests");
269
275
    helper->getData(s_hidden_map, "hidden_map");
270
276
    helper->getData(s_diplomacy, "diplomacy");
271
 
    int val = -1;
272
 
    helper->getData(val, "neutral_cities");
273
 
    s_neutral_cities = GameParameters::NeutralCities (val);
274
 
    val = -1;
275
 
    helper->getData(val, "razing_cities");
276
 
    s_razing_cities = GameParameters::RazingCities (val);
 
277
    std::string neutral_cities_str;
 
278
    helper->getData(neutral_cities_str, "neutral_cities");
 
279
    s_neutral_cities = neutralCitiesFromString(neutral_cities_str);
 
280
    std::string razing_cities_str;
 
281
    helper->getData(razing_cities_str, "razing_cities");
 
282
    s_razing_cities = razingCitiesFromString(razing_cities_str);
277
283
    helper->getData(s_intense_combat, "intense_combat");
278
284
    helper->getData(s_military_advisor, "military_advisor");
279
285
    helper->getData(s_random_turns, "random_turns");
280
286
    helper->getData(s_quick_start, "quick_start");
281
287
    helper->getData(s_cusp_of_war, "cusp_of_war");
 
288
    helper->getData(s_decorated, "decorated");
 
289
    helper->getData(s_remember_recent_games, "remember_recent_games");
282
290
    return true;
283
291
}
284
292
 
292
300
        bool saveconf = conf.saveConfigurationFile(Configuration::configuration_file_path);
293
301
        if (!saveconf)
294
302
        {
295
 
            std::cerr << _("Couldn't save the new configuration file...") << std::endl;
296
 
            std::cerr << _("Check permissions of your home directory....aborting!") << std::endl;
 
303
            std::cerr << "Couldn't save the new configuration file..." << std::endl;
 
304
            std::cerr << "Check permissions of your home directory....aborting!" << std::endl;
297
305
            exit(-1);
298
306
        }
299
307
        else
300
 
            std::cerr <<_("Created the standard configuration file ") << Configuration::configuration_file_path << std::endl;
 
308
            std::cerr << "Created the standard configuration file " << Configuration::configuration_file_path << std::endl;
301
309
    }
302
310
    
303
311
#ifndef __WIN32__
310
318
        Uint32 mask = 0755; //make directory only readable for user and group
311
319
        if (mkdir(Configuration::s_savePath.c_str(), mask))
312
320
        {
313
 
            std::cerr <<_("Couldn't create save game directory ");
 
321
            std::cerr << "Couldn't create save game directory ";
314
322
            std::cerr << Configuration::s_savePath <<".\n";
315
 
            std::cerr <<_("Check permissions and the entries in your lordsawarrc file!") << std::endl;
 
323
            std::cerr << "Check permissions and the entries in your lordsawarrc file!" << std::endl;
316
324
            exit(-1);
317
325
        }
318
326
    }
319
327
#endif
320
328
}
 
329
 
 
330
std::string Configuration::neutralCitiesToString(const GameParameters::NeutralCities neutrals)
 
331
{
 
332
  switch (neutrals)
 
333
    {
 
334
      case GameParameters::AVERAGE:
 
335
        return "GameParameters::AVERAGE";
 
336
        break;
 
337
      case GameParameters::STRONG:
 
338
        return "GameParameters::STRONG";
 
339
        break;
 
340
      case GameParameters::ACTIVE:
 
341
        return "GameParameters::ACTIVE";
 
342
        break;
 
343
    }
 
344
  return "GameParameters::AVERAGE";
 
345
}
 
346
 
 
347
GameParameters::NeutralCities Configuration::neutralCitiesFromString(std::string str)
 
348
{
 
349
  if (str.size() > 0 && isdigit(str.c_str()[0]))
 
350
    return GameParameters::NeutralCities(atoi(str.c_str()));
 
351
  if (str == "GameParameters::AVERAGE")
 
352
    return GameParameters::AVERAGE;
 
353
  else if (str == "GameParameters::STRONG")
 
354
    return GameParameters::STRONG;
 
355
  else if (str == "GameParameters::ACTIVE")
 
356
    return GameParameters::ACTIVE;
 
357
    
 
358
  return GameParameters::AVERAGE;
 
359
}
 
360
 
 
361
std::string Configuration::razingCitiesToString(const GameParameters::RazingCities razing)
 
362
{
 
363
  switch (razing)
 
364
    {
 
365
      case GameParameters::NEVER:
 
366
        return "GameParameters::NEVER";
 
367
        break;
 
368
      case GameParameters::ON_CAPTURE:
 
369
        return "GameParameters::ON_CAPTURE";
 
370
        break;
 
371
      case GameParameters::ALWAYS:
 
372
        return "GameParameters::ALWAYS";
 
373
        break;
 
374
    }
 
375
  return "GameParameters::ALWAYS";
 
376
}
 
377
 
 
378
GameParameters::RazingCities Configuration::razingCitiesFromString(std::string str)
 
379
{
 
380
  if (str.size() > 0 && isdigit(str.c_str()[0]))
 
381
    return GameParameters::RazingCities(atoi(str.c_str()));
 
382
  if (str == "GameParameters::NEVER")
 
383
    return GameParameters::NEVER;
 
384
  else if (str == "GameParameters::ON_CAPTURE")
 
385
    return GameParameters::ON_CAPTURE;
 
386
  else if (str == "GameParameters::ALWAYS")
 
387
    return GameParameters::ALWAYS;
 
388
    
 
389
  return GameParameters::ALWAYS;
 
390
}