60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
package cbtc_sys
|
|
|
|
import (
|
|
"github.com/yohamta/donburi"
|
|
"joylink.club/ecs"
|
|
"joylink.club/ecs/filter"
|
|
"joylink.club/rtsssimulation/component"
|
|
"joylink.club/rtsssimulation/entity"
|
|
)
|
|
|
|
// 列车运行控制组件,给列车增加限制组件
|
|
type TrainRunControlSys struct {
|
|
trainQuery *ecs.Query
|
|
}
|
|
|
|
func NewTrainRunControlSys() *TrainRunControlSys {
|
|
return &TrainRunControlSys{
|
|
trainQuery: ecs.NewQuery(filter.Contains(component.TrainRunStatusType)),
|
|
}
|
|
}
|
|
|
|
func (sls *TrainRunControlSys) Update(w ecs.World) {
|
|
sls.trainQuery.Each(w, func(e *donburi.Entry) {
|
|
runStatus := component.TrainRunStatusType.Get(e)
|
|
headDevice := runStatus.HeadPosition.Device
|
|
// 限速赋值
|
|
if headDevice.HasComponent(component.SpeedLimitType) { // 车头所在设备有限速组件
|
|
speedLimit := component.SpeedLimitType.Get(headDevice)
|
|
runStatus.SpeedMax = speedLimit.Val
|
|
} else {
|
|
runStatus.SpeedMax = component.TrainSpeedMax
|
|
}
|
|
// 检测扣车、跳停
|
|
worldData := entity.GetWorldData(w)
|
|
uid := component.UidType.Get(headDevice)
|
|
section := worldData.Repo.FindPhysicalSection(uid.Id)
|
|
platform := section.Platform()
|
|
if platform != nil { // 是站台轨
|
|
pe := worldData.EntityMap[platform.Id()]
|
|
// 扣车
|
|
runStatus.Hold = pe.HasComponent(component.PlatformHoldStatusType)
|
|
// 跳停
|
|
skip := pe.HasComponent(component.PlatformSkipStatusType)
|
|
if pe.HasComponent(component.PlatformSkipStatusType) {
|
|
st := component.PlatformSkipStatusType.Get(pe)
|
|
skip = st.AllSkip
|
|
if !skip {
|
|
for _, t := range st.Trains {
|
|
if t.Id() == e.Id() {
|
|
skip = true
|
|
break
|
|
}
|
|
}
|
|
}
|
|
}
|
|
runStatus.Skip = skip
|
|
}
|
|
})
|
|
}
|