diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-08-07 01:25:14 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-08-07 01:25:14 +0300 |
commit | 1740b281aa32ba2c30a2a6203f7748af6a21fd39 (patch) | |
tree | 2cc63714431f7ddebb5af57e71926cde419be4b5 /src/resources | |
parent | 2b6564dcd936825853727fa256e5da7f84f933da (diff) | |
download | plus-1740b281aa32ba2c30a2a6203f7748af6a21fd39.tar.gz plus-1740b281aa32ba2c30a2a6203f7748af6a21fd39.tar.bz2 plus-1740b281aa32ba2c30a2a6203f7748af6a21fd39.tar.xz plus-1740b281aa32ba2c30a2a6203f7748af6a21fd39.zip |
Extend horses.xml with separate offset for each direction for rider, up and down sprites.
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/db/horsedb.cpp | 127 | ||||
-rw-r--r-- | src/resources/horseinfo.h | 28 | ||||
-rw-r--r-- | src/resources/horseoffset.h | 47 |
3 files changed, 163 insertions, 39 deletions
diff --git a/src/resources/db/horsedb.cpp b/src/resources/db/horsedb.cpp index 0784a1e75..cdcc9ef3b 100644 --- a/src/resources/db/horsedb.cpp +++ b/src/resources/db/horsedb.cpp @@ -23,6 +23,8 @@ #include "configuration.h" +#include "enums/resources/spritedirection.h" + #include "resources/beingcommon.h" #include "resources/horseinfo.h" @@ -71,11 +73,6 @@ void HorseDB::load() currentSprite->variant = 0; mUnknown.upSprites.push_back(currentSprite); - mUnknown.upOffsetX = 0; - mUnknown.upOffsetY = 0; - mUnknown.downOffsetX = 0; - mUnknown.downOffsetY = 0; - logger->log1("Initializing horse database..."); loadXmlFile(paths.getStringValue("horsesFile"), SkipError_false); @@ -85,6 +82,69 @@ void HorseDB::load() mLoaded = true; } +static int parseDirectionName(const std::string &name) +{ + int id = -1; + if (name == "down") + { + id = SpriteDirection::DOWN; + } + else if (name == "downleft" || name == "leftdown") + { + id = SpriteDirection::DOWNLEFT; + } + else if (name == "left") + { + id = SpriteDirection::LEFT; + } + else if (name == "upleft" || name == "leftup") + { + id = SpriteDirection::UPLEFT; + } + else if (name == "up") + { + id = SpriteDirection::UP; + } + else if (name == "upright" || name == "rightup") + { + id = SpriteDirection::UPRIGHT; + } + else if (name == "right") + { + id = SpriteDirection::RIGHT; + } + else if (name == "downright" || name == "rightdown") + { + id = SpriteDirection::DOWNRIGHT; + } + // hack for died action. + else if (name == "died") + { + id = 9; + } + + return id; +} + +static void loadRiderOffset(XmlNodePtrConst node, + HorseInfo *const currentInfo) +{ + const std::string dirName = XML::getProperty(node, + "direction", ""); + const int dir = parseDirectionName(dirName); + if (dir == -1) + { + reportAlways("Wrong or missing horse rider direcion: %s", + dirName.c_str()); + return; + } + HorseOffset &offset = currentInfo->offsets[dir]; + offset.riderOffsetX = XML::getProperty(node, + "riderOffsetX", 0); + offset.riderOffsetY = XML::getProperty(node, + "riderOffsetY", 0); +} + void HorseDB::loadXmlFile(const std::string &fileName, const SkipError skipError) { @@ -131,44 +191,58 @@ void HorseDB::loadXmlFile(const std::string &fileName, if (!currentInfo) continue; - currentInfo->upOffsetX = XML::getProperty(horseNode, - "upOffsetX", 0); - currentInfo->upOffsetY = XML::getProperty(horseNode, - "upOffsetY", 0); - currentInfo->downOffsetX = XML::getProperty(horseNode, - "downOffsetX", 0); - currentInfo->downOffsetY = XML::getProperty(horseNode, - "downOffsetY", 0); - currentInfo->riderOffsetX = XML::getProperty(horseNode, - "riderOffsetX", 0); - currentInfo->riderOffsetY = XML::getProperty(horseNode, - "riderOffsetY", 0); - for_each_xml_child_node(spriteNode, horseNode) { - if (!XmlHaveChildContent(spriteNode)) - continue; - - if (xmlNameEqual(spriteNode, "sprite")) - loadSprite(downSprites) - if (xmlNameEqual(spriteNode, "down")) loadDownSprites(spriteNode, currentInfo); else if (xmlNameEqual(spriteNode, "up")) loadUpSprites(spriteNode, currentInfo); + else if (xmlNameEqual(spriteNode, "offset")) + loadRiderOffset(spriteNode, currentInfo); } mHorseInfos[id] = currentInfo; } } +static void loadOffset(XmlNodePtrConst node, + HorseInfo *const currentInfo, + const bool isUp) +{ + const std::string dirName = XML::getProperty(node, + "direction", ""); + const int dir = parseDirectionName(dirName); + if (dir == -1) + { + reportAlways("Wrong or missing horse direcion: %s", + dirName.c_str()); + return; + } + HorseOffset &offset = currentInfo->offsets[dir]; + if (isUp) + { + offset.upOffsetX = XML::getProperty(node, + "horseOffsetX", 0); + offset.upOffsetY = XML::getProperty(node, + "horseOffsetY", 0); + } + else + { + offset.downOffsetX = XML::getProperty(node, + "horseOffsetX", 0); + offset.downOffsetY = XML::getProperty(node, + "horseOffsetY", 0); + } +} + static void loadDownSprites(XmlNodePtrConst parentNode, HorseInfo *const currentInfo) { for_each_xml_child_node(spriteNode, parentNode) { + if (xmlNameEqual(spriteNode, "offset")) + loadOffset(spriteNode, currentInfo, false); if (!XmlHaveChildContent(spriteNode)) continue; - if (xmlNameEqual(spriteNode, "sprite")) loadSprite(downSprites) } @@ -179,9 +253,10 @@ static void loadUpSprites(XmlNodePtrConst parentNode, { for_each_xml_child_node(spriteNode, parentNode) { + if (xmlNameEqual(spriteNode, "offset")) + loadOffset(spriteNode, currentInfo, true); if (!XmlHaveChildContent(spriteNode)) continue; - if (xmlNameEqual(spriteNode, "sprite")) loadSprite(upSprites) } diff --git a/src/resources/horseinfo.h b/src/resources/horseinfo.h index 4ff1dfb09..97bcdcc6f 100644 --- a/src/resources/horseinfo.h +++ b/src/resources/horseinfo.h @@ -24,6 +24,8 @@ #include "resources/sprite/spritereference.h" +#include "resources/horseoffset.h" + #include "localconsts.h" struct HorseInfo final @@ -31,24 +33,24 @@ struct HorseInfo final HorseInfo() : downSprites(), upSprites(), - downOffsetX(0), - downOffsetY(0), - upOffsetX(0), - upOffsetY(0), - riderOffsetX(0), - riderOffsetY(0) - { } + offsets() + { + for (int f = 0; f < 10; f ++) + { + offsets[f].upOffsetX = 0; + offsets[f].upOffsetY = 0; + offsets[f].downOffsetX = 0; + offsets[f].downOffsetY = 0; + offsets[f].riderOffsetX = 0; + offsets[f].riderOffsetY = 0; + } + } A_DELETE_COPY(HorseInfo) std::vector<SpriteReference*> downSprites; std::vector<SpriteReference*> upSprites; - int downOffsetX; - int downOffsetY; - int upOffsetX; - int upOffsetY; - int riderOffsetX; - int riderOffsetY; + HorseOffset offsets[10]; // by direction }; #endif // RESOURCES_HORSEINFO_H diff --git a/src/resources/horseoffset.h b/src/resources/horseoffset.h new file mode 100644 index 000000000..be7a3e76b --- /dev/null +++ b/src/resources/horseoffset.h @@ -0,0 +1,47 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2016 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef RESOURCES_HORSEOFFSET_H +#define RESOURCES_HORSEOFFSET_H + +#include "localconsts.h" + +struct HorseOffset final +{ + HorseOffset() : + upOffsetX(0), + upOffsetY(0), + downOffsetX(0), + downOffsetY(0), + riderOffsetX(0), + riderOffsetY(0) + { } + + A_DELETE_COPY(HorseOffset) + + int upOffsetX; + int upOffsetY; + int downOffsetX; + int downOffsetY; + int riderOffsetX; + int riderOffsetY; +}; + +#endif // RESOURCES_HORSEOFFSET_H |