Skip to content

Commit

Permalink
feat(simulationcraft): improve meaning of "desired_targets"
Browse files Browse the repository at this point in the history
In SimulationCraft, "desired_targets" is the number of long-lived
enemies that exist for the duration of the fight, and is less than
or equal to "active_enemies", which is the total number of enemies
present. Instead of translating "desired_targets" into
"Enemies(tagged=1)", which is the number of active enemies that the
player has attacked, change it to a custom function that by default
returns 1, but can be modified by a dropdown menu option.

Currently, support 1, 2, or 3 desired targets.

Fixes issue #236.
  • Loading branch information
johnnylam88 committed Dec 27, 2020
1 parent 11ea3a8 commit 9c1a7d8
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
5 changes: 1 addition & 4 deletions src/simulationcraft/definitions.ts
Expand Up @@ -672,10 +672,6 @@ export const MISC_OPERAND: LuaObj<MiscOperand> = {
["demon_soul_fragments"]: {
name: "soulfragments", // GREATER/demon
},
["desired_targets"]: {
name: "enemies",
extraNamedParameter: { name: "tagged", value: 1 },
},
["druid"]: {
name: "checkboxon",
modifiers: {
Expand Down Expand Up @@ -1124,6 +1120,7 @@ export class Annotation implements InterruptAnnotation {

sync?: LuaObj<ActionParseNode>;

desired_targets?: boolean;
using_apl?: LuaObj<boolean>;
currentVariable?: AstAddFunctionNode;
variable: LuaObj<AstAddFunctionNode> = {};
Expand Down
5 changes: 4 additions & 1 deletion src/simulationcraft/emiter.ts
Expand Up @@ -3908,7 +3908,10 @@ export class Emiter {
target = (target && `${target}.`) || "";
operand = lower(operand);
let code;
if (
if (operand == "desired_targets") {
code = `${CamelCase(specialization)}DesiredTargets()`;
annotation.desired_targets = true;
} else if (
className == "DEATHKNIGHT" &&
operand == "dot.breath_of_sindragosa.ticking"
) {
Expand Down
52 changes: 52 additions & 0 deletions src/simulationcraft/generator.ts
Expand Up @@ -21,6 +21,8 @@ import {
import { format } from "@wowts/string";
import { OvaleDataClass } from "../engine/data";

const MAX_DESIRED_TARGETS = 3;

const self_functionDefined: LuaObj<boolean> = {};
const self_functionUsed: LuaObj<boolean> = {};

Expand Down Expand Up @@ -583,6 +585,34 @@ export class Generator {
let count = 0;
const nodeList = annotation.astAnnotation.nodeList;
const camelSpecialization = LowerSpecialization(annotation);
const lowerSpecialization = LowerSpecialization(annotation);
if (annotation.desired_targets) {
const lines: LuaArray<string> = {};
for (let k = MAX_DESIRED_TARGETS; k > 1; k += -1) {
insert(
lines,
`if List(opt_${lowerSpecialization}_desired_targets desired_targets_${k}) ${k}`
);
}
insert(lines, "1");
const fmt = `
AddFunction %sDesiredTargets
{
%s
}
`;
const code = format(fmt, camelSpecialization, concat(lines, "\n"));
const [node] = this.ovaleAst.ParseCode(
"add_function",
code,
nodeList,
annotation.astAnnotation
);
if (node) {
insert(child, 1, node);
count = count + 1;
}
}
if (annotation.melee == "DEATHKNIGHT") {
const fmt = `
AddFunction %sGetInMeleeRange
Expand Down Expand Up @@ -1030,6 +1060,7 @@ export class Generator {
);
}
const nodeList = annotation.astAnnotation.nodeList;
const lowerSpecialization = LowerSpecialization(annotation);
const ifSpecialization = `enabled=(specialization(${annotation.specialization}))`;
if (annotation.using_apl && next(annotation.using_apl)) {
for (const [name] of pairs(annotation.using_apl)) {
Expand Down Expand Up @@ -1060,6 +1091,27 @@ export class Generator {
insert(child, 1, node);
}
}
if (annotation.desired_targets) {
for (let k = MAX_DESIRED_TARGETS; k > 0; k += -1) {
const fmt = "AddListItem(%s %s %s %s%s)";
const code = format(
fmt,
`opt_${lowerSpecialization}_desired_targets`,
`desired_targets_${k}`,
`"Desired targets: ${k}"`,
(k == 1 && "default ") || "",
ifSpecialization
);
const [node] = this.ovaleAst.ParseCode(
"list_item",
code,
nodeList,
annotation.astAnnotation
);
insert(child, 1, node);
count = count + 1;
}
}
if (annotation.options) {
for (const [v] of pairs(annotation.options)) {
const fmt = `
Expand Down

0 comments on commit 9c1a7d8

Please sign in to comment.