Esempio n. 1
0
void StateEvaluationTreePanel::OnMouseRightUp(wxMouseEvent &Ev)
{
  if (!ClickUnmoved)
    return;
  
  if (HoverNodeIt != Nodes.end()) {
    auto const Stmt = HoverNodeIt->Statement;
    auto const Value = HoverNodeIt->Value.get();

    if (Recording) {
      auto const NodeIndex = std::distance(Nodes.cbegin(), HoverNodeIt);
      Recording->recordEventL("StateEvaluationTree.NodeRightClick",
                              make_attribute("node", NodeIndex),
                              make_attribute("stmt", Stmt));
    }
    
    auto const MaybeIndex = CurrentProcess->getThreadIndex(*CurrentThread);
    if (!MaybeIndex.assigned<std::size_t>())
      return;
    
    auto const ThreadIndex = MaybeIndex.get<std::size_t>();
    
    wxMenu CM{};
    addStmtNavigation(*this, CurrentAccess, CM, ThreadIndex, Stmt, Recording);
    if (Value) {
      CM.AppendSeparator();
      addValueNavigation(*this, CurrentAccess, CM, *Value, *CurrentProcess,
                         Recording);
    }
    CM.AppendSeparator();
    addStmtAnnotationEdit(CM, this, *Trace, Stmt);
    PopupMenu(&CM);
  }
}
Esempio n. 2
0
PlayerCharacter* PlayerCharacter::create(const std::string& name, const std::string& className, int level)
{
  PlayerCharacter* character = new PlayerCharacter;

  character->m_name = name;
  character->m_class = player_class_ref(className);

  character->m_faceTexture = cache::loadTexture(character->m_class.faceTexture);
  character->m_textureRect = character->m_class.textureRect;

  character->m_status.push_back(get_status_effect("Normal"));

  character->m_attributes["level"] = make_attribute(0);
  character->m_attributes["exp"] = make_attribute(0);

  for (int i = 1; i <= level; i++)
  {
    character->setLevel(i, false);

    if (i < level)
    {
      // Gain enough exp for the current level.
      character->getAttribute("exp").max = character->expForLevel();
      reset_attribute(character->getAttribute("exp"));
    }
  }

  reset_attribute(character->m_attributes["hp"]);
  reset_attribute(character->m_attributes["mp"]);

  return character;
}
Esempio n. 3
0
Character* Character::createMonster(const std::string& name)
{
  MonsterDef def = get_monster_definition(name);

  Character* character = new Character;

  character->m_name = def.name;
  character->m_faceTexture = cache::loadTexture(def.texture);
  if (def.textureRect.height == 0 && def.textureRect.width == 0)
  {
    character->m_textureRect = sf::IntRect(0, 0,
        character->m_faceTexture->getSize().x,
        character->m_faceTexture->getSize().y);
  }
  else
  {
    character->m_textureRect = def.textureRect;
  }
  character->m_color = def.color;
  character->m_textureScale = def.scale;
  character->m_unarmedAttackEffect = def.attackEffect;

  character->m_status.push_back(get_status_effect("Normal"));

  for (auto it = def.attributeMap.begin(); it != def.attributeMap.end(); ++it)
  {
    character->m_attributes[it->first] = make_attribute(it->second);

    // Variance to monster stats.
    if (it->first != terms::exp && it->first != terms::gold && it->first != terms::level)
    {
      float variance = rand_float(0.95, 1.05);
      character->m_attributes[it->first].max *= variance;

      // Don't want too low stats.
      if (character->m_attributes[it->first].max <= 1)
      {
        character->m_attributes[it->first] = make_attribute(it->second);
      }

      reset_attribute(character->m_attributes[it->first]);
    }
  }

  character->m_itemsToSteal = def.stealItems;

  character->m_resistance = def.resistance;
  character->m_statusImmunity = def.immunity;

  return character;
}
Esempio n. 4
0
static int
exmpp_xml_cb_make_attributes(struct exmpp_xml_ctx *ctx, void *user_data)
{
	int n, i, value_len;
	const char *ns, *attr, *value;
	struct exmpp_xml_data *edd;

	if (user_data == NULL)
		return (0);

	edd = (struct exmpp_xml_data *)user_data;

	for (n = 0, i = 0; n < edd->attrs_count; ++n, i += 5) {
		ns = (char *)edd->attrs[i + 2];
		attr = (char *)edd->attrs[i];
		value = (char *)edd->attrs[i + 3];
		value_len = edd->attrs[i + 4] - edd->attrs[i + 3];

		make_attribute(ctx,
		    ns, -1,
		    attr, -1,
		    value, value_len);
	}

	return (0);
}
Esempio n. 5
0
void StateEvaluationTreePanel::OnHover(wxTimerEvent &Ev)
{
  if (HoverNodeIt == Nodes.end())
    return;
  
  if (Recording) {
    auto const NodeIndex = std::distance(Nodes.cbegin(), HoverNodeIt);
    auto const NodeStmt = HoverNodeIt != Nodes.end() ? HoverNodeIt->Statement
                                                     : nullptr;
    
    Recording->recordEventL("StateEvaluationTree.NodeHover",
                            make_attribute("node", NodeIndex),
                            make_attribute("stmt", NodeStmt));
  }
  
  showHoverTooltip(*HoverNodeIt);
}
Esempio n. 6
0
void PlayerCharacter::setLevel(int levelReached, bool display)
{
  m_attributes["level"] = make_attribute(levelReached);

  std::map<std::string, Attribute> attributesTemp = m_attributes;

  setAttributes();

  if (levelReached > 0)
  {
    if (display)
      show_message("%s has reached level %d!", getName().c_str(), levelReached);

    std::string buffer;

    for (auto it = m_attributes.begin(); it != m_attributes.end(); ++it)
    {
      int increase = it->second.max - attributesTemp[it->first].max;

      if (it->first != "level" && it->first != "exp")
        buffer += capitalize(it->first) + " +" + toString(increase) + "! ";
    }

    if (display)
      show_message("%s", buffer.c_str());

    if (m_class.spells.count(levelReached) > 0)
    {
      auto it = m_class.spells.find(levelReached);

      for (auto spellIt = it->second.begin(); spellIt != it->second.end(); ++spellIt)
      {
        if (std::find(m_spells.begin(), m_spells.end(), *spellIt) == m_spells.end())
        {
          m_spells.push_back(*spellIt);
          if (display)
            show_message("%s learned %s!", getName().c_str(), spellIt->c_str());
        }
      }
    }
  }
}
Esempio n. 7
0
int
exmpp_xml_cb_make_attributes(struct exmpp_xml_ctx *ctx, void *attributes)
{
	int i, ns_len;
	const char *real_attr, *ns;
	const char **attrs;

	if (attributes == NULL)
		return (0);

	i = 0;
	attrs = (const char **)attributes;

	while (attrs[i] != NULL) {
		/* With Expat, we must extract the namespace from the
		 * attribute's name. */
		real_attr = strchr(attrs[i], NS_SEP);
		if (real_attr != NULL) {
			/* This element has a namespace. */
			ns = attrs[i];
			ns_len = real_attr - attrs[i];
			real_attr++;
		} else {
			ns = NULL;
			ns_len = 0;
			real_attr = attrs[i];
		}

		make_attribute(ctx,
		    ns, ns_len,
		    real_attr, strlen(real_attr),
		    attrs[i + 1], strlen(attrs[i + 1]));

		i += 2;
	}

	return (0);
}
Esempio n. 8
0
void
StateGraphViewerPanel::
OnMouseOverDisplayable(MouseOverDisplayableEvent const &Ev)
{
  // Remove highlighting from the existing value (if any).
  if (auto const Prev = MouseOver.get()) {
    if (llvm::isa<DisplayableValue>(Prev)) {
      if (auto Access = CurrentAccess->getAccess())
        Notifier->createNotify<ConEvHighlightValue>(nullptr, CurrentAccess);
    }
    else if (llvm::isa<DisplayableDereference>(Prev)) {
      if (auto Access = CurrentAccess->getAccess())
        Notifier->createNotify<ConEvHighlightValue>(nullptr, CurrentAccess);
    }
    else if (llvm::isa<DisplayableFunctionState>(Prev)) {
      Notifier->createNotify<ConEvHighlightDecl>(nullptr);
    }
    else if (llvm::isa<DisplayableLocalState>(Prev)) {
      Notifier->createNotify<ConEvHighlightDecl>(nullptr);
    }
    else if (llvm::isa<DisplayableParamState>(Prev)) {
      Notifier->createNotify<ConEvHighlightDecl>(nullptr);
    }
    else if (llvm::isa<DisplayableGlobalVariable>(Prev)) {
      Notifier->createNotify<ConEvHighlightDecl>(nullptr);
    }
    else if (auto const DA = llvm::dyn_cast<DisplayableReferencedArea>(Prev)) {
      if (auto Access = CurrentAccess->getAccess()) {
        auto const Start = DA->getAreaStart();
        auto const MMalloc = CurrentProcess->getDynamicMemoryAllocation(Start);
        if (MMalloc.assigned<seec::cm::MallocState>()) {
          auto const &Malloc = MMalloc.get<seec::cm::MallocState>();
          if (Malloc.getAllocatorStmt())
            Notifier->createNotify<ConEvHighlightStmt>(nullptr);
        }
      }
    }
  }

  MouseOver = Ev.getDisplayableShared();

  auto const Node = MouseOver.get();

  if (!Node) {
    if (Recording)
      Recording->recordEventL("StateGraphViewer.MouseOverNone");
  }
  else if (auto const DV = llvm::dyn_cast<DisplayableValue>(Node)) {
    if (auto Access = CurrentAccess->getAccess()) {
      Notifier->createNotify<ConEvHighlightValue>(&(DV->getValue()),
                                                  CurrentAccess);
    }

    if (Recording) {
      std::vector<std::unique_ptr<IAttributeReadOnly>> Attrs;
      addAttributesForValue(Attrs, DV->getValue());
      Recording->recordEventV("StateGraphViewer.MouseOverValue", Attrs);
    }
  }
  else if (auto const DD = llvm::dyn_cast<DisplayableDereference>(Node)) {
    if (auto Access = CurrentAccess->getAccess()) {
      Notifier->createNotify<ConEvHighlightValue>(&(DD->getPointer()),
                                                  CurrentAccess);
    }

    if (Recording) {
      std::vector<std::unique_ptr<IAttributeReadOnly>> Attrs;
      addAttributesForValue(Attrs, DD->getPointer());
      Recording->recordEventV("StateGraphViewer.MouseOverDereference", Attrs);
    }
  }
  else if (auto const DF = llvm::dyn_cast<DisplayableFunctionState>(Node)) {
    auto const Decl = DF->getFunctionState().getFunctionDecl();
    Notifier->createNotify<ConEvHighlightDecl>(Decl);

    if (Recording) {
      auto const &FS = DF->getFunctionState();
      Recording->recordEventL("StateGraphViewer.MouseOverFunctionState",
                              make_attribute("function", FS.getNameAsString()));
    }
  }
  else if (auto const DL = llvm::dyn_cast<DisplayableLocalState>(Node)) {
    auto const Decl = DL->getLocalState().getDecl();
    Notifier->createNotify<ConEvHighlightDecl>(Decl);

    if (Recording) {
      // TODO
    }
  }
  else if (auto const DP = llvm::dyn_cast<DisplayableParamState>(Node)) {
    auto const Decl = DP->getParamState().getDecl();
    Notifier->createNotify<ConEvHighlightDecl>(Decl);

    if (Recording) {
      // TODO
    }
  }
  else if (auto const DG = llvm::dyn_cast<DisplayableGlobalVariable>(Node)) {
    auto const Decl = DG->getGlobalVariable().getClangValueDecl();
    Notifier->createNotify<ConEvHighlightDecl>(Decl);

    if (Recording) {
      // TODO
    }
  }
  else if (auto const DA = llvm::dyn_cast<DisplayableReferencedArea>(Node)) {
    if (auto Access = CurrentAccess->getAccess()) {
      auto const Start = DA->getAreaStart();
      auto const MayMalloc = CurrentProcess->getDynamicMemoryAllocation(Start);
      if (MayMalloc.assigned<seec::cm::MallocState>()) {
        auto const &Malloc = MayMalloc.get<seec::cm::MallocState>();
        if (auto const S = Malloc.getAllocatorStmt())
          Notifier->createNotify<ConEvHighlightStmt>(S);
      }
    }

    if (Recording) {
      Recording->recordEventL("StateGraphViewer.MouseOverReferencedArea",
                              make_attribute("start", DA->getAreaStart()),
                              make_attribute("end", DA->getAreaEnd()));
    }
  }
  else {
    wxLogDebug("Mouse over unknown Displayable.");

    if (Recording) {
      Recording->recordEventL("StateGraphViewer.MouseOverUnknown");
    }
  }
}