1
<?php
2
/**
3
 *   File functions:
4
 *   Hospital - heal and resurrect players
5
 *
6
 *   @name                 : hospital.php                            
7
 *   @copyright            : (C) 2004,2005,2006,2007 Vallheru Team based on Gamers-Fusion ver 2.5
8
 *   @author               : thindil <thindil@users.sourceforge.net>
9
 *   @version              : 1.3
10
 *   @since                : 24.02.2007
11
 *
12
 */
13
14
//
15
//
16
//       This program is free software; you can redistribute it and/or modify
17
//   it under the terms of the GNU General Public License as published by
18
//   the Free Software Foundation; either version 2 of the License, or
19
//   (at your option) any later version.
20
//
21
//   This program is distributed in the hope that it will be useful,
22
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
23
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
//   GNU General Public License for more details.
25
//
26
//   You should have received a copy of the GNU General Public License
27
//   along with this program; if not, write to the Free Software
28
//   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
29
//
30
// $Id: hospital.php 898 2007-02-24 21:24:28Z thindil $
31
32
$title = "Uzdrowiciel";
33
require_once("includes/head.php");
34
35
/**
36
* Get the localization for game
37
*/
38
require_once("languages/".$player -> lang."/hospital.php");
39
40
if ($player -> location != 'Altara' && $player -> location != 'Ardulith') 
41
{
42
    error(ERROR);
43
}
44
45
$mytribe = $db -> Execute("SELECT `hospass` FROM `tribes` WHERE `id`=".$player -> tribe);
46
$resurect_time = $db -> Execute("SELECT `resurect` FROM `players` WHERE `id`=".$player -> id);
47
//$crneed = ($player -> max_hp - $player -> hp) * 3;
48
if (!isset ($_GET['action'])) 
49
{
50
    if ($player -> hp == $player -> max_hp) 
51
    {
52
        error(STOP_WASTE." (<a href=\"city.php\">".BACK."</a>)");
53
    }
54
    $smarty -> assign ("hpneeded",($player -> max_hp - $player -> hp));
55
    $smarty -> assign ("sure","");
56
    $smarty -> assign ("Costtext",(COSTTEXT." 3 ".GOLD_COINS2));
57
    if ($player -> hp > 0) 
58
    {
59
        $crneed = ($player -> max_hp - $player -> hp) * 3;
60
		$basecrneed = 3;
61
        if ($player -> tribe > 0) 
62
        {
63
            if ($mytribe -> fields['hospass'] == "Y" && $player -> hp > 0) 
64
            {
65
                $crneed = ceil($crneed / 2);
66
				$basecrneed = 1.5;
67
                $smarty -> assign ("Costtext",(COSTTEXT." 1.5 ".GOLD_COINS2));
68
                $smarty -> assign ("sure",SURE_IT);
69
//                error(COULD_YOU." <a href=hospital.php?action=heal>".A_HEAL."</a>?<br />".SURE_IT.$crneed.GOLD_COINS);
70
            }
71
//            $smarty -> assign ("Need",$crneed);
72
        }
73
        if ($crneed < 0)
74
        {
75
            $crneed = 0;
76
			$maxpoints = 0;
77
        }
78
		else
79
		{
80
			$maxpoints = floor($player -> credits / $basecrneed);
81
		}
82
        if ($maxpoints < 1) 
83
        {
84
            error(NO_MONEY2.$crneed.GOLD_COINS2." (<a href=\"city.php\">".BACK."</a>)");
85
        }
86
		if ($maxpoints > ($player -> max_hp - $player -> hp)) $maxpoints = ($player -> max_hp - $player -> hp);
87
        $smarty -> assign ("Need",$crneed);
88
		$smarty -> assign ("Maxpoints",$maxpoints);
89
    }
90
    if ($player -> hp <= 0) 
91
    {
92
    	$crneed = (75 * $player -> level);
93
    	if ($resurect_time -> fields['resurect'] > 0)
94
    	{
95
    		$been_resurect=BEEN_UNDER_RESURECT_POTION;
96
    	}
97
        else
98
        {
99
            if ($crneed > $player -> credits) 
100
            {
101
                error(NO_MONEY.$crneed.GOLD_COINS2." (<a href=\"city.php\">".BACK."</a>)");
102
                
103
            }
104
       }
105
       $smarty -> assign ("Need",$crneed);
106
    }
107
}
108
109
if (isset($_GET['action']) && $_GET['action'] == 'heal') 
110
{
111
    if ($player -> hp <= 0) 
112
    {
113
        error(BAD_ACTION);
114
    }
115
    $crneed = ($player -> max_hp - $player -> hp) * 3;
116
    if ($mytribe -> fields['hospass'] == "Y")
117
    {
118
        $crneed = ceil($crneed / 2);
119
    }
120
    if ($crneed < 0)
121
    {
122
        $crneed = 0;
123
    }
124
    if ($crneed > $player -> credits) 
125
    {
126
        error(NO_MONEY.$crneed.GOLD_COINS." (<a href=\"city.php\">".BACK."</a>)");
127
    }
128
    $db -> Execute("UPDATE `players` SET `hp`=`max_hp`, `credits`=`credits`-".$crneed." WHERE `id`=".$player -> id);
129
    error(YOU_HEALED." (<a href=\"city.php\">".BACK."</a>)");
130
}
131
if (isset($_GET['action']) && $_GET['action'] == 'pheal') 
132
{
133
    if ($player -> hp <= 0) 
134
    {
135
        error(BAD_ACTION);
136
    }
137
    $hpoints = (int)$_POST["amount"];
138
    if (!isset($hpoints) || $hpoints=="" || $hpoints > ($player -> max_hp - $player -> hp) )
139
    {
140
        error();
141
    }
142
    $crneed = $hpoints * 3;
143
    if ($mytribe -> fields['hospass'] == "Y")
144
    {
145
        $crneed = ceil($crneed / 2);
146
    }
147
    if ($crneed < 0)
148
    {
149
        $crneed = 0;
150
    }
151
    if ($crneed > $player -> credits) 
152
    {
153
        error(NO_MONEY.$crneed.GOLD_COINS." (<a href=\"city.php\">".BACK."</a>)");
154
    }
155
    $db -> Execute("UPDATE `players` SET `hp`=`hp`+".$hpoints.", `credits`=`credits`-".$crneed." WHERE `id`=".$player -> id);
156
    error(YOU_HEALED2." ".$hpoints." ".HPOINTS." (<a href=\"city.php\">".BACK."</a>)");
157
}
158
if($mytribe)
159
{
160
    $mytribe -> Close();
161
}
162
163
if (isset($_GET['action']) && $_GET['action'] == 'ressurect') 
164
{
165
    require_once('includes/resurect.php');
166
}
167
168
/**
169
* Initialization of variables
170
*/
171
if (!isset($_GET['action'])) 
172
{
173
    $_GET['action'] = '';
174
    $smarty -> assign(array("Resurect" => $resurect_time -> fields['resurect'],
175
    	                    "Ayes" => YES,
176
                            "Couldyou" => COULD_YOU,
177
                            "Couldyou2" => COULD_YOU2,
178
                            "Itcost" => IT_COST,
179
                            "Itcost2" => IT_COST2,
180
                            "Goldcoins" => GOLD_COINS2,
181
                            "Aheal" => A_HEAL,
182
                            "Iwant" => IWANT,
183
                            "hpoints" => HPOINTS,
184
                            "Been_under" => BEEN_UNDER_RESURECT_POTION));
185
}
186
187
/**
188
* Assign variables to template and display page
189
*/
190
$smarty -> assign("Action", $_GET['action']);
191
$smarty -> display('hospital.tpl');
192
193
require_once("includes/foot.php");
194
?>