Selador / stadt.php

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
<?php

/* stadt.php - Front-end code for the city view page
 *
 * Copyright (C) 2006, 2007, 2008 Kevin Read, Simone Schaefer
 *
 * This file is part of Selador, a browser-based fantasy strategy game
 *
 * This program is distributed under the terms of the GNU Affero General Public License.
 *
 *
 *   Selador is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Affero General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   any later version.
 *
 *   Selador is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Affero General Public License for more details.
 *
 *   You should have received a copy of the GNU Affero General Public License
 *   along with Selador.  If not, see <http://www.gnu.org/licenses/>.
 **/

// require_once("php/classes.php");
require_once("php/base/user.inc.php");
require_once("php/base.php");
require_once("php/event.php");
$body_onload = "allow_mouseover();\">";

require_once("headers.php");


$city_path="precity/";
$precalcpath = $city_path.$me->activevillageid;
// Acquire lock for village here!

$glob_build = array();
$buildingdur = 0;
// $glob_build = 0;  // FIXME bad
// Handle past events
// $me->event_handler (true, $me->activevillageid, $gui);


require_once ("php/citycont.php");
$build = city_fetch_db ($me->activevillageid);
$research = research_fetch_db ($me->uid);

// Then calculate ressources through checking income - this takes into account
// past events, because event_handler might have updated $secspassed
// $me->activevillage->do_income ();



// Test No 1: Construction and level set, and building queue not full
if (isset ($_REQUEST['r']) && isset ($_REQUEST['l']) && (count($gui->building_queue) < 2) && (!$me->activeoutpostid))
{
//sicher ist sicher
	if ($me->blocked == 1)
	{
		echo "<div id=\"stadt\">";
		echo $text_blocked;
		echo "</div>";
		$me->activevillage->update_stamp ();
		cleanup ();
		die();
	}

  $enhance = $_REQUEST['r'];
  $tolevel = $_REQUEST['l'];
  $levelfac = $tolevel * pow (NEXTLEVEL_COSTS, $tolevel - 1);

  if (isset ($build[$enhance]))
  {
		$build_id = $build[$enhance][7];

		// If we are already upgrading this building, mark it as being one level higher in the data
		if (isset ($gui->buildid_queue))
		{
			foreach ($gui->buildid_queue as $this_build)
				if ($this_build == $build_id)
					$build[$enhance][1]++;
		}

		if (!( $errstr = Calc_Building_Dep ($enhance, $build[$enhance][1], $build, $research, 1)))
		{
			// Test No. 2: Is the level that we want to enhance the thing to one more than the actual level?
			if ($build[$enhance][1]+1 == $tolevel)
			{
				// Test No. 3: Do we have enough ressources?
				if ($me->activevillage->can_spend ((int)($build[$enhance][2]*$levelfac), (int)($build[$enhance][3]*$levelfac), (int)($build[$enhance][4]*$levelfac), (int)($build[$enhance][15]*$levelfac)))
				{
					// Test No. 4: Counter reload build queue auto-submit
					if (!check_event_village2 ($me->uid, $me->activevillageid, 1, $tolevel, $build[$enhance][7]))
					{
						$costs = (int)(($build[$enhance][2] + $build[$enhance][3] + $build[$enhance][4] + $build[$enhance][15]) * $levelfac);
						$newbuiltdur =  max (1, (int)($costs * $me->activevillage->speed_build / WORLD_SPEED / BUILD_SPEED)) + (int)$gui->building_duration;

						// echo "<b>Dur:".$newbuiltdur."</b>";
						// Insert into event queue FIXME: Type depends on tile type, timestamp depends on finish time of last building in queue
						$query = "insert into event (uid1, village1, uid2, village2, type, param, param2, timestamp, score) values (".$me->uid.", ".$me->activevillageid.", 0, ".$build[$enhance][7].", 1, ".$tolevel.", ".$enhance.", addtime(now(), sec_to_time(".$newbuiltdur.")), ".$costs.")";
						if (!mysql_query ($query))
							log_err ("Cannot insert building event: ".$query.": ".mysql_error());
						else
						{
							$eid = mysql_insert_id ();
							$query = "insert into eventlog (eid, uid1, village1, uid2, village2, type, param, param2, fired, happened, score, state) values (".$eid.", ".$me->uid.", ".$me->activevillageid.", 0, ".$build[$enhance][7].", 1, ".$tolevel.", ".$enhance.", NULL, addtime(now(), sec_to_time(".$newbuiltdur.")), ".$costs.", 0)";

							if (!@mysql_query ($query))
								log_err ("Cannot log building event: ".$query.", ".mysql_error());

							log_info ($build[$enhance][0]." (".$bid.") angefangen, wird ".$newbuiltdur." Sekunden dauern. Query: ".$query);

							if (count ($gui->building_queue) == 0)
							{
								$gui->displayedtimers++;
								$gui->building_queue[$newbuiltdur] = $build[$enhance][0]." ".$tolevel." <span title=\"Fertig am ".date ("d.m. H:i:s", time () + $newbuiltdur)."\" id=\"timer".$gui->displayedtimers."\">";
								$gui->building_queue[$newbuiltdur] .= external_calcdur ($newbuiltdur)."</span>";
							}
							else
								$gui->building_queue[$newbuiltdur] = $build[$enhance][0]." ".$tolevel." <span title=\"Fertig am ".date ("d.m. H:i:s", time () + $newbuiltdur)."\">".external_calcdur ($newbuiltdur - (int)$gui->building_duration)."</span>";

							$me->activevillage->spend ((int)($build[$enhance][2]*$levelfac), (int)($build[$enhance][3]*$levelfac), (int)($build[$enhance][4]*$levelfac), (int)($build[$enhance][15]*$levelfac));

							// We should pass this on to the tutorial, if it is still going strong
							if (is_object ($tutorial))
							{
								if ($tutorial->active)
									$tutorial->upgrading_building ($enhance);
							}
						}

						// Add to global variable of buildings being built, so that we won't give the user the option
						// of enhancing the same level again
						$gui->buildid_queue[] = $build[$enhance][7];

						// Delete the cached files
						@unlink ($precalcpath."-0.php");
						@unlink ($precalcpath."-1.php");
						@unlink ($precalcpath."-2.php");
					}
				}
			}
		}
		else
		{
			$build_err = "Du erf&uuml;llst die Vorraussetzungen nicht: ".$errstr;
			log_info ("Cheater! Wanted to construct ".$enhance.", but missing ".$errstr);
		}
	}
	else
	{
		$build_err = "Dieses Geb&auml;ude existiert nicht";
		log_info ("Cheater! Wanted to construct ".$enhance);
	}
}

