<?php 

// Время перезарядки ящика в секундах
$TOWER_FREE_TIME = 60 * 60 * 12; 

// Стоимость ящика строителя
$TOWER_PRICE = 10; 

// Таблица валюты для покупки ящика
$TOWER_PRICE_TABLE = 'money';

// Название валюты 
$TOWER_COINS_NAME = array('Coins', 'Coins', 'Coins'); 

// Ссылка на биллинг
$TOWER_URL_BILLING = '/user/money/index.php';

// Прибавлять / Убавлять рейтинг пользователю?
$TOWER_USER_RATING = TRUE; 

// Название поля в user с рейтингом
$TOWER_USER_RATING_TABLE = 'rating';
$TOWER_USER_RATING_NAME = 'Rating';

// Еденица рейтинга за каждый метр башни
$TOWER_USER_RATING_COUNT = 1;

$TOWER_TIME_SHIED = 60 * 60;
$TOWER_TIME_SHIED_FULL = 60 * 60 * 6;

$_TOWER_HEIGHT_LOSE = array(10, 25, 50, 100, 250, 500, 1000, 5000, 10000, 25000, 50000, 100000); 
$_TOWER_HEIGHT_COST = array(1, 3, 10, 25, 40, 70, 100, 150, 200, 300, 500, 1000); 

$TOWER_GIFT = array(
    'plus5' => array(
        'name' => 'Rating 5+ to 7 days',
        'img'  => 'components/img/5plus_44.png',
        'img_big'  => 'components/img/5plus.png',
    ), 
    'money10' => array(
        'name' => des2num(10, $TOWER_COINS_NAME) . ' to your account!',
        'img'  => 'components/img/money10_44.png', 
        'img_big'  => 'components/img/money10.png',
    ), 
); 

/**
* h / b
* b 1
* p 2
* r 3 
* y 4
*/

$TOWER_BLOCKS = array(
    1 => array(1, 1), 
    2 => array(1, 2), 
    3 => array(1, 3), 
    4 => array(1, 4), 
    5 => array(2, 1), 
    6 => array(2, 2), 
    7 => array(2, 3), 
    8 => array(2, 4), 
    9 => array(3, 1), 
    10 => array(3, 2), 
    11 => array(3, 3), 
    12 => array(3, 4), 
    13 => array(4, 1), 
    14 => array(4, 2), 
    15 => array(4, 3), 
    16 => array(4, 4), 
); 

if (!empty($_SESSION['TOWER_NOTIFICATION'])) {
    $TOWER_NOTIFICATION = $_SESSION['TOWER_NOTIFICATION'];  
    $TOWER_NOTIFICATION_CLASS = $_SESSION['TOWER_NOTIFICATION_CLASS'];  
    $_SESSION['TOWER_NOTIFICATION'] = $_SESSION['TOWER_NOTIFICATION_CLASS'] = NULL;
}

/**
* Открываем ящик
*/

function getTowerBox() 
{
    $array = array(); 
    $array['type'] = $type = (mt_rand(1, 20) == 1 ? 2 : 1); 
    
    if ($type == 1) {
        $count = 3;
        for($i = 1; $i <= $count; $i++) {
            $array['item'][$i] = mt_rand(1, 16);
        }
    }
    
    else {
        $array['item'] = 1; 
    }
    
    return $array; 
}

function getTowerBlocks($uid = 0, $color = 0) {
    $q = mysql_query("SELECT *, COUNT(uid) AS cnt
                      FROM tower_blocks WHERE userId = '" . $uid . "'
                      GROUP BY uid"); 
    
    $array = array(); 
    
    while($block = mysql_fetch_assoc($q)) {
        if ($color && $block['colorBottom'] == $color) {
            $array['there'][$block['uid']] = $block['cnt']; 
        }
        
        else {
            $array['other'][$block['uid']] = $block['cnt']; 
        }
    }
    
    return $array; 
}

function getTowerFreeTime($time = 0) 
{
    global $TOWER_FREE_TIME; 
    
    $time = ($TOWER_FREE_TIME - (time() - $time)); 
    
    if ($time > 0) {
      	$hours = floor($time / 3600);
        
      	if ($hours > 0)$hours = $hours . 'h ';
      	else $hours = NULL;
        
      	$min = floor($minutes = ($time / 3600 - $hours)*60);
        if ($min > 0)
            $min .= 'Мin ';
      	else $min = NULL;
        
      	if ($hours <= 0 && $minutes < 10)$sec = ceil(($minutes - floor($minutes)) * 60) . 'sec ';
        else $sec = NULL; 
        
      	return $hours . $min . $sec;
    }
}

function getTowerShieldTime($time = 0) 
{
    if ($time > 0) {
      	$hours = floor($time / 3600);
        
      	if ($hours > 0)$hours = $hours . 'h ';
      	else $hours = NULL;
        
      	$min = floor($minutes = ($time / 3600 - $hours)*60);
        if ($min > 0)
            $min .= 'min ';
      	else $min = NULL;
        
      	if ($hours <= 0 && $minutes < 10)$sec = ceil(($minutes - floor($minutes)) * 60) . 'sec ';
        else $sec = NULL; 
        
      	return $hours . $min . $sec;
    }
}

function star2galaxy($L = 0) 
{
  	$R = array(1 => 5, 2 => 25, 3 => 75, 4 => 375, 5 => 1875, 6 => 9375, 7 => 46875, 8 => 234375); 

    arsort($R);
    
    $stars = array(); 
    foreach($R AS $key => $value) {
        $res = floor($L / $value); 
        
        if ($res) {
            for($i = 1; $i <= $res; $i++) {                
                $stars[] = '<img src="components/img/star/' . $key . '.png" />';
                $L -= $value; 
            } 
        }
    }
    
    return '<span class="galaxy-star">' . implode('', $stars) . '</span>';
}
