Beispiel #1
0
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;
}
Beispiel #2
0
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;
}
Beispiel #3
0
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;
            }
        }
        if ($movementID == 2) {
            // move units/resources
            if (strtoupper($targetPlayer->tribe) != strtoupper($params->SESSION->player->tribe)) {
                //may tade in own tribe
                $ownTribe = $params->SESSION->player->tribe;
                $targetTribe = $targetPlayer->tribe;
                $targetIsNonPlayer = $targetPlayer->playerID == 0;
                $ownTribeAtWar = tribe_isAtWar($ownTribe, TRUE, $db);
                $targetTribeAtWar = tribe_isAtWar($targetTribe, TRUE, $db);
                $TribesMayTrade = relation_areAllies($ownTribe, $targetTribe, $db) || relation_areEnemys($ownTribe, $targetTribe, $db) || $targetIsNonPlayer;
                $denymovement_nonenemy = $ownTribeAtWar && !$TribesMayTrade;
                $denymovement_targetwar = $targetTribeAtWar && !$TribesMayTrade;
            }
        }
        if ($params->POST->movementID == 0) {
            $msg = _('Bitte Bewegungsart auswählen!');
        } else {
            if (!sizeof($unit)) {
                $msg = _('Es sind keine Einheiten ausgewählt!');
            } else {
                if (empty($targetXCoord) || empty($targetYCoord) and empty($targetCaveName)) {
                    $msg = _('Es fehlt eine Zielkoordinate oder ein Zielhöhlenname!');
                } else {
                    if (empty($targetXCoord) || empty($targetYCoord) and !empty($targetCaveName) and $validCaveName === FALSE) {
                        $msg = sprintf(_('Es gibt keine Höhle mit dem Namen "%s"!'), $targetCaveName);
                    } else {
                        if ($overloaded) {
                            $msg = _('Deine Krieger können die Menge an Ressourcen nicht tragen!!');
                        } else {
                            if (beginner_isCaveProtectedByCoord($targetXCoord, $targetYCoord, $db)) {
                                $msg = _('Die Zielhöhle steht unter Anfängerschutz.');
                            } else {
                                if (beginner_isCaveProtectedByID($caveID, $db)) {
                                    $msg = _('Ihre Höhle steht unter Anfängerschutz. Sie können den Schutz sofort unter dem Punkt <a href="?modus=cave_detail">Bericht über diese Höhle</a> beenden');
                                } else {
                                    if ($params->POST->movementID == 6 && cave_isCaveSecureByCoord($targetXCoord, $targetYCoord, $db)) {
                                        $msg = _('Sie können diese Höhle nicht übernehmen. Sie ist gegen Übernahmen geschützt.');
                                    } else {
                                        if ($denymovement_nonenemy) {
                                            $msg = _('Sie können im Krieg keine Einheiten zu unbeteiligten Parteien verschieben!');
                                        } else {
                                            if ($denymovement_targetwar) {
                                                $msg = _('Sie können keine Einheiten zu kriegführenden Stämmen verschieben, wenn Sie unbeteiligt sind.');
                                            } else {
                                                // Entfernung x Dauer pro Höhle x größter Geschwindigkeitsfaktor x Bewegungsfaktor
                                                $duration = ceil(getDistanceByCoords($details['xCoord'], $details['yCoord'], $targetXCoord, $targetYCoord) * $minutesPerCave * getMaxSpeedFactor($unit) * $ua_movements[$movementID]->speedfactor);
                                                $distance = ceil(getDistanceByCoords($details['xCoord'], $details['yCoord'], $targetXCoord, $targetYCoord));
                                                $tmpdist = 0;
                                                $i = 0;
                                                if ($distance > 15) {
                                                    $distance = $distance - 15;
                                                    $tmpdist = 15;
                                                    if (floor($distance / 5) < 11) {
                                                        $tmpdist += $distance % 5 * (1 - 0.1 * floor($distance / 5));
                                                    }
                                                    for ($i = 1; $i <= floor($distance / 5) && $i < 11; $i++) {
                                                        $tmpdist += 5 * (1 - 0.1 * ($i - 1));
                                                    }
                                                } else {
                                                    $tmpdist = $distance;
                                                }
                                                // Dauer x Rationen x Größe einer Ration x Bewegungsfaktor
                                                $reqFood = ceil($tmpdist * $minutesPerCave * getMaxSpeedFactor($unit) * $ua_movements[$movementID]->speedfactor * calcRequiredFood($unit) * $foodPerCave * $ua_movements[$movementID]->foodfactor);
                                                if ($details[$resourceTypeList[$FUELRESOURCEID]->dbFieldName] < $reqFood) {
                                                    $msg = _('Nicht genug Nahrung zum Ernähren der Krieger auf ihrem langen Marsch vorhanden!');
                                                } else {
                                                    $msgID = setMovementEvent($caveID, $details, $targetXCoord, $targetYCoord, $unit, $resource, $movementID, $reqFood, $duration, $moveArtefact, $minutesPerCave * $ua_movements[$movementID]->speedfactor);
                                                    switch ($msgID) {
                                                        case 0:
                                                            $msg = sprintf(_('Die Krieger wurden losgeschickt und haben %d Nahrung mitgenommen!'), $reqFood);
                                                            break;
                                                        case 1:
                                                            $msg = _('In diesen Koordinaten liegt keine Höhle!');
                                                            break;
                                                        case 2:
                                                            $msg = _('Für diese Bewegung sind nicht genügend Einheiten/Rohstoffe verfügbar!');
                                                            break;
                                                        case 3:
                                                            $msg = _('Schwerer Fehler: Bitte Admin kontaktieren!');
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } else {
        if (!empty($params->POST->eventID)) {
            $msgID = reverseMovementEvent($caveID, $params->POST->eventID);
            switch ($msgID) {
                case 0:
                    $msg = _('Die Einheiten kehren zurück!');
                    break;
                case 1:
                    $msg = _('Fehler bei der Rückkehr!');
                    break;
            }
        }
    }
    // refresh this cave
    $temp = getCaveSecure($caveID, $params->SESSION->player->playerID);
    $meineHoehlen[$caveID] = $details = $temp->nextRow(MYSQL_ASSOC);
    // make sure that bagged artefacts are not shown again
    if ($moveArtefact != 0) {
        $myartefacts = artefact_getArtefactsReadyForMovement($caveID);
    }
    // //////////////////////////////////////////////////////////////
    // Create the page
    // //////////////////////////////////////////////////////////////
    $template = tmpl_open($params->SESSION->player->getTemplatePath() . 'unitaction.ihtml');
    // messages
    if (isset($msg)) {
        tmpl_set($template, '/MESSAGE/msg', $msg);
    }
    // javascript support
    tmpl_set($template, 'currentX', $details['xCoord']);
    tmpl_set($template, 'currentY', $details['yCoord']);
    tmpl_set($template, 'dim_x', $dim_x);
    tmpl_set($template, 'dim_y', $dim_y);
    tmpl_set($template, 'speed', $minutesPerCave);
    tmpl_set($template, 'fuel_id', $FUELRESOURCEID);
    tmpl_set($template, 'fuel_name', $resourceTypeList[$FUELRESOURCEID]->name);
    tmpl_set($template, 'movementcostconstant', $foodPerCave);
    tmpl_set($template, "resourceTypes", $MAX_RESOURCE);
    tmpl_set($template, "rules_path", RULES_PATH);
    // movements
    $selectable_movements = array();
    foreach ($ua_movements as $value) {
        if ($value->playerMayChoose) {
            $selectable_movements[] = get_object_vars($value);
        }
    }
    tmpl_set($template, 'SELECTACTION', $selectable_movements);
    // resources
    $resources = array();
    for ($res = 0; $res < sizeof($resourceTypeList); $res++) {
        if (!$resourceTypeList[$res]->nodocumentation) {
            $resources[] = array('resourceID' => $resourceTypeList[$res]->resourceID, 'name' => $resourceTypeList[$res]->name, 'currentAmount' => "0" + $details[$resourceTypeList[$res]->dbFieldName], 'dbFieldName' => $resourceTypeList[$res]->dbFieldName);
        }
    }
    tmpl_set($template, 'RESOURCE', $resources);
    tmpl_set($template, 'TOTAL', $resources);
    tmpl_set($template, 'RESOURCE_LUGGAGE', $resources);
    // units table
    $unitprops = array();
    $units = array();
    for ($i = 0; $i < sizeof($unitTypeList); $i++) {
        // if no units of this type, next type
        if (!$details[$unitTypeList[$i]->dbFieldName]) {
            continue;
        }
        $temp = array();
        $encumbrance = array();
        for ($j = 0; $j < count($resourceTypeList); $j++) {
            if (!$resourceTypeList[$j]->nodocumentation) {
                $encumbrance[$j] = array('resourceID' => $j, 'load' => "0" + $unitTypeList[$i]->encumbranceList[$j]);
                $temp[] = "0" + $unitTypeList[$i]->encumbranceList[$j];
            }
        }
        $unitprops[] = array('unitID' => $unitTypeList[$i]->unitID, 'foodCost' => $unitTypeList[$i]->foodCost, 'speedFactor' => $unitTypeList[$i]->wayCost, 'resourceLoad' => implode(",", $temp), 'maxWarriorAnzahl' => $details[$unitTypeList[$i]->dbFieldName]);
        $units[] = array('name' => $unitTypeList[$i]->name, 'modus' => UNIT_PROPERTIES, 'unitID' => $unitTypeList[$i]->unitID, 'foodCost' => $unitTypeList[$i]->foodCost, 'speedFactor' => $unitTypeList[$i]->wayCost, 'maxWarriorAnzahl' => $details[$unitTypeList[$i]->dbFieldName], 'warriorID' => $i, 'ENCUMBRANCE' => $encumbrance);
    }
    tmpl_set($template, 'UNITPROPS', $unitprops);
    tmpl_set($template, 'SELECTWARRIOR', $units);
    // weitergereichte Koordinaten
    if (empty($params->POST->movementID)) {
        tmpl_set($template, 'targetXCoord', $params->POST->targetXCoord);
        tmpl_set($template, 'targetYCoord', $params->POST->targetYCoord);
        tmpl_set($template, 'targetCaveName', $params->POST->targetCaveName);
    }
    // weitere Paramter
    $hidden = array(array('name' => 'modus', 'value' => UNIT_MOVEMENT), array('name' => 'moveit', 'value' => 'true'), array('name' => 'trigger', 'value' => 'self'), array('name' => 'tstamp', 'value' => "" . time()));
    tmpl_set($template, 'PARAMS', $hidden);
    $movements = digest_getMovements(array($caveID => $details), array(), true);
    //$movements = digest_getMovements($meineHoehlen, array(), true);
    foreach ($movements as $move) {
        if ($move['isOwnMovement']) {
            tmpl_iterate($template, 'MOVEMENT/MOVE');
            tmpl_set($template, 'MOVEMENT/MOVE', $move);
        } else {
            tmpl_iterate($template, 'OPPMOVEMENT/MOVE');
            tmpl_set($template, 'OPPMOVEMENT/MOVE', $move);
        }
    }
    // artefakte
    if (sizeof($myartefacts) != 0) {
        tmpl_set($template, '/ARTEFACTS/ARTEFACT', $myartefacts);
    }
    // Module "CaveBookmarks" Integration
    // FIXME should know whether the module is installed
    if (TRUE) {
        // show CAVEBOOKMARKS context
        tmpl_set($template, '/CAVEBOOKMARKS/iterate', '');
        // get model
        $cb_model = new CaveBookmarks_Model();
        // get bookmarks
        $bookmarks = $cb_model->getCaveBookmarks(true);
        // set bookmarks
        if (sizeof($bookmarks)) {
            tmpl_set($template, '/CAVEBOOKMARKS/CAVEBOOKMARK', $bookmarks);
            tmpl_set($template, '/CAVEBOOKMARKS/CAVEBOOKMARKJS', $bookmarks);
        }
    }
    return tmpl_parse($template);
}
Beispiel #4
0
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&ouml;tter haben Ihr Flehen nicht erh&ouml;rt! Die " . "eingesetzten Opfergaben sind nat&uuml;rlich dennoch verloren. " . "Mehr Gl&uuml;ck beim n&auml;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);
}
Beispiel #5
0
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' => "&gt;= " . $level));
        }
    }
    foreach ($unit->defenseSystemDepList as $key => $level) {
        if ($level) {
            array_push($defensesystemdep, array('name' => $GLOBALS['defenseSystemTypeList'][$key]->name, 'level' => "&gt;= " . $level));
        }
    }
    foreach ($unit->resourceDepList as $key => $level) {
        if ($level) {
            array_push($resourcedep, array('name' => $GLOBALS['resourceTypeList'][$key]->name, 'level' => "&gt;= " . $level));
        }
    }
    foreach ($unit->scienceDepList as $key => $level) {
        if ($level) {
            array_push($sciencedep, array('name' => $GLOBALS['scienceTypeList'][$key]->name, 'level' => "&gt;= " . $level));
        }
    }
    foreach ($unit->unitDepList as $key => $level) {
        if ($level) {
            array_push($unitdep, array('name' => $GLOBALS['unitTypeList'][$key]->name, 'level' => "&gt;= " . $level));
        }
    }
    foreach ($unit->maxBuildingDepList as $key => $level) {
        if ($level != -1) {
            array_push($buildingdep, array('name' => $GLOBALS['buildingTypeList'][$key]->name, 'level' => "&lt;= " . $level));
        }
    }
    foreach ($unit->maxDefenseSystemDepList as $key => $level) {
        if ($level != -1) {
            array_push($defensesystemdep, array('name' => $GLOBALS['defenseSystemTypeList'][$key]->name, 'level' => "&lt;= " . $level));
        }
    }
    foreach ($unit->maxResourceDepList as $key => $level) {
        if ($level != -1) {
            array_push($resourcedep, array('name' => $GLOBALS['resourceTypeList'][$key]->name, 'level' => "&lt;= " . $level));
        }
    }
    foreach ($unit->maxScienceDepList as $key => $level) {
        if ($level != -1) {
            array_push($sciencedep, array('name' => $GLOBALS['scienceTypeList'][$key]->name, 'level' => "&lt;= " . $level));
        }
    }
    if (sizeof($buildingdep)) {
        array_push($dependencies, array('name' => _('Erweiterungen'), 'dep' => $buildingdep));
    }
    if (sizeof($defensesystemdep)) {
        array_push($dependencies, array('name' => _('Verteidigungsanlagen'), 'dep' => $defensesystemdep));
    }
    if (sizeof($resourcedep)) {
        array_push($dependencies, array('name' => _('Rohstoffe'), 'dep' => $resourcedep));
    }
    if (sizeof($sciencedep)) {
        array_push($dependencies, array('name' => _('Forschungen'), 'dep' => $sciencedep));
    }
    if (sizeof($unitdep)) {
        array_push($dependencies, array('name' => _('Einheiten'), 'dep' => $unitdep));
    }
    if ($unit->visible != 1) {
        $template->addVar('INVISIBLE', array('text' => _('unsichtbar')));
    }
    $template->addVars(array('name' => $unit->name, 'dbFieldName' => $unit->dbFieldName, 'description' => $unit->description, 'resouce_cost' => $resourceCost, 'unit_cost' => $unitCost, 'buiding_cost' => $buildingCost, 'defense_cost' => $defenseCost, 'rangeAttack' => $unit->attackRange, 'arealAttack' => $unit->attackAreal, 'attackRate' => $unit->attackRate, 'rd_Resist' => $unit->rangedDamageResistance, 'defenseRate' => $unit->defenseRate, 'size' => $unit->hitPoints, 'spyValue' => $unit->spyValue, 'spyChance' => $unit->spyChance, 'spyQuality' => $unit->spyQuality, 'antiSpyChance' => $unit->antiSpyChance, 'fuelName' => $resourceTypeList[1]->dbFieldName, 'fuelFactor' => $unit->foodCost, 'wayCost' => $unit->wayCost, 'dependencies' => $dependencies, 'duration' => time_formatDuration(eval('return ' . formula_parseToPHP($unit->productionTimeFunction . ";", '$details')) * BUILDING_TIME_BASE_FACTOR), 'rules_path' => RULES_PATH));
}
Beispiel #6
0
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) {
            $improvement[$building->buildingID] = array('name' => $building->name, 'dbFieldName' => $building->dbFieldName, 'building_id' => $building->buildingID, 'cave_id' => $caveID, 'time' => time_formatDuration(eval('return ' . formula_parseToPHP($building->productionTimeFunction . ";", '$details')) * BUILDING_TIME_BASE_FACTOR), 'maxlevel' => $maxLevel, 'currentlevel' => "0" + $details[$building->dbFieldName], 'breakdown_link' => $details[$building->dbFieldName] > 0 ? true : false);
            $improvement[$building->buildingID] = array_merge($improvement[$building->buildingID], parseCost($building, $details));
            // show the building link ?!
            if (sizeof($queue)) {
                $improvement[$building->buildingID]['no_build_msg'] = _('Ausbau im Gange');
            } else {
                if ($improvement[$building->buildingID]['notenough'] && $maxLevel > $details[$building->dbFieldName]) {
                    $improvement[$building->buildingID]['no_build_msg'] = _('Zu wenig Rohstoffe');
                } else {
                    if ($maxLevel > $details[$building->dbFieldName]) {
                        $improvement[$building->buildingID]['build_link'] = true;
                    } else {
                        $improvement[$building->buildingID]['no_build_msg'] = _('Max. Stufe');
                    }
                }
            }
            /****************************************************************************************************
            *
            * Erweiterungen die zwar nicht gebaut werden können aber schon in der Höhle sind (Relikt)
            *
            ****************************************************************************************************/
        } else {
            if ($details[$building->dbFieldName]) {
                $improvementRelict[$building->buildingID] = array('name' => $building->name, 'dbFieldName' => $building->dbFieldName, 'building_id' => $building->buildingID, 'cave_id' => $caveID, 'currentlevel' => "0" + $details[$building->dbFieldName], 'dependencies' => $result !== FALSE ? $result : false);
                /****************************************************************************************************
                *
                * Erweiterungen die nicht gebaut werden können.
                *
                ****************************************************************************************************/
            } else {
                if ($result !== FALSE && !$building->nodocumentation) {
                    $improvementUnqualified[$building->buildingID] = array('name' => $building->name, 'dbFieldName' => $building->dbFieldName, 'building_id' => $building->buildingID, 'cave_id' => $caveID, 'dependencies' => $result);
                }
            }
        }
    }
    /****************************************************************************************************
    *
    * Irgendwas im Ausbau?
    *
    ****************************************************************************************************/
    if (sizeof($queue)) {
        $template->addVars(array('quene_show' => true, 'quene_name' => $GLOBALS['buildingTypeList'][$queue['expansionID']]->name, 'quene_nextlevel' => $details[$GLOBALS['buildingTypeList'][$queue['expansionID']]->dbFieldName] + 1, 'quene_finish' => time_formatDatetime($queue['end']), 'quene_modus' => IMPROVEMENT_BUILDER, 'quene_event_id' => $queue['event_expansionID']));
    }
    /****************************************************************************************************
    *
    * Übergeben ans Template
    *
    ****************************************************************************************************/
    $template->addVars(array('cave_id' => $caveID, 'status_msg' => isset($messageID) ? $messageText[$messageID] : '', 'improvement' => $improvement, 'improvement_unqualified' => $improvementUnqualified, 'improvement_relict' => $improvementRelict));
}
Beispiel #7
0
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);
}
Beispiel #8
0
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;
}
Beispiel #9
0
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' => "&gt;= " . $level));
        }
    }
    foreach ($building->defenseSystemDepList as $key => $level) {
        if ($level) {
            array_push($defensesystemdep, array('name' => $GLOBALS['defenseSystemTypeList'][$key]->name, 'level' => "&gt;= " . $level));
        }
    }
    foreach ($building->resourceDepList as $key => $level) {
        if ($level) {
            array_push($resourcedep, array('name' => $GLOBALS['resourceTypeList'][$key]->name, 'level' => "&gt;= " . $level));
        }
    }
    foreach ($building->scienceDepList as $key => $level) {
        if ($level) {
            array_push($sciencedep, array('name' => $GLOBALS['scienceTypeList'][$key]->name, 'level' => "&gt;= " . $level));
        }
    }
    foreach ($building->unitDepList as $key => $level) {
        if ($level) {
            array_push($unitdep, array('name' => $GLOBALS['unitTypeList'][$key]->name, 'level' => "&gt;= " . $level));
        }
    }
    foreach ($building->maxBuildingDepList as $key => $level) {
        if ($level != -1) {
            array_push($buildingdep, array('name' => $GLOBALS['buildingTypeList'][$key]->name, 'level' => "&lt;= " . $level));
        }
    }
    foreach ($building->maxDefenseSystemDepList as $key => $level) {
        if ($level != -1) {
            array_push($defensesystemdep, array('name' => $GLOBALS['defenseSystemTypeList'][$key]->name, 'level' => "&lt;= " . $level));
        }
    }
    foreach ($building->maxResourceDepList as $key => $level) {
        if ($level != -1) {
            array_push($resourcedep, array('name' => $GLOBALS['resourceTypeList'][$key]->name, 'level' => "&lt;= " . $level));
        }
    }
    foreach ($building->maxScienceDepList as $key => $level) {
        if ($level != -1) {
            array_push($sciencedep, array('name' => $GLOBALS['scienceTypeList'][$key]->name, 'level' => "&lt;= " . $level));
        }
    }
    foreach ($building->maxUnitDepList as $key => $level) {
        if ($level != -1) {
            array_push($unitdep, array('name' => $GLOBALS['unitTypeList'][$key]->name, 'level' => "&lt;= " . $level));
        }
    }
    if (sizeof($buildingdep)) {
        array_push($dependencies, array('name' => _('Erweiterungen'), 'dep' => $buildingdep));
    }
    if (sizeof($defensesystemdep)) {
        array_push($dependencies, array('name' => _('Verteidigungsanlagen'), 'dep' => $defensesystemdep));
    }
    if (sizeof($resourcedep)) {
        array_push($dependencies, array('name' => _('Rohstoffe'), 'dep' => $resourcedep));
    }
    if (sizeof($sciencedep)) {
        array_push($dependencies, array('name' => _('Forschungen'), 'dep' => $sciencedep));
    }
    if (sizeof($unitdep)) {
        array_push($dependencies, array('name' => _('Einheiten'), 'dep' => $unitdep));
    }
    $template->addVars(array('name' => $building->name, 'dbFieldName' => $building->dbFieldName, 'description' => $building->description, 'maxlevel' => $maxLevel, 'maxReadable' => $maxReadable, 'currentlevel' => $currentlevel, 'cost_time_lvl' => $costTimeLvl, 'dependencies' => $dependencies, 'rules_path' => RULES_PATH));
}
Beispiel #10
0
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++;
        $sum += $row_sum;
        $temp['sum'] = $row_sum;
        $mydefenses[] = $temp;
    }
    if ($sum > 0) {
        $template->addVar('defenses', $mydefenses);
    }
}
Beispiel #11
0
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&auml;ude wurde erfolgreich abgerissen", 6 => "Das Geb&auml;ude konnte nicht abgerissen werden", 7 => "Sie haben von der Sorte gar keine Geb&auml;ude", 8 => "Sie k&ouml;nnen derzeit kein Geb&auml;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);
                    } else {
                        tmpl_set($template, "IMPROVEMENT/BUILDINGCOST/LESS/value", $cost);
                        $notenough = TRUE;
                    }
                    tmpl_set($template, "IMPROVEMENT/BUILDINGCOST/name", $buildingTypeList[$buildingID]->name);
                }
            }
            // iterate externalcosts
            foreach ($building->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 break down link
            tmpl_set($template, 'IMPROVEMENT/BREAK_DOWN_LINK', array('action' => IMPROVEMENT_BREAK_DOWN, 'buildingID' => $building->buildingID, 'caveID' => $caveID));
            // show the building link ?!
            if ($queue) {
                tmpl_set($template, 'IMPROVEMENT/BUILD_LINK_NO/message', "Ausbau im Gange");
            } else {
                if ($notenough && $maxLevel > $details[$building->dbFieldName]) {
                    tmpl_set($template, 'IMPROVEMENT/BUILD_LINK_NO/message', "");
                } else {
                    if ($maxLevel > $details[$building->dbFieldName]) {
                        tmpl_set($template, 'IMPROVEMENT/BUILD_LINK', array('action' => IMPROVEMENT_DETAIL, 'buildingID' => $building->buildingID, 'caveID' => $caveID));
                    } else {
                        tmpl_set($template, '/IMPROVEMENT/BUILD_LINK_NO/message', "Max. Stufe");
                    }
                }
            }
        } else {
            if ($details[$building->dbFieldName]) {
                tmpl_iterate($template, '/UNWANTEDIMPROVEMENTS/IMPROVEMENT');
                tmpl_set($template, '/UNWANTEDIMPROVEMENTS/IMPROVEMENT', array('alternate' => $count_unwanted++ % 2 ? "" : "alternate", 'modus' => IMPROVEMENT_BUILDING_DETAIL, 'buildingID' => $i, 'caveID' => $caveID, 'size' => $details[$building->dbFieldName], 'dbFieldName' => $building->dbFieldName, 'name' => $building->name, 'action' => IMPROVEMENT_BREAK_DOWN));
                if ($result !== FALSE) {
                    tmpl_set($template, '/UNWANTEDIMPROVEMENTS/IMPROVEMENT/dependencies', $result);
                }
            } else {
                if ($params->SESSION->user['show_unqualified'] && $result !== FALSE && !$building->nodocumentation) {
                    tmpl_iterate($template, '/UNQUALIFIEDIMPROVEMENTS/IMPROVEMENT');
                    tmpl_set($template, '/UNQUALIFIEDIMPROVEMENTS/IMPROVEMENT', array('alternate' => $count_unqualified++ % 2 ? "" : "alternate", 'modus' => IMPROVEMENT_BUILDING_DETAIL, 'buildingID' => $i, 'caveID' => $caveID, 'dbFieldName' => $building->dbFieldName, 'name' => $building->name, 'dependencies' => $result));
                }
            }
        }
    }
    // Show the building queue
    if ($queue) {
        // display the building queue
        $row = $queue->nextRow();
        tmpl_set($template, 'IMPROVEMENT_QUEUE', array('name' => $buildingTypeList[$row['expansionID']]->name, 'size' => $details[$buildingTypeList[$row['expansionID']]->dbFieldName] + 1, 'finish' => date("d.m.Y H:i:s", time_timestampToTime($row['event_end'])), 'action' => IMPROVEMENT_DETAIL, 'eventID' => $row['event_expansionID'], 'caveID' => $caveID));
    }
    return tmpl_parse($template);
}
Beispiel #12
0
/**
 *
 */
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;
        }
        /****************************************************************************************************
        *
        * Verteidigungsanlage die gebaut werden können.
        *
        ****************************************************************************************************/
        if ($result === TRUE) {
            $defenseSystem[$defense->defenseCategory]['items'][$defense->defenseSystemID] = array('name' => $defense->name, 'dbFieldName' => $defense->dbFieldName, 'defense_id' => $defense->defenseSystemID, 'cave_id' => $caveID, 'time' => time_formatDuration(eval('return ' . formula_parseToPHP($defense->productionTimeFunction . ";", '$details')) * DEFENSESYSTEM_TIME_BASE_FACTOR), 'maxlevel' => $maxLevel, 'currentlevel' => "0" + $details[$defense->dbFieldName], 'antiSpyChance' => $defense->antiSpyChance, 'breakdown_link' => $details[$defense->dbFieldName] > 0 ? true : false);
            $defenseSystem[$defense->defenseCategory]['items'][$defense->defenseSystemID] = array_merge($defenseSystem[$defense->defenseCategory]['items'][$defense->defenseSystemID], parseCost($defense, $details));
            // show the building link ?!
            if (sizeof($queue)) {
                $defenseSystem[$defense->defenseCategory]['items'][$defense->defenseSystemID]['no_build_msg'] = _('Ausbau im Gange');
            } else {
                if ($defenseSystem[$defense->defenseCategory]['items'][$defense->defenseSystemID]['notenough'] && $maxLevel > $details[$defense->dbFieldName]) {
                    $defenseSystem[$defense->defenseCategory]['items'][$defense->defenseSystemID]['no_build_msg'] = _('Zu wenig Rohstoffe');
                } else {
                    if ($maxLevel > $details[$defense->dbFieldName]) {
                        $defenseSystem[$defense->defenseCategory]['items'][$defense->defenseSystemID]['build_link'] = true;
                    } else {
                        $defenseSystem[$defense->defenseCategory]['items'][$defense->defenseSystemID]['no_build_msg'] = _('Max. Stufe');
                    }
                }
            }
            /****************************************************************************************************
            *
            * Verteidigungsanlage die zwar nicht gebaut werden können aber schon in der Höhle sind (Relikt)
            *
            ****************************************************************************************************/
        } else {
            if ($details[$defense->dbFieldName]) {
                $defenseSystemRelict[$defense->defenseCategory]['items'][$defense->defenseSystemID] = array('name' => $defense->name, 'dbFieldName' => $defense->dbFieldName, 'defense_id' => $defense->defenseSystemID, 'cave_id' => $caveID, 'currentlevel' => "0" + $details[$defense->dbFieldName], 'dependencies' => $result !== false ? $result : false);
                /****************************************************************************************************
                *
                * Verteidigungsanlage die nicht gebaut werden können.
                *
                ****************************************************************************************************/
            } else {
                if ($result !== false && !$defense->nodocumentation) {
                    $defenseSystemUnqualified[$defense->defenseCategory]['items'][$defense->defenseSystemID] = array('name' => $defense->name, 'dbFieldName' => $defense->dbFieldName, 'defense_id' => $defense->defenseSystemID, 'cave_id' => $caveID, 'dependencies' => $result, 'antiSpyChance' => $defense->antiSpyChance);
                }
            }
        }
    }
    /****************************************************************************************************
    *
    * Namen zu den Kategorien hinzufügen & sortieren
    *
    ****************************************************************************************************/
    $tmpDefenseSystem = $tmpDefenseSystemRelict = $tmpDefenseSystemUnqualified = array();
    foreach ($GLOBALS['defenseCategoryTypeList'] as $defenseCategory) {
        if (isset($defenseSystem[$defenseCategory->id])) {
            $tmpDefenseSystem[$defenseCategory->sortID] = array('id' => $defenseCategory->id, 'name' => $defenseCategory->name, 'items' => $defenseSystem[$defenseCategory->id]['items']);
            unset($defenseSystem[$defenseCategory->id]);
        }
        if (isset($defenseSystemRelict[$defenseCategory->id])) {
            $tmpDefenseSystemRelict[$defenseCategory->sortID] = array('id' => $defenseCategory->id, 'name' => $defenseCategory->name, 'items' => $defenseSystemRelict[$defenseCategory->id]['items']);
            unset($defenseSystemRelict[$defenseCategory->id]);
        }
        if (isset($defenseSystemUnqualified[$defenseCategory->id])) {
            $tmpDefenseSystemUnqualified[$defenseCategory->sortID] = array('id' => $defenseCategory->id, 'name' => $defenseCategory->name, 'items' => $defenseSystemUnqualified[$defenseCategory->id]['items']);
            unset($defenseSystemUnqualified[$defenseCategory->id]);
        }
    }
    $defenseSystem = $tmpDefenseSystem;
    $defenseSystemRelict = $tmpDefenseSystemRelict;
    $defenseSystemUnqualified = $tmpDefenseSystemUnqualified;
    unset($tmpDefenseSystem, $tmpDefenseSystemRelict, $tmpDefenseSystemUnqualified);
    ksort($defenseSystem);
    ksort($defenseSystemRelict);
    ksort($defenseSystemUnqualified);
    /****************************************************************************************************
    *
    * Irgendwas im Ausbau?
    *
    ****************************************************************************************************/
    if (sizeof($queue)) {
        $template->addVars(array('quene_show' => true, 'quene_name' => $GLOBALS['defenseSystemTypeList'][$queue['defenseSystemID']]->name, 'quene_nextlevel' => $details[$GLOBALS['defenseSystemTypeList'][$queue['defenseSystemID']]->dbFieldName] + 1, 'quene_finish' => time_formatDatetime($queue['end']), 'quene_modus' => DEFENSE_BUILDER, 'quene_event_id' => $queue['event_defenseSystemID']));
    }
    /****************************************************************************************************
    *
    * Übergeben ans Template
    *
    ****************************************************************************************************/
    $template->addVars(array('cave_id' => $caveID, 'status_msg' => isset($messageID) ? $messageText[$messageID] : '', 'defense_system' => $defenseSystem, 'defense_system_unqualified' => $defenseSystemUnqualified, 'defense_system_relict' => $defenseSystemRelict));
}
Beispiel #13
0
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}");
        }
    }
    foreach ($science->maxDefenseSystemDepList as $key => $value) {
        if ($value != -1) {
            array_push($where, "{$defenseSystemTypeList[$key]->dbFieldName} <= {$value}");
        }
    }
    foreach ($science->resourceDepList as $key => $value) {
        if ($value != "" && $value != "0") {
            array_push($where, "{$resourceTypeList[$key]->dbFieldName} >= {$value}");
        }
    }
    foreach ($science->maxResourceDepList as $key => $value) {
        if ($value != -1) {
            array_push($where, "{$resourceTypeList[$key]->dbFieldName} <= {$value}");
        }
    }
    foreach ($science->scienceDepList as $key => $value) {
        if ($value != "" && $value != "0") {
            array_push($where, "{$scienceTypeList[$key]->dbFieldName} >= {$value}");
        }
    }
    foreach ($science->maxScienceDepList as $key => $value) {
        if ($value != -1) {
            array_push($where, "{$scienceTypeList[$key]->dbFieldName} <= {$value}");
        }
    }
    foreach ($science->unitDepList as $key => $value) {
        if ($value != "" && $value != "0") {
            array_push($where, "{$unitTypeList[$key]->dbFieldName} >= {$value}");
        }
    }
    foreach ($science->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 2;
    }
    $prodTime = 0;
    // calculate the production time;
    if ($time_formula = $science->productionTimeFunction) {
        $time_eval_formula = formula_parseToPHP($time_formula, '$caveData');
        $time_eval_formula = "\$prodTime={$time_eval_formula};";
        eval($time_eval_formula);
    }
    $prodTime *= SCIENCE_TIME_BASE_FACTOR;
    $now = time();
    $query = sprintf("INSERT INTO Event_science (caveID, playerID, scienceID, " . "`start`, `end`) VALUES (%d, %d, %d, '%s', '%s')", $caveID, $playerID, $scienceID, time_toDatetime($now), time_toDatetime($now + $prodTime));
    if (!$db->query($query)) {
        $db->query($setBack);
        return 2;
    }
    return 3;
}
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 "&quot;Dieses Geschenk kann ich euch nicht anbieten, H&auml;uptling!&quot;";
    }
    // 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 "&quot;Ihr habt nicht die passenden Schnecken, H&auml;uptling!&quot;";
    */
    if ($myaccount['credits'] < $price['credits']) {
        return "&quot;Ihr habt nicht die passenden Schnecken, H&auml;uptling!&quot;";
    }
    // Preis abziehen
    if (!questionnaire_addCredits(-$row['credits'])) {
        return "&quot;Ich bin mit dem Schnecken abz&auml;hlen durcheinander " . "gekommen, H&auml;uptling! Versucht es noch einmal!&quot;";
    }
    // 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&uuml;r die Schnecken!";
}
Beispiel #15
0
function wonder_processOrder($playerID, $wonderID, $caveID, $coordX, $coordY, $caveData, $db)
{
    global $defenseSystemTypeList, $unitTypeList, $buildingTypeList, $scienceTypeList, $resourceTypeList, $wonderTypeList, $WONDERRESISTANCE;
    if ($wonderTypeList[$wonderID]->target == "same") {
        $targetID = $caveID;
        $query = "SELECT * FROM Cave " . "WHERE caveID = '{$targetID}' ";
        if (!($result = $db->query($query)) || !($targetData = $result->nextRow())) {
            return -3;
        }
        $coordX = $targetData['xCoord'];
        $coordY = $targetData['yCoord'];
    } else {
        // check the target cave
        $query = "SELECT * FROM Cave " . "WHERE xCoord = '{$coordX}' " . "AND yCoord = '{$coordY}'";
        if (!($result = $db->query($query)) || !($targetData = $result->nextRow())) {
            return -3;
        }
        $targetID = $targetData['caveID'];
    }
    // check, if cave allowed
    if ($wonderTypeList[$wonderID]->target == "own") {
        $allowed = $playerID == $targetData['playerID'];
    } else {
        if ($wonderTypeList[$wonderID]->target == "other") {
            $allowed = $playerID != $targetData['playerID'];
        } else {
            // $wonderTypeList[$wonderID]->target == "all"  or == "same"
            $allowed = 1;
        }
    }
    if (!$allowed) {
        return -2;
    }
    $set = array();
    $setBack = array();
    $where = array("WHERE caveID = '{$caveID}' ");
    // get all the resource costs
    foreach ($wonderTypeList[$wonderID]->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 ($wonderTypeList[$wonderID]->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}");
        }
    }
    foreach ($wonderTypeList[$wonderID]->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}");
        }
    }
    // 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 ($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&ouml;hle in {$coordX}/{$coordY} ein Wunder " . $wonderTypeList[$wonderID]->name . " erwirkt.";
    $targetMessage = "Der Besitzer der H&ouml;hle in {$caveData['xCoord']}/{$caveData['yCoord']} " . "hat auf Ihre H&ouml;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;
}
Beispiel #16
0
function defense_showProperties($defenseID, $cave, $method)
{
    global $template;
    // open template
    if ($method == 'ajax') {
        $shortVersion = true;
        $template->setFile('defenseDetailAjax.tmpl');
    } else {
        $shortVersion = false;
        $template->setFile('defenseDetail.tmpl');
    }
    // first check whether that unit should be displayed...
    if (!isset($GLOBALS['defenseSystemTypeList'][$defenseID])) {
        $template->addVar('status_msg', array('type' => 'error', 'message' => _('Die Verteidigung wurde nicht gefunden oder ist derzeit nicht baubar.')));
        return;
    }
    $defense = $GLOBALS['defenseSystemTypeList'][$defenseID];
    $maxLevel = round(eval('return ' . formula_parseToPHP("{$defense->maxLevel};", '$cave')));
    $maxLevel = $maxLevel < 0 ? 0 : $maxLevel;
    $maxReadable = formula_parseToReadable($defense->maxLevel);
    if ($defense->nodocumentation && !$cave[$defense->dbFieldName] && rules_checkDependencies($defense, $cave) !== true) {
        $template->addVar('status_msg', array('type' => 'error', 'message' => _('Die Erweiterung wurde nicht gefunden oder ist derzeit nicht baubar.')));
        return;
    }
    $currentlevel = $cave[$defense->dbFieldName];
    $levels = $costTimeLvl = array();
    for ($level = $cave[$defense->dbFieldName], $count = 0; $level < $maxLevel && $count < ($shortVersion ? 3 : 10); ++$count, ++$level, ++$cave[$defense->dbFieldName]) {
        $duration = time_formatDuration(eval('return ' . formula_parseToPHP($defense->productionTimeFunction . ";", '$cave')) * DEFENSESYSTEM_TIME_BASE_FACTOR);
        // iterate ressourcecosts
        $resourceCost = array();
        foreach ($defense->resourceProductionCost as $resourceID => $function) {
            $cost = ceil(eval('return ' . formula_parseToPHP($function . ';', '$cave')));
            if ($cost) {
                array_push($resourceCost, array('name' => $GLOBALS['resourceTypeList'][$resourceID]->name, 'dbFieldName' => $GLOBALS['resourceTypeList'][$resourceID]->dbFieldName, 'value' => $cost));
            }
        }
        // iterate unitcosts
        $unitCost = array();
        foreach ($defense->unitProductionCost as $unitID => $function) {
            $cost = ceil(eval('return ' . formula_parseToPHP($function . ';', '$cave')));
            if ($cost) {
                array_push($unitCost, array('name' => $GLOBALS['unitTypeList'][$unitID]->name, 'dbFieldName' => $GLOBALS['unitTypeList'][$unitID]->dbFieldName, 'value' => $cost));
            }
        }
        // iterate buildingCost
        $buildingCost = array();
        foreach ($defense->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 ($defense->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));
            }
        }
        if (rules_checkDependencies($defense, $cave) === true) {
            $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' => $cave['population'], 'item' => $levels);
    }
    $dependencies = array();
    $buildingdep = array();
    $defensesystemdep = array();
    $resourcedep = array();
    $sciencedep = array();
    $unitdep = array();
    foreach ($defense->buildingDepList as $key => $level) {
        if ($level) {
            array_push($buildingdep, array('name' => $GLOBALS['buildingTypeList'][$key]->name, 'level' => "&gt;= " . $level));
        }
    }
    foreach ($defense->defenseSystemDepList as $key => $level) {
        if ($level) {
            array_push($defensesystemdep, array('name' => $GLOBALS['defenseSystemTypeList'][$key]->name, 'level' => "&gt;= " . $level));
        }
    }
    foreach ($defense->resourceDepList as $key => $level) {
        if ($level) {
            array_push($resourcedep, array('name' => $GLOBALS['resourceTypeList'][$key]->name, 'level' => "&gt;= " . $level));
        }
    }
    foreach ($defense->scienceDepList as $key => $level) {
        if ($level) {
            array_push($sciencedep, array('name' => $GLOBALS['scienceTypeList'][$key]->name, 'level' => "&gt;= " . $level));
        }
    }
    foreach ($defense->unitDepList as $key => $level) {
        if ($level) {
            array_push($unitdep, array('name' => $GLOBALS['unitTypeList'][$key]->name, 'level' => "&gt;= " . $level));
        }
    }
    foreach ($defense->maxBuildingDepList as $key => $level) {
        if ($level != -1) {
            array_push($buildingdep, array('name' => $GLOBALS['buildingTypeList'][$key]->name, 'level' => "&lt;= " . $level));
        }
    }
    foreach ($defense->maxDefenseSystemDepList as $key => $level) {
        if ($level != -1) {
            array_push($defensesystemdep, array('name' => $GLOBALS['defenseSystemTypeList'][$key]->name, 'level' => "&lt;= " . $level));
        }
    }
    foreach ($defense->maxResourceDepList as $key => $level) {
        if ($level != -1) {
            array_push($resourcedep, array('name' => $GLOBALS['resourceTypeList'][$key]->name, 'level' => "&lt;= " . $level));
        }
    }
    foreach ($defense->maxScienceDepList as $key => $level) {
        if ($level != -1) {
            array_push($sciencedep, array('name' => $GLOBALS['scienceTypeList'][$key]->name, 'level' => "&lt;= " . $level));
        }
    }
    foreach ($defense->maxUnitDepList as $key => $level) {
        if ($level != -1) {
            array_push($unitdep, array('name' => $GLOBALS['unitTypeList'][$key]->name, 'level' => "&lt;= " . $level));
        }
    }
    if (sizeof($buildingdep)) {
        array_push($dependencies, array('name' => _('Erweiterungen'), 'dep' => $buildingdep));
    }
    if (sizeof($defensesystemdep)) {
        array_push($dependencies, array('name' => _('Verteidigungsanlagen'), 'dep' => $defensesystemdep));
    }
    if (sizeof($resourcedep)) {
        array_push($dependencies, array('name' => _('Rohstoffe'), 'dep' => $resourcedep));
    }
    if (sizeof($sciencedep)) {
        array_push($dependencies, array('name' => _('Forschungen'), 'dep' => $sciencedep));
    }
    if (sizeof($unitdep)) {
        array_push($dependencies, array('name' => _('Einheiten'), 'dep' => $unitdep));
    }
    $template->addVars(array('name' => $defense->name, 'dbFieldName' => $defense->dbFieldName, 'description' => $defense->description, 'maxlevel' => $maxLevel, 'maxReadable' => $maxReadable, 'currentlevel' => $currentlevel, 'rangeAttack' => $defense->attackRange, 'attackRate' => $defense->attackRate, 'defenseRate' => $defense->defenseRate, 'size' => $defense->hitPoints, 'antiSpyChance' => $defense->antiSpyChance, 'warPoints' => $defense->warPoints, 'cost_time_lvl' => $costTimeLvl, 'dependencies' => $dependencies, 'rules_path' => RULES_PATH));
}
Beispiel #17
0
function improvement_processOrder($buildingID, $caveID, $caveData)
{
    global $db;
    $sql = $db->prepare("SELECT count(*) as count\n                       FROM " . EVENT_EXPANSION_TABLE . " \n                       WHERE caveID = :caveID");
    $sql->bindValue('caveID', $caveID, PDO::PARAM_INT);
    if (!$sql->execute()) {
        return 2;
    }
    $return = $sql->fetch();
    $sql->closeCursor();
    if ($return['count'] != 0) {
        return 2;
    }
    $building = $GLOBALS['buildingTypeList'][$buildingID];
    // take production costs from cave
    if (!processProductionCost($building, $caveID, $caveData)) {
        return 2;
    }
    $prodTime = 0;
    // calculate the production time;
    if ($time_formula = $building->productionTimeFunction) {
        $time_eval_formula = formula_parseToPHP($time_formula, '$caveData');
        $time_eval_formula = "\$prodTime={$time_eval_formula};";
        eval($time_eval_formula);
    }
    $prodTime *= BUILDING_TIME_BASE_FACTOR;
    $now = time();
    $sql = $db->prepare("INSERT INTO " . EVENT_EXPANSION_TABLE . " \n                      (caveID, expansionID, start, end) \n                      VALUES (:caveID, :expansionID, :start, :end)");
    $sql->bindValue('caveID', $caveID, PDO::PARAM_INT);
    $sql->bindValue('expansionID', $buildingID, 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($building, $caveID, $caveData);
        return 2;
    }
    return 3;
}
Beispiel #18
0
/**
 *
 */
