本文整理汇总了PHP中formula_parseToPHP函数的典型用法代码示例。如果您正苦于以下问题:PHP formula_parseToPHP函数的具体用法?PHP formula_parseToPHP怎么用?PHP formula_parseToPHP使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了formula_parseToPHP函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: science_processOrder
function science_processOrder($scienceID, $caveID, $cave)
{
global $defenseSystemTypeList, $buildingTypeList, $scienceTypeList, $resourceTypeList, $unitTypeList;
global $config, $db;
$science = $scienceTypeList[$scienceID];
$maxLevel = round(eval('return ' . formula_parseToPHP("{$science->maxLevel};", '$cave')));
// check, that this science isn't researched in an other cave at the
// same time
$sql = $db->prepare("SELECT event_scienceID\n FROM " . EVENT_SCIENCE_TABLE . "\n WHERE playerID = :playerID \n AND scienceID = :scienceID");
$sql->bindValue('playerID', $_SESSION['player']->playerID, PDO::PARAM_INT);
$sql->bindValue('scienceID', $scienceID, PDO::PARAM_INT);
if ($sql->rowCountSelect() != 0) {
return 4;
}
// check for scienceMaxDeps in Event_Handler
$dep_count = 0;
$deps = '';
foreach ($science->maxScienceDepList as $key => $value) {
if ($value != -1 && $cave[$scienceTypeList[$key]->dbFieldName] > $value - 1) {
if ($dep_count) {
$deps .= ", ";
}
$deps .= $key;
$dep_count++;
}
}
if ($dep_count) {
$sql = $db->prepare("SELECT event_scienceID\n FROM " . EVENT_SCIENCE_TABLE . "\n WHERE playerID = :playerID\n AND scienceID IN ({$deps})");
$sql->bindValue('playerID', $_SESSION['player']->playerID, PDO::PARAM_INT);
if ($sql->rowCountSelect() != 0) {
return 5;
}
}
// take production costs from cave
if (!processProductionCost($science, $caveID, $cave)) {
return 2;
}
$prodTime = 0;
// calculate the production time;
if ($time_formula = $science->productionTimeFunction) {
$time_eval_formula = formula_parseToPHP($time_formula, '$cave');
$time_eval_formula = "\$prodTime={$time_eval_formula};";
eval($time_eval_formula);
}
$prodTime *= SCIENCE_TIME_BASE_FACTOR;
$now = time();
$sql = $db->prepare("INSERT INTO " . EVENT_SCIENCE_TABLE . " (caveID, playerID, scienceID, " . "start, end) VALUES (:caveID, :playerID, :scienceID, :start, :end)");
$sql->bindValue('caveID', $caveID, PDO::PARAM_INT);
$sql->bindValue('playerID', $_SESSION['player']->playerID, PDO::PARAM_INT);
$sql->bindValue('scienceID', $scienceID, PDO::PARAM_INT);
$sql->bindValue('start', time_toDatetime($now), PDO::PARAM_STR);
$sql->bindValue('end', time_toDatetime($now + $prodTime), PDO::PARAM_STR);
if (!$sql->execute() || !$sql->rowCount() == 1) {
processProductionCostSetBack($science, $caveID, $cave);
return 2;
}
return 3;
}
示例2: unit_processOrder
function unit_processOrder($unitID, $quantity, $caveID, $details)
{
global $db;
if ($quantity == -1) {
$quantity = MAX_SIMULTAN_BUILDED_UNITS;
while (!processProductionCost($GLOBALS['unitTypeList'][$unitID], $caveID, $details, $quantity) && $quantity != 0) {
$quantity--;
}
if ($quantity <= 0) {
return 4;
}
} else {
if ($quantity > MAX_SIMULTAN_BUILDED_UNITS || $quantity <= 0) {
return 4;
}
// take the production costs from cave
if (!processProductionCost($GLOBALS['unitTypeList'][$unitID], $caveID, $details, $quantity)) {
return 2;
}
}
$prodTime = 0;
// calculate the production time;
if ($time_formula = $GLOBALS['unitTypeList'][$unitID]->productionTimeFunction) {
$time_eval_formula = formula_parseToPHP($time_formula, '$details');
eval('$prodTime=' . $time_eval_formula . ';');
}
$prodTime *= BUILDING_TIME_BASE_FACTOR * $quantity;
$now = time();
$sql = $db->prepare("INSERT INTO " . EVENT_UNIT_TABLE . " (caveID, unitID, quantity, " . "start, end) VALUES (:caveID, :unitID, :quantity, :start, :end)");
$sql->bindValue('caveID', $caveID, PDO::PARAM_INT);
$sql->bindValue('unitID', $unitID, PDO::PARAM_INT);
$sql->bindValue('quantity', $quantity, PDO::PARAM_INT);
$sql->bindValue('start', time_toDatetime($now), PDO::PARAM_STR);
$sql->bindValue('end', time_toDatetime($now + $prodTime), PDO::PARAM_STR);
if (!$sql->execute() || $sql->rowCount() == 0) {
processProductionCostSetBack($GLOBALS['unitTypeList'][$unitID], $caveID, $details, $quantity);
return 2;
}
return 3;
}
示例3: unitAction
function unitAction($caveID, &$meineHoehlen)
{
global $config, $db, $MAX_RESOURCE, $MOVEMENTCOSTCONSTANT, $MOVEMENTSPEEDCONSTANT, $params, $resourceTypeList, $unitTypeList, $FUELRESOURCEID;
// get movements
$ua_movements = Movement::getMovements();
$details = $meineHoehlen[$caveID];
/***************************************************************************/
/** **/
/** CHECK ARTEFACTS **/
/** **/
/***************************************************************************/
// artefact moving: get ID if any
//
// $params->POST->myartefacts will be
// NULL, if it is not set at all
// -1 when choosing no artefact to move
// 0 if there was a real choice
// default: Move No Artefact (this var holds the artefactID to move)
$moveArtefact = 0;
// this array shall contain the artefacts if any
$myartefacts = array();
// does the cave contain an artefact at least?
if ($details['artefacts'] > 0) {
// get artefacts
$myartefacts = artefact_getArtefactsReadyForMovement($caveID);
// was an artefact chosen?
if ((int) $params->POST->myartefacts > 0) {
$tempID = (int) $params->POST->myartefacts;
// now check, whether this artefactID belongs to this cave
foreach ($myartefacts as $key => $value) {
// if found, set it
if ($tempID == $value['artefactID']) {
$moveArtefact = $tempID;
break;
}
}
}
}
// now $moveArtefact should contain 0 for 'move no artefact'
// or the artefactID of the artefact to be moved
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
// put user, its session and nogfx flag into session
$_SESSION['player'] = Player::getPlayer($params->SESSION->player->playerID);
$params->SESSION->player = $_SESSION['player'];
// get Map Size
$size = getMapSize();
$dim_x = ($size['maxX'] - $size['minX'] + 1) / 2;
$dim_y = ($size['maxY'] - $size['minY'] + 1) / 2;
$foodPerCave = eval('return ' . formula_parseToPHP($MOVEMENTCOSTCONSTANT . ';', '$details'));
$minutesPerCave = eval('return ' . formula_parseToPHP($MOVEMENTSPEEDCONSTANT . ';', '$details'));
$minutesPerCave *= MOVEMENT_TIME_BASE_FACTOR / 60;
if (isset($params->POST->moveit) && sizeof($params->POST->unit)) {
$targetXCoord = intval($params->POST->targetXCoord);
$targetYCoord = intval($params->POST->targetYCoord);
$targetCaveName = $params->POST->targetCaveName;
$targetCaveID = intval($params->POST->targetCaveID);
$movementID = intval($params->POST->movementID);
// check for scripters
check_timestamp($params->POST->tstamp);
$validCaveName = FALSE;
// targetCaveID >>> coords
if (isset($targetCaveID) && $targetCaveID > 0) {
$result = getCaveByID(intval($targetCaveID));
if (sizeof($result) != 0) {
$targetXCoord = $result['xCoord'];
$targetYCoord = $result['yCoord'];
$validCaveName = TRUE;
}
// name >>> coords
} else {
if (isset($targetCaveName)) {
$result = getCaveByName($targetCaveName);
if (sizeof($result) != 0) {
$targetXCoord = $result['xCoord'];
$targetYCoord = $result['yCoord'];
$validCaveName = TRUE;
}
}
}
// get target player
$result = getCaveByCoords(intval($targetXCoord), intval($targetYCoord));
if (sizeof($result) != 0) {
$targetPlayer = new Player(getPlayerByID($result['playerID']));
}
// Array von Nullwerten befreien
$unit = array_filter($params->POST->unit, "filterZeros");
$unit = array_map("checkFormValues", $unit);
$resource = array_map("checkFormValues", $params->POST->rohstoff);
// Test, ob Einheitentragekapazität ausgelastet
foreach ($resource as $resKey => $aRes) {
$capacity = 0;
foreach ($unit as $unitKey => $aUnit) {
$capacity += $aUnit * $unitTypeList[$unitKey]->encumbranceList[$resKey];
}
if ($capacity < $aRes) {
$overloaded = 1;
break;
}
//.........这里部分代码省略.........
示例4: wonder_getWonderContent
function wonder_getWonderContent($playerID, $caveID, &$details)
{
global $buildingTypeList, $resourceTypeList, $wonderTypeList, $unitTypeList, $config, $params, $db;
// messages
$messageText = array(-4 => "Die Zielsiedlung steht unter Schutz. Der Zauber kann nicht erwirkt werden.", -3 => "Die angegebene Zielsiedlung wurde nicht gefunden.", -2 => "Der Zauber kann nicht auf die angegbene Zielsiedlung erwirkt " . "werden.", -1 => "Es ist ein Fehler bei der Verarbeitung Ihrer Anfrage aufgetreten. " . "Bitte wenden Sie sich an die Administratoren.", 0 => "Der Zauber kann nicht erwirkt werden. Es fehlen die " . "notwendigen Voraussetzungen.", 1 => "Das Erwirken des Zaubers scheint Erfolg zu haben.", 2 => "Die Götter haben Ihr Flehen nicht erhört! Die " . "eingesetzten Opfergaben sind natürlich dennoch verloren. " . "Mehr Glück beim nächsten Mal!");
// ADDED by chris--- for cavebook -----------------------
if ($params->POST->targetCaveID != -1) {
$targetCave = getCaveByID($params->POST->targetCaveID);
$x = $targetCave[xCoord];
$y = $targetCave[yCoord];
} else {
$x = $params->POST->xCoord;
$y = $params->POST->yCoord;
}
// ------------------------------------------------------
// and changed $params->POST->xCoord to $x etc
if (isset($params->POST->wonderID)) {
$messageID = wonder_processOrder($playerID, $params->POST->wonderID, $caveID, $x, $y, $details, $db);
$reload = 1;
}
if ($reload) {
// this isn't that elegant...
$r = getCaveSecure($caveID, $params->SESSION->user['playerID']);
if ($r->isEmpty()) {
page_dberror();
}
$details = $r->nextRow();
}
$template = @tmpl_open("./templates/" . $config->template_paths[$params->SESSION->user['template']] . "/wonder.ihtml");
// Show a special message
if (isset($messageID)) {
tmpl_set($template, '/MESSAGE/message', $messageText[$messageID]);
}
// ADDED by chris--- for cavebook ---------------------------------
// Getting entries
$cavelist = cavebook_getEntries($params->SESSION->user['playerID']);
// Show the cave table
$cavebook = array();
for ($ix = 0; $ix < sizeof($cavelist[id]); $ix++) {
$cavebook[$ix][cavebook_entry] = $cavelist[name][$ix];
$cavebook[$ix][cavebook_id] = $cavelist[id][$ix];
$cavebook[$ix][cavebook_x] = $cavelist[x][$ix];
$cavebook[$ix][cavebook_y] = $cavelist[y][$ix];
}
// --------------------------------------------------------------
// Show the wonder table
for ($i = 0; $i < sizeof($wonderTypeList); $i++) {
$wonder = $wonderTypeList[$i];
// the current building
$result = rules_checkDependencies($wonder, $details);
if ($result === TRUE) {
tmpl_iterate($template, 'WONDER');
tmpl_set($template, "WONDER/alternate", $count++ % 2 ? "alternate" : "");
tmpl_set($template, 'WONDER', array('name' => $wonder->name, 'wonderID' => $i, 'modus' => WONDER_DETAIL, 'caveID' => $caveID));
// iterate ressourcecosts
foreach ($wonder->resourceProductionCost as $resourceID => $function) {
$cost = ceil(eval('return ' . formula_parseToPHP($function . ';', '$details')));
if ($cost) {
tmpl_iterate($template, "WONDER/RESSOURCECOST");
if ($details[$resourceTypeList[$resourceID]->dbFieldName] >= $cost) {
tmpl_set($template, "WONDER/RESSOURCECOST/ENOUGH/value", $cost);
} else {
tmpl_set($template, "WONDER/RESSOURCECOST/LESS/value", $cost);
}
tmpl_set($template, "WONDER/RESSOURCECOST/dbFieldName", $resourceTypeList[$resourceID]->dbFieldName);
tmpl_set($template, "WONDER/RESSOURCECOST/name", $resourceTypeList[$resourceID]->name);
}
}
// iterate unitcosts
foreach ($wonder->unitProductionCost as $unitID => $function) {
$cost = ceil(eval('return ' . formula_parseToPHP($function . ';', '$details')));
if ($cost) {
tmpl_iterate($template, "WONDER/UNITCOST");
if ($details[$unitTypeList[$unitID]->dbFieldName] >= $cost) {
tmpl_set($template, "WONDER/UNITCOST/ENOUGH/value", $cost);
} else {
tmpl_set($template, "WONDER/UNITCOST/LESS/value", $cost);
}
tmpl_set($template, "WONDER/UNITCOST/name", $unitTypeList[$unitID]->name);
}
}
// show the wonder link
tmpl_set($template, 'WONDER/BUILD_LINK', array('action' => WONDER, 'wonderID' => $wonder->wonderID, 'cave_book_link' => CAVE_BOOK, 'BOOKENTRY' => $cavebook, 'caveID' => $caveID));
} else {
if ($params->SESSION->user['show_unqualified'] && $result !== FALSE && !$wonder->nodocumentation) {
tmpl_iterate($template, '/UNQUALIFIEDWONDERS/WONDER');
tmpl_set($template, '/UNQUALIFIEDWONDERS/WONDER', array('alternate' => $count_unqualified++ % 2 ? "" : "alternate", 'modus' => WONDER_DETAIL, 'wonderID' => $i, 'caveID' => $caveID, 'name' => $wonder->name, 'dependencies' => $result));
}
}
}
return tmpl_parse($template);
}
示例5: unit_getUnitDetails
function unit_getUnitDetails($unitID, $caveData, $method)
{
global $template;
global $buildingTypeList, $defenseSystemTypeList, $resourceTypeList, $scienceTypeList, $unitTypeList;
$details = $caveData;
// first check whether that unit should be displayed...
$unit = $unitTypeList[$unitID];
if (!$unit || $unit->nodocumentation && !$caveData[$unit->dbFieldName] && rules_checkDependencies($unit, $caveData) !== TRUE) {
$unit = current($unitTypeList);
}
// open template
if ($method == 'ajax') {
$shortVersion = true;
$template->setFile('unitDetailAjax.tmpl');
} else {
$shortVersion = false;
$template->setFile('unitDetail.tmpl');
$template->setShowRresource(false);
}
// iterate ressourcecosts
$resourceCost = array();
foreach ($unit->resourceProductionCost as $resourceID => $function) {
$cost = ceil(eval('return ' . formula_parseToPHP($function . ';', '$caveData')));
if ($cost) {
array_push($resourceCost, array('name' => $GLOBALS['resourceTypeList'][$resourceID]->name, 'dbFieldName' => $GLOBALS['resourceTypeList'][$resourceID]->dbFieldName, 'value' => $cost));
}
}
// iterate unitcosts
$unitCost = array();
foreach ($unit->unitProductionCost as $unitID => $function) {
$cost = ceil(eval('return ' . formula_parseToPHP($function . ';', '$caveData')));
if ($cost) {
array_push($unitCost, array('name' => $GLOBALS['unitTypeList'][$unitID]->name, 'dbFieldName' => $GLOBALS['unitTypeList'][$unitID]->dbFieldName, 'value' => $cost));
}
}
// iterate buildingCost
$buildingCost = array();
foreach ($unit->buildingProductionCost as $buildingID => $function) {
$cost = ceil(eval('return ' . formula_parseToPHP($function . ';', '$caveData')));
if ($cost) {
array_push($buildingCost, array('name' => $GLOBALS['buildingTypeList'][$buildingID]->name, 'dbFieldName' => $GLOBALS['buildingTypeList'][$buildingID]->dbFieldName, 'value' => $cost));
}
}
// iterate defenseCost
$defenseCost = array();
foreach ($unit->defenseProductionCost as $defenseID => $function) {
$cost = ceil(eval('return ' . formula_parseToPHP($function . ';', '$caveData')));
if ($cost) {
array_push($defenseCost, array('name' => $GLOBALS['defenseSystemTypeList'][$defenseID]->name, 'dbFieldName' => $GLOBALS['defenseSystemTypeList'][$defenseID]->dbFieldName, 'value' => $cost));
}
}
$dependencies = array();
$buildingdep = array();
$defensesystemdep = array();
$resourcedep = array();
$sciencedep = array();
$unitdep = array();
foreach ($unit->buildingDepList as $key => $level) {
if ($level) {
array_push($buildingdep, array('name' => $GLOBALS['buildingTypeList'][$key]->name, 'level' => ">= " . $level));
}
}
foreach ($unit->defenseSystemDepList as $key => $level) {
if ($level) {
array_push($defensesystemdep, array('name' => $GLOBALS['defenseSystemTypeList'][$key]->name, 'level' => ">= " . $level));
}
}
foreach ($unit->resourceDepList as $key => $level) {
if ($level) {
array_push($resourcedep, array('name' => $GLOBALS['resourceTypeList'][$key]->name, 'level' => ">= " . $level));
}
}
foreach ($unit->scienceDepList as $key => $level) {
if ($level) {
array_push($sciencedep, array('name' => $GLOBALS['scienceTypeList'][$key]->name, 'level' => ">= " . $level));
}
}
foreach ($unit->unitDepList as $key => $level) {
if ($level) {
array_push($unitdep, array('name' => $GLOBALS['unitTypeList'][$key]->name, 'level' => ">= " . $level));
}
}
foreach ($unit->maxBuildingDepList as $key => $level) {
if ($level != -1) {
array_push($buildingdep, array('name' => $GLOBALS['buildingTypeList'][$key]->name, 'level' => "<= " . $level));
}
}
foreach ($unit->maxDefenseSystemDepList as $key => $level) {
if ($level != -1) {
array_push($defensesystemdep, array('name' => $GLOBALS['defenseSystemTypeList'][$key]->name, 'level' => "<= " . $level));
}
}
foreach ($unit->maxResourceDepList as $key => $level) {
if ($level != -1) {
array_push($resourcedep, array('name' => $GLOBALS['resourceTypeList'][$key]->name, 'level' => "<= " . $level));
}
}
foreach ($unit->maxScienceDepList as $key => $level) {
if ($level != -1) {
array_push($sciencedep, array('name' => $GLOBALS['scienceTypeList'][$key]->name, 'level' => "<= " . $level));
//.........这里部分代码省略.........
示例6: improvement_getImprovementDetail
function improvement_getImprovementDetail($caveID, &$details)
{
global $template;
// open template
$template->setFile('improvementBuilder.tmpl');
// messages
$messageText = array(0 => array('type' => 'success', 'message' => _('Der Arbeitsauftrag wurde erfolgreich gestoppt.')), 1 => array('type' => 'error', 'message' => _('Es konnte kein Arbeitsauftrag gestoppt werden.')), 2 => array('type' => 'error', 'message' => _('Der Auftrag konnte nicht erteilt werden. Es fehlen die notwendigen Voraussetzungen.')), 3 => array('type' => 'success', 'message' => _('Der Arbeitsauftrag wurde erfolgreich erteilt.')), 5 => array('type' => 'success', 'message' => _('Das Gebäude wurde erfolgreich abgerissen.')), 6 => array('type' => 'error', 'message' => _('Das Gebäude konnte nicht abgerissen werden.')), 7 => array('type' => 'error', 'message' => _('Sie haben von der Sorte gar keine Gebäude.')), 8 => array('type' => 'error', 'message' => sprintf(_('Sie können derzeit kein Gebäude oder Verteidigungen abreißen, weil erst vor Kurzem etwas in dieser Höhle abgerissen wurde. Generell muss zwischen zwei Abrissen eine Zeitspanne von %d Minuten liegen.'), TORE_DOWN_TIMEOUT)), 9 => array('type' => 'error', 'message' => _('Der Arbeitsauftrag konnte nicht erteilt werden. Ein Arbeitsauftrag ist schon im Gange.')));
// get this cave's queue
$queue = improvement_getQueue($_SESSION['player']->playerID, $caveID);
$action = Request::getVar('action', '');
switch ($action) {
/****************************************************************************************************
*
* Erweiterung bauen
*
****************************************************************************************************/
case 'build':
$buildingID = Request::getVar('buildingID', -1);
if ($buildingID == -1) {
$messageID = 2;
break;
}
// check queue exist
if (sizeof($queue)) {
$messageID = 9;
break;
}
$messageID = improvement_processOrder($buildingID, $caveID, $details);
$details = getCaveSecure($caveID, $_SESSION['player']->playerID);
$queue = improvement_getQueue($_SESSION['player']->playerID, $caveID);
break;
/****************************************************************************************************
*
* Ausbau der Erweiterung abbrechen
*
****************************************************************************************************/
/****************************************************************************************************
*
* Ausbau der Erweiterung abbrechen
*
****************************************************************************************************/
case 'cancelOrder':
$eventID = Request::getVar('id', 0);
if ($eventID == 0) {
$messageID = 1;
break;
}
// check queue exist
if (!sizeof($queue) || $queue['event_expansionID'] != $eventID) {
$messageID = 1;
break;
}
if (Request::isPost('cancelOrderConfirm')) {
$messageID = improvement_cancelOrder($eventID, $caveID);
if ($messageID == 0) {
$queue = null;
}
} else {
$template->addVars(array('cancelOrder_box' => true, 'confirm_action' => 'cancelOrder', 'confirm_id' => $eventID, 'confirm_mode' => IMPROVEMENT_BUILDER, 'confirm_msg' => sprintf(_('Möchtest du den Arbeitsauftrag von <span class="bold">%s</span> abbrechen?'), $GLOBALS['buildingTypeList'][$queue['expansionID']]->name)));
}
break;
/****************************************************************************************************
*
* Erweiterung abreißen
*
****************************************************************************************************/
/****************************************************************************************************
*
* Erweiterung abreißen
*
****************************************************************************************************/
case 'demolishing':
$improvementID = Request::getVar('id', -1);
if ($improvementID == -1) {
$messageID = 4;
break;
}
if (!isset($GLOBALS['buildingTypeList'][$improvementID])) {
$messageID = 4;
break;
}
if (Request::isPost('cancelOrderConfirm')) {
$messageID = improvement_Demolishing($improvementID, $caveID, $details);
$details = getCaveSecure($caveID, $_SESSION['player']->playerID);
} else {
$template->addVars(array('cancelOrder_box' => true, 'confirm_action' => 'demolishing', 'confirm_id' => $improvementID, 'confirm_mode' => IMPROVEMENT_BUILDER, 'confirm_msg' => sprintf(_('Möchtest du <span class="bold">%s</span> einmal abreißen?'), $GLOBALS['buildingTypeList'][$improvementID]->name)));
}
break;
}
$improvement = $improvementRelict = $improvementUnqualified = array();
foreach ($GLOBALS['buildingTypeList'] as $id => $building) {
$maxLevel = round(eval('return ' . formula_parseToPHP("{$building->maxLevel};", '$details')));
$notenough = FALSE;
$result = rules_checkDependencies($building, $details);
/****************************************************************************************************
*
* Erweiterungen die gebaut werden können.
*
****************************************************************************************************/
if ($result === TRUE) {
//.........这里部分代码省略.........
示例7: science_getScienceDetail
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));
//.........这里部分代码省略.........
示例8: parseCost
function parseCost($building, &$details)
{
$ret = array();
$notenough = false;
if (isset($building->resourceProductionCost)) {
foreach ($building->resourceProductionCost as $resourceID => $function) {
$cost = ceil(eval('return ' . formula_parseToPHP($function . ';', '$details')));
if ($cost) {
$ret['resource_cost'][] = array('dbFieldName' => $GLOBALS['resourceTypeList'][$resourceID]->dbFieldName, 'name' => $GLOBALS['resourceTypeList'][$resourceID]->name, 'value' => $cost, 'enough' => $details[$GLOBALS['resourceTypeList'][$resourceID]->dbFieldName] >= $cost ? true : false, 'missing' => $cost - $details[$GLOBALS['resourceTypeList'][$resourceID]->dbFieldName]);
if ($details[$GLOBALS['resourceTypeList'][$resourceID]->dbFieldName] < $cost) {
$notenough = true;
}
}
}
}
if (isset($building->unitProductionCost)) {
foreach ($building->unitProductionCost as $unitID => $function) {
$cost = ceil(eval('return ' . formula_parseToPHP($function . ';', '$details')));
if ($cost) {
$ret['unit_cost'][] = array('dbFieldName' => $GLOBALS['unitTypeList'][$unitID]->dbFieldName, 'name' => $GLOBALS['unitTypeList'][$unitID]->name, 'value' => $cost, 'enough' => $details[$GLOBALS['unitTypeList'][$unitID]->dbFieldName] >= $cost ? true : false, 'missing' => $cost - $details[$GLOBALS['unitTypeList'][$unitID]->dbFieldName]);
if ($details[$GLOBALS['unitTypeList'][$unitID]->dbFieldName] < $cost) {
$notenough = true;
}
}
}
}
if (isset($building->buildingProductionCost)) {
foreach ($building->buildingProductionCost as $buildingID => $function) {
$cost = ceil(eval('return ' . formula_parseToPHP($function . ';', '$details')));
if ($cost) {
$ret['building_cost'][] = array('dbFieldName' => $GLOBALS['buildingTypeList'][$buildingID]->dbFieldName, 'name' => $GLOBALS['buildingTypeList'][$buildingID]->name, 'value' => $cost, 'enough' => $details[$GLOBALS['buildingTypeList'][$buildingID]->dbFieldName] >= $cost ? true : false, 'missing' => $cost - $details[$GLOBALS['buildingTypeList'][$buildingID]->dbFieldName]);
if ($details[$GLOBALS['buildingTypeList'][$buildingID]->dbFieldName] < $cost) {
$notenough = true;
}
}
}
}
if (isset($building->defenseProductionCost)) {
foreach ($building->defenseProductionCost as $defenseID => $function) {
$cost = ceil(eval('return ' . formula_parseToPHP($function . ';', '$details')));
if ($cost) {
$ret['defense_cost'][] = array('dbFieldName' => $GLOBALS['defenseSystemTypeList'][$defenseID]->dbFieldName, 'name' => $GLOBALS['defenseSystemTypeList'][$defenseID]->name, 'value' => $cost, 'enough' => $details[$GLOBALS['defenseSystemTypeList'][$defenseID]->dbFieldName] >= $cost ? true : false, 'missing' => $cost - $details[$GLOBALS['defenseSystemTypeList'][$defenseID]->dbFieldName]);
if ($details[$GLOBALS['defenseSystemTypeList'][$defenseID]->dbFieldName] < $cost) {
$notenough = true;
}
}
}
}
$ret['notenough'] = $notenough;
return $ret;
}
示例9: improvement_getBuildingDetails
function improvement_getBuildingDetails($buildingID, $caveData, $method)
{
global $template;
// first check whether that building should be displayed...
$building = $GLOBALS['buildingTypeList'][$buildingID];
$maxLevel = round(eval('return ' . formula_parseToPHP("{$building->maxLevel};", '$caveData')));
$maxLevel = $maxLevel < 0 ? 0 : $maxLevel;
$maxReadable = formula_parseToReadable($building->maxLevel);
if (!$building || $building->nodocumentation && !$caveData[$building->dbFieldName] && rules_checkDependencies($building, $caveData) !== TRUE) {
$building = current($GLOBALS['buildingTypeList']);
}
// open template
if ($method == 'ajax') {
$shortVersion = true;
$template->setFile('improvementDetailAjax.tmpl');
} else {
$shortVersion = false;
$template->setFile('improvementDetail.tmpl');
$template->setShowRresource(false);
}
$currentlevel = $caveData[$building->dbFieldName];
$levels = $costTimeLvl = array();
for ($level = $caveData[$building->dbFieldName], $count = 0; $level < $maxLevel && $count < ($shortVersion ? 3 : 10); ++$count, ++$level, ++$caveData[$building->dbFieldName]) {
$duration = time_formatDuration(eval('return ' . formula_parseToPHP($GLOBALS['buildingTypeList'][$buildingID]->productionTimeFunction . ";", '$caveData')) * BUILDING_TIME_BASE_FACTOR);
// iterate ressourcecosts
$resourceCost = array();
foreach ($building->resourceProductionCost as $resourceID => $function) {
$cost = ceil(eval('return ' . formula_parseToPHP($function . ';', '$caveData')));
if ($cost) {
array_push($resourceCost, array('name' => $GLOBALS['resourceTypeList'][$resourceID]->name, 'dbFieldName' => $GLOBALS['resourceTypeList'][$resourceID]->dbFieldName, 'value' => $cost));
}
}
// iterate unitcosts
$unitCost = array();
foreach ($building->unitProductionCost as $unitID => $function) {
$cost = ceil(eval('return ' . formula_parseToPHP($function . ';', '$caveData')));
if ($cost) {
array_push($unitCost, array('name' => $GLOBALS['unitTypeList'][$unitID]->name, 'dbFieldName' => $GLOBALS['unitTypeList'][$unitID]->dbFieldName, 'value' => $cost));
}
}
// iterate buildingCost
$buildingCost = array();
foreach ($building->buildingProductionCost as $buildingID => $function) {
$cost = ceil(eval('return ' . formula_parseToPHP($function . ';', '$caveData')));
if ($cost) {
array_push($buildingCost, array('name' => $GLOBALS['buildingTypeList'][$buildingID]->name, 'dbFieldName' => $GLOBALS['buildingTypeList'][$buildingID]->dbFieldName, 'value' => $cost));
}
}
// iterate defenseCost
$defenseCost = array();
foreach ($building->defenseProductionCost as $defenseID => $function) {
$cost = ceil(eval('return ' . formula_parseToPHP($function . ';', '$caveData')));
if ($cost) {
array_push($defenseCost, array('name' => $GLOBALS['defenseSystemTypeList'][$defenseID]->name, 'dbFieldName' => $GLOBALS['defenseSystemTypeList'][$defenseID]->dbFieldName, 'value' => $cost));
}
}
$levels[$count] = array('level' => $level + 1, 'time' => $duration, 'resource_cost' => $resourceCost, 'unit_cost' => $unitCost, 'building_cost' => $buildingCost, 'defense_cost' => $defenseCost);
}
if (sizeof($levels)) {
$costTimeLvl = array('population' => $caveData['population'], 'item' => $levels);
}
$dependencies = array();
$buildingdep = array();
$defensesystemdep = array();
$resourcedep = array();
$sciencedep = array();
$unitdep = array();
foreach ($building->buildingDepList as $key => $level) {
if ($level) {
array_push($buildingdep, array('name' => $GLOBALS['buildingTypeList'][$key]->name, 'level' => ">= " . $level));
}
}
foreach ($building->defenseSystemDepList as $key => $level) {
if ($level) {
array_push($defensesystemdep, array('name' => $GLOBALS['defenseSystemTypeList'][$key]->name, 'level' => ">= " . $level));
}
}
foreach ($building->resourceDepList as $key => $level) {
if ($level) {
array_push($resourcedep, array('name' => $GLOBALS['resourceTypeList'][$key]->name, 'level' => ">= " . $level));
}
}
foreach ($building->scienceDepList as $key => $level) {
if ($level) {
array_push($sciencedep, array('name' => $GLOBALS['scienceTypeList'][$key]->name, 'level' => ">= " . $level));
}
}
foreach ($building->unitDepList as $key => $level) {
if ($level) {
array_push($unitdep, array('name' => $GLOBALS['unitTypeList'][$key]->name, 'level' => ">= " . $level));
}
}
foreach ($building->maxBuildingDepList as $key => $level) {
if ($level != -1) {
array_push($buildingdep, array('name' => $GLOBALS['buildingTypeList'][$key]->name, 'level' => "<= " . $level));
}
}
foreach ($building->maxDefenseSystemDepList as $key => $level) {
if ($level != -1) {
array_push($defensesystemdep, array('name' => $GLOBALS['defenseSystemTypeList'][$key]->name, 'level' => "<= " . $level));
//.........这里部分代码省略.........
示例10: getAllCavesDetailsContent
function getAllCavesDetailsContent($ownCaves)
{
global $db, $template;
// open template
$template->setFile('cavesDetail.tmpl');
$mycaves = array();
foreach ($ownCaves as $caveID => $caveDetails) {
$mycaves[] = array('cave_name_url' => urlencode($caveDetails['name']), 'cave_name' => $caveDetails['name'], 'cave_id' => $caveID, 'cave_x' => $caveDetails['xCoord'], 'cave_y' => $caveDetails['yCoord']);
}
$template->addVar('caves', $mycaves);
$template->addVar('cave_count', count($mycaves));
$sum = $alt = 0;
$myres = array();
foreach ($GLOBALS['resourceTypeList'] as $resource) {
$temp = array('name' => $resource->name, 'dbFieldName' => $resource->dbFieldName, 'cave' => array());
$row_sum = $row_sum_delta = $row_sum_max = 0;
foreach ($ownCaves as $caveID => $caveDetails) {
$amount = $caveDetails[$resource->dbFieldName];
$delta = $caveDetails[$resource->dbFieldName . '_delta'];
$max = round(eval('return ' . formula_parseToPHP("{$resource->maxLevel};", '$caveDetails')));
$row_sum += $amount;
$row_sum_delta += $delta;
$row_sum_max += $max;
if ($delta >= 0) {
$delta = "+" . $delta;
}
$temp['cave'][] = array('amount' => $amount, 'delta' => $delta);
}
if (!$row_sum) {
continue;
}
$alt++;
$sum += $row_sum;
$temp['sum'] = $row_sum;
if ($row_sum_delta >= 0) {
$row_sum_delta = "+" . $row_sum_delta;
}
$temp['sum_delta'] = $row_sum_delta;
$temp['sum_max'] = $row_sum_max;
$myres[] = $temp;
}
if ($sum > 0) {
$template->addVar('resource', $myres);
}
$sum = $alt = 0;
$myunits = array();
foreach ($GLOBALS['unitTypeList'] as $unit) {
$temp = array('name' => $unit->name, 'dbFieldName' => $unit->dbFieldName, 'cave' => array());
$row_sum = 0;
foreach ($ownCaves as $caveID => $caveDetails) {
$amount = $caveDetails[$unit->dbFieldName];
$row_sum += $amount;
$temp['cave'][] = array('amount' => $amount);
}
if (!$row_sum) {
continue;
}
$alt++;
$sum += $row_sum;
$temp['sum'] = $row_sum;
$myunits[] = $temp;
}
if ($sum > 0) {
$template->addVar('unit', $myunits);
}
$sum = $alt = 0;
$mybuildings = array();
foreach ($GLOBALS['buildingTypeList'] as $building) {
$temp = array('name' => $building->name, 'dbFieldName' => $building->dbFieldName, 'CAVE' => array());
$row_sum = 0;
foreach ($ownCaves as $caveID => $caveDetails) {
$amount = $caveDetails[$building->dbFieldName];
$row_sum += $amount;
$temp['cave'][] = array('amount' => $amount);
}
if (!$row_sum) {
continue;
}
$alt++;
$sum += $row_sum;
$temp['sum'] = $row_sum;
$mybuildings[] = $temp;
}
if ($sum > 0) {
$template->addVar('building', $mybuildings);
}
$sum = $alt = 0;
$mydefenses = array();
foreach ($GLOBALS['defenseSystemTypeList'] as $defense) {
$temp = array('name' => $defense->name, 'dbFieldName' => $defense->dbFieldName, 'cave' => array());
$row_sum = 0;
foreach ($ownCaves as $caveID => $caveDetails) {
$amount = $caveDetails[$defense->dbFieldName];
$row_sum += $amount;
$temp['cave'][] = array('amount' => $amount);
}
if (!$row_sum) {
continue;
}
$alt++;
//.........这里部分代码省略.........
示例11: improvement_getImprovementDetail
function improvement_getImprovementDetail($caveID, &$details)
{
global $buildingTypeList, $defenseSystemTypeList, $resourceTypeList, $unitTypeList, $config, $params, $db;
// messages
$messageText = array(0 => "Der Arbeitsauftrag wurde erfolgreich gestoppt.", 1 => "Es konnte kein Arbeitsauftrag gestoppt werden.", 2 => "Der Auftrag konnte nicht erteilt werden. Es fehlen die " . "notwendigen Voraussetzungen.", 3 => "Der Auftrag wurde erteilt", 5 => "Das Gebäude wurde erfolgreich abgerissen", 6 => "Das Gebäude konnte nicht abgerissen werden", 7 => "Sie haben von der Sorte gar keine Gebäude", 8 => "Sie können derzeit kein Gebäude abreissen, weil erst vor Kurzem etwas in dieser Siedlung abgerissen wurde. Generell muss zwischen zwei Abrissen eine Zeitspanne von " . TORE_DOWN_TIMEOUT . " Minuten liegen.");
// proccess a cancel-order request
if (isset($params->POST->eventID)) {
$messageID = improvement_processOrderCancel($params->POST->eventID, $caveID, $db);
}
// proccess a tore down or new order request
if (isset($params->POST->breakDownConfirm)) {
$messageID = improvement_breakDown($params->POST->buildingID, $caveID, $details, $db);
$reload = 1;
} else {
if (isset($params->POST->buildingID)) {
$messageID = improvement_processOrder($params->POST->buildingID, $caveID, $details, $db);
$reload = 1;
}
}
if ($reload) {
// this isn't that elegant...
$r = getCaveSecure($caveID, $params->SESSION->user['playerID']);
if ($r->isEmpty()) {
page_dberror();
}
$details = $r->nextRow();
}
$queue = improvement_getImprovementQueueForCave($params->SESSION->user['playerID'], $caveID);
$template = @tmpl_open("./templates/" . $config->template_paths[$params->SESSION->user['template']] . "/improvement.ihtml");
// Show a special message
if (isset($messageID)) {
tmpl_set($template, '/MESSAGE/message', $messageText[$messageID]);
}
// Show the improvement table
for ($i = 0; $i < sizeof($buildingTypeList); $i++) {
$notenough = FALSE;
$building = $buildingTypeList[$i];
// the current building
$maxLevel = round(eval('return ' . formula_parseToPHP("{$building->maxLevel};", '$details')));
$result = rules_checkDependencies($building, $details);
if ($result === TRUE) {
tmpl_iterate($template, 'IMPROVEMENT');
tmpl_set($template, "IMPROVEMENT/alternate", $count++ % 2 ? "alternate" : "");
tmpl_set($template, 'IMPROVEMENT', array('name' => $building->name, 'dbFieldName' => $building->dbFieldName, 'buildingID' => $i, 'modus' => IMPROVEMENT_BUILDING_DETAIL, 'caveID' => $caveID, 'maxlevel' => $maxLevel, 'size' => "0" + $details[$building->dbFieldName], 'time' => time_formatDuration(eval('return ' . formula_parseToPHP($building->productionTimeFunction . ";", '$details')) * BUILDING_TIME_BASE_FACTOR)));
// iterate ressourcecosts
foreach ($building->resourceProductionCost as $resourceID => $function) {
$cost = ceil(eval('return ' . formula_parseToPHP($function . ';', '$details')));
if ($cost) {
tmpl_iterate($template, "IMPROVEMENT/RESSOURCECOST");
if ($details[$resourceTypeList[$resourceID]->dbFieldName] >= $cost) {
tmpl_set($template, "IMPROVEMENT/RESSOURCECOST/ENOUGH/value", $cost);
} else {
tmpl_set($template, "IMPROVEMENT/RESSOURCECOST/LESS/value", $cost);
$notenough = TRUE;
}
tmpl_set($template, "IMPROVEMENT/RESSOURCECOST/dbFieldName", $resourceTypeList[$resourceID]->dbFieldName);
tmpl_set($template, "IMPROVEMENT/RESSOURCECOST/name", $resourceTypeList[$resourceID]->name);
}
}
// iterate unitcosts
foreach ($building->unitProductionCost as $unitID => $function) {
$cost = ceil(eval('return ' . formula_parseToPHP($function . ';', '$details')));
if ($cost) {
tmpl_iterate($template, "IMPROVEMENT/UNITCOST");
if ($details[$unitTypeList[$unitID]->dbFieldName] >= $cost) {
tmpl_set($template, "IMPROVEMENT/UNITCOST/ENOUGH/value", $cost);
} else {
tmpl_set($template, "IMPROVEMENT/UNITCOST/LESS/value", $cost);
$notenough = TRUE;
}
tmpl_set($template, "IMPROVEMENT/UNITCOST/name", $unitTypeList[$unitID]->name);
}
}
// iterate buildingcosts
/*
foreach ($building->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 buildingcosts
foreach ($building->buildingProductionCost as $buildingID => $function) {
$cost = ceil(eval('return ' . formula_parseToPHP($function . ';', '$details')));
if ($cost) {
tmpl_iterate($template, "IMPROVEMENT/BUILDINGCOST");
if ($details[$buildingTypeList[$buildingID]->dbFieldName] >= $cost) {
tmpl_set($template, "IMPROVEMENT/BUILDINGCOST/ENOUGH/value", $cost);
//.........这里部分代码省略.........
示例12: defense_builder
/**
*
*/
function defense_builder($caveID, &$details)
{
global $template;
// open template
$template->setFile('defenseBuilder.tmpl');
//messages
$messageText = array(0 => array('type' => 'error', 'message' => _('Es konnte kein Arbeitsauftrag gestoppt werden.')), 1 => array('type' => 'success', 'message' => _('Der Arbeitsauftrag wurde erfolgreich gestoppt.')), 2 => array('type' => 'info', 'message' => sprintf(_('Du kannst derzeit kein Gebäude oder Verteidigungen abreissen, weil erst vor Kurzem etwas in dieser Höhle abgerissen wurde. Generell muss zwischen zwei Abrissen eine Zeitspanne von %d Minuten liegen.'), TORE_DOWN_TIMEOUT)), 3 => array('type' => 'error', 'message' => _('Du hast von der Sorte gar keine Gebäude')), 4 => array('type' => 'error', 'message' => _('Das Gebäude konnte nicht abgerissen werden.')), 5 => array('type' => 'success', 'message' => _('Das Gebäude wurde erfolgreich abgerissen.')), 6 => array('type' => 'error', 'message' => _('Der Auftrag konnte nicht erteilt werden. Es fehlen die notwendigen Voraussetzungen.')), 7 => array('type' => 'success', 'message' => _('Der Arbeitsauftrag wurde erteilt.')), 8 => array('type' => 'error', 'message' => _('Der Arbeitsauftrag konnte nicht erteilt werden. Ein Arbeitsauftrag ist schon im Gange.')));
// get this cave's queue
$queue = defense_getQueue($_SESSION['player']->playerID, $caveID);
$action = Request::getVar('action', '');
switch ($action) {
/****************************************************************************************************
*
* Verteidigungsanlage bauen
*
****************************************************************************************************/
case 'build':
$defenseID = Request::getVar('defenseID', -1);
if ($defenseID == -1 || !isset($GLOBALS['defenseSystemTypeList'][$defenseID])) {
$messageID = 6;
break;
}
// check queue exist
if (sizeof($queue)) {
$messageID = 8;
break;
}
$messageID = defense_processOrder($defenseID, $caveID, $details);
$details = getCaveSecure($caveID, $_SESSION['player']->playerID);
$queue = defense_getQueue($_SESSION['player']->playerID, $caveID);
break;
/****************************************************************************************************
*
* Ausbau der Verteidigungsanlage abbrechen
*
****************************************************************************************************/
/****************************************************************************************************
*
* Ausbau der Verteidigungsanlage abbrechen
*
****************************************************************************************************/
case 'cancelOrder':
$eventID = Request::getVar('id', 0);
if ($eventID == 0) {
$messageID = 0;
break;
}
// check queue exist
if (!sizeof($queue) || $queue['event_defenseSystemID'] != $eventID) {
$messageID = 0;
break;
}
if (Request::isPost('postConfirm')) {
$messageID = defense_cancelOrder($eventID, $caveID);
if ($messageID == 1) {
$queue = null;
}
} else {
$template->addVars(array('cancelOrder_box' => true, 'confirm_action' => 'cancelOrder', 'confirm_id' => $eventID, 'confirm_mode' => DEFENSE_BUILDER, 'confirm_msg' => sprintf(_('Möchtest du den Arbeitsauftrag von <span class="bold">%s</span> abbrechen?'), $GLOBALS['defenseSystemTypeList'][$queue['defenseSystemID']]->name)));
}
break;
/****************************************************************************************************
*
* Verteidigungsanlage abreißen
*
****************************************************************************************************/
/****************************************************************************************************
*
* Verteidigungsanlage abreißen
*
****************************************************************************************************/
case 'demolishing':
$defenseID = Request::getVar('id', -1);
if ($defenseID == -1) {
$messageID = 4;
break;
}
if (!isset($GLOBALS['defenseSystemTypeList'][$defenseID])) {
$messageID = 4;
break;
}
if (Request::isPost('postConfirm')) {
$messageID = defense_Demolishing($defenseID, $caveID, $details);
$details = getCaveSecure($caveID, $_SESSION['player']->playerID);
} else {
$template->addVars(array('cancelOrder_box' => true, 'confirm_action' => 'demolishing', 'confirm_id' => $defenseID, 'confirm_mode' => DEFENSE_BUILDER, 'confirm_msg' => sprintf(_('Möchtest du <span class="bold">%s</span> einmal abreißen?'), $GLOBALS['defenseSystemTypeList'][$defenseID]->name)));
}
break;
}
$defenseSystem = $defenseSystemRelict = $defenseSystemUnqualified = array();
foreach ($GLOBALS['defenseSystemTypeList'] as $id => $defense) {
$maxLevel = round(eval('return ' . formula_parseToPHP("{$defense->maxLevel};", '$details')));
$result = rules_checkDependencies($defense, $details);
// if all requirements are met, but the maxLevel is 0, treat it like a non-buildable
if ($maxLevel <= 0 && $result === TRUE) {
$result = !$details[$defense->dbFieldName] ? _('Max. Stufe: 0') : false;
}
//.........这里部分代码省略.........
示例13: science_processOrder
function science_processOrder($scienceID, $caveID, $playerID, $caveData, $db)
{
global $defenseSystemTypeList, $buildingTypeList, $scienceTypeList, $resourceTypeList, $unitTypeList, $config;
$science = $scienceTypeList[$scienceID];
$maxLevel = round(eval('return ' . formula_parseToPHP("{$science->maxLevel};", '$caveData')));
// check, that this science isn't researched in an other cave at the
// same time
$sql = "SELECT event_scienceID FROM Event_science " . "WHERE playerID='{$playerID}' AND scienceID = '{$scienceID}'";
$r = $db->query($sql);
if (!$r) {
page_dberror();
}
if (!$r->isEmpty()) {
return 4;
}
// check for scienceMaxDeps in Event_Handler
$dep_count = 0;
foreach ($science->maxScienceDepList as $key => $value) {
if ($value != -1 && $caveData[$scienceTypeList[$key]->dbFieldName] > $value - 1) {
if ($dep_count) {
$deps .= ",";
}
$deps .= $key;
$dep_count++;
}
}
if ($dep_count) {
$query = "SELECT event_scienceID FROM Event_science " . "WHERE playerID = '{$playerID}' AND scienceID IN ({$deps})";
if (!($r = $db->query($query))) {
page_dberror();
}
if (!$r->isEmpty()) {
return 5;
}
}
$set = array();
$setBack = array();
$where = array("WHERE caveID = '{$caveID}'", "{$science->dbFieldName} < {$maxLevel}");
// get all the resource costs
foreach ($science->resourceProductionCost as $key => $value) {
if ($value != "" && $value != "0") {
$formula = formula_parseToSQL($value);
$dbField = $resourceTypeList[$key]->dbFieldName;
array_push($set, "{$dbField} = {$dbField} - ({$formula})");
array_push($setBack, "{$dbField} = {$dbField} + ({$formula})");
array_push($where, "{$dbField} >= ({$formula})");
}
}
// get all the unit costs
foreach ($science->unitProductionCost as $key => $value) {
if ($value != "" && $value != "0") {
$formula = formula_parseToSQL($value);
$dbField = $unitTypeList[$key]->dbFieldName;
array_push($set, "{$dbField} = {$dbField} - {$formula}");
array_push($setBack, "{$dbField} = {$dbField} + {$formula}");
array_push($where, "{$dbField} >= {$formula}");
}
}
// get all the building costs
foreach ($science->buildingProductionCost as $key => $value) {
if ($value != "" && $value != "0") {
$formula = formula_parseToSQL($value);
$dbField = $buildingTypeList[$key]->dbFieldName;
array_push($set, "{$dbField} = {$dbField} - {$formula}");
array_push($setBack, "{$dbField} = {$dbField} + {$formula}");
array_push($where, "{$dbField} >= {$formula}");
}
}
// get all the external costs
foreach ($science->externalProductionCost as $key => $value) {
if ($value != "" && $value != "0") {
$formula = formula_parseToSQL($value);
$dbField = $defenseSystemTypeList[$key]->dbFieldName;
array_push($set, "{$dbField} = {$dbField} - {$formula}");
array_push($setBack, "{$dbField} = {$dbField} + {$formula}");
array_push($where, "{$dbField} >= {$formula}");
}
}
// generate SQL
if (sizeof($set)) {
$set = implode(", ", $set);
$set = "UPDATE Cave SET {$set} ";
$setBack = implode(", ", $setBack);
$setBack = "UPDATE Cave SET {$setBack} WHERE caveID = '{$caveID}'";
}
// generate dependecies
foreach ($science->buildingDepList as $key => $value) {
if ($value != "" && $value != "0") {
array_push($where, "{$buildingTypeList[$key]->dbFieldName} >= {$value}");
}
}
foreach ($science->maxBuildingDepList as $key => $value) {
if ($value != -1) {
array_push($where, "{$buildingTypeList[$key]->dbFieldName} <= {$value}");
}
}
foreach ($science->defenseSystemDepList as $key => $value) {
if ($value != "" && $value != "0") {
array_push($where, "{$defenseSystemTypeList[$key]->dbFieldName} >= {$value}");
}
//.........这里部分代码省略.........
示例14: questionnaire_getPresent
function questionnaire_getPresent($caveID, &$meineHoehlen, $presentID)
{
global $config, $db, $params, $defenseSystemTypeList, $resourceTypeList, $unitTypeList;
$query = "SELECT * FROM `Questionnaire_presents` WHERE presentID = " . intval($presentID);
if (!($result = $db->query($query))) {
return "Datenbankfehler: " . mysql_error();
}
$row = $result->nextRow(MYSQL_ASSOC);
if (!questionnaire_timeIsRight($row)) {
return ""Dieses Geschenk kann ich euch nicht anbieten, Häuptling!"";
}
// genügend Schnecken?
$myaccount = questionnaire_getCredits($params->SESSION->user['questionCredits']);
$price = questionnaire_getCredits($row['credits']);
/*
if ($myaccount['credits'] < $price['credits'] ||
$myaccount['COPPER']['copper'] < $price['COPPER']['copper'] ||
$myaccount['SILVER']['silver'] < $price['SILVER']['silver'] ||
$myaccount['GOLD']['gold'] < $price['GOLD']['gold'])
return ""Ihr habt nicht die passenden Schnecken, Häuptling!"";
*/
if ($myaccount['credits'] < $price['credits']) {
return ""Ihr habt nicht die passenden Schnecken, Häuptling!"";
}
// Preis abziehen
if (!questionnaire_addCredits(-$row['credits'])) {
return ""Ich bin mit dem Schnecken abzählen durcheinander " . "gekommen, Häuptling! Versucht es noch einmal!"";
}
// Geschenk überreichen
$presents = array();
$caveData = $meineHoehlen[$caveID];
foreach ($defenseSystemTypeList as $external) {
if ($row[$external->dbFieldName] > 0) {
$dbField = $external->dbFieldName;
$maxLevel = round(eval('return ' . formula_parseToPHP("{$external->maxLevel};", '$caveData')));
$presents[] = "{$dbField} = LEAST(GREATEST({$maxLevel}, {$dbField}), {$dbField} + " . $row[$external->dbFieldName] . ")";
}
}
foreach ($resourceTypeList as $resource) {
if ($row[$resource->dbFieldName] > 0) {
$dbField = $resource->dbFieldName;
$maxLevel = round(eval('return ' . formula_parseToPHP("{$resource->maxLevel};", '$caveData')));
$presents[] = "{$dbField} = LEAST({$maxLevel}, {$dbField} + " . $row[$resource->dbFieldName] . ")";
}
}
foreach ($unitTypeList as $unit) {
if ($row[$unit->dbFieldName] > 0) {
$dbField = $unit->dbFieldName;
$presents[] = "{$dbField} = {$dbField} + " . $row[$unit->dbFieldName];
}
}
if (sizeof($presents)) {
// UPDATE Cave
$query = "UPDATE Cave SET " . implode(", ", $presents) . " WHERE caveID = {$caveID} AND playerID = " . $params->SESSION->user['playerID'];
$update_result = $db->query($query);
if (!$update_result) {
return "Datenbankfehler: " . mysql_error();
}
// UPDATE Questionnaire_presents
$query = "UPDATE Questionnaire_presents SET use_count = use_count + 1 " . "WHERE presentID = " . $presentID;
$update_result = $db->query($query);
if (!$update_result) {
return "Datenbankfehler: " . mysql_error();
}
if ($db->affected_rows() != 1) {
return "Probleme beim UPDATE des Geschenks";
}
// Höhle auffrischen
$r = getCaveSecure($caveID, $params->SESSION->user['playerID']);
if ($r->isEmpty()) {
page_dberror();
}
$meineHoehlen[$caveID] = $r->nextRow();
return "Eure Geschenke sind nun in eurer Siedlung!";
}
return "Danke für die Schnecken!";
}
示例15: wonder_processOrder
//.........这里部分代码省略.........
$setBack = implode(", ", $setBack);
$setBack = "UPDATE Cave SET {$setBack} WHERE caveID = '{$caveID}'";
}
// generate dependecies
foreach ($wonderTypeList[$wonderID]->buildingDepList as $key => $value) {
if ($value != "" && $value != "0") {
array_push($where, "{$buildingTypeList[$key]->dbFieldName} >= {$value}");
}
}
foreach ($wonderTypeList[$wonderID]->maxBuildingDepList as $key => $value) {
if ($value != -1) {
array_push($where, "{$wonderTypeList[$key]->dbFieldName} <= {$value}");
}
}
foreach ($wonderTypeList[$wonderID]->defenseSystemDepList as $key => $value) {
if ($value != "" && $value != "0") {
array_push($where, "{$defenseSystemTypeList[$key]->dbFieldName} >= {$value}");
}
}
foreach ($wonderTypeList[$wonderID]->maxDefenseSystemDepList as $key => $value) {
if ($value != -1) {
array_push($where, "{$defenseSystemTypeList[$key]->dbFieldName} <= {$value}");
}
}
foreach ($wonderTypeList[$wonderID]->resourceDepList as $key => $value) {
if ($value != "" && $value != "0") {
array_push($where, "{$resourceTypeList[$key]->dbFieldName} >= {$value}");
}
}
foreach ($wonderTypeList[$wonderID]->maxResourceDepList as $key => $value) {
if ($value != -1) {
array_push($where, "{$resourceTypeList[$key]->dbFieldName} <= {$value}");
}
}
foreach ($wonderTypeList[$wonderID]->scienceDepList as $key => $value) {
if ($value != "" && $value != "0") {
array_push($where, "{$scienceTypeList[$key]->dbFieldName} >= {$value}");
}
}
foreach ($wonderTypeList[$wonderID]->maxScienceDepList as $key => $value) {
if ($value != -1) {
array_push($where, "{$scienceTypeList[$key]->dbFieldName} <= {$value}");
}
}
foreach ($wonderTypeList[$wonderID]->unitDepList as $key => $value) {
if ($value != "" && $value != "0") {
array_push($where, "{$unitTypeList[$key]->dbFieldName} >= {$value}");
}
}
foreach ($wonderTypeList[$wonderID]->maxUnitDepList as $key => $value) {
if ($value != -1) {
array_push($where, "{$unitTypeList[$key]->dbFieldName} <= {$value}");
}
}
$where = implode(" AND ", $where);
if (!$db->query($set . $where) || $db->affected_rows() != 1) {
return 0;
}
// calculate the chance and evaluate into $chance
if ($chance_formula = $wonderTypeList[$wonderID]->chance) {
$chance_eval_formula = formula_parseToPHP($chance_formula, '$caveData');
$chance_eval_formula = "\$chance={$chance_eval_formula};";
eval($chance_eval_formula);
}
// if this wonder is offensive
// calculate the wonder resistance and evaluate into $resistance
// TODO: Wertebereich der Resistenz ist derzeit 0 - 1, also je höher desto resistenter
if ($wonderTypeList[$wonderID]->offensiveness == "offensive") {
$resistance_eval_formula = formula_parseToPHP($WONDERRESISTANCE, '$targetData');
$resistance_eval_formula = "\$resistance={$resistance_eval_formula};";
eval($resistance_eval_formula);
} else {
$resistance = 0.0;
}
// does the wonder fail?
if ((double) rand() / (double) getRandMax() > $chance - $resistance) {
return 2;
// wonder did fail
}
// schedule the wonder's impacts
// create a random factor between -0.3 and +0.3
$delayRandFactor = rand(0, getrandmax()) / getrandmax() * 0.6 - 0.3;
// now calculate the delayDelta depending on the first impact's delay
$delayDelta = $wonderTypeList[$wonderID]->impactList[0]['delay'] * $delayRandFactor;
foreach ($wonderTypeList[$wonderID]->impactList as $impactID => $impact) {
$delay = (int) (($delayDelta + $impact['delay']) * WONDER_TIME_BASE_FACTOR);
$now = time();
$query = sprintf("INSERT INTO Event_wonder (casterID, sourceID, targetID, " . "wonderID, impactID, `start`, `end`) " . "VALUES (%d, %d, %d, %d, %d, '%s', '%s')", $playerID, $caveID, $targetID, $wonderID, $impactID, time_toDatetime($now), time_toDatetime($now + $delay));
if (!$db->query($query)) {
$db->query($setBack);
return -1;
}
}
// create messages
$sourceMessage = "Sie haben auf die Höhle in {$coordX}/{$coordY} ein Wunder " . $wonderTypeList[$wonderID]->name . " erwirkt.";
$targetMessage = "Der Besitzer der Höhle in {$caveData['xCoord']}/{$caveData['yCoord']} " . "hat auf Ihre Höhle in {$coordX}/{$coordY} ein Wunder gewirkt.";
messages_sendSystemMessage($playerID, 9, "Wunder erwirkt auf {$coordX}/{$coordY}", $sourceMessage, $db);
messages_sendSystemMessage($targetData['playerID'], 9, "Wunder!", $targetMessage, $db);
return 1;
}