-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.php
2236 lines (1868 loc) · 89.1 KB
/
index.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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
// uebersicht und karte fuer das browsergame www.dieverdammten.de
// note : xml api via http://www.php.net/manual/de/book.simplexml.php
/*
Copyright (c) 2010 <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/*
IDEEN :
* tagebuch tools, beispiel : Geniales Gehöft (rang1) http://forum.der-holle.de/viewtopic.php?f=8&t=55&start=30 (GesamtFazit interessant btw)
* eingebauter chat: http://02.chat.mibbit.com/?channel=%23dieverdammten&server=irc.mibbit.net&autoConnect=true&nick=teeest123
** http://wiki.mibbit.com/index.php/Uri_parameters Ocoma tipp : http://tools.mibbit.com/widget-uri-creator/
* tooltip : ruinen texte aus wiki (fundliste)
* sabo warnung : seelen-auszeichnung nicht im stream, aber hängung(todesart) und ban(bürgerliste) aus städten in der db kriegt man
* auswertung des stadtlogs, also alles copy-pasten , dann kriegt man hübsch angezeigt wer interessante sachen rausgenommen hat, und angriffe etc um sabos früh zu erkennen. (auch nutzung von werkstatt ohne säge usw)
* tooltip : ruine-noch-nicht-ausgegraben : möglichkeiten anhand entfernung auflisten (wiki)
* ruinen-icon : aufklärer kann ruinen in der nähe? sehen ohne das das feld aufgedeckt ist (zombiezahl?)
* optimale aufklärer verteilung für stadtpos+kartengrösse berechnen (zombiezahl in umgebung->ruinen), 18ap+rückkehr, keine drogen/alk.
* stadtauflistung mit suchfunktion (stadtname,spielername), und verschiedene stats nach denen man sortieren kann (tage,leute am leben, vieleicht paar bewertungen, gesamt def, dev vs zombies, vll sogar abschätzung der lebenserwartung nach statistischem durchschnitt der zombie-angriffe vs baumöglichkeiten mit material+ap der lebenden einwohner inklusive bankvorräten)
* rückblick über mehrere tage, "wie sah stadt x gestern aus"
* eingetragene exp und leute hinterlassen "spur" (leer, oder fussstapfen)
* dvnavi idea asid : sturm richtung = wichtigste info
IDEEN : style :
* style : starwars:jawas/schrotthändler http://images3.wikia.nocookie.net/__cb20090730135822/starwars/images/2/27/JawaEngineer-SWGTCGAoD.jpg
* style : fallout ?
bilder meta/mola :
http://www.geo-reisecommunity.de/bild/regular/38772/Duenen-von-Merzouga.jpg
http://www.geo-reisecommunity.de/bild/regular/46336/Halbwueste-Karoo-erodierter-Fels-auf-den-Huegeln.jpg
http://img.fotocommunity.com/photos/2858888.jpg
http://giz.me/wp-content/uploads/2008/12/fallout_playground.jpg
http://www.pcgameshardware.de/screenshots/medium/2008/11/Fallout3_02.jpg
http://www.ps3blog.de/wp-content/gallery/fout200808/fallout-3_2008_08-20-08_03.jpg
http://blog.gcshop.ch/pebble/images/november/fallout3.jpg
http://www.wallpaperez.info/de/games/Fallout-3-nuclear-mountain-1007.html
http://olbertz.de/blog/wp-content/uploads/2008/12/fallout3.jpg
http://www.pcgameshardware.de/screenshots/medium/2008/11/Fallout3_04.jpg
(sidenote, nice logo new vegas : http://onipepper.de/wp-content/uploads/2010/02/fallout_newvegas.jpg)
green console style (also bioshock) http://t1.gstatic.com/images?q=tbn:n3Oxc-m5SkSM_M:http://www.ps-spotlight.de/~pics/review/fallout3/fallout3_3.jpg&t=1
http://forum.exp.de/members/allucard-albums-games-picture7-der-kleine-helfer-pipboy-3000-fallout-3.jpg
http://www.gamers.at/images/screenshots/screenshot_fallout_online_03_35188.jpg
http://fidgit.com/Fallout_3_diaries_grocer.jpg
hightech map : http://www.forumla.de/attachments/sony-ps3-forum/28041d1231015479-fallout-3-loesungen-hinweise-ratschlaege-unbenannt.jpg
mission map with annotations : http://t1.gstatic.com/images?q=tbn:IufZzObCwlbevM:http://i4.photobucket.com/albums/y109/Ultradyne/Fallout3RPmap.jpg&t=1
ruined highway with western style houses : http://www.play3.de/wp-content/gallery/fallout_new_vegas_060310/fallout-new-vegas_2010_03-06-10_04.jpg
http://verdammten.bplaced.net/phpBB3/styles/DirtyBoard2.0/theme/images/bg_body.jpg
http://etacar.put.poznan.pl/piotr.pieranski//Physics%20Around%20Us/Sand%20waves%2010.jpg
*/
$gIndex_StartT = time();
if (!file_exists("defines.php")) exit('error: please rename "defines.dist.php" to "defines.php"');
require_once("defines.php");
require_once("roblib.php");
require_once("lib.verdammt.php");
//~ function MyEscXML ($txt) { return htmlspecialchars($txt); } // ö->uuml;
function MyEscXML ($txt) {
//~ return utf8_decode($txt);
return strtr($txt,array("roßer"=>"rosser","ö"=>"ö","ü"=>"ü","ä"=>"ae","Ö"=>"Ö","Ü"=>"Ü","Ä"=>"Ä"));
//~ wegen den umlauten ein tip: utf8_decode
} // htmlspecialchars
function MyEsc ($txt) { return utf8_decode($txt); } // htmlspecialchars
function MyEscHTML ($txt) { return utf8_decode($txt); } // htmlspecialchars
function MyEscHTML2 ($txt) { return htmlspecialchars(($txt)); } // htmlspecialchars
//~ function MyEsc ($txt) { return strtr($txt,array("Ã?"=>"ß","ü"=>"ü","ö"=>"ö")); } // htmlspecialchars
function StripUml($txt) { return preg_replace('/[^a-zA-Z0-9]/','',$txt); }
function MyImgTitleConst ($txt) { return utf8_encode($txt); }
function WikiName ($name) { return strtr((string)$name,array("ß"=>"ss"," "=>"_")); }
function LinkWiki ($name,$html=false) { return href("http://nobbz.de/wiki/index.php/".urlencode(WikiName($name)),$html?$html:($name)); }
function LinkRuin ($name,$html=false) { return LinkWiki($name,$html); }
function LinkBuilding ($name,$html=false) { return LinkWiki($name,$html); }
function LinkItem ($name,$html=false) { return LinkWiki($name,$html); }
// note : htmlentities() is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.
define("kNumIcons",8);
define("kIconID_DigLeer",0);
define("kIconID_DigVoll",1);
define("kIconID_Verboten",4);
define("kIconID_Green",5);
define("kIconID_Notiz",6);
define("kIconID_Bonus",7);
define("kBuildingLevelMax",5);
define("kSearchGameID",isset($_REQUEST["gameid"])?intval($_REQUEST["gameid"]):false);
define("kSearchGameDay",isset($_REQUEST["day"])?intval($_REQUEST["day"]):false);
define("kSearchXMLID",isset($_REQUEST["xmlid"])?intval($_REQUEST["xmlid"]):false);
define("kGhostKey",isset($_REQUEST["key"])?($_REQUEST["key"]):false);
define("kMapMode_Marker" ,1);
define("kMapMode_Buerger" ,2);
define("kMapMode_InGameTags" ,3);
define("kMapMode_6KM" ,4);
define("kMapMode_15KM" ,5);
define("kMapMode_Storm" ,6);
$gGhostStreamOk = false;
$gRegisteredItemTypeIDs = sqlgettable("SELECT id FROM itemtype","id");
$gRegisteredItemTypes = sqlgettable("SELECT * FROM itemtype","id");
$gRegisteredBuildingTypeIDs = sqlgettable("SELECT id,buildingid FROM buildingtype","buildingid");
$gIconText = array(
0=>"Feld leer",
1=>"Feld regeneriert : graben!",
2=>"Feld temporaer gesichert",
3=>"Notruf",
4=>"DVNavi:Verboten!",
5=>"ok",
6=>"notiz",
7=>"DVNavi:Bonus!",
);
function RegisterRuin ($gameid,$rx,$ry,$name,$type) { // <building name="Autowracks" type="7" dig="0">
if (intval($type) == -1) return;
$o = false;
$o->gameid = $gameid;
$o->x = $rx;
$o->y = $ry;
if (sqlgetone("SELECT 1 FROM ruin WHERE ".obj2sql($o," AND "))) return;
$o->ap = abs($rx)+abs($ry);
$o->name = utf8_decode($name);
$o->type = intval($type);
sql("REPLACE INTO ruin SET ".obj2sql($o));
}
function GetTextBetween ($text,$start,$end,$startskipto=false,$bReturnFullOnFail=false) {
if ($text === false) return $bReturnFullOnFail?$text:false;
$pos0 = strpos($text,$start);
if ($pos0 === false) return $bReturnFullOnFail?$text:false;
$pos0 += strlen($start);
if ($startskipto) {
$pos0 = strpos($text,$startskipto,$pos0);
if ($pos0 === false) return $bReturnFullOnFail?$text:false;
$pos0 += strlen($startskipto);
}
$pos1 = strpos($text,$end,$pos0);
if ($pos1 === false) return $bReturnFullOnFail?$text:false;
return substr($text,$pos0,$pos1-$pos0);
}
function ExtractWikiTextArea ($txt) { return GetTextBetween($txt,"<textarea","</textarea",">",true); } // <textarea name="wpTextbox1" id="wpTextbox1" cols="80" rows="25" tabindex="1" accesskey=",">
function ExtractWikiPageContent ($txt) { return GetTextBetween($txt,"<!-- start content -->",'<div class="printfooter">',false,true); } // <textarea name="wpTextbox1" id="wpTextbox1" cols="80" rows="25" tabindex="1" accesskey=",">
function GetWikiSrcRedirect ($src) {
if ((stripos($src,"#redirect") !== false || stripos($src,"#weiterleitung") !== false) && eregi("#[a-z]+[ \t]+\\[\\[(.+)\\]\\]",$src,$r)) {
echo "GetWikiSrcRedirect 1=".$r[1]."<br>\n";
return $r[1];
}
return false;
}
if (isset($_REQUEST["download_wiki"])) {
echo "download wiki entries<br>\n";
set_time_limit(0); // disable max execution time
$itemtypes = sqlgettable("SELECT * FROM itemtype");
$i = 0;
foreach ($itemtypes as $o) {
$redirect = GetWikiSrcRedirect($o->wiki_src);
if (trim($o->wiki_src) != "" && trim($o->wiki_html) != "" && !$redirect) continue;
// #redirect [[Hähnchenflügel]]
if ($i >= 120) break; else ++$i;
$wikiname = $o->name;
$wikiname = eregi_replace("\\([0-9]+ [a-z]+\\)","(gefüllt)",$wikiname);
// (3 rationen/ladungen) -> gefüllt
$url_html = "http://nobbz.de/wiki/index.php?title=".urlencode($wikiname); echo $o->id." ".href($url_html)."<br>\n";
$url_wiki = "http://nobbz.de/wiki/index.php?action=edit&title=".urlencode($redirect ? $redirect : $wikiname); echo $o->id." ".href($url_wiki)."<br>\n";
$new = false;
if (trim($new->wiki_html) == "") $new->wiki_html = ExtractWikiPageContent(file_get_contents($url_html));
$new->wiki_src = ExtractWikiTextArea(file_get_contents($url_wiki));
//~ echo "<textarea cols=80 rows=20>".$wiki_src."</textarea>";
sql("UPDATE itemtype SET ".obj2sql($new)." WHERE id = ".intval($o->id));
/*
Warning: file_get_contents(http://nobbz.de/wiki/index.php?title=Reparturset+%28kaputt%29)
Warning: file_get_contents(http://nobbz.de/wiki/index.php?title=Angebissene+H%C3%A4hnchenfl%C3%BCgel)
Warning: file_get_contents(http://nobbz.de/wiki/index.php?title=Kanisterpumpe+%28zerlegt%29)
Warning: file_get_contents(http://nobbz.de/wiki/index.php?title=Unverarbeitete+Blechplatten)
*/
}
exit(0);
}
if (isset($_REQUEST["refresh_other"])) {
//~ $arr = sqlgettable("SELECT *,MAX(time) as maxtime FROM accesslog GROUP BY seelenid");
//~ for ($i=0;$i<10;++$i) {
$arr = sqlgettable("SELECT id,seelenid,cityname,MAX(time) as maxtime FROM xml GROUP BY seelenid ORDER BY maxtime");
echo count($arr)." found "."<br>\n";
$today_start_t = floor(time() / (24*3600))*24*3600;
$seelenid = false;
$otherid = false;
$bestday = 0;
$infos = array();
foreach ($arr as $o) {
//~ if ($o->maxtime < $today_start_t) {
if ($o->maxtime < time() - 6*3600) {
$lastknown = sqlgetobject("SELECT day FROM xml WHERE ".arr2sql(array("seelenid"=>$o->seelenid))." ORDER BY id DESC LIMIT 1");
$curday = $lastknown ? $lastknown->day : 0;
$infos[] = "refresh day=$curday id ".$o->id." ".$o->cityname." ".$seelenid."<br>\n";
if (!$seelenid || $curday > $bestday) {
$seelenid = $o->seelenid;
$otherid = $o->id;
$bestday = $curday;
}
}
}
if ($seelenid) {
if (!define("kSeelenID",$seelenid)) exit("failed to set constant, already set?");
$xmlurl = "http://www.dieverdammten.de/xml/?k=".urlencode(kSeelenID).";sk=".urlencode(kDV_SiteKey);
define("kXMLUrl_Basic",$xmlurl); // kein sitekey
define("kXMLUrl_Secret",$xmlurl); // enthaelt sitekey! das sollte der user nicht zu sehen kriegen
$xmlstr = file_get_contents(kXMLUrl_Secret);
if (!$xmlstr) exit("failed to load xml");
$xml = simplexml_load_string(MyEscXML($xmlstr));
MyLoadGlobals();
StoreXML();
echo "stored day=$bestday '$otherid' : ".(string)$city["city"]." ".kSeelenID."<br>\n";
echo "<hr>\n";
}
echo implode("",$infos);
//~ }
exit("refresh other");
}
$gShowAvatars = false;
$temp_seelenid = isset($_COOKIE["SeelenID"]) ? $_COOKIE["SeelenID"] : false;
if ($temp_seelenid) LogAccess($temp_seelenid);
$gUseSampleData = isset($_REQUEST["sample"]);
if ($gUseSampleData) $temp_seelenid = "abcdefghijklmnopqrstuvwxyz";
if (isset($_REQUEST["LogOut"])) {
setcookie ("SeelenID", "", time() - 3600);
//~ echo "logout<br>";
$temp_seelenid = false;
} elseif (isset($_REQUEST["Login"])) {
setcookie ("SeelenID", $_REQUEST["SeelenID"], time() + 30*24*3600);
//~ echo "login:".$_REQUEST["SeelenID"]."<br>";
$temp_seelenid = $_REQUEST["SeelenID"];
}
if ($temp_seelenid) $temp_seelenid = preg_replace('/[^a-zA-Z0-9]/','',$temp_seelenid);
define("kSeelenID",$temp_seelenid); // replaces the old $gSeelenID
//~ session_start(); // -> man kann $_SESSION benutzen
function GetLatestXmlByID ($xmlid) { return sqlgetone("SELECT xml FROM xml WHERE ".arr2sql(array("id"=>$xmlid))); }
function GetLatestXmlStrFromGameID ($gameid) { return sqlgetone("SELECT xml FROM xml WHERE ".arr2sql(array("gameid"=>$gameid))." ORDER BY id DESC LIMIT 1"); }
function GetLatestXmlStrFromGameIDAndDay ($gameid,$day) { return sqlgetone("SELECT xml FROM xml WHERE ".arr2sql(array("gameid"=>$gameid,"day"=>$day)," AND ")." ORDER BY id DESC LIMIT 1"); }
function GetLatestXmlStrFromSeelenID ($seelenid) { return sqlgetone("SELECT xml FROM xml WHERE ".arr2sql(array("seelenid"=>$seelenid))." ORDER BY id DESC LIMIT 1"); }
if (isset($_REQUEST["scanitemtypes"])) {
// only used once during development, later new items will be registered automatically when they are seen in the bank
$r = sql("SELECT xml FROM xml");
while ($arr = mysql_fetch_array($r)) {
$xml = simplexml_load_string(MyEscXML($arr[0]));
foreach ($xml->data[0]->bank[0]->item as $item) RegisterItemType($item);
}
exit(0);
}
function RegisterItemType ($item) {
global $gRegisteredItemTypeIDs;
$o = false;
$o->id = (string)$item["id"];
if ($gRegisteredItemTypeIDs[$o->id]) return;
$o->cat = (string)$item["cat"];
$o->img = (string)$item["img"];
$o->name = (string)$item["name"];
$o->cat2 = $o->cat; // later used to mark special types : alcohol,drugs,tools(weapons)#
if (!sqlgetone("SELECT 1 FROM itemtype WHERE id = ".intval($o->id)))
sql("REPLACE INTO itemtype SET ".obj2sql($o));
}
function RegisterBuildingType ($building) {
global $gRegisteredBuildingTypeIDs;
$o = false;
$o->buildingid = (string)$building["id"];
if ($gRegisteredBuildingTypeIDs[$o->buildingid]) return;
$o->img = (string)$building["img"];
$o->name = (string)$building["name"];
$o->notfall = (int)$building["temporary"];
if (!sqlgetone("SELECT 1 FROM buildingtype WHERE id = ".intval($o->id)))
sql("REPLACE INTO buildingtype SET ".obj2sql($o));
}
if (isset($_REQUEST["ajax"])) {
if (kSearchXMLID) $xmlstr = GetLatestXmlByID(kSearchXMLID);
else if (kSearchGameID && kSearchGameDay) $xmlstr = GetLatestXmlStrFromGameIDAndDay(kSearchGameID,kSearchGameDay);
else if (kSearchGameID) $xmlstr = GetLatestXmlStrFromGameID(kSearchGameID);
else $xmlstr = GetLatestXmlStrFromSeelenID(kSeelenID);
if (!$xmlstr) exit("failed to load xml");
$xml = simplexml_load_string(MyEscXML($xmlstr));
MyLoadGlobals();
$rx = intval($_REQUEST["x"]);
$ry = intval($_REQUEST["y"]);
//~ echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">'."\n";
//~ echo "südosten";
ob_start(); // collect output to encode with utf8 before sending to browser
switch ($_REQUEST["ajax"]) {
case "addmapnote": Ajax_AddMapNote($rx,$ry); break;
case "cellinfo": Ajax_MapCellInfo($rx,$ry); break;
case "maputil_digg": Ajax_MapUtil_Digg($rx,$ry); break;
case "maputil_scout": Ajax_MapUtil_Scout($rx,$ry); break;
case "mapmode": Ajax_MapMode(); break;
case "shownavimenu": Ajax_ShowNaviMenu(); break;
default: echo "unknown request ".$_REQUEST["ajax"]; break;
}
$html = ob_get_contents();
ob_end_clean();
echo utf8_encode($html);
exit();
}
function Ajax_MapMode() { RenderMapBlock(intval($_REQUEST["mapmode"])); }
function Ajax_ShowNaviMenu () {
global $gIconText;
?>
DVNavi : Expeditions-Routen-Vorschlag<br>
Tipp : <?=img("images/map/icon_".kIconID_Verboten.".gif",$gIconText[$i])?> Marker = verbotenes Feld.<br>
<form action="?" method="post" class='mapadd' id='form_dvnavi'>
<input class='mapaddsmall_input' type="text" size="3" maxlength="5" name="ap" value='18'>AP
<select name="mode">
<option value="explore" selected>Unerforschte Felder und Ruinen</option>
<option value="bonus">Primär Bonus</option>
<option value="6km">6km 18ap</option>
<option value="6kmNoRet">6km 18ap+Rückkehr</option>
</select>
<input class='mapaddsmall_button' type="button" name="util_scout" value="Route berechnen" onclick="DVNavi_Execute(this.form.ap.value,this.form.mode.value)"></td>
</form>
<span id='idDVNaviStatus'></span>
<span id='idDVNaviResult'></span>
<?php
}
function IsUnexploredRelPos ($rx,$ry) {
$data = Map($rx + kCityX,kCityY - $ry);
if ($data) return false;
return true;
}
function MapSetIconRelPos ($rx,$ry,$icon) {
if ($rx == 0 && $ry == 0) return; // no mark on city
if (IsUnexploredRelPos($rx,$ry)) return; // no mark on unexplored
$o = GetMapNoteRelPos($rx,$ry);
AddMapNote($rx,$ry,$icon,$o?$o->zombies:"",$o?$o->txt:"");
}
function MapSetZombieRelPos ($rx,$ry,$zombies) {
if ($rx == 0 && $ry == 0) return; // no mark on city
if (IsUnexploredRelPos($rx,$ry)) return; // no mark on unexplored
$o = GetMapNoteRelPos($rx,$ry);
AddMapNote($rx,$ry,$o?$o->icon:-1,$zombies,$o?$o->txt:"");
}
function Ajax_MapUtil_Digg ($rx,$ry) {
$n = intval($_REQUEST["dig_north"]);
$w = intval($_REQUEST["dig_west"]);
$m = intval($_REQUEST["dig_mid"]);
$e = intval($_REQUEST["dig_east"]);
$s = intval($_REQUEST["dig_south"]);
//~ echo "$n,$w,$m,$e,$s<br>\n";
MapSetIconRelPos($rx ,$ry+1,$n?kIconID_DigVoll:kIconID_DigLeer);
MapSetIconRelPos($rx-1,$ry ,$w?kIconID_DigVoll:kIconID_DigLeer);
MapSetIconRelPos($rx ,$ry ,$m?kIconID_DigVoll:kIconID_DigLeer);
MapSetIconRelPos($rx+1,$ry ,$e?kIconID_DigVoll:kIconID_DigLeer);
MapSetIconRelPos($rx ,$ry-1,$s?kIconID_DigVoll:kIconID_DigLeer);
RenderMapBlock();
}
function Ajax_MapUtil_Scout ($rx,$ry) {
$n = ($_REQUEST["zombie_north"]);
$w = ($_REQUEST["zombie_west"]);
$m = ($_REQUEST["zombie_mid"]);
$e = ($_REQUEST["zombie_east"]);
$s = ($_REQUEST["zombie_south"]);
//~ echo "$n,$w,$m,$e,$s<br>\n";
MapSetZombieRelPos($rx ,$ry+1,$n);
MapSetZombieRelPos($rx-1,$ry ,$w);
MapSetZombieRelPos($rx ,$ry ,$m);
MapSetZombieRelPos($rx+1,$ry ,$e);
MapSetZombieRelPos($rx ,$ry-1,$s);
RenderMapBlock();
}
function Ajax_AddMapNote ($rx,$ry) {
AddMapNote($rx,$ry,intval($_REQUEST["icon"]),$_REQUEST["zombies"],$_REQUEST["msg"]);
echo MapGetCellContentRelPos($rx,$ry);
}
function MapGetCellContentRelPos ($rx,$ry) { return MapGetCellContent(kCityX + $rx,kCityY - $ry); }
function Ajax_MapCellInfo ($rx,$ry) { // idMapCellInfo
global $gGameID,$gIconText;
$lastnote = GetMapNote($rx,$ry);
$icon = $lastnote ? intval($lastnote->icon) : kIconID_Notiz;
$msg = $lastnote ? $lastnote->txt : "";
$zombies = $lastnote ? $lastnote->zombies : "?";
if ($zombies == -1) $zombies = "?";
//~ echo "$rx,$ry lastnote=".($lastnote?"ok":"-")." gameid=$gGameID ".$lastnote->icon." ".$lastnote->txt."<br>\n";
$x = kCityX + $rx;
$y = kCityY - $ry;
?>
<form action="?" method="post" class='mapadd' id='form_mapadd_1'>
(<?=$rx?>/<?=$ry?>) [<?=abs($rx)+abs($ry)?>AP] <?=$lastnote?("[".GetAgeText($lastnote->day,$lastnote->time)."]"):""?><br>
<?=img(kIconURL_zombie,"zombies")?><input class='mapaddsmall_input' type="text" size="3" maxlength="5" name="zombies" value='<?=$zombies?>' />
<input type="hidden" name="x" value='<?=$rx?>'/>
<input type="hidden" name="y" value='<?=$ry?>'/>
<span class='bframe'><input type="radio" name="icon" value="-1" <?=($icon==-1)?"checked":""?> /></span>
<?php for ($i=0;$i<kNumIcons;++$i) {?>
<span class='bframe'><input type="radio" name="icon" value="<?=$i?>" <?=($icon==$i)?"checked":""?> /><?=img("images/map/icon_".$i.".gif",$gIconText[$i])?></span>
<?php }?>
<br>
<?php
$zone = sqlgetobject("SELECT * FROM mapzone WHERE ".arr2sql(array("gameid"=>kGameID,"x"=>$x,"y"=>$y)," AND "));
$items = sqlgettable("SELECT * FROM mapitem WHERE ".arr2sql(array("gameid"=>kGameID,"x"=>$x,"y"=>$y)," AND "));
if ($zone) {
echo "(".date("Y.d.m H:i",$zone->time)." Z:".$zone->z." ".(($zone->dried!=0)?"LEER":"")."):";
global $gRegisteredItemTypes;
foreach ($items as $o) {
$t = $gRegisteredItemTypes[$o->itemtype];
$c = $o->num;
$bBroken = $o->broken != 0;
$html = (($c>1)?($c."x"):"").LinkItem($t->name,img(kIconUrlItem.$t->img.".gif",($t->name),$bBroken?"class='broken'":""));
echo " ".$html;
}
echo "<br>\n";
}
?>
<textarea cols="40" rows="3" name='msg'><?=htmlspecialchars($msg)?></textarea><br>
<?php if (!IsOwnGame()) {?>
(kann nur in der eigenen Stadt bearbeitet werden)
<?php }?>
<?php if (IsOwnGame()) {?>
<table><tr><td valign='top'>
<input class='mapaddsmall_button' type="button" name="speichern" value="speichern" onclick="AddMapNote_Form(this.form)">
</td><td valign='top'>
</td><td valign='top'>
<?php /* ***** ***** UTIL : BUDDLER ***** ***** */ ?>
<?php $attr = " title='ankreuzen = REGENERIERTES feld = gruen'"; ?>
<?php $attr .= " onchange=\"this.parentNode.style.backgroundColor = this.checked?'green':'red';\""; ?>
<?php $cellattr = " style='background-color:red;'"; ?>
<table border=1 cellspacing=0>
<tr>
<td><?=img(kIconURL_hero_dig,MyImgTitleConst("Helden die den Beruf Buddler wählen können sehen ob umgebende Felder leer sind"))?></td>
<td <?=$cellattr?>><input type="checkbox" name="dig_north" value="1" <?=$attr?>></td>
<td></td>
</tr><tr>
<td <?=$cellattr?>><input type="checkbox" name="dig_west" value="1" <?=$attr?>></td>
<td <?=$cellattr?>><input type="checkbox" name="dig_mid" value="1" <?=$attr?>></td>
<td <?=$cellattr?>><input type="checkbox" name="dig_east" value="1" <?=$attr?>></td>
</tr><tr>
<td></td>
<td <?=$cellattr?>><input type="checkbox" name="dig_south" value="1" <?=$attr?>></td>
<td><input class='mapaddsmall_button2' type="button" name="util_digg" value="ok" onclick="Form_Map_Digg(this.form)"></td>
</tr></table>
</td><td valign='top'>
<?php /* ***** ***** UTIL : AUFKLÄRER ***** ***** */ ?>
<?php $tipp = "title='Geschätzte Zombieanzahl'"; ?>
<table border=1 cellspacing=0>
<tr>
<td><?=img(kIconURL_hero_scout,MyImgTitleConst("Helden die den Beruf Aufklärer wählen können die Anzahl der Zombies in umgebenden Feldern abschätzen."))?></td>
<td><input class='mapaddsmall_input' type="text" size="3" maxlength="5" name="zombie_north" <?=$tipp?> /></td>
<td></td>
</tr><tr>
<td><input class='mapaddsmall_input' type="text" size="3" maxlength="5" name="zombie_west" <?=$tipp?> /></td>
<td><input class='mapaddsmall_input' type="text" size="3" maxlength="5" name="zombie_mid" <?=$tipp?> /></td>
<td><input class='mapaddsmall_input' type="text" size="3" maxlength="5" name="zombie_east" <?=$tipp?> /></td>
</tr><tr>
<td></td>
<td><input class='mapaddsmall_input' type="text" size="3" maxlength="5" name="zombie_south" <?=$tipp?> /></td>
<td><input class='mapaddsmall_button2' type="button" name="util_scout" value="ok" onclick="Form_Map_Scout(this.form)"></td>
</tr></table>
</td></tr></table>
<?php }?>
</form>
<?php
}
function GetCurrentGameIDForSeelenID ($seelenid) { return sqlgetone("SELECT gameid FROM xml WHERE ".arr2sql(array("seelenid"=>$seelenid))." ORDER BY id DESC LIMIT 1"); }
function IsOwnGame () {
global $gGameID;
return GetCurrentGameIDForSeelenID(kSeelenID) == $gGameID;
}
function AddMapNote ($rx,$ry,$icon,$zombies,$txt) { // $rx,$ry relative from city 0, 1
if (!IsOwnGame()) return;
global $gGameID,$gGameDay;
$o = false;
$o->x = $rx;
$o->y = $ry;
$o->icon = $icon;
$o->zombies = $zombies; // ($zombies=="?")?-1:intval($zombies);
$o->txt = $txt;
$o->time = time();
$o->day = $gGameDay;
$o->gameid = $gGameID;
$o->seelenid = kSeelenID;
sql("INSERT INTO mapnote SET ".obj2sql($o));
}
function GetMapNoteRelPos ($rx,$ry) { return GetMapNote($rx,$ry); }
function GetMapNote ($x,$y) {
global $gGameID;
//~ echo "SELECT * FROM mapnote WHERE ".arr2sql(array("gameid"=>$gGameID,"x"=>$x,"y"=>$y)," AND ");
return sqlgetobject("SELECT * FROM mapnote WHERE ".arr2sql(array("gameid"=>$gGameID,"x"=>$x,"y"=>$y)," AND ")." ORDER BY `id` DESC LIMIT 1");
}
// ***** ***** ***** ***** ***** ghost xml parser
function ParseGhostXMLMapInfo($ghostxmlstr,$dbentry=false) {
@$xml = simplexml_load_string(MyEscXML($ghostxmlstr)); if (!$xml) return;
$x_zone = $xml->headers[0]->owner[0]->myZone[0]; if (!$x_zone) return;
$x_citizen = $xml->headers[0]->owner[0]->citizen[0]; if (!$x_citizen) return;
$x_game = $xml->headers[0]->game[0]; if (!$x_game) return;
//~ <citizen dead="0" hero="1" name="ghoulsblade" avatar="hordes/4/9/7d2611ba_9720.jpg" x="8" y="3" id="9720" ban="0" job="guardian" out="1" baseDef="1">
$zone = false;
$zone->gameid = intval($x_game["id"]);
$zone->x = intval($x_citizen["x"]);
$zone->y = intval($x_citizen["y"]);
$zone->time = $dbentry ? $dbentry->time : time();
$zone->seelenid = $dbentry ? $dbentry->seelenid : kSeelenID;
$zone->dried = intval($x_zone["dried"]); // <myZone dried="1" h="30" z="2">
$zone->h = intval($x_zone["h"]); // times explored ? aufklaerer sicherheit ?
$zone->z = intval($x_zone["z"]); // zombies
sql("REPLACE INTO mapzone SET ".obj2sql($zone));
sql("DELETE FROM mapitem WHERE ".arr2sql(array("gameid"=>$zone->gameid,"x"=>$zone->x,"y"=>$zone->y)," AND "));
foreach ($x_zone->item as $item_x) { // <item name="Raketenpulver" count="1" id="173" cat="Misc" img="powder" broken="0"/>
$item = false;
$item->gameid = $zone->gameid;
$item->x = $zone->x;
$item->y = $zone->y;
$item->itemtype = intval($item_x["id"]);
$item->num = intval($item_x["count"]);
$item->broken = intval($item_x["broken"]);
sql("INSERT INTO mapitem SET ".obj2sql($item));
}
}
if (isset($_REQUEST["parse_ghost_db"])) {
$r = sql("SELECT * FROM stream_ghost_debug ORDER BY id");
while ($o = mysql_fetch_object($r)) {
ParseGhostXMLMapInfo($o->xml,$o);
}
exit(0);
}
function PrintFooter () { global $gIndex_StartT; echo "total time for page ".(time()-$gIndex_StartT)."msec<br>\n"; ?></body></html><?php }
// htmlspecialchars
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>ZWMap</title>
<style type="text/css">
body {
font-family:Arial;
color: #000000;
font-size:8pt;
}
div.notice {
background-color:#FFFFFF;
border:1px solid #000000;
font-size:8pt;
align:center;
width:450px;
}
.broken { border:1px solid red; }
.map td {
width: 21px; height: 21px;
min-width: 21px; min-height: 21px;
background-repeat:no-repeat;
margin: 0px;
padding: 0px;
}
//.mapcell img {
//margin: 0px;
//padding: 0px;
//~ width: 18px; height: 18px;
//}
.map {
display:inline;
}
.dvnavimap * {
line-height:5px;
}
.map * {
line-height:5px;
}
.bframe {
border:1px solid black;
}
.iconmark {
position:relative;
left:0px;
top:0px;
}
.mapaddsmall_input {
font-family:Arial,sans-serif;
color:#000000;
background-color:#F4FFF4;
font-size:12px;
border: 1px solid #008030;
height:18px;
width:20px;
padding:0px;
margin:0px;
}
.mapcellzombietxt {
font-family:Arial,sans-serif;
color:#800000;
font-size:10px;
font-weight:bold;
background-color:#8aa534;
cursor:default;
}
.mapaddsmall_button {
font-family:Arial,sans-serif;
color:#000000;
background-color:#F4FFF4;
font-size:12px;
border: 1px solid #008030;
height:20px;
// width:20px;
// padding:0px;
margin:2px 0px 0px 0px; // top,bottom,left,right
}
.mapaddsmall_button2 {
font-family:Arial,sans-serif;
color:#000000;
background-color:#F4FFF4;
font-size:12px;
border: 1px solid #008030;
height:20px;
width:20px;
// padding:0px;
margin:2px 0px 0px 0px; // top,bottom,left,right
}
a img { border:0px; }
</style>
</head>
<body onload='MyOnLoad()'>
<?php
function PrintJavaScriptBlock () { global $gGameID;?>
<script type="text/javascript">
function RadioValue(rObj,vDefault) {
for (var i=0; i<rObj.length; i++) if (rObj[i].checked) return rObj[i].value;
return vDefault;
}
function MyAjaxGet (sQuery,sTargetID) {
if (window.XMLHttpRequest)
xmlhttp=new XMLHttpRequest(); // code for IE7+, Firefox, Chrome, Opera, Safari
else xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); // code for IE6, IE5
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
if (document.getElementById(sTargetID))
document.getElementById(sTargetID).innerHTML = xmlhttp.responseText;
else alert("ajax target element not found : "+sTargetID);
}
}
xmlhttp.open("GET",sQuery,true);
xmlhttp.send();
}
function AddMapNote_Form (form) {
var x = form.x.value;
var y = form.y.value;
var z = form.zombies.value;
var sQuery = "?ajax=addmapnote&x="+escape(""+x)+"&y="+escape(""+y)+"&zombies="+escape(""+z)+"&icon="+RadioValue(form.icon,-1)+"&msg="+escape(form.msg.value);
MyAjaxGet(sQuery,"map_"+x+"_"+y); // whole map would be idMapContainer
}
<?php function BuildJSUrl ($prefix,$arr_val,$arr_check=array()) { $url = '"'.$prefix;
foreach ($arr_val as $n) $url .= '&'.$n.'="+escape(""+(form.'.$n.'.value'.'))+"';
foreach ($arr_check as $n) $url .= '&'.$n.'="+escape(""+(form.'.$n.'.checked?1:0'.'))+"';
return $url.'"';
} ?>
function Form_Map_Digg (form) { MyAjaxGet(<?=BuildJSUrl("?ajax=maputil_digg",array("x","y"),array("dig_north","dig_west","dig_mid","dig_east","dig_south"))?>,"idMapContainer"); }
function Form_Map_Scout (form) { MyAjaxGet(<?=BuildJSUrl("?ajax=maputil_scout",array("x","y","zombie_north","zombie_west","zombie_mid","zombie_east","zombie_south"))?>,"idMapContainer"); }
function ColorCheckBox (el,col) {
el.style.backgroundColor = col;
el.style.color = col;
}
function GetAjaxUrlParamAdd () {
return "&gameid="+escape(<?=$gGameID?>)+"&day="+escape(<?=kSearchGameDay?kSearchGameDay:"false"?>);
}
function MapCellTooltip (td) {
// TODO
}
function MapClickCell (x,y) {
//~ alert("ClickCell"+x+","+y);
MyAjaxGet("?ajax=cellinfo&x="+escape(x)+"&y="+escape(y)+GetAjaxUrlParamAdd(),"idMapCellInfo");
}
function MapClickCell_Dummy (x,y) { // IsOwnGame()?"MapClickCell":"MapClickCell_Dummy"
MyAjaxGet("?ajax=cellinfo&x="+escape(x)+"&y="+escape(y)+GetAjaxUrlParamAdd(),"idMapCellInfo");
//~ document.getElementById("idMapCellInfo").innerHTML = "nur in der eigenen Stadt möglich";
}
function ShowHide (id) {
var e = document.getElementById(id);
if (!e) { alert("ShowHide target element not found : "+id); return; }
if ( e.style.display != "none")
e.style.display = "none";
else e.style.display = "inline";
}
function SetMapMode (d) { MyAjaxGet("?ajax=mapmode&mapmode="+escape(d)+GetAjaxUrlParamAdd(),"idMapContainer"); }
// ***** ***** ***** ***** ***** DVNavi START
function ShowNaviMenu () { MyAjaxGet("?ajax=shownavimenu"+GetAjaxUrlParamAdd(),"idMapCellInfo"); }
<?php
function DVNaviGetMapClass($x,$y) {
global $gGameDay;
if ($x == kCityX && $y == kCityY) return "city";
$rx = $x-kCityX;
$ry = kCityY-$y;
$o = GetMapNote($rx,$ry);
if ($o->day == $gGameDay && $o->icon == kIconID_Verboten) return "verboten"; // per icon manuell deaktiviert
if ($o->day == $gGameDay && $o->icon == kIconID_Bonus) return "bonus"; // per icon manuell deaktiviert
$data = Map($x,$y);
if (!$data) return "unexp"; // unexplored -> sure that it is NONEMPTY, could have ruin
if (IsMapCellRuine($x,$y)) return "ruin";
if ($o && (int)$o->day == (int)$gGameDay) { // von heute
if ($o->icon == kIconID_DigVoll) return "voll";
if ($o->icon == kIconID_DigLeer) return "leer";
}
return "old"; // old
}
echo "gDVNavi_MapW = ".kMapW.";\n";
echo "gDVNavi_MapH = ".kMapH.";\n";
echo "gDVNavi_CityX = ".(kCityX+1).";\n";
echo "gDVNavi_CityY = ".(kCityY+1).";\n";
echo "gDVNavi_MapClass = new Array();\n";
echo "gDVNavi_MapScore = new Array();\n";
for ($y=0;$y<kMapH;++$y) { echo "gDVNavi_MapScore[$y] = new Array();\n"; }
for ($y=0;$y<kMapH;++$y) { echo "gDVNavi_MapClass[$y] = new Array("; for ($x=0;$x<kMapW;++$x) { echo "'".DVNaviGetMapClass($x,$y)."',"; } echo "0);\n"; }
?>
kDVNaviMaxScore = 1100;
kDVNavi2ndMaxScore = 100; // zweithoechste moegliche punktzahl
gDVNavi_ScoreTable_Unexplored = new Object();
gDVNavi_ScoreTable_Unexplored.verboten = -10*kDVNaviMaxScore;
gDVNavi_ScoreTable_Unexplored.city = 0;
gDVNavi_ScoreTable_Unexplored.old = 5;
gDVNavi_ScoreTable_Unexplored.leer = 0;
gDVNavi_ScoreTable_Unexplored.voll = 10;
gDVNavi_ScoreTable_Unexplored.unexp = kDVNaviMaxScore-100;
gDVNavi_ScoreTable_Unexplored.ruin = kDVNavi2ndMaxScore;
gDVNavi_ScoreTable_Unexplored.bonus = kDVNaviMaxScore;
function DVNavi_AbsToRelX (x) { return x - gDVNavi_CityX; }
function DVNavi_AbsToRelY (y) { return gDVNavi_CityY - y; }
function DVNavi_FieldDistAP (rx,ry) { return Math.abs(rx) + Math.abs(ry); }
function DVNavi_FieldDistKM (rx,ry) { return Math.round(Math.sqrt(rx*rx + ry*ry)); }
function InitScoreMap (scoretable) {
//~ gMaxScorePerField = 0;
//~ for (var k in scoretable) gMaxScorePerField = Math.max(gMaxScorePerField,scoretable[k]);
var b6km = gDVNaviMode == "6kmNoRet" || gDVNaviMode == "6km";
var bBonusMode = gDVNaviMode == "bonus";
//~ alert("InitScoreMap "+b6km+" : "+gDVNaviMode);
for (y=0;y<gDVNavi_MapH;++y) for (x=0;x<gDVNavi_MapW;++x) {
var rx = DVNavi_AbsToRelX(x+1);
var ry = DVNavi_AbsToRelY(y+1);
var km = DVNavi_FieldDistKM(rx,ry);
var ap = DVNavi_FieldDistAP(rx,ry);
var ap2 = ap*2;
var zoneClass = gDVNavi_MapClass[y][x];
var bUnexplored = zoneClass == "unexp";
var bRuin = zoneClass == "ruin";
var bVerboten = zoneClass == "verboten";
var bBonusZone = zoneClass == "bonus";
if (bBonusMode) {
gDVNavi_MapScore[y][x] = bBonusZone ? (kDVNaviMaxScore) : (scoretable[gDVNavi_MapClass[y][x]] / 4);
} else if (b6km) {
if ((bRuin || bUnexplored) && km >= 6) {
if (ap2 < 18) gDVNavi_MapScore[y][x] = 1000;
else if (ap2 == 18) gDVNavi_MapScore[y][x] = 1000;
else gDVNavi_MapScore[y][x] = 100; // >18ap single reachable dist
} else {
gDVNavi_MapScore[y][x] = bUnexplored ? 1 : 0;
}
if (bVerboten) gDVNavi_MapScore[y][x] = -5000;
} else {
gDVNavi_MapScore[y][x] = scoretable[gDVNavi_MapClass[y][x]];
}
}
}
gMap = {}
for (y=1;y<=gDVNavi_MapH;++y) { var row = new Array(); gMap[y] = row; for (x=1;x<=gDVNavi_MapW;++x) { row[x] = new Object(); } } // every cell is a table
function Map (x,y) { return gMap[y][x]; }
function DVNavi_Score (x,y) { return gDVNavi_MapScore[y-1][x-1]; } // gMap indices are one-based, gDVNavi_MapScore zero-based
function DVNavi_Class (x,y) { return gDVNavi_MapClass[y-1][x-1]; } // gMap indices are one-based, gDVNavi_MapScore zero-based
function IsCity (x,y) { return x == gDVNavi_CityX && y == gDVNavi_CityY; }
function Valid (x,y) { return x >= 1 && x <= gDVNavi_MapW && y >= 1 && y <= gDVNavi_MapH; }
function ReturnAP (x,y) { return Math.abs(x-gDVNavi_CityX) + Math.abs(y-gDVNavi_CityY); }
// expeditions
function clonemod1 (t,k1,v1) { // copy assoc-array t, and modify one value by key k1 -> v1
var res = new Object();
for (var k in t) res[k] = t[k];
res[k1] = v1;
return res;
}
function DVNavi_Heuristic (x,y,ap) {
// determine the area than can be travalled, and see how often we can achieve max-score in it
var e = Math.floor((ap - (gDVNaviReturnByHeroAction?0:ReturnAP(x,y))) / 2);
var minx = Math.max(1,Math.min(gDVNavi_MapW, Math.min(x,gDVNavi_CityX)-e ));
var maxx = Math.max(1,Math.min(gDVNavi_MapW, Math.max(x,gDVNavi_CityX)+e ));
var miny = Math.max(1,Math.min(gDVNavi_MapH, Math.min(y,gDVNavi_CityY)-e ));
var maxy = Math.max(1,Math.min(gDVNavi_MapH, Math.max(y,gDVNavi_CityY)+e ));
var maxc = 0;
for (var ty=miny;ty<=maxy && maxc < ap;++ty)
for (var tx=minx;tx<=maxx;++tx) if (DVNavi_Score(tx,ty) >= kDVNaviMaxScore) { ++maxc; if (maxc >= ap) break; }
return maxc * kDVNaviMaxScore + (ap - maxc) * kDVNavi2ndMaxScore; // an upper limit for the score achievable with the remaining ap
}
function AddExpedition (x,y,ap,visited,score,txt) {
if (ap < 0 || !Valid(x,y) || (ReturnAP(x,y) > ap && !gDVNaviReturnByHeroAction)) return;
var pos = (x-gDVNavi_CityX) + "/" + (gDVNavi_CityY-y); // as string
if (!visited[pos]) score += DVNavi_Score(x,y);
if (score + ap*kDVNaviMaxScore <= gMinScore) return;
var heur = score + DVNavi_Heuristic(x,y,ap);
if (heur <= gMinScore) return;
var newexp = new Object();
newexp.x = x;
newexp.y = y;
newexp.ap = ap;
newexp.score = score;
newexp.heur = heur;
newexp.visited = clonemod1(visited,pos,true);
newexp.txt = txt+" "+pos;
gExpeditions.push(newexp);
gExpeditionC = gExpeditionC + 1;
}
function InExp (e,x,y) {
var pos = " "+(x-gDVNavi_CityX)+"/"+(gDVNavi_CityY-y)+" "
return e.txt.search(pos) != -1;
}
function MyPrintStatus (txt) { gDVNaviStatus.innerHTML = txt; }
function MyPrintLine (txt) { gDVNaviConsole.innerHTML += txt+"<br>\n"; }
function DVNavi_Execute (ap,mode) {
gDVNaviMode = mode;
gDVNaviReturnByHeroAction = false;
if (gDVNaviMode == "6kmNoRet") gDVNaviReturnByHeroAction = true;
gExpeditions = new Array();
gExpeditionC = 0;
gFinishedExp = new Array();
gMinScore = 0;
gBestExpPath = "";
gDVNaviConsole = false;
gDVNaviStatus = false;
gExpeditionMaxAP = 18;
gDVNavi_BlockSteps = 200;
gExpeditionMaxAP = ap;
gDVNavi_BlockSteps = <?=isset($_REQUEST["dvnavi_cpu"])?$_REQUEST["dvnavi_cpu"]:200?>;
InitScoreMap(gDVNavi_ScoreTable_Unexplored);
gDVNaviConsole = document.getElementById("idMapCellInfo");
//~ gDVNaviConsole.innerHTML += "<br>\n";
gDVNaviStatus = document.getElementById("idDVNaviStatus");
AddExpedition(gDVNavi_CityX,gDVNavi_CityY,gExpeditionMaxAP,new Object(),0,"");
gDVNavi_Steps = 0;
DVNavi_StepBlock();
return false;
}
function DVNavi_StepBlock () { // delayed execution to avoid browser hang
var blocksteps = gDVNavi_BlockSteps;
while (gExpeditions.length > 0 && blocksteps > 0) { DVNavi_Step(); --blocksteps; }
if (gExpeditions.length > 0)
window.setTimeout("DVNavi_StepBlock()",10); // short pause, then continue
else DVNavi_Finished();
}
function DVNavi_Step () { // main step, this eats cpu for breakfast
<?php $bHeuristicsActive = isset($_REQUEST["heuristic"]);?>
<?php $bHeuristicsActive = true;?>
<?php if ($bHeuristicsActive) {?>
// try to pick the "best" element. but didn't work, neither with current score, nor with heuristic
var len = Math.min(2000,gExpeditions.length);
var e = false;
var e_i = 0;
var next_heur = -1;
var next_score = -1;
for (var i=0;i<len;++i) {
var cur = gExpeditions[i];
if (cur.heur > next_heur) { e_i = i; next_heur = cur.heur; e = cur; }
//~ if (cur.score > next_score || (cur.score == next_score && cur.heur > next_heur)) { e_i = i; next_heur = cur.heur; next_score = cur.score; e = cur; }
}
if (e) { gExpeditions[e_i] = gExpeditions[gExpeditions.length-1]; gExpeditions.pop(); }
<?php } else {?>
var e = gExpeditions.pop(); // just take the last element
<?php }?>
if (!e) return;
gExpeditionC -= 1;
var bFinished = e.ap <= 2 && (ReturnAP(e.x,e.y) == 0 || gDVNaviReturnByHeroAction);
if (bFinished && e.score > gMinScore) {
gMinScore = e.score;
//~ table.insert(gFinishedExp,e)
//~ MyPrintLine("new highscore",gMinScore,e.txt);
gBestExp = e;
gBestExpPath = e.txt;
DVNavi_ShowBestResult();
}
AddExpedition(e.x-1,e.y,e.ap-1,e.visited,e.score,e.txt);
AddExpedition(e.x+1,e.y,e.ap-1,e.visited,e.score,e.txt);
AddExpedition(e.x,e.y-1,e.ap-1,e.visited,e.score,e.txt);
AddExpedition(e.x,e.y+1,e.ap-1,e.visited,e.score,e.txt);
++gDVNavi_Steps;
if ((gDVNavi_Steps % 500) == 0) MyPrintStatus("step "+gDVNavi_Steps+","+gExpeditionC+","+gMinScore+","+gBestExpPath);