rts-sim-module/fi/psd.go

187 lines
4.7 KiB
Go

package fi
import (
"fmt"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"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 {
setPsdKm(entry, 4)
} 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 {
cancelPsdKm(entry, 4)
} 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 {
setPsdKm(entry, 8)
} 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 {
cancelPsdKm(entry, 8)
} 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 {
setPsdGm(entry)
} 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 {
cancelPsdGm(entry)
} else {
return ecs.NewErrResult(fmt.Errorf("未找到id=%s的屏蔽门", id))
}
return ecs.NewOkEmptyResult()
})
return result.Err
}
func setPsdKm(psdEntry *ecs.Entry, group int) {
if psdEntry.HasComponent(component.PsdInterlockDriveCircuitType) { //有联锁区段电路
driveCircuit := component.PsdInterlockDriveCircuitType.Get(psdEntry)
switch group {
case 4:
setPsdDriveKm4(driveCircuit)
case 8:
setPsdDriveKm8(driveCircuit)
}
} else {
psc := component.PscType.Get(psdEntry)
switch group {
case 4:
setPscKm4(psc)
case 8:
setPscKm8(psc)
}
}
}
func cancelPsdKm(psdEntry *ecs.Entry, group int) {
if psdEntry.HasComponent(component.PsdInterlockDriveCircuitType) { //有联锁区段电路
driveCircuit := component.PsdInterlockDriveCircuitType.Get(psdEntry)
switch group {
case 4:
driveCircuit.KMJ4 = false
case 8:
driveCircuit.KMJ8 = false
}
} else {
psc := component.PscType.Get(psdEntry)
switch group {
case 4:
psc.InterlockKM4 = false
case 8:
psc.InterlockKM8 = false
}
}
}
func setPsdGm(psdEntry *ecs.Entry) {
if psdEntry.HasComponent(component.PsdInterlockDriveCircuitType) { //有联锁区段电路
driveCircuit := component.PsdInterlockDriveCircuitType.Get(psdEntry)
setPsdDriveGm(driveCircuit)
} else {
psc := component.PscType.Get(psdEntry)
setPscGm(psc)
}
}
func cancelPsdGm(psdEntry *ecs.Entry) {
if psdEntry.HasComponent(component.PsdInterlockDriveCircuitType) { //有联锁区段电路
driveCircuit := component.PsdInterlockDriveCircuitType.Get(psdEntry)
driveCircuit.GMJ = false
} else {
psc := component.PscType.Get(psdEntry)
psc.InterlockGM = false
}
}
func setPsdDriveKm4(driveCircuit *component.PsdInterlockDriveCircuit) {
driveCircuit.KMJ4 = true
driveCircuit.KMJ8 = false
driveCircuit.GMJ = false
}
func setPsdDriveKm8(driveCircuit *component.PsdInterlockDriveCircuit) {
driveCircuit.KMJ4 = false
driveCircuit.KMJ8 = true
driveCircuit.GMJ = false
}
func setPsdDriveGm(driveCircuit *component.PsdInterlockDriveCircuit) {
driveCircuit.KMJ4 = false
driveCircuit.KMJ8 = false
driveCircuit.GMJ = true
}
func setPscKm4(psc *component.Psc) {
psc.InterlockKM4 = true
psc.InterlockKM8 = false
psc.InterlockGM = false
}
func setPscKm8(psc *component.Psc) {
psc.InterlockKM4 = false
psc.InterlockKM8 = true
psc.InterlockGM = false
}
func setPscGm(psc *component.Psc) {
psc.InterlockKM4 = false
psc.InterlockKM8 = false
psc.InterlockGM = true
}