refactor: floats, tests

This commit is contained in:
Ilia Denisov
2026-02-04 18:33:38 +02:00
parent 9d46abe805
commit 6a603ea9ad
37 changed files with 381 additions and 722 deletions
+20 -20
View File
@@ -73,7 +73,7 @@ func (c *Cache) InitReport(t uint) *mr.Report {
if vi := slices.IndexFunc(c.g.Race, func(v game.Race) bool { return r.VoteFor == v.ID }); vi < 0 {
panic(fmt.Sprintf("voting for unknown race, id=%v", r.VoteFor))
} else {
sumVote[vi] += r.Votes
sumVote[vi] += r.Votes.F()
dest := &report.Player[vi]
dest.Votes = mr.F(sumVote[vi])
}
@@ -110,7 +110,7 @@ func (c *Cache) ReportRace(ri int, rep *mr.Report, battles []*mr.BattleReport, b
// votes based on population
// TODO: check vote values was previously calculated
rep.Votes = mr.F(r.Votes)
rep.Votes = mr.F(r.Votes.F())
// relations
for i := range r.Relations {
@@ -185,10 +185,10 @@ func (c *Cache) ReportLocalScience(ri int, rep *mr.Report) {
for i := range r.Sciences {
sliceIndexValidate(&rep.LocalScience, i)
rep.LocalScience[i].Name = r.Sciences[i].Name
rep.LocalScience[i].Drive = mr.F(r.Sciences[i].Drive)
rep.LocalScience[i].Weapons = mr.F(r.Sciences[i].Weapons)
rep.LocalScience[i].Shields = mr.F(r.Sciences[i].Shields)
rep.LocalScience[i].Cargo = mr.F(r.Sciences[i].Cargo)
rep.LocalScience[i].Drive = mr.F(r.Sciences[i].Drive.F())
rep.LocalScience[i].Weapons = mr.F(r.Sciences[i].Weapons.F())
rep.LocalScience[i].Shields = mr.F(r.Sciences[i].Shields.F())
rep.LocalScience[i].Cargo = mr.F(r.Sciences[i].Cargo.F())
}
slices.SortFunc(rep.LocalScience, func(a, b mr.Science) int { return cmp.Compare(a.Name, b.Name) })
@@ -215,10 +215,10 @@ func (c *Cache) ReportOtherScience(ri int, rep *mr.Report) {
sliceIndexValidate(&rep.OtherScience, i)
rep.OtherScience[i].Name = owner.Name
rep.OtherScience[i].Drive = mr.F(sc.Drive)
rep.OtherScience[i].Weapons = mr.F(sc.Weapons)
rep.OtherScience[i].Shields = mr.F(sc.Shields)
rep.OtherScience[i].Cargo = mr.F(sc.Cargo)
rep.OtherScience[i].Drive = mr.F(sc.Drive.F())
rep.OtherScience[i].Weapons = mr.F(sc.Weapons.F())
rep.OtherScience[i].Shields = mr.F(sc.Shields.F())
rep.OtherScience[i].Cargo = mr.F(sc.Cargo.F())
i++
}
@@ -236,11 +236,11 @@ func (c *Cache) ReportLocalShipClass(ri int, report *mr.Report) {
for st := range c.ListShipTypes(ri) {
sliceIndexValidate(&report.LocalShipClass, i)
report.LocalShipClass[i].Name = st.Name
report.LocalShipClass[i].Drive = mr.F(st.Drive)
report.LocalShipClass[i].Drive = mr.F(st.Drive.F())
report.LocalShipClass[i].Armament = st.Armament
report.LocalShipClass[i].Weapons = mr.F(st.Weapons)
report.LocalShipClass[i].Shields = mr.F(st.Shields)
report.LocalShipClass[i].Cargo = mr.F(st.Cargo)
report.LocalShipClass[i].Weapons = mr.F(st.Weapons.F())
report.LocalShipClass[i].Shields = mr.F(st.Shields.F())
report.LocalShipClass[i].Cargo = mr.F(st.Cargo.F())
report.LocalShipClass[i].Mass = mr.F(st.EmptyMass())
i++
}
@@ -308,11 +308,11 @@ func (c *Cache) ReportOtherShipClass(ri int, rep *mr.Report) {
sliceIndexValidate(&rep.OtherShipClass, i)
rep.OtherShipClass[i].Race = c.g.Race[c.RaceIndex(sg.OwnerID)].Name
rep.OtherShipClass[i].Name = st.Name
rep.OtherShipClass[i].Drive = mr.F(st.Drive)
rep.OtherShipClass[i].Drive = mr.F(st.Drive.F())
rep.OtherShipClass[i].Armament = st.Armament
rep.OtherShipClass[i].Weapons = mr.F(st.Weapons)
rep.OtherShipClass[i].Shields = mr.F(st.Shields)
rep.OtherShipClass[i].Cargo = mr.F(st.Cargo)
rep.OtherShipClass[i].Weapons = mr.F(st.Weapons.F())
rep.OtherShipClass[i].Shields = mr.F(st.Shields.F())
rep.OtherShipClass[i].Cargo = mr.F(st.Cargo.F())
rep.OtherShipClass[i].Mass = mr.F(st.EmptyMass())
i++
}
@@ -543,7 +543,7 @@ func (c *Cache) ReportShipProduction(ri int, rep *mr.Report) {
rep.ShipProduction[pi].Free = mr.F(free)
// FIXME: take logic from [ProduceShip] and test at [controller_test.TestProduceShip]
rep.ShipProduction[pi].Wasted = mr.F(free * *p.Production.Progress)
rep.ShipProduction[pi].Wasted = mr.F(free * (*p.Production.Progress).F())
i++
}
}
@@ -717,7 +717,7 @@ func (c *Cache) otherGroup(v *mr.OtherGroup, sg *game.ShipGroup, st *game.ShipTy
v.Class = st.Name
// rep.LocalGroup[i].Tech = make(map[string]mr.Float)
for t, val := range sg.Tech {
v.Tech[t.String()] = mr.F(val)
v.Tech[t.String()] = mr.F(val.F())
}
v.Cargo = sg.CargoString()
v.Load = mr.F(sg.Load.F())