Skip to content

Commit

Permalink
Troops at outter village
Browse files Browse the repository at this point in the history
  • Loading branch information
Spamercz committed Feb 14, 2016
1 parent 1ffbc95 commit fbfb5dd
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 49 deletions.
10 changes: 10 additions & 0 deletions App/GameModule/Model/Units/UnitModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,14 @@
class UnitModel extends App\Model\BaseModel
{
protected $table = 'unit';


/**
* @return array
*/
public function getNames()
{
return $this->database->select('id, name')->from($this->table)
->fetchPairs('id', 'name');
}
}
22 changes: 17 additions & 5 deletions App/GameModule/Model/Units/UnitService.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class UnitService
];

/**
* @var App\GameModule\Model\Units\UnitsModel
* @var App\GameModule\Model\Units\UnitModel
*/
private $unitModel;
/**
Expand Down Expand Up @@ -217,6 +217,9 @@ public function train($form, $values, $village)
} else {
$amount = $trainable;
}
if ($amount == 0) {
continue;
}

$this->VDataModel->update($village->getId(), [
'wood' => $village->getActualWood() - $amount * $unit->getWood(),
Expand Down Expand Up @@ -411,10 +414,10 @@ public function getTrainableUnits($village, $units)
*/
public function getTrainableUnit($village, $unit)
{
$wood = round($village->getActualWood() / $unit->getWood());
$clay = round($village->getActualClay() / $unit->getClay());
$iron = round($village->getActualIron() / $unit->getIron());
$crop = round($village->getActualCrop() / $unit->getCrop());
$wood = floor($village->getActualWood() / $unit->getWood());
$clay = floor($village->getActualClay() / $unit->getClay());
$iron = floor($village->getActualIron() / $unit->getIron());
$crop = floor($village->getActualCrop() / $unit->getCrop());
return min($wood, $clay, $iron, $crop);
}

Expand All @@ -429,4 +432,13 @@ public function getUnits($village)

return $unitData;
}


/**
* @return array
*/
public function getNames()
{
return $this->unitModel->getNames();
}
}
8 changes: 8 additions & 0 deletions App/GameModule/Presenters/OuterVillagePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ class OuterVillagePresenter extends GamePresenter
/** @var App\FrontModule\Model\VData\VDataModel @inject */
public $VDataModel;

/** @var App\GameModule\Model\Units\UnitsModel @inject */
public $unitsModel;

/** @var App\GameModule\Model\Units\UnitService @inject */
public $unitService;


public function startup()
{
Expand All @@ -37,6 +43,8 @@ public function actionDefault($id)
$id = $field->wref;
}
$this->template->village = $this->villageService->getVillage($id);
$this->template->units = $this->unitsModel->get($id);
$this->template->unitNames = $this->unitService->getNames();
}


Expand Down
30 changes: 30 additions & 0 deletions App/GameModule/Templates/OuterVillage/default.latte
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,36 @@
</tr>
</tbody>
</table>
<table id="troops" cellpadding="1" cellspacing="1">
<thead>
<tr>
<th colspan="3">Troops</th>
</tr>
</thead>
<tbody>
{var $hasUnits = FALSE}
{for $i = 1; $i < 50; $i++}
{if $units['u' . $i] > 0}
<tr>
<td class="ico">
<img class="unit u{$i}" src="{$baseUrl}/img/x.gif"
alt="{$unitNames[$i]}" title="{$unitNames[$i]}" />
</td>
<td class="num">
{$units['u' . $i]}
</td>
<td class="un">
{$unitNames[$i]}
</td>
</tr>
{var $hasUnits = TRUE}
{/if}
{/for}
<tr n:if=" ! $hasUnits">
<td>none</td>
</tr>
</tbody>
</table>
</div>
{control building}
</div>
Expand Down
37 changes: 0 additions & 37 deletions www/Templates/troops.tpl

This file was deleted.

5 changes: 0 additions & 5 deletions www/Templates/version.tpl

This file was deleted.

2 changes: 0 additions & 2 deletions www/dorf1.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

<?php
include("Templates/movement.tpl");
// --production--
include("Templates/troops.tpl");

?>

Expand Down

0 comments on commit fbfb5dd

Please sign in to comment.