Mercurial > hg > batmud > misc
view materials/info.php @ 253:1eca10751695 misc
Improve alloy browser output.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 07 Mar 2015 23:22:33 +0200 |
parents | 233141af4dcf |
children | af08f54f0bc6 |
line wrap: on
line source
<? $pageTitle = "Pupunen BatMUD Alloy Browser"; $pageIndex = "info.php"; require "msitegen.inc.php"; require "materials.inc.php"; require "alloys.inc.php"; $showOnly = intval(stGetRequestItem("o", 0, TRUE)); if (isset($_GET["m"])) { $showMat = strtolower($_GET["m"]); $showMatName = strtoupper(substr($showMat,0,1)).substr($showMat, 1); } $swapRows = (isset($_GET["swap"]) && is_array($_GET["swap"])) ? $_GET["swap"] : array(); function matLink($mat, $title = "", $extra = "") { $tmp = ($title != "") ? " title=\"".chentities($title)."\"" : ""; return "<a href=\"/mat/".urlencode($mat)."\"".$tmp.">".chentities($mat)."</a>".$extra; } function addValueStyle($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."\""; } 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> </ul> </td> </tr> <tr> <td class="icenter"> <select name="o"> <? $typeTable = 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), ); foreach ($typeTable as $key => $value) { echo " <option value=\"$key\"". ($showOnly == $key ? " selected=\"selected\"" : ""). ">".chentities($value[0])."</option>\n"; } ?> </select> </td> </tr> <tr> <td class="icenter"><input type="submit" value=" Filter " class="isubmit" /></td> </tr> </table> </form> <? if (isset($showMat)) { if (!isset($matTable[$showMat])) { echo "<h2>Error! No such material '".$showMatName."'</h2>\n". "<p>Material is not known. Check spelling.</p>\n"; } else { echo "<h2>".$showMatName."</h2>\n". "<table width=\"95%\">\n". "<tr>"; $n = 0; foreach ($matTable[$showMat] as $key => $val) { echo "<th>".chentities($transNameTable[$key+1])."</th><td>"; if (is_array($val)) { reset($val); if (list($nam, $lode) = each($val)) echo chentities($transTable[$key][$lode]); while (list($nam, $lode) = each($val)) echo ", ".chentities($transTable[$key][$lode]); } else { echo chentities($transTable[$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[$showMat])) { echo "<ul>\n"; foreach ($alloyRevTable[$showMat] as $mat => $value) { echo " <li>".matLink($mat)." <b>+</b> "; reset($value); if (list($a, $b) = each($value)) echo matLink($a); while (list($a, $b) = each($value)) echo " <b>|</b> ".matLink($a); echo "<b> = ".chentities($showMat)."</b></li>\n"; } echo "</ul>\n"; } else { echo "<p>No known alloy combinations.</p>\n"; } /* $typeMats = array(); foreach ($matTable as $name => $data) { if ($data[14] == $matTable[$showMat][14] && $name != $showMat) $typeMats[] = $name; } echo "Full mix: "; if (list($a, $b) = each($typeMats)) echo matLink($b); while (list($a, $b) = each($typeMats)) echo " <b>+</b> ".matLink($b); echo "<br />\n"; */ echo "<h3>Mixtable</h3>\n"; if (count($alloyTable[$showMat]) > 0) { echo "<table class=\"matTable\">". " <tr>\n". " <th>+</th>\n"; foreach ($alloyTable[$showMat] as $key => $value) { echo "<th>".matLink($key)."</th>\n"; } echo " </tr>\n". " <tr><th>".chentities($showMat)."</th>"; foreach ($alloyTable[$showMat] as $key => $value) if (list($a, $b) = each($value)) { echo "<td ".addValueStyle($b).">".matLink($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 ($matTable as $name => $data) { if ($data[14] == $typeTable[$showOnly][1] || $data[14] == $typeTable[$showOnly][2]) $currTable[] = $name; } // Swap desired rows if (count($swapRows) > 0) { $str = array(); $nkeys = count($currTable); foreach ($swapRows 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>".matLink($name)."</th>\n"; } echo " </tr>\n"; foreach ($currTable as $mat1) { echo " <tr><th>".matLink($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; $slist = array(); foreach ($tmp as $a => $b) { $slist[] = matLink($a, $b." successful alloys (".$mat1." + ".$mat2." = ".$a.")". (count($tmp) > 1 ? " [UNSTABLE]" : ""), " <sup>".$b."</sup>"); } echo "<td".addValueStyle($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"; } echo "</table>\n"; } cmPrintPageFooter(); ?>