public override void Update(GameTime gameTime) { if (Online) { var storage = Parant.FindAllSubsystems <IStorage>(); float consumption = CurrentFuelConsumption * (float)gameTime.ElapsedGameTime.TotalSeconds; for (int i = 0; consumption > 0; i++) { if (storage.Count <= i) { Online = false; CurrentSpeed = 0; } consumption -= storage[i].GetItem(Item.GetFuel(consumption)).Amount; } } base.Update(gameTime); }
protected void GetEngineSpeed()//XXX: possible performance issue, easy to adjust { var engines = Parant.FindAllSubsystems <IEngine>(); engines.RemoveAll(p => !(p as Subsystem).Online); AssignedEngines = engines; float weightedTurnSpeeds = 0; MaxSpeed = 0; MinSpeed = 0; EngineAcceleration = 0; foreach (var elem in engines) { weightedTurnSpeeds += elem.MaxTurnSpeed * elem.MaxSpeed; MaxSpeed += elem.MaxSpeed; MinSpeed += elem.MinSpeed; EngineAcceleration += elem.EngineAcceleration; } MaxTurnSpeed = weightedTurnSpeeds / MaxSpeed; }