94 lines
3.0 KiB
Go
94 lines
3.0 KiB
Go
package iscs_sys
|
|
|
|
import (
|
|
"joylink.club/ecs"
|
|
"joylink.club/ecs/filter"
|
|
"joylink.club/rtsssimulation/component"
|
|
"joylink.club/rtsssimulation/entity"
|
|
"joylink.club/rtsssimulation/repository"
|
|
)
|
|
|
|
type CircuitBreakerSystem struct {
|
|
query *ecs.Query
|
|
}
|
|
|
|
func NewCircuitBreakerSystem() *CircuitBreakerSystem {
|
|
return &CircuitBreakerSystem{
|
|
query: ecs.NewQuery(filter.Contains(component.UidType, component.CircuitBreakerType, component.DeviceExceptionType)),
|
|
}
|
|
}
|
|
func (s *CircuitBreakerSystem) Update(w ecs.World) {
|
|
s.circuitBreakerTransPower(w)
|
|
|
|
}
|
|
|
|
// 断路器传递电能
|
|
func (s *CircuitBreakerSystem) circuitBreakerTransPower(w ecs.World) {
|
|
wd := entity.GetWorldData(w)
|
|
s.query.Each(w, func(entry *ecs.Entry) {
|
|
breakerId := component.UidType.Get(entry).Id
|
|
closed := component.CircuitBreakerType.Get(entry).Closed
|
|
breakerModel := (wd.Repo.FindById(breakerId)).(*repository.CircuitBreaker)
|
|
//断路器A端连接的管线
|
|
breakerPortA := breakerModel.PortA
|
|
//断路器B端连接的管线
|
|
breakerPortB := breakerModel.PortB
|
|
//传递电能
|
|
towPipePortsTransPower(wd, closed, breakerPortA, breakerPortB)
|
|
})
|
|
}
|
|
|
|
// 两位置开关传递电能(断路器、手车、隔离开关)
|
|
func towPipePortsTransPower(
|
|
wd *component.WorldData,
|
|
closed bool,
|
|
breakerPortA *repository.PipePort,
|
|
breakerPortB *repository.PipePort) {
|
|
//断路器A端连接的管线
|
|
breakerPortAPipeEntry := wd.EntityMap[breakerPortA.Device().Id()]
|
|
breakerPortAPipe := component.PowerPipeType.Get(breakerPortAPipeEntry)
|
|
//断路器B端连接的管线
|
|
breakerPortBPipeEntry := wd.EntityMap[breakerPortB.Device().Id()]
|
|
breakerPortBPipe := component.PowerPipeType.Get(breakerPortBPipeEntry)
|
|
//A->B
|
|
for portAPipePsId, portAPipePs := range breakerPortAPipe.Sources { //A
|
|
portBPipePs, ok := breakerPortBPipe.Sources[portAPipePsId] //B
|
|
if ok {
|
|
if portAPipePs.Fresh > portBPipePs.Fresh {
|
|
*breakerPortBPipe.Sources[portAPipePsId] = *portAPipePs
|
|
breakerPortBPipe.Sources[portAPipePsId].Fresh -= 1
|
|
if !closed {
|
|
breakerPortBPipe.Sources[portAPipePsId].Voltage = 0
|
|
}
|
|
}
|
|
} else {
|
|
breakerPortBPipe.Sources[portAPipePsId] = &component.ElePower{}
|
|
*breakerPortBPipe.Sources[portAPipePsId] = *portAPipePs
|
|
breakerPortBPipe.Sources[portAPipePsId].Fresh -= 1
|
|
if !closed {
|
|
breakerPortBPipe.Sources[portAPipePsId].Voltage = 0
|
|
}
|
|
}
|
|
}
|
|
//B->A
|
|
for portBPipePsId, portBPipePs := range breakerPortBPipe.Sources { //B
|
|
portAPipePs, ok := breakerPortAPipe.Sources[portBPipePsId] //A
|
|
if ok {
|
|
if portBPipePs.Fresh > portAPipePs.Fresh {
|
|
*breakerPortAPipe.Sources[portBPipePsId] = *portBPipePs
|
|
breakerPortAPipe.Sources[portBPipePsId].Fresh -= 1
|
|
if !closed {
|
|
breakerPortAPipe.Sources[portBPipePsId].Voltage = 0
|
|
}
|
|
}
|
|
} else {
|
|
breakerPortAPipe.Sources[portBPipePsId] = &component.ElePower{}
|
|
*breakerPortAPipe.Sources[portBPipePsId] = *portBPipePs
|
|
breakerPortAPipe.Sources[portBPipePsId].Fresh -= 1
|
|
if !closed {
|
|
breakerPortAPipe.Sources[portBPipePsId].Voltage = 0
|
|
}
|
|
}
|
|
}
|
|
}
|