physics test
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
package itemprops
|
||||
|
||||
import "github.com/shopspring/decimal"
|
||||
|
||||
//MedicalSystem организм
|
||||
// Humanoid
|
||||
// Circuits
|
||||
@ -55,94 +57,94 @@ package itemprops
|
||||
// -> [right] joint -> leg -> joint -> hip -> joint -> foot -> 5 x finger
|
||||
// -> head -> joint -> jaw
|
||||
|
||||
//MedicalSystem Организм
|
||||
// MedicalSystem Организм
|
||||
type MedicalSystem struct {
|
||||
BasePart BodyPart
|
||||
BasePart BodyPart
|
||||
}
|
||||
|
||||
//MedicalCircuit Система обращения
|
||||
// MedicalCircuit Система обращения
|
||||
type MedicalCircuit struct {
|
||||
Provides MedicalAbility
|
||||
DependsOn Organ
|
||||
Vessel MedicalVessel
|
||||
Contains []Organ
|
||||
Provides MedicalAbility
|
||||
DependsOn Organ
|
||||
Vessel MedicalVessel
|
||||
Contains []Organ
|
||||
}
|
||||
|
||||
//MedicalVessel кровь, желчь, пульпа, воздух, еда
|
||||
// MedicalVessel кровь, желчь, пульпа, воздух, еда
|
||||
type MedicalVessel struct {
|
||||
Name string
|
||||
Material
|
||||
Pressure DimensionItemDensity
|
||||
Name string
|
||||
Material
|
||||
Pressure decimal.Decimal //Pressure давление, kg / m3
|
||||
}
|
||||
|
||||
//BodyPart часть тела
|
||||
// BodyPart часть тела
|
||||
type BodyPart struct {
|
||||
LayerExtra MedicalMaterial
|
||||
LayerOuter MedicalMaterial
|
||||
LayerMiddle MedicalMaterial
|
||||
LayerInner MedicalMaterial
|
||||
LayerExtra MedicalMaterial
|
||||
LayerOuter MedicalMaterial
|
||||
LayerMiddle MedicalMaterial
|
||||
LayerInner MedicalMaterial
|
||||
|
||||
Joints []Joint
|
||||
Contains []InnerOrgan
|
||||
Exposes []OuterOrgan
|
||||
Joints []Joint
|
||||
Contains []InnerOrgan
|
||||
Exposes []OuterOrgan
|
||||
}
|
||||
|
||||
//Joint суставы, к чему и что крепится
|
||||
// Joint суставы, к чему и что крепится
|
||||
type Joint struct {
|
||||
Name string
|
||||
ConnectsFrom BodyPart
|
||||
ConnectsTo BodyPart
|
||||
Name string
|
||||
ConnectsFrom BodyPart
|
||||
ConnectsTo BodyPart
|
||||
}
|
||||
|
||||
type Organ struct {
|
||||
Name string
|
||||
Material
|
||||
Name string
|
||||
Material
|
||||
}
|
||||
|
||||
//InnerOrgan ливер, селезёнка, сердце, кишки итп
|
||||
// InnerOrgan ливер, селезёнка, сердце, кишки итп
|
||||
type InnerOrgan struct {
|
||||
Organ
|
||||
DependsOn MedicalCircuit
|
||||
BelongsTo MedicalCircuit
|
||||
Organ
|
||||
DependsOn MedicalCircuit
|
||||
BelongsTo MedicalCircuit
|
||||
}
|
||||
|
||||
//OuterOrgan глаза, уши, волосы, когти итп
|
||||
// OuterOrgan глаза, уши, волосы, когти итп
|
||||
type OuterOrgan struct {
|
||||
Organ
|
||||
DependsOn MedicalCircuit
|
||||
BelongsTo MedicalCircuit
|
||||
Organ
|
||||
DependsOn MedicalCircuit
|
||||
BelongsTo MedicalCircuit
|
||||
}
|
||||
|
||||
//слой части тела - кожа/чешуя/роговые пластины/хитиновый панцирь, жир, мускулы, кости
|
||||
// слой части тела - кожа/чешуя/роговые пластины/хитиновый панцирь, жир, мускулы, кости
|
||||
type MedicalMaterial struct {
|
||||
Name string
|
||||
Material
|
||||
MedicalSystemFlags
|
||||
Name string
|
||||
Material
|
||||
MedicalSystemFlags
|
||||
}
|
||||
|
||||
//@todo заменить на Medical Circuit
|
||||
// @todo заменить на Medical Circuit
|
||||
type MedicalSystemFlags struct {
|
||||
//Structural является ли опорным аппаратом
|
||||
Structural bool
|
||||
//Содежит ли кровь/ихор/
|
||||
MajorVeins bool //вход на мотор, сломаешь - быстро выйдет из строя если будет двигаться
|
||||
MajorArteria bool //выход, то же самое + высокое давление
|
||||
//Structural является ли опорным аппаратом
|
||||
Structural bool
|
||||
//Содежит ли кровь/ихор/
|
||||
MajorVeins bool //вход на мотор, сломаешь - быстро выйдет из строя если будет двигаться
|
||||
MajorArteria bool //выход, то же самое + высокое давление
|
||||
|
||||
Veins bool //вход на мотор
|
||||
Arteria bool //выход из мотора, высокое давление
|
||||
Veins bool //вход на мотор
|
||||
Arteria bool //выход из мотора, высокое давление
|
||||
|
||||
MajorNerve bool //повредишь - ниже по суставам не работает
|
||||
NerveTissue bool //повредишь - ниже по суставамс болит
|
||||
MajorNerve bool //повредишь - ниже по суставам не работает
|
||||
NerveTissue bool //повредишь - ниже по суставамс болит
|
||||
|
||||
OxygenTube bool //трахея
|
||||
OxygenPump bool //лёгкое
|
||||
OxygenTube bool //трахея
|
||||
OxygenPump bool //лёгкое
|
||||
|
||||
BloodPump bool //мотор
|
||||
BloodPump bool //мотор
|
||||
|
||||
ContainsCongestionLiquid bool
|
||||
ContainsCongestionLiquid bool
|
||||
|
||||
IsMainCongestionPump bool
|
||||
IsMainCongestionPump bool
|
||||
}
|
||||
|
||||
//MedicalAbility спсобность есть, стоять, не терять равновесие, дышать, выздоравливать, лечить свои органы, видеть итп
|
||||
// MedicalAbility спсобность есть, стоять, не терять равновесие, дышать, выздоравливать, лечить свои органы, видеть итп
|
||||
type MedicalAbility string
|
||||
|
175
engine/items/itemprops/ip_test.go
Normal file
175
engine/items/itemprops/ip_test.go
Normal file
@ -0,0 +1,175 @@
|
||||
package itemprops
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type IpTestSuite struct {
|
||||
suite.Suite
|
||||
}
|
||||
|
||||
// метод для установки тестовых данных для всего набора, запускается до всего прочего
|
||||
func (suite *IpTestSuite) SetupSuite() {
|
||||
}
|
||||
|
||||
// метод для сноса наделанного тестом до идеально чистого состояния, запускается после всего прочего
|
||||
func (suite *IpTestSuite) TearDownSuite() {
|
||||
}
|
||||
|
||||
// запускается перед каждым тестом
|
||||
func (suite *IpTestSuite) SetupTest() {}
|
||||
|
||||
// запускается после каждого теста
|
||||
func (suite *IpTestSuite) TearDownTest() {}
|
||||
|
||||
func TestApi(t *testing.T) {
|
||||
tests := new(IpTestSuite)
|
||||
suite.Run(t, tests)
|
||||
}
|
||||
|
||||
func (suite *IpTestSuite) TestMaterialWeightAndVolume() {
|
||||
// плотность https://tekkos.ru/katalog/poleznaya-informatsiya/tablica-plotnosti-stali-kg-m3.html
|
||||
// ударная вязкость https://nposanef.ru/DOCUMENTS/PB-03-605-03/PB-03-605-03_Tab-2.6.pdf
|
||||
// температура плавления http://zaozmi.ru/polezno/temperatura_plavleniya_metallov.html
|
||||
// температура кипения http://temperatures.ru/pages/temperatura_plavleniya_i_kipeniya
|
||||
// Пределы прочности некоторых материалов https://sevparitet.ru/raznoe/koefficient-uprugosti-tablica.html
|
||||
|
||||
metalMaterialFlags := MaterialFlags{
|
||||
ConductsElictricity: true,
|
||||
BlocksLiquid: true,
|
||||
AcidResistant: true,
|
||||
BlocksGas: true,
|
||||
Flammable: false,
|
||||
ConductsHeat: true,
|
||||
Radiates: true,
|
||||
}
|
||||
|
||||
woodMaterialFlags := MaterialFlags{
|
||||
ConductsElictricity: false,
|
||||
BlocksLiquid: true,
|
||||
AcidResistant: false,
|
||||
BlocksGas: true,
|
||||
Flammable: true,
|
||||
ConductsHeat: false,
|
||||
Radiates: false,
|
||||
}
|
||||
|
||||
teststeel := Material{
|
||||
Name: "teststeel",
|
||||
Flags: metalMaterialFlags,
|
||||
Density: DimensionItemDensity{decimal.NewFromInt(7800)},
|
||||
FractureToughness: DimensionFractureToughness{decimal.NewFromInt(30)},
|
||||
MeltingPoint: DimensionItemNullTemperature{decimal.NullDecimal{decimal.NewFromInt(1400), true}},
|
||||
BoilingPoint: DimensionItemNullTemperature{decimal.NullDecimal{decimal.NewFromInt(3200), true}},
|
||||
}
|
||||
|
||||
testOakWood := Material{
|
||||
Name: "testoakwood",
|
||||
Flags: woodMaterialFlags,
|
||||
Density: DimensionItemDensity{decimal.NewFromInt(700)},
|
||||
FractureToughness: DimensionFractureToughness{decimal.NewFromFloat(4.5)},
|
||||
MeltingPoint: DimensionItemNullTemperature{decimal.NullDecimal{decimal.NewFromInt(600), true}}, //загорается при 600 град Цельсия
|
||||
}
|
||||
|
||||
testCube := ItemPhysics{
|
||||
Material: teststeel,
|
||||
DimensionItemRigidity: DimensionItemRigidity{decimal.NewFromInt(65)},
|
||||
DimensionItemSize: DimensionItemSize{
|
||||
Width: decimal.NewFromFloat(0.1),
|
||||
Height: decimal.NewFromFloat(0.1),
|
||||
Depth: decimal.NewNullDecimal(decimal.NewFromFloat(0.1)),
|
||||
Thickness: decimal.NullDecimal{},
|
||||
},
|
||||
DimensionItemTemperature: DimensionItemTemperature{decimal.NewFromInt(20)},
|
||||
}
|
||||
|
||||
suite.Equal(decimal.NewFromFloat(7.8).String(), testCube.Weight().String())
|
||||
suite.Equal(decimal.NewFromFloat(0.001).String(), testCube.Volume().String())
|
||||
|
||||
testOakCube := ItemPhysics{
|
||||
Material: testOakWood,
|
||||
DimensionItemRigidity: DimensionItemRigidity{decimal.NewFromInt(4)},
|
||||
DimensionItemSize: DimensionItemSize{
|
||||
Width: decimal.NewFromFloat(0.1),
|
||||
Height: decimal.NewFromFloat(0.1),
|
||||
Depth: decimal.NewNullDecimal(decimal.NewFromFloat(0.1)),
|
||||
Thickness: decimal.NullDecimal{},
|
||||
},
|
||||
DimensionItemTemperature: DimensionItemTemperature{decimal.NewFromInt(20)},
|
||||
}
|
||||
|
||||
//oakwood is ~10 times lighter than steel
|
||||
suite.Equal(decimal.NewFromFloat(0.7).String(), testOakCube.Weight().String())
|
||||
suite.Equal(decimal.NewFromFloat(0.001).String(), testOakCube.Volume().String())
|
||||
|
||||
testCuirass := ItemPhysics{
|
||||
Material: teststeel,
|
||||
DimensionItemRigidity: DimensionItemRigidity{decimal.NewFromInt(55)},
|
||||
DimensionItemSize: DimensionItemSize{
|
||||
Width: decimal.NewFromFloat(0.5), //60 cm wide
|
||||
Height: decimal.NewFromFloat(0.8), //80 cm high
|
||||
Depth: decimal.NewNullDecimal(decimal.NewFromFloat(0.4)), //50 cm deep
|
||||
Thickness: decimal.NewNullDecimal(decimal.NewFromFloat(0.001)), // 1mm thick
|
||||
},
|
||||
DimensionItemTemperature: DimensionItemTemperature{},
|
||||
}
|
||||
|
||||
//12.1992 kg HEAVY ARMOR IS HEAVY
|
||||
suite.Equal(decimal.NewFromFloat(12.1992).String(), testCuirass.Weight().String())
|
||||
//0.001564 m3 of steel
|
||||
suite.Equal(decimal.NewFromFloat(0.001564).String(), testCuirass.Volume().String())
|
||||
}
|
||||
|
||||
func (suite *IpTestSuite) TestMaterialSerialization() {
|
||||
metalMaterialFlags := MaterialFlags{
|
||||
ConductsElictricity: true,
|
||||
BlocksLiquid: true,
|
||||
AcidResistant: true,
|
||||
BlocksGas: true,
|
||||
Flammable: false,
|
||||
ConductsHeat: true,
|
||||
Radiates: true,
|
||||
}
|
||||
|
||||
woodMaterialFlags := MaterialFlags{
|
||||
ConductsElictricity: false,
|
||||
BlocksLiquid: true,
|
||||
AcidResistant: false,
|
||||
BlocksGas: true,
|
||||
Flammable: true,
|
||||
ConductsHeat: false,
|
||||
Radiates: false,
|
||||
}
|
||||
|
||||
teststeel := Material{
|
||||
Name: "teststeel",
|
||||
Flags: metalMaterialFlags,
|
||||
Density: DimensionItemDensity{decimal.NewFromInt(7800)},
|
||||
FractureToughness: DimensionFractureToughness{decimal.NewFromInt(30)},
|
||||
MeltingPoint: DimensionItemNullTemperature{decimal.NullDecimal{decimal.NewFromInt(1400), true}},
|
||||
BoilingPoint: DimensionItemNullTemperature{decimal.NullDecimal{decimal.NewFromInt(3200), true}},
|
||||
}
|
||||
|
||||
testOakWood := Material{
|
||||
Name: "testoakwood",
|
||||
Flags: woodMaterialFlags,
|
||||
Density: DimensionItemDensity{decimal.NewFromInt(700)},
|
||||
FractureToughness: DimensionFractureToughness{decimal.NewFromFloat(4.5)},
|
||||
MeltingPoint: DimensionItemNullTemperature{decimal.NullDecimal{decimal.NewFromInt(600), true}}, //загорается при 600 град Цельсия
|
||||
}
|
||||
bytes, err := json.Marshal(teststeel)
|
||||
suite.NoError(err)
|
||||
suite.Equal(
|
||||
`{"name":"teststeel","material_flags":{"conducts_elictricity":true,"blocks_liquid":true,"acid_resistant":true,"blocks_gas":true,"flammable":false,"conducts_heat":true,"radiates":true},"density":"7800","fracture_toughness":"30","melting_point":"1400","boiling_point":"3200"}`,
|
||||
string(bytes),
|
||||
)
|
||||
|
||||
bytes, err = json.Marshal(testOakWood)
|
||||
suite.NoError(err)
|
||||
suite.Equal(`{"name":"testoakwood","material_flags":{"conducts_elictricity":false,"blocks_liquid":true,"acid_resistant":false,"blocks_gas":true,"flammable":true,"conducts_heat":false,"radiates":false},"density":"700","fracture_toughness":"4.5","melting_point":"600","boiling_point":null}`,
|
||||
string(bytes),
|
||||
)
|
||||
}
|
@ -3,35 +3,54 @@ package itemprops
|
||||
import "github.com/shopspring/decimal"
|
||||
|
||||
type ItemPhysics struct {
|
||||
Material Material
|
||||
Rigidity DimensionItemRigidity
|
||||
Size DimensionItemSize
|
||||
Temperature DimensionItemTemperature
|
||||
Material `json:"material"`
|
||||
//DimensionItemRigidity жёсткость (самого предмета а не материала), мера прочности,
|
||||
//уменьшается со временем, может зависеть от тепмературы
|
||||
DimensionItemRigidity `json:"rigidity"`
|
||||
DimensionItemSize `json:"size"`
|
||||
DimensionItemTemperature `json:"temperature"`
|
||||
//CubeFactor фактор близости куб <-> сфера по площади поверхности, чем ближе к 0, тем ближе к сфере,
|
||||
//100 - куб, >100 - для суперсложных (шипастых например) поверхностей
|
||||
CubeFactor decimal.NullDecimal `json:"cube_factor,omitempty"`
|
||||
}
|
||||
|
||||
//DimensionItemSize length in m (1 mm = 1/1000 of 1m)
|
||||
// DimensionItemSize length in m (1 mm = 1/1000 of 1m)
|
||||
type DimensionItemSize struct {
|
||||
Width decimal.Decimal
|
||||
Height decimal.Decimal
|
||||
// if item is solid - depth in m (1mm = 1/1000 of m)
|
||||
Depth decimal.NullDecimal
|
||||
//Thickness if item is hollow - thickness of outer item shell, ie for armor, in m (1 mm = 1/1000 of m)
|
||||
Thickness decimal.NullDecimal
|
||||
Width decimal.Decimal `json:"width"`
|
||||
Height decimal.Decimal `json:"height"`
|
||||
// if item is solid - depth in m (1mm = 1/1000 of m)
|
||||
Depth decimal.NullDecimal `json:"depth,omitempty"`
|
||||
//Thickness if item is hollow - thickness of outer item shell, ie for armor, in m (1 mm = 1/1000 of m)
|
||||
Thickness decimal.NullDecimal `json:"thickness,omitempty"`
|
||||
}
|
||||
|
||||
//Area is frontal area
|
||||
// Area is frontal area
|
||||
func (d *DimensionItemSize) Area() decimal.Decimal {
|
||||
return d.Width.Mul(d.Height)
|
||||
return d.Width.Mul(d.Height)
|
||||
}
|
||||
|
||||
//DimensionItemDensity density in kg/m3
|
||||
type DimensionItemDensity decimal.Decimal
|
||||
func (ip *ItemPhysics) Weight() decimal.Decimal {
|
||||
return ip.Material.Density.Mul(ip.Volume())
|
||||
}
|
||||
|
||||
//DimensionItemRigidity rigidity жёсткость, способность твёрдого тела, конструкции или её элементов сопротивляться деформации in N/m
|
||||
type DimensionItemRigidity decimal.Decimal
|
||||
|
||||
//NotchFractureToughness ударная вязкость по Шарпи, Дж (надо ли?)
|
||||
type NotchFractureToughness decimal.Decimal
|
||||
|
||||
//DimensionItemTemperature in celsius, -273 to 10000
|
||||
type DimensionItemTemperature decimal.Decimal
|
||||
func (d *ItemPhysics) Volume() decimal.Decimal {
|
||||
v := d.Width.Mul(d.Height)
|
||||
//есть глубина
|
||||
if !d.Depth.Decimal.IsZero() {
|
||||
v = v.Mul(d.Depth.Decimal)
|
||||
//пустотелый
|
||||
if !d.Thickness.Decimal.IsZero() {
|
||||
surfaceArea := d.Width.Mul(d.Height).Mul(decimal.NewFromInt(2)).
|
||||
Add(d.Height.Mul(d.Depth.Decimal).Mul(decimal.NewFromInt(2))).
|
||||
Add(d.Width.Mul(d.Depth.Decimal).Mul(decimal.NewFromInt(2)))
|
||||
surfaceAreaCoeff := 0.85
|
||||
if !d.CubeFactor.Decimal.IsZero() {
|
||||
surfaceAreaCoeff = surfaceAreaCoeff * float64(int(d.CubeFactor.Decimal.IntPart())/100)
|
||||
}
|
||||
v = surfaceArea.Mul(d.Thickness.Decimal).
|
||||
//волюнтаристский коэффт отличия поверхности от куба, см https/en.wikipedia.org/wiki/Volume-to-surface_area_ratio
|
||||
Mul(decimal.NewFromFloat(surfaceAreaCoeff))
|
||||
}
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
35
engine/items/itemprops/item_physics_dimensions.go
Normal file
35
engine/items/itemprops/item_physics_dimensions.go
Normal file
@ -0,0 +1,35 @@
|
||||
package itemprops
|
||||
|
||||
import "github.com/shopspring/decimal"
|
||||
|
||||
// плотность https://tekkos.ru/katalog/poleznaya-informatsiya/tablica-plotnosti-stali-kg-m3.html
|
||||
// ударная вязкость https://nposanef.ru/DOCUMENTS/PB-03-605-03/PB-03-605-03_Tab-2.6.pdf
|
||||
// температура плавления http://zaozmi.ru/polezno/temperatura_plavleniya_metallov.html
|
||||
// температура кипения http://temperatures.ru/pages/temperatura_plavleniya_i_kipeniya
|
||||
// Пределы прочности некоторых материалов https://sevparitet.ru/raznoe/koefficient-uprugosti-tablica.html
|
||||
|
||||
// DimensionItemDensity density in kg/m3
|
||||
type DimensionItemDensity struct {
|
||||
decimal.Decimal
|
||||
}
|
||||
|
||||
// DimensionItemRigidity rigidity жёсткость, способность твёрдого тела, конструкции или её элементов сопротивляться деформации in N/m
|
||||
type DimensionItemRigidity struct {
|
||||
decimal.Decimal
|
||||
}
|
||||
|
||||
// DimensionFractureToughness ударная вязкость по Шарпи, Дж (надо ли?)
|
||||
// Ударная вязкость, мера скорости поглощения энергии без деформаций, джоули на квадратный метр в секунду
|
||||
type DimensionFractureToughness struct {
|
||||
decimal.Decimal
|
||||
}
|
||||
|
||||
// DimensionItemTemperature in celsius, -273 to 10000
|
||||
type DimensionItemTemperature struct {
|
||||
decimal.Decimal
|
||||
}
|
||||
|
||||
// DimensionItemTemperature in celsius, -273 to 10000
|
||||
type DimensionItemNullTemperature struct {
|
||||
decimal.NullDecimal
|
||||
}
|
@ -1,20 +1,20 @@
|
||||
package itemprops
|
||||
|
||||
type Material struct {
|
||||
Name string
|
||||
Flags MaterialFlags
|
||||
Density DimensionItemDensity
|
||||
FractureToughness NotchFractureToughness
|
||||
MeltingPoint DimensionItemTemperature
|
||||
BoilingPoint DimensionItemTemperature
|
||||
Name string `json:"name"`
|
||||
Flags MaterialFlags `json:"material_flags"`
|
||||
Density DimensionItemDensity `json:"density"`
|
||||
FractureToughness DimensionFractureToughness `json:"fracture_toughness"`
|
||||
MeltingPoint DimensionItemNullTemperature `json:"melting_point,omitempty"`
|
||||
BoilingPoint DimensionItemNullTemperature `json:"boiling_point,omitempty"`
|
||||
}
|
||||
|
||||
type MaterialFlags struct {
|
||||
ConductsElictricity bool
|
||||
BlocksLiquid bool
|
||||
AcidResistant bool
|
||||
BlocksGas bool
|
||||
Flammable bool
|
||||
ConductsHeat bool
|
||||
Radiates bool
|
||||
ConductsElictricity bool `json:"conducts_elictricity"`
|
||||
BlocksLiquid bool `json:"blocks_liquid"`
|
||||
AcidResistant bool `json:"acid_resistant"`
|
||||
BlocksGas bool `json:"blocks_gas"`
|
||||
Flammable bool `json:"flammable"`
|
||||
ConductsHeat bool `json:"conducts_heat"`
|
||||
Radiates bool `json:"radiates"`
|
||||
}
|
||||
|
Reference in New Issue
Block a user