$me->activevillage->update_stamp ();

$build = city_fetch_db ($me->activevillageid);
$research = research_fetch_db ($me->uid);
$what = 1;

$list = $build;

$path = "gfx/b/".$me->race."/";

if ($me->race == 4)
{
	$gfxb[1] = array ("Stammeshalle", "469,234,470,214,591,141,617,180,609,192,523,255", 453, 121, 158, 127, 1);
	$gfxb[2] = array ("Schwarzmarkt", "164,57, 262,57,262,163,164,163", 164, 57, 98, 86, 1);
	$gfxb[3] = array ("Barracken", "11,121,286,121,286,227,11,227", 11, 121, 275, 105, 2);
	$gfxb[5] = array ("Sklavenlager", "556,271,594,276,594,252,630,237,664,273,723,280,729,320,700,323,698,341,613,346,598,317,558,307", 543, 227, 184, 109, 2);
	$gfxb[6] = array ("Lager", "544,103,544,126,576,142,636,139,611,77", 536, 74, 97, 69, 2);
	$gfxb[9] = array ("Kriegsschmiede", "107,192,305,192,305,337,107,337", 107, 192, 198, 145, 2);
	$gfxb[10] = array ("Schamane", "639,116,651,148,723,145,684,94", 633, 88, 63, 55, 1);
	$gfxb[11] = array ("Ringmauer", "2,289,55,311,93,298,131,295,149,323,249,320,254,294,314,296,322,348,517,349,527,294,586,300,585,325,686,330,694,301,761,299,760,410,0,404,2,404,3,405", 0, 0, 764, 415, 1);
	$gfxb[12] = array ("Grenzposten", "30,0,118,0,118,68,30,118", 30, 0, 68, 74 ,2);
	$gfxb[18] = array ("Schie&szlig;stand", "625,158,718,159,762,237,751,262,656,258", 619, 143, 131, 101, 2);
	$gfxb[19] = array ("Zwinger", "78,88,164,88,164,143,78,143", 78, 88, 86, 55, 1);
	$gfxb[20] = array ("Festung", "478,183,477,152,527,127,525,80,468,34,418,23,345,41,345,54,306,72,310,128,339,146,357,149,356,181", 291, 12, 223, 163, 3);
}
else
{
	$gfxb[12] = array ("Wachturm", "611,0,730,0,730,200", 650, 0, 92, 81);
	$gfxb[11] = array ("Stadtmauer", "767,331,745,330,731,294,745,235,730,204,704,207,694,224,666,197,672,143,656,117,627,128,624,117,637,68,604,39,581,74,539,64,527,14,239,12,18,117,1,163,1,407,116,415,65,357,34,299,31,275,84,217,172,156,288,109,375,96,496,107,571,140,613,215,663,281,669,318,709,387,707,409,764,410,763,410", 0, 0, 768, 416);
	$gfxb[3] = array ("Garnison", "146,204,209,168,296,204,301,275,205,286,127,279", 133, 169, 166, 116);
	$gfxb[20] = array ("Burg", "314,125,312,186,485,221,507,89,362,107,335,120", 311, 89, 191, 129);
	$gfxb[1] = array ("Bergfried", "305,124,304,189,212,164,224,74", 186, 87, 110, 96);
	$gfxb[10] = array ("Alchimist", "501,159,487,223,536,246,570,236,572,178,541,147", 488, 171, 84, 73);
	$gfxb[2] = array ("Marktplatz", "417,216,406,276,478,297,498,248,465,221,427,214", 408, 234, 72, 60);
	$gfxb[19] = array ("Stallungen", "509,277,470,324,484,352,565,396,590,323", 459, 291, 120, 93);
	$gfxb[6] = array ("Rohstofflager", "618,318,582,313,530,283,552,246,597,226,621,239", 530, 234, 86, 80);
	$gfxb[18] = array ("Sch&uuml;tzenhof", "371,294,355,376,417,394,491,377,452,297", 384, 299, 90, 77);
	$gfxb[9] = array ("Werkstatt", "241,290,294,281,325,271,361,291,329,369,249,356", 257, 272, 100, 84);
	$gfxb[5] = array ("Zunfthaus", "311,198,351,196,408,211,400,286,349,282,314,263", 299, 189, 103, 90);
}


