2023-09-27 18:39:18 +08:00
|
|
|
package fi
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"joylink.club/ecs"
|
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
"joylink.club/rtsssimulation/entity"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 道岔功能接口
|
|
|
|
|
2023-09-28 14:34:00 +08:00
|
|
|
func driveTurnoutZzj(w ecs.World, id string, dc bool, on bool) {
|
2023-09-27 18:39:18 +08:00
|
|
|
w.Execute(func() {
|
|
|
|
wd := entity.GetWorldData(w)
|
|
|
|
entry, ok := wd.EntityMap[id]
|
|
|
|
if ok {
|
2023-09-28 14:34:00 +08:00
|
|
|
if entry.HasComponent(component.Zdj9TwoElectronicType) { // 有电路,驱动继电器
|
2023-09-27 18:39:18 +08:00
|
|
|
zdj9 := component.Zdj9TwoElectronicType.Get(entry)
|
|
|
|
ycj := component.RelayDriveType.Get(zdj9.TDC_YCJ)
|
|
|
|
dcj := component.RelayDriveType.Get(zdj9.TDC_DCJ)
|
2023-09-28 14:34:00 +08:00
|
|
|
fcj := component.RelayDriveType.Get(zdj9.TDC_FCJ)
|
2023-09-27 18:39:18 +08:00
|
|
|
ycj.Td = on
|
2023-09-28 14:34:00 +08:00
|
|
|
if dc {
|
|
|
|
dcj.Td = on
|
|
|
|
} else {
|
|
|
|
fcj.Td = on
|
|
|
|
}
|
|
|
|
} else { // 无电路,直接驱动转辙机
|
|
|
|
tz := component.TurnoutZzjType.Get(entry)
|
|
|
|
for _, zzj := range tz.ZzjList {
|
|
|
|
state := component.ZzjStateType.Get(zzj)
|
|
|
|
state.Td = on
|
|
|
|
if dc {
|
|
|
|
state.Dw = true
|
|
|
|
} else {
|
|
|
|
state.Dw = false
|
|
|
|
}
|
|
|
|
}
|
2023-09-27 18:39:18 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fmt.Println("未找到id=", id, "的道岔")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-09-28 14:34:00 +08:00
|
|
|
// 驱动道岔转辙机定操启动
|
|
|
|
func DriveTurnoutDCOn(w ecs.World, id string) {
|
|
|
|
driveTurnoutZzj(w, id, true, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 驱动道岔转辙机定操停止
|
|
|
|
func DriveTurnoutDCOff(w ecs.World, id string) {
|
|
|
|
driveTurnoutZzj(w, id, true, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 驱动道岔转辙机反操启动
|
|
|
|
func DriveTurnoutFCOn(w ecs.World, id string) {
|
|
|
|
driveTurnoutZzj(w, id, false, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 驱动道岔转辙机反操停止
|
|
|
|
func DriveTurnoutFCOff(w ecs.World, id string) {
|
|
|
|
driveTurnoutZzj(w, id, false, false)
|
2023-09-27 18:39:18 +08:00
|
|
|
}
|