예제 #1
0
파일: digest.inc.php 프로젝트: norter/Game
function digest_getMovements($ownCave, $doNotShow, $showDetails)
{
    global $db;
    // get movements
    $ua_movements = Movement::getMovements();
    // caveIDs einsammeln
    $caveIDs = implode(', ', array_map(array($db, 'quote'), array_keys($ownCave)));
    // Bewegungen besorgen
    $query = "SELECT *\n            FROM " . EVENT_MOVEMENT_TABLE . "\n            WHERE source_caveID IN (" . $caveIDs . ")\n              OR target_caveID IN (" . $caveIDs . ")\n            ORDER BY end ASC, event_movementID ASC";
    if (!($sql = $db->query($query))) {
        return array();
    }
    $rows = $sql->fetchAll();
    $sql->closeCursor();
    // bewegungen durchgehen
    $result = array();
    foreach ($rows as $row) {
        // "do not show" movements should not be shown
        if (in_array($row['movementID'], $doNotShow)) {
            continue;
        }
        // is own movement?
        $row['isOwnMovement'] = in_array($row['caveID'], array_keys($ownCave));
        /////////////////////////////////
        // SICHTWEITE BESCHRÄNKEN
        /* We got some problems, as reverse movements should not ALWAYS be visible.
         * For example a transport reverse movement should be visible, but a
         * spy reverse movement should not...
         * As a work around we will fix it by not showing any adverse reverse movement.
         *
         * The original code is following...
        
            if (!$row['isOwnMovement']){
        
              if ($ua_movements[$row['movementID']]->returnID == -1){
                $sichtweite = getVisionRange($ownCave[$row['source_caveID']]) * $row['speedFactor'];
                $distance = time() - (time_fromDatetime($row['end']) - getDistanceByID($srcID, $destID) * $row['speedFactor']);
              } else {
                $sichtweite = getVisionRange($ownCave[$row['target_caveID']]) * $row['speedFactor'];
                $distance = ceil((time_fromDatetime($row['end']) - time())/60);
              }
        
              if ($sichtweite < $distance) continue;
            }
         */
        // compute visibility
        if (!$row['isOwnMovement']) {
            // don't show adverse reverse movements
            if ($ua_movements[$row['movementID']]->returnID == -1) {
                continue;
            }
            $sichtweite = getVisionRange($ownCave[$row['target_caveID']]) * $row['speedFactor'];
            $distance = ceil((time_fromDatetime($row['end']) - time()) / 60);
            if ($sichtweite < $distance) {
                continue;
            }
        }
        /////////////////////////////////
        // ***** fremde unsichtbare bewegung *****
        if ($row['isOwnMovement'] == 0) {
            if ($ua_movements[$row['movementID']]->mayBeInvisible) {
                $anzahl_sichtbarer_einheiten = 0;
                foreach ($GLOBALS['unitTypeList'] as $unitType) {
                    if ($unitType->visible) {
                        $anzahl_sichtbarer_einheiten += $row[$unitType->dbFieldName];
                    }
                }
                if ($anzahl_sichtbarer_einheiten == 0) {
                    continue;
                }
            }
        }
        $tmp = array('event_id' => $row['event_movementID'], 'cave_id' => $row['caveID'], 'source_cave_id' => $row['source_caveID'], 'target_cave_id' => $row['target_caveID'], 'movement_id' => $row['movementID'], 'event_start' => time_fromDatetime($row['start']), 'event_start_date' => time_formatDatetime($row['start']), 'event_end' => time_fromDatetime($row['end']), 'event_end_date' => time_formatDatetime($row['end']), 'isOwnMovement' => intval($row['isOwnMovement']), 'seconds_before_end' => time_fromDatetime($row['end']) - time(), 'movement_id_description' => $ua_movements[$row['movementID']]->description);
        // Quelldaten
        $source = getCaveNameAndOwnerByCaveID($row['source_caveID']);
        foreach ($source as $key => $value) {
            $tmp['source_' . $key] = $value;
        }
        // Zieldaten
        $target = getCaveNameAndOwnerByCaveID($row['target_caveID']);
        foreach ($target as $key => $value) {
            $tmp['target_' . $key] = $value;
        }
        // ***** Einheiten, Rohstoffe und Artefakte *****
        if ($showDetails) {
            // show artefact
            if ($row['artefactID']) {
                $tmp['artefact'] = artefact_getArtefactByID($row['artefactID']);
            }
            // show hero
            if ($row['heroID']) {
                $tmp['hero'] = "Held läuft mit!";
            }
            // eval(GameConstants::EXPOSE_INVISIBLE)
            // FIXME (mlunzena): oben holen wir schon bestimmte Höhlendaten,
            //                   das sollte man zusammenfassen..
            $target = getCaveByID($row['target_caveID']);
            $expose = eval('return ' . formula_parseToPHP(GameConstants::EXPOSE_INVISIBLE . ";", '$target'));
            // show units
            $units = array();
            foreach ($GLOBALS['unitTypeList'] as $unit) {
                // this movement does not contain units of that type
                if (!$row[$unit->dbFieldName]) {
                    continue;
                }
                // expose invisible units
                //   if it is your own move
                //   if unit is visible
                if (!$row['isOwnMovement'] && !$unit->visible) {
                    // if target cave's EXPOSEINVISIBLE is > than exposeChance
                    if ($expose <= $row['exposeChance']) {
                        // do not expose
                        continue;
                    } else {
                        // do something
                        // for example:
                        // $row[$unit->dbFieldName] *= 2.0 * (double)rand() / (double)getRandMax();
                    }
                }
                $units[] = array('unitID' => $unit->unitID, 'dbFieldName' => $unit->dbFieldName, 'name' => $unit->name, 'value' => $ua_movements[$row['movementID']]->fogUnit && !$row['isOwnMovement'] ? calcFogUnit($row[$unit->dbFieldName]) : $row[$unit->dbFieldName]);
            }
            if (sizeof($units)) {
                $tmp['units'] = $units;
            }
            $resources = array();
            foreach ($GLOBALS['resourceTypeList'] as $resource) {
                if (!$row[$resource->dbFieldName]) {
                    continue;
                }
                $resources[] = array('name' => $resource->name, 'dbFieldName' => $resource->dbFieldName, 'value' => $ua_movements[$row['movementID']]->fogResource && !$row['isOwnMovement'] ? calcFogResource($row[$resource->dbFieldName]) : $row[$resource->dbFieldName]);
            }
            if (sizeof($resources)) {
                $tmp['resources'] = $resources;
            }
            if ($row['isOwnMovement'] && $ua_movements[$row['movementID']]->returnID != -1 && !$row['artefactID'] && !$row['blocked']) {
                $tmp['cancel'] = array("modus" => UNIT_MOVEMENT, "eventID" => $row['event_movementID']);
            }
        }
        $result[] = $tmp;
    }
    return $result;
}
예제 #2
0
function export_movement_irc($movementID)
{
    global $db;
    require_once 'lib/Movement.php';
    require_once 'include/digest.inc.php';
    // gather data
    $ua_movements = Movement::getMovements();
    $move = export_getSingleMovement($movementID);
    if (!sizeof($move)) {
        return 'Es wurde keine Bewegung gefunden!';
    }
    // get Cave data
    $sourceCaveData = getCaveNameAndOwnerByCaveID($move['source_caveID']);
    $targetCaveData = getCaveNameAndOwnerByCaveID($move['target_caveID']);
    // check if it's a player related movement
    if ($sourceCaveData['player_name'] !== $_SESSION['player']->name && $targetCaveData['player_name'] !== $_SESSION['player']->name) {
        return 'Nur eigene Bewegungen erlaubt!';
    }
    // artefact data
    $artefactData = array();
    if ($move['artefactID'] != 0) {
        $artefactData = artefact_getArtefactByID($move['artefactID']);
    }
    // header
    $header = "Bewegungsart: 4" . $ua_movements[$move['movementID']]->description . "\n";
    $header .= "Startzeitpunkt:4 " . time_formatDatetime($move['start']) . "\n";
    $header .= "Endzeitpunkt:4 " . time_formatDatetime($move['end']) . "\n";
    // movement source
    $source = "Starthöhle: 4" . $sourceCaveData['cave_name'] . " ";
    $source .= " (" . $sourceCaveData['xCoord'] . "|" . $sourceCaveData['yCoord'] . ") ";
    if ($sourceCaveData['player_name']) {
        $source .= "des Spielers  4" . $sourceCaveData['player_name'] . " ";
        $source .= "aus dem Stamme 4" . $sourceCaveData['player_tribe'] . " ";
    }
    $source .= "\n";
    // movement target
    $target = "Zielhöhle: 4" . $targetCaveData['cave_name'];
    $target .= " (" . $targetCaveData['xCoord'] . "|" . $targetCaveData['yCoord'] . ") ";
    if ($targetCaveData['player_name']) {
        $target .= "des Spielers 4 " . $targetCaveData['player_name'] . " ";
        $target .= "aus dem Stamme 4" . $targetCaveData['player_tribe'] . " ";
    }
    $target .= "\n";
    // units
    $units = "Einheiten: ";
    foreach ($GLOBALS['unitTypeList'] as $unitsID => $unitDetail) {
        if ($move[$unitDetail->dbFieldName] > 0) {
            if ($move['isOwnMovement'] || $unitDetail->visible) {
                $units .= $unitDetail->name . ": " . ($ua_movements[$move['movementID']]->fogUnit && !$move['isOwnMovement'] ? calcFogUnit($move[$unitDetail->dbFieldName]) : $move[$unitDetail->dbFieldName]) . ", ";
            }
        }
    }
    $units = substr($units, 0, -2);
    // resources
    $resources = "";
    foreach ($GLOBALS['resourceTypeList'] as $resourceID => $resourceDetail) {
        if ($move[$resourceDetail->dbFieldName] > 0) {
            $resources .= $resourceDetail->name . ": " . ($ua_movements[$move['movementID']]->fogResource && !$move['isOwnMovement'] ? calcFogResource($move[$resourceDetail->dbFieldName]) : $move[$resourceDetail->dbFieldName]) . ", ";
        }
    }
    if ($resources !== "") {
        $resources = "transportierte Rohstoffe: " . $resources;
        $resources = substr($resources, 0, -2);
    }
    // Artefacts
    $artefact = '';
    if ($move['artefactID'] != 0) {
        $artefact = "transportierte Artefakte: " . $artefactData['name'];
    }
    // Hero
    $hero = '';
    if ($move['heroID'] != 0 && $move['isOwnMovement']) {
        $hero = "Held läuft mit!";
    }
    $irc = "";
    $irc .= $header;
    $irc .= $source;
    $irc .= $target . "\n";
    $irc .= $units . "\n";
    $irc .= $resources . "\n";
    $irc .= $artefact . "\n";
    $irc .= $hero . "\n";
    return $irc;
}
예제 #3
0
function digest_getMovements($ownCave, $doNotShow, $showDetails)
{
    global $db;
    // get movements
    $ua_movements = Movement::getMovements();
    // caveIDs einsammeln
    $caveIDs = implode(', ', array_map(array($db, 'quote'), array_keys($ownCave)));
    $targetExtraFilds = formula_parseToSelectSQL(GameConstants::EXPOSE_INVISIBLE);
    $sqlExtra = array();
    foreach ($targetExtraFilds as $field) {
        $sqlTargetExtra[] = 'tc.' . $field . ' AS target_' . $field;
    }
    $sql = $db->prepare("SELECT em.*, sc.name AS source_cave_name, sp.name AS source_player_name, st.tag AS source_player_tribe, sc.xCoord AS source_xCoord, sc.yCoord AS source_yCoord, tc.name AS target_cave_name, tp.name AS target_player_name, tt.tag AS target_player_tribe, tc.xCoord AS target_xCoord, tc.yCoord AS target_yCoord " . (!empty($sqlTargetExtra) ? ', ' . implode(', ', $sqlTargetExtra) : '') . "\n                       FROM " . EVENT_MOVEMENT_TABLE . " em\n                         LEFT JOIN " . CAVE_TABLE . " sc ON sc.caveID = em.source_caveID\n                         LEFT JOIN " . PLAYER_TABLE . " sp ON sp.playerID = sc.playerID\n                         LEFT JOIN " . TRIBE_TABLE . " st ON st.tribeID = sp.tribeID\n                         LEFT JOIN " . CAVE_TABLE . " tc ON tc.caveID = em.target_caveID\n                         LEFT JOIN " . PLAYER_TABLE . " tp ON tp.playerID = tc.playerID\n                         LEFT JOIN " . TRIBE_TABLE . " tt ON tt.tribeID = tp.tribeID\n                       WHERE em.source_caveID IN (" . $caveIDs . ")\n                         OR em.target_caveID IN (" . $caveIDs . ")\n                       ORDER BY em.end ASC, em.event_movementID ASC");
    if (!$sql->execute()) {
        return array();
    }
    $rows = $sql->fetchAll(PDO::FETCH_ASSOC);
    $sql->closeCursor();
    // bewegungen durchgehen
    $result = array();
    foreach ($rows as $row) {
        // "do not show" movements should not be shown
        if (in_array($row['movementID'], $doNotShow)) {
            continue;
        }
        // is own movement?
        $row['isOwnMovement'] = in_array($row['caveID'], array_keys($ownCave));
        /////////////////////////////////
        // SICHTWEITE BESCHRÄNKEN
        /* We got some problems, as reverse movements should not ALWAYS be visible.
         * For example a transport reverse movement should be visible, but a
         * spy reverse movement should not...
         * As a work around we will fix it by not showing any adverse reverse movement.
         *
         * The original code is following...
        
            if (!$row['isOwnMovement']){
        
              if ($ua_movements[$row['movementID']]->returnID == -1){
                $sichtweite = getVisionRange($ownCave[$row['source_caveID']]) * $row['speedFactor'];
                $distance = time() - (time_fromDatetime($row['end']) - getDistanceByID($srcID, $destID) * $row['speedFactor']);
              } else {
                $sichtweite = getVisionRange($ownCave[$row['target_caveID']]) * $row['speedFactor'];
                $distance = ceil((time_fromDatetime($row['end']) - time())/60);
              }
        
              if ($sichtweite < $distance) continue;
            }
         */
        // compute visibility
        if (!$row['isOwnMovement']) {
            // don't show adverse reverse movements
            if ($ua_movements[$row['movementID']]->returnID == -1) {
                continue;
            }
            $sichtweite = getVisionRange($ownCave[$row['target_caveID']]) * $row['speedFactor'];
            $distance = ceil((time_fromDatetime($row['end']) - time()) / 60);
            if ($sichtweite < $distance) {
                continue;
            }
        }
        /////////////////////////////////
        // ***** fremde unsichtbare bewegung *****
        if ($row['isOwnMovement'] == 0) {
            if ($ua_movements[$row['movementID']]->mayBeInvisible) {
                $anzahl_sichtbarer_einheiten = 0;
                foreach ($GLOBALS['unitTypeList'] as $unitType) {
                    if ($unitType->visible) {
                        $anzahl_sichtbarer_einheiten += $row[$unitType->dbFieldName];
                    }
                }
                if ($anzahl_sichtbarer_einheiten == 0) {
                    continue;
                }
            }
        }
        $tmp = array('event_id' => $row['event_movementID'], 'cave_id' => $row['caveID'], 'source_cave_id' => $row['source_caveID'], 'target_cave_id' => $row['target_caveID'], 'movement_id' => $row['movementID'], 'event_start' => time_fromDatetime($row['start']), 'event_start_date' => time_formatDatetime($row['start']), 'event_end' => time_fromDatetime($row['end']), 'event_end_date' => time_formatDatetime($row['end']), 'isOwnMovement' => intval($row['isOwnMovement']), 'seconds_before_end' => time_fromDatetime($row['end']) - time(), 'movement_id_description' => $ua_movements[$row['movementID']]->description, 'source_cave_name' => $row['source_cave_name'], 'source_player_name' => $row['source_player_name'], 'source_player_tribe' => $row['source_player_tribe'], 'source_xCoord' => $row['source_xCoord'], 'source_yCoord' => $row['source_yCoord'], 'target_cave_name' => $row['target_cave_name'], 'target_player_name' => $row['target_player_name'], 'target_player_tribe' => $row['target_player_tribe'], 'target_xCoord' => $row['target_xCoord'], 'target_yCoord' => $row['target_yCoord']);
        // ***** Einheiten, Rohstoffe und Artefakte *****
        if ($showDetails) {
            // show artefact
            if ($row['artefactID']) {
                $tmp['artefact'] = artefact_getArtefactByID($row['artefactID']);
            }
            // show hero
            if ($row['heroID']) {
                $tmp['hero'] = "Held läuft mit!";
            }
            // eval(GameConstants::EXPOSE_INVISIBLE)
            // FIXME (mlunzena): oben holen wir schon bestimmte Höhlendaten,
            //                   das sollte man zusammenfassen..
            foreach ($targetExtraFilds as $field) {
                $target[$field] = $row['target_' . $field];
            }
            $expose = eval('return ' . formula_parseToPHP(GameConstants::EXPOSE_INVISIBLE . ";", '$target'));
            // show units
            $units = array();
            foreach ($GLOBALS['unitTypeList'] as $unit) {
                // this movement does not contain units of that type
                if (!$row[$unit->dbFieldName]) {
                    continue;
                }
                // expose invisible units
                //   if it is your own move
                //   if unit is visible
                if (!$row['isOwnMovement'] && !$unit->visible) {
                    // if target cave's EXPOSEINVISIBLE is > than exposeChance
                    if ($expose <= $row['exposeChance']) {
                        // do not expose
                        continue;
                    } else {
                        // do something
                        // for example:
                        // $row[$unit->dbFieldName] *= 2.0 * (double)rand() / (double)getRandMax();
                    }
                }
                $units[] = array('unitID' => $unit->unitID, 'dbFieldName' => $unit->dbFieldName, 'name' => $unit->name, 'value' => $ua_movements[$row['movementID']]->fogUnit && !$row['isOwnMovement'] ? calcFogUnit($row[$unit->dbFieldName]) : $row[$unit->dbFieldName]);
            }
            if (sizeof($units)) {
                $tmp['units'] = $units;
            }
            $resources = array();
            foreach ($GLOBALS['resourceTypeList'] as $resource) {
                if (!$row[$resource->dbFieldName]) {
                    continue;
                }
                $resources[] = array('name' => $resource->name, 'dbFieldName' => $resource->dbFieldName, 'value' => $ua_movements[$row['movementID']]->fogResource && !$row['isOwnMovement'] ? calcFogResource($row[$resource->dbFieldName]) : $row[$resource->dbFieldName]);
            }
            if (sizeof($resources)) {
                $tmp['resources'] = $resources;
            }
            if ($row['isOwnMovement'] && $ua_movements[$row['movementID']]->returnID != -1 && !$row['artefactID'] && !$row['blocked']) {
                $tmp['cancel'] = array("modus" => UNIT_MOVEMENT, "eventID" => $row['event_movementID']);
            }
        }
        $result[] = $tmp;
    }
    return $result;
}