package fi import ( "fmt" "joylink.club/ecs" "joylink.club/rtsssimulation/component" "joylink.club/rtsssimulation/entity" ) // 道岔功能接口 // 驱动道岔转辙机 // id - 道岔uid // dc - 定操/反操 // on - 设置/取消 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 */) }