71 lines
1.6 KiB
Go
71 lines
1.6 KiB
Go
package game
|
|
|
|
import (
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type ShipType struct {
|
|
ID uuid.UUID `json:"id"`
|
|
Name string `json:"name"`
|
|
Drive Float `json:"drive"`
|
|
Armament uint `json:"armament"`
|
|
Weapons Float `json:"weapons"`
|
|
Shields Float `json:"shields"`
|
|
Cargo Float `json:"cargo"`
|
|
}
|
|
|
|
func (st ShipType) Equal(o ShipType) bool {
|
|
return st.Drive == o.Drive &&
|
|
st.Weapons == o.Weapons &&
|
|
st.Armament == o.Armament &&
|
|
st.Shields == o.Shields &&
|
|
st.Cargo == o.Cargo
|
|
}
|
|
|
|
func (st ShipType) BlockMass(t Tech) float64 {
|
|
switch t {
|
|
case TechDrive:
|
|
return st.DriveBlockMass()
|
|
case TechWeapons:
|
|
return st.WeaponsBlockMass()
|
|
case TechShields:
|
|
return st.ShieldsBlockMass()
|
|
case TechCargo:
|
|
return st.CargoBlockMass()
|
|
default:
|
|
panic("BlockMass: unexpectec tech: " + t.String())
|
|
}
|
|
}
|
|
|
|
func (st ShipType) DriveBlockMass() float64 {
|
|
return st.Drive.F()
|
|
}
|
|
|
|
func (st ShipType) WeaponsBlockMass() float64 {
|
|
if st.Armament == 0 || st.Weapons == 0 {
|
|
return 0
|
|
}
|
|
return float64(st.Armament+1) * (st.Weapons.F() / 2)
|
|
}
|
|
|
|
func (st ShipType) ShieldsBlockMass() float64 {
|
|
return st.Shields.F()
|
|
}
|
|
|
|
func (st ShipType) CargoBlockMass() float64 {
|
|
return st.Cargo.F()
|
|
}
|
|
|
|
func (st ShipType) EmptyMass() float64 {
|
|
shipMass := st.DriveBlockMass() + st.ShieldsBlockMass() + st.CargoBlockMass() + st.WeaponsBlockMass()
|
|
return shipMass
|
|
}
|
|
|
|
// ProductionCost returns Material (MAT) and Population (POP) to produce this [ShipType]
|
|
// TODO: do we need this?
|
|
func (st ShipType) ProductionCost() (mat float64, pop float64) {
|
|
mat = st.EmptyMass()
|
|
pop = mat * 10
|
|
return
|
|
}
|