rts-sim-module/sys/iscs_sys/iscs_pscada_pipe_fitting.go

60 lines
1.6 KiB
Go
Raw Normal View History

package iscs_sys
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/entity"
)
type PipeFittingSystem struct {
}
func NewPipeFittingSystem() *PipeFittingSystem {
return &PipeFittingSystem{}
}
// Update 母线管件电能传递
func (s *PipeFittingSystem) Update(w ecs.World) {
wd := entity.GetWorldData(w)
for _, pf := range wd.Repo.PipeFittingMap {
if pf.IsEle() {
//与管件连接的所有管线
pipes := pf.Ports()
//筛选出相对电源
pipePsMap := make(map[string]*component.ElePower)
for _, pipePort := range pipes {
pipeEntry := wd.EntityMap[pipePort.Device().Id()]
powerPipe := component.PowerPipeType.Get(pipeEntry)
for epId, ep := range powerPipe.Sources {
pipePs, ok := pipePsMap[epId]
if ok {
if ep.Fresh > pipePs.Fresh {
pipePsMap[epId] = ep
}
} else {
pipePsMap[epId] = ep
}
}
}
//管件连接的管线间电能传递
for _, pipePort := range pipes {
for pipePsId, pipePs := range pipePsMap { //相对电源
pipeEntry := wd.EntityMap[pipePort.Device().Id()]
powerPipe := component.PowerPipeType.Get(pipeEntry)
pipePortPs, ok := powerPipe.Sources[pipePsId]
if ok {
if pipePs.Fresh > pipePortPs.Fresh {
*powerPipe.Sources[pipePsId] = *pipePs
powerPipe.Sources[pipePsId].Fresh -= 1 //保证相对性
}
} else {
powerPipe.Sources[pipePsId] = &component.ElePower{}
*powerPipe.Sources[pipePsId] = *pipePs
powerPipe.Sources[pipePsId].Fresh -= 1 //保证相对性
}
}
}
}
}
}