fix: ship production math
This commit is contained in:
committed by
Ilia Denisov
parent
9088cc77c9
commit
327f2865d4
+28
-100
@@ -107,17 +107,16 @@ func (c *Cache) PlanetProduction(ri int, number int, prod game.ProductionType, s
|
||||
}
|
||||
|
||||
if p.Production.Type == game.ProductionShip && (prod != game.ProductionShip || *subjectID != *p.Production.SubjectID) {
|
||||
mat, _ := c.MustShipType(ri, *p.Production.SubjectID).ProductionCost()
|
||||
p.Mat(p.Material.F() + mat*(*p.Production.Progress).F())
|
||||
*p.Production.Progress = 0.
|
||||
p.ReleaseMaterial(c.MustShipType(ri, *p.Production.SubjectID).EmptyMass())
|
||||
} else if prod == game.ProductionShip {
|
||||
// new ship class to produce; otherwise we must have been returned from the func earlier
|
||||
progress := game.F(0.)
|
||||
p.Production.Progress = &progress
|
||||
p.Production.Progress = new(game.Float)
|
||||
p.Production.ProdUsed = new(game.Float)
|
||||
}
|
||||
|
||||
if prod != game.ProductionShip {
|
||||
p.Production.Progress = nil
|
||||
p.Production.ProdUsed = nil
|
||||
}
|
||||
|
||||
p.Production.Type = prod
|
||||
@@ -301,105 +300,40 @@ func (c *Cache) putMaterial(pn uint, v float64) {
|
||||
c.MustPlanet(pn).Mat(v)
|
||||
}
|
||||
|
||||
func ProduceShip_old(p *game.Planet, productionAvailable, shipMass float64) uint {
|
||||
if productionAvailable <= 0 {
|
||||
return 0
|
||||
}
|
||||
// CAP_perShip := shipMass / p.Resources.F()
|
||||
CAP_perShip := ShipCapitalCost(shipMass, float64(p.Resources))
|
||||
productionForMass := ShipProductionCost(shipMass)
|
||||
ships := uint(0)
|
||||
flZero := game.F(0.)
|
||||
p.Production.Progress = &flZero
|
||||
for productionAvailable > 0 {
|
||||
var productionExtraCAP float64
|
||||
if CAP_deficit := p.Capital.F() - CAP_perShip; CAP_deficit < 0 {
|
||||
productionExtraCAP = -CAP_deficit
|
||||
}
|
||||
productionCost := productionExtraCAP + productionForMass
|
||||
if productionAvailable >= productionCost {
|
||||
productionAvailable -= productionCost
|
||||
p.Cap(p.Capital.F() - (CAP_perShip - productionExtraCAP))
|
||||
ships++
|
||||
} else {
|
||||
progress := game.F(productionAvailable / productionCost)
|
||||
productionAvailable -= productionCost * progress.F()
|
||||
p.Production.Progress = &progress
|
||||
|
||||
v := (productionForMass + CAP_perShip) * float64(progress)
|
||||
fmt.Println("P=", v)
|
||||
// fmt.Println("productionForMass", productionForMass, "CAP_perShip", CAP_perShip, "productionCost", productionCost, "productionAvailable", productionAvailable, "progress", progress)
|
||||
break
|
||||
}
|
||||
}
|
||||
return ships
|
||||
}
|
||||
|
||||
func ProduceShip(p *game.Planet, productionAvailable, shipMass float64) uint {
|
||||
if productionAvailable <= 0 {
|
||||
return 0
|
||||
}
|
||||
// MAT_perShip := shipMass / p.Resources.F()
|
||||
MAT_perShip := ShipMaterialCost(shipMass, float64(p.Resources))
|
||||
fmt.Println("MAT_perShip", MAT_perShip)
|
||||
productionForMass := ShipProductionCost(shipMass)
|
||||
ships := uint(0)
|
||||
fval := game.F(0.)
|
||||
p.Production.Progress = &fval
|
||||
for productionAvailable > 0 {
|
||||
var productionExtraMAT float64
|
||||
MAT_deficit := float64(p.Material) - MAT_perShip
|
||||
// fmt.Println("> MAT:", p.Material)
|
||||
if MAT_deficit < 0 {
|
||||
productionExtraMAT = (-MAT_deficit)
|
||||
// p.Mat(0)
|
||||
} else {
|
||||
// p.Mat(float64(p.Material) - MAT_deficit)
|
||||
pa := productionAvailable
|
||||
PRODcost := ShipProductionCost(shipMass)
|
||||
var MATneed, MATfarm, totalCost float64
|
||||
for {
|
||||
MATneed = shipMass - float64(p.Material)
|
||||
if MATneed < 0 {
|
||||
MATneed = 0
|
||||
}
|
||||
// fmt.Println("< MAT:", p.Material)
|
||||
productionCost := productionExtraMAT + productionForMass
|
||||
// fmt.Println("ships:", ships, "cost:", productionCost, "avail:", productionAvailable)
|
||||
fmt.Println()
|
||||
fmt.Println("productionExtraMAT", productionExtraMAT)
|
||||
fmt.Println("productionForMass", productionForMass)
|
||||
fmt.Println("productionCost", productionCost)
|
||||
fmt.Println("productionAvailable", productionAvailable)
|
||||
if productionAvailable >= productionCost {
|
||||
productionAvailable -= productionCost
|
||||
// fmt.Println("> MAT:", p.Material)
|
||||
if MAT_deficit < 0 {
|
||||
// productionExtraMAT = -MAT_deficit
|
||||
p.Mat(0)
|
||||
} else {
|
||||
p.Mat(float64(p.Material) - MAT_deficit)
|
||||
}
|
||||
// fmt.Println("< MAT:", p.Material)
|
||||
// fmt.Println("> MAT:", p.Material)
|
||||
// p.Mat(float64(p.Material) - (MAT_perShip - productionExtraMAT))
|
||||
// fmt.Println("< MAT:", p.Material)
|
||||
ships++
|
||||
} else {
|
||||
progress := productionAvailable / productionCost
|
||||
// productionAvailable -= productionCost * progress
|
||||
MATfarm = MATneed / float64(p.Resources)
|
||||
totalCost = PRODcost + MATfarm
|
||||
// fmt.Printf("PRODcost: %3.03f MATcost: %3.03f MAThave: %3.03f MATneed: %3.03f MATfarm: %3.03f total: %3.03f \n",
|
||||
// PRODcost, shipMass, float64(p.Material), MATneed, MATfarm, totalCost)
|
||||
if pa < totalCost {
|
||||
progress := pa / totalCost
|
||||
pval := game.F(progress)
|
||||
if p.Production.Progress != nil {
|
||||
pval += *p.Production.Progress
|
||||
}
|
||||
p.Production.Progress = &pval
|
||||
aval := game.F(productionAvailable)
|
||||
p.Production.FreeProd = &aval
|
||||
|
||||
// fmt.Println("MAT_deficit", MAT_deficit)
|
||||
|
||||
fmt.Println()
|
||||
fmt.Println("productionExtraMAT", productionExtraMAT)
|
||||
fmt.Println("productionForMass", productionForMass)
|
||||
fmt.Println("productionCost", productionCost)
|
||||
fmt.Println("productionAvailable", productionAvailable)
|
||||
fmt.Println("progress", progress)
|
||||
v := ShipProductionCost(MAT_perShip * float64(progress))
|
||||
fmt.Println("MAT=", v)
|
||||
break
|
||||
fval := game.F(pa)
|
||||
p.Production.ProdUsed = &fval
|
||||
// fmt.Println("pa", pa, "progress", progress, "MAT:", progress*shipMass)
|
||||
return ships
|
||||
} else {
|
||||
pa -= totalCost
|
||||
p.Mat(float64(p.Material) - shipMass + MATneed)
|
||||
ships += 1
|
||||
}
|
||||
}
|
||||
return ships
|
||||
}
|
||||
|
||||
func ShipProductionCost(shipMass float64) float64 {
|
||||
@@ -408,9 +342,3 @@ func ShipProductionCost(shipMass float64) float64 {
|
||||
func ShipMaterialCost(shipMass, planetResource float64) float64 {
|
||||
return shipMass / planetResource
|
||||
}
|
||||
|
||||
func ShipCapitalCost(shipMass, planetResource float64) float64 {
|
||||
return shipMass / planetResource
|
||||
}
|
||||
|
||||
// TODO: при смене производства на планете проверить, сколько материалов высвободится в MAT
|
||||
|
||||
Reference in New Issue
Block a user