Esempio n. 1
0
function tribe_getContent($caveID, $tribeID)
{
    global $db, $template;
    if (!$tribeID) {
        $template->throwError('Der Stamm wurde nicht gefunden.');
        return;
    }
    // open template
    $template->setFile('tribeDetail.tmpl');
    $template->setShowResource(false);
    $tribe = Tribe::getByID($tribeID);
    if ($tribe == null) {
        $template->throwError('Der Stamm wurde nicht gefunden.');
        return;
    }
    // parse tribe message
    $parser = new parser();
    $tribe['description'] = $parser->p($tribe['description']);
    $ranking = Tribe::getRanking($tribeID);
    $tribe['rank'] = $ranking;
    // leader
    if ($tribe['leaderID'] != 0) {
        $leader = Player::getPlayer($tribe['leaderID']);
        $tribe['leader_name'] = $leader->name;
    }
    $template->addVar('tribe_details', $tribe);
    // history
    $template->addVar('tribe_history', Tribe::getHistory($tribeID));
    // player list
    $template->addVar('tribe_player_list', Tribe::getPlayerList($tribeID, true, true));
    // relations
    $relations = TribeRelation::getRelations($tribeID);
    $relationsData = array();
    if (isset($relations['own'])) {
        foreach ($relations['own'] as $target => $relationData) {
            $relationsData[$target] = array('tribe' => $relationData['targetTag'], 'tribeID_target' => $relationData['tribeID_target'], 'relation_to' => $GLOBALS['relationList'][$relationData['relationType']]['name'], 'relation_from' => isset($relations['other'][$target]) && $relations['other'][$target] ? $GLOBALS['relationList'][$relations['other'][$target]['relationType']]['name'] : $GLOBALS['relationList'][0]['name']);
        }
    }
    if (isset($relations['other'])) {
        foreach ($relations['other'] as $target => $relationData) {
            // already printed out this relation
            if (isset($relationsData[$target])) {
                continue;
            }
            $relationsData[$target] = array('tribe' => $relationData['targetTag'], 'tribeID_target' => $relationData['tribeID_target'], 'relation_to' => $GLOBALS['relationList'][0]['name'], 'relation_from' => $GLOBALS['relationList'][$relationData['relationType']]['name']);
        }
    }
    $template->addVar('relations_data', $relationsData);
}
Esempio n. 2
0
        echo "Error recalcing leader for Tribe {$data['tag']}\n";
        return -1;
    }
    if ($r > 0) {
        echo "Tribe {$data['tag']} has a new leader: {$r}\n";
    }
}
// ----------------------------------------------------------------------------
// Step 3 Check Relations
echo "-- Check Relations --\n";
$sql = $db->prepare("SELECT *\n                       FROM " . TRIBE_ELECTION_TABLE . "\n                       WHERE relationType = :iwr");
$sql->bindValue('iwr', ID_WARALLY_RELATION, PDO::PARAM_INT);
if (!$sql->execute()) {
    echo "Error checking for war-allies tribes.\n";
    return -2;
}
while ($row = $sql->fetch()) {
    if (!TribeRelation::hasSameEnemy($row['tribeID'], $row['tribeID_target'], true, true)) {
        echo "Tear down war-ally : " . $row['tribeID'] . " => " . $row['tribeID_target'] . " ";
        $update = $db->prepare("UPDATE " . RELATION_TABLE . "\n                              SET relationType = :iafwr\n                              WHERE tribeID = :tribeID\n                                AND tribeID_target = :tribeID_target");
        $update->bindValue('iafwr', ID_AFTER_WARALLY_RELATION, PDO::PARAM_INT);
        $update->bindValue('tribeID', $row['tribe'], PDO::PARAM_INT);
        $update->bindValue('tribeID_target', $row['tribeID_target'], PDO::PARAM_INT);
        if ($update->execute()) {
            echo "Success\n";
        } else {
            echo "FAILED\n";
        }
    }
}
echo "Tribes end " . date("r") . "   -----------------------\n\n";
Esempio n. 3
0
 public static function processWonder($wonderID, $casterTribeData, $targetTribeName)
 {
     global $db;
     if ($wonderID < 0 || empty($casterTribeData) || empty($targetTribeName)) {
         return -30;
     }
     // check if wonder exists and is TribeWonder
     if (isset($GLOBALS['wonderTypeList'][$wonderID]) || !$wonder->isTribeWonder) {
         $wonder = $GLOBALS['wonderTypeList'][$wonderID];
     } else {
         return -33;
     }
     // check if tribes exist
     $targetTribeData = Tribe::getID($targetTribeName, true);
     if (empty($targetTribeData)) {
         return -15;
     }
     $casterTribeID = $casterTribeData['tribeID'];
     $targetTribeID = $targetTribeData['tribeID'];
     // check if tribe is valid
     if (!$targetTribeData['valid']) {
         return -34;
     }
     // check if caster tribe ist valid
     if (!$casterTribeData['valid']) {
         return -35;
     }
     $casterTribeRelations = TribeRelation::getRelations($casterTribeID);
     $targetTribeRelations = TribeRelation::getRelations($targetTribeID);
     $wonderPossible = false;
     foreach ($wonder->targetsPossible as $targetsPossible) {
         // check target
         if ($targetsPossible['target'] == 'own' && $casterTribeID !== $targetTribeID) {
             continue;
         }
         if ($targetsPossible['target'] == 'other' && $casterTribeID === $targetTribeID) {
             continue;
         }
         // check relation
         $check = self::checkRelations($targetsPossible['relation'], $targetTribeID, $casterTribeID, $casterTribeRelations, $targetTribeRelations);
         if ($check == true) {
             $wonderPossible = true;
             break;
         }
     }
     if ($wonderPossible == false) {
         return -37;
     }
     // take wonder Costs from TribeStorage
     $memberNumber = Tribe::getMemberCount($casterTribeID);
     if (!processProductionCost($wonder, 0, NULL, $memberNumber, true)) {
         return -33;
     }
     // does the wonder fail?
     if ((double) rand() / (double) getRandMax() > $wonder->chance) {
         return 11;
         // 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 = $wonder->impactList[0]['delay'] * $delayRandFactor;
     // get targets
     $targets = Tribe::getPlayerList($targetTribeID, false, true);
     if (sizeof($targets) == 0) {
         return -33;
     }
     $now = time();
     // loop over targets
     foreach ($targets as $playerID => $playerData) {
         foreach ($playerData['caves'] as $caveID => $caveData) {
             // loop over impacts
             foreach ($wonder->impactList as $impactID => $impact) {
                 $delay = (int) (($delayDelta + $impact['delay']) * WONDER_TIME_BASE_FACTOR);
                 $sql = $db->prepare("INSERT INTO " . EVENT_WONDER_TABLE . "\n                                (casterID, sourceID, targetID, wonderID, impactID, start, end)\n                               VALUES\n                                 (:playerID, :caveID, :targetID, :wonderID, :impactID, :start, :end)");
                 $sql->bindValue('playerID', 0, PDO::PARAM_INT);
                 // playerID 0, for not receiving lots of wonder-end-messages
                 $sql->bindValue('caveID', $casterTribeID, PDO::PARAM_INT);
                 $sql->bindValue('targetID', $caveID, 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);
                 $sql->execute();
             }
             // end foreach impactList
         }
     }
     // end foreach target
     // send caster messages
     $messageClass = new Messages();
     $messageClass->sendSystemMessage($_SESSION['player']->playerID, 9, sprintf(_("Stammeswunder erwirkt auf %s"), $targetTribeData['tag']), sprintf(_("Sie haben auf den Stamm %s ein Stammeswunder %s erwirkt."), $targetTribeData['tag'], $wonder->name));
     // send target messages
     $targetPlayersArray = array();
     foreach ($targets as $target) {
         if (!isset($targetPlayersArray[$target['playerID']])) {
             $targetPlayersArray[$target['playerID']] = $target;
         }
     }
     foreach ($targetPlayersArray as $target) {
         $messageClass->sendSystemMessage($target['playerID'], 9, 'Stammeswunder!', sprintf(_("Der Stamm %s hat ein Stammeswunder auf deine Höhlen gewirkt."), $casterTribeData['tag']));
     }
     return 12;
 }
Esempio n. 4
0
function cave_giveUpCave($caveID, $playerID, $tribeID)
{
    global $db;
    $sql = $db->prepare("UPDATE " . CAVE_TABLE . "\n                      SET playerID = 0,\n                        takeoverable = 0,\n                        protection_end = NOW()+0,\n                        secureCave = 0\n                      WHERE playerID = :playerID\n                        AND caveID = :caveID\n                        AND starting_position = 0");
    $sql->bindValue('playerID', $playerID, PDO::PARAM_INT);
    $sql->bindValue('caveID', $caveID, PDO::PARAM_INT);
    if (!$sql->execute() || $sql->rowCount() == 0) {
        return false;
    }
    $sql = $db->prepare("UPDATE " . CAVE_TABLE . " c\n                       SET  name = (SELECT name FROM " . CAVE_ORGINAL_NAME_TABLE . " co WHERE co.caveID = :caveID)\n                       WHERE c.caveID = :caveID");
    $sql->bindValue('caveID', $caveID, PDO::PARAM_INT);
    $sql->execute();
    @unlink("/var/www/speed/images/temp/{$caveID}.png");
    // delete all scheduled Events
    //   Event_movement - will only be deleted, when a new player gets that cave
    //   Event_artefact - can't be deleted, as it would result in serious errors
    //   Event_wonder   - FIX ME: don't know
    $db->query("DELETE FROM " . EVENT_DEFENSE_SYSTEM_TABLE . " WHERE caveID = '{$caveID}'");
    $db->query("DELETE FROM " . EVENT_EXPANSION_TABLE . " WHERE caveID = '{$caveID}'");
    $db->query("DELETE FROM " . EVENT_SCIENCE_TABLE . " WHERE caveID = '{$caveID}'");
    $db->query("DELETE FROM " . EVENT_UNIT_TABLE . " WHERE caveID = '{$caveID}'");
    $db->query("DELETE FROM " . EVENT_HERO_TABLE . " WHERE caveID = '{$caveID}'");
    if ($tribeID != 0) {
        $ownRelations = TribeRelation::getRelations($tribeID);
        foreach ($ownRelations['own'] as $actRelation) {
            $ownType = $actRelation['relationType'];
            if ($GLOBALS['relationList'][$ownType]['isPrepareForWar'] || $GLOBALS['relationList'][$ownType]['isWar']) {
                $newfame = $actRelation['fame'] - NONSECURE_CAVE_VAlUE * NONSECURE_CAVE_GIVEUP_FAKTOR;
                $sql = $db->prepare("UPDATE " . RELATION_TABLE . "\n                             SET fame = :newfame\n                             WHERE tribeID = :actTribeRelation\n                               AND tribeID_target  = :actTargetRelation");
                $sql->bindValue('newfame', $newfame, PDO::PARAM_INT);
                $sql->bindValue('actTribeRelation', $actRelation['tribeID'], PDO::PARAM_INT);
                $sql->bindValue('actTargetRelation', $actRelation['tribeID_target'], PDO::PARAM_INT);
                $sql->execute();
            }
        }
    }
    // delete hero
    $caveData = getCaveByID($caveID);
    if ($caveData['hero'] != 0) {
        hero_killHero($playerID);
    }
    return 1;
}
Esempio n. 5
0
/** calculates the displayed data for a specific map region. */
function calcCaveMapRegionData($caveID, $caves, $xCoord, $yCoord)
{
    $caveData = $caves[$caveID];
    $mapSize = getMapSize();
    // Größe der Karte wird benötigt
    $message = '';
    // calculate the dimensions of the visible map region
    $section = calcVisibleMapRegion($mapSize, $xCoord, $yCoord);
    $minX = $section['minX'];
    // minimum x-coordinate of caves in visible part of the map
    $minY = $section['minY'];
    // minimum y-coordinate of caves in visible part of the map
    $maxX = $section['maxX'];
    // maximum x-coordinate of caves in visible part of the map
    $maxY = $section['maxY'];
    // maximum y-coordinate of caves in visible part of the map
    $centerX = $section['centerX'];
    $centerY = $section['centerY'];
    // get the map details
    $caveDetails = getCaveDetailsByCoords($minX, $minY, $maxX, $maxY);
    $relations = TribeRelation::getRelations($_SESSION['player']->tribeID);
    $map = array();
    foreach ($caveDetails as $cave) {
        $cell = array('caveID' => $cave['caveID'], 'terrain' => 'terrain' . $cave['terrain'], 'terrain_tribe' => $GLOBALS['terrainList'][$cave['terrain']]['tribeRegion'], 'imgMap' => $GLOBALS['terrainList'][$cave['terrain']]['imgMap'], 'barren' => $GLOBALS['terrainList'][$cave['terrain']]['barren'], 'title' => 'Dies ist der Landstrich "' . $cave['cavename'] . '" (' . $cave['xCoord'] . '|' . $cave['yCoord'] . ') - ' . $GLOBALS['terrainList'][$cave['terrain']]['name']);
        // unbewohnte Höhle
        if ($cave['playerID'] == 0) {
            // als Frei! zeigen
            if ($cave['takeoverable'] == 1) {
                $text = _('Frei!');
                $file = "icon_cave_empty";
                // als Einöde zeigen
            } else {
                $text = _('Einöde');
                $file = "icon_waste";
            }
            // bewohnte Höhle
        } else {
            // eigene Höhle
            if ($cave['playerID'] == $_SESSION['player']->playerID) {
                $file = "icon_cave_own";
            } else {
                $file = "icon_cave_other";
                // fremde Höhle
            }
            // mit Artefakt
            if ($cave['hasArtefact'] && ($cave['tribe'] != GOD_ALLY || $_SESSION['player']->tribe == GOD_ALLY)) {
                $file .= "_artefact";
            }
            // Stamm abkürzen
            $decodedTribe = unhtmlentities($cave['tribe']);
            if (strlen($decodedTribe) > 10) {
                $cell['tribe'] = htmlentities(substr($decodedTribe, 0, 8)) . "..";
            } else {
                $cell['tribe'] = $cave['tribe'];
            }
            $cell['tribeID'] = $cave['tribeID'];
            // Besitzer
            $decodedOwner = unhtmlentities($cave['name']);
            if (strlen($decodedOwner) > 10) {
                $text = htmlentities(substr($decodedOwner, 0, 8)) . "..";
            } else {
                $text = $cave['name'];
            }
            // übernehmbare Höhlen können gekennzeichnet werden
            if ($cave['secureCave'] != 1) {
                $cell['unsecure'] = array('dummy' => '');
            }
            if ($_SESSION['player']->playerID == $cave['playerID']) {
                $cell['css_self'] = 't_self';
            }
            if (isset($relations['own'][$cave['tribeID']])) {
                $cell['css_own'] = 't_own_relation_' . $relations['own'][$cave['tribeID']]['relationType'];
            }
            if (isset($relations['other'][$cave['tribeID']])) {
                $cell['css_other'] = 't_other_relation_' . $relations['other'][$cave['tribeID']]['relationType'];
            }
        }
        $cell['file'] = $file;
        $cell['text'] = $text;
        $map[$cave['xCoord']][$cave['yCoord']] = $cell;
    }
    // create a region data array with an empty row as starting point.
    $regionData = array('rows' => array());
    // über alle Zeilen
    for ($j = $minY - 1; $j <= $maxY + 1; ++$j) {
        $cells = array();
        // über alle Spalten
        for ($i = $minX - 1; $i <= $maxX + 1; ++$i) {
            // leere Zellen
            if (($j == $minY - 1 || $j == $maxY + 1) && ($i == $minX - 1 || $i == $maxX + 1)) {
                array_push($cells, getCornerCell());
                // x-Beschriftung
            } else {
                if ($j == $minY - 1 || $j == $maxY + 1) {
                    array_push($cells, getLegendCell('x', $i));
                    // y-Beschriftung
                } else {
                    if ($i == $minX - 1 || $i == $maxX + 1) {
                        array_push($cells, getLegendCell('y', $j));
                        // Kartenzelle
                    } else {
                        array_push($cells, getMapCell($map, $i, $j));
                    }
                }
            }
        }
        array_push($regionData['rows'], $cells);
    }
    $mapData = array('centerXCoord' => $centerX, 'centerYCoord' => $centerY, 'queryXCoord' => $xCoord, 'queryYCoord' => $yCoord, 'mapregion' => $regionData);
    return $mapData;
}
Esempio n. 6
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);
        $hero['maxUnitsSize'] = max(HERO_MAX_UNIT_SIZE, $hero['exp']);
        if ($hero['isAlive'] != 1) {
            $details['hero'] = 0;
        }
    }
    if ($details['hero'] != 0 && Request::getVar('moveHero', 0) == 1) {
        $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 = Player::getPlayer($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('resource', 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 ($targetPlayer != null) {
                if ($targetPlayer->tribeID != $_SESSION['player']->tribeID) {
                    //may tade in own tribe
                    $ownTribeAtWar = TribeRelation::hasWar($_SESSION['player']->tribeID, true);
                    $targetTribeAtWar = TribeRelation::hasWar($targetPlayer->tribeID, true);
                    $TribesMayTrade = TribeRelation::isAlly($_SESSION['player']->tribeID, $targetPlayer->tribeID) && TribeRelation::hasSameEnemy($_SESSION['player']->tribeID, $targetPlayer->tribeID, true, true) || TribeRelation::isEnemy($_SESSION['player']->tribeID, $targetPlayer->tribeID);
                    $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'] && $armySize > HERO_MAX_UNIT_SIZE) {
                $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' && Request::getVar('eventID', 0)) {
            $msgID = reverseMovementEvent($caveID, Request::getVar('eventID', 0));
            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');
    // movements
    $selectableMovements = array();
    foreach ($ua_movements as $value) {
        if ($value->playerMayChoose) {
            $selectableMovements[$value->id] = get_object_vars($value);
        }
    }
    $template->addVar('selectable_movements', $selectableMovements);
    $movementData = array('currentX' => $details['xCoord'], 'currentY' => $details['yCoord'], 'dim_x' => $dim_x, 'dim_y' => $dim_y, 'minutesPerCave' => $minutesPerCave, 'foodID' => GameConstants::FUEL_RESOURCE_ID, 'foodfactor' => $foodPerCave, 'movements' => $selectableMovements);
    $template->addVars(array('fuel_name' => $GLOBALS['resourceTypeList'][GameConstants::FUEL_RESOURCE_ID]->name, 'status_msg' => isset($msg) ? $msg : '', 'movement_data' => json_encode($movementData)));
    // resources
    $resources = array();
    foreach ($GLOBALS['resourceTypeList'] as $resourceID => $dummy) {
        $amount = isset($details[$GLOBALS['resourceTypeList'][$resourceID]->dbFieldName]) ? floor($details[$GLOBALS['resourceTypeList'][$resourceID]->dbFieldName]) : 0;
        if (!$GLOBALS['resourceTypeList'][$resourceID]->nodocumentation || $amount > 0) {
            $resources[] = array('resource_id' => $GLOBALS['resourceTypeList'][$resourceID]->resourceID, 'name' => $GLOBALS['resourceTypeList'][$resourceID]->name, 'current_amount' => $details[$GLOBALS['resourceTypeList'][$resourceID]->dbFieldName], 'dbFieldName' => $GLOBALS['resourceTypeList'][$resourceID]->dbFieldName, 'value' => $safeForm && isset($resource[$resourceID]) && $resource[$resourceID] > 0 ? $resource[$resourceID] : '');
            $resourcesJson[$resourceID] = array('resource_id' => $GLOBALS['resourceTypeList'][$resourceID]->resourceID, 'name' => $GLOBALS['resourceTypeList'][$resourceID]->name, 'current_amount' => $details[$GLOBALS['resourceTypeList'][$resourceID]->dbFieldName], 'amount' => 0);
        }
    }
    $template->addVar('resource', $resources);
    $template->addVar('resource_json', json_encode($resourcesJson));
    // units table
    $unitprops = array();
    $units = array();
    $unitsJson = 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) {
            $amount = isset($details[$GLOBALS['resourceTypeList'][$resourceID]->dbFieldName]) ? floor($details[$GLOBALS['resourceTypeList'][$resourceID]->dbFieldName]) : 0;
            if (!$GLOBALS['resourceTypeList'][$resourceID]->nodocumentation || $amount > 0) {
                $encumbrance[$resourceID] = array('resourceID' => $resourceID, 'dbFieldName' => isset($GLOBALS['unitTypeList'][$unitID]->encumbranceList[$resourceID]) ? $GLOBALS['resourceTypeList'][$resourceID]->dbFieldName : '', 'name' => isset($GLOBALS['unitTypeList'][$unitID]->encumbranceList[$resourceID]) ? $GLOBALS['resourceTypeList'][$resourceID]->name : '', 'load' => isset($GLOBALS['unitTypeList'][$unitID]->encumbranceList[$resourceID]) ? $GLOBALS['unitTypeList'][$unitID]->encumbranceList[$resourceID] : 0);
                $temp[] = 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, '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] : '', 'size' => $GLOBALS['unitTypeList'][$unitID]->hitPoints, 'arealAttack' => $GLOBALS['unitTypeList'][$unitID]->attackAreal, 'rangeAttack' => $GLOBALS['unitTypeList'][$unitID]->attackRange, 'attackRate' => $GLOBALS['unitTypeList'][$unitID]->attackRate);
        $unitsJson[] = array('unit_id' => $unitID, 'foodCost' => $GLOBALS['unitTypeList'][$unitID]->foodCost, 'speedFactor' => $GLOBALS['unitTypeList'][$unitID]->wayCost, 'maxUnitCount' => $details[$GLOBALS['unitTypeList'][$unitID]->dbFieldName], 'encumbrance' => $encumbrance, 'hitPoints' => $GLOBALS['unitTypeList'][$unitID]->hitPoints, 'size' => $GLOBALS['unitTypeList'][$unitID]->hitPoints, 'arealAttack' => $GLOBALS['unitTypeList'][$unitID]->attackAreal, 'rangeAttack' => $GLOBALS['unitTypeList'][$unitID]->attackRange, 'attackRate' => $GLOBALS['unitTypeList'][$unitID]->attackRate);
    }
    $template->addVar('unit_list', $units);
    $template->addVar('unit_list_json', json_encode($unitsJson));
    // 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' => '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) {
        $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);
        }
    }
}
Esempio n. 7
0
function tribe_getContent($caveID, &$details)
{
    global $template;
    // messages
    $messageText = array(-47 => array('type' => 'error', 'message' => _('Fehler beim entfernen der Spielerrechte.')), -46 => array('type' => 'error', 'message' => _('Der Stamm wurde nicht gefunden.')), -45 => array('type' => 'error', 'message' => _('Der Spieler wurde nicht gefunden.')), -44 => array('type' => 'error', 'message' => _('Beim hinzufügen der Spielerrechte ist ein Fehler aufgetreten.')), -43 => array('type' => 'error', 'message' => _('Die Regierung wurde nicht geändert, weil sie sich nicht geändert hat.')), -42 => array('type' => 'error', 'message' => _('Ein Rohstoff wurde erst vor kurzen eingelagert. Bitte warte bis du es erneut versucht.')), -41 => array('type' => 'error', 'message' => _('Beim kicken das Spielers ist ein Fehler aufgetreten.')), -40 => array('type' => 'error', 'message' => _('Der Stamm befindet sich zur Zeit in einem Krieg und es kann kein Spieler gekickt werden.')), -39 => array('type' => 'error', 'message' => _('Der Stammesführer kann nicht entlassen werden.')), -38 => array('type' => 'error', 'message' => _('Der Spieler wurde in dem Stamm nicht gefunden!')), -37 => array('type' => 'error', 'message' => _('Der Zielstamm besitzt nicht die benötigte Vorraussetzung um das Wunder erwirken zu können.')), -36 => array('type' => 'error', 'message' => _('Dieses Wunder wurde erst vor kurzen gewundert. Bitte warte etwas bevor du es erneut wunderst.')), -35 => array('type' => 'error', 'message' => _('Der gegnerische Stamm hat nicht genug Mitglieder um Stammeswunder bekommen zu können!')), -34 => array('type' => 'error', 'message' => _('Ihr Stamm hat nicht genug Mitglieder um Stammeswunder sprechen zu können!')), -33 => array('type' => 'error', 'message' => _('Beim erbitten des Stammeswunders ist ein Problem aufgetreten!')), -32 => array('type' => 'error', 'message' => _('Das Stammeswunder konnte nicht gewirkt werden.')), -31 => array('type' => 'error', 'message' => _('Die Rechte konnten nicht angewandt werden.')), -30 => array('type' => 'error', 'message' => _('Fehler in den Formulardaten!')), -29 => array('type' => 'error', 'message' => _('Die Stimme konnte wegen eines Fehlers nicht abgegeben werden.')), -28 => array('type' => 'error', 'message' => _('Die Regierung konnte nicht geändert werden, weil sie erst vor kurzem geändert wurde.')), -27 => array('type' => 'error', 'message' => _('Die Regierung konnte aufgrund eines Fehlers nicht aktualisiert werden')), -26 => array('type' => 'error', 'message' => _('Ihr Kriegsanteil ist nicht hoch genug, um den Gegner zur Aufgabe zu zwingen.')), -25 => array('type' => 'error', 'message' => _('Eure Untergebenen weigern sich, diese Beziehung gegenüber einem so großen Stamm einzugehen.')), -24 => array('type' => 'error', 'message' => _('Eure Untergebenen weigern sich, diese Beziehung gegenüber einem so kleinen Stamm einzugehen.')), -23 => array('type' => 'error', 'message' => _('Ihr habt mit dem anderen Stamm keinen gleichen Kriegsgegner.')), -22 => array('type' => 'error', 'message' => _('Die Beziehung des anderen Stammes erlauben kein Kriegsbündniss.')), -21 => array('type' => 'error', 'message' => _('Unsere aktuelle Beziehung erlaubt kein Kriegsbündniss.')), -20 => array('type' => 'error', 'message' => _('Von der derzeitigen Beziehung kann nicht direkt auf die ausgewählte Beziehungsart gewechselt werden.')), -19 => array('type' => 'error', 'message' => _('Die Mindestlaufzeit von der derzeitigen Beziehung läuft noch!')), -18 => array('type' => 'error', 'message' => _('Die Beziehung wurde nicht geändert, weil der ausgewählte Beziehungstyp bereits eingestellt ist.')), -17 => array('type' => 'error', 'message' => _('Die Beziehung konnte aufgrund eines Fehlers nicht aktualisiert werden.')), -16 => array('type' => 'error', 'message' => _('Der Stamm hat noch nicht genug Mitglieder um Beziehungen eingehen zu dürfen')), -15 => array('type' => 'error', 'message' => _('Den Stamm gibt es nicht!')), -14 => array('type' => 'error', 'message' => _('Zu sich selber kann man keine Beziehungen aufnehmen!')), -13 => array('type' => 'error', 'message' => _('Ungültiges Bild oder URL beim Avatar! Wird zurückgesetzt!')), -12 => array('type' => 'error', 'message' => _('Ungültiges Passwort! (Mind. 6 Zeichen, ohne Sonderzeichen)')), -11 => array('type' => 'error', 'message' => _('Fehler beim Eintragen ins Stammeslager!')), -10 => array('type' => 'error', 'message' => _('Nicht genug Rohstoffe vorhanden!')), -9 => array('type' => 'error', 'message' => _('Eine Rohstoff hat den maximalen Einzahlungswert überschritten!')), -8 => array('type' => 'info', 'message' => _('Bitte die gewünscht Menge an Rohstoffen die eingezahlt werden sollen angeben.')), -7 => array('type' => 'error', 'message' => _('Die Nachricht konnte nicht verschickt werden.')), -6 => array('type' => 'error', 'message' => _('Du mußt eine Nachricht schreiben um sie versenden zu können.')), -5 => array('type' => 'error', 'message' => _('Sie konnten nicht austreten. Vermutlich gehören Sie gar keinem Stamm an.')), -4 => array('type' => 'error', 'message' => _('Sie sind der Stammesanführer und konnten nicht entlassen werden.')), -3 => array('type' => 'error', 'message' => _('Die Stammeszugehörigkeit hat sich erst vor kurzem geändert. Warten Sie, bis die Stammeszugehörigkeit geändert werden darf.')), -2 => array('type' => 'error', 'message' => _('Ihr Stamm befindet sich im Krieg. Sie dürfen derzeit nicht austreten.')), -1 => array('type' => 'error', 'message' => _('Du hast keine Berechtigung dies zu tun.')), 1 => array('type' => 'success', 'message' => _('Du hast den Stamm verlassen.')), 2 => array('type' => 'success', 'message' => _('Du hast den Stamm erfolgreich verlassen.<br />Da du das letzte Mitglied warst, wurde der Stamm aufgelöst.')), 3 => array('type' => 'success', 'message' => _('Die Nachricht wurde Erfolgreich verschickt.')), 4 => array('type' => 'success', 'message' => _('Deine Rohstoffe wurden Erfolgreich ins Stammeslager eingezahlt!')), 5 => array('type' => 'success', 'message' => _('Die Daten wurden erfolgreich aktualisiert.')), 6 => array('type' => 'error', 'message' => _('Die Daten konnten gar nicht oder zumindest nicht vollständig aktualisiert werden.')), 7 => array('type' => 'success', 'message' => _('Die Beziehung zu dem anderen Stamm wurde erfolgreich geändert.')), 8 => array('type' => 'success', 'message' => _('Die Regierung des Stammes wurde erfolgreich geändert.')), 9 => array('type' => 'success', 'message' => _('Die Stimme wurde erfolgreich gezählt.')), 10 => array('type' => 'success', 'message' => _('Der Spieler hat seine Rechte erfolgreich erhalten.')), 11 => array('type' => 'info', 'message' => _('Die Götter haben Ihr Flehen nicht erhört! Die eingesetzten Opfergaben sind natürlich dennoch verloren. Mehr Glück beim nächsten Mal!')), 12 => array('type' => 'success', 'message' => _('Das Erflehen des Wunders scheint Erfolg zu haben.')), 13 => array('type' => 'success', 'message' => _('Der Spieler wurde erfolgreich gekickt.')), 14 => array('type' => 'success', 'message' => _('Spielerrechte erfolgreich hinzugefügt. In kürze kann der Spieler den Raum betreten.')), 15 => array('type' => 'success', 'message' => _('Spielerrechte erfolgreich hinzugefügt. In kürze können die Spieler den Raum betreten.')), 16 => array('type' => 'success', 'message' => _('Spielerrechte erfolgreich entfernt. In kürze können der/die Spieler den Raum nicht mehr betreten.')));
    if (!$_SESSION['player']->tribeID) {
        tribe_getContentNoTribe($caveID, $details);
        return;
    }
    $tribeID = $_SESSION['player']->tribeID;
    $tribeData = Tribe::getByID($tribeID);
    if ($tribeData == null) {
        $template->throwError('Der Stamm konnte nicht geladen werden.');
        return;
    }
    $tribeMembers = Tribe::getPlayerList($tribeID, true, true, 'p.name');
    // open template
    $template->setFile('tribeMember.tmpl');
    $template->setShowResource(true);
    // init auth
    $auth = new auth();
    $userAuth = $auth->getAllTypePermission('tribe', $_SESSION['player']->auth['tribe']);
    $userAuth['isLeader'] = $tribeData['leaderID'] == $_SESSION['player']->playerID ? true : false;
    // init Chat Channel
    $chatRooms = Chat::getRoomsByTribeID($tribeID);
    // process form data
    $tribeAction = Request::getVar('action', 0);
    switch ($tribeAction) {
        /****************************************************************************************************
        *
        * Spielerrechte Ändern
        *
        ****************************************************************************************************/
        case TRIBE_ACTION_AUTH:
            if (!$userAuth['isLeader']) {
                $messageID = -1;
                break;
            }
            $playerID = Request::getVar('player_id', 0);
            if ($playerID == 0 || !isset($tribeMembers[$playerID])) {
                $messageID = -38;
                break;
            }
            $authID = 0;
            foreach ($auth->perm['tribe'] as $type => $data) {
                $authID = $authID | Request::getVar($type, 0);
            }
            $newUserAuth = $auth->setPermission('tribe', $authID, $playerID);
            if ($newUserAuth !== false) {
                $messageID = 10;
                $tribeMembers[$playerID]['tribeAuth'] = $auth->getAllTypePermission('tribe', $newUserAuth);
            } else {
                $messageID = -31;
            }
            break;
            /****************************************************************************************************
            *
            * Auswahl des Anführers
            *
            ****************************************************************************************************/
        /****************************************************************************************************
        *
        * Auswahl des Anführers
        *
        ****************************************************************************************************/
        case TRIBE_ACTION_CHOOSE_LEADER:
            $chooseLeaderID = Request::getVar('chooseLeaderID', 0);
            if ($chooseLeaderID != 0 && isset($tribeMembers[$chooseLeaderID])) {
                $messageID = TribeLeader::setChoice($chooseLeaderID, $_SESSION['player']->playerID, $tribeID);
                break;
            } else {
                if ($chooseLeaderID == 0) {
                    $messageID = TribeLeader::removeChoice($_SESSION['player']->playerID);
                } else {
                    $messageID = -38;
                }
            }
            break;
            /****************************************************************************************************
            *
            * Ressie Spende an den Stamm
            *
            ****************************************************************************************************/
        /****************************************************************************************************
        *
        * Ressie Spende an den Stamm
        *
        ****************************************************************************************************/
        case TRIBE_ACTION_DONATE:
            $value = Request::getVar('value', array('' => ''));
            $messageID = TribeDonation::setDonations($value, $caveID, $details);
            $tribeData = Tribe::getByID($tribeID);
            break;
            /****************************************************************************************************
            *
            * Regierungstyp ändern
            *
            ****************************************************************************************************/
        /****************************************************************************************************
        *
        * Regierungstyp ändern
        *
        ****************************************************************************************************/
        case TRIBE_ACTION_GOVERMENT:
            if (!$userAuth['isLeader']) {
                $messageID = -1;
                break;
            }
            if (!TribeGovernment::isChangeable($tribeID)) {
                $messageID = -28;
                break;
            }
            $governmentID = Request::getVar('governmentID', 0);
            if ($governmentID == 0) {
                $messageID = -27;
                break;
            }
            if ($governmentID == $tribeData['governmentID']) {
                $messageID = -43;
                break;
            }
            $messageID = TribeGovernment::setGovernment($tribeID, $governmentID);
            break;
            /****************************************************************************************************
            *
            * bye bye Spieler
            *
            ****************************************************************************************************/
        /****************************************************************************************************
        *
        * bye bye Spieler
        *
        ****************************************************************************************************/
        case TRIBE_ACTION_KICK:
            if (!$userAuth['kick_member'] && !$userAuth['isLeader']) {
                $messageID = -1;
                break;
            }
            $playerID = Request::getVar('playerID', 0);
            if ($playerID == 0 || !isset($tribeMembers[$playerID])) {
                $messageID = -38;
                break;
            }
            if ($tribeData['leaderID'] == $playerID) {
                $messageID = -39;
                break;
            }
            $messageID = Tribe::processKickMember($playerID, $tribeData);
            if ($messageID > 0) {
                unset($tribeMembers[$playerID]);
            }
            break;
            /****************************************************************************************************
            *
            * Bye Bye Stamm :(
            *
            ****************************************************************************************************/
        /****************************************************************************************************
        *
        * Bye Bye Stamm :(
        *
        ****************************************************************************************************/
        case TRIBE_ACTION_LEAVE:
            if (Request::isPost('postConfirm')) {
                $messageID = Tribe::processLeave($_SESSION['player']->playerID, $tribeData);
                if ($messageID > 0) {
                    page_refreshUserData();
                    $template->addVar('status_msg', $messageText[$messageID]);
                    tribe_getContentNoTribe($caveID, $details);
                    return;
                }
            } else {
                $template->addVars(array('confirm_box' => true, 'confirm_action' => TRIBE_ACTION_LEAVE, 'confirm_id' => false, 'confirm_mode' => TRIBE, 'confirm_msg' => sprintf(_('Möchtest du den Stamm <span class="bold">%s</span> wirklich verlassen?'), $tribeTag)));
            }
            break;
            /****************************************************************************************************
            *
            * paar Spieler informieren über irgendwas
            *
            ****************************************************************************************************/
        /****************************************************************************************************
        *
        * paar Spieler informieren über irgendwas
        *
        ****************************************************************************************************/
        case TRIBE_ACTION_MESSAGE:
            if (!$userAuth['msg_tribe'] && !$userAuth['msg_public'] && !$userAuth['isLeader']) {
                $messageID = -1;
                break;
            }
            $message = Request::getVar('messageText', '', true);
            if (empty($message)) {
                $messageID = -6;
                break;
            }
            $button = Request::getVar('button', '');
            $messageType = Request::getVar('messageType', '');
            if ($button == 'ingame' && ($userAuth['msg_public'] || $userAuth['isLeader'])) {
                $messageID = TribeMessage::processSendPlayer($tribeID, $_SESSION['player']->name, $message);
            } else {
                if ($button == 'tribemsg' && $userAuth['msg_tribe'] || $userAuth['isLeader']) {
                    $messageID = TribeMessage::processSendIntern($tribeID, $_SESSION['player']->name, $message);
                } else {
                    $messageID = -1;
                }
            }
            break;
            /****************************************************************************************************
            *
            * Krieg? Niederlage? Verbünden? Aktualisieren der Beziehung
            *
            ****************************************************************************************************/
        /****************************************************************************************************
        *
        * Krieg? Niederlage? Verbünden? Aktualisieren der Beziehung
        *
        ****************************************************************************************************/
        case TRIBE_ACTION_RELATION:
            if (!$userAuth['change_relation'] && !$userAuth['isLeader']) {
                $messageID = -1;
                break;
            }
            $targetTribe = Request::getVar('targetTribe', '');
            $relationID = Request::getVar('relationID', 0);
            if (empty($targetTribe)) {
                $messageID = -15;
                break;
            }
            $targeData = Tribe::getID($targetTribe, true);
            if (empty($targeData)) {
                $messageID = -15;
                break;
            }
            $button = Request::getVar('button', '');
            if ($button == 'forceSurrender') {
                $messageID = TribeRelation::forceSurrender($tribeData, $targeData, $relationID);
            } else {
                $messageID = TribeRelation::processRelationUpdate($tribeData, $targeData, $relationID);
            }
            break;
            /****************************************************************************************************
            *
            * Stammesinfos aktualisieren
            *
            ****************************************************************************************************/
        /****************************************************************************************************
        *
        * Stammesinfos aktualisieren
        *
        ****************************************************************************************************/
        case TRIBE_ACTION_UPDATE:
            if (!$userAuth['change_settings'] && !$userAuth['isLeader']) {
                $messageID = -1;
                break;
            }
            $password = Request::getVar('inputPassword', '');
            $postData = array('name' => Request::getVar('inputName', '', true), 'password' => !empty($password) ? $password : $tribeData['password'], 'avatar' => Request::getVar('inputAvatar', ''), 'description' => Request::getVar('inputDescription', '', true));
            $messageID = Tribe::updateTribeData($tribeID, $postData);
            $tribeData = Tribe::getByID($tribeID);
            break;
            /****************************************************************************************************
            *
            * Stammeswunder?
            *
            ****************************************************************************************************/
        /****************************************************************************************************
        *
        * Stammeswunder?
        *
        ****************************************************************************************************/
        case TRIBE_ACTION_WONDER:
            if (!$userAuth['wonder'] && !$userAuth['isLeader']) {
                $messageID = -1;
                break;
            }
            $wonderID = Request::getVar('wonderID', -1);
            $tribeName = Request::getVar('tribeName', '');
            if ($wonderID == -1) {
                $messageID = -32;
                break;
            }
            if (empty($tribeName)) {
                $messageID = -15;
                break;
            }
            if (isset($tribeData['wonderLocked'][$wonderID]) && $tribeData['wonderLocked'][$wonderID] > time()) {
                $messageID = -36;
                break;
            }
            $messageID = TribeWonder::processWonder($wonderID, $tribeData, $tribeName);
            if ($messageID > 0) {
                TribeWonder::setBlockedTime($tribeID, $wonderID, $tribeData['wonderLocked']);
            }
            if ($messageID == 11 || $messageID == 12) {
                $success = $messageID == 12 ? 1 : 2;
                wonder_addStatistic($wonderID, $success);
            }
            $tribeData = Tribe::getByID($tribeID);
            break;
            /****************************************************************************************************
            *
            * User/Stammes Rechte für den Chat vergeben
            *
            ****************************************************************************************************/
        /****************************************************************************************************
        *
        * User/Stammes Rechte für den Chat vergeben
        *
        ****************************************************************************************************/
        case TRIBE_ACTION_CHAT_ADD:
            if (!$userAuth['manage_chat'] && !$userAuth['isLeader']) {
                $messageID = -1;
                break;
            }
            $roomID = Request::getVar('roomID', 0);
            if (empty($roomID) || !isset($chatRooms[$roomID])) {
                $messageID = -30;
                break;
            }
            $user = Request::getVar('user', '');
            $tribe = Request::getVar('tribe', '');
            if (!empty($user)) {
                if (Chat::checkUserExists($user)) {
                    if (Chat::authAdd($roomID, $user)) {
                        $messageID = 14;
                        break;
                    } else {
                        $messageID = -44;
                        break;
                    }
                } else {
                    $messageID = -45;
                    break;
                }
            } else {
                if (!empty($tribe)) {
                    $chatTribeID = Tribe::getID($tribe);
                    if ($tribe !== false) {
                        if (Chat::authAddTribe($roomID, $chatTribeID)) {
                            $messageID = 15;
                            break;
                        } else {
                            $messageID = -44;
                            break;
                        }
                    } else {
                        $messageID = -45;
                        break;
                    }
                } else {
                    $messageID = -30;
                    break;
                }
            }
            break;
            /****************************************************************************************************
            *
            * Userrechte entfernen
            *
            ****************************************************************************************************/
        /****************************************************************************************************
        *
        * Userrechte entfernen
        *
        ****************************************************************************************************/
        case TRIBE_ACTION_CHAT_REMOVE:
            if (!$userAuth['manage_chat'] && !$userAuth['isLeader']) {
                $messageID = -1;
                break;
            }
            $roomID = Request::getVar('roomID', 0);
            if (empty($roomID) || !isset($chatRooms[$roomID])) {
                $messageID = -30;
                break;
            }
            $removeIDs = Request::getVar('removeIDs', array('' => ''));
            if (!empty($removeIDs)) {
                if (Chat::authDel($roomID, $removeIDs)) {
                    $messageID = 16;
                    break;
                } else {
                    $messageID = -47;
                    break;
                }
            } else {
                $messageID = -30;
                break;
            }
            break;
    }
    /****************************************************************************************************
     *
     * Auswahl der Regierungsformen
     *
     ****************************************************************************************************/
    $tribeGovernment = TribeGovernment::getGovernment($tribeID);
    if (empty($tribeGovernment)) {
        $template->throwError('Fehler beim Auslesen der Regierungsform.');
        return;
    }
    $tribeGovernment['name'] = $GLOBALS['governmentList'][$tribeGovernment['governmentID']]['name'];
    if ($userAuth['isLeader'] && $tribeGovernment['isChangeable']) {
        $GovernmentSelect = array();
        foreach ($GLOBALS['governmentList'] as $governmentID => $typeData) {
            $GovernmentSelect[] = array('value' => $governmentID, 'selected' => $governmentID == $tribeGovernment['governmentID'] ? 'selected="selected"' : '', 'name' => $typeData['name']);
        }
        $template->addVar('government_select', $GovernmentSelect);
    } else {
        $template->addVar('government_data', array('name' => $tribeGovernment['name'], 'duration' => $tribeGovernment['time']));
    }
    if ($tribeGovernment['governmentID'] == 2) {
        $choice = TribeLeader::getVotes($_SESSION['player']->playerID);
        $votes = TribeLeader::getElection($tribeID);
        $possibleChoices = $tribeMembers;
        $possibleChoices[0] = array('name' => _('Keiner'), 'playerID' => 0);
        foreach ($possibleChoices as $key => $value) {
            if ($key == $choice) {
                $possibleChoices[$key]['selected'] = 'selected="selected"';
            }
        }
        ksort($possibleChoices);
        $template->addVars(array('goverment_votes_list' => $votes, 'goverment_choice_list' => $possibleChoices, 'goverment_choice_name' => $GLOBALS['leaderDeterminationList'][$tribeGovernment['governmentID']]['name'], 'goverment_choice_description' => $GLOBALS['leaderDeterminationList'][$tribeGovernment['governmentID']]['description']));
    } else {
        $template->addVars(array('choose' => false, 'goverment_choice_message' => _('Ihr habt keinen Einfluss auf die Bestimmung des Stammesanführers.'), 'goverment_choice_name' => $GLOBALS['leaderDeterminationList'][$tribeGovernment['governmentID']]['name'], 'goverment_choice_description' => $GLOBALS['leaderDeterminationList'][$tribeGovernment['governmentID']]['description']));
    }
    /****************************************************************************************************
     *
     * Auslesen der Stammesnachrichten
     *
     ****************************************************************************************************/
    $messagesClass = new Messages();
    $messageAry = array();
    $messages = TribeMessage::getMessages($tribeID);
    if (sizeof($messages)) {
        foreach ($messages as $msgID => $messageData) {
            $messageAry[] = array('time' => $messageData['date'], 'subject' => $messageData['messageSubject'], 'message' => $messagesClass->p($messageData['messageText']));
        }
        $template->addVar('tribe_messages', $messageAry);
    }
    /****************************************************************************************************
     *
     * Auslesen und Anzeigen der Beziehungen
     *
     ****************************************************************************************************/
    $relationsAll = TribeRelation::getRelations($tribeID);
    $relationsWar = TribeRelation::getWarRelations($tribeID);
    // Allgemein -> Allgemeines
    // Regierung -> Beziehungen
    $relations = $relationAlly = $relations_info = array();
    foreach ($relationsAll['own'] as $target => $targetData) {
        if (in_array($targetData['relationType'], Config::$tribeRelationAlly)) {
            $relationAlly[] = $targetData;
        }
        if (!$targetData['changeable']) {
            $relations_info[$target] = array('tag' => $targetData['targetTag'], 'relation' => $GLOBALS['relationList'][$targetData['relationType']]['name'], 'duration' => $targetData['time'], 'their_relation' => isset($relationsAll['other'][$target]) ? $GLOBALS['relationList'][$relationsAll['other'][$target]['relationType']]['name'] : $GLOBALS['relationList'][0]['name']);
            // war?
            if (isset($relationsWar[$target])) {
                $relations_info[$target]['war'] = true;
                $relations_info[$target]['fame_own'] = $relationsWar[$target]['fame_own'];
                $relations_info[$target]['fame_target'] = $relationsWar[$target]['fame_target'];
                $relations_info[$target]['percent_actual'] = $relationsWar[$target]['percent_actual'];
            }
        } else {
            $relations[$target] = array('tag' => $targetData['targetTag'], 'target_points' => $targetData['target_rankingPoints'], 'tribe_points' => $targetData['tribe_rankingPoints'], 'their_relation' => isset($relationsAll['other'][$target]) ? $GLOBALS['relationList'][$relationsAll['other'][$target]['relationType']]['name'] : $GLOBALS['relationList'][0]['name'], 'relation_type' => $targetData['relationType']);
            if (isset($relationsWar[$target])) {
                $relations[$target]['war'] = true;
                $relations[$target]['fame_own'] = $relationsWar[$target]['fame_own'];
                $relations[$target]['fame_target'] = $relationsWar[$target]['fame_target'];
                $relations[$target]['percent_actual'] = $relationsWar[$target]['percent_actual'];
                if ($relationsWar[$target]['isForcedSurrenderTheoreticallyPossible']) {
                    $relations[$target]['isForcePossible'] = true;
                    $relations[$target]['percent_estimated'] = $relationsWar[$target]['percent_estimated'];
                }
            }
        }
    }
    foreach ($relationsAll['other'] as $target => $targetData) {
        if (isset($relationsAll['own'][$target])) {
            continue;
        }
        $relations[$target] = array('tag' => $targetData['targetTag'], 'their_relation' => $GLOBALS['relationList'][$relationsAll['other'][$target]['relationType']]['name'], 'duration' => $targetData['time'], 'relation_type' => 0);
    }
    /****************************************************************************************************
     *
     * Stammeslager
     *
     ****************************************************************************************************/
    $tribeStorageValues = $tribeStorage = array();
    $dontePossible = false;
    foreach ($GLOBALS['resourceTypeList'] as $resourceID => $resource) {
        if ($resource->maxTribeDonation == 0) {
            continue;
        }
        $tribeStorage[$resource->dbFieldName] = $tribeData[$resource->dbFieldName];
        $tribeStorageValues[$resource->dbFieldName]['resourceID'] = $resource->resourceID;
        $tribeStorageValues[$resource->dbFieldName]['name'] = $resource->name;
        $tribeStorageValues[$resource->dbFieldName]['value'] = $tribeData[$resource->dbFieldName];
        $tribeStorageValues[$resource->dbFieldName]['dbFieldName'] = $resource->dbFieldName;
        $tribeStorageValues[$resource->dbFieldName]['maxTribeDonation'] = $resource->maxTribeDonation;
        if (!isset($_SESSION['player']->donateLocked['tribe'][$resource->dbFieldName]) || empty($_SESSION['player']->donateLocked['tribe'][$resource->dbFieldName])) {
            $tribeStorageValues[$resource->dbFieldName]['lastDonate'] = '';
            $tribeStorageValues[$resource->dbFieldName]['donatePossible'] = true;
            $dontePossible = true;
        } else {
            $tribeStorageValues[$resource->dbFieldName]['lastDonate'] = date("d.m. H:i:s", $_SESSION['player']->donateLocked['tribe'][$resource->dbFieldName]);
            if ($_SESSION['player']->donateLocked['tribe'][$resource->dbFieldName] < time()) {
                $tribeStorageValues[$resource->dbFieldName]['donatePossible'] = true;
                $dontePossible = true;
            } else {
                $tribeStorageValues[$resource->dbFieldName]['donatePossible'] = false;
            }
        }
    }
    $template->addVars(array('tribeStorageValues' => $tribeStorageValues, 'donationInterval' => TRIBE_STORAGE_DONATION_INTERVAL, 'showTribeStorageDonations' => $dontePossible));
    /****************************************************************************************************
     *
     * Einzahlungen
     *
     ****************************************************************************************************/
    $donations = TribeDonation::getDonations($tribeID);
    $template->addVar('donations', $donations);
    /****************************************************************************************************
     *
     * Stammeswunder
     *
     ****************************************************************************************************/
    $wonders = array();
    $memberCount = count($tribeMembers);
    foreach ($GLOBALS['wonderTypeList'] as $wonder) {
        // exclude nonTribeWonders
        if (!$wonder->isTribeWonder || $wonder->nodocumentation) {
            continue;
        }
        // multiply costs with number of tribe members
        foreach ($wonder->resourceProductionCost as $prodID => $prod) {
            $wonder->resourceProductionCost[$prodID] = $prod * $memberCount;
        }
        foreach ($wonder->unitProductionCost as $prodID => $prod) {
            $wonder->unitProductionCost[$prodID] = $prod * $memberCount;
        }
        foreach ($wonder->buildingProductionCost as $prodID => $prod) {
            $wonder->buildingProductionCost[$prodID] = $prod * $memberCount;
        }
        $wonders[$wonder->wonderID] = array('dbFieldName' => $wonder->wonderID, 'name' => $wonder->name, 'wonder_id' => $wonder->wonderID, 'description' => $wonder->description);
        $wonders[$wonder->wonderID] = array_merge($wonders[$wonder->wonderID], parseCost($wonder, $tribeStorage));
        // show the building link ?!
        if (isset($tribeData['wonderLocked'][$wonder->wonderID]) && $tribeData['wonderLocked'][$wonder->wonderID] > time()) {
            $wonders[$wonder->wonderID]['no_build_msg'] = sprintf(_('Das Wunder ist noch gesperrt bis: %s'), date("d. m. H:i:s", $tribeData['wonderLocked'][$wonder->wonderID]));
        } else {
            if ($wonders[$wonder->wonderID]['notenough']) {
                $wonders[$wonder->wonderID]['no_build_msg'] = _('Zu wenig Rohstoffe');
            } else {
                $wonders[$wonder->wonderID]['build_link'] = true;
            }
        }
    }
    /****************************************************************************************************
     *
     * Chat
     *
     ****************************************************************************************************/
    $userRooms = Chat::getUsersByTribeID($tribeID);
    foreach ($chatRooms as $id => $data) {
        if (!isset($userRooms[$id]) || empty($userRooms[$id])) {
            continue;
        }
        $chatRooms[$id]['auth'] = $userRooms[$id];
    }
    /****************************************************************************************************
     *
     * Übergabe ans Template
     *
     ****************************************************************************************************/
    $template->addVars(array('tribe_name' => $tribeData['name'], 'tribe_tag' => $tribeData['tag'], 'tribe_avatar' => $tribeData['avatar'], 'tribe_description' => $tribeData['description'], 'tribe_leader_name' => $tribeData['leaderName'], 'tribe_leader_id' => $tribeData['leaderID'], 'tribe_members' => $tribeMembers, 'tribe_members_count' => strval($memberCount), 'government_name' => $GLOBALS['governmentList'][$tribeData['governmentID']]['name'], 'is_auth' => $userAuth, 'relations' => isset($relations) ? $relations : array(), 'relations_ally' => $relationAlly, 'relations_list' => $GLOBALS['relationList'], 'relations_info' => $relations_info, 'relations_war' => !empty($relationsWar) ? true : false, 'wonders' => $wonders, 'chat_rooms' => $chatRooms, 'status_msg' => isset($messageID) ? $messageText[$messageID] : '', 'tribe_action_auth' => TRIBE_ACTION_AUTH, 'tribe_action_chat_add' => TRIBE_ACTION_CHAT_ADD, 'tribe_action_chat_remove' => TRIBE_ACTION_CHAT_REMOVE, 'tribe_action_choose_leader' => TRIBE_ACTION_CHOOSE_LEADER, 'tribe_action_donate' => TRIBE_ACTION_DONATE, 'tribe_action_goverment' => TRIBE_ACTION_GOVERMENT, 'tribe_action_leave' => TRIBE_ACTION_LEAVE, 'tribe_action_message' => TRIBE_ACTION_MESSAGE, 'tribe_action_relation' => TRIBE_ACTION_RELATION, 'tribe_action_update' => TRIBE_ACTION_UPDATE, 'tribe_action_wonder' => TRIBE_ACTION_WONDER, 'tribe_action_kick' => TRIBE_ACTION_KICK));
}