function defense_processOrder($defenseID, $caveID, $cave)
{
    global $db;
    // take production costs from cave
    if (!processProductionCost($GLOBALS['defenseSystemTypeList'][$defenseID], $caveID, $cave)) {
        return 6;
    }
    // calculate the production time;
    $prodTime = 0;
    if ($time_formula = $GLOBALS['defenseSystemTypeList'][$defenseID]->productionTimeFunction) {
        $time_eval_formula = formula_parseToPHP($time_formula, '$cave');
        $time_eval_formula = "\$prodTime = {$time_eval_formula};";
        eval($time_eval_formula);
    }
    $prodTime *= DEFENSESYSTEM_TIME_BASE_FACTOR;
    $now = time();
    $sql = $db->prepare("INSERT INTO " . EVENT_DEFENSE_SYSTEM_TABLE . " \n                         (caveID, defenseSystemID, start, end)\n                       VALUES\n                         (:caveID, :defenseID, :start, :end)");
    $sql->bindValue('caveID', $caveID, PDO::PARAM_INT);
    $sql->bindValue('defenseID', $defenseID, 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) {
        //give production costs back
        processProductionCostSetBack($GLOBALS['defenseSystemTypeList'][$defenseID], $caveID, $cave);
        return 6;
    }
    return 7;
}
Beispiel #19
0
function wonder_processOrder($playerID, $wonderID, $caveID, $coordX, $coordY, $caveData, $db)
{
    global $defenseSystemTypeList, $unitTypeList, $buildingTypeList, $scienceTypeList, $resourceTypeList, $wonderTypeList;
    // ADDED by chris--- for farmschutz: protection_end in sql
    // check the target cave
    $query = "SELECT playerID, caveID, protection_end FROM Cave " . "WHERE xCoord = '{$coordX}' " . "AND yCoord = '{$coordY}'";
    if (!($result = $db->query($query)) || !($targetData = $result->nextRow())) {
        return -3;
    }
    // ADDED by chris--- for farmschutz
    if (date("YmdHis", time()) < $targetData[protection_end]) {
        return -4;
    }
    // ----------------------------------
    $targetID = $targetData[caveID];
    // check, if cave allowed
    if ($wonderTypeList[$wonderID]->target == "same") {
        $allowed = $caveID == $targetID;
    } else {
        if ($wonderTypeList[$wonderID]->target == "own") {
            $allowed = $playerID == $targetData[playerID];
        } else {
            if ($wonderTypeList[$wonderID]->target == "other") {
                $allowed = $playerID != $targetData[playerID];
            } else {
                // $wonderTypeList[$wonderID]->target == "all"
                $allowed = 1;
            }
        }
    }
    if (!$allowed) {
        return -2;
    }
    $set = array();
    $setBack = array();
    $where = array("WHERE caveID = '{$caveID}' ");
    // get all the resource costs
    foreach ($wonderTypeList[$wonderID]->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 ($wonderTypeList[$wonderID]->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}");
        }
    }
    // 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 ($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);
    }
    // does the wonder fail?
    //  if ((double)rand() / (double)getRandMax() > $chance) {
    srand((double) microtime() * 1000000);
    $wond1 = (double) rand();
    $wond2 = (double) getRandMax();
    //echo $wond1." / ".$wond2." = ".$wond1/$wond2." -- ". $chance."<br>";
    if ($wond1 / $wond2 > $chance) {
        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 imact'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);
        $query = "INSERT INTO Event_wonder " . "(casterID, sourceID, targetID, wonderID, impactID, event_start, " . "event_end) " . "VALUES ('{$playerID}', '{$caveID}', '{$targetID}', '{$wonderID}', " . "'{$impactID}', NOW()+0, (NOW() + INTERVAL {$delay} SECOND)+0)";
        if (!$db->query($query)) {
            $db->query($setBack);
            return -1;
        }
    }
    // create messages
    $sourceMessage = "Sie haben auf die Siedlung in {$coordX}/{$coordY} einen Zauber " . $wonderTypeList[$wonderID]->name . " erwirkt.";
    $targetMessage = "Der Besitzer der Siedlung in {$caveData['xCoord']}/{$caveData['yCoord']} " . "hat auf Ihre Siedlung in {$coordX}/{$coordY} einen Zauber gewirkt.";
    messages_sendSystemMessage($playerID, 9, "Zauber erwirkt auf {$coordX}/{$coordY}", $sourceMessage, $db);
    messages_sendSystemMessage($targetData[playerID], 9, "Zauber!", $targetMessage, $db);
    return 1;
}
Beispiel #20
0
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);
}
function science_getScienceDetails($scienceID, $caveData)
{
    global $buildingTypeList, $defenseSystemTypeList, $resourceTypeList, $scienceTypeList, $unitTypeList, $no_resource_flag, $config, $params;
    $no_resource_flag = 1;
    // first check whether that science should be displayed...
    $science = $scienceTypeList[$scienceID];
    $maxLevel = round(eval('return ' . formula_parseToPHP("{$science->maxLevel};", '$caveData')));
    if (!$science || $science->nodocumentation && !$caveData[$science->dbFieldName] && rules_checkDependencies($science, $caveData) !== TRUE) {
        $science = current($scienceTypeList);
    }
    $template = tmpl_open($params->SESSION->player->getTemplatePath() . 'science_detail.ihtml');
    $currentlevel = $caveData[$science->dbFieldName];
    $levels = array();
    for ($level = $caveData[$science->dbFieldName], $count = 0; $level < $maxLevel && $count < 6; ++$count, ++$level, ++$caveData[$science->dbFieldName]) {
        $duration = time_formatDuration(eval('return ' . formula_parseToPHP($scienceTypeList[$scienceID]->productionTimeFunction . ";", '$caveData')) * BUILDING_TIME_BASE_FACTOR);
        // iterate ressourcecosts
        $resourcecost = array();
        foreach ($science->resourceProductionCost as $resourceID => $function) {
            $cost = ceil(eval('return ' . formula_parseToPHP($function . ';', '$caveData')));
            if ($cost) {
                array_push($resourcecost, array('name' => $resourceTypeList[$resourceID]->name, 'dbFieldName' => $resourceTypeList[$resourceID]->dbFieldName, 'value' => $cost));
            }
        }
        // iterate unitcosts
        $unitcost = array();
        foreach ($science->unitProductionCost as $unitID => $function) {
            $cost = ceil(eval('return ' . formula_parseToPHP($function . ';', '$caveData')));
            if ($cost) {
                array_push($unitcost, array('name' => $unitTypeList[$unitID]->name, 'dbFieldName' => $unitTypeList[$unitID]->dbFieldName, 'value' => $cost));
            }
        }
        $buildingCost = array();
        foreach ($science->buildingProductionCost as $key => $value) {
            if ($value != "" && $value != 0) {
                array_push($buildingCost, array('dbFieldName' => $buildingTypeList[$key]->dbFieldName, 'name' => $buildingTypeList[$key]->name, 'value' => ceil(eval('return ' . formula_parseToPHP($science->buildingProductionCost[$key] . ';', '$details')))));
            }
        }
        $externalCost = array();
        foreach ($science->externalProductionCost as $key => $value) {
            if ($value != "" && $value != 0) {
                array_push($externalCost, array('dbFieldName' => $defenseSystemTypeList[$key]->dbFieldName, 'name' => $defenseSystemTypeList[$key]->name, 'value' => ceil(eval('return ' . formula_parseToPHP($science->externalProductionCost[$key] . ';', '$details')))));
            }
        }
        $levels[$count] = array('level' => $level + 1, 'time' => $duration, 'BUILDINGCOST' => $buildingCost, 'EXTERNALCOST' => $externalCost, 'RESOURCECOST' => $resourcecost, 'UNITCOST' => $unitcost);
    }
    if (sizeof($levels)) {
        $levels = array('population' => $caveData['resource_population'], 'LEVEL' => $levels);
    }
    $dependencies = array();
    $buildingdep = array();
    $defensesystemdep = array();
    $resourcedep = array();
    $sciencedep = array();
    $unitdep = array();
    foreach ($science->buildingDepList as $key => $level) {
        if ($level) {
            array_push($buildingdep, array('name' => $buildingTypeList[$key]->name, 'level' => "&gt;= " . $level));
        }
    }
    foreach ($science->defenseSystemDepList as $key => $level) {
        if ($level) {
            array_push($defensesystemdep, array('name' => $defenseSystemTypeList[$key]->name, 'level' => "&gt;= " . $level));
        }
    }
    foreach ($science->resourceDepList as $key => $level) {
        if ($level) {
            array_push($resourcedep, array('name' => $resourceTypeList[$key]->name, 'level' => "&gt;= " . $level));
        }
    }
    foreach ($science->scienceDepList as $key => $level) {
        if ($level) {
            array_push($sciencedep, array('name' => $scienceTypeList[$key]->name, 'level' => "&gt;= " . $level));
        }
    }
    foreach ($science->unitDepList as $key => $level) {
        if ($level) {
            array_push($unitdep, array('name' => $unitTypeList[$key]->name, 'level' => "&gt;= " . $level));
        }
    }
    foreach ($science->maxBuildingDepList as $key => $level) {
        if ($level != -1) {
            array_push($buildingdep, array('name' => $buildingTypeList[$key]->name, 'level' => "&lt;= " . $level));
        }
    }
    foreach ($science->maxDefenseSystemDepList as $key => $level) {
        if ($level != -1) {
            array_push($defensesystemdep, array('name' => $defenseSystemTypeList[$key]->name, 'level' => "&lt;= " . $level));
        }
    }
    foreach ($science->maxResourceDepList as $key => $level) {
        if ($level != -1) {
            array_push($resourcedep, array('name' => $resourceTypeList[$key]->name, 'level' => "&lt;= " . $level));
        }
    }
    foreach ($science->maxScienceDepList as $key => $level) {
        if ($level != -1) {
            array_push($sciencedep, array('name' => $scienceTypeList[$key]->name, 'level' => "&lt;= " . $level));
        }
    }
    foreach ($science->maxUnitDepList as $key => $level) {
        if ($level != -1) {
            array_push($unitdep, array('name' => $unitTypeList[$key]->name, 'level' => "&lt;= " . $level));
        }
    }
    if (sizeof($buildingdep)) {
        array_push($dependencies, array('name' => _('Erweiterungen'), 'DEP' => $buildingdep));
    }
    if (sizeof($defensesystemdep)) {
        array_push($dependencies, array('name' => _('Verteidigungsanlagen'), 'DEP' => $defensesystemdep));
    }
    if (sizeof($resourcedep)) {
        array_push($dependencies, array('name' => _('Rohstoffe'), 'DEP' => $resourcedep));
    }
    if (sizeof($sciencedep)) {
        array_push($dependencies, array('name' => _('Forschungen'), 'DEP' => $sciencedep));
    }
    if (sizeof($unitdep)) {
        array_push($dependencies, array('name' => _('Einheiten'), 'DEP' => $unitdep));
    }
    tmpl_set($template, '/', array('name' => $science->name, 'dbFieldName' => $science->dbFieldName, 'description' => $science->description, 'maxlevel' => $maxLevel, 'currentlevel' => $currentlevel, 'LEVELS' => $levels, 'DEPGROUP' => $dependencies, 'rules_path' => RULES_PATH));
    return tmpl_parse($template);
}
Beispiel #22
0
function wonder_processOrder($playerID, $wonderID, $caveID, $coordX, $coordY, $caveData)
{
    global $db;
    if ($GLOBALS['wonderTypeList'][$wonderID]->target == "same") {
        $targetID = $caveID;
        $sql = $db->prepare("SELECT * FROM " . CAVE_TABLE . " \n                         WHERE caveID = :targetID");
        $sql->bindValue('targetID', $targetID);
        if (!$sql->execute() || !($targetData = $sql->fetch(PDO::FETCH_ASSOC))) {
            return -3;
        }
        $sql->closeCursor();
        $coordX = $targetData['xCoord'];
        $coordY = $targetData['yCoord'];
    } else {
        // check the target cave
        $sql = $db->prepare("SELECT * FROM " . CAVE_TABLE . " \n                        WHERE xCoord = :coordX\n                        AND yCoord = :coordY");
        $sql->bindValue('coordX', $coordX, PDO::PARAM_INT);
        $sql->bindValue('coordY', $coordY, PDO::PARAM_INT);
        if (!$sql->execute() || !($targetData = $sql->fetch(PDO::FETCH_ASSOC))) {
            return -3;
        }
        $sql->closeCursor();
        $targetID = $targetData['caveID'];
    }
    // check, if cave allowed
    if ($GLOBALS['wonderTypeList'][$wonderID]->target == "own") {
        $allowed = $playerID == $targetData['playerID'];
    } else {
        if ($GLOBALS['wonderTypeList'][$wonderID]->target == "other") {
            $allowed = $playerID != $targetData['playerID'];
        } else {
            // $wonderTypeList[$wonderID]->target == "all"  or == "same"
            $allowed = 1;
        }
    }
    if (!$allowed) {
        return -2;
    }
    // take production costs from cave
    if (!processProductionCost($GLOBALS['wonderTypeList'][$wonderID], $caveID, $caveData)) {
        return 0;
    }
    // calculate the chance and evaluate into $chance
    if ($chance_formula = $GLOBALS['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 ($GLOBALS['wonderTypeList'][$wonderID]->offensiveness == "offensive") {
        $resistance_eval_formula = formula_parseToPHP(GameConstants::WONDER_RESISTANCE, '$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 = $GLOBALS['wonderTypeList'][$wonderID]->impactList[0]['delay'] * $delayRandFactor;
    foreach ($GLOBALS['wonderTypeList'][$wonderID]->impactList as $impactID => $impact) {
        $delay = (int) (($delayDelta + $impact['delay']) * WONDER_TIME_BASE_FACTOR);
        $now = time();
        $sql = $db->prepare("INSERT INTO " . EVENT_WONDER_TABLE . " (casterID, sourceID, targetID, \n                     wonderID, impactID, start, end) \n                     VALUES (:playerID, :caveID, :targetID, :wonderID, :impactID, :start, :end)");
        $sql->bindValue('playerID', $playerID, PDO::PARAM_INT);
        $sql->bindValue('caveID', $caveID, PDO::PARAM_INT);
        $sql->bindValue('targetID', $targetID, PDO::PARAM_INT);
        $sql->bindValue('wonderID', $wonderID, PDO::PARAM_INT);
        $sql->bindValue('impactID', $impactID, PDO::PARAM_INT);
        $sql->bindValue('start', time_toDatetime($now), PDO::PARAM_STR);
        $sql->bindValue('end', time_toDatetime($now + $delay), PDO::PARAM_STR);
        if (!$sql->execute()) {
            //give production costs back
            processProductionCostSetBack($GLOBALS['wonderTypeList'][$wonderID], $caveID, $caveData);
            return -1;
        }
    }
    // create messages
    $messageClass = new Messages();
    $sourceMessage = 'Sie haben auf die Höhle in ' . $coordX . '/' . $coordY . ' ein Wunder ' . $GLOBALS['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.';
    // create xml message
    $casterxml = new SimpleXMLElement('<?xml version=\'1.0\' encoding=\'utf-8\'?><wonderMessageCaster></wonderMessageCaster>');
    $casterxml->addChild('timestamp', time());
    $casterxml->addChild('wonderType', 'caster');
    $casterxml->addChild('source');
    $casterxml->source->addChild('xCoord', $caveData['xCoord']);
    $casterxml->source->addChild('yCoord', $caveData['yCoord']);
    $casterxml->source->addChild('caveName', $caveData['name']);
    $casterxml->addChild('target');
    $casterxml->target->addChild('xCoord', $targetData['xCoord']);
    $casterxml->target->addChild('yCoord', $targetData['yCoord']);
    $casterxml->target->addChild('caveName', $targetData['name']);
    $casterxml->addChild('wonderName', $GLOBALS['wonderTypeList'][$wonderID]->name);
    $targetxml = new SimpleXMLElement('<?xml version=\'1.0\' encoding=\'utf-8\'?><wonderMessageTarget></wonderMessageTarget>');
    $targetxml->addChild('timestamp', time());
    $targetxml->addChild('wonderType', 'target');
    $targetxml->addChild('source');
    $targetxml->source->addChild('xCoord', $caveData['xCoord']);
    $targetxml->source->addChild('yCoord', $caveData['yCoord']);
    $targetxml->source->addChild('caveName', $caveData['name']);
    $targetxml->addChild('target');
    $targetxml->target->addChild('xCoord', $targetData['xCoord']);
    $targetxml->target->addChild('yCoord', $targetData['yCoord']);
    $targetxml->target->addChild('caveName', $targetData['name']);
    $messageClass->sendSystemMessage($playerID, 9, 'Wunder erwirkt auf ' . $coordX . '/' . $coordY, $sourceMessage, $casterxml->asXML());
    $messageClass->sendSystemMessage($targetData['playerID'], 9, 'Wunder!', $targetMessage, $targetxml->asXML());
    return 1;
}
Beispiel #23
0
    /////////////////////////////////////////////////////////////////////////////
    default:
        $pagetitle = _("Modus nicht bekannt");
        $content = "Modus " . $modus . " CaveID " . $caveID;
}
// prepare resource bar
$resources = array();
if (!$no_resource_flag && isset($resourceTypeList)) {
    foreach ($resourceTypeList as $resource) {
        $amount = floor($meineHoehlen[$caveID][$resource->dbFieldName]);
        if (!$resource->nodocumentation || $amount > 0) {
            $delta = $meineHoehlen[$caveID][$resource->dbFieldName . "_delta"];
            if ($delta > 0) {
                $delta = "+" . $delta;
            }
            $resources[] = array('dbFieldName' => $resource->dbFieldName, 'name' => $resource->name, 'amount' => $amount, 'delta' => $delta, 'maxLevel' => round(eval('return ' . formula_parseToPHP("{$resource->maxLevel};", '$meineHoehlen[$caveID]'))));
        }
    }
}
// prepare new mail
list($nm_title, $nm_content) = messages_main($caveID, $meineHoehlen);
// prepare next and previous cave
$keys = array_keys($meineHoehlen);
$pos = array_search($caveID, $keys);
$prev = isset($keys[$pos - 1]) ? $keys[$pos - 1] : $keys[count($keys) - 1];
$next = isset($keys[$pos + 1]) ? $keys[$pos + 1] : $keys[0];
// open template
$template = tmpl_open($params->SESSION->player->getTemplatePath() . 'main.ihtml');
// fill it
tmpl_set($template, array('pagetitle' => $pagetitle, 'content' => $content, 'cave_name' => $meineHoehlen[$caveID]['name'], 'cave_x_coord' => $meineHoehlen[$caveID]['xCoord'], 'cave_y_coord' => $meineHoehlen[$caveID]['yCoord'], 'bottom' => vote_main(), 'new_mail' => $nm_content, 'rules_path' => RULES_PATH, 'help_path' => HELP_PATH));
if (sizeof($resources)) {
Beispiel #24
0
function unitAction($caveID, &$meineHoehlen)
{
    global $config, $db, $MAX_RESOURCE, $MOVEMENTCOSTCONSTANT, $MOVEMENTSPEEDCONSTANT, $params, $ua_movements, $resourceTypeList, $unitTypeList, $effectTypeList, $FUELRESOURCEID;
    $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
    /***************************************************************************/
    /***************************************************************************/
    /***************************************************************************/
    // 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'));
    if (isset($params->POST->moveit)) {
        $targetXCoord = $params->POST->targetXCoord;
        $targetYCoord = $params->POST->targetYCoord;
        $targetCaveName = $params->POST->targetCaveName;
        $movementID = $params->POST->movementID;
        // check for scripters
        check_timestamp($params->POST->tstamp);
        // HöhlenName >>> Koordinate
        $validCaveName = FALSE;
        if (empty($targetXCoord) || empty($targetYCoord) and !empty($targetCaveName)) {
            $result = getCaveByName($targetCaveName);
            if (sizeof($result) != 0) {
                $targetXCoord = $result['xCoord'];
                $targetYCoord = $result['yCoord'];
                $validCaveName = TRUE;
            }
        }
        // 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;
            }
        }
        // ADDED by chris--- for farmschutz
        if (FARMSCHUTZ_ACTIVE == 1) {
            if ($params->POST->movementID == 3 || $params->POST->movementID == 6) {
                $farmschutz = farmschutz($targetXCoord, $targetYCoord, $params->SESSION->user['playerID'], $db);
            }
        }
        // ------------------------------------
        if ($params->POST->movementID == 0) {
            $msg = "*#\$@*#\$%: Bitte Bewegungsart ausw&auml;hlen!";
        } else {
            if (!sizeof($unit)) {
                $msg = "*#\$@*#\$%: Es sind keine Einheiten ausgew&auml;hlt!";
            } else {
                if (empty($targetXCoord) || empty($targetYCoord) and empty($targetCaveName)) {
                    $msg = "*#\$@*#\$%: Es fehlt eine Zielkoordinate oder ein Zielsiedlungsname!";
                } else {
                    if (empty($targetXCoord) || empty($targetYCoord) and !empty($targetCaveName) and $validCaveName === FALSE) {
                        $msg = "*#\$@*#\$%: Es gibt keine Siedlung mit dem Namen '" . $targetCaveName . "'!";
                    } else {
                        if ($overloaded) {
                            $msg = "*#\$@*#\$%: Deine Krieger k&ouml;nnen die Menge an Ressourcen nicht tragen!!";
                        } else {
                            if (beginner_isCaveProtectedByCoord($targetXCoord, $targetYCoord, $db)) {
                                $msg = "*#\$@*#\$%: Die Zielsiedlung steht unter Anf&auml;ngerschutz. ";
                            } else {
                                if (beginner_isCaveProtectedByID($caveID, $db)) {
                                    $msg = "*#\$@*#\$%: Ihre Siedlung steht unter Anf&auml;ngerschutz. " . "Sie k&ouml;nnen den Schutz sofort unter dem Punkt Bericht: Alle " . "meine Siedlungen beenden";
                                } else {
                                    if ($params->POST->movementID == 6 && cave_isCaveSecureByCoord($targetXCoord, $targetYCoord, $db)) {
                                        $msg = "*#\$@*#\$%: Sie k&ouml;nnen diese Siedlung nicht &uuml;bernehmen. " . "Sie ist gegen &Uuml;bernahmen gesch&uuml;tzt.";
                                    } else {
                                        if (FARMSCHUTZ_ACTIVE == 1 && ($params->POST->movementID == 3 || $params->POST->movementID == 6) && $farmschutz == 1) {
                                            $msg = "*#\$@*#\$%: Der Spieler steht unter Farmschutz. Sie k&ouml;nnen ihn nicht angreifen.";
                                        } else {
                                            if (FARMSCHUTZ_ACTIVE == 1 && ($params->POST->movementID == 3 || $params->POST->movementID == 6) && $farmschutz == 2) {
                                                $msg = "*#\$@*#\$%: Sie stehen unter Farmschutz. Dieser Spieler ist zu gro&szlig; zum angreifen.";
                                            } else {
                                                // Entfernung x Dauer pro Höhle x größter Geschwindigkeitsfaktor x Bewegungsfaktor
                                                $duration = ceil(getDistanceByCoords($details['xCoord'], $details['yCoord'], $targetXCoord, $targetYCoord) * $minutesPerCave * getMaxSpeedFactor($unit) * $ua_movements[$movementID]->speedfactor * (1 + $details[$effectTypeList[25]->dbFieldName]));
                                                // Dauer x Rationen x Größe einer Ration x Bewegungsfaktor
                                                $reqFood = ceil($duration * calcRequiredFood($unit) * $foodPerCave * $ua_movements[$movementID]->foodfactor);
                                                if ($details[$resourceTypeList[$FUELRESOURCEID]->dbFieldName] < $reqFood) {
                                                    $msg = "*#\$@*#\$%: Nicht genug Nahrung zum Ern&auml;hren der Krieger auf ihrem langen Marsch vorhanden!!";
                                                } else {
                                                    $msgID = setMovementEvent($caveID, $details, $targetXCoord, $targetYCoord, $unit, $resource, $movementID, $reqFood, $duration, $moveArtefact, $minutesPerCave * $ua_movements[$movementID]->speedfactor);
                                                    switch ($msgID) {
                                                        case 0:
                                                            $msg = "Die Krieger wurden losgeschickt und haben {$reqFood} Nahrung mitgenommen!";
                                                            break;
                                                        case 1:
                                                            $msg = "*#\$@*#\$%: In diesen Koordinaten liegt keine Siedlung!";
                                                            break;
                                                        case 2:
                                                            $msg = "*#\$@*#\$%: F&uuml;r diese Bewegung sind nicht gen&uuml;gend Einheiten/Rohstoffe verf&uuml;gbar!";
                                                            break;
                                                        case 3:
                                                            $msg = "Schwerer *#\$@*#\$%: Bitte Admin kontaktieren!";
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } else {
        if (!empty($params->POST->eventID)) {
            $msgID = reverseMovementEvent($caveID, $params->POST->eventID);
            switch ($msgID) {
                case 0:
                    $msg = "Die Einheiten kehren zurück!";
                    break;
                case 1:
                    $msg = "*#\$@*#\$%: Fehler bei der Rückkehr!";
                    break;
            }
        }
    }
    // refresh this cave
    $temp = getCaveSecure($caveID, $params->SESSION->user['playerID']);
    $meineHoehlen[$caveID] = $details = $temp->nextRow(MYSQL_ASSOC);
    // make sure that bagged artefacts are not shown again
    if ($moveArtefact != 0) {
        $myartefacts = artefact_getArtefactsReadyForMovement($caveID);
    }
    // //////////////////////////////////////////////////////////////
    // Create the page
    // //////////////////////////////////////////////////////////////
    $template = @tmpl_open("./templates/" . $config->template_paths[$params->SESSION->user['template']] . "/unitaction.ihtml");
    // messages
    if (isset($msg)) {
        tmpl_set($template, '/MESSAGE/msg', $msg);
    }
    // javascript support
    tmpl_set($template, 'currentX', $details['xCoord']);
    tmpl_set($template, 'currentY', $details['yCoord']);
    tmpl_set($template, 'dim_x', $dim_x);
    tmpl_set($template, 'dim_y', $dim_y);
    tmpl_set($template, 'speed', $minutesPerCave);
    tmpl_set($template, 'movementcostconstant', $foodPerCave);
    tmpl_set($template, "resourceTypes", $MAX_RESOURCE);
    tmpl_set($template, "movement_speed_factor", $details[$effectTypeList[25]->dbFieldName]);
    // ADDED by chris--- for movement_speed_factor
    // ADDED by chris--- for cavebook:
    tmpl_set($template, 'show_book_modus', CAVE_BOOK);
    // Getting entries
    $cavelist = cavebook_getEntries($params->SESSION->user['playerID']);
    // Show the cave table
    for ($i = 0; $i < sizeof($cavelist[id]); $i++) {
        $cavename = $cavelist[name][$i];
        // the current cavename
        $cavebookID = $cavelist[id][$i];
        $cave_x = $cavelist[x][$i];
        $cave_y = $cavelist[y][$i];
        tmpl_iterate($template, '/BOOKENTRY');
        tmpl_set($template, 'BOOKENTRY/book_entry', $cavename);
        tmpl_set($template, 'BOOKENTRY/book_id', $cavebookID);
        tmpl_set($template, 'BOOKENTRY/book_x', $cave_x);
        tmpl_set($template, 'BOOKENTRY/book_y', $cave_y);
        tmpl_iterate($template, '/BOOKENTRYJS');
        tmpl_set($template, 'BOOKENTRYJS/book_entry', unhtmlentities($cavename));
        tmpl_set($template, 'BOOKENTRYJS/book_id', $cavebookID);
        tmpl_set($template, 'BOOKENTRYJS/book_x', $cave_x);
        tmpl_set($template, 'BOOKENTRYJS/book_y', $cave_y);
    }
    // movements
    $selectable_movements = array();
    foreach ($ua_movements as $value) {
        if ($value->playerMayChoose) {
            $selectable_movements[] = get_object_vars($value);
        }
    }
    tmpl_set($template, 'SELECTACTION', $selectable_movements);
    // resources
    $resources = array();
    for ($res = 0; $res < sizeof($resourceTypeList); $res++) {
        $resources[] = array('resourceID' => $resourceTypeList[$res]->resourceID, 'name' => $resourceTypeList[$res]->name, 'currentAmount' => "0" + $details[$resourceTypeList[$res]->dbFieldName], 'dbFieldName' => $resourceTypeList[$res]->dbFieldName);
    }
    tmpl_set($template, 'RESOURCE', $resources);
    tmpl_set($template, 'TOTAL', $resources);
    tmpl_set($template, 'RESOURCE_LUGGAGE', $resources);
    // units table
    $unitprops = array();
    $units = array();
    $unitsAll = array();
    // ADDED by chris---
    for ($i = 0; $i < sizeof($unitTypeList); $i++) {
        // if no units of this type, next type
        if (!$details[$unitTypeList[$i]->dbFieldName]) {
            continue;
        }
        $temp = array();
        $encumbrance = array();
        for ($j = 0; $j < count($resourceTypeList); $j++) {
            $encumbrance[$j] = array('resourceID' => $j, 'load' => "0" + $unitTypeList[$i]->encumbranceList[$j]);
            $temp[] = "0" + $unitTypeList[$i]->encumbranceList[$j];
        }
        $unitprops[] = array('unitID' => $unitTypeList[$i]->unitID, 'foodCost' => $unitTypeList[$i]->foodCost, 'speedFactor' => $unitTypeList[$i]->wayCost, 'resourceLoad' => implode(",", $temp));
        $units[] = array('name' => $unitTypeList[$i]->name, 'modus' => UNIT_PROPERTIES, 'unitID' => $unitTypeList[$i]->unitID, 'foodCost' => $unitTypeList[$i]->foodCost, 'speedFactor' => $unitTypeList[$i]->wayCost, 'maxWarriorAnzahl' => $details[$unitTypeList[$i]->dbFieldName], 'warriorID' => $i, 'ENCUMBRANCE' => $encumbrance);
        $unitAnzahl = sizeof($units);
    }
    tmpl_set($template, 'UNITPROPS', $unitprops);
    tmpl_set($template, 'SELECTWARRIOR', $units);
    tmpl_set($template, '/unitAnzahl', $unitAnzahl);
    // weitergereichte Koordinateny
    if (empty($params->POST->movementID)) {
        tmpl_set($template, 'targetXCoord', $params->POST->targetXCoord);
        tmpl_set($template, 'targetYCoord', $params->POST->targetYCoord);
        tmpl_set($template, 'targetCaveName', $params->POST->targetCaveName);
    }
    // weitere Paramter
    $hidden = array(array('name' => 'modus', 'value' => MOVEMENT), array('name' => 'moveit', 'value' => 'true'), array('name' => 'trigger', 'value' => 'self'), array('name' => 'tstamp', 'value' => "" . time()));
    tmpl_set($template, 'PARAMS', $hidden);
    $movements = digest_getMovements(array($caveID => $details), array(), true);
    //$movements = digest_getMovements($meineHoehlen, array(), true);
    foreach ($movements as $move) {
        if ($move['isOwnMovement']) {
            if (isCaveInvisibleToPlayer($move['target_caveID'], $params->SESSION->user['playerID'], $db)) {
                $move['target_player_tribe'] = "";
                $move['target_player_name'] = "";
            }
            tmpl_iterate($template, 'MOVEMENT/MOVE');
            tmpl_set($template, 'MOVEMENT/MOVE', $move);
        } else {
            tmpl_iterate($template, 'OPPMOVEMENT/MOVE');
            tmpl_set($template, 'OPPMOVEMENT/MOVE', $move);
        }
    }
    // artefakte
    if (sizeof($myartefacts) != 0) {
        tmpl_set($template, '/ARTEFACTS/ARTEFACT', $myartefacts);
    }
    return tmpl_parse($template);
}
Beispiel #25
0
/** This function computes the vision range of a given cave.
 *  The measuring unit of the returned value is 'caves'.
 *  For example a returned value of 3 equals a vision range of
 *  three caves in any direction.
 */
function getVisionRange($cave_data)
{
    return eval('return ' . formula_parseToPHP(GameConstants::WATCHTOWER_VISION_RANGE . ";", '$cave_data'));
}
Beispiel #26
0
function improvement_processOrder($buildingID, $caveID, $caveData, $db)
{
    global $defenseSystemTypeList, $unitTypeList, $buildingTypeList, $scienceTypeList, $resourceTypeList;
    $building = $buildingTypeList[$buildingID];
    $maxLevel = round(eval('return ' . formula_parseToPHP("{$building->maxLevel};", '$caveData')));
    $set = array();
    $setBack = array();
    $where = array("WHERE caveID = '{$caveID}'", "{$building->dbFieldName} < {$maxLevel}");
    // get all the resource costs
    foreach ($building->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 ($building->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 ($building->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 ($building->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 ($building->buildingDepList as $key => $value) {
        if ($value != "" && $value != "0") {
            array_push($where, "{$buildingTypeList[$key]->dbFieldName} >= {$value}");
        }
    }
    foreach ($building->maxBuildingDepList as $key => $value) {
        if ($value != -1) {
            array_push($where, "{$buildingTypeList[$key]->dbFieldName} <= {$value}");
        }
    }
    foreach ($building->defenseSystemDepList as $key => $value) {
        if ($value != "" && $value != "0") {
            array_push($where, "{$defenseSystemTypeList[$key]->dbFieldName} >= {$value}");
        }
    }
    foreach ($building->maxDefenseSystemDepList as $key => $value) {
        if ($value != -1) {
            array_push($where, "{$defenseSystemTypeList[$key]->dbFieldName} <= {$value}");
        }
    }
    foreach ($building->resourceDepList as $key => $value) {
        if ($value != "" && $value != "0") {
            array_push($where, "{$resourceTypeList[$key]->dbFieldName} >= {$value}");
        }
    }
    foreach ($building->maxResourceDepList as $key => $value) {
        if ($value != -1) {
            array_push($where, "{$resourceTypeList[$key]->dbFieldName} <= {$value}");
        }
    }
    foreach ($building->scienceDepList as $key => $value) {
        if ($value != "" && $value != "0") {
            array_push($where, "{$scienceTypeList[$key]->dbFieldName} >= {$value}");
        }
    }
    foreach ($building->maxScienceDepList as $key => $value) {
        if ($value != -1) {
            array_push($where, "{$scienceTypeList[$key]->dbFieldName} <= {$value}");
        }
    }
    foreach ($building->unitDepList as $key => $value) {
        if ($value != "" && $value != "0") {
            array_push($where, "{$unitTypeList[$key]->dbFieldName} >= {$value}");
        }
    }
    foreach ($building->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 2;
    }
    $prodTime = 0;
    // calculate the production time;
    if ($time_formula = $building->productionTimeFunction) {
        $time_eval_formula = formula_parseToPHP($time_formula, '$caveData');
        $time_eval_formula = "\$prodTime={$time_eval_formula};";
        eval($time_eval_formula);
    }
    $prodTime *= BUILDING_TIME_BASE_FACTOR;
    $now = time();
    $query = sprintf("INSERT INTO Event_expansion (caveID, expansionID, " . "`start`, `end`) VALUES (%d, %d, '%s', '%s')", $caveID, $buildingID, time_toDatetime($now), time_toDatetime($now + $prodTime));
    if (!$db->query($query)) {
        $db->query($setBack);
        return 2;
    }
    return 3;
}
Beispiel #27
0
// RESOURCEN ZEIGEN
if ($no_resource_flag) {
    tmpl_set($template, "NOTICKER", array('dummy' => ""));
}
if (!$no_resource_flag) {
    // ADDED by chris--- for ticker
    if ($params->SESSION->user['show_ticker']) {
        // Getting the last 20 messages
        $ticker_text = ticker_text();
        tmpl_set($template, "/", array('ticker_text' => $ticker_text));
        tmpl_set($template, "TICKER", array('ticker_text' => $ticker_text, 'link1' => TICKER_ENTRY, 'link2' => TICKER_ARCHIVE));
    } else {
        tmpl_set($template, "NOTICKER", array('dummy' => ""));
    }
    $resources = array();
    for ($i = 0; $i < sizeof($resourceTypeList); ++$i) {
        $delta = $meineHoehlen[$caveID][$resourceTypeList[$i]->dbFieldName . "_delta"];
        if ($delta > 0) {
            $delta = "+" . $delta;
        }
        //echo formula_parseToPHP("{$resourceTypeList[$i]->maxLevel};", '$meineHoehlen[$caveID]')."<br>";
        $maxlevel = round(eval('return ' . formula_parseToPHP("{$resourceTypeList[$i]->maxLevel};", '$meineHoehlen[$caveID]')));
        $prozent = round(floor($meineHoehlen[$caveID][$resourceTypeList[$i]->dbFieldName]) / $maxlevel * 100, 0);
        $resources[$i] = array('dbFieldName' => $resourceTypeList[$i]->dbFieldName, 'name' => $resourceTypeList[$i]->name, 'amount' => floor($meineHoehlen[$caveID][$resourceTypeList[$i]->dbFieldName]), 'delta' => $delta, 'maxLevel' => $maxlevel, 'prozent' => $prozent);
    }
    tmpl_set($template, "RESOURCES/RESOURCE", $resources);
}
tmpl_set($template, "", array('cave_name' => $meineHoehlen[$caveID]['name'], 'cave_x_coord' => $meineHoehlen[$caveID]['xCoord'], 'cave_y_coord' => $meineHoehlen[$caveID]['yCoord']));
$gfx = $params->SESSION->nogfx ? DEFAULT_GFX_PATH : $params->SESSION->user['gfxpath'];
echo str_replace('%gfx%', $gfx, tmpl_parse($template));
page_end();
Beispiel #28
0
function unit_processOrder($unitID, $quantity, $caveID, $db, $details)
{
    global $defenseSystemTypeList, $unitTypeList, $buildingTypeList, $scienceTypeList, $resourceTypeList;
    if ($quantity > MAX_SIMULTAN_BUILDED_UNITS || $quantity <= 0) {
        return 4;
    }
    $set = array();
    $setBack = array();
    $where = array("WHERE caveID = '{$caveID}'");
    // get all the resource costs
    foreach ($unitTypeList[$unitID]->resourceProductionCost as $key => $value) {
        if ($value != "" && $value != "0") {
            $formula = formula_parseToSQL($value);
            $formula *= $quantity;
            $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 ($unitTypeList[$unitID]->unitProductionCost as $key => $value) {
        if ($value != "" && $value != "0") {
            $formula = formula_parseToSQL($value);
            $formula *= $quantity;
            $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 ($unitTypeList[$unitID]->buildingProductionCost as $key => $value) {
        if ($value != "" && $value != "0") {
            $formula = formula_parseToSQL($value);
            $formula *= $quantity;
            $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 ($unitTypeList[$unitID]->externalProductionCost as $key => $value) {
        if ($value != "" && $value != "0") {
            $formula = formula_parseToSQL($value);
            $formula *= $quantity;
            $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 ($unitTypeList[$unitID]->buildingDepList as $key => $value) {
        if ($value != "" && $value != "0") {
            array_push($where, "{$buildingTypeList[$key]->dbFieldName} >= {$value}");
        }
    }
    foreach ($unitTypeList[$unitID]->maxBuildingDepList as $key => $value) {
        if ($value != -1) {
            array_push($where, "{$buildingTypeList[$key]->dbFieldName} <= {$value}");
        }
    }
    foreach ($unitTypeList[$unitID]->defenseSystemDepList as $key => $value) {
        if ($value != "" && $value != "0") {
            array_push($where, "{$defenseSystemTypeList[$key]->dbFieldName} >= {$value}");
        }
    }
    foreach ($unitTypeList[$unitID]->maxDefenseSystemDepList as $key => $value) {
        if ($value != -1) {
            array_push($where, "{$defenseSystemTypeList[$key]->dbFieldName} <= {$value}");
        }
    }
    foreach ($unitTypeList[$unitID]->resourceDepList as $key => $value) {
        if ($value != "" && $value != "0") {
            array_push($where, "{$resourceTypeList[$key]->dbFieldName} >= {$value}");
        }
    }
    foreach ($unitTypeList[$unitID]->maxResourceDepList as $key => $value) {
        if ($value != -1) {
            array_push($where, "{$resourceTypeList[$key]->dbFieldName} <= {$value}");
        }
    }
    foreach ($unitTypeList[$unitID]->scienceDepList as $key => $value) {
        if ($value != "" && $value != "0") {
            array_push($where, "{$scienceTypeList[$key]->dbFieldName} >= {$value}");
        }
    }
    foreach ($unitTypeList[$unitID]->maxScienceDepList as $key => $value) {
        if ($value != -1) {
            array_push($where, "{$scienceTypeList[$key]->dbFieldName} <= {$value}");
        }
    }
    foreach ($unitTypeList[$unitID]->unitDepList as $key => $value) {
        if ($value != "" && $value != "0") {
            array_push($where, "{$unitTypeList[$key]->dbFieldName} >= {$value}");
        }
    }
    foreach ($unitTypeList[$unitID]->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 2;
    }
    $prodTime = 0;
    // calculate the production time;
    if ($time_formula = $unitTypeList[$unitID]->productionTimeFunction) {
        $time_eval_formula = formula_parseToPHP($time_formula, '$details');
        eval('$prodTime=' . $time_eval_formula . ';');
    }
    $prodTime *= BUILDING_TIME_BASE_FACTOR * $quantity;
    $now = time();
    $query = sprintf("INSERT INTO Event_unit (caveID, unitID, quantity, " . "`start`, `end`) VALUES (%d, %d, %d, '%s', '%s')", $caveID, $unitID, $quantity, time_toDatetime($now), time_toDatetime($now + $prodTime));
    if (!$db->query($query)) {
        $db->query($setBack);
        return 2;
    }
    return 3;
}
Beispiel #29
0
/**
 *
 */
function externals_performOrder($externalID, $caveID, $cave, $db)
{
    global $defenseSystemTypeList, $unitTypeList, $buildingTypeList, $scienceTypeList, $resourceTypeList;
    $external = $defenseSystemTypeList[$externalID];
    $maxLevel = round(eval('return ' . formula_parseToPHP("{$external->maxLevel};", '$cave')));
    $set = array();
    $setBack = array();
    $where = array("WHERE caveID = '{$caveID}'", "{$external->dbFieldName} < {$maxLevel}");
    // get all the resource costs
    foreach ($external->resourceProductionCost as $key => $value) {
        if ($value) {
            $formula = formula_parseToSQL($value);
            $dbField = $resourceTypeList[$key]->dbFieldName;
            $set[] = "{$dbField} = {$dbField} - ({$formula})";
            $setBack[] = "{$dbField} = {$dbField} + ({$formula})";
            $where[] = "{$dbField} >= ({$formula})";
        }
    }
    // get all the unit costs
    foreach ($external->unitProductionCost as $key => $value) {
        if ($value) {
            $formula = formula_parseToSQL($value);
            $dbField = $unitTypeList[$key]->dbFieldName;
            $set[] = "{$dbField} = {$dbField} - ({$formula})";
            $setBack[] = "{$dbField} = {$dbField} + ({$formula})";
            $where[] = "{$dbField} >= ({$formula})";
        }
    }
    // get all the building costs
    foreach ($external->buildingProductionCost as $key => $value) {
        if ($value) {
            $formula = formula_parseToSQL($value);
            $dbField = $buildingTypeList[$key]->dbFieldName;
            $set[] = "{$dbField} = {$dbField} - ({$formula})";
            $setBack[] = "{$dbField} = {$dbField} + ({$formula})";
            $where[] = "{$dbField} >= ({$formula})";
        }
    }
    // get all the external costs
    foreach ($external->externalProductionCost as $key => $value) {
        if ($value) {
            $formula = formula_parseToSQL($value);
            $dbField = $defenseSystemTypeList[$key]->dbFieldName;
            $set[] = "{$dbField} = {$dbField} - ({$formula})";
            $setBack[] = "{$dbField} = {$dbField} + ({$formula})";
            $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 dependencies
    foreach ($external->buildingDepList as $key => $value) {
        if ($value) {
            $where[] = "{$buildingTypeList[$key]->dbFieldName} >= {$value}";
        }
    }
    foreach ($external->maxBuildingDepList as $key => $value) {
        if ($value != -1) {
            $where[] = "{$buildingTypeList[$key]->dbFieldName} <= {$value}";
        }
    }
    foreach ($external->defenseSystemDepList as $key => $value) {
        if ($value) {
            $where[] = "{$defenseSystemTypeList[$key]->dbFieldName} >= {$value}";
        }
    }
    foreach ($external->maxDefenseSystemDepList as $key => $value) {
        if ($value != -1) {
            $where[] = "{$defenseSystemTypeList[$key]->dbFieldName} <= {$value}";
        }
    }
    foreach ($external->resourceDepList as $key => $value) {
        if ($value) {
            $where[] = "{$resourceTypeList[$key]->dbFieldName} >= {$value}";
        }
    }
    foreach ($external->maxResourceDepList as $key => $value) {
        if ($value != -1) {
            $where[] = "{$resourceTypeList[$key]->dbFieldName} <= {$value}";
        }
    }
    foreach ($external->scienceDepList as $key => $value) {
        if ($value) {
            $where[] = "{$scienceTypeList[$key]->dbFieldName} >= {$value}";
        }
    }
    foreach ($external->maxScienceDepList as $key => $value) {
        if ($value != -1) {
            $where[] = "{$scienceTypeList[$key]->dbFieldName} <= {$value}";
        }
    }
    foreach ($external->unitDepList as $key => $value) {
        if ($value) {
            $where[] = "{$unitTypeList[$key]->dbFieldName} >= {$value}";
        }
    }
    foreach ($external->maxUnitDepList as $key => $value) {
        if ($value != -1) {
            $where[] = "{$unitTypeList[$key]->dbFieldName} <= {$value}";
        }
    }
    $where = implode(" AND ", $where);
    if (!$db->query($set . $where) || !$db->affected_rows() == 1) {
        return _('Der Auftrag konnte nicht erteilt werden. Es fehlen die notwendigen Voraussetzungen.');
    }
    // calculate the production time;
    $prodTime = 0;
    if ($time_formula = $external->productionTimeFunction) {
        $time_eval_formula = formula_parseToPHP($time_formula, '$cave');
        $time_eval_formula = "\$prodTime={$time_eval_formula};";
        eval($time_eval_formula);
    }
    $prodTime *= DEFENSESYSTEM_TIME_BASE_FACTOR;
    $now = time();
    $query = sprintf("INSERT INTO Event_defenseSystem (caveID, defenseSystemID, " . "`start`, `end`) VALUES (%d, %d, '%s', '%s')", $caveID, $externalID, time_toDatetime($now), time_toDatetime($now + $prodTime));
    if (!$db->query($query)) {
        $db->query($setBack);
        return _('Der Auftrag konnte nicht erteilt werden. Es fehlen die notwendigen Voraussetzungen.');
    }
    return _('Der Auftrag wurde erteilt.');
}
Beispiel #30
0
function unit_Movement($caveID, &$ownCave)
{
    global $db, $template;
    $safeForm = true;
    // get movements
    $ua_movements = Movement::getMovements();
    $details = $ownCave[$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);
        $moveArtefactID = Request::getVar('myartefacts', 0);
        // was an artefact chosen?
        if ($moveArtefactID > 0) {
            // now check, whether this artefactID belongs to this cave
            foreach ($myartefacts as $key => $value) {
                // if found, set it
                if ($moveArtefactID == $value['artefactID']) {
                    $moveArtefact = $moveArtefactID;
                    break;
                }
            }
        }
    }
    // now $moveArtefact should contain 0 for 'move no artefact'
    // or the artefactID of the artefact to be moved
    /***************************************************************************/
    /***************************************************************************/
    /***************************************************************************/
    /**
     * HERO MOVEMENT
     */
    $moveHero = 0;
    if ($details['hero'] != 0) {
        $hero = getHeroByPlayer($_SESSION['player']->playerID);
        if ($hero['isAlive'] != 1) {
            $details['hero'] = 0;
        }
    }
    if ($details['hero'] != 0 && Request::getVar('moveHero', false) == true) {
        $moveHero = $details['hero'];
    }
    /**
     * END HERO MOVEMENTS
     */
    // put user, its session and nogfx flag into session
    $_SESSION['player'] = Player::getPlayer($_SESSION['player']->playerID);
    // 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(GameConstants::MOVEMENT_COST . ';', '$details'));
    $minutesPerCave = eval('return ' . formula_parseToPHP(GameConstants::MOVEMENT_SPEED . ';', '$details'));
    $minutesPerCave *= MOVEMENT_TIME_BASE_FACTOR / 60;
    if (Request::getVar('moveit', false) && sizeof(Request::getVar('unit', array('' => '')))) {
        $targetXCoord = Request::getVar('targetXCoord', 0);
        $targetYCoord = Request::getVar('targetYCoord', 0);
        $targetCaveName = Request::getVar('targetCaveName', '');
        $targetCaveID = Request::getVar('targetCaveID', 0);
        $movementID = Request::getVar('movementID', 0);
        // check for scripters
        check_timestamp(Request::getVar('tstamp', 0));
        $validCaveName = false;
        // targetCaveID >>> coords
        if ($targetCaveID > 0) {
            $result = getCaveByID(intval($targetCaveID));
            if (sizeof($result) != 0) {
                $targetXCoord = $result['xCoord'];
                $targetYCoord = $result['yCoord'];
                $validCaveName = true;
            }
            // name >>> coords
        } else {
            if ($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(Request::getVar('unit', array('' => '')), "filterZeros");
        $unit = array_map("checkFormValues", $unit);
        $resource = array_map("checkFormValues", Request::getVar('rohstoff', array('' => '')));
        // Test, ob Einheitentragekapazität ausgelastet
        $overloaded = 0;
        foreach ($resource as $resKey => $aRes) {
            $capacity = 0;
            foreach ($unit as $unitKey => $aUnit) {
                if (isset($GLOBALS['unitTypeList'][$unitKey]->encumbranceList[$resKey])) {
                    $capacity += $aUnit * $GLOBALS['unitTypeList'][$unitKey]->encumbranceList[$resKey];
                }
            }
            if ($capacity < $aRes) {
                $overloaded = 1;
                break;
            }
        }
        $denymovement_nonenemy = false;
        $denymovement_targetwar = false;
        if ($movementID == 2) {
            // move units/resources
            if (strtoupper($targetPlayer->tribe) != strtoupper($_SESSION['player']->tribe)) {
                //may tade in own tribe
                $ownTribe = $_SESSION['player']->tribe;
                $targetTribe = $targetPlayer->tribe;
                $targetIsNonPlayer = $targetPlayer->playerID == 0;
                $ownTribeAtWar = tribe_isAtWar($ownTribe, TRUE);
                $targetTribeAtWar = tribe_isAtWar($targetTribe, TRUE);
                $TribesMayTrade = relation_areAllies($ownTribe, $targetTribe) || relation_areEnemys($ownTribe, $targetTribe) || $targetIsNonPlayer;
                $denymovement_nonenemy = $ownTribeAtWar && !$TribesMayTrade;
                $denymovement_targetwar = $targetTribeAtWar && !$TribesMayTrade;
            }
        }
        // check if army is small enough for hero
        $denymovement_hero = false;
        if ($moveHero && (Request::getVar('movementID', 0) == 3 || Request::getVar('movementID', 0) == 6)) {
            //calculate size of army
            $armySize = 0;
            foreach ($unit as $unitID => $value) {
                $armySize += $GLOBALS['unitTypeList'][$unitID]->hitPoints * $value;
            }
            if ($armySize > $hero['exp']) {
                $denymovement_hero = true;
            }
        }
        if (Request::getVar('movementID', 0) == 0) {
            $msg = array('type' => 'error', 'message' => _('Bitte Bewegungsart auswählen!'));
            $moveHero = 0;
        } else {
            if (!sizeof($unit)) {
                $msg = array('type' => 'error', 'message' => _('Es sind keine Einheiten ausgewählt!'));
                $moveHero = 0;
            } else {
                if (($targetXCoord == 0 || $targetYCoord == 0) && $targetCaveName == "") {
                    $msg = array('type' => 'error', 'message' => _('Es fehlt eine Zielkoordinate oder ein Zielhöhlenname!'));
                    $moveHero = 0;
                } else {
                    if (($targetXCoord == 0 || $targetYCoord == 0) && !($targetCaveName == "") && $validCaveName === FALSE) {
                        $msg = array('type' => 'error', 'message' => sprintf(_('Es gibt keine Höhle mit dem Namen "%s"!'), $targetCaveName));
                        $moveHero = 0;
                    } else {
                        if ($overloaded) {
                            $msg = array('type' => 'error', 'message' => _('Deine Krieger können die Menge an Ressourcen nicht tragen!!'));
                            $moveHero = 0;
                        } else {
                            if (beginner_isCaveProtectedByCoord($targetXCoord, $targetYCoord)) {
                                $msg = array('type' => 'error', 'message' => _('Die Zielhöhle steht unter Anfängerschutz.'));
                                $moveHero = 0;
                            } else {
                                if (beginner_isCaveProtectedByID($caveID)) {
                                    $msg = array('type' => 'error', 'message' => _('Ihre Höhle steht unter Anfängerschutz. Sie können den Schutz sofort unter dem Punkt <a href="?modus=cave_detail">Bericht über diese Höhle</a> beenden'));
                                    $moveHero = 0;
                                } else {
                                    if (Request::getVar('movementID', 0) == 6 && cave_isCaveSecureByCoord($targetXCoord, $targetYCoord)) {
                                        $msg = array('type' => 'error', 'message' => _('Sie können diese Höhle nicht übernehmen. Sie ist gegen übernahmen geschützt.'));
                                        $moveHero = 0;
                                    } else {
                                        if ($denymovement_nonenemy) {
                                            $msg = array('type' => 'error', 'message' => _('Sie können im Krieg keine Einheiten zu unbeteiligten Parteien verschieben!'));
                                        } else {
                                            if ($denymovement_targetwar) {
                                                $msg = array('type' => 'error', 'message' => _('Sie können keine Einheiten zu kriegführenden Stämmen verschieben, wenn Sie unbeteiligt sind.'));
                                                $moveHero = 0;
                                            } else {
                                                if ($denymovement_hero) {
                                                    $msg = array('type' => 'error', 'message' => _('Die Armee ist zu groß um vom Helden unterstützt zu werden!'));
                                                    $moveHero = 0;
                                                } else {
                                                    // Entfernung x Dauer pro Höhle x größter Geschwindigkeitsfaktor x Bewegungsfaktor
                                                    $duration = ceil(getDistanceByCoords($details['xCoord'], $details['yCoord'], $targetXCoord, $targetYCoord) * $minutesPerCave * getMaxSpeedFactor($unit) * $ua_movements[$movementID]->speedfactor);
                                                    $distance = ceil(getDistanceByCoords($details['xCoord'], $details['yCoord'], $targetXCoord, $targetYCoord));
                                                    $tmpdist = 0;
                                                    $i = 0;
                                                    if ($distance > 15) {
                                                        $distance = $distance - 15;
                                                        $tmpdist = 15;
                                                        if (floor($distance / 5) < 11) {
                                                            $tmpdist += $distance % 5 * (1 - 0.1 * floor($distance / 5));
                                                        }
                                                        for ($i = 1; $i <= floor($distance / 5) && $i < 11; $i++) {
                                                            $tmpdist += 5 * (1 - 0.1 * ($i - 1));
                                                        }
                                                    } else {
                                                        $tmpdist = $distance;
                                                    }
                                                    // Dauer x Rationen x Größe einer Ration x Bewegungsfaktor
                                                    $reqFood = ceil($tmpdist * $minutesPerCave * getMaxSpeedFactor($unit) * $ua_movements[$movementID]->speedfactor * calcRequiredFood($unit) * $foodPerCave * $ua_movements[$movementID]->foodfactor);
                                                    if ($details[$GLOBALS['resourceTypeList'][GameConstants::FUEL_RESOURCE_ID]->dbFieldName] < $reqFood) {
                                                        $msg = array('type' => 'error', 'message' => _('Nicht genug Nahrung zum Ernähren der Krieger auf ihrem langen Marsch vorhanden!'));
                                                    } else {
                                                        $msgID = setMovementEvent($caveID, $details, $targetXCoord, $targetYCoord, $unit, $resource, $movementID, $reqFood, $duration, $moveArtefact, $moveHero, $minutesPerCave * $ua_movements[$movementID]->speedfactor);
                                                        switch ($msgID) {
                                                            case 0:
                                                                $msg = array('type' => 'success', 'message' => sprintf(_('Die Krieger wurden losgeschickt und haben %d Nahrung mitgenommen!'), $reqFood));
                                                                $safeForm = false;
                                                                break;
                                                            case 1:
                                                                $msg = array('type' => 'error', 'message' => _('In diesen Koordinaten liegt keine Höhle!'));
                                                                $moveHero = 0;
                                                                break;
                                                            case 2:
                                                                $msg = array('type' => 'error', 'message' => _('Für diese Bewegung sind nicht genügend Einheiten/Rohstoffe verfügbar!'));
                                                                $moveHero = 0;
                                                                break;
                                                            case 3:
                                                                $msg = array('type' => 'error', 'message' => _('Schwerer Fehler: Bitte Admin kontaktieren!'));
                                                                $moveHero = 0;
                                                                break;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } else {
        if (Request::isPost('action') && Request::getVar('action', '') == 'cancel' && ($eventID = Request::getVar('eventID', 0))) {
            $msgID = reverseMovementEvent($caveID, $eventID);
            switch ($msgID) {
                case 0:
                    $msg = array('type' => 'success', 'message' => _('Die Einheiten kehren zurück!'));
                    break;
                case 1:
                    $msg = array('type' => 'error', 'message' => _('Fehler bei der Rückkehr!'));
                    break;
            }
        } else {
            if (Request::getVar('moveit', false) && !sizeof(Request::getVar('unit', array('' => '')))) {
                $msg = array('type' => 'error', 'message' => _('Einheiten mitnehmen?'));
            }
        }
    }
    // refresh this cave
    $temp = getCaveSecure($caveID, $_SESSION['player']->playerID);
    $ownCave[$caveID] = $details = $temp;
    // make sure that bagged artefacts are not shown again
    if ($moveArtefact != 0) {
        $myartefacts = artefact_getArtefactsReadyForMovement($caveID);
    }
    // make sure that moved hero is not shown again
    if ($moveHero != 0) {
        $details['hero'] = 0;
    }
    // //////////////////////////////////////////////////////////////
    // Create the page
    // //////////////////////////////////////////////////////////////
    // open template
    $template->setFile('unitMovement.tmpl');
    $template->addVars(array('currentX' => $details['xCoord'], 'currentY' => $details['yCoord'], 'dim_x' => $dim_x, 'dim_y' => $dim_y, 'speed' => $minutesPerCave, 'fuel_id' => GameConstants::FUEL_RESOURCE_ID, 'fuel_name' => $GLOBALS['resourceTypeList'][GameConstants::FUEL_RESOURCE_ID]->name, 'movement_cost_constant' => $foodPerCave, 'resource_types' => GameConstants::MAX_RESOURCE, 'status_msg' => isset($msg) ? $msg : ''));
    // movements
    $selectable_movements = array();
    foreach ($ua_movements as $value) {
        if ($value->playerMayChoose) {
            $selectable_movements[] = get_object_vars($value);
        }
    }
    $template->addVar('selectable_movements', $selectable_movements);
    // resources
    $resources = array();
    foreach ($GLOBALS['resourceTypeList'] as $resourceID => $dummy) {
        if (!$GLOBALS['resourceTypeList'][$resourceID]->nodocumentation) {
            $resources[] = array('resource_id' => $GLOBALS['resourceTypeList'][$resourceID]->resourceID, 'name' => $GLOBALS['resourceTypeList'][$resourceID]->name, 'current_amount' => "0" + $details[$GLOBALS['resourceTypeList'][$resourceID]->dbFieldName], 'dbFieldName' => $GLOBALS['resourceTypeList'][$resourceID]->dbFieldName, 'value' => $safeForm && isset($resource[$resourceID]) && $resource[$resourceID] > 0 ? $resource[$resourceID] : '');
        }
    }
    $template->addVar('resource', $resources);
    // units table
    $unitprops = array();
    $units = array();
    foreach ($GLOBALS['unitTypeList'] as $unitID => $dummy) {
        // if no units of this type, next type
        if (!$details[$GLOBALS['unitTypeList'][$unitID]->dbFieldName]) {
            continue;
        }
        $temp = array();
        $encumbrance = array();
        foreach ($GLOBALS['resourceTypeList'] as $resourceID => $dummy) {
            if (!$GLOBALS['resourceTypeList'][$resourceID]->nodocumentation) {
                $encumbrance[$resourceID] = array('resourceID' => $resourceID, 'load' => "0" + (isset($GLOBALS['unitTypeList'][$unitID]->encumbranceList[$resourceID]) ? $GLOBALS['unitTypeList'][$unitID]->encumbranceList[$resourceID] : 0));
                $temp[] = "0" + (isset($GLOBALS['unitTypeList'][$unitID]->encumbranceList[$resourceID]) ? $GLOBALS['unitTypeList'][$unitID]->encumbranceList[$resourceID] : 0);
            }
        }
        $units[] = array('name' => $GLOBALS['unitTypeList'][$unitID]->name, 'unit_id' => $unitID, 'food_cost' => $GLOBALS['unitTypeList'][$unitID]->foodCost, 'resource_load' => implode(",", $temp), 'speed_factor' => $GLOBALS['unitTypeList'][$unitID]->wayCost, 'max_unit_count' => $details[$GLOBALS['unitTypeList'][$unitID]->dbFieldName], 'encumbrance' => $encumbrance, 'hitPoints' => $GLOBALS['unitTypeList'][$unitID]->hitPoints, 'value' => $safeForm && isset($unit[$unitID]) ? $unit[$unitID] : '');
    }
    $template->addVar('unit_list', $units);
    // weitergereichte Koordinaten
    if (!Request::getVar('movementID', 0) || $safeForm) {
        if (Request::getVar('targetCaveID', 0) > 0) {
            $caveData = getCaveByID(Request::getVar('targetCaveID', 0));
            $template->addVars(array('target_x_coord' => $caveData['xCoord'], 'target_y_coord' => $caveData['yCoord'], 'target_cave_name' => $caveData['name']));
        } else {
            $template->addVars(array('target_x_coord' => Request::getVar('targetXCoord', ''), 'target_y_coord' => Request::getVar('targetYCoord', ''), 'target_cave_name' => Request::getVar('targetCaveName', '')));
        }
    }
    // weitere Paramter
    $template->addVar('params', array(array('name' => 'modus', 'value' => UNIT_MOVEMENT), array('name' => 'moveit', 'value' => 'true'), array('name' => 'trigger', 'value' => 'self'), array('name' => 'tstamp', 'value' => "" . time())));
    $movements = digest_getMovements(array($caveID => $details), array(), true);
    $ownMovement = $oppMovement = array();
    foreach ($movements as $move) {
        if ($move['isOwnMovement']) {
            $ownMovement[] = $move;
        } else {
            $oppMovement[] = $move;
        }
    }
    $template->addVars(array('ownMovement' => $ownMovement, 'oppMovement' => $oppMovement));
    // artefakte
    if (sizeof($myartefacts) != 0) {
        //tmpl_set($template, '/ARTEFACTS/ARTEFACT', $myartefacts);
        $template->addVar('artefact', $myartefacts);
    }
    // hero
    if ($details['hero'] != 0) {
        $template->addVar('hero', $hero);
    }
    // Module "CaveBookmarks" Integration
    // FIXME should know whether the module is installed
    if (TRUE) {
        // get model
        $cb_model = new CaveBookmarks_Model();
        // get bookmarks
        $bookmarks = $cb_model->getCaveBookmarks(true);
        // set bookmarks
        if (sizeof($bookmarks)) {
            $template->addVar('bookmarks_cave', $bookmarks);
        }
    }
}