// Returns amount of excess fuel public float addFuel(float amount, GameManager.FuelType type) { if (type != this.type) { this.type = type; fuelAmount = 0; } if (amount <= 0.0f) { return(0.0f); } ; fuelAmount += amount; this.lightTorch(); if (fuelAmount > maxFuel) { float retVal = fuelAmount - maxFuel; fuelAmount = maxFuel; return(retVal); } else { return(0.0f); } }
public float addFuel(float amount, GameManager.FuelType type) { if (amount <= 0) { return(0.0f); } // If new type override type if (type != this.type) { this.type = type; quantity = 0; } // Otherwise just add to existing type quantity += amount; if (quantity > maxFuel) { return(quantity - maxFuel); } else { return(0.0f); } }
public float SetFuel(float amount, GameManager.FuelType type) { this.type = type; quantity = amount; if (quantity > maxFuel) { // Return excess float retVal = quantity - maxFuel; quantity = maxFuel; return(retVal); } else { return(0.0f); } }
// If tank is of a different type, then return that too public FuelTank GetEmptiestFuelTankOfType(GameManager.FuelType type) { FuelTank emptiest = null; float leastAmountOfFuel = float.PositiveInfinity; foreach (FuelTank tank in fuelTanks) { if (tank.type != type && tank.quantity > 0.0f) continue; if (tank.quantity < leastAmountOfFuel) { emptiest = tank; leastAmountOfFuel = tank.quantity; } } return emptiest; }
public FuelTank(GameManager.FuelType type, float quantity) { this.type = type; this.quantity = quantity; }