<?php

#################################################################################
##              -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =-                 ##
## --------------------------------------------------------------------------- ##
##  Filename       : CRANNY                                                    ##
##  Type           : BUILDING TEMPLATE                                         ##
## --------------------------------------------------------------------------- ##
##  Refactored by  : Shadow                                                    ##
##  Redesign by    : Shadow                                                    ##
## --------------------------------------------------------------------------- ##
##  Contact        : cata7007@gmail.com                                        ##
##  Project        : TravianZ                                                  ##
##  Test Server    : https://travianz.org                                      ##
##  GitHub         : https://github.com/Shadowss/TravianZ                      ##
## --------------------------------------------------------------------------- ##
##  License        : TravianZ Project                                          ##
##  Copyright      : TravianZ (c) 2010-2026. All rights reserved.              ##
## --------------------------------------------------------------------------- ##
#################################################################################

global $session, $village, $database, $bid23, $id, $loopsame, $doublebuild, $master;

include("next.tpl");

$multiplier = (($session->tribe == 3) ? 2 : 1) * CRANNY_CAPACITY;
$actualLevel = (int)$village->resarray['f'.$id];
$level = min($actualLevel + 1 + $loopsame + $doublebuild + $master, 10);

// FIX (PHP log): $bid23 e indexat de la nivel 1 (nu are cheia 0). Daca
// cranny e la nivel 0 (abia demolat/darat jos de catapulte, sau link
// deschis inainte ca nivelul curent sa fi fost incarcat), $bid23[0] nu
// exista -> "Undefined array key 0" + acces pe null pe linia urmatoare.
// La nivel 0 nu exista "attri" curent, deci tratam ca 0 unitati ascunse.
$currentAttri = $actualLevel > 0 ? $bid23[$actualLevel]['attri'] : 0;
$currentHidden = $database->getArtifactsValueInfluence($session->uid, $village->wid, 7, $currentAttri * $multiplier);
$nextHidden = $database->getArtifactsValueInfluence($session->uid, $village->wid, 7, $bid23[$level]['attri'] * $multiplier);
?>
<div id="build" class="gid23">
    <a href="#" onClick="return Popup(23,4);" class="build_logo">
        <img class="building g23" src="img/x.gif" alt="<?php echo CRANNY; ?>" title="<?php echo CRANNY;?>" />
    </a>
    <h1><?php echo CRANNY;?> <span class="level"><?php echo LEVEL;?> <?php echo $actualLevel;?></span></h1>
    <p class="build_desc"><?php echo CRANNY_DESC;?></p>

    <table cellpadding="1" cellspacing="1" id="build_value">
        <tr>
            <th><?php echo CURRENT_HIDDEN_UNITS;?></th>
            <td><b><?php echo $currentHidden;?></b> <?php echo UNITS;?></td>
        </tr>
        <?php if ($actualLevel < 10):?>
        <tr>
            <th><?php echo HIDDEN_UNITS_LEVEL;?> <?php echo $level;?>:</th>
            <td><b><?php echo $nextHidden;?></b> <?php echo UNITS;?></td>
        </tr>
        <?php endif;?>
    </table>

    <?php include("upgrade.tpl");?>
</div>