ManaPlus
Namespaces | Macros | Functions | Variables
itemdb.cpp File Reference

(986a3bf)

#include "resources/db/itemdb.h"
#include "const/resources/map/map.h"
#include "configuration.h"
#include "enums/resources/spritedirection.h"
#include "fs/virtfs/tools.h"
#include "resources/iteminfo.h"
#include "resources/itemmenuitem.h"
#include "resources/itemtypemapdata.h"
#include "resources/db/itemfielddb.h"
#include "resources/sprite/spritereference.h"
#include "net/net.h"
#include "utils/checkutils.h"
#include "utils/delete2.h"
#include "utils/dtor.h"
#include "utils/foreach.h"
#include "utils/itemxmlutils.h"
#include "utils/stdmove.h"
#include "utils/stringmap.h"
#include "debug.h"

Go to the source code of this file.

Namespaces

 anonymous_namespace{itemdb.cpp}
 

Macros

#define CHECK_PARAM(param)
 

Functions

static void loadSpriteRef (ItemInfo *const itemInfo, const xmlNodePtr node)
 
static void loadSoundRef (ItemInfo *const itemInfo, const xmlNodePtr node)
 
static void loadFloorSprite (SpriteDisplay &display, const xmlNode *const node)
 
static void loadReplaceSprite (ItemInfo *const itemInfo, const xmlNodePtr replaceNode)
 
static void loadOrderSprite (ItemInfo *const itemInfo, const xmlNodePtr node, const bool drawAfter)
 
static int parseSpriteName (const std::string &name)
 
static int parseDirectionName (const std::string &name)
 
static ItemDbTypeT itemTypeFromString (const std::string &name)
 
static std::string useButtonFromItemType (const ItemDbTypeT &type)
 
static std::string useButton2FromItemType (const ItemDbTypeT &type)
 
static void initStatic ()
 
static void loadMenu (xmlNode *const parentNode, std::vector< ItemMenuItem > &menu)
 
static bool getIsEquipment (const ItemDbTypeT type)
 

Variables

ItemDB::ItemInfos anonymous_namespace{itemdb.cpp}::mItemInfos
 
ItemDB::NamedItemInfos anonymous_namespace{itemdb.cpp}::mNamedItemInfos
 
ItemInfoanonymous_namespace{itemdb.cpp}::mUnknown = 0
 
bool anonymous_namespace{itemdb.cpp}::mLoaded = false
 
bool anonymous_namespace{itemdb.cpp}::mConstructed = false
 
StringVect anonymous_namespace{itemdb.cpp}::mTagNames
 
StringIntMap anonymous_namespace{itemdb.cpp}::mTags
 
std::map< std::string, ItemSoundEvent::Typeanonymous_namespace{itemdb.cpp}::mSoundNames
 
int anonymous_namespace{itemdb.cpp}::mNumberOfHairstyles = 1
 

Macro Definition Documentation

◆ CHECK_PARAM

#define CHECK_PARAM (   param)
Value:
if (param.empty()) \
{ \
logger->log("ItemDB: Missing " #param " attribute for item %i!", \
id); \
}

Function Documentation

◆ getIsEquipment()

static bool getIsEquipment ( const ItemDbTypeT  type)
static

Definition at line 235 of file itemdb.cpp.

236 {
237  switch (type)
238  {
251  return true;
253  case ItemDbType::USABLE:
254  case ItemDbType::CARD:
257  default:
258  return false;
259  }
260 }
@ EQUIPMENT_HEAD
Definition: itemdbtype.h:38
@ EQUIPMENT_RING
Definition: itemdbtype.h:41
@ EQUIPMENT_LEGS
Definition: itemdbtype.h:39
@ EQUIPMENT_TWO_HANDS_WEAPON
Definition: itemdbtype.h:34
@ EQUIPMENT_FEET
Definition: itemdbtype.h:43
@ EQUIPMENT_AMMO
Definition: itemdbtype.h:44
@ EQUIPMENT_SHIELD
Definition: itemdbtype.h:40
@ EQUIPMENT_ONE_HAND_WEAPON
Definition: itemdbtype.h:33
@ EQUIPMENT_CHARM
Definition: itemdbtype.h:45
@ EQUIPMENT_TORSO
Definition: itemdbtype.h:35
@ EQUIPMENT_ARMS
Definition: itemdbtype.h:36
@ EQUIPMENT_NECKLACE
Definition: itemdbtype.h:42

