Skip to content

Commit

Permalink
removed all old min/max functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lologarithm committed Sep 29, 2023
1 parent 3eff6aa commit 4e6431d
Show file tree
Hide file tree
Showing 72 changed files with 137 additions and 181 deletions.
2 changes: 1 addition & 1 deletion cmd/wowsimcli/cmd/decode_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"fmt"
"strings"

goproto "github.com/golang/protobuf/proto"
"github.com/spf13/cobra"
"github.com/wowsims/wotlk/sim/core/proto"
"google.golang.org/protobuf/encoding/protojson"
goproto "google.golang.org/protobuf/proto"
)

var decodeLinkCmd = &cobra.Command{
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ module github.com/wowsims/wotlk
go 1.21

require (
github.com/golang/protobuf v1.5.3
github.com/google/go-cmp v0.5.8
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
github.com/satori/go.uuid v1.2.0
github.com/spf13/cobra v1.7.0
github.com/tailscale/hujson v0.0.0-20221223112325-20486734a56a
golang.org/x/exp v0.0.0-20221028150844-83b7d23a625f
google.golang.org/protobuf v1.30.0
google.golang.org/protobuf v1.31.0
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
2 changes: 1 addition & 1 deletion sim/common/tbc/melee_items.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func init() {
})
}

numHits := core.MinInt32(5, character.Env.GetNumTargets())
numHits := min(5, character.Env.GetNumTargets())
debuffAuras := make([]*core.Aura, len(character.Env.Encounter.TargetUnits))
for i, target := range character.Env.Encounter.TargetUnits {
debuffAuras[i] = makeDebuffAura(target)
Expand Down
4 changes: 2 additions & 2 deletions sim/common/wotlk/other_effects.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func init() {

character.AddDynamicDamageTakenModifier(func(sim *core.Simulation, spell *core.Spell, result *core.SpellResult) {
if procAura.IsActive() {
result.Damage = core.MaxFloat(0, result.Damage-140)
result.Damage = max(0, result.Damage-140)
}
})

Expand Down Expand Up @@ -52,7 +52,7 @@ func init() {

character.AddDynamicDamageTakenModifier(func(sim *core.Simulation, spell *core.Spell, result *core.SpellResult) {
if procAura.IsActive() {
result.Damage = core.MaxFloat(0, result.Damage-205)
result.Damage = max(0, result.Damage-205)
}
})

Expand Down
8 changes: 4 additions & 4 deletions sim/core/apl_values_operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,14 +486,14 @@ func (value *APLValueMax) Type() proto.APLValueType {
func (value *APLValueMax) GetInt(sim *Simulation) int32 {
result := value.vals[0].GetInt(sim)
for i := 1; i < len(value.vals); i++ {
result = MaxInt32(result, value.vals[i].GetInt(sim))
result = max(result, value.vals[i].GetInt(sim))
}
return result
}
func (value *APLValueMax) GetFloat(sim *Simulation) float64 {
result := value.vals[0].GetFloat(sim)
for i := 1; i < len(value.vals); i++ {
result = MaxFloat(result, value.vals[i].GetFloat(sim))
result = max(result, value.vals[i].GetFloat(sim))
}
return result
}
Expand Down Expand Up @@ -537,14 +537,14 @@ func (value *APLValueMin) Type() proto.APLValueType {
func (value *APLValueMin) GetInt(sim *Simulation) int32 {
result := value.vals[0].GetInt(sim)
for i := 1; i < len(value.vals); i++ {
result = MinInt32(result, value.vals[i].GetInt(sim))
result = min(result, value.vals[i].GetInt(sim))
}
return result
}
func (value *APLValueMin) GetFloat(sim *Simulation) float64 {
result := value.vals[0].GetFloat(sim)
for i := 1; i < len(value.vals); i++ {
result = MinFloat(result, value.vals[i].GetFloat(sim))
result = min(result, value.vals[i].GetFloat(sim))
}
return result
}
Expand Down
7 changes: 4 additions & 3 deletions sim/core/attack.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package core

import (
"golang.org/x/exp/slices"
"time"

"golang.org/x/exp/slices"

"github.com/wowsims/wotlk/sim/core/proto"
"github.com/wowsims/wotlk/sim/core/stats"
)
Expand Down Expand Up @@ -294,13 +295,13 @@ func (unit *Unit) EnableAutoAttacks(agent Agent, options AutoAttackOptions) {

if unit.Type == EnemyUnit {
unit.AutoAttacks.MHConfig.ApplyEffects = func(sim *Simulation, target *Unit, spell *Spell) {
ap := MaxFloat(0, spell.Unit.stats[stats.AttackPower])
ap := max(0, spell.Unit.stats[stats.AttackPower])
baseDamage := spell.Unit.AutoAttacks.MH.EnemyWeaponDamage(sim, ap, spell.Unit.PseudoStats.DamageSpread)

spell.CalcAndDealDamage(sim, target, baseDamage, spell.OutcomeEnemyMeleeWhite)
}
unit.AutoAttacks.OHConfig.ApplyEffects = func(sim *Simulation, target *Unit, spell *Spell) {
ap := MaxFloat(0, spell.Unit.stats[stats.AttackPower])
ap := max(0, spell.Unit.stats[stats.AttackPower])
baseDamage := spell.Unit.AutoAttacks.MH.EnemyWeaponDamage(sim, ap, spell.Unit.PseudoStats.DamageSpread) * 0.5

spell.CalcAndDealDamage(sim, target, baseDamage, spell.OutcomeEnemyMeleeWhite)
Expand Down
5 changes: 3 additions & 2 deletions sim/core/aura.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package core

import (
"fmt"
"golang.org/x/exp/constraints"
"math"
"strconv"
"time"

"golang.org/x/exp/constraints"

"github.com/wowsims/wotlk/sim/core/proto"
"github.com/wowsims/wotlk/sim/core/stats"
)
Expand Down Expand Up @@ -183,7 +184,7 @@ func (aura *Aura) SetStacks(sim *Simulation, newStacks int32) {
panic("MaxStacks required to set Aura stacks: " + aura.Label)
}
oldStacks := aura.stacks
newStacks = MinInt32(newStacks, aura.MaxStacks)
newStacks = min(newStacks, aura.MaxStacks)

if oldStacks == newStacks {
return
Expand Down
4 changes: 2 additions & 2 deletions sim/core/buffs.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func applyBuffEffects(agent Agent, raidBuffs *proto.RaidBuffs, partyBuffs *proto
kingsStrStamAmount = 1.1
} else if raidBuffs.DrumsOfForgottenKings {
kingsAgiIntSpiAmount = 1.08
kingsStrStamAmount = MaxFloat(kingsStrStamAmount, 1.08)
kingsStrStamAmount = max(kingsStrStamAmount, 1.08)
}
if kingsStrStamAmount > 0 {
character.MultiplyStat(stats.Strength, kingsStrStamAmount)
Expand Down Expand Up @@ -379,7 +379,7 @@ func ApplyInspiration(character *Character, uptime float64) {
if uptime <= 0 {
return
}
uptime = MinFloat(1, uptime)
uptime = min(1, uptime)

inspirationAura := InspirationAura(&character.Unit, 3)

Expand Down
2 changes: 1 addition & 1 deletion sim/core/bulksim.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"sync/atomic"
"time"

goproto "github.com/golang/protobuf/proto"
goproto "google.golang.org/protobuf/proto"

"github.com/wowsims/wotlk/sim/core/proto"
)
Expand Down
2 changes: 1 addition & 1 deletion sim/core/bulksim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"context"
"testing"

goproto "github.com/golang/protobuf/proto"
"github.com/google/go-cmp/cmp"
"github.com/wowsims/wotlk/sim/core/proto"
goproto "google.golang.org/protobuf/proto"
)

const (
Expand Down
8 changes: 4 additions & 4 deletions sim/core/cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (spell *Spell) makeCastFunc(config CastConfig) CastSuccessFunc {
if spell.CurCast.CastTime > 0 {
if sim.Log != nil && !spell.Flags.Matches(SpellFlagNoLogs) {
spell.Unit.Log(sim, "Casting %s (Cost = %0.03f, Cast Time = %s, Effective Time = %s)",
spell.ActionID, MaxFloat(0, spell.CurCast.Cost), spell.CurCast.CastTime, spell.CurCast.EffectiveTime())
spell.ActionID, max(0, spell.CurCast.Cost), spell.CurCast.CastTime, spell.CurCast.EffectiveTime())
}

spell.Unit.Hardcast = Hardcast{
Expand Down Expand Up @@ -177,7 +177,7 @@ func (spell *Spell) makeCastFunc(config CastConfig) CastSuccessFunc {

if sim.Log != nil && !spell.Flags.Matches(SpellFlagNoLogs) {
spell.Unit.Log(sim, "Casting %s (Cost = %0.03f, Cast Time = %s, Effective Time = %s)",
spell.ActionID, MaxFloat(0, spell.CurCast.Cost), spell.CurCast.CastTime, spell.CurCast.EffectiveTime())
spell.ActionID, max(0, spell.CurCast.Cost), spell.CurCast.CastTime, spell.CurCast.EffectiveTime())
spell.Unit.Log(sim, "Completed cast %s", spell.ActionID)
}

Expand Down Expand Up @@ -260,6 +260,6 @@ func (spell *Spell) makeCastFuncAutosOrProcs() CastSuccessFunc {

func (spell *Spell) ApplyCostModifiers(cost float64) float64 {
cost -= spell.Unit.PseudoStats.CostReduction
cost = MaxFloat(0, cost*spell.Unit.PseudoStats.CostMultiplier)
return MaxFloat(0, cost*spell.CostMultiplier)
cost = max(0, cost*spell.Unit.PseudoStats.CostMultiplier)
return max(0, cost*spell.CostMultiplier)
}
2 changes: 1 addition & 1 deletion sim/core/dot.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (dot *Dot) MaxTicksRemaining() int32 {
func (dot *Dot) NumTicksRemaining(sim *Simulation) int {
maxTicksRemaining := dot.MaxTicksRemaining()
finalTickAt := dot.lastTickTime + dot.tickPeriod*time.Duration(maxTicksRemaining)
return MaxInt(0, int((finalTickAt-sim.CurrentTime)/dot.tickPeriod)+1)
return max(0, int((finalTickAt-sim.CurrentTime)/dot.tickPeriod)+1)
}

// Roll over = gets carried over with everlasting refresh and doesn't get applied if triggered when the spell is already up.
Expand Down
6 changes: 3 additions & 3 deletions sim/core/energy.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (unit *Unit) EnableEnergyBar(maxEnergy float64, onEnergyGain OnEnergyGain)

unit.energyBar = energyBar{
unit: unit,
maxEnergy: MaxFloat(100, maxEnergy),
maxEnergy: max(100, maxEnergy),
onEnergyGain: func(sim *Simulation) {
if !sim.Options.Interactive && (!unit.IsWaitingForEnergy() || unit.DoneWaitingForEnergy(sim)) {
if unit.IsUsingAPL {
Expand Down Expand Up @@ -69,7 +69,7 @@ func (eb *energyBar) addEnergyInternal(sim *Simulation, amount float64, metrics
panic("Trying to add negative energy!")
}

newEnergy := MinFloat(eb.currentEnergy+amount, eb.maxEnergy)
newEnergy := min(eb.currentEnergy+amount, eb.maxEnergy)
metrics.AddEvent(amount, newEnergy-eb.currentEnergy)

if sim.Log != nil {
Expand Down Expand Up @@ -114,7 +114,7 @@ func (eb *energyBar) ResetEnergyTick(sim *Simulation) {
}

func (eb *energyBar) AddComboPoints(sim *Simulation, pointsToAdd int32, metrics *ResourceMetrics) {
newComboPoints := MinInt32(eb.comboPoints+pointsToAdd, 5)
newComboPoints := min(eb.comboPoints+pointsToAdd, 5)
metrics.AddEvent(float64(pointsToAdd), float64(newComboPoints-eb.comboPoints))

if sim.Log != nil {
Expand Down
4 changes: 2 additions & 2 deletions sim/core/focus.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (fb *focusBar) AddFocus(sim *Simulation, amount float64, actionID ActionID)
panic("Trying to add negative focus!")
}

newFocus := MinFloat(fb.currentFocus+amount, MaxFocus)
newFocus := min(fb.currentFocus+amount, MaxFocus)

if sim.Log != nil {
fb.unit.Log(sim, "Gained %0.3f focus from %s (%0.3f --> %0.3f).", amount, actionID, fb.currentFocus, newFocus)
Expand Down Expand Up @@ -119,7 +119,7 @@ func newFocusCost(spell *Spell, options FocusCostOptions) *FocusCost {
}

func (fc *FocusCost) MeetsRequirement(spell *Spell) bool {
spell.CurCast.Cost = MaxFloat(0, spell.CurCast.Cost*spell.Unit.PseudoStats.CostMultiplier)
spell.CurCast.Cost = max(0, spell.CurCast.Cost*spell.Unit.PseudoStats.CostMultiplier)
return spell.Unit.CurrentFocus() >= spell.CurCast.Cost
}
func (fc *FocusCost) LogCostFailure(sim *Simulation, spell *Spell) {
Expand Down
6 changes: 3 additions & 3 deletions sim/core/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (hb *healthBar) GainHealth(sim *Simulation, amount float64, metrics *Resour
}

oldHealth := hb.currentHealth
newHealth := MinFloat(oldHealth+amount, hb.unit.MaxHealth())
newHealth := min(oldHealth+amount, hb.unit.MaxHealth())
metrics.AddEvent(amount, newHealth-oldHealth)

if sim.Log != nil {
Expand All @@ -67,7 +67,7 @@ func (hb *healthBar) RemoveHealth(sim *Simulation, amount float64) {
}

oldHealth := hb.currentHealth
newHealth := MaxFloat(oldHealth-amount, 0)
newHealth := max(oldHealth-amount, 0)
metrics := hb.DamageTakenHealthMetrics
metrics.AddEvent(-amount, newHealth-oldHealth)

Expand Down Expand Up @@ -151,7 +151,7 @@ func (character *Character) applyHealingModel(healingModel *proto.HealingModel)
if medianCadence == 0 {
medianCadence = 2.0
}
minCadence := MaxFloat(0.0, medianCadence-healingModel.CadenceVariation)
minCadence := max(0.0, medianCadence-healingModel.CadenceVariation)
cadenceVariationLow := medianCadence - minCadence

healthMetrics := character.NewHealthMetrics(ActionID{OtherID: proto.OtherAction_OtherActionHealingModel})
Expand Down
8 changes: 4 additions & 4 deletions sim/core/mana.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (unit *Unit) AddMana(sim *Simulation, amount float64, metrics *ResourceMetr
}

oldMana := unit.CurrentMana()
newMana := MinFloat(oldMana+amount, unit.MaxMana())
newMana := min(oldMana+amount, unit.MaxMana())
metrics.AddEvent(amount, newMana-oldMana)

if sim.Log != nil {
Expand Down Expand Up @@ -194,10 +194,10 @@ func (unit *Unit) UpdateManaRegenRates() {
func (unit *Unit) ManaTick(sim *Simulation) {
if sim.CurrentTime < unit.PseudoStats.FiveSecondRuleRefreshTime {
regen := unit.manaTickWhileCasting
unit.AddMana(sim, MaxFloat(0, regen), unit.manaCastingMetrics)
unit.AddMana(sim, max(0, regen), unit.manaCastingMetrics)
} else {
regen := unit.manaTickWhileNotCasting
unit.AddMana(sim, MaxFloat(0, regen), unit.manaNotCastingMetrics)
unit.AddMana(sim, max(0, regen), unit.manaNotCastingMetrics)
}
}

Expand Down Expand Up @@ -307,7 +307,7 @@ func newManaCost(spell *Spell, options ManaCostOptions) *ManaCost {
baseCost := TernaryFloat64(options.FlatCost > 0, options.FlatCost, options.BaseCost*spell.Unit.BaseMana)
if player := spell.Unit.Env.Raid.GetPlayerFromUnit(spell.Unit); player != nil {
if player.GetCharacter().HasTrinketEquipped(45703) { // Spark of Hope
baseCost = MaxFloat(0, baseCost-44)
baseCost = max(0, baseCost-44)
}
}

Expand Down
6 changes: 3 additions & 3 deletions sim/core/rage.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (unit *Unit) EnableRageBar(options RageBarOptions, onRageGain OnRageGain) {
}

// generatedRage is capped for very low damage swings
generatedRage := MinFloat((damage*7.5/RageFactor+hitFactor*speed)/2, damage*15/RageFactor)
generatedRage := min((damage*7.5/RageFactor+hitFactor*speed)/2, damage*15/RageFactor)

generatedRage *= options.RageMultiplier

Expand Down Expand Up @@ -101,7 +101,7 @@ func (unit *Unit) EnableRageBar(options RageBarOptions, onRageGain OnRageGain) {

unit.rageBar = rageBar{
unit: unit,
startingRage: MaxFloat(0, MinFloat(options.StartingRage, MaxRage)),
startingRage: max(0, min(options.StartingRage, MaxRage)),
onRageGain: onRageGain,

RageRefundMetrics: unit.NewRageMetrics(ActionID{OtherID: proto.OtherAction_OtherActionRefund}),
Expand All @@ -121,7 +121,7 @@ func (rb *rageBar) AddRage(sim *Simulation, amount float64, metrics *ResourceMet
panic("Trying to add negative rage!")
}

newRage := MinFloat(rb.currentRage+amount, MaxRage)
newRage := min(rb.currentRage+amount, MaxRage)
metrics.AddEvent(amount, newRage-rb.currentRage)

if sim.Log != nil {
Expand Down
4 changes: 2 additions & 2 deletions sim/core/raid.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func NewRaid(raidConfig *proto.Raid) *Raid {
}
}

numDummies := MinInt(24, int(raidConfig.TargetDummies))
numDummies := min(24, int(raidConfig.TargetDummies))
for i := 0; i < numDummies; i++ {
party, partyIndex := raid.GetFirstEmptyRaidIndex()
dummy := NewTargetDummy(i, party, partyIndex)
Expand Down Expand Up @@ -383,7 +383,7 @@ func (raid *Raid) GetPlayerFromUnit(unit *Unit) Agent {
}

func (raid *Raid) GetFirstNPlayersOrPets(n int32) []*Unit {
return raid.AllUnits[:MinInt32(n, int32(len(raid.AllUnits)))]
return raid.AllUnits[:min(n, int32(len(raid.AllUnits)))]
}

func (raid *Raid) GetPlayerFromUnitIndex(unitIndex int32) Agent {
Expand Down
2 changes: 1 addition & 1 deletion sim/core/runic_power.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (rp *runicPowerBar) addRunicPowerInterval(sim *Simulation, amount float64,
panic("Trying to add negative runic power!")
}

newRunicPower := MinFloat(rp.currentRunicPower+amount, rp.maxRunicPower)
newRunicPower := min(rp.currentRunicPower+amount, rp.maxRunicPower)

metrics.AddEvent(amount, newRunicPower-rp.currentRunicPower)

Expand Down
2 changes: 1 addition & 1 deletion sim/core/spell.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (unit *Unit) RegisterSpell(config SpellConfig) *Spell {
ThreatMultiplier: config.ThreatMultiplier,
FlatThreatBonus: config.FlatThreatBonus,

splitSpellMetrics: make([][]SpellMetrics, MaxInt(1, config.MetricSplits)),
splitSpellMetrics: make([][]SpellMetrics, max(1, config.MetricSplits)),

RelatedAuras: config.RelatedAuras,
}
Expand Down
Loading

0 comments on commit 4e6431d

Please sign in to comment.