Exemplo n.º 1
0
void LocationPane::connectionEstablished(RemoteBroker *remoteBroker)
{
	Q_CHECK_PTR(remoteBroker);
	Q_CHECK_PTR(getItemById(remoteBroker->getItemId()));

	qDebug() << "void LocationPane::connectionEstablished(RemoteBroker *remoteBroker)";
	qDebug() << "\t With Broker:" << remoteBroker;
	qDebug() << "\t Associated Item Id:" << remoteBroker->getItemId();

	LocationItem *childItem = 0;
	LocationItem *selectedItem = getItemById(remoteBroker->getItemId());
	selectedItem->setConnectionMode(LocationItem::Established);

	// Find all of the auto-subscribe items
	for (int index = 0; index < selectedItem->childCount(); ++index)
	{
		childItem = (LocationItem *) selectedItem->child(index);

		Q_CHECK_PTR(childItem);

		qDebug() << "\t Child Item:";
		qDebug() << "\t\t Item Id:" << childItem->getId();
		qDebug() << "\t\t Is Subscription:" << childItem->isSubscription();
		qDebug() << "\t\t Is Auto Subscription:" << childItem->isAutoSubscription();
		qDebug() << "\t\t Subscription:" << childItem->getSubscription();

		if (false == childItem->isSubscription() || false == childItem->isAutoSubscription())
			qDebug() << "\t\t Skipping subscription attempt.";
		else
			remoteBroker->setSubscribed(childItem->getSubscription(), true);
	}
}
Exemplo n.º 2
0
void LocationPane::connectionError(RemoteBroker *remoteBroker, RemoteBroker::SocketError socketError)
{
	Q_CHECK_PTR(remoteBroker);
	Q_CHECK_PTR(getItemById(remoteBroker->getItemId()));

	qDebug() << "void LocationPane::connectionError(RemoteBroker *remoteBroker, RemoteBroker::SocketError socketError)";

	getItemById(remoteBroker->getItemId())->setConnectionMode(LocationItem::Error);
}
Exemplo n.º 3
0
void LocationPane::connectionClosed(RemoteBroker *remoteBroker)
{
	Q_CHECK_PTR(remoteBroker);
	Q_CHECK_PTR(getItemById(remoteBroker->getItemId()));

	qDebug() << "void LocationPane::connectionClosed(RemoteBroker *remoteBroker)";
	qDebug() << "\t With Broker:" << remoteBroker;
	qDebug() << "\t Associated Item Id: " << remoteBroker->getItemId();

	getItemById(remoteBroker->getItemId())->setConnectionMode(LocationItem::Closed);
}
Exemplo n.º 4
0
QAction* QRibbonButtonBar::getActionById(int nID)
{
	QRibbonButtonBarButtonBase* pBase = getItemById(nID);
	if (pBase && pBase->m_pAction)
		return pBase->m_pAction;
	return NULL;
}
Exemplo n.º 5
0
QStandardItem *DataBase::getItemById(QStandardItem *currentItem, int itemId) {
  QStandardItem *foundItem = 0;
  QVariant currentData = currentItem->data();
  int currentId = currentData.toInt();

  if (currentId != itemId) {
    int childCount = currentItem->rowCount();
    for (int i = 0; i < childCount; ++i) {
      foundItem = getItemById(currentItem->child(i), itemId);

      if (foundItem) {
        break;
      }
    }
  }
  else {
    foundItem = currentItem;
  }

  return foundItem;
}
Exemplo n.º 6
0
bool parseDotaData (char const* dest, char const* path)
{
  MPQARCHIVE map = MPQOpen (path, MPQFILE_READ);
  if (map == 0)
    map = MPQOpen (mprintf ("%s%s", warPath, path), MPQFILE_READ);
  if (map == 0)
  {
    if (useropen)
      MessageBox (NULL, mprintf ("Could not locate %s", path), "Error", MB_OK | MB_ICONHAND);
    return false;
  }
  MPQAddArchive (warloader, map);

  CProgressDlg* prg = ((CDotAReplayApp*) ::AfxGetApp ())->progress;
  char title[256];
  _splitpath (path, NULL, NULL, title, NULL);
  prg->SetSupText (mprintf ("Parsing %s", title), 0);
  prg->SetSubText ("Parsing object data...");
  prg->show ();

  GameData data;
  LoadGameData (data, warloader, WC3_LOAD_UNITS | WC3_LOAD_ITEMS | WC3_LOAD_ABILITIES);

  resetData ();

  bool ok = true;

  dir = NULL;
  idir = NULL;

  reset_id ();

  int tavernCount = 0;
  prg->SetSubText ("Parsing taverns and shops...", 40);
  for (int i = 0; i < data.data[WC3_UNITS]->getNumUnits (); i++)
  {
    UnitData* tav = data.data[WC3_UNITS]->getUnit (i);
    if (tav != NULL)
    {
      char const* name = tav->getStringData ("Name");
      for (int ti = 0; ti < numTaverns; ti++)
      {
        if (!stricmp (taverns[ti].name, name))
        {
          tavernCount++;
          char const* herolist = tav->getData ("Sellunits");
          for (int p = 0; herolist[p];)
          {
            static char _id[5];
            int idl = 0;
            for (; idl < 4 && herolist[p]; idl++, p++)
              _id[idl] = herolist[p];
            if (idl == 4)
            {
              _id[4] = 0;
              if (getValue (dir, _id) == 0)
              {
                UnitData* hero = data.data[WC3_UNITS]->getUnitById (_id);
                if (hero)
                  addHero (data.data[WC3_ABILITIES], hero, ti);
                dir = addString (dir, _id, 1);
              }
            }
            if (herolist[p] == ',')
              p++;
            else
              break;
          }
        }
      }
      for (int si = 0; si < numShops; si++)
      {
        if (!stricmp (shops[si].name, name))
        {
          for (int m = 0; m < 2; m++)
          {
            char const* itemlist = tav->getData (m ? "Sellitems" : "Sellunits");
            for (int p = 0; itemlist[p];)
            {
              static char _id[5];
              int idl = 0;
              for (; idl < 4 && itemlist[p]; idl++, p++)
                _id[idl] = itemlist[p];
              if (idl == 4)
              {
                _id[4] = 0;
                if (getValue (dir, _id) == 0)
                {
                  UnitData* item = data.data[m ? WC3_ITEMS : WC3_UNITS]->getUnitById (_id);
                  if (item)
                    if (addSoldItem (item))
                      dir = addString (dir, _id, 1);
                }
              }
              if (itemlist[p] == ',')
                p++;
              else
                break;
            }
          }
          break;
        }
      }
    }
  }
  if (tavernCount == 0)
  {
    for (int i = 0; i < data.data[WC3_UNITS]->getNumUnits (); i++)
    {
      UnitData* tav = data.data[WC3_UNITS]->getUnit (i);
      if (tav != NULL)
      {
        char const* name = tav->getStringData ("Name");
        for (int ti = 0; ti < numOldTaverns; ti++)
        {
          if (!stricmp (oldTaverns[ti], name))
          {
            char const* herolist = tav->getData ("Sellunits");
            for (int p = 0; herolist[p];)
            {
              static char _id[5];
              int idl = 0;
              for (; idl < 4 && herolist[p]; idl++, p++)
                _id[idl] = herolist[p];
              if (idl == 4)
              {
                _id[4] = 0;
                if (getValue (dir, _id) == 0)
                {
                  UnitData* hero = data.data[WC3_UNITS]->getUnitById (_id);
                  if (hero)
                    addHero (data.data[WC3_ABILITIES], hero, ti);
                  dir = addString (dir, _id, 1);
                }
              }
              if (herolist[p] == ',')
                p++;
              else
                break;
            }
          }
        }
      }
    }
  }
  prg->SetSubText ("Parsing items...", 60);
  for (int i = 0; i < numItems; i++)
  {
    if (items[i].index == 0) continue;
    if (items[i].type == ITEM_RECIPE)
    {
      // parse recipe
      UnitData* unit = data.data[WC3_ITEMS]->getUnitById (items[i].ids[0]);
      if (unit == NULL)
        unit = data.data[WC3_UNITS]->getUnitById (items[i].ids[0]);
      if (unit)
      {
        char const* descr = strstr (unit->getStringData ("Ubertip"), "Requires:");
        if (descr && (strstr (descr, "Any of the following") ||
                      strstr (descr, "Staff of Wizardry and Blade of Alacrity")))
        {
          // scepter
          int scepter = items[items[i].realid].ids[0];
          int recipe = items[i].ids[0];
          int booster = _getItemByName ("Point Booster");
          int axe = _getItemByName ("Ogre Axe");
          int blade = _getItemByName ("Blade of Alacrity");
          int staff = _getItemByName ("Staff of Wizardry");
          recipes[numRecipes].recipeid = recipe;
          recipes[numRecipes].result = scepter;
          recipes[numRecipes].numsrc = 4;
          recipes[numRecipes].srcid[0] = recipe;
          recipes[numRecipes].srccount[0] = 1;
          recipes[numRecipes].srcid[1] = booster;
          recipes[numRecipes].srccount[1] = 1;
          recipes[numRecipes].srcid[2] = axe;
          recipes[numRecipes].srccount[2] = 1;
          recipes[numRecipes].srcid[3] = blade;
          recipes[numRecipes].srccount[3] = 1;
          numRecipes++;
          recipes[numRecipes].recipeid = recipe;
          recipes[numRecipes].result = scepter;
          recipes[numRecipes].numsrc = 4;
          recipes[numRecipes].srcid[0] = recipe;
          recipes[numRecipes].srccount[0] = 1;
          recipes[numRecipes].srcid[1] = booster;
          recipes[numRecipes].srccount[1] = 1;
          recipes[numRecipes].srcid[2] = axe;
          recipes[numRecipes].srccount[2] = 1;
          recipes[numRecipes].srcid[3] = staff;
          recipes[numRecipes].srccount[3] = 1;
          numRecipes++;
          recipes[numRecipes].recipeid = recipe;
          recipes[numRecipes].result = scepter;
          recipes[numRecipes].numsrc = 4;
          recipes[numRecipes].srcid[0] = recipe;
          recipes[numRecipes].srccount[0] = 1;
          recipes[numRecipes].srcid[1] = booster;
          recipes[numRecipes].srccount[1] = 1;
          recipes[numRecipes].srcid[2] = staff;
          recipes[numRecipes].srccount[2] = 1;
          recipes[numRecipes].srcid[3] = blade;
          recipes[numRecipes].srccount[3] = 1;
          numRecipes++;
        }
        else if (descr)
        {
          recipes[numRecipes].numsrc = 0;
          recipes[numRecipes].recipeid = 0;
          if (items[i].cost)
          {
            recipes[numRecipes].srccount[0] = 1;
            recipes[numRecipes].srcid[0] = items[i].ids[0];
            recipes[numRecipes].numsrc = 1;
            recipes[numRecipes].recipeid = items[i].ids[0];
          }
          recipes[numRecipes].result = items[items[i].realid].ids[0];
          int num = 0;
          int pos = 0;
          int prev = 0;
          bool prevOr = false;
          while (true)
          {
            if (descr[pos] == 0 || (descr[pos] == '|' && descr[pos + 1] == 'n'))
            {
              if (num)
              {
                char* iname = strip_item (descr + prev, pos - prev);
                int count = 1;
                bool hasx = false;
                if (*iname >= '0' && *iname <= '9')
                {
                  count = atoi (iname);
                  while (*iname && *iname != ' ')
                  {
                    if (*iname == 'x')
                      hasx = true;
                    iname++;
                  }
                  while (*iname == ' ')
                    iname++;
                }
                if (count > 1)
                {
                  int len = (int) strlen (iname);
                  if (len && iname[len - 1] == 's')
                    iname[--len] = 0;
                }
                int upgrLen = (int) strlen ("Buy recipe to upgrade (");
                if (!stricmp (iname, "or"))
                  prevOr = true;
                else if (!strnicmp (iname, "Buy recipe to upgrade (", upgrLen))
                {
                  int levels = atoi (iname + upgrLen);
                  int iid = items[i].realid;
                  for (int lvl = 2; lvl <= levels; lvl++)
                  {
                    numRecipes++;
                    recipes[numRecipes].numsrc = 2;
                    recipes[numRecipes].srcid[0] = recipes[numRecipes - 1].srcid[0];
                    recipes[numRecipes].srccount[0] = 1;
                    recipes[numRecipes].srcid[1] = recipes[numRecipes - 1].result;
                    recipes[numRecipes].srccount[1] = 1;
                    items[numItems].ids[0] = new_id ();
                    recipes[numRecipes].result = items[numItems].ids[0];
                    items[numItems].numIds = 1;
                    sprintf (items[numItems].name, "%s %d", items[iid].name, lvl);
                    strcpy (items[numItems].imgTag, items[iid].imgTag);
                    items[numItems].index = numItems;
                    items[numItems].type = ITEM_COMBO;
                    items[numItems].realid = i;
                    items[numItems].cost = 0;
                    idir = saddString (idir, items[numItems].name, numItems + 1);
                    numItems++;
                  }
                  strcat (items[iid].name, " 1");
                  idir = saddString (idir, items[iid].name, iid + 1);
                }
                else
                {
                  int cpos = sgetValue (idir, iname) - 1;
                  if (cpos >= 0)
                  {
                    if (prevOr)
                    {
                      memcpy (&recipes[numRecipes + 1], &recipes[numRecipes], sizeof recipes[0]);
                      numRecipes++;
                      recipes[numRecipes].srcid[recipes[numRecipes].numsrc - 1] = items[cpos].ids[0];
                      recipes[numRecipes].srccount[recipes[numRecipes].numsrc - 1] = count;
                    }
                    else
                    {
                      recipes[numRecipes].srcid[recipes[numRecipes].numsrc] = items[cpos].ids[0];
                      recipes[numRecipes].srccount[recipes[numRecipes].numsrc] = count;
                      recipes[numRecipes].numsrc++;
                    }
                    prevOr = false;
                  }
                }
              }
              num++;
              if (descr[pos] == 0)
                break;
              pos += 2;
              prev = pos;
            }
            else
              pos++;
          }
          if (recipes[numRecipes].numsrc)
            numRecipes++;
        }
      }
    }
  }
  for (int i = 0; i < data.data[WC3_ITEMS]->getNumUnits (); i++)
  {
    UnitData* item = data.data[WC3_ITEMS]->getUnit (i);
    if (item != NULL)
      mergeItemName (item);
  }
  for (int i = 0; i < data.data[WC3_UNITS]->getNumUnits (); i++)
  {
    UnitData* item = data.data[WC3_UNITS]->getUnit (i);
    if (item != NULL)
      mergeItemName (item);
  }

  prg->SetSubText ("Parsing upgradeable abilities...", 80);
  for (int i = 0; i < data.data[WC3_ABILITIES]->getNumUnits (); i++)
  {
    UnitData* abil = data.data[WC3_ABILITIES]->getUnit (i);
    if (abil != NULL && !strcmp (abil->getStringData ("code"), "ANeg"))
      addEngineering (abil);
  }

  prg->SetSubText ("Computing recipe costs...", 90);
  for (int i = 0; i < numRecipes; i++)
  {
    int res = getItemById (recipes[i].result)->index;
    if (res > 0 && items[res].type >= 0)
    {
      items[res].cost = 0;
      items[res].type = -items[res].type;
    }
  }
  for (int maxc = 0; maxc < 20; maxc++)
  {
    bool total = true;
    for (int i = 0; i < numRecipes; i++)
    {
      int res = getItemById (recipes[i].result)->index;
      if (res > 0 && items[res].type < 0)
      {
        bool ok = true;
        items[res].cost = 0;
        for (int j = 0; j < recipes[i].numsrc; j++)
        {
          int comp = getItemById (recipes[i].srcid[j])->index;
          if (comp > 0)
          {
            if (items[comp].type < 0)
            {
              ok = false;
              break;
            }
            else
              items[res].cost += items[comp].cost * recipes[i].srccount[j];
          }
        }
        if (!ok)
          total = false;
        else
          items[res].type = ITEM_COMBO;
      }
    }
    if (total)
      break;
  }
  //FILE* log = fopen ("recipes.txt", "wt");
  //for (int i = 0; i < numRecipes; i++)
  //{
  //  int res = getItemById (recipes[i].result)->index;
  //  if (res <= 0) continue;
  //  fprintf (log, "%s =", items[res].name);
  //  for (int j = 0; j < recipes[i].numsrc; j++)
  //  {
  //    int comp = getItemById (recipes[i].srcid[j])->index;
  //    if (comp > 0)
  //      fprintf (log, " %s x%d", items[comp].name, recipes[i].srccount[j]);
  //  }
  //  fprintf (log, "\n");
  //}
  //fclose (log);

  delete dir;
  delete idir;
  MPQRemoveArchive (warloader, map);
  MPQClose (map);
  prg->hide ();

  if (!ok) return false;
  return saveDotaData (dest);
}
Exemplo n.º 7
0
int DataBase::read(QString filePath) {
  DBGS(PRINT_START("filePath: %s", qPrintable(filePath)));

  int rv = ERROR_UNKNOWN_ERROR;
  QFile fileIn(filePath);

  if (fileIn.open(QIODevice::ReadOnly)) {
    if (domDoc.setContent(&fileIn)) {
      rv = readJotterHeader();

      if (rv == ALL_OK) {
        QString bodyName = KSILIT_JOTTER_DOM_BODY_TAG;
        QDomNodeList bodyList = domDoc.elementsByTagName(bodyName);
        QDomNode bodyNode = bodyList.at(0);
        QDomElement bodyElement = bodyNode.toElement();

        if (!bodyElement.isNull()) {
          int rootId = 0;
          QString rootNodeName = KSILIT_JOTTER_DOM_ELEMENT_TAG;
          rootNodeName += QString::number(rootId);
          QDomNodeList rootNodeList = domDoc.elementsByTagName(rootNodeName);
          QDomNode rootNode = rootNodeList.at(0);
          QDomElement rootElement = rootNode.toElement();

          QDomNode childNode = rootElement.firstChild();

          while (!childNode.isNull()) {
            QDomElement childElement = childNode.toElement();
            QString childTag = childElement.tagName();
            DBG3(PRINT_DBG("childTag: %s", qPrintable(childTag)));

            QString attributeChildId = childElement.attribute(KSILIT_JOTTER_DOM_ELEMENT_ATTRIBUTE_ID);
            DBG3(PRINT_DBG("attributeChildId: %s", qPrintable(attributeChildId)));

            QString attributeChildName = childElement.attribute(KSILIT_JOTTER_DOM_ELEMENT_ATTRIBUTE_NAME);
            DBG3(PRINT_DBG("attributeChildName: %s", qPrintable(attributeChildName)));

            QString attributeChildText = childElement.attribute(KSILIT_JOTTER_DOM_ELEMENT_ATTRIBUTE_TEXT);
            DBG3(PRINT_DBG("attributeChildText: %s", qPrintable(attributeChildText)));

            QDomNode parentNode = childElement.parentNode();

            if (!parentNode.isNull()) {
              QDomElement parentElement = parentNode.toElement();

              if (!parentElement.isNull()) {
                int parentId = 0;
                QString attributeParentId = parentElement.attribute(KSILIT_JOTTER_DOM_ELEMENT_ATTRIBUTE_ID);

                if (!attributeParentId.isEmpty()) {
                  parentId = attributeParentId.toInt();
                }

                DBG3(PRINT_DBG("parentId: %i", parentId));

                QStandardItem *parentItem = rootItem;

                if (parentId) {
                  parentItem = getItemById(rootItem, parentId);
                }

                if (parentItem){
                  QStandardItem *childItem = new QStandardItem();
                  parentItem->appendRow(childItem);

                  QVariant childData = attributeChildId;
                  childItem->setData(childData);

                  childItem->setText(attributeChildName);

                  int childId = attributeChildId.toInt();
                  jotter->createJot(childId);
                  jotter->setName(childId, attributeChildName);
                  jotter->setText(childId, attributeChildText);
                }
                else {
                  DBGE(PRINT_ERROR("parentItem not found!"));
                }
              }
              else {
                DBGE(PRINT_ERROR("Error converting parent node to element!"));
              }
            }
            else {
              DBGE(PRINT_ERROR("parentNode is null!"));
            }

            childNode = getNextNode(childNode, rootNode);

            if (childNode.isNull()) {
              rv = ALL_OK;
            }
          }
        }
        else {
          DBGE(PRINT_ERROR("rootElement is null!"));
        }
      }
      else {
        DBGE(PRINT_ERROR("Error reading jotter header!"));
      }
    }
    else {
      DBGE(PRINT_ERROR("Error setting DOM document content!"));
    }
  }
  else {
    DBGE(PRINT_ERROR("Error opening file: %s", qPrintable(filePath)));
    rv = ERROR_OPENING_FILE;
  }

  fileIn.close();

  DBGR(PRINT_RETURN("rv: %i", rv));
  return rv;
}
Exemplo n.º 8
0
void ItemManager::useItem(int id)
{
	auto item = getItemById(id);
	this->useItem(item);
}
Exemplo n.º 9
0
void ItemManager::buyItem(int id)
{
	auto item = getItemById(id);
	buyItem(item);
}
Exemplo n.º 10
0
void DiagramScene::loadDiagram()
{
    QDomNodeList lst = projXml->elementsByTagName("item");

    for(int i=0;i<lst.count();i++)
    {
        QDomNode xmlNode = lst.at(i);
        QDomNamedNodeMap attr = xmlNode.attributes();
        int type = attr.namedItem("type").nodeValue().toInt();
        int id = attr.namedItem("id").nodeValue().toInt();
        int diagId = attr.namedItem("diagId").nodeValue().toInt();

        qreal x = attr.namedItem("x").nodeValue().toDouble();
        qreal y = attr.namedItem("y").nodeValue().toDouble();

        DiagramNode nod = ((DiagramWindow*)parent())->searchById(type,id);

        DiagramItem* item = new DiagramItem(((DiagramItem::DiagramType)type),
                                            myItemMenu,
                                            nod.name,
                                            xmlNode,
                                            diagId,
                                            nod.inputs);

        item->setPos(x,y);

        diagItems.append(item);
        addItem(item);
    }

    QDomNodeList lst2 = projXml->elementsByTagName("arrow");

    for(int i=0;i<lst2.count();i++)
    {
        QDomNamedNodeMap attr = lst2.at(i).attributes();

        DiagramItem* startParent =
                getItemById(attr.namedItem("parentInId").nodeValue().toInt());

        DiagramItem* endParent =
                getItemById(attr.namedItem("parentOutId").nodeValue().toInt());

        Connector* start =
                startParent->childAt(attr.namedItem("connectorInId").nodeValue().toInt());

        Connector* end =
                endParent->childAt(attr.namedItem("connectorOutId").nodeValue().toInt());

        Arrow *arrow = new Arrow(start, end,lst2.at(i));
        arrowList.append(arrow);

        arrow->setColor(myLineColor);
        start->addArrow(arrow);
        end->addArrow(arrow);
        addItem(arrow);
        arrow->setZValue(-1000.0);
        arrow->updatePosition();
    }

    for(int i=0;i<diagItems.count();i++)
    {
        diagItems.at(i)->updateId(itemCount);
        itemCount++;
    }
}