diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 45b7e9c0..05bb88e0 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -1345,8 +1345,21 @@ bool Unit::morph(const MorphCommandType *mct){ float Unit::computeHeight(const Vec2i &pos) const{ float height= map->getCell(pos)->getHeight(); - if(currField==fAir){ - height+= World::airHeight; + if(currField == fAir) { + height += World::airHeight; + + Unit *unit = map->getCell(pos)->getUnit(fLand); + if(unit != NULL && unit->getType()->getHeight() > World::airHeight) { + height += (std::min((float)unit->getType()->getHeight(),World::airHeight * 3) - World::airHeight); + } + else { + SurfaceCell *sc = map->getSurfaceCell(map->toSurfCoords(pos)); + if(sc != NULL && sc->getObject() != NULL && sc->getObject()->getType() != NULL) { + if(sc->getObject()->getType()->getHeight() > World::airHeight) { + height += (std::min((float)sc->getObject()->getType()->getHeight(),World::airHeight * 3) - World::airHeight); + } + } + } } return height; diff --git a/source/glest_game/types/object_type.cpp b/source/glest_game/types/object_type.cpp index 4b1ddc73..aa9bfd48 100644 --- a/source/glest_game/types/object_type.cpp +++ b/source/glest_game/types/object_type.cpp @@ -20,10 +20,11 @@ namespace Glest{ namespace Game{ // class ObjectType // ===================================================== -void ObjectType::init(int modelCount, int objectClass, bool walkable){ +void ObjectType::init(int modelCount, int objectClass, bool walkable, int height) { models.reserve(modelCount); this->objectClass= objectClass; this->walkable= walkable; + this->height = height; } void ObjectType::loadModel(const string &path){ diff --git a/source/glest_game/types/object_type.h b/source/glest_game/types/object_type.h index 2bfd003b..74f01834 100644 --- a/source/glest_game/types/object_type.h +++ b/source/glest_game/types/object_type.h @@ -44,9 +44,10 @@ private: Vec3f color; int objectClass; bool walkable; + int height; public: - void init(int modelCount, int objectClass, bool walkable); + void init(int modelCount, int objectClass, bool walkable, int height); void loadModel(const string &path); @@ -55,6 +56,7 @@ public: const Vec3f &getColor() const {return color;} int getClass() const {return objectClass;} bool getWalkable() const {return walkable;} + int getHeight() const {return height;} bool isATree() const {return objectClass==tree1 || objectClass==tree2;} void deletePixels(); }; diff --git a/source/glest_game/world/tileset.cpp b/source/glest_game/world/tileset.cpp index 398e335b..e42c5ae4 100644 --- a/source/glest_game/world/tileset.cpp +++ b/source/glest_game/world/tileset.cpp @@ -152,8 +152,18 @@ void Tileset::load(const string &dir, Checksum *checksum){ for(int i=0; igetChild("object", i); int childCount= objectNode->getChildCount(); - objectTypes[i].init(childCount, i, objectNode->getAttribute("walkable")->getBoolValue()); - for(int j=0; jgetAttribute("walkable")->getBoolValue(); + if(walkable == false) { + const XmlAttribute *heightAttribute = objectNode->getAttribute("height",false); + if(heightAttribute != NULL) { + objectHeight = heightAttribute->getIntValue(); + } + } + + objectTypes[i].init(childCount, i, walkable,objectHeight); + for(int j=0; jgetChild("model", j); const XmlAttribute *pathAttribute= modelNode->getAttribute("path"); objectTypes[i].loadModel(dir +"/"+ pathAttribute->getRestrictedValue()); diff --git a/source/shared_lib/include/xml/xml_parser.h b/source/shared_lib/include/xml/xml_parser.h index 7dd962dd..4b4006fc 100644 --- a/source/shared_lib/include/xml/xml_parser.h +++ b/source/shared_lib/include/xml/xml_parser.h @@ -106,7 +106,7 @@ public: const string &getText() const {return text;} XmlAttribute *getAttribute(unsigned int i) const; - XmlAttribute *getAttribute(const string &name) const; + XmlAttribute *getAttribute(const string &name,bool mustExist=true) const; XmlNode *getChild(unsigned int i) const; XmlNode *getChild(const string &childName, unsigned int childIndex=0) const; bool hasChildAtIndex(const string &childName, int childIndex=0) const; diff --git a/source/shared_lib/sources/xml/xml_parser.cpp b/source/shared_lib/sources/xml/xml_parser.cpp index 0094b129..66014c7d 100644 --- a/source/shared_lib/sources/xml/xml_parser.cpp +++ b/source/shared_lib/sources/xml/xml_parser.cpp @@ -241,13 +241,17 @@ XmlAttribute *XmlNode::getAttribute(unsigned int i) const{ return attributes[i]; } -XmlAttribute *XmlNode::getAttribute(const string &name) const{ +XmlAttribute *XmlNode::getAttribute(const string &name,bool mustExist) const { for(unsigned int i=0; igetName()==name){ return attributes[i]; } } - throw runtime_error("\"" + getName() + "\" node doesn't have a attribute named \"" + name + "\""); + if(mustExist == true) { + throw runtime_error("\"" + getName() + "\" node doesn't have a attribute named \"" + name + "\""); + } + + return NULL; } XmlNode *XmlNode::getChild(unsigned int i) const {