Mercurial > hg > batmud > misc
view materials/info.php @ 296:8724b9de70bf misc
Variable renames, cleanups, etc.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 09 Mar 2015 14:03:41 +0200 |
parents | fa66c4c8cd8a |
children | b7a8b9cf7689 |
line wrap: on
line source
<? $pageTitle = "Pupunen BatMUD Alloy Browser"; $pageIndex = "info.php"; $people = array("Hair", "Malacoda", "Kiomet", "Aegenor", "Gileon", "Corto"); $matTypeTable = array( 0 => array("Organic + cloth (sewing)", 0, 1), 1 => array("Wood + bone (carpentry)", 5, 3), 2 => array("Metal + alloy (blacksmithing)", 4, 7), 3 => array("Stone (masonry)", 6, -1), 4 => array("Gem (gemcutting)", 10, -1), 5 => array("Inorganic (sculpture)", 8, -1), 6 => array("Glass (glassblowing)", 9, -1), 7 => array("Organic", 0, -1), 8 => array("Wood", 5, -1), 9 => array("Metal", 4, -1), 10 => array("Cloth", -1, 1), 11 => array("Bone", -1, 3), 12 => array("Alloy", -1, 7), ); require "msitegen.inc.php"; require "materials.inc.php"; require "alloys.inc.php"; function stGetMatLink($mat, $title = "", $extra = "") { $tmp = ($title != "") ? " title=\"".chentities($title)."\"" : ""; return "<a href=\"/mat/".urlencode($mat)."\"".$tmp.">".chentities($mat)."</a>".$extra; } function stGetValueStyle($n) { if ($n >= 40) $str = 40; else if ($n >= 20) $str = 20; else if ($n >= 10) $str = 10; else if ($n >= 5) $str = 5; else if ($n > 0) $str = 0; else return ""; return " class=\"hits".$str."\""; } // // Actual main code begins // $setShowOnly = intval(stGetRequestItem("o", 0, TRUE)); if (isset($_GET["m"])) { $setShowMat = strtolower($_GET["m"]); $setShowMatName = strtoupper(substr($setShowMat,0,1)).substr($setShowMat, 1); } $setSwapRows = (isset($_GET["swap"]) && is_array($_GET["swap"])) ? $_GET["swap"] : array(); cmPrintPageHeader($pageTitle, " <meta name=\"robots\" content=\"nofollow\" /> <style type=\"text/css\"> span.alternate { color: red; font-weight: bold; } td.hits20 a, .hits20 { color: black; } td.hits40, .hits40 { background: #0f0; color: white; } td.hits20, .hits20 { background: #0c0; color: black; } td.hits10, .hits10 { background: #080; } td.hits5, .hits5 { background: #750; } td.hits0, .hits0 { background: #420; } td.nohits, .nohits { background: black; } td.impossible { background: black; color: #f00; text-align: center; } </style> "); ?> <h1><? echo $pageTitle; ?></h1> <form action="<? echo $pageIndex; ?>" method="get"> <table class="optionsTable" width="100%"> <tr> <th width="25%">Show type</th> <td rowspan="3" class="infobox"> [<a href="<? echo $pageIndex; ?>">Reset/Clear</a>] [<a href="index.php">Material browser</a>] <br /> <ul> <li><b>Also available in <a href="alloys.txt">ASCII plaintext format</a>.</b></li> <li>Only 2-material alloys are currently supported by this browser. <b>Yes, I know some you think that this project is "useless".</b></li> <li>There may be bugs and lots of combinations are not researched yet.</li> <li>The cell colour reflects how "reliable" the information is: <b> <span class="hits0">1-4 tries</span>, <span class="hits5">5-9 tries</span>, <span class="hits10">10-19 tries</span>, <span class="hits20">20..39 tries</span>, <span class="hits40">40 or more</span></b>. </li> <? if (isset($people) && count($people) > 0) { $tmp = array(); foreach ($people as $key) $tmp[] = "<b>".$key."</b>"; echo "<li>Thanks to the following people for providing alloying data: ".join(", ", $tmp).".</li>"; } ?> </ul> </td> </tr> <tr> <td class="icenter"> <select name="o"> <? foreach ($matTypeTable as $key => $value) { $n = 0; foreach ($matDataTable as $name => $data) { if ($data[14] == $value[1] || $data[14] == $value[2]) $n++; } $matTypeTable[$key][] = $n; printf( " <option value=\"%s\"%s>%-30s [%d]</option>\n", $key, ($setShowOnly == $key ? " selected=\"selected\"" : ""), chentities($value[0]), $n); } ?> </select> </td> </tr> <tr> <td class="icenter"><input type="submit" value=" Filter " class="isubmit" /></td> </tr> </table> </form> <? if (isset($setShowMat)) { if (!isset($matDataTable[$setShowMat])) { echo "<h2>Error! No such material '".$setShowMatName."'</h2>\n". "<p>Material is not known. Check spelling.</p>\n"; } else { echo "<h2>".$setShowMatName."</h2>\n". "<table width=\"95%\">\n". "<tr>"; $n = 0; foreach ($matDataTable[$setShowMat] as $key => $val) { echo "<th>".chentities($matTransNames[$key + 1])."</th><td>"; if (is_array($val)) { $tmp = array(); foreach ($val as $lode) $tmp[] = chentities($matTransTable[$key][$lode]); echo join(", ", $tmp); } else { echo chentities($matTransTable[$key][$val]); } echo "</td>"; if ($n++ >= 2) { echo "</tr>\n<tr>"; $n = 0; } } echo "</tr>\n</table>\n"; echo "<h3>Alloy combinations</h3>\n"; if (isset($alloyRevTable[$setShowMat])) { echo "<ul>\n"; foreach ($alloyRevTable[$setShowMat] as $mat => $value) { $tmp = array(); foreach ($value as $qkey => $qval) $tmp[] = stGetMatLink($qkey); echo " <li>".stGetMatLink($mat)." <b>+</b> ".join(" <b>|</b> ", $tmp). "<b> = ".chentities($setShowMat)."</b></li>\n"; } echo "</ul>\n". "<pre>\n". "Syntax: <b>+</b> is AND, <b>|</b> is OR, e.g.:\n". "<b>A + B = C</b> means A alloyed with B produces C.\n". "<b>A + B | C = D</b> means A alloyed with B <b>or</b> C produces D.\n". "</pre>\n"; } else { echo "<p>No known alloy combinations.</p>\n"; } /* $typeMats = array(); foreach ($matDataTable as $name => $data) { if ($data[14] == $matDataTable[$setShowMat][14] && $name != $setShowMat) $typeMats[] = $name; } echo "Full mix: "; if (list($a, $b) = each($typeMats)) echo stGetMatLink($b); while (list($a, $b) = each($typeMats)) echo " <b>+</b> ".stGetMatLink($b); echo "<br />\n"; */ echo "<h3>Mixtable</h3>\n"; if (count($alloyTable[$setShowMat]) > 0) { echo "<table class=\"matTable\">". " <tr>\n". " <th>+</th>\n"; foreach ($alloyTable[$setShowMat] as $key => $value) { echo "<th>".stGetMatLink($key)."</th>\n"; } echo " </tr>\n". " <tr><th>".chentities($setShowMat)."</th>"; foreach ($alloyTable[$setShowMat] as $key => $value) if (list($a, $b) = each($value)) { echo "<td ".stGetValueStyle($b).">".stGetMatLink($a)."</td>"; } echo "</tr></table>\n"; } else { echo "<p>No mixtable entries.</p>\n"; } } } else { /* * Print alloy table for given material type */ // Filter table from maintable matching desired material type(s) $currTable = array(); foreach ($matDataTable as $name => $data) { if ($data[14] == $matTypeTable[$setShowOnly][1] || $data[14] == $matTypeTable[$setShowOnly][2]) $currTable[] = $name; } // Swap desired rows if (count($setSwapRows) > 0) { $str = array(); $nkeys = count($currTable); foreach ($setSwapRows as $from => $to) if ($from >= 0 && $from < $nkeys && $to >= 0 && $to < $nkeys && $to != $from) { $str[] = $from." <=> ".$to; $tmp = $currTable[$from]; $currTable[$from] = $currTable[$to]; $currTable[$to] = $tmp; } if (count($str) > 0) echo "<p>Swapped rows: ".implode(", ", $str)."</p>\n"; } // Print out the table echo "<table class=\"alloyTable\">". " <tr>\n". " <th>-</th>\n"; foreach ($currTable as $name) { echo " <th>".stGetMatLink($name)."</th>\n"; } echo " </tr>\n"; $researched = 0; $researchValue = 0; foreach ($currTable as $mat1) { echo " <tr><th>".stGetMatLink($mat1)."</th>"; foreach ($currTable as $mat2) { // Is the combo possible? if ($mat1 != $mat2) { // Check for combination result if (isset($alloyTable[$mat1][$mat2])) $tmp = $alloyTable[$mat1][$mat2]; else if (isset($alloyTable[$mat2][$mat1])) $tmp = $alloyTable[$mat2][$mat1]; else unset($tmp); if (isset($tmp)) { arsort($tmp); $value = 0; foreach ($tmp as $a => $b) $value += $b; $researched++; $researchValue += $value; $slist = array(); foreach ($tmp as $a => $b) { $slist[] = stGetMatLink($a, $b." successful alloys (".$mat1." + ".$mat2." = ".$a.")". (count($tmp) > 1 ? " [UNSTABLE]" : "") ); // , " <sup>".$b."</sup>"); } echo "<td".stGetValueStyle($value, count($tmp) > 1 ? " mitalic" : "").">". join(" <span class=\"alternate\">/</span> ", $slist)."</td>"; } else echo "<td class=\"nohits\" title=\"Not researched\">?</td>"; } else { echo "<td class=\"impossible\" title=\"Impossible combination\">-</td>"; } } echo "</tr>\n"; } $mats = count($currTable); $total = $mats * $mats - $mats; printf("</table>\n". "<div><b>%1.2f%%</b> (%d / %d) of combinations researched. ". "Estimating <b>%1.2f%%</b> overall accuracy.</div>\n", ($researched * 100.0) / $total, $researched, $total, ($researchValue * 100.0) / ($total * 10.0)); } cmPrintPageFooter(); ?>