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

36 lines
698 B
Go

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