Skip to content

Commit

Permalink
slightly improved error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dschu012 committed Jun 21, 2024
1 parent 7e96630 commit 0300e51
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 135 deletions.
4 changes: 2 additions & 2 deletions Action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,12 @@ void MinimapIconAction::SetResult(ActionResult& action, Unit* pItem) const {
action.nMinimapIconPaletteIndex = m_PaletteIndex;
}

void WeightAction::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void WeightAction::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
for (auto stat : CustomStats) {
replace(m_Value, stat.first, stat.second);
}
m_Expression = Parser::Parse(m_Value.c_str());
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
}

void WeightAction::SetResult(ActionResult& action, Unit* pItem) const {
Expand Down
4 changes: 2 additions & 2 deletions Action.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Action {
Action(std::wstring_view value = {}, ActionType type = ActionType::NONE) : m_Value(value), m_Type(type) {};
virtual ~Action() = default;
ActionType GetType() const { return m_Type; }
virtual void Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {};
virtual void Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {};
virtual void SetResult(ActionResult& action, Unit* pItem) const = 0;
};

Expand Down Expand Up @@ -175,7 +175,7 @@ class WeightAction : public Action {
std::unique_ptr<Expression> m_Expression;
public:
WeightAction(std::wstring_view value = L"") : Action(value, ActionType::WEIGHT) {};
void Initialize(const utility::string_umap<std::wstring, int32_t>& variables) override;
void Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) override;
void SetResult(ActionResult& action, Unit* pItem) const override;

static std::unique_ptr<Action> MakeInstance(std::wstring_view value = {}) { return std::make_unique<WeightAction>(value); }
Expand Down
120 changes: 60 additions & 60 deletions Condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ bool CodeCondition::Evaluate(Unit* pItem) {
return m_Expression->Evaluate(pItem);
}

void CodeCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void CodeCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool TypeCondition::Evaluate(Unit* pItem) {
m_Left.SetValue(GetItemsTxt(pItem)->dwCode);
return m_Expression->Evaluate(pItem);
}

void TypeCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void TypeCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool PlayerClassCondition::Evaluate(Unit* pItem) {
Expand All @@ -29,48 +29,48 @@ bool PlayerClassCondition::Evaluate(Unit* pItem) {
return m_Expression->Evaluate(pItem);
}

void PlayerClassCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void PlayerClassCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool ClassCondition::Evaluate(Unit* pItem) {
return m_Expression->Evaluate(pItem);
}

void ClassCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void ClassCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::ParseCall(m_Value.c_str(), Token::CLASS);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool RarityCondition::Evaluate(Unit* pItem) {
m_Left.SetValue(static_cast<int32_t>(pItem->pItemData->dwRarity));
return m_Expression->Evaluate(pItem);
}

void RarityCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void RarityCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool EtherealCondition::Evaluate(Unit* pItem) {
m_Left.SetValue((pItem->pItemData->dwItemFlags & ItemFlags::ETHEREAL) == ItemFlags::ETHEREAL);
return m_Expression->Evaluate(pItem);
}

void EtherealCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void EtherealCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool RunewordCondition::Evaluate(Unit* pItem) {
m_Left.SetValue((pItem->pItemData->dwItemFlags & ItemFlags::RUNEWORD) == ItemFlags::RUNEWORD);
return m_Expression->Evaluate(pItem);
}

void RunewordCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void RunewordCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool PrefixCondition::Evaluate(Unit* pItem) {
Expand All @@ -87,9 +87,9 @@ bool PrefixCondition::Evaluate(Unit* pItem) {
return false;
}

void PrefixCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void PrefixCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool SuffixCondition::Evaluate(Unit* pItem) {
Expand All @@ -106,58 +106,58 @@ bool SuffixCondition::Evaluate(Unit* pItem) {
return false;
}

void SuffixCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void SuffixCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool ItemLevelCondition::Evaluate(Unit* pItem) {
m_Left.SetValue(pItem->pItemData->dwItemLevel);
return m_Expression->Evaluate(pItem);
}

void ItemLevelCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void ItemLevelCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool QualityCondition::Evaluate(Unit* pItem) {
m_Left.SetValue(GetQualityLevel(pItem));
return m_Expression->Evaluate(pItem);
}

void QualityCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void QualityCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool AreaLevelCondition::Evaluate(Unit* pItem) {
return false;
}

void AreaLevelCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void AreaLevelCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool CharacterLevelCondition::Evaluate(Unit* pItem) {
m_Left.SetValue(D2COMMON_STATLIST_GetUnitStatUnsigned(D2CLIENT_GetPlayerUnit(), Stat::LEVEL, 0));
return m_Expression->Evaluate(pItem);
}

void CharacterLevelCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void CharacterLevelCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool DifficultyCondition::Evaluate(Unit* pItem) {
m_Left.SetValue(D2CLIENT_GetDifficulty());
return m_Expression->Evaluate(pItem);
}

void DifficultyCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void DifficultyCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool RuneCondition::Evaluate(Unit* pItem) {
Expand All @@ -169,19 +169,19 @@ bool RuneCondition::Evaluate(Unit* pItem) {
return m_Expression->Evaluate(pItem);
}

void RuneCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void RuneCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool IdCondition::Evaluate(Unit* pItem) {
m_Left.SetValue(pItem->dwLineId);
return m_Expression->Evaluate(pItem);
}

void IdCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void IdCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool GoldCondition::Evaluate(Unit* pItem) {
Expand All @@ -192,51 +192,51 @@ bool GoldCondition::Evaluate(Unit* pItem) {
return m_Expression->Evaluate(pItem);
}

void GoldCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void GoldCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool StatsCondition::Evaluate(Unit* pItem) {
return m_Expression->Evaluate(pItem);
}

void StatsCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void StatsCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
for (const auto& stat : CustomStats) {
replace(m_Value, stat.first, stat.second);
}
m_Expression = Parser::Parse(m_Value.c_str());
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool DefenseCondition::Evaluate(Unit* pItem) {
m_Left.SetValue(D2COMMON_STATLIST_GetUnitStatUnsigned(pItem, Stat::ARMORCLASS, 0));
return m_Expression->Evaluate(pItem);
}

void DefenseCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void DefenseCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool ArmorCondition::Evaluate(Unit* pItem) {
m_Left.SetValue(D2COMMON_ITEMS_CheckItemTypeId(pItem, ItemType::ANY_ARMOR));
return m_Expression->Evaluate(pItem);
}

void ArmorCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void ArmorCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool WeaponCondition::Evaluate(Unit* pItem) {
m_Left.SetValue(D2COMMON_ITEMS_CheckItemTypeId(pItem, ItemType::WEAPON));
return m_Expression->Evaluate(pItem);
}

void WeaponCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void WeaponCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool PriceCondition::Evaluate(Unit* pItem) {
Expand All @@ -249,68 +249,68 @@ bool PriceCondition::Evaluate(Unit* pItem) {
return false;
}

void PriceCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void PriceCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool ModeCondition::Evaluate(Unit* pItem) {
return false;
}

void ModeCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void ModeCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool IdentifiedCondition::Evaluate(Unit* pItem) {
m_Left.SetValue((pItem->pItemData->dwItemFlags & ItemFlags::IDENTIFIED) == ItemFlags::IDENTIFIED);
return m_Expression->Evaluate(pItem);
}

void IdentifiedCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void IdentifiedCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool SocketsCondition::Evaluate(Unit* pItem) {
m_Left.SetValue(D2COMMON_STATLIST_GetUnitStatUnsigned(pItem, Stat::ITEM_NUMSOCKETS, 0));
return m_Expression->Evaluate(pItem);
}

void SocketsCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void SocketsCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool WidthCondition::Evaluate(Unit* pItem) {
m_Left.SetValue(GetItemsTxt(pItem)->nInvWidth);
return m_Expression->Evaluate(pItem);
}

void WidthCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void WidthCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool HeightCondition::Evaluate(Unit* pItem) {
m_Left.SetValue(GetItemsTxt(pItem)->nInvHeight);
return m_Expression->Evaluate(pItem);
}

void HeightCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void HeightCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool RandomCondition::Evaluate(Unit* pItem) {
m_Left.SetValue(rand() % 100); //random between 0-99
return m_Expression->Evaluate(pItem);
}

void RandomCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void RandomCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool OwnedCondition::Evaluate(Unit* pItem) {
Expand Down Expand Up @@ -355,17 +355,17 @@ bool OwnedCondition::Evaluate(Unit* pItem) {
return m_Expression->Evaluate(pItem);
}

void OwnedCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void OwnedCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
};

bool HasWeightCondition::Evaluate(Unit* pItem) {
m_Left.SetValue(ITEM_ACTIONS[pItem->dwUnitId].nWeight);
return m_Expression->Evaluate(pItem);
}

void HasWeightCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
void HasWeightCondition::Initialize(uint32_t nLineNumber, const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
m_Expression->SetVariables(nLineNumber, variables);
}
Loading

0 comments on commit 0300e51

Please sign in to comment.