function science_getScienceDetail($caveID, &$details) { global $buildingTypeList, $defenseSystemTypeList, $resourceTypeList, $unitTypeList, $scienceTypeList, $config, $params, $db; // messages $messageText = array(0 => _('Der Forschungsauftrag wurde erfolgreich gestoppt.'), 1 => _('Es konnte kein Forschungsauftrag gestoppt werden.'), 2 => _('Der Auftrag konnte nicht erteilt werden. Es fehlen die notwendigen Voraussetzungen.'), 3 => _('Der Auftrag wurde erteilt'), 4 => _('Dieses Wissen wird schon in einer anderen Höhle erforscht.'), 5 => _('Es wird gerade in einer anderen Höhle Wissen erforscht, dass dieses Wissen ausschließt.')); // proccess a cancel-order request if (isset($params->POST->eventID)) { $messageID = science_processOrderCancel($params->POST->eventID, $caveID, $db); } if (isset($params->POST->scienceID)) { $messageID = science_processOrder($params->POST->scienceID, $caveID, $params->SESSION->player->playerID, $details, $db); $r = getCaveSecure($caveID, $params->SESSION->player->playerID); if ($r->isEmpty()) { page_dberror(); } $details = $r->nextRow(); } $queue = science_getScienceQueueForCave($params->SESSION->player->playerID, $caveID); $template = tmpl_open($params->SESSION->player->getTemplatePath() . 'science.ihtml'); // Show a special message if (isset($messageID)) { tmpl_set($template, '/MESSAGE/message', $messageText[$messageID]); } // Show the science table for ($i = 0; $i < sizeof($scienceTypeList); $i++) { $science = $scienceTypeList[$i]; // the current science $maxLevel = round(eval('return ' . formula_parseToPHP("{$science->maxLevel};", '$details'))); $notenough = FALSE; $result = rules_checkDependencies($science, $details); if ($result === TRUE) { tmpl_iterate($template, 'SCIENCE'); tmpl_set($template, "SCIENCE/alternate", $count++ % 2 ? "alternate" : ""); tmpl_set($template, 'SCIENCE', array('dbFieldName' => $science->dbFieldName, 'name' => $science->name, 'scienceID' => $i, 'modus' => SCIENCE_DETAIL, 'caveID' => $caveID, 'size' => "0" + $details[$science->dbFieldName], 'time' => time_formatDuration(eval('return ' . formula_parseToPHP($science->productionTimeFunction . ";", '$details')) * SCIENCE_TIME_BASE_FACTOR))); // iterate ressourcecosts foreach ($science->resourceProductionCost as $resourceID => $function) { $cost = ceil(eval('return ' . formula_parseToPHP($function . ';', '$details'))); if ($cost) { tmpl_iterate($template, "SCIENCE/RESSOURCECOST"); if ($details[$resourceTypeList[$resourceID]->dbFieldName] >= $cost) { tmpl_set($template, "SCIENCE/RESSOURCECOST/ENOUGH/value", $cost); } else { tmpl_set($template, "SCIENCE/RESSOURCECOST/LESS/value", $cost); $notenough = TRUE; } tmpl_set($template, "SCIENCE/RESSOURCECOST/dbFieldName", $resourceTypeList[$resourceID]->dbFieldName); tmpl_set($template, "SCIENCE/RESSOURCECOST/name", $resourceTypeList[$resourceID]->name); } } // iterate unitcosts foreach ($science->unitProductionCost as $unitID => $function) { $cost = ceil(eval('return ' . formula_parseToPHP($function . ';', '$details'))); if ($cost) { tmpl_iterate($template, "SCIENCE/UNITCOST"); if ($details[$unitTypeList[$unitID]->dbFieldName] >= $cost) { tmpl_set($template, "SCIENCE/UNITCOST/ENOUGH/value", $cost); } else { tmpl_set($template, "SCIENCE/UNITCOST/LESS/value", $cost); $notenough = TRUE; } tmpl_set($template, "SCIENCE/UNITCOST/name", $unitTypeList[$unitID]->name); } } // iterate buildingcosts foreach ($science->buildingProductionCost as $buildingID => $function) { $cost = ceil(eval('return ' . formula_parseToPHP($function . ';', '$details'))); if ($cost) { tmpl_iterate($template, "DEFENSESYSTEM/BUILDINGCOST"); if ($details[$buildingTypeList[$buildingID]->dbFieldName] >= $cost) { tmpl_set($template, "DEFENSESYSTEM/BUILDINGCOST/ENOUGH/value", $cost); } else { tmpl_set($template, "DEFENSESYSTEM/BUILDINGCOST/LESS/value", $cost); $notenough = TRUE; } tmpl_set($template, "DEFENSESYSTEM/BUILDINGCOST/name", $buildingTypeList[$buildingID]->name); } } // iterate externalcosts foreach ($science->externalProductionCost as $externalID => $function) { $cost = ceil(eval('return ' . formula_parseToPHP($function . ';', '$details'))); if ($cost) { tmpl_iterate($template, "DEFENSESYSTEM/EXTERNALCOST"); if ($details[$defenseSystemTypeList[$externalID]->dbFieldName] >= $cost) { tmpl_set($template, "DEFENSESYSTEM/EXTERNALCOST/ENOUGH/value", $cost); } else { tmpl_set($template, "DEFENSESYSTEM/EXTERNALCOST/LESS/value", $cost); $notenough = TRUE; } tmpl_set($template, "DEFENSESYSTEM/EXTERNALCOST/name", $defenseSystemTypeList[$externalID]->name); } } // show the science link ?! if ($queue) { tmpl_set($template, 'SCIENCE/RESEARCH_LINK_NO/message', _('Erforschung im Gange')); } else { if ($notenough && $maxLevel > $details[$science->dbFieldName]) { tmpl_set($template, 'SCIENCE/RESEARCH_LINK_NO/message', _('Zu wenig Rohstoffe')); } else { if ($maxLevel > $details[$science->dbFieldName]) { tmpl_set($template, 'SCIENCE/RESEARCH_LINK', array('action' => SCIENCE, 'scienceID' => $science->scienceID, 'caveID' => $caveID)); } else { tmpl_set($template, '/SCIENCE/RESEARCH_LINK_NO/message', _('Max. Stufe')); } } } } else { if ($result !== FALSE && !$science->nodocumentation) { tmpl_iterate($template, '/UNQUALIFIEDSCIENCES/SCIENCE'); tmpl_set($template, '/UNQUALIFIEDSCIENCES/SCIENCE', array('alternate' => $count_unqualified++ % 2 ? "" : "alternate", 'modus' => SCIENCE_DETAIL, 'scienceID' => $science->scienceID, 'caveID' => $caveID, 'dbFieldName' => $science->dbFieldName, 'name' => $science->name, 'dependencies' => $result)); } } } // Show the science queue if ($queue) { // display the science queue $row = $queue->nextRow(); tmpl_set($template, 'SCIENCE_QUEUE', array('name' => $scienceTypeList[$row['scienceID']]->name, 'size' => $details[$scienceTypeList[$row['scienceID']]->dbFieldName] + 1, 'finish' => time_formatDatetime($row['end']), 'action' => SCIENCE, 'eventID' => $row['event_scienceID'], 'caveID' => $caveID)); } tmpl_set($template, "rules_path", RULES_PATH); return tmpl_parse($template); }
function science_getScienceDetail($caveID, &$details) { global $template; // open template $template->setFile('scienceBuilder.tmpl'); // messages $messageText = array(0 => array('type' => 'success', 'message' => _('Der Forschungsauftrag wurde erfolgreich gestoppt.')), 1 => array('type' => 'error', 'message' => _('Es konnte kein Forschungsauftrag gestoppt werden.')), 2 => array('type' => 'error', 'message' => _('Der Auftrag konnte nicht erteilt werden. Es fehlen die notwendigen Voraussetzungen.')), 3 => array('type' => 'success', 'message' => _('Der Auftrag wurde erteilt')), 4 => array('type' => 'info', 'message' => _('Dieses Wissen wird schon in einer anderen Höhle erforscht.')), 5 => array('type' => 'info', 'message' => _('Es wird gerade in einer anderen Höhle Wissen erforscht, das dieses Wissen ausschließt.'))); // get this cave's queue $queue = science_getQueue($_SESSION['player']->playerID, $caveID); $action = Request::getVar('action', ''); switch ($action) { /**************************************************************************************************** * * Forschung starten * ****************************************************************************************************/ case 'build': $scienceID = Request::getVar('scienceID', -1); if ($scienceID == -1) { $messageID = 2; break; } // check queue exist if (sizeof($queue)) { $messageID = 2; break; } $messageID = science_processOrder($scienceID, $caveID, $details); $details = getCaveSecure($caveID, $_SESSION['player']->playerID); $queue = science_getQueue($_SESSION['player']->playerID, $caveID); break; /**************************************************************************************************** * * Forschung abbrechen * ****************************************************************************************************/ /**************************************************************************************************** * * Forschung abbrechen * ****************************************************************************************************/ case 'cancelOrder': $eventID = Request::getVar('id', 0); if ($eventID == 0) { $messageID = 2; break; } // check queue exist if (!sizeof($queue) || $queue['event_scienceID'] != $eventID) { $messageID = 2; break; } if (Request::isPost('cancelOrderConfirm')) { $messageID = science_cancelOrder($eventID, $caveID); if ($messageID == 0) { $queue = null; } } else { $template->addVars(array('cancelOrder_box' => true, 'confirm_action' => 'cancelOrder', 'confirm_id' => $eventID, 'confirm_mode' => SCIENCE_BUILDER, 'confirm_msg' => sprintf(_('Möchtest die Forschung von <span class="bold">%s</span> abbrechen?'), $GLOBALS['scienceTypeList'][$queue['scienceID']]->name))); } break; } $sciences = $sciencesUnqualified = array(); foreach ($GLOBALS['scienceTypeList'] as $id => $science) { $maxLevel = round(eval('return ' . formula_parseToPHP("{$science->maxLevel};", '$details'))); $notenough = FALSE; $result = rules_checkDependencies($science, $details); /**************************************************************************************************** * * Forschungen die man forschen kann. * ****************************************************************************************************/ if ($result === TRUE) { $sciences[$science->scienceID] = array('name' => $science->name, 'dbFieldName' => $science->dbFieldName, 'science_id' => $science->scienceID, 'modus' => SCIENCE_BUILDER, 'cave_id' => $caveID, 'time' => time_formatDuration(eval('return ' . formula_parseToPHP($science->productionTimeFunction . ";", '$details')) * SCIENCE_TIME_BASE_FACTOR), 'maxlevel' => $maxLevel, 'currentlevel' => "0" + $details[$science->dbFieldName], 'description' => $science->description, 'duration_formula' => formula_parseToReadable($science->productionTimeFunction)); $sciences[$science->scienceID] = array_merge($sciences[$science->scienceID], parseCost($science, $details)); // show the building link ?! if (sizeof($queue)) { $sciences[$science->scienceID]['no_build_msg'] = _('Erforschung im Gange'); } else { if ($sciences[$science->scienceID]['notenough'] && $maxLevel > $details[$science->dbFieldName]) { $sciences[$science->scienceID]['no_build_msg'] = _('Zu wenig Rohstoffe'); } else { if ($maxLevel > $details[$science->dbFieldName]) { $sciences[$science->scienceID]['build_link'] = true; } else { $sciences[$science->scienceID]['no_build_msg'] = _('Max. Stufe'); } } } /**************************************************************************************************** * * Forschungen die noch nicht geforscht werden können. * ****************************************************************************************************/ } else { if ($result !== FALSE && !$science->nodocumentation) { $sciencesUnqualified[$science->scienceID] = array('name' => $science->name, 'dbFieldName' => $science->dbFieldName, 'science_id' => $science->scienceID, 'modus' => SCIENCE_DETAIL, 'caveID' => $caveID, 'dependencies' => $result, 'description' => $science->description, 'duration_formula' => formula_parseToReadable($science->productionTimeFunction)); } } } /**************************************************************************************************** * * Irgendwas im Ausbau? * ****************************************************************************************************/ if (sizeof($queue)) { $template->addVars(array('quene_show' => true, 'quene_name' => $GLOBALS['scienceTypeList'][$queue['scienceID']]->name, 'quene_nextlevel' => $details[$GLOBALS['scienceTypeList'][$queue['scienceID']]->dbFieldName] + 1, 'quene_finish' => time_formatDatetime($queue['end']), 'quene_modus' => SCIENCE_BUILDER, 'quene_event_id' => $queue['event_scienceID'])); } /**************************************************************************************************** * * Übergeben ans Template * ****************************************************************************************************/ $template->addVars(array('cave_id' => $caveID, 'status_msg' => isset($messageID) ? $messageText[$messageID] : '', 'science' => $sciences, 'science_unqualified' => $sciencesUnqualified)); }