References ItemDbType::CARD, ItemDbType::EQUIPMENT_AMMO, ItemDbType::EQUIPMENT_ARMS, ItemDbType::EQUIPMENT_CHARM, ItemDbType::EQUIPMENT_FEET, ItemDbType::EQUIPMENT_HEAD, ItemDbType::EQUIPMENT_LEGS, ItemDbType::EQUIPMENT_NECKLACE, ItemDbType::EQUIPMENT_ONE_HAND_WEAPON, ItemDbType::EQUIPMENT_RING, ItemDbType::EQUIPMENT_SHIELD, ItemDbType::EQUIPMENT_TORSO, ItemDbType::EQUIPMENT_TWO_HANDS_WEAPON, ItemDbType::SPRITE_HAIR, ItemDbType::SPRITE_RACE, ItemDbType::UNUSABLE, and ItemDbType::USABLE.

Referenced by ItemDB::loadXmlFile().

◆ initStatic()

static void initStatic ( )
static

Definition at line 131 of file itemdb.cpp.

References ItemSoundEvent::DROP, ItemSoundEvent::EQUIP, ItemSoundEvent::HIT, anonymous_namespace{itemdb.cpp}::mConstructed, ItemSoundEvent::MISS, anonymous_namespace{itemdb.cpp}::mSoundNames, ItemSoundEvent::PICKUP, ItemSoundEvent::PUT, ItemSoundEvent::TAKE, ItemSoundEvent::UNEQUIP, ItemSoundEvent::USE, and ItemSoundEvent::USECARD.

Referenced by ItemDB::load().

◆ itemTypeFromString()

static ItemDbTypeT itemTypeFromString ( const std::string &  name)
static

Definition at line 84 of file itemdb.cpp.

85 {
86  const size_t sz = sizeof(itemTypeMap) / sizeof(itemTypeMap[0]);
87  for (size_t f = 0; f < sz; f ++)
88  {
89  const ItemTypeMap &type = itemTypeMap[f];
90  if (type.name == name)
91  return type.type;
92  }
93  logger->log("Unknown item type: " + name);
94  return ItemDbType::UNUSABLE;
95 }
void log(const char *const log_text,...)
Definition: logger.cpp:269
ItemTypeMap itemTypeMap[]
Logger * logger
Definition: logger.cpp:89
ItemDbTypeT type
Definition: itemtypemap.h:36
std::string name
Definition: itemtypemap.h:35

References itemTypeMap, Logger::log(), logger, ItemTypeMap::name, ItemTypeMap::type, and ItemDbType::UNUSABLE.

Referenced by ItemDB::loadXmlFile().

◆ loadFloorSprite()

static void loadFloorSprite ( SpriteDisplay display,
const xmlNode *const  node 
)
static

Definition at line 1003 of file itemdb.cpp.

1005 {
1006  if (floorNode == nullptr)
1007  return;
1008  for_each_xml_child_node(spriteNode, floorNode)
1009  {
1010  if (!XmlHaveChildContent(spriteNode))
1011  continue;
1012  if (xmlNameEqual(spriteNode, "sprite"))
1013  {
1014  SpriteReference *const currentSprite = new SpriteReference;
1015  currentSprite->sprite = XmlChildContent(spriteNode);
1016  currentSprite->variant
1017  = XML::getProperty(spriteNode, "variant", 0);
1018  display.sprites.push_back(currentSprite);
1019  }
1020  else if (xmlNameEqual(spriteNode, "particlefx"))
1021  {
1022  display.particles.push_back(XmlChildContent(spriteNode));
1023  }
1024  }
1025 }
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:174
StringVect particles
Definition: spritedisplay.h:48
std::vector< SpriteReference * > sprites
Definition: spritedisplay.h:47
std::string sprite

