- added new attribute for tileset objects named "height". Air units will try to fly above the height of units and objects now (up to a max of terrain height + 15)

This commit is contained in:
Mark Vejvoda 2010-10-30 04:05:48 +00:00
parent 465ae629ba
commit dec9dfe653
6 changed files with 39 additions and 9 deletions

View File

@ -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;

View File

@ -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){

View File

@ -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();
};

View File

@ -152,8 +152,18 @@ void Tileset::load(const string &dir, Checksum *checksum){
for(int i=0; i<objCount; ++i){
const XmlNode *objectNode= objectsNode->getChild("object", i);
int childCount= objectNode->getChildCount();
objectTypes[i].init(childCount, i, objectNode->getAttribute("walkable")->getBoolValue());
for(int j=0; j<childCount; ++j){
int objectHeight = 0;
bool walkable = objectNode->getAttribute("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; j<childCount; ++j) {
const XmlNode *modelNode= objectNode->getChild("model", j);
const XmlAttribute *pathAttribute= modelNode->getAttribute("path");
objectTypes[i].loadModel(dir +"/"+ pathAttribute->getRestrictedValue());

View File

@ -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;

View File

@ -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; i<attributes.size(); ++i){
if(attributes[i]->getName()==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 {