载入中...
搜索中...
未找到
SettlementRules.cpp
浏览该文件的文档.
84eve::Diagnostic expressionDiagnostic(eve::DiagnosticCode code, std::string message, std::string path,
86 eve::DiagnosticDetails details{{"line", std::to_string(token.line)}, {"column", std::to_string(token.column)}};
89 return eve::Diagnostic::error(code, std::move(message), std::move(path), details, "settlement.condition");
136 expressionDiagnostic(eve::DiagnosticCode::ParseError, "condition contains an invalid number", path,
179 expressionDiagnostic(eve::DiagnosticCode::ParseError, "condition string is not terminated", path,
188 if (pair == "&&" || pair == "||" || pair == "==" || pair == "!=" || pair == "<=" || pair == ">=") {
198 expressionDiagnostic(eve::DiagnosticCode::ParseError, "condition contains an unsupported character",
236 if (!accept(text)) fail("condition expected '" + std::string(text) + "'", std::string(text), current().text);
241 error_ = expressionDiagnostic(eve::DiagnosticCode::ParseError, std::move(message), path_, current(),
254 std::uint16_t binary(ExpressionKind kind, ExpressionType result, std::uint16_t left, std::uint16_t right,
261 eve::DiagnosticCode::TypeMismatch, "condition operator has incompatible operands", path_, operation,
262 typeName(operand), std::string(typeName(nodes_[left].type)) + "," + typeName(nodes_[right].type));
269 if (nodes_[index].type == ExpressionType::Unknown && nodes_[index].kind == ExpressionKind::Field)
320 left = add(ExpressionNode{operation.text == "==" ? ExpressionKind::Equal : ExpressionKind::NotEqual,
329 (current().text == "<" || current().text == "<=" || current().text == ">" || current().text == ">=")) {
351 binary(operation.text == "+" ? ExpressionKind::Add : ExpressionKind::Subtract, ExpressionType::Number,
395 ExpressionNode{operation.text == "!" ? ExpressionKind::Not : ExpressionKind::Negate, expected, child});
413 error_ = expressionDiagnostic(eve::DiagnosticCode::TypeMismatch, "has_tag expects one string literal",
422 if ((name != "min" && name != "max" && name != "clamp" && name != "abs") || arguments.size() != arity) {
432 expressionDiagnostic(eve::DiagnosticCode::TypeMismatch, "numeric function received a non-number",
477 fail("condition expected a literal, field, function, or parenthesized expression", "expression",
494 else if (!token.text.starts_with("context.") || token.text.size() == std::string_view("context.").size()) {
495 error_ = expressionDiagnostic(eve::DiagnosticCode::NotFound, "condition references an unknown field", path_,
516eve::Result<EvaluatedValue> evaluationFailure(eve::DiagnosticCode code, std::string message, std::string path) {
553 const bool present = std::find(request.tags.begin(), request.tags.end(), node.name) != request.tags.end();
585 return evaluationFailure(eve::DiagnosticCode::TypeMismatch, "condition context field is not String",
614 if (node.kind == ExpressionKind::And && !left.boolean) return eve::Result<EvaluatedValue>::success(std::move(left));
615 if (node.kind == ExpressionKind::Or && left.boolean) return eve::Result<EvaluatedValue>::success(std::move(left));
635 return evaluationFailure(eve::DiagnosticCode::InvalidArgument, "condition attempted division by zero",
701 return evaluationFailure(eve::DiagnosticCode::InvalidArgument, "condition produced a non-finite number",
727eve::Result<CompiledExpression> compileExpression(std::string_view source, const std::string& path) {
731 expressionDiagnostic(eve::DiagnosticCode::InvalidArgument, "condition exceeds the source length limit",
766 if (!accepted.value()) return eve::Result<void>::success(eve::Status::success(eve::StatusCode::NoOp));
768 const double operand = rule.value + rule.valuePerExtraStack * static_cast<double>(rule.stacks - 1);
788 case RuleOperation::Critical: context.setCritical(operand != 0.0); return eve::Result<void>::success();
814 return eve::Result<void>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvariantViolation,
823 if (!conditionDigest.empty()) context.setStageDetail("condition_digest", eve::Value(conditionDigest));
840 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "settlement rule id must not be empty", path + ".id"));
842 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "settlement rule ids must be unique", path + ".id"));
844 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "settlement rule stack count must be positive", path + ".stacks"));
847 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "settlement rule operands must be finite", path + ".value"));
848 if (rule.stage == StageKind::Validate || rule.stage == StageKind::Apply || rule.stage == StageKind::Event)
850 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "settlement rule cannot mutate a terminal or validation phase", path + ".stage"));
853 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "decision-stage rules currently support only immune outcomes", path + ".operation"));
856 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "immune rules must run in the decision stage", path + ".stage"));
861 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "trigger-stage rules require a derived-request operation", path + ".operation"));
864 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "derived-request rules must run in the trigger stage", path + ".stage"));
865 if ((rule.operation == RuleOperation::Multiply || rule.operation == RuleOperation::ResistFlat ||
870 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "settlement rule operation requires non-negative operands", path + ".value"));
875 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "settlement resistance percentage must remain in [0,1]", path + ".value"));
Declarative, domain-neutral rules for buffs and gameplay effects.
A structured explanation of a failed, degraded, or noteworthy result.
Definition Diagnostic.h:94
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.cpp:21
const Status & status() const noexcept
Inspect the structured operation status.
Definition Result.h:521
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.cpp:19
const T * getIf() const noexcept
Return a typed pointer, or nullptr when the kind differs.
Definition Value.h:209
Value * find(const std::string &key) noexcept
Return an object member, or nullptr when absent.
Definition Value.cpp:244
Mutable calculation frame visible to policy and custom stage code.
Definition Settlement.h:338
Deterministically ordered, composable settlement pipeline.
Definition Settlement.h:542
eve::Result< void > addStage(StageKind kind, std::string name, int priority, StageFunction function)
Add one named custom stage; duplicate names are rejected.
Definition Settlement.cpp:656
eve::Result< void > configure(std::vector< SettlementRule > rules)
Atomically replace all rules after validating ids, operands and phases.
Definition SettlementRules.cpp:830
eve::Result< void > install(SettlementPipeline &pipeline) const
Install a stable snapshot as custom stages on a pipeline.
Definition SettlementRules.cpp:899
Result< T > fail(std::string message, DiagnosticCode code=DiagnosticCode::InvalidArgument)
Definition BuildingAssemblyInternal.h:35
@ GreaterEqual
@ LessEqual
@ Number
Unsigned numeric literal; sign handling belongs to the parser.
@ Absolute
constexpr HexDirection next(HexDirection d) noexcept
The next direction clockwise (NW wraps to NE).
Definition HexMetrics.h:76
ForceVector add(ForceVector a, ForceVector b)
Definition ForceMath.h:13
ShapeState * child(const JPH::Body &body, const JPH::SubShapeID &id)
Resolves a native child record for a synchronous callback or query. @ownership Borrowed from the worl...
Definition JoltInternal.h:138
Definition Settlement.cpp:11
@ Critical
@ ClampMaximum
@ ResistPercent
@ AbsorbFlat
@ ResistFlat
@ Lifesteal
@ Multiply
@ Decision
@ Validate
@ Trigger
std::vector< DiagnosticDetail > DiagnosticDetails
Owning collection of diagnostic details with stable insertion order.
Definition Diagnostic.h:88
@ InvalidArgument
@ TypeMismatch
A stable reference resolved to a different canonical domain type.
@ NotFound
@ PreconditionViolation
@ InvariantViolation
@ ParseError
@ NoOp
@ Applied
@ Unknown
Definition Container.h:602
Domain-neutral input to one settlement operation.
Definition Settlement.h:107
One owning, serializable projection of a buff/effect contribution.
Definition SettlementRules.h:54