References for_each_xml_child_node, XML::getProperty(), SpriteDisplay::particles, SpriteReference::sprite, SpriteDisplay::sprites, and SpriteReference::variant.

Referenced by ItemDB::loadXmlFile().

◆ loadMenu()

static void loadMenu ( xmlNode *const  parentNode,
std::vector< ItemMenuItem > &  menu 
)
static

Definition at line 212 of file itemdb.cpp.

214 {
215  for_each_xml_child_node(node, parentNode)
216  {
217  if (xmlNameEqual(node, "menu"))
218  {
219  const std::string name1 = XML::langProperty(node,
220  "name1", "");
221  const std::string name2 = XML::langProperty(node,
222  "name2", "");
223  const std::string command1 = XML::getProperty(node,
224  "command1", "");
225  const std::string command2 = XML::getProperty(node,
226  "command2", command1);
227  menu.push_back(ItemMenuItem(name1,
228  name2,
229  command1,
230  command2));
231  }
232  }
233 }
MenuTypeT menu
Definition: menu.cpp:28
std::string langProperty(const xmlNodePtr node, const char *const name, const std::string &def)
Definition: libxml.cpp:258

References for_each_xml_child_node, XML::getProperty(), XML::langProperty(), and EAthena::menu.

Referenced by ItemDB::loadXmlFile().

◆ loadOrderSprite()

static void loadOrderSprite ( ItemInfo *const  itemInfo,
const xmlNodePtr  node,
const bool  drawAfter 
)
static

Definition at line 1160 of file itemdb.cpp.

1163 {
1164  const int sprite = parseSpriteName(XML::getProperty(node, "name", ""));
1165  const int priority = XML::getProperty(node, "priority", 0);
1166 
1167  const int direction = parseDirectionName(XML::getProperty(
1168  node, "direction", "all"));
1169  if (drawAfter)
1170  itemInfo->setDrawAfter(direction, sprite);
1171  else
1172  itemInfo->setDrawBefore(direction, sprite);
1173  itemInfo->setDrawPriority(direction, priority);
1174 }
static int parseSpriteName(const std::string &name)
Definition: itemdb.cpp:839
static int parseDirectionName(const std::string &name)
Definition: itemdb.cpp:903
bool itemInfo(InputEvent &event)
Definition: commands.cpp:105

References XML::getProperty(), Actions::itemInfo(), parseDirectionName(), and parseSpriteName().

Referenced by ItemDB::loadXmlFile().

◆ loadReplaceSprite()

static void loadReplaceSprite ( ItemInfo *const  itemInfo,
const xmlNodePtr  replaceNode 
)
static

Definition at line 1027 of file itemdb.cpp.

