package fi import ( "fmt" "joylink.club/ecs" "joylink.club/rtsssimulation/component" "joylink.club/rtsssimulation/component/component_proto" "joylink.club/rtsssimulation/entity" ) func SetInterlockKm4(world ecs.World, id string) error { result := <-ecs.Request[ecs.EmptyType](world, func() ecs.Result[ecs.EmptyType] { wd := entity.GetWorldData(world) entry, ok := wd.EntityMap[id] if ok { err := setInterlockKm(wd, entry, 4) if err != nil { return ecs.NewErrResult(err) } } else { return ecs.NewErrResult(fmt.Errorf("未找到id=%s的屏蔽门", id)) } return ecs.NewOkEmptyResult() }) return result.Err } func CancelInterlockKm4(world ecs.World, id string) error { result := <-ecs.Request[ecs.EmptyType](world, func() ecs.Result[ecs.EmptyType] { wd := entity.GetWorldData(world) entry, ok := wd.EntityMap[id] if ok { err := cancelInterlockKm(wd, entry, 4) if err != nil { return ecs.NewErrResult(err) } } else { return ecs.NewErrResult(fmt.Errorf("未找到id=%s的屏蔽门", id)) } return ecs.NewOkEmptyResult() }) return result.Err } func SetInterlockKm8(world ecs.World, id string) error { result := <-ecs.Request[ecs.EmptyType](world, func() ecs.Result[ecs.EmptyType] { wd := entity.GetWorldData(world) entry, ok := wd.EntityMap[id] if ok { err := setInterlockKm(wd, entry, 8) if err != nil { return ecs.NewErrResult(err) } } else { return ecs.NewErrResult(fmt.Errorf("未找到id=%s的屏蔽门", id)) } return ecs.NewOkEmptyResult() }) return result.Err } func CancelInterlockKm8(world ecs.World, id string) error { result := <-ecs.Request[ecs.EmptyType](world, func() ecs.Result[ecs.EmptyType] { wd := entity.GetWorldData(world) entry, ok := wd.EntityMap[id] if ok { err := cancelInterlockKm(wd, entry, 8) if err != nil { return ecs.NewErrResult(err) } } else { return ecs.NewErrResult(fmt.Errorf("未找到id=%s的屏蔽门", id)) } return ecs.NewOkEmptyResult() }) return result.Err } func SetInterlockGm(world ecs.World, id string) error { result := <-ecs.Request[ecs.EmptyType](world, func() ecs.Result[ecs.EmptyType] { wd := entity.GetWorldData(world) entry, ok := wd.EntityMap[id] if ok { err := setInterlockGm(wd, entry) if err != nil { return ecs.NewErrResult(err) } } else { return ecs.NewErrResult(fmt.Errorf("未找到id=%s的屏蔽门", id)) } return ecs.NewOkEmptyResult() }) return result.Err } func CancelInterlockGm(world ecs.World, id string) error { result := <-ecs.Request[ecs.EmptyType](world, func() ecs.Result[ecs.EmptyType] { wd := entity.GetWorldData(world) entry, ok := wd.EntityMap[id] if ok { err := cancelInterlockGm(wd, entry) if err != nil { return ecs.NewErrResult(err) } } else { return ecs.NewErrResult(fmt.Errorf("未找到id=%s的屏蔽门", id)) } return ecs.NewOkEmptyResult() }) return result.Err } func SetPsdFault(world ecs.World, id string, fault component_proto.Psd_Fault, asdCodes []int32) error { result := <-ecs.Request[ecs.EmptyType](world, func() ecs.Result[ecs.EmptyType] { wd := entity.GetWorldData(world) psdEntry, ok := wd.EntityMap[id] if !ok { return ecs.NewErrResult(fmt.Errorf("未找到id=%s的屏蔽门", id)) } tag, err := component.GetAsdFaultTag(fault) if err != nil { return ecs.NewErrResult(err) } asdList := component.AsdListType.Get(psdEntry).List for _, code := range asdCodes { asdEntry := asdList[int(code-1)] asdEntry.AddComponent(tag) } return ecs.NewOkEmptyResult() }) return result.Err } func CancelPsdFault(world ecs.World, id string, fault component_proto.Psd_Fault, asdCodes []int32) error { result := <-ecs.Request[ecs.EmptyType](world, func() ecs.Result[ecs.EmptyType] { wd := entity.GetWorldData(world) psdEntry, ok := wd.EntityMap[id] if !ok { return ecs.NewErrResult(fmt.Errorf("未找到id=%s的屏蔽门", id)) } tag, err := component.GetAsdFaultTag(fault) if err != nil { return ecs.NewErrResult(err) } asdList := component.AsdListType.Get(psdEntry).List for _, code := range asdCodes { asdEntry := asdList[int(code-1)] asdEntry.RemoveComponent(tag) } return ecs.NewOkEmptyResult() }) return result.Err } func SetQDTC(world ecs.World, id string) error { result := <-ecs.Request[ecs.EmptyType](world, func() ecs.Result[ecs.EmptyType] { wd := entity.GetWorldData(world) entry, ok := wd.EntityMap[id] if ok { err := setQDTC(wd, entry) if err != nil { return ecs.NewErrResult(err) } } else { return ecs.NewErrResult(fmt.Errorf("未找到id=%s的屏蔽门", id)) } return ecs.NewOkEmptyResult() }) return result.Err } func CancelQDTC(world ecs.World, id string) error { result := <-ecs.Request[ecs.EmptyType](world, func() ecs.Result[ecs.EmptyType] { wd := entity.GetWorldData(world) entry, ok := wd.EntityMap[id] if ok { err := cancelQDTC(wd, entry) if err != nil { return ecs.NewErrResult(err) } } else { return ecs.NewErrResult(fmt.Errorf("未找到id=%s的屏蔽门", id)) } return ecs.NewOkEmptyResult() }) return result.Err } func SetTZTC(world ecs.World, id string) error { result := <-ecs.Request[ecs.EmptyType](world, func() ecs.Result[ecs.EmptyType] { wd := entity.GetWorldData(world) entry, ok := wd.EntityMap[id] if ok { err := setTZTC(wd, entry) if err != nil { return ecs.NewErrResult(err) } } else { return ecs.NewErrResult(fmt.Errorf("未找到id=%s的屏蔽门", id)) } return ecs.NewOkEmptyResult() }) return result.Err } func CancelTZTC(world ecs.World, id string) error { result := <-ecs.Request[ecs.EmptyType](world, func() ecs.Result[ecs.EmptyType] { wd := entity.GetWorldData(world) entry, ok := wd.EntityMap[id] if ok { err := cancelTZTC(wd, entry) if err != nil { return ecs.NewErrResult(err) } } else { return ecs.NewErrResult(fmt.Errorf("未找到id=%s的屏蔽门", id)) } return ecs.NewOkEmptyResult() }) return result.Err } func cancelTZTC(wd *component.WorldData, psdEntry *ecs.Entry) error { if psdEntry.HasComponent(component.PsdCircuitType) { circuit := component.PsdCircuitType.Get(psdEntry) return wd.SetQdBit(component.UidType.Get(circuit.TZTCJ).Id, false) } else { psc := component.PscType.Get(psdEntry) psc.TZTC = false } return nil } func setTZTC(wd *component.WorldData, psdEntry *ecs.Entry) error { if psdEntry.HasComponent(component.PsdCircuitType) { circuit := component.PsdCircuitType.Get(psdEntry) return wd.SetQdBits([]*component.QdBitParam{ component.NewQdBitParam(component.UidType.Get(circuit.QDTCJ).Id, false), component.NewQdBitParam(component.UidType.Get(circuit.TZTCJ).Id, true), }) } else { psc := component.PscType.Get(psdEntry) psc.QDTC = false psc.TZTC = true } return nil } func cancelQDTC(wd *component.WorldData, psdEntry *ecs.Entry) error { if psdEntry.HasComponent(component.PsdCircuitType) { circuit := component.PsdCircuitType.Get(psdEntry) return wd.SetQdBit(component.UidType.Get(circuit.QDTCJ).Id, false) } else { psc := component.PscType.Get(psdEntry) psc.QDTC = false } return nil } func setQDTC(wd *component.WorldData, psdEntry *ecs.Entry) error { if psdEntry.HasComponent(component.PsdCircuitType) { circuit := component.PsdCircuitType.Get(psdEntry) return wd.SetQdBits([]*component.QdBitParam{ component.NewQdBitParam(component.UidType.Get(circuit.QDTCJ).Id, true), component.NewQdBitParam(component.UidType.Get(circuit.TZTCJ).Id, false), }) } else { psc := component.PscType.Get(psdEntry) psc.QDTC = true psc.TZTC = false } return nil } // 设置联锁开门 func setInterlockKm(wd *component.WorldData, psdEntry *ecs.Entry, group int) error { if psdEntry.HasComponent(component.PsdCircuitType) { //有联锁区段电路 circuit := component.PsdCircuitType.Get(psdEntry) switch group { case 4: return setInterlockDriveKm4(wd, circuit) case 8: return setInterlockDriveKm8(wd, circuit) } } else { psc := component.PscType.Get(psdEntry) switch group { case 4: setPscKm4(psc) case 8: setPscKm8(psc) } } return nil } // 取消联锁开门 func cancelInterlockKm(wd *component.WorldData, psdEntry *ecs.Entry, group int) error { if psdEntry.HasComponent(component.PsdCircuitType) { //有联锁区段电路 circuit := component.PsdCircuitType.Get(psdEntry) switch group { case 4: return wd.SetQdBit(component.UidType.Get(circuit.KMJ4).Id, false) case 8: return wd.SetQdBit(component.UidType.Get(circuit.KMJ8).Id, false) } } else { psc := component.PscType.Get(psdEntry) switch group { case 4: psc.InterlockKM4 = false case 8: psc.InterlockKM8 = false } } return nil } // 设置联锁关门 func setInterlockGm(wd *component.WorldData, psdEntry *ecs.Entry) error { if psdEntry.HasComponent(component.PsdCircuitType) { //有联锁区段电路 circuit := component.PsdCircuitType.Get(psdEntry) return setInterlockDriveGm(wd, circuit) } else { psc := component.PscType.Get(psdEntry) setPscGm(psc) } return nil } // 取消联锁关门 func cancelInterlockGm(wd *component.WorldData, psdEntry *ecs.Entry) error { if psdEntry.HasComponent(component.PsdCircuitType) { circuit := component.PsdCircuitType.Get(psdEntry) return wd.SetQdBit(component.UidType.Get(circuit.GMJ).Id, false) } else { psc := component.PscType.Get(psdEntry) psc.InterlockGM = false } return nil } // 联锁驱动4编组开门 func setInterlockDriveKm4(wd *component.WorldData, circuit *component.PsdCircuit) error { return wd.SetQdBits([]*component.QdBitParam{ component.NewQdBitParam(component.UidType.Get(circuit.GMJ).Id, false), component.NewQdBitParam(component.UidType.Get(circuit.KMJ4).Id, true), component.NewQdBitParam(component.UidType.Get(circuit.KMJ8).Id, false), }) } // 联锁驱动8编组开门 func setInterlockDriveKm8(wd *component.WorldData, circuit *component.PsdCircuit) error { return wd.SetQdBits([]*component.QdBitParam{ component.NewQdBitParam(component.UidType.Get(circuit.GMJ).Id, false), component.NewQdBitParam(component.UidType.Get(circuit.KMJ4).Id, false), component.NewQdBitParam(component.UidType.Get(circuit.KMJ8).Id, true), }) } // 联锁驱动关门 func setInterlockDriveGm(wd *component.WorldData, circuit *component.PsdCircuit) error { return wd.SetQdBits([]*component.QdBitParam{ component.NewQdBitParam(component.UidType.Get(circuit.GMJ).Id, true), component.NewQdBitParam(component.UidType.Get(circuit.KMJ4).Id, false), component.NewQdBitParam(component.UidType.Get(circuit.KMJ8).Id, false), }) } // 直接设置PSC的状态4编组开门。在无屏蔽门电路时使用 func setPscKm4(psc *component.Psc) { psc.InterlockKM4 = true psc.InterlockKM8 = false psc.InterlockGM = false } // 直接设置PSC的状态8编组开门。在无屏蔽门电路时使用 func setPscKm8(psc *component.Psc) { psc.InterlockKM4 = false psc.InterlockKM8 = true psc.InterlockGM = false } // 直接设置PSC的状态关门。在无屏蔽门电路时使用 func setPscGm(psc *component.Psc) { psc.InterlockKM4 = false psc.InterlockKM8 = false psc.InterlockGM = true }