vibes
This commit is contained in:
+32
-7
@@ -37,6 +37,22 @@ func (s *State) RunDay(cfg config.Config, in DayInput) (DayResult, error) {
|
||||
res.Events = append(res.Events, Event{0, l.ShipID, "launch", ""})
|
||||
}
|
||||
sort.Slice(s.Ships, func(i, j int) bool { return s.Ships[i].ID < s.Ships[j].ID })
|
||||
s.migrateLegacyCargo()
|
||||
|
||||
// Scrapped ships vanish; whatever they were towing is left adrift where it is.
|
||||
for _, id := range in.Scraps {
|
||||
for i, sh := range s.Ships {
|
||||
if sh.ID != id {
|
||||
continue
|
||||
}
|
||||
if sh.Alive {
|
||||
s.releaseTow(sh, dayStart)
|
||||
}
|
||||
s.Ships = append(s.Ships[:i], s.Ships[i+1:]...)
|
||||
res.Events = append(res.Events, Event{0, id, "scrapped", ""})
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Uplinks land in the RX buffer at the start of RAM.
|
||||
for _, u := range in.Uplinks {
|
||||
@@ -57,16 +73,24 @@ func (s *State) RunDay(cfg config.Config, in DayInput) (DayResult, error) {
|
||||
now := dayStart + int64(tick)*dt
|
||||
stPos, stVel = s.Station.Orbit.State(now)
|
||||
tc := newTickCtx(s, cfg, tick, now, stPos, stVel, &res, &sold)
|
||||
s.sellNearStation(tc) // ore in containers left near the station is sold...
|
||||
s.expireContainers(tc) // ...and containers adrift for ten days vanish
|
||||
for _, sh := range s.Ships {
|
||||
if !sh.Alive {
|
||||
continue
|
||||
}
|
||||
sh.CPU.Run(&shipBus{tc: tc, sh: sh}, cfg.CyclesPerTick)
|
||||
s.physics(cfg, sh, dt, tick, &res)
|
||||
if sh.Alive && sh.Mining {
|
||||
s.mine(sh, tc.now+dt)
|
||||
if sh.Alive {
|
||||
s.syncTow(sh)
|
||||
if sh.Mining {
|
||||
s.mine(sh, tc.now+dt)
|
||||
}
|
||||
} else {
|
||||
s.releaseTow(sh, tc.now)
|
||||
}
|
||||
}
|
||||
s.driftContainers(cfg.OrbitSpeed, dt, tick, &res)
|
||||
}
|
||||
|
||||
for _, sh := range s.Ships {
|
||||
@@ -109,7 +133,7 @@ func (s *State) physics(cfg config.Config, sh *Ship, dt int64, tick int, res *Da
|
||||
burn = sh.Fuel
|
||||
}
|
||||
// dv (km/s) = thrust*dt / mass / 1000.
|
||||
dv := fixed.FromInt(thrust * dt).Div(sh.Mass()).DivInt(1000)
|
||||
dv := fixed.FromInt(thrust * dt).Div(s.shipMass(sh)).DivInt(1000)
|
||||
sh.Vel = sh.Vel.Add(thrustDir(sh).Scale(dv))
|
||||
sh.Fuel -= burn
|
||||
}
|
||||
@@ -132,8 +156,9 @@ func (s *State) canReach(sh *Ship, pos, vel fixed.Vec, rangeKm int64) bool {
|
||||
relV.Len() <= fixed.FromRatio(MaxRelSpeedM, 1000)
|
||||
}
|
||||
|
||||
// mine moves ore from the target asteroid into the ship's hold, split
|
||||
// proportionally to the asteroid's composition. at is the absolute time (s)
|
||||
// mine moves ore from the target asteroid into the containers the ship is towing,
|
||||
// split proportionally to the asteroid's composition. With no container in tow, or
|
||||
// none with room, nothing is mined. at is the absolute time (s)
|
||||
// at which range is evaluated.
|
||||
func (s *State) mine(sh *Ship, at int64) {
|
||||
a := s.asteroid(sh.Target)
|
||||
@@ -141,7 +166,7 @@ func (s *State) mine(sh *Ship, at int64) {
|
||||
return
|
||||
}
|
||||
total := a.TotalOre()
|
||||
room := sh.Hull.CargoCap - sh.CargoTotal()
|
||||
room := s.towOf(sh.ID).Room
|
||||
amt := min(sh.Hull.MineRate, room, total)
|
||||
if amt <= 0 {
|
||||
return
|
||||
@@ -163,8 +188,8 @@ func (s *State) mine(sh *Ship, at int64) {
|
||||
}
|
||||
for o, kg := range taken {
|
||||
a.Ore[o] -= kg
|
||||
sh.Cargo[o] += kg
|
||||
}
|
||||
s.fillTow(sh.ID, taken)
|
||||
}
|
||||
|
||||
// thrustDir converts the ship's azimuth/pitch (milliradians) to a unit vector.
|
||||
|
||||
Reference in New Issue
Block a user