1029 {
1030  if (replaceNode == nullptr)
1031  return;
1032  const std::string removeSprite = XML::getProperty(
1033  replaceNode, "sprite", "");
1034  const int direction = parseDirectionName(XML::getProperty(
1035  replaceNode, "direction", "all"));
1036 
1037  itemInfo->setRemoveSprites();
1038 
1039  switch (direction)
1040  {
1041  case -1:
1042  {
1043  if (removeSprite.empty())
1044  { // remove all sprites
1045  for (int f = 0; f < 10; f ++)
1046  {
1047  for (int sprite = 0; sprite < 13; sprite ++)
1048  itemInfo->addReplaceSprite(sprite, f);
1049  }
1050  }
1051  else
1052  { // replace only given sprites
1053  for (int f = 0; f < 10; f ++)
1054  {
1055  IntMap *const mapList = itemInfo->addReplaceSprite(
1056  parseSpriteName(removeSprite), f);
1057  if (mapList == nullptr)
1058  continue;
1059  for_each_xml_child_node(itemNode, replaceNode)
1060  {
1061  if (xmlNameEqual(itemNode, "item"))
1062  {
1063  const int from = XML::getProperty(
1064  itemNode, "from", 0);
1065  const int to = XML::getProperty(
1066  itemNode, "to", 1);
1067  (*mapList)[from] = to;
1068  }
1069  }
1070  }
1071  }
1072  break;
1073  }
1074  case -2:
1075  {
1076  itemInfo->addReplaceSprite(parseSpriteName(
1077  removeSprite), SpriteDirection::DOWN);
1078  itemInfo->addReplaceSprite(parseSpriteName(
1079  removeSprite), SpriteDirection::DOWNLEFT);
1080  itemInfo->addReplaceSprite(parseSpriteName(
1081  removeSprite), SpriteDirection::DOWNRIGHT);
1082 
1083  for_each_xml_child_node(itemNode, replaceNode)
1084  {
1085  if (xmlNameEqual(itemNode, "item"))
1086  {
1087  const int from = XML::getProperty(itemNode, "from", 0);
1088  const int to = XML::getProperty(itemNode, "to", 1);
1089  IntMap *mapList = itemInfo->addReplaceSprite(
1090  parseSpriteName(removeSprite), SpriteDirection::DOWN);
1091  if (mapList != nullptr)
1092  (*mapList)[from] = to;
1093 
1094  mapList = itemInfo->addReplaceSprite(parseSpriteName(
1095  removeSprite), SpriteDirection::DOWNLEFT);
1096  if (mapList != nullptr)
1097  (*mapList)[from] = to;
1098 
1099  mapList = itemInfo->addReplaceSprite(parseSpriteName(
1100  removeSprite), SpriteDirection::DOWNRIGHT);
1101  if (mapList != nullptr)
1102  (*mapList)[from] = to;
1103  }
1104  }
1105  break;
1106  }
1107  case -3:
1108  {
1109  itemInfo->addReplaceSprite(parseSpriteName(
1110  removeSprite), SpriteDirection::UP);
1111  itemInfo->addReplaceSprite(parseSpriteName(
1112  removeSprite), SpriteDirection::UPLEFT);
1113  itemInfo->addReplaceSprite(parseSpriteName(
1114  removeSprite), SpriteDirection::UPRIGHT);
1115 
1116  for_each_xml_child_node(itemNode, replaceNode)
1117  {
1118  if (xmlNameEqual(itemNode, "item"))
1119  {
1120  const int from = XML::getProperty(itemNode, "from", 0);
1121  const int to = XML::getProperty(itemNode, "to", 1);
1122  IntMap *mapList = itemInfo->addReplaceSprite(
1123  parseSpriteName(removeSprite), SpriteDirection::UP);
1124  if (mapList != nullptr)
1125  (*mapList)[from] = to;
1126 
1127  mapList = itemInfo->addReplaceSprite(parseSpriteName(
1128  removeSprite), SpriteDirection::UPLEFT);
1129  if (mapList != nullptr)
1130  (*mapList)[from] = to;
1131 
1132  mapList = itemInfo->addReplaceSprite(parseSpriteName(
1133  removeSprite), SpriteDirection::UPRIGHT);
1134  if (mapList != nullptr)
1135  (*mapList)[from] = to;
1136  }
1137  }
1138  break;
1139  }
1140  default:
1141  {
1142  IntMap *const mapList = itemInfo->addReplaceSprite(
1143  parseSpriteName(removeSprite), direction);
1144  if (mapList == nullptr)
1145  return;
1146  for_each_xml_child_node(itemNode, replaceNode)
1147  {
1148  if (xmlNameEqual(itemNode, "item"))
1149  {
1150  const int from = XML::getProperty(itemNode, "from", 0);
1151  const int to = XML::getProperty(itemNode, "to", 1);
1152  (*mapList)[from] = to;
1153  }
1154  }
1155  break;
1156  }
1157  }
1158 }
std::map< int, int > IntMap
Definition: intmap.h:27

