HypotheticBattle::HypotheticBattle(Subject realBattle) : BattleProxy(realBattle), bonusTreeVersion(1) { auto activeUnit = realBattle->battleActiveUnit(); activeUnitId = activeUnit ? activeUnit->unitId() : -1; nextId = 0xF0000000; }
void JobView::setProcessedAmount(qlonglong amount, const QString &unit) { const int id = unitId(unit); const QString processedString = QString("processedAmount%1").arg(id); const qlonglong prevTotal = data().value(processedString).toLongLong(); if (prevTotal != amount) { if (id == m_bytesUnitId) { m_processedBytes = amount; updateEta(); } setData(processedString, amount); scheduleUpdate(); } }
void MemoryUnit::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { MemoryScene* p_scene = dynamic_cast<MemoryScene*>(scene()); if(!p_scene) return; setUnitSelected(true); p_scene->setUnitInfo(QString( QObject::tr("Unit Group Id: ") +QString::number(unitId()) +QString(QObject::tr(" Unit State: ")) +state() +QObject::tr(" Unit Memory: ") +"0x"+fixedNumPresentation(start(),16,2047) +" - 0x"+fixedNumPresentation(finish(),16,2047) )); setZValue(100); update(); return QGraphicsItem::hoverEnterEvent(event); }
bool Teleport::prepareEffects(std::string & errorMessage, BattleStackMoved & pack, const Mechanics * m, const EffectTarget & target) const { if(target.size() != 2) { errorMessage = "Teleport requires 2 destinations."; return false; } auto targetUnit = target[0].unitValue; if(nullptr == targetUnit) { errorMessage = "No unit to teleport"; return false; } const BattleHex destination = target[1].hexValue; if(!destination.isValid()) { errorMessage = "Invalid teleport destination"; return false; } //TODO: move here all teleport checks if(!m->cb->battleCanTeleportTo(targetUnit, destination, m->getEffectLevel())) { errorMessage = "Forbidden teleport."; return false; } pack.distance = 0; pack.stack = targetUnit->unitId(); std::vector<BattleHex> tiles; tiles.push_back(destination); pack.tilesToMove = tiles; pack.teleporting = true; return true; }
RcppExport SEXP xbrlProcessFacts(SEXP epaDoc) { xmlDocPtr doc = (xmlDocPtr) R_ExternalPtrAddr(epaDoc); xmlXPathContextPtr context = xmlXPathNewContext(doc); xmlXPathObjectPtr fact_res = xmlXPathEvalExpression((xmlChar*) "//*[@*[local-name()='contextRef']]", context); xmlNodeSetPtr fact_nodeset = fact_res->nodesetval; xmlXPathFreeContext(context); int fact_nodeset_ln = fact_nodeset->nodeNr; CharacterVector elementId(fact_nodeset_ln); CharacterVector contextId(fact_nodeset_ln); CharacterVector unitId(fact_nodeset_ln); CharacterVector fact(fact_nodeset_ln); CharacterVector decimals(fact_nodeset_ln); CharacterVector sign(fact_nodeset_ln); CharacterVector scale(fact_nodeset_ln); CharacterVector tupleRef(fact_nodeset_ln); CharacterVector order(fact_nodeset_ln); CharacterVector factId(fact_nodeset_ln); CharacterVector ns(fact_nodeset_ln); for (int i=0; i < fact_nodeset_ln; i++) { xmlNodePtr fact_node = fact_nodeset->nodeTab[i]; if (fact_node->ns->prefix) elementId[i] = (char *) ((string) (char *) fact_node->ns->prefix + "_" + (string) (char *) fact_node->name).data(); else elementId[i] = (char *) fact_node->name; xmlChar *tmp_str; if ((tmp_str = xmlGetProp(fact_node, (xmlChar*) "contextRef"))) { contextId[i] = (char *) tmp_str; xmlFree(tmp_str); } else { contextId[i] = NA_STRING; } if ((tmp_str = xmlGetProp(fact_node, (xmlChar*) "unitRef"))) { unitId[i] = (char *) tmp_str; xmlFree(tmp_str); } else { unitId[i] = NA_STRING; } if ((tmp_str = xmlNodeListGetString(doc, fact_node->xmlChildrenNode, 1))) { fact[i] = (char *) tmp_str; xmlFree(tmp_str); } else { fact[i] = NA_STRING; } if ((tmp_str = xmlGetProp(fact_node, (xmlChar*) "decimals"))) { decimals[i] = (char *) tmp_str; xmlFree(tmp_str); } else { decimals[i] = NA_STRING; } if ((tmp_str = xmlGetProp(fact_node, (xmlChar*) "scale"))) { scale[i] = (char *) tmp_str; xmlFree(tmp_str); } else { scale[i] = NA_STRING; } if ((tmp_str = xmlGetProp(fact_node, (xmlChar*) "sign"))) { sign[i] = (char *) tmp_str; xmlFree(tmp_str); } else { sign[i] = NA_STRING; } if ((tmp_str = xmlGetProp(fact_node, (xmlChar*) "tupleRef"))) { sign[i] = (char *) tmp_str; xmlFree(tmp_str); } else { sign[i] = NA_STRING; } if ((tmp_str = xmlGetProp(fact_node, (xmlChar*) "order"))) { sign[i] = (char *) tmp_str; xmlFree(tmp_str); } else { sign[i] = NA_STRING; } if ((tmp_str = xmlGetProp(fact_node, (xmlChar*) "id"))) { factId[i] = (char *) tmp_str; xmlFree(tmp_str); } else if ((tmp_str = xmlGetProp(fact_node, (xmlChar*) "name"))) { factId[i] = (char *) tmp_str; xmlFree(tmp_str); } else { factId[i] = NA_STRING; } ns[i] = (char *) fact_node->ns->href; } xmlXPathFreeObject(fact_res); return DataFrame::create(Named("elementId")=elementId, Named("contextId")=contextId, Named("unitId")=unitId, Named("fact")=fact, Named("factId")=factId, Named("decimals")=decimals, Named("scale")=scale, Named("sign")=sign, Named("tupleRef")=tupleRef, Named("order")=order, Named("ns")=ns); }
RcppExport SEXP xbrlProcessUnits(SEXP epaDoc) { xmlDocPtr doc = (xmlDocPtr) R_ExternalPtrAddr(epaDoc); xmlXPathContextPtr context = xmlXPathNewContext(doc); xmlXPathObjectPtr unit_res = xmlXPathEvalExpression((xmlChar*) "//*[local-name()='unit']", context); xmlNodeSetPtr unit_nodeset = unit_res->nodesetval; int unit_nodeset_ln = unit_nodeset->nodeNr; xmlXPathFreeContext(context); CharacterVector unitId(unit_nodeset_ln); CharacterVector measure(unit_nodeset_ln); CharacterVector unitNumerator(unit_nodeset_ln); CharacterVector unitDenominator(unit_nodeset_ln); for (int i=0; i < unit_nodeset_ln; i++) { xmlNodePtr unit_node = unit_nodeset->nodeTab[i]; xmlChar *tmp_str; if ((tmp_str = xmlGetProp(unit_node, (xmlChar*) "id"))) { unitId[i] = (char *) tmp_str; xmlFree(tmp_str); } else { unitId[i] = NA_STRING; } measure[i] = unitNumerator[i] = unitDenominator[i] = NA_STRING; xmlNodePtr child_node = unit_node->xmlChildrenNode; while (child_node) { if (!xmlStrcmp(child_node->name, (xmlChar*) "measure")) { if ((tmp_str = xmlNodeListGetString(doc, child_node->xmlChildrenNode, 1))) { measure[i] = (char *) tmp_str; xmlFree(tmp_str); } } else if (!xmlStrcmp(child_node->name, (xmlChar*) "divide")) { xmlNodePtr gchild_node = child_node->xmlChildrenNode; while (gchild_node) { if (!xmlStrcmp(gchild_node->name, (xmlChar*) "unitNumerator")) { xmlNodePtr ggchild_node = gchild_node->xmlChildrenNode; while (ggchild_node) { if (!xmlStrcmp(ggchild_node->name, (xmlChar*) "measure")) { if ((tmp_str = xmlNodeListGetString(doc, ggchild_node->xmlChildrenNode, 1))) { unitNumerator[i] = (char *) tmp_str; xmlFree(tmp_str); } } ggchild_node = ggchild_node->next; } } else if (!xmlStrcmp(gchild_node->name, (xmlChar*) "unitDenominator")) { xmlNodePtr ggchild_node = gchild_node->xmlChildrenNode; while (ggchild_node) { if (!xmlStrcmp(ggchild_node->name, (xmlChar*) "measure")) { if ((tmp_str = xmlNodeListGetString(doc, ggchild_node->xmlChildrenNode, 1))) { unitDenominator[i] = (char *) tmp_str; xmlFree(tmp_str); } } ggchild_node = ggchild_node->next; } } gchild_node = gchild_node->next; } } child_node = child_node->next; } } xmlXPathFreeObject(unit_res); return DataFrame::create(Named("unitId")=unitId, Named("measure")=measure, Named("unitNumerator")=unitNumerator, Named("unitDenominator")=unitDenominator); }
std::string Unit::getDescription() const { boost::format fmt("Unit %d of side %d"); fmt % unitId() % unitSide(); return fmt.str(); }
void Clone::apply(BattleStateProxy * battleState, RNG & rng, const Mechanics * m, const EffectTarget & target) const { for(const Destination & dest : target) { const battle::Unit * clonedStack = dest.unitValue; //we shall have all targets to be stacks if(!clonedStack) { battleState->complain("No target stack to clone! Invalid effect target transformation."); continue; } //should not happen, but in theory we might have stack took damage from other effects if(clonedStack->getCount() < 1) continue; auto hex = m->cb->getAvaliableHex(clonedStack->creatureId(), m->casterSide); if(!hex.isValid()) { battleState->complain("No place to put new clone!"); break; } auto unitId = m->cb->battleNextUnitId(); battle::UnitInfo info; info.id = unitId; info.count = clonedStack->getCount(); info.type = clonedStack->creatureId(); info.side = m->casterSide; info.position = hex; info.summoned = true; BattleUnitsChanged pack; pack.changedStacks.emplace_back(info.id, UnitChanges::EOperation::ADD); info.save(pack.changedStacks.back().data); battleState->apply(&pack); //TODO: use BattleUnitsChanged with UPDATE operation BattleUnitsChanged cloneFlags; auto cloneUnit = m->cb->battleGetUnitByID(unitId); auto cloneState = cloneUnit->acquireState(); cloneState->cloned = true; cloneFlags.changedStacks.emplace_back(cloneState->unitId(), UnitChanges::EOperation::RESET_STATE); cloneState->save(cloneFlags.changedStacks.back().data); auto originalState = clonedStack->acquireState(); originalState->cloneID = unitId; cloneFlags.changedStacks.emplace_back(originalState->unitId(), UnitChanges::EOperation::RESET_STATE); originalState->save(cloneFlags.changedStacks.back().data); battleState->apply(&cloneFlags); SetStackEffect sse; Bonus lifeTimeMarker(Bonus::N_TURNS, Bonus::NONE, Bonus::SPELL_EFFECT, 0, SpellID::CLONE); //TODO: use special bonus type lifeTimeMarker.turnsRemain = m->getEffectDuration(); std::vector<Bonus> buffer; buffer.push_back(lifeTimeMarker); sse.toAdd.push_back(std::make_pair(unitId, buffer)); battleState->apply(&sse); } }