</tr>
<tr>
<th>Soldiers</th>
- <td>${city.population}</td>
+ <td>${city.soldiers}</td>
<td>
<form hx-post="/units">
<input type="number" name="amount" size="6" max="${city.population}" hx-trigger="keyup" hx-post="/cost/training" hx-target="#${unit.soldiers.slug}-cost">
</tr>
<tr>
<th>Attackers</th>
- <td>${city.soldiers}</td>
+ <td>${city.attackers}</td>
<td>
<form hx-post="/units">
<input type="number" name="amount" size="6" max="${city.soldiers}" hx-trigger="keyup" hx-post="/cost/training" hx-target="#${unit.attackers.slug}-cost">
</tr>
<tr>
<th>Defenders</th>
- <td>${city.soldiers}</td>
+ <td>${city.defenders}</td>
<td>
<form hx-post="/units">
<input type="number" name="amount" size="6" max="${city.soldiers}" hx-trigger="keyup" hx-post="/cost/training" hx-target="#${unit.defenders.slug}-cost">
</tr>
<tr>
<th>Special Attackers</th>
- <td>${city.attackers}</td>
+ <td>${city.sp_attackers}</td>
<td>
<form hx-post="/units">
<input type="number" name="amount" size="6" max="${city.attackers}" hx-trigger="keyup" hx-post="/cost/training" hx-target="#${unit.sp_attackers.slug}-cost">
</tr>
<tr>
<th>Special Defenders</th>
- <td>${city.defenders}</td>
+ <td>${city.sp_defenders}</td>
<td>
<form hx-post="/units">
<input type="number" name="amount" size="6" max="${city.defenders}" hx-trigger="keyup" hx-post="/cost/training" hx-target="#${unit.sp_defenders.slug}-cost">
throw new InsufficientResourceError('defenders', unit.defenders, city.defenders);
}
+ console.log(city);
+ console.log(unit, amount);
+
// validate that they have enough of the buildings to support this
// ok they have everything, lets update their city
city.credits -= unit.credits * amount;
city.food -= unit.food * amount;
- city.population -= coalesce(unit.population, 0) * amount;
- city.soldiers -= coalesce(unit.soldiers, 0) * amount;
- city.attackers -= coalesce(unit.attackers, 0) * amount;
- city.defenders -= coalesce(unit.defenders, 0) * amount;
+ city.population -= unit.population * amount;
+ city.soldiers -= unit.soldiers * amount;
+ city.attackers -= unit.attackers * amount;
+ city.defenders -= unit.defenders * amount;
+
+ console.log(city);
await this.save(city);