References SpriteDirection::DOWN, SpriteDirection::DOWNLEFT, SpriteDirection::DOWNRIGHT, for_each_xml_child_node, XML::getProperty(), Actions::itemInfo(), parseDirectionName(), parseSpriteName(), SpriteDirection::UP, SpriteDirection::UPLEFT, and SpriteDirection::UPRIGHT.

Referenced by ItemDB::loadXmlFile().

◆ loadSoundRef()

static void loadSoundRef ( ItemInfo *const  itemInfo,
const xmlNodePtr  node 
)
static

Definition at line 980 of file itemdb.cpp.

981 {
982  if (node == nullptr ||
983  !XmlHaveChildContent(node))
984  {
985  return;
986  }
987  const std::string event = XML::getProperty(node, "event", "");
988  const std::map<std::string, ItemSoundEvent::Type>::const_iterator
989  it = mSoundNames.find(event);
990  if (it != mSoundNames.end())
991  {
992  const int delay = XML::getProperty(node, "delay", 0);
993  const std::string filename = XmlChildContent(node);
994  itemInfo->addSound((*it).second, filename, delay);
995  }
996  else
997  {
998  reportAlways("ItemDB: Ignoring unknown sound event '%s'",
999  event.c_str())
1000  }
1001 }
#define reportAlways(...)
Definition: checkutils.h:253

References XML::getProperty(), Actions::itemInfo(), anonymous_namespace{itemdb.cpp}::mSoundNames, and reportAlways.

Referenced by ItemDB::loadXmlFile().

◆ loadSpriteRef()

static void loadSpriteRef ( ItemInfo *const  itemInfo,
const xmlNodePtr  node 
)
static

Definition at line 965 of file itemdb.cpp.

966 {
967  const std::string gender = XML::getProperty(node, "gender", "unisex");
968  if ((node == nullptr) || !XmlHaveChildContent(node))
969  return;
970 
971  const std::string filename = XmlChildContent(node);
972 
973  const int race = XML::getProperty(node, "race", 0);
974  if (gender == "male" || gender == "unisex")
975  itemInfo->setSprite(filename, Gender::MALE, race);
976  if (gender == "female" || gender == "unisex")
977  itemInfo->setSprite(filename, Gender::FEMALE, race);
978 }
@ MALE
Definition: gender.h:31
@ FEMALE
Definition: gender.h:32

References Gender::FEMALE, XML::getProperty(), Actions::itemInfo(), and Gender::MALE.

Referenced by ItemDB::loadXmlFile().

◆ parseDirectionName()

static int parseDirectionName ( const std::string &  name)
static

Definition at line 903 of file itemdb.cpp.

904 {
905  int id = -1;
906  if (name == "down")
907  {
908 #ifdef TMWA_SUPPORT
910  id = -2;
911  else
912 #endif
914  }
915  else if (name == "downleft" || name == "leftdown")
916  {
918  }
919  else if (name == "left")
920  {
922  }
923  else if (name == "upleft" || name == "leftup")
924  {
926  }
927  else if (name == "up")
928  {
929 #ifdef TMWA_SUPPORT
931  id = -3;
932  else
933 #endif
934  id = SpriteDirection::UP;
935  }
936  else if (name == "upright" || name == "rightup")
937  {
939  }
940  else if (name == "right")
941  {
943  }
944  else if (name == "downright" || name == "rightdown")
945  {
947  }
948  else if (name == "downall")
949  {
950  id = -2;
951  }
952  else if (name == "upall")
953  {
954  id = -3;
955  }
956  // hack for died action.
957  else if (name == "died")
958  {
959  id = 9;
960  }
961 
962  return id;
963 }
ServerTypeT getNetworkType()
Definition: net.cpp:189