echo "<script type=\"text/javascript\">\nbuild=new Array(100);\n";
echo "theme=\"".$_SESSION['theme']."\";\n";
$zindex = 11;
foreach ($gfxb as $building_id => $this_build)
{
	$zindex++;
	echo "build[".$building_id."] = new Image;\n";
	if ($list[$building_id][1] > 0)
		echo "build[".$building_id."].src = \"".$path."b".$building_id.".png\";";
	else
		echo "build[".$building_id."].src = \"".$path."h".$building_id.".png\";";
	echo "build[".$building_id."].width = ".$this_build[4].";\nbuild[".$building_id."].height = ".$this_build[5].";\nbuild[".$building_id."].style.cssText = \"position:absolute; z-index:".$zindex."; top: ".$this_build[3]."px; left: ".$this_build[2]."px\";\n";
}

echo "race=".$me->race.";\n";

echo "js_sep = \"".NUMBER_FORMAT2."\";\n";
?>
var build_id=0;
var was_ok = true;
var finished_loading = false;
function allow_mouseover() {
	finished_loading = true;
}
</script>
<script src="scripts/stadt.js" type="text/javascript"></script>
<?php

// We include basic design parts here
require_once ("styles/php/base_design-".$_SESSION['theme'].".php");
require_once("blocked.php");

echo '<div id="contentbox">';


if (count($gui->building_queue) < 2)
	$slotsfree = true;
else
	$slotsfree = false;

$pics = "";
$map = "";

if ($me->activeoutpostid)
	echo "<span class=\"error\">Ein Au&szlig;enposten hat erst Geb&auml;ude, wenn er zur Stadt wird.</span>\n";
