コード例 #1
0
ファイル: unitbuild.html.php プロジェクト: agatho/uaenhanced
function unit_getUnitDetail($caveID, &$details)
{
    global $buildingTypeList, $defenseSystemTypeList, $resourceTypeList, $unitTypeList, $config, $params, $db, $MAX_RESOURCE;
    // 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", 4 => "Bitte korrekte Anzahl der Einheiten Angeben (1 ... " . MAX_SIMULTAN_BUILDED_UNITS . ")");
    // proccess a cancel-order request
    if (isset($params->POST->eventID)) {
        $messageID = unit_processOrderCancel($params->POST->eventID, $caveID, $db);
    }
    // proccess a new order request
    if (isset($params->POST->unitID)) {
        $messageID = unit_processOrder($params->POST->unitID, intval($params->POST->quantity), $caveID, $db, $details);
        $r = getCaveSecure($caveID, $params->SESSION->user['playerID']);
        if ($r->isEmpty()) {
            page_dberror();
        }
        $details = $r->nextRow();
    }
    $queue = unit_getUnitQueueForCave($params->SESSION->user['playerID'], $caveID);
    $template = @tmpl_open("./templates/" . $config->template_paths[$params->SESSION->user['template']] . "/unitbuild.ihtml");
    // Show a special message
    if (isset($messageID)) {
        tmpl_set($template, '/MESSAGE/message', $messageText[$messageID]);
    }
    // Show the unit table
    for ($i = 0; $i < sizeof($unitTypeList); $i++) {
        $notenough = FALSE;
        $unit = $unitTypeList[$i];
        // the current unit
        $result = rules_checkDependencies($unit, $details);
        if ($result === TRUE) {
            tmpl_iterate($template, '/UNIT');
            tmpl_set($template, "UNIT/alternate", $count++ % 2 ? "alternate" : "");
            tmpl_set($template, 'UNIT', array('name' => $unit->name, 'dbFieldName' => $unit->dbFieldName, 'unitID' => $i, 'modus' => UNIT_PROPERTIES, 'caveID' => $caveID, 'size' => "0" + $details[$unit->dbFieldName], 'time' => time_formatDuration(eval('return ' . formula_parseToPHP($unit->productionTimeFunction . ";", '$details')) * BUILDING_TIME_BASE_FACTOR)));
            // iterate ressourcecosts
            foreach ($unit->resourceProductionCost as $resourceID => $function) {
                $cost = ceil(eval('return ' . formula_parseToPHP($function . ';', '$details')));
                if ($cost) {
                    tmpl_iterate($template, "UNIT/RESSOURCECOST");
                    if ($details[$resourceTypeList[$resourceID]->dbFieldName] >= $cost) {
                        tmpl_set($template, "UNIT/RESSOURCECOST/ENOUGH/value", $cost);
                    } else {
                        tmpl_set($template, "UNIT/RESSOURCECOST/LESS/value", $cost);
                        $notenough = TRUE;
                    }
                    tmpl_set($template, "UNIT/RESSOURCECOST/dbFieldName", $resourceTypeList[$resourceID]->dbFieldName);
                    tmpl_set($template, "UNIT/RESSOURCECOST/name", $resourceTypeList[$resourceID]->name);
                }
            }
            // iterate unitcosts
            foreach ($unit->unitProductionCost as $unitID => $function) {
                $cost = ceil(eval('return ' . formula_parseToPHP($function . ';', '$details')));
                if ($cost) {
                    tmpl_iterate($template, "UNIT/UNITCOST");
                    if ($details[$unitTypeList[$unitID]->dbFieldName] >= $cost) {
                        tmpl_set($template, "UNIT/UNITCOST/ENOUGH/value", $cost);
                    } else {
                        tmpl_set($template, "UNIT/UNITCOST/LESS/value", $cost);
                        $notenough = TRUE;
                    }
                    tmpl_set($template, "UNIT/UNITCOST/name", $unitTypeList[$unitID]->name);
                }
            }
            // iterate buildingcosts
            foreach ($unit->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 ($unit->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 improvement link ?!
            if ($queue) {
                tmpl_set($template, "UNIT/UNIT_LINK_NO/message", "Ausbildung im Gange");
            } else {
                if ($notenough) {
                    tmpl_set($template, "UNIT/UNIT_LINK_NO/message", "");
                } else {
                    $formParams = array(array('name' => 'modus', 'value' => UNIT_BUILDER), array('name' => 'caveID', 'value' => $caveID), array('name' => 'unitID', 'value' => $unit->unitID));
                    tmpl_set($template, "UNIT/UNIT_LINK/PARAMS", $formParams);
                }
            }
        } else {
            if ($params->SESSION->user['show_unqualified'] && $result !== FALSE && !$unit->nodocumentation) {
                tmpl_iterate($template, '/UNQUALIFIEDUNITS/UNIT');
                tmpl_set($template, '/UNQUALIFIEDUNITS/UNIT', array('alternate' => $count_unqualified++ % 2 ? "" : "alternate", 'modus' => UNIT_PROPERTIES, 'unitID' => $i, 'caveID' => $caveID, 'dbFieldName' => $unit->dbFieldName, 'name' => $unit->name, 'dependencies' => $result));
            }
        }
    }
    // Show the building queue
    if ($queue) {
        // display the unit building queue
        $row = $queue->nextRow();
        tmpl_set($template, 'UNIT_QUEUE', array('name' => $unitTypeList[$row[unitID]]->name, 'quantity' => $row['quantity'], 'finish' => date("d.m.Y H:i:s", time_timestampToTime($row[event_end])), 'action' => UNIT_BUILDER, 'eventID' => $row['event_unitID'], 'caveID' => $caveID));
    }
    return tmpl_parse($template);
}
コード例 #2
0
ファイル: unit.html.php プロジェクト: microlefes/Game
function unit_getUnitDetail($caveID, &$details)
{
    global $template;
    // open template
    $template->setFile('unitBuilder.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 Auftrag wurde erteilt')), 4 => array('type' => 'info', 'message' => sprintf(_('Bitte korrekte Anzahl der Einheiten Angeben (1 ... %d)'), MAX_SIMULTAN_BUILDED_UNITS)), 5 => array('type' => 'error', 'message' => _('Der Arbeitsauftrag konnte nicht erteilt werden. Ein Arbeitsauftrag ist schon im Gange.')));
    // get this cave's queue
    $queue = unit_getQueue($_SESSION['player']->playerID, $caveID);
    $action = Request::getVar('action', '');
    switch ($action) {
        /****************************************************************************************************
        *
        * Einheiten bauen
        *
        ****************************************************************************************************/
        case 'build':
            $unitID = Request::getVar('unitID', -1);
            $quantity = Request::getVar('quantity', 0);
            if ($unitID == -1) {
                $messageID = 2;
                break;
            }
            // check queue exist
            if (sizeof($queue)) {
                $messageID = 5;
                break;
            }
            $messageID = unit_processOrder($unitID, $quantity, $caveID, $details);
            $details = getCaveSecure($caveID, $_SESSION['player']->playerID);
            $queue = unit_getQueue($_SESSION['player']->playerID, $caveID);
            break;
            /****************************************************************************************************
            *
            * Ausbau der Einheiten abbrechen
            *
            ****************************************************************************************************/
        /****************************************************************************************************
        *
        * Ausbau der Einheiten abbrechen
        *
        ****************************************************************************************************/
        case 'cancelOrder':
            $eventID = Request::getVar('id', 0);
            if ($eventID == 0) {
                $messageID = 1;
                break;
            }
            // check queue exist
            if (!sizeof($queue) || $queue['event_unitID'] != $eventID) {
                $messageID = 1;
                break;
            }
            if (Request::isPost('postConfirm')) {
                $messageID = unit_cancelOrder($eventID, $caveID);
                if ($messageID == 0) {
                    $queue = null;
                }
            } else {
                $template->addVars(array('cancelOrder_box' => true, 'confirm_action' => 'cancelOrder', 'confirm_id' => $eventID, 'confirm_mode' => UNIT_BUILDER, 'confirm_msg' => sprintf(_('Möchtest du den Arbeitsauftrag von <span class="bold">%s</span> abbrechen?'), $GLOBALS['unitTypeList'][$queue['unitID']]->name)));
            }
            break;
    }
    $units = $unitsUnqualified = array();
    foreach ($GLOBALS['unitTypeList'] as $id => $unit) {
        $result = rules_checkDependencies($unit, $details);
        /****************************************************************************************************
        *
        * Einheiten die gebaut werden können.
        *
        ****************************************************************************************************/
        if ($result === TRUE) {
            $units[$unit->unitCategory]['items'][$unit->unitID] = array('name' => $unit->name, 'dbFieldName' => $unit->dbFieldName, 'unit_id' => $unit->unitID, 'unitCategory' => $unit->unitCategory, 'cave_id' => $caveID, 'time' => time_formatDuration(eval('return ' . formula_parseToPHP($unit->productionTimeFunction . ";", '$details')) * BUILDING_TIME_BASE_FACTOR), 'stock' => "0" + $details[$unit->dbFieldName], 'description' => $unit->description, 'duration_formula' => formula_parseToReadable($unit->productionTimeFunction), 'visible' => $unit->visible, 'range_attack' => $unit->attackRange, 'areal_attack' => $unit->attackAreal, 'attack_rate' => $unit->attackRate, 'rd_Resist' => $unit->rangedDamageResistance, 'defense_rate' => $unit->defenseRate, 'size' => $unit->hitPoints, 'spy_value' => $unit->spyValue, 'spy_chance' => $unit->spyChance, 'spy_quality' => $unit->spyQuality, 'anti_spy_chance' => $unit->antiSpyChance, 'fuel_name' => $GLOBALS['resourceTypeList'][GameConstants::FUEL_RESOURCE_ID]->dbFieldName, 'fuel_factor' => $unit->foodCost, 'way_cost' => $unit->wayCost, 'normal_damage_probabilit' => 100 * (1 - ($unit->heavyDamageProbability + $unit->criticalDamageProbability)), 'heavy_damage_probability' => 100 * $unit->heavyDamageProbability, 'critical_damage_probability' => 100 * $unit->criticalDamageProbability);
            $units[$unit->unitCategory]['items'][$unit->unitID] = array_merge($units[$unit->unitCategory]['items'][$unit->unitID], parseCost($unit, $details));
            // show the building link ?!
            if (sizeof($queue)) {
                $units[$unit->unitCategory]['items'][$unit->unitID]['no_build_msg'] = _('Ausbau im Gange');
            } else {
                if ($units[$unit->unitCategory]['items'][$unit->unitID]['notenough']) {
                    $units[$unit->unitCategory]['items'][$unit->unitID]['no_build_msg'] = _('Zu wenig Rohstoffe');
                } else {
                    $units[$unit->unitCategory]['items'][$unit->unitID]['build_link'] = true;
                }
            }
            /****************************************************************************************************
            *
            * Einheiten die nicht gebaut werden können.
            *
            ****************************************************************************************************/
        } else {
            if ($result !== FALSE && !$unit->nodocumentation) {
                $unitsUnqualified[$unit->unitCategory]['items'][$unit->unitID] = array('name' => $unit->name, 'dbFieldName' => $unit->dbFieldName, 'unit_id' => $unit->unitID, 'unitCategory' => $unit->unitCategory, 'cave_id' => $caveID, 'dependencies' => $result, 'description' => $unit->description, 'duration_formula' => formula_parseToReadable($unit->productionTimeFunction), 'visible' => $unit->visible, 'range_attack' => $unit->attackRange, 'areal_attack' => $unit->attackAreal, 'attack_rate' => $unit->attackRate, 'rd_Resist' => $unit->rangedDamageResistance, 'defense_rate' => $unit->defenseRate, 'size' => $unit->hitPoints, 'spy_value' => $unit->spyValue, 'spy_chance' => $unit->spyChance, 'spy_quality' => $unit->spyQuality, 'anti_spy_chance' => $unit->antiSpyChance, 'fuel_name' => $GLOBALS['resourceTypeList'][GameConstants::FUEL_RESOURCE_ID]->dbFieldName, 'fuel_factor' => $unit->foodCost, 'way_cost' => $unit->wayCost, 'normal_damage_probabilit' => 100 * (1 - ($unit->heavyDamageProbability + $unit->criticalDamageProbability)), 'heavy_damage_probability' => 100 * $unit->heavyDamageProbability, 'critical_damage_probability' => 100 * $unit->criticalDamageProbability);
                $unitsUnqualified[$unit->unitCategory]['items'][$unit->unitID] = array_merge($unitsUnqualified[$unit->unitCategory]['items'][$unit->unitID], parseCost($unit, $details));
            }
        }
    }
    /****************************************************************************************************
    *
    * Namen zu den Kategorien hinzufügen & sortieren
    *
    ****************************************************************************************************/
    $tmpUnits = $tmpUnitsUnqualified = array();
    foreach ($GLOBALS['unitCategoryTypeList'] as $unitsCategory) {
        if (isset($units[$unitsCategory->id])) {
            $tmpUnits[$unitsCategory->sortID] = array('id' => $unitsCategory->id, 'name' => $unitsCategory->name, 'items' => $units[$unitsCategory->id]['items']);
            unset($units[$unitsCategory->id]);
        }
        if (isset($unitsUnqualified[$unitsCategory->id])) {
            $tmpUnitsUnqualified[$unitsCategory->sortID] = array('id' => $unitsCategory->id, 'name' => $unitsCategory->name, 'items' => $unitsUnqualified[$unitsCategory->id]['items']);
            unset($unitsUnqualified[$unitsCategory->id]);
        }
    }
    $units = $tmpUnits;
    $unitsUnqualified = $tmpUnitsUnqualified;
    unset($tmpUnits, $tmpUnitsUnqualified);
    ksort($units);
    ksort($unitsUnqualified);
    /****************************************************************************************************
    *
    * Irgendwas im Ausbau?
    *
    ****************************************************************************************************/
    if (sizeof($queue)) {
        $template->addVars(array('quene_show' => true, 'quene_name' => $GLOBALS['unitTypeList'][$queue['unitID']]->name, 'quene_quantity' => $queue['quantity'], 'quene_finish' => time_formatDatetime($queue['end']), 'quene_modus' => UNIT_BUILDER, 'quene_event_id' => $queue['event_unitID']));
    }
    /****************************************************************************************************
    *
    * Übergeben ans Template
    *
    ****************************************************************************************************/
    $template->addVars(array('cave_id' => $caveID, 'status_msg' => isset($messageID) ? $messageText[$messageID] : '', 'units' => $units, 'units_unqualified' => $unitsUnqualified, 'max_build_units' => MAX_SIMULTAN_BUILDED_UNITS));
}