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

« back to all changes in this revision

Viewing changes to src/bridge.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:
18
18
#include "bridge.h"
19
19
#include "GameMap.h"
20
20
 
 
21
std::string Bridge::d_tag = "bridge";
 
22
 
21
23
Bridge::Bridge(Vector<int> pos, int type)
22
24
  :Location(pos), d_type(type)
23
25
{
28
30
Bridge::Bridge(XML_Helper* helper)
29
31
    :Location(helper)
30
32
{
31
 
    //mark the location on the game map as occupied by a bridge
32
 
    helper->getData(d_type, "type");
33
 
    GameMap::getInstance()->getTile(getPos())->setBuilding(Maptile::BRIDGE);
 
33
  std::string type_str;
 
34
  helper->getData(type_str, "type");
 
35
  d_type = bridgeTypeFromString(type_str);
 
36
    
 
37
  //mark the location on the game map as occupied by a bridge
 
38
  GameMap::getInstance()->getTile(getPos())->setBuilding(Maptile::BRIDGE);
34
39
}
35
40
 
36
41
Bridge::Bridge(const Bridge& s)
46
51
{
47
52
    bool retval = true;
48
53
 
49
 
    retval &= helper->openTag("bridge");
 
54
    retval &= helper->openTag(Bridge::d_tag);
50
55
    retval &= helper->saveData("id", d_id);
51
56
    retval &= helper->saveData("x", getPos().x);
52
57
    retval &= helper->saveData("y", getPos().y);
53
 
    retval &= helper->saveData("type", d_type);
 
58
    std::string type_str = bridgeTypeToString(Bridge::Type(d_type));
 
59
    retval &= helper->saveData("type", type_str);
54
60
    retval &= helper->closeTag();
55
61
    
56
62
    return retval;
57
63
}
 
64
 
 
65
std::string Bridge::bridgeTypeToString(const Bridge::Type type)
 
66
{
 
67
  switch (type)
 
68
    {
 
69
    case Bridge::CONNECTS_TO_EAST:
 
70
      return "Bridge::CONNECTS_TO_EAST";
 
71
    case Bridge::CONNECTS_TO_NORTH:
 
72
      return "Bridge::CONNECTS_TO_NORTH";
 
73
    case Bridge::CONNECTS_TO_WEST:
 
74
      return "Bridge::CONNECTS_TO_WEST";
 
75
    case Bridge::CONNECTS_TO_SOUTH:
 
76
      return "Bridge::CONNECTS_TO_SOUTH";
 
77
    }
 
78
  return "Bridge::CONNECTS_TO_EAST";
 
79
}
 
80
 
 
81
Bridge::Type Bridge::bridgeTypeFromString(const std::string str)
 
82
{
 
83
  if (str.size() > 0 && isdigit(str.c_str()[0]))
 
84
    return Bridge::Type(atoi(str.c_str()));
 
85
  if (str == "Bridge::CONNECTS_TO_EAST")
 
86
    return Bridge::CONNECTS_TO_EAST;
 
87
  else if (str == "Bridge::CONNECTS_TO_NORTH")
 
88
    return Bridge::CONNECTS_TO_NORTH;
 
89
  else if (str == "Bridge::CONNECTS_TO_WEST")
 
90
    return Bridge::CONNECTS_TO_WEST;
 
91
  else if (str == "Bridge::CONNECTS_TO_SOUTH")
 
92
    return Bridge::CONNECTS_TO_SOUTH;
 
93
  return Bridge::CONNECTS_TO_EAST;
 
94
}