else
{
	require_once ("php/citycont.php");
	$buildspeed = $me->activevillage->speed_build;

	$zindex = 10;
	foreach ($gfxb as $bid=>$entry)
	{
		$zindex++;

		if ($list[$bid][1] > 0)
			$pics .= '<img src="'.$path.$bid.'.png" style="position:absolute; left:'.$entry[2].'px; top:'.$entry[3]."px; z-index:".$zindex."; \">\n";

		$errstr = $outstr = null;
		if (($errstr = Calc_Building_Dep ($bid, $list[$bid][1], $build, $research, $what)))
    {
      /* if (strlen ($errstr) > 50)
        $errstr = substr ($errstr, 0, 47)."..."; */
  	  $outstr = "Ben&ouml;tigt <br>".$errstr;
  	}

  	$tolevel = $list[$bid][1] + 1;
		if (isset($gui->buildid_queue))
		{
			foreach ($gui->buildid_queue as $this_build)
			{
				if ($this_build == $build[$bid][7])
				{
					$tolevel++;
				}
			}
		}
		$tmp_notenough = false;
		$levelfac = $tolevel * pow (NEXTLEVEL_COSTS, $tolevel - 1);
		$r1 = (int)($list[$bid][2]*$levelfac);
		$r2 = (int)($list[$bid][3]*$levelfac);
		$r3 = (int)($list[$bid][4]*$levelfac);
		$r4 = (int)($list[$bid][15]*$levelfac);

		$this_cost = (int)(($list[$bid][2] + $list[$bid][3] + $list[$bid][4] + $list[$bid][15]) * $levelfac);
		$this_dur = external_calcdur (max (1, (int)($this_cost * $me->activevillage->speed_build / WORLD_SPEED / BUILD_SPEED)));

		if (!$outstr)
		{
			if (!$slotsfree)
				$outstr = "Die Bauschleife ist momentan voll.";
		}

  	if ($outstr)
  		$map .= "<area shape=\"poly\" coords=\"".$entry[1]."\" alt=\"".$entry[0]."\" onMouseOver=\"bui (".$bid.", '".$entry[0]."',".$entry[2].",".$entry[3].",".$entry[4].",".$entry[5].", ".(int)$list[$bid][1].", ".$tolevel.", false, '".$outstr."', '".$this_dur."', ".$r1.", ".$r2.", ".$r3.", ".$r4.")\" onMouseOut=\"bhide();\" href=\"".$_SERVER['PHP_SELF']."?b=".$bid."\">\n";
  	else
  		$map .= "<area shape=\"poly\" coords=\"".$entry[1]."\" alt=\"".$entry[0]."\" onMouseOver=\"bui (".$bid.", '".$entry[0]."',".$entry[2].",".$entry[3].",".$entry[4].",".$entry[5].", ".(int)$list[$bid][1].", ".$tolevel.", true, '', '".$this_dur."', ".$r1.", ".$r2.", ".$r3.", ".$r4.")\" onMouseOut=\"bhide();\" href=\"".$_SERVER['PHP_SELF']."?b=".$bid."\">\n";
  	// $map .= "<area shape=\"poly\" coords=\"".$entry[1]."\" alt=\"".$entry[0]."\" onMouseOver=\"gimme ('wow');\" onMouseOut=\"bhide();\" href=\"haha.php\">\n";
  }

	if (isset ($_REQUEST['b']))
	{
		$b = (int)$_REQUEST['b'];

		// We should pass this on to the tutorial, if it is still going strong
		if (is_object ($tutorial))
		{
			if ($tutorial->active)
				$tutorial->looking_at_building ($b);
		}

		if (isset ($gfxb[$b]))
		{
			$tolevel = $list[$b][1] + 1;
      if (isset($gui->buildid_queue))
      {
        foreach ($gui->buildid_queue as $this_build)
        {
          if ($this_build == $build[$b][7])
          {
            $tolevel++;
          }
        }
      }

      $tmp_notenough = false;
      $levelfac = $tolevel * pow (NEXTLEVEL_COSTS, $tolevel - 1);
      $thiscost = array (1=>(int)($list[$b][2]*$levelfac), 2=>(int)($list[$b][3]*$levelfac), 3=>(int)($list[$b][4]*$levelfac), 4=>(int)($list[$b][15]*$levelfac));
			$errstr = $outstr = null;
			if (($errstr = Calc_Building_Dep ($b, $list[$b][1], $build, $research, $what)))
			{
				/* if (strlen ($errstr) > 50)
					$errstr = substr ($errstr, 0, 47)."..."; */
					$errstr = str_replace ("hhaamm", "<img src=\"gfx/hammer.gif\" width=\"16\" height=\"16\" border=\"0\">&nbsp;", $errstr);
					$errstr = str_replace ("ffoorr", "<img src=\"gfx/forschung.gif\" width=\"16\" height=\"16\" border=\"0\">&nbsp;", $errstr);
				$outstr = "Benötigt<br> ".$errstr;
			}


  	  $this_cost = (int)(($list[$b][2] + $list[$b][3] + $list[$b][4] + $list[$b][15]) * $levelfac);

  	  $this_dur = external_calcdur (max (1, (int)($this_cost * $me->activevillage->speed_build / WORLD_SPEED / BUILD_SPEED)));

			echo "<div id=\"onecolumn\">";
			if ($gfxb[$b][6] > 1)
				$which = rand (1, $gfxb[$b][6]);
			else
				$which = 1;
			echo "<img style=\"padding-right:15px;z-index:".$zindex.";float:left;\" src=\"".$path."w/".$b."-".$which.".jpg\">";
			echo "<div style=\"z-index:".$zindex.";padding-top:10px\"><center><b>".$list[$b][0]."</b></center>";
			echo "<p>".$list[$b][6]."</p>";
			//echo "</div>";

			//$ldiv = "<div id=\"infos-bild\"><img src=\"styles/".$_SESSION['theme']."/infos.png\" style=\"\"></div>";
			$ldiv .= "<div id=\"townbuild\"";
			if (is_object($tutorial) && $tutorial->active && !$tutorial->seeLandInfo(300))
				$ldiv .= ' style="visibility:hidden"';
			if (is_object($tutorial) && $tutorial->active && $tutorial->highlight(43))
				$ldiv .= ' style="border:3px solid red"';
			$ldiv .= ">"; // Gebäude: ".$list[$b][0]."<br>";

			$ldiv .= 'Kosten f&uuml;r Ausbau auf Stufe '.$tolevel.':<br>';
			$ldiv .= $me->activevillage->display_money($thiscost)."<br>";
			$ldiv .= "<img src=\"gfx/uhr.gif\" width=\"16\" height=\"16\">: ".$this_dur.'<br>';
		//	$ldiv .= "</div><div ";
		//	if (is_object($tutorial) && $tutorial->active && !$tutorial->seeLandInfo(200))
		//		$ldiv .= ' style="visibility:hidden"';

			//$ldiv .= ">";
			if (!$outstr)
			{
				if (!$tmp_notenough)
				{
					if ($slotsfree)
						$ldiv .= '<a href="'.$SERVER['PHP_SELF'].'?r='.$b.'&l='.$tolevel.'&b='.$b.'"><img src="gfx/hammer.gif" width="16" height="16">Auf Stufe '.$tolevel.' ausbauen</a><br><br>';
					else
						$ldiv .= '<span class="error">Die Bauschleife ist momentan voll.</span><br><br>';
				}
				else
					$ldiv .= '<span class="error">Nicht genug Rohstoffe, um dieses Geb&auml;ude auszubauen.</span><br><br>';
			}
			else
				$ldiv .= '<span class="error">'.$outstr."</span><br><br>";

			$ldiv .= "</div></div>\n";
		}
	}
	else
	{
		// We should pass this on to the tutorial, if it is still going strong
		if (is_object ($tutorial))
		{
			if ($tutorial->active)
				$tutorial->is_in_city ();
		}
		echo "<div id=\"map\"><div id=\"karte\">";
		echo '<img src="gfx/blank.gif" style="z-index:5000;position:absolute; left:0px; top:0px;" width="764" height="415" border="0" usemap="#ork1" />';
		echo '<img src="'.$path.'g.jpg" style="z-index=1;" width="764" height="415" border="0"/ >'."\n";
		echo $pics;

		echo "<map name=\"ork1\">".$map."</map>";
	}

	if (isset ($build_err))
		echo "<b>".$build_err."</b>";
}

echo "</div>";

if (isset ($ldiv))
	echo $ldiv;
else
{
 	echo "<div id=\"infos\"";
	//if (is_object($tutorial) && $tutorial->active && $tutorial->highlight(40))
	//	echo ' style="border:3px solid red"';
	echo "><div id=\"stadt-infos\">Geb&auml;ude: <span id=\"bname\"></span></div>";
	echo "<div id=\"todo\"";
	if (is_object($tutorial) && $tutorial->active && $tutorial->highlight(41))
		echo ' style="border:3px solid red"';
	if (is_object($tutorial) && $tutorial->active && !$tutorial->seeLandInfo(100))
	{
		echo ' style="visibility:hidden"';
	}

	echo "></div></div></div>";
}
	//<div id=\"infos-bild\"><img src=\"styles/".$_SESSION['theme']."/infos.png\" style=\"\"></div><div id=\"todo-bild\"><img src=\"styles/".$_SESSION['theme']."/todo.png\" style=\"\"></div><\n";

echo "</div>";
require_once("footer.php");

?>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.