Ejemplo n.º 1
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);
}
Ejemplo n.º 2
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);
}
Ejemplo n.º 3
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);
        }
    }
}