2023-09-26 18:06:15 +08:00
|
|
|
|
package device_sys
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"joylink.club/ecs"
|
2023-10-09 11:17:25 +08:00
|
|
|
|
"joylink.club/ecs/filter"
|
2023-09-26 18:06:15 +08:00
|
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
|
"joylink.club/rtsssimulation/consts"
|
|
|
|
|
)
|
|
|
|
|
|
2023-09-27 18:39:18 +08:00
|
|
|
|
type ZzjSys struct {
|
2023-09-26 18:06:15 +08:00
|
|
|
|
query *ecs.Query
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-27 18:39:18 +08:00
|
|
|
|
func NewZzjSys() *ZzjSys {
|
|
|
|
|
return &ZzjSys{
|
2023-12-29 17:48:57 +08:00
|
|
|
|
query: ecs.NewQuery(filter.Contains(component.ZzjStateType, component.FixedPositionTransformType)),
|
2023-09-26 18:06:15 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
// 转辙机从一个位置到另一个位置转动时间,单位ms
|
|
|
|
|
TurnTime = 3 * 1000
|
|
|
|
|
|
|
|
|
|
// 自动开闭器解锁点位置百分比
|
|
|
|
|
KbqJsPercent = 0.05
|
|
|
|
|
)
|
|
|
|
|
|
2023-09-27 18:39:18 +08:00
|
|
|
|
func (z *ZzjSys) Update(w ecs.World) {
|
2023-09-26 18:06:15 +08:00
|
|
|
|
z.query.Each(w, func(entry *ecs.Entry) {
|
2023-09-28 14:34:00 +08:00
|
|
|
|
zzj := component.ZzjStateType.Get(entry)
|
2023-12-29 17:48:57 +08:00
|
|
|
|
tp := component.FixedPositionTransformType.Get(entry)
|
2023-10-12 16:29:00 +08:00
|
|
|
|
if entry.HasComponent(component.TurnoutFaultJcType) {
|
|
|
|
|
// 道岔挤岔,设置位置到中间,且不再能转动
|
|
|
|
|
tp.Pos = consts.TwoPosMax / 2
|
|
|
|
|
tp.Speed = 0
|
|
|
|
|
} else { // 正常转辙机带动
|
|
|
|
|
if zzj.Td { // 通电
|
|
|
|
|
if tp.Speed >= 0 && tp.Pos > consts.TwoPosMin && zzj.Dw { // 转到定位
|
|
|
|
|
tp.Speed = -component.CalculateTwoPositionAvgSpeed(TurnTime, w.Tick())
|
|
|
|
|
} else if tp.Speed <= 0 && tp.Pos < consts.TwoPosMax && !zzj.Dw { // 转到反位
|
|
|
|
|
tp.Speed = component.CalculateTwoPositionAvgSpeed(TurnTime, w.Tick())
|
|
|
|
|
}
|
|
|
|
|
} else { // 未通电
|
|
|
|
|
if tp.Speed != 0 { // 停止
|
|
|
|
|
tp.Speed = 0
|
|
|
|
|
}
|
2023-09-26 18:06:15 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-12 16:29:00 +08:00
|
|
|
|
|
2023-09-26 18:06:15 +08:00
|
|
|
|
if tp.Pos == consts.TwoPosMax { // 到反位
|
|
|
|
|
if !zzj.JD12 {
|
|
|
|
|
zzj.JD12 = true
|
|
|
|
|
}
|
|
|
|
|
if !zzj.JD34 {
|
|
|
|
|
zzj.JD34 = true
|
|
|
|
|
}
|
|
|
|
|
} else if tp.Pos == consts.TwoPosMin { // 到定位
|
|
|
|
|
if zzj.JD12 {
|
|
|
|
|
zzj.JD12 = false
|
|
|
|
|
}
|
|
|
|
|
if zzj.JD34 {
|
|
|
|
|
zzj.JD34 = false
|
|
|
|
|
}
|
|
|
|
|
} else if tp.Percentage() > KbqJsPercent && tp.Percentage() < (1-KbqJsPercent) { //中间位置
|
|
|
|
|
if zzj.JD12 {
|
|
|
|
|
zzj.JD12 = false
|
|
|
|
|
}
|
|
|
|
|
if !zzj.JD34 {
|
|
|
|
|
zzj.JD34 = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|