import { Account } from "../repository/accounts";
-import { CityWithLocation } from "../repository/city";
+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;
energyProductionPerTick: number;
}
+const cityRepo = new CityRepository();
+
export function renderKingomOverview(city: CityWithLocation & Usage, account: Account): string {
const foodRateOfChange = city.foodProductionPerTick - city.foodUsagePerTick;
const energyRateOfChange = city.energyProductionPerTick - city.energyUsagePerTick;
<th>Captain</th>
<td>${account.username}</td>
<th>Population</th>
- <td>${city.population.toLocaleString()}/${_.max([city.farms * 70, city.population])}</td>
+ <td>${city.population.toLocaleString()}/${cityRepo.maxPopulation(city)}</td>
</tr>
<tr>
<th>Space</th>
</tr>
<tr>
<th>Alloys</th>
- <td>${city.alloys.toLocaleString()}</td>
+ <td>${city.alloys.toLocaleString()} @ ${percent(city.alloys, cityRepo.maxAlloy(city), 100)} % Ore Refiniery Utilization</td>
<th>Special Attackers</th>
<td>${city.sp_attackers.toLocaleString()}</td>
</tr>
<tr>
<th>Energy</th>
- <td>${city.energy.toLocaleString()} (<span class="rate-of-change ${energyRateOfChange < 0 ? 'danger-text' : 'success-text'}">${energyRateOfChange.toLocaleString()}</span>)</td>
+ <td>
+ ${city.energy.toLocaleString()} (<span class="rate-of-change ${energyRateOfChange < 0 ? 'danger-text' : 'success-text'}">${energyRateOfChange.toLocaleString()}</span>)
+ @ ${percent(city.energy, cityRepo.maxEnergy(city), 100)}% Accumulator Utilization
+ </td>
<th>Special Defenders</th>
<td>${city.sp_defenders.toLocaleString()}</td>
</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, cityRepo.maxFood(city), 100)}% Warehouse utilization
+ </td>
</tr>
</table>
</div>