References SpriteDirection::DOWN, SpriteDirection::DOWNLEFT, SpriteDirection::DOWNRIGHT, Net::getNetworkType(), SpriteDirection::LEFT, SpriteDirection::RIGHT, ServerType::TMWATHENA, SpriteDirection::UP, SpriteDirection::UPLEFT, and SpriteDirection::UPRIGHT.

Referenced by loadOrderSprite(), and loadReplaceSprite().

◆ parseSpriteName()

static int parseSpriteName ( const std::string &  name)
static

Definition at line 839 of file itemdb.cpp.

840 {
841  int id = -1;
842  if (name == "race" || name == "type")
843  {
844  id = 0;
845  }
846  else if (name == "shoes" || name == "boot" || name == "boots")
847  {
848  id = 1;
849  }
850  else if (name == "bottomclothes" || name == "bottom" || name == "pants")
851  {
852  id = 2;
853  }
854  else if (name == "topclothes" || name == "top"
855  || name == "torso" || name == "body")
856  {
857  id = 3;
858  }
859  else if (name == "misc1")
860  {
861  id = 4;
862  }
863  else if (name == "misc2" || name == "scarf" || name == "scarfs")
864  {
865  id = 5;
866  }
867  else if (name == "hair")
868  {
869  id = 6;
870  }
871  else if (name == "hat" || name == "hats")
872  {
873  id = 7;
874  }
875  else if (name == "wings")
876  {
877  id = 8;
878  }
879  else if (name == "glove" || name == "gloves")
880  {
881  id = 9;
882  }
883  else if (name == "weapon" || name == "weapons")
884  {
885  id = 10;
886  }
887  else if (name == "shield" || name == "shields")
888  {
889  id = 11;
890  }
891  else if (name == "amulet" || name == "amulets")
892  {
893  id = 12;
894  }
895  else if (name == "ring" || name == "rings")
896  {
897  id = 13;
898  }
899 
900  return id;
901 }

Referenced by loadOrderSprite(), loadReplaceSprite(), and ItemDB::loadXmlFile().

◆ useButton2FromItemType()

static std::string useButton2FromItemType ( const ItemDbTypeT type)
static

Definition at line 114 of file itemdb.cpp.

115 {
116  const size_t sz = sizeof(itemTypeMap) / sizeof(itemTypeMap[0]);
117  for (size_t f = 0; f < sz; f ++)
118  {
119  const ItemTypeMap &item = itemTypeMap[f];
120  if (item.type == type)
121  {
122  if (item.useButton2.empty())
123  return std::string();
124  return gettext(item.useButton2.c_str());
125  }
126  }
127  logger->log("Unknown item type");
128  return std::string();
129 }
std::string useButton2
Definition: itemtypemap.h:38

References itemTypeMap, Logger::log(), logger, ItemTypeMap::type, and ItemTypeMap::useButton2.

Referenced by ItemDB::loadXmlFile().

◆ useButtonFromItemType()

static std::string useButtonFromItemType ( const ItemDbTypeT type)
static

Definition at line 97 of file itemdb.cpp.

98 {
99  const size_t sz = sizeof(itemTypeMap) / sizeof(itemTypeMap[0]);
100  for (size_t f = 0; f < sz; f ++)
101  {
102  const ItemTypeMap &item = itemTypeMap[f];
103  if (item.type == type)
104  {
105  if (item.useButton.empty())
106  return std::string();
107  return gettext(item.useButton.c_str());
108  }
109  }
110  logger->log("Unknown item type");
111  return std::string();
112 }
std::string useButton
Definition: itemtypemap.h:37

References itemTypeMap, Logger::log(), logger, ItemTypeMap::type, and ItemTypeMap::useButton.

Referenced by ItemDB::loadXmlFile().