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; }
function digest_getMovements($meineHoehlen, $doNotShow, $showDetails) { global $resourceTypeList, $unitTypeList, $params, $db, $ua_movements; // caveIDs einsammeln $caveIDs = array(); foreach ($meineHoehlen as $caveID => $value) { $caveIDs[] = $caveID; } $str_caveIDs = implode(",", $caveIDs); // Bewegungen besorgen $query = "SELECT * " . "FROM Event_movement " . "WHERE (source_caveID IN ({$str_caveIDs}) OR (target_caveID IN ({$str_caveIDs}))) " . "ORDER BY event_end ASC"; $dbresult = $db->query($query); if (!$dbresult) { return array(); } // bewegungen durchgehen $result = array(); while ($row = $dbresult->nextrow(MYSQL_ASSOC)) { // "do not show" movements should not be shown // ADDED by chris--- for returns if (!$params->SESSION->user['show_returns']) { if (in_array($row['movementID'], $doNotShow)) { continue; } } // is own movement? $row['isOwnMovement'] = in_array($row['caveID'], $caveIDs); ///////////////////////////////// // 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($meineHoehlen[$row['source_caveID']]) * $row['speedFactor']; $distance = time() - (time_timestampToTime($row['event_end']) - getDistanceByID($srcID, $destID) * $row['speedFactor']); } else { $sichtweite = getVisionRange($meineHoehlen[$row['target_caveID']]) * $row['speedFactor']; $distance = ceil((time_timestampToTime($row['event_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($meineHoehlen[$row['target_caveID']]) * $row['speedFactor']; $distance = ceil((time_timestampToTime($row['event_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 ($unitTypeList as $unitType) { if ($unitType->visible) { $anzahl_sichtbarer_einheiten += $row[$unitType->dbFieldName]; } } if ($anzahl_sichtbarer_einheiten == 0) { continue; } } } $tmp = array('eventID' => $row['event_movementID'], 'caveID' => $row['caveID'], 'source_caveID' => $row['source_caveID'], 'target_caveID' => $row['target_caveID'], 'movementID' => $row['movementID'], 'event_start' => date("d.m.Y H:i:s", time_timestampToTime($row['event_start'])), 'event_end' => date("d.m.Y H:i:s", time_timestampToTime($row['event_end'])), 'isOwnMovement' => intval($row['isOwnMovement']), 'seconds_before_end' => time_timestampToTime($row['event_end']) - time(), 'movementID_description' => $ua_movements[$row['movementID']]->description); // Quelldaten $source = digest_getCaveNameAndOwnerByCaveID($row['source_caveID']); foreach ($source as $key => $value) { $tmp['source_' . $key] = $value; } // Zieldaten $target = digest_getCaveNameAndOwnerByCaveID($row['target_caveID']); foreach ($target as $key => $value) { $tmp['target_' . $key] = $value; } // ***** Einheiten, Rohstoffe und Artefakte ***** if ($showDetails) { if ($row['artefactID']) { $tmp['ARTEFACT'] = artefact_getArtefactByID($row['artefactID']); } $units = array(); foreach ($unitTypeList as $value) { if (!$row[$value->dbFieldName]) { continue; } if (!$row['isOwnMovement'] && !$value->visible) { continue; } $units[] = array('name' => $value->name, 'value' => $row[$value->dbFieldName]); } if (sizeof($units)) { $tmp['UNITS'] = $units; } $resources = array(); foreach ($resourceTypeList as $value) { if (!$row[$value->dbFieldName]) { continue; } $resources[] = array('name' => $value->name, 'value' => $row[$value->dbFieldName]); } if (sizeof($resources)) { $tmp['RESOURCES'] = $resources; } if ($row['isOwnMovement'] && $ua_movements[$row['movementID']]->returnID != -1 && !$row['artefactID'] && !$row['blocked']) { $tmp['CANCEL'] = array("modus" => MOVEMENT, "eventID" => $row['event_movementID']); } } $result[] = $tmp; } return $result; }
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; }