68 lines
1.6 KiB
Go
68 lines
1.6 KiB
Go
package fi
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"joylink.club/ecs"
|
|
"joylink.club/rtsssimulation/component"
|
|
"joylink.club/rtsssimulation/entity"
|
|
)
|
|
|
|
// 道岔功能接口
|
|
|
|
func driveTurnoutZzj(w ecs.World, id string, dc bool, on bool) {
|
|
w.Execute(func() {
|
|
wd := entity.GetWorldData(w)
|
|
entry, ok := wd.EntityMap[id]
|
|
if ok {
|
|
if entry.HasComponent(component.Zdj9TwoElectronicType) { // 有电路,驱动继电器
|
|
zdj9 := component.Zdj9TwoElectronicType.Get(entry)
|
|
ycj := component.RelayDriveType.Get(zdj9.TDC_YCJ)
|
|
dcj := component.RelayDriveType.Get(zdj9.TDC_DCJ)
|
|
fcj := component.RelayDriveType.Get(zdj9.TDC_FCJ)
|
|
ycj.Td = on
|
|
if dc {
|
|
dcj.Td = on
|
|
fcj.Td = !on
|
|
} else {
|
|
dcj.Td = !on
|
|
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
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
fmt.Println("未找到id=", id, "的道岔")
|
|
}
|
|
})
|
|
}
|
|
|
|
// 驱动道岔转辙机定操启动
|
|
func DriveTurnoutDCOn(w ecs.World, id string) {
|
|
driveTurnoutZzj(w, id, true /* dc */, true /* on */)
|
|
}
|
|
|
|
// 驱动道岔转辙机定操停止
|
|
func DriveTurnoutDCOff(w ecs.World, id string) {
|
|
driveTurnoutZzj(w, id, true /* dc */, false /* on */)
|
|
}
|
|
|
|
// 驱动道岔转辙机反操启动
|
|
func DriveTurnoutFCOn(w ecs.World, id string) {
|
|
driveTurnoutZzj(w, id, false /* dc */, true /* on */)
|
|
}
|
|
|
|
// 驱动道岔转辙机反操停止
|
|
func DriveTurnoutFCOff(w ecs.World, id string) {
|
|
driveTurnoutZzj(w, id, false /* dc */, false /* on */)
|
|
}
|