- 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:
parent
465ae629ba
commit
dec9dfe653
|
@ -1345,8 +1345,21 @@ bool Unit::morph(const MorphCommandType *mct){
|
||||||
float Unit::computeHeight(const Vec2i &pos) const{
|
float Unit::computeHeight(const Vec2i &pos) const{
|
||||||
float height= map->getCell(pos)->getHeight();
|
float height= map->getCell(pos)->getHeight();
|
||||||
|
|
||||||
if(currField==fAir){
|
if(currField == fAir) {
|
||||||
height+= World::airHeight;
|
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;
|
return height;
|
||||||
|
|
|
@ -20,10 +20,11 @@ namespace Glest{ namespace Game{
|
||||||
// class ObjectType
|
// 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);
|
models.reserve(modelCount);
|
||||||
this->objectClass= objectClass;
|
this->objectClass= objectClass;
|
||||||
this->walkable= walkable;
|
this->walkable= walkable;
|
||||||
|
this->height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectType::loadModel(const string &path){
|
void ObjectType::loadModel(const string &path){
|
||||||
|
|
|
@ -44,9 +44,10 @@ private:
|
||||||
Vec3f color;
|
Vec3f color;
|
||||||
int objectClass;
|
int objectClass;
|
||||||
bool walkable;
|
bool walkable;
|
||||||
|
int height;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void init(int modelCount, int objectClass, bool walkable);
|
void init(int modelCount, int objectClass, bool walkable, int height);
|
||||||
|
|
||||||
void loadModel(const string &path);
|
void loadModel(const string &path);
|
||||||
|
|
||||||
|
@ -55,6 +56,7 @@ public:
|
||||||
const Vec3f &getColor() const {return color;}
|
const Vec3f &getColor() const {return color;}
|
||||||
int getClass() const {return objectClass;}
|
int getClass() const {return objectClass;}
|
||||||
bool getWalkable() const {return walkable;}
|
bool getWalkable() const {return walkable;}
|
||||||
|
int getHeight() const {return height;}
|
||||||
bool isATree() const {return objectClass==tree1 || objectClass==tree2;}
|
bool isATree() const {return objectClass==tree1 || objectClass==tree2;}
|
||||||
void deletePixels();
|
void deletePixels();
|
||||||
};
|
};
|
||||||
|
|
|
@ -152,8 +152,18 @@ void Tileset::load(const string &dir, Checksum *checksum){
|
||||||
for(int i=0; i<objCount; ++i){
|
for(int i=0; i<objCount; ++i){
|
||||||
const XmlNode *objectNode= objectsNode->getChild("object", i);
|
const XmlNode *objectNode= objectsNode->getChild("object", i);
|
||||||
int childCount= objectNode->getChildCount();
|
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 XmlNode *modelNode= objectNode->getChild("model", j);
|
||||||
const XmlAttribute *pathAttribute= modelNode->getAttribute("path");
|
const XmlAttribute *pathAttribute= modelNode->getAttribute("path");
|
||||||
objectTypes[i].loadModel(dir +"/"+ pathAttribute->getRestrictedValue());
|
objectTypes[i].loadModel(dir +"/"+ pathAttribute->getRestrictedValue());
|
||||||
|
|
|
@ -106,7 +106,7 @@ public:
|
||||||
const string &getText() const {return text;}
|
const string &getText() const {return text;}
|
||||||
|
|
||||||
XmlAttribute *getAttribute(unsigned int i) const;
|
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(unsigned int i) const;
|
||||||
XmlNode *getChild(const string &childName, unsigned int childIndex=0) const;
|
XmlNode *getChild(const string &childName, unsigned int childIndex=0) const;
|
||||||
bool hasChildAtIndex(const string &childName, int childIndex=0) const;
|
bool hasChildAtIndex(const string &childName, int childIndex=0) const;
|
||||||
|
|
|
@ -241,13 +241,17 @@ XmlAttribute *XmlNode::getAttribute(unsigned int i) const{
|
||||||
return attributes[i];
|
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){
|
for(unsigned int i=0; i<attributes.size(); ++i){
|
||||||
if(attributes[i]->getName()==name){
|
if(attributes[i]->getName()==name){
|
||||||
return attributes[i];
|
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 {
|
XmlNode *XmlNode::getChild(unsigned int i) const {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user