rts-sim-module/sys/iscs_sys/iscs_pscada_power_pipe.go
2024-01-05 11:30:39 +08:00

40 lines
759 B
Go

package iscs_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
)
// PowerPipeSystem 电力
type PowerPipeSystem struct {
query *ecs.Query
}
func NewPowerPipeSystem() *PowerPipeSystem {
return &PowerPipeSystem{
query: ecs.NewQuery(filter.Contains(component.PipeElectricityType)),
}
}
// Update 电线中电力计算
func (s *PowerPipeSystem) Update(w ecs.World) {
s.query.Each(w, func(entry *ecs.Entry) {
pipe := component.PipeElectricityType.Get(entry)
voltage := uint32(0)
ac := false
sx := false
for _, power := range pipe.Sources {
if power.U > voltage {
voltage = power.U
ac = power.Ac
sx = power.Sx
}
}
//
pipe.U = voltage
pipe.Ac = ac
pipe.Sx = sx
})
}