import { CityWithLocation, CityRepository } from "../repository/city";
import * as _ from 'lodash';
+function percent(curr: number, max: number, cap?: number): number {
+ const val = Math.ceil((curr/max) * 100);
+ if(cap && val > cap) {
+ return cap;
+ }
+
+ return val;
+}
+
type Usage = {
foodUsagePerTick: number;
foodProductionPerTick: number;
</tr>
<tr>
<th>Food</th>
- <td>${city.food.toLocaleString()} (<span class="rate-of-change ${foodRateOfChange < 0 ? 'danger-text' : 'success-text'}">${foodRateOfChange.toLocaleString()}</span>)</td>
+ <td>
+ ${city.food.toLocaleString()} (<span class="rate-of-change ${foodRateOfChange < 0 ? 'danger-text' : 'success-text'}">${foodRateOfChange.toLocaleString()}</span>) @ ${percent(city.food, city.warehouses, 100)}% Warehouse utilization
+ </td>
</tr>
</table>
</div>
sp_defenders: number;
homes: number;
farms: number;
+ warehouses: number;
barracks: number;
special_attacker_trainer: number;
special_defender_trainer: number;
sp_attackers: 0,
sp_defenders: 0,
homes: 20,
- farms: 0,
+ farms: 5,
+ warehouses: 5,
barracks: 0,
special_attacker_trainer: 0,
special_defender_trainer: 0,
return city.homes * 25;
}
+ maxFood(city: City): number {
+ return city.warehouses * 250;
+ }
+
async foodProductionPerTick(city: City): Promise<number> {
// eventually we should supply the warehouse formula
// to calculate the max amount of food created per tick