예제 #1
0
파일: Map.php 프로젝트: Toxicat/dolumar
 public function getObjects($squarePoints, $radius)
 {
     $profiler = Neuron_Profiler_Profiler::getInstance();
     // Let's replace this :)
     $out = array();
     $buildingSQL = Dolumar_Map_Map::getBuildingsFromLocations($squarePoints, max($radius, 3));
     $objects = array();
     foreach ($buildingSQL as $buildingV) {
         $profiler->start('Initializing building');
         $profiler->start('Fetching building race object');
         $race = Dolumar_Races_Race::getRace($buildingV['race']);
         $profiler->stop();
         $profiler->start('Fetching building object');
         $b = Dolumar_Buildings_Building::getBuilding($buildingV['buildingType'], $race, $buildingV['xas'], $buildingV['yas']);
         $village = Dolumar_Players_Village::getVillage($buildingV['village']);
         $b->setVillage($village);
         $profiler->stop();
         $profiler->start('Setting data');
         $b->setData($buildingV['bid'], $buildingV);
         if ($buildingV['destroyDate'] > 0 && $buildingV['destroyDate'] < NOW) {
             $b->setDestroyed(true);
         }
         $profiler->stop();
         $profiler->start('Assigning building to array');
         //$buildings[floor ($buildingV['xas'])][floor ($buildingV['yas'])][] = $b;
         $objects[] = new Dolumar_Map_Object($b);
         $profiler->stop();
         $profiler->stop();
     }
     return $objects;
 }
예제 #2
0
 public static function output_distance($distance, $abbrevation = false, $round = false)
 {
     if ($distance === false) {
         return null;
     } else {
         $distance = Dolumar_Map_Map::tile2league($distance);
         if ($round) {
             $distance = round($distance);
         } else {
             $distance = round($distance, 1);
             if ($distance == floor($distance)) {
                 $distance .= '.0';
             }
         }
         return $distance . ($abbrevation ? 'L' : ' league');
     }
 }
예제 #3
0
파일: Map.php 프로젝트: Toxicat/dolumar
 public static function getSnapshot($x, $y, $width, $height, $zoom)
 {
     $stats = Neuron_Core_Stats::__getInstance();
     $fZoom = $zoom / 100;
     // Make a bigger image
     $width = $width / $fZoom;
     $height = $height / $fZoom;
     $floatZoom = 1;
     $tileSizeX = 200 * $floatZoom;
     $tileSizeY = $tileSizeX / 2;
     $halfTileX = $tileSizeX / 2;
     $halfTileY = $tileSizeY / 2;
     $offsetX = ceil($tileSizeX / 2);
     $offsetY = ceil($tileSizeY / 2);
     $loadExtra = 1;
     $switchpoint = max(ceil($width / ($tileSizeX * 1)), ceil($height / $tileSizeY));
     $im = imagecreatetruecolor($width, $height);
     list($startX, $startY) = self::getStartposition($x, $y, $width, $height, $tileSizeX, $tileSizeY);
     $locations = array(array($startX + $switchpoint / 2, $startY - $switchpoint / 2));
     // Load buildings from SQL
     $buildingSQL = Dolumar_Map_Map::getBuildingsFromLocations($locations, $switchpoint + 15);
     $buildings = array();
     foreach ($buildingSQL as $buildingV) {
         $race = Dolumar_Races_Race::getRace($buildingV['race']);
         $b = Dolumar_Buildings_Building::getBuilding($buildingV['buildingType'], $race, $buildingV['xas'], $buildingV['yas']);
         $village = Dolumar_Players_Village::getVillage($buildingV['village']);
         $b->setVillage($village);
         $b->setData($buildingV['bid'], $buildingV);
         $buildings[floor($buildingV['xas'])][floor($buildingV['yas'])][] = $b;
     }
     for ($i = 0 - $loadExtra; $i <= $switchpoint * 2; $i++) {
         if ($i > $switchpoint) {
             $offset = ($i - $switchpoint + 1) * 2;
         } else {
             $offset = 0;
         }
         $colStart = 0 - $i + $offset - $loadExtra;
         $colEnd = $i - $offset + $loadExtra + 1;
         //$output['regions'][$sQ]['tiles'][$i] = array ();
         $tx = $startX + $i;
         for ($j = $colStart; $j < $colEnd; $j++) {
             $ty = $startY - $j;
             $px = ($i - $j) * $offsetX;
             $py = ($i + $j) * $offsetY;
             // Check for building
             $hasBuildings = isset($buildings[$tx]) && isset($buildings[$tx][$ty]);
             $location = Dolumar_Map_Location::getLocation($tx, $ty, $hasBuildings);
             $image = $location->getImage();
             $sImagePath = IMAGE_PATH . 'tiles/' . $image['image'] . '.gif';
             //die ($sImagePath);
             self::drawSnapshotImage($im, $sImagePath, $px, $py, $floatZoom);
             //checkBuildings ($buildings, $sQ, $i, $j, $tx, $ty);
             if ($hasBuildings) {
                 foreach ($buildings[$tx][$ty] as $building) {
                     $short = $building->getIsoImage();
                     $url = $building->getImagePath();
                     $offset = $building->getTileOffset();
                     $fakeurl = IMAGE_PATH . 'sprites/' . $short . '.png';
                     //echo "---\n";
                     //echo $url . "\n";
                     //echo $fakeurl . "\n";
                     $oi = $i + $offset[0];
                     $oj = $j + $offset[1];
                     $pox = round(($oi - $oj) * floor($tileSizeX / 2));
                     $poy = round(($oi + $oj) * floor($tileSizeY / 2));
                     self::drawSnapshotImage($im, $url, $pox + $stats->get('offsetx', $short, 'images', 0) * $floatZoom, $poy + $stats->get('offsety', $short, 'images', 0) * $floatZoom, $floatZoom, false);
                 }
             }
         }
     }
     // Resize the image
     $newwidth = $width * $fZoom;
     $newheight = $height * $fZoom;
     $newimg = imagecreatetruecolor($newwidth, $newheight);
     imagecopyresampled($newimg, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
     return $newimg;
 }
예제 #4
0
 private function loadCache($x, $y)
 {
     if (!isset($this->aTiles[$x]) || !isset($this->aTiles[$x][$y])) {
         // Check the size of aTiles!
         if (memory_get_usage() > MAX_MEMORY_USAGE) {
             $this->aTiles = array();
         }
         $memcachename = $this->getCacheName($x, $y);
         list($startX, $startY, $endX, $endY) = $this->getArea($x, $y);
         $c = $this->objMemcache->getCache($memcachename);
         if ($c) {
             $c = $this->unpack($c, $startX, $startY);
             foreach ($c as $x => $v) {
                 if (!isset($this->aTiles[$x])) {
                     $this->aTiles[$x] = array();
                 }
                 foreach ($v as $y => $vv) {
                     $this->aTiles[$x][$y] = $vv;
                 }
             }
         } else {
             $tmparray = array();
             // Load all the data for this area
             for ($i = $startX; $i < $endX; $i++) {
                 $this->aTiles[$i] = array();
                 $tmparray[$i] = array();
                 for ($j = $startY; $j < $endY; $j++) {
                     $data = Dolumar_Map_Map::getFreshTileData($i, $j);
                     $this->aTiles[$i][$j] = $data;
                     $tmparray[$i][$j] = $data;
                 }
             }
             // Put these results in memcache
             $this->objMemcache->setCache($memcachename, $this->pack($tmparray, $startX, $startY));
         }
     }
     return $this->aTiles[$x][$y];
 }
예제 #5
0
 if (file_exists($file)) {
     if (filectime($file) > time() - 60 * 60 * 24 * 31) {
         $parseNew = isset($_GET['parseNew']);
         if ($parseNew) {
             unlink($file);
         } else {
             echo file_get_contents($file);
         }
     } else {
         unlink($file);
     }
 }
 if ($parseNew) {
     // Load buildings from SQL
     $points = array(array($_GET['x'] * $imageSize + $imageSize / 2, $_GET['y'] * $imageSize + $imageSize / 2));
     $buildingSQL = Dolumar_Map_Map::getBuildingsFromLocations($points, $imageSize);
     $buildings = array();
     foreach ($buildingSQL as $buildingV) {
         $race = Dolumar_Races_Race::getRace($buildingV['race']);
         $b = Dolumar_Buildings_Building::getBuilding($buildingV['buildingType'], $race, $buildingV['xas'], $buildingV['yas']);
         $b->setData($buildingV['bid'], $buildingV);
         $buildings[floor($buildingV['xas'])][floor($buildingV['yas'])][] = $b;
     }
     // Add buildings
     $startX = $_GET['x'] * $imageSize;
     $endX = $startX + $imageSize;
     $startY = $_GET['y'] * $imageSize;
     $endY = $startY + $imageSize;
     $im = imagecreate($imageSize, $imageSize);
     $i = 0;
     for ($x = $startX; $x <= $endX; $x++) {
예제 #6
0
 $areaToLoad = MAXMAPSTRAAL + MAXMAPSTRAAL * 0.1;
 // The whole wide world:
 $sizeX = $areaToLoad;
 $sizeY = $areaToLoad;
 $zoom = max(0, $zoom);
 $zoom = pow(2, $zoom);
 $dx = $areaToLoad * 2 / $zoom / $width;
 $dy = $areaToLoad * 2 / $zoom / $height;
 $startX = $areaToLoad * 2 / $zoom * $x - $areaToLoad;
 $startY = $areaToLoad * 2 / $zoom * $y - $areaToLoad;
 // Show all these pixels
 for ($i = 0; $i < $width; $i++) {
     for ($j = 0; $j < $height; $j++) {
         $lx = round($startX + $dx * $i);
         $ly = round($startY + $dy * $j);
         $location = Dolumar_Map_Map::getLocation($lx, $ly, false, false);
         $px = $i;
         $py = $height - $j;
         $c = $location->getHeightIntencity();
         $col = $location->getMapColor();
         $col[0] = floor($col[0] * $c);
         $col[1] = floor($col[1] * $c);
         $col[2] = floor($col[2] * $c);
         $color = color_cache($im, $col);
         imagesetpixel($im, $i, $j, $color);
     }
 }
 $locations = array(array($startX + 125, $startY + 125));
 // Load buildings from SQL
 /*
 $buildingSQL = Dolumar_Map_Map::getBuildingsFromLocations ($locations, 125);
예제 #7
0
파일: Battle.php 프로젝트: Toxicat/dolumar
 private function getChooseSpecialUnits($target, $squads, $error = null)
 {
     $page = new Neuron_Core_Template();
     $page->setTextSection('specialUnits', 'battle');
     $page->set('error', $error);
     $page->set('target', Neuron_Core_Tools::output_varchar($target->getName()));
     $page->set('targetId', $target->getId());
     $distance = Dolumar_Map_Map::getDistanceBetweenVillages($this->village, $target, false);
     $page->set('distance', Neuron_Core_Tools::output_distance($distance));
     foreach ($this->village->getAttackSlots($target) as $k => $v) {
         if (isset($squads[$k])) {
             $unitId = $squads[$k]->getSquad()->getId() . '_' . $squads[$k]->getUnitId();
             $page->addListValue('slots', array('id' => $k, 'unit' => $unitId));
         }
     }
     $duration = $this->village->battle->getMoveDuration($squads, $distance);
     if ($duration > 60 * 60 * 24) {
         $page->set('duration', $duration);
     }
     $honour = Dolumar_Battle_Battle::getHonourPenalty($this->village, $target);
     if ($honour > 0) {
         //$bigger = round ( ($this->village->getScore () / $target->getScore ()) * 100) - 100;
         $bigger = round(Dolumar_Battle_Battle::getSizeDifference($this->village, $target) * 100 - 100);
         $page->set('honour', $honour);
         $page->set('size', $bigger);
     }
     // Fetch thze special units
     $units = $this->village->getSpecialUnits();
     foreach ($units as $v) {
         $actions = $v->getEffects();
         // Prepare the actions
         $aActions = array();
         foreach ($actions as $action) {
             if ($action instanceof Dolumar_Effects_Battle) {
                 $aActions[] = array('name' => $action->getName(), 'id' => $action->getId(), 'cost' => Neuron_Core_Tools::resourceToText($action->getCost($v, $target), false, false, false, 'rune', false));
             }
         }
         if (count($aActions) > 0) {
             asort($aActions);
             // Add the special unit to the list
             $page->addListValue('specialunits', array('id' => $v->getId(), 'name' => Neuron_Core_Tools::output_varchar($v->getName(false, true)), 'actions' => $aActions));
         }
     }
     return $page->parse('battle/specialUnits.phpt');
 }
예제 #8
0
<?php

$village1 = Neuron_Core_Tools::getInput('_GET', 'village1', 'int');
$village2 = Neuron_Core_Tools::getInput('_GET', 'village2', 'int');
$v1 = Dolumar_Players_Village::getVillage($village1);
$v2 = Dolumar_Players_Village::getVillage($village2);
echo 'Calculating distance between ' . $v1->getName() . ' to ' . $v2->getName() . '<br />';
$l1 = $v1->buildings->getTownCenterLocation();
$l2 = $v2->buildings->getTownCenterLocation();
$distance = Dolumar_Map_Map::getDistanceBetweenVillages($v1, $v2);
$straight = Dolumar_Map_Map::calculateDistance($l1[0], $l1[1], $l2[0], $l2[1]);
$profiler = Neuron_Profiler_Profiler::getInstance();
echo '<h2>Profiler</h2>';
echo '<pre>';
echo $profiler;
echo '</pre>';
echo '<p>Distance: <strong>' . $distance . '</strong><br />';
echo 'Straight line distance: <strong>' . $straight . '</strong></p>';
예제 #9
0
파일: Player.php 프로젝트: Toxicat/dolumar
 public function calculateNewStartLocation($d, $race, $maxrange = MAXMAPSTRAAL, $minrange = null, $fCheckCallback = null)
 {
     $db = Neuron_Core_Database::__getInstance();
     $minbuildingradius = MAXBUILDINGRADIUS;
     if (is_array($d) && count($d) == 2 && is_numeric($d[0]) && is_numeric($d[1])) {
         // Location: find location close to this location
         $startX = floor($d[0]);
         $startY = floor($d[1]);
         if (sqrt($startX * $startX + $startY * $startY) > MAXMAPSTRAAL) {
             $startX = 0;
             $startY = 0;
         }
         $startRad = 0;
         $endRad = 2;
         // Radius should start at minimal distant between 2 villages ;-)
         if (isset($minrange)) {
             $radius = $minrange;
         } else {
             $radius = MAXBUILDINGRADIUS * 2;
         }
     } else {
         // $d is a string, search in one direction
         // e ne n wn w sw s es
         $radials = Dolumar_Map_Map::getRadialFromDirection($d);
         $startRad = $radials[0];
         $endRad = $radials[1];
         $startX = 0;
         $startY = 0;
         // Do the area trick
         // Count amount of town centers on the map
         $buildings = $db->select('map_buildings', array('COUNT(*) AS aantal'), "buildingType = 1");
         $towns = count($buildings) == 1 ? $buildings[0]['aantal'] : 0;
         $radius = ceil(abs(sqrt($towns / pi())) * MAXBUILDINGRADIUS * 2);
         $radius = min($radius, MAXMAPSTRAAL * 0.75);
         $fradius = $radius;
         // Now let's find the very first town center built
         $firstbuilding = $db->select('map_buildings', array('MIN(startDate) AS mStartDate'));
         $firstbuilding = count($firstbuilding) == 1 ? $firstbuilding[0]['mStartDate'] : 0;
         $month = 60 * 60 * 24 * 31;
         $month2 = 60 * 60 * 24 * 31 * 2;
         // Elke 2 maanden springen we terug naar het midden.
         $radiusChange = abs(time() - $firstbuilding + $month) % $month2 / $month2;
         $radius *= sin($radiusChange * pi());
         // Minimal building radius between non clan members
         $minbuildingradius = $minbuildingradius * 5;
     }
     // Fetch towncenter
     $townCenter = Dolumar_Buildings_Building::getBuilding(1, $race);
     $okay = false;
     $startRad *= pi();
     $endRad *= pi();
     $maxruns = 5000;
     $incr = ceil(MAXBUILDINGRADIUS / 5);
     while (!$okay) {
         // Max radius check
         if ($radius > $maxrange) {
             return false;
         }
         if ($maxruns < 0) {
             return false;
         }
         $maxruns--;
         // Random radiation
         $rad = mt_rand($startRad * 100000, $endRad * 100000) / 100000;
         $x = $startX + floor(sin($rad) * $radius);
         $y = $startY + floor(cos($rad) * $radius);
         // Check if location is valid
         $okay = $townCenter->checkBuildLocation(null, $x, $y, $minbuildingradius);
         $okay = $okay[0];
         if ($okay && isset($fCheckCallback)) {
             $okay = call_user_func($fCheckCallback, $x, $y);
         }
         // It not right: increase randius and take new random rad.
         $radius += $incr;
     }
     return array($x, $y, $radius);
 }
예제 #10
0
 private function commandMoveUnit($building, $unit)
 {
     $input = $this->getInputData();
     $id = isset($input['target']) ? intval($input['target']) : null;
     if ($id > 0 && $id != $unit->getLocation()->getId()) {
         // Calculate distance & duration
         $target = Dolumar_Players_Village::getVillage($id);
         if (!$target) {
             return '<p>Invalid input: target village not found.</p>';
         }
         if (isset($input['confirm'])) {
             $page = new Neuron_Core_Template();
             $page->setTextSection('moveUnit', 'thievery');
             $page->set('input', array('building' => $building->getId()));
             // Move the bloody unit
             $unit->moveUnit($target);
             return $page->parse('thieves/doneMoving.phpt');
         } else {
             $page = new Neuron_Core_Template();
             $page->setTextSection('moveUnit', 'thievery');
             $distance = Dolumar_Map_Map::getDistanceBetweenVillages($unit->getLocation(), $target);
             // Calculate duration
             $duration = $unit->getTravelDuration($distance);
             $page->set('input', array_merge($input, array('confirm' => 'true')));
             $page->set('distance', Neuron_Core_Tools::output_distance($distance));
             $page->set('duration', Neuron_Core_Tools::getDuration($duration));
             return $page->parse('thieves/moveThief.phpt');
         }
     } else {
         $structure = new Neuron_Structure_ChooseTarget($this->getInputData(), $this->village, true, true);
         $structure->setReturnData(array('building' => $building->getId()));
         return $structure->getHTML();
     }
 }
예제 #11
0
<?php 
echo '<h2>Current key</h2>';
echo '<p>Config key: "' . RANDMAPFACTOR . '"</p>';
if (isset($_POST['key'])) {
    $keys = explode(',', $_POST['key']);
    foreach ($keys as $key) {
        $key = trim($key);
        $GLOBALS['MAP_CONFIG_RANDMAPFACTOR'] = $key;
        echo '<h2>Checking hash "' . $key . '" against local cache:</h2>';
        echo '<ul>';
        // Check the first 25 square for a match
        for ($i = 0; $i < 2; $i++) {
            for ($j = 0; $j < 2; $j++) {
                $d1 = Dolumar_Map_Map::getLocation($i, $j, false, false);
                $d2 = Dolumar_Map_Map::getLocation($i, $j, false, true);
                // Check if equal
                $img1 = $d1->getImage();
                $img2 = $d2->getImage();
                echo '<li>';
                if ($d1->getHeight() == $d2->getHeight() && $img1['image'] == $img2['image']) {
                    echo '<span style="color: green;">Location ' . $i . ',' . $j . ' does match!</span>';
                } else {
                    echo '<span style="color: red;">Location ' . $i . ',' . $j . ' does not match (' . $img1['image'] . ' != ' . $img2['image'] . ').</span>';
                    echo '<pre>';
                    echo "Fresh data:\n";
                    print_r($d1);
                    echo "Cache:\n";
                    print_r($d2);
                    echo '</pre>';
                    break 2;
예제 #12
0
 private function calculateDirection($x, $y)
 {
     return Dolumar_Map_Map::getDirection($x, $y);
 }
예제 #13
0
 private static function getNeighbourNodes($loc, $des, $portals, $ignoreIslands)
 {
     $out = array();
     // We can always walk to the destination...
     if ($ignoreIslands || Dolumar_Map_Map::isPassable($loc[0], $loc[1], $des[0], $des[1])) {
         $out[self::getKeyName($des)] = array('key' => $des, 'cost' => self::calculateDistance($loc[0], $loc[1], $des[0], $des[1]), 'heuristics' => self::calculateDistance($loc[0], $loc[1], $des[0], $des[1]));
     }
     foreach ($portals as $v) {
         self::addPortalNodes($out, $v, $loc, $des);
     }
     return $out;
 }
예제 #14
0
 protected function getRandom($base)
 {
     return Dolumar_Map_Map::getRandom($this->x(), $this->y(), $base);
 }
예제 #15
0
 public static function getLocation($x, $y, $hasBuilding = false)
 {
     return Dolumar_Map_Map::getLocation($x, $y, $hasBuilding);
 }
예제 #16
0
 public function moveUnit($target)
 {
     // Calculate distance
     $distance = Dolumar_Map_Map::getDistanceBetweenVillages($this->getLocation(), $target);
     $duration = $this->getTravelDuration($distance);
     // Update
     $db = Neuron_Core_Database::__getInstance();
     $db->update('villages_specialunits', array('vsu_moveStart' => Neuron_Core_Tools::timestampToMysqlDatetime(time()), 'vsu_moveEnd' => Neuron_Core_Tools::timestampToMysqlDatetime(time() + $duration), 'vsu_location' => $target->getId()), "vsu_id = " . $this->getId());
 }
예제 #17
0
파일: Battle.php 프로젝트: Toxicat/dolumar
 public function attackVillage($oTarget, $oUnits, $specialUnits = array())
 {
     if (count($oUnits) > 0) {
         $db = Neuron_Core_Database::__getInstance();
         // First: check if special units are valid
         $aSpecialUnits = array();
         foreach ($specialUnits as $v) {
             $action = $v[0]->getEffect($v[1]);
             if ($action && $action instanceof Dolumar_Effects_Battle) {
                 $aSpecialUnits[] = array($v[0], $action);
             }
         }
         // Second: calculate the sum of all resource cost
         $aResources = array();
         foreach ($aSpecialUnits as $v) {
             foreach ($v[1]->getCost($v, $oTarget) as $res => $am) {
                 if (isset($aResources[$res])) {
                     $aResources[$res] += $am;
                 } else {
                     $aResources[$res] = $am;
                 }
             }
         }
         // Thirdly: withdraw the required amount
         if (!$this->objProfile->resources->takeResourcesAndRunes($aResources)) {
             $this->error = 'no_resources';
         } else {
             $afstand = Dolumar_Map_Map::getDistanceBetweenVillages($this->objProfile, $oTarget);
             $naarVillage = $this->getMoveDuration($oUnits, $afstand, true);
             $naarHuis = $this->getMoveDuration($oUnits, $afstand, false);
             $fightDate = NOW + $naarVillage;
             // Honour!!!
             $honour = Dolumar_Battle_Battle::getHonourPenalty($this->objProfile, $oTarget);
             $slotsamount = count($this->getAttackSlots($oTarget));
             // Insert battle
             $battleId = $db->insert('battle', array('vid' => $this->objProfile->getId(), 'targetId' => $oTarget->getId(), 'startDate' => NOW, 'arriveDate' => NOW + $naarVillage, 'fightDate' => $fightDate, 'endDate' => $fightDate + $naarHuis + 1, 'goHomeDuration' => $naarHuis, 'iHonourLose' => $honour, 'iBattleSlots' => $slotsamount));
             // Add troops
             foreach ($oUnits as $slot => $unit) {
                 $db->insert('battle_squads', array('bs_bid' => $battleId, 'bs_squadId' => $unit->getSquad()->getId(), 'bs_unitId' => $unit->getUnitId(), 'bs_vid' => $unit->getVillage()->getId(), 'bs_slot' => $slot));
             }
             // Add special troops
             foreach ($aSpecialUnits as $v) {
                 $db->insert('battle_specialunits', array('bsu_bid' => $battleId, 'bsu_vsu_id' => $v[0]->getId(), 'bsu_ba_id' => $v[1]->getId(), 'bsu_vid' => $this->objProfile->getId()));
             }
             // Notify players
             $pl_attacker = $this->objProfile->getOwner();
             $pl_defender = $oTarget->getOwner();
             $notExtra = array('attacker' => $this->objProfile, 'defender' => $oTarget, 'pl_attacker' => $this->objProfile->getOwner(), 'pl_defender' => $oTarget->getOwner());
             $pl_attacker->sendNotification('attacking', 'battle', array('defender' => $oTarget, 'pl_defender' => $oTarget->getOwner(), 'village' => $this->objProfile, 'player' => $this->objProfile->getOwner()), $pl_attacker, true);
             $pl_defender->sendNotification('defending', 'battle', array('attacker' => $this->objProfile, 'pl_attacker' => $this->objProfile->getOwner(), 'village' => $oTarget, 'player' => $oTarget), $pl_attacker, false);
             // Done
             return true;
         }
     } else {
         $this->error = 'no_troops';
         return false;
     }
 }
예제 #18
0
파일: Market.php 프로젝트: Toxicat/dolumar
 public function getTransferDuration(Dolumar_Players_Village $target)
 {
     //return 30;
     $distance = Dolumar_Map_Map::getDistanceBetweenVillages($this->getVillage(), $target, true);
     // Speed for the "marketing managers"
     $speed = 15;
     //return (GAME_SPEED_RESOURCES * $distance * 60 * 10) / (GAME_SPEED_RESOURCES * $speed);
     return $distance * 60 * 10 / (GAME_SPEED_RESOURCES * $speed);
     //return $duration;
     //return 10;
 }
예제 #19
0
 private function doPrepareCircle($start, $end)
 {
     $start = intval($start);
     $end = intval($end);
     // Power the start & end to make everything run faster
     $pStart = $start * $start;
     $pEnd = $end * $end;
     $pi = pi();
     // Count the values in the database,
     // maybe we don't have to run this check!
     $toFind = 0;
     for ($x = 0 - $end; $x < $end; $x++) {
         for ($y = 0 - $end; $y < $end; $y++) {
             $distance = $x * $x + $y * $y;
             if ($distance > $pStart && $distance < $pEnd) {
                 $toFind++;
             }
         }
     }
     // Now count all values in the circle
     $db = Neuron_DB_Database::getInstance();
     $check = $db->query("\n\t\t\tSELECT\n\t\t\t\tt_distance AS distance\n\t\t\tFROM\n\t\t\t\tz_cache_tiles\n\t\t\tHAVING\n\t\t\t\tdistance > {$start} AND \n\t\t\t\tdistance < {$end}\n\t\t");
     $aantal = count($check);
     if ($aantal == $toFind) {
         echo "[" . date("d/m/Y H:i:s") . "]" . " Skipping since the database contains enough tiles...\n";
         return;
     }
     for ($x = 0 - $end; $x < $end; $x++) {
         for ($y = 0 - $end; $y < $end; $y++) {
             // Check the distance!
             $distance = $x * $x + $y * $y;
             if ($distance > $pStart && $distance < $pEnd) {
                 Dolumar_Map_Map::getLocation($x, $y);
             }
         }
     }
 }
예제 #20
0
 public function getVillageProfile($objVillage)
 {
     if (!$objVillage || !$objVillage->isFound()) {
         return '<p>Village not found.</p>';
         return null;
     }
     $text = Neuron_Core_Text::__getInstance();
     $text->setFile('village');
     $text->setSection('profile');
     $townCenter = $objVillage->buildings->getTownCenter();
     if ($townCenter) {
         $l = $townCenter->getLocation();
     } else {
         $l = array('?', '?');
     }
     $page = new Neuron_Core_Template();
     $page->set('village', Neuron_Core_Tools::output_varchar($objVillage->getName()));
     $page->set('location', $text->get('location'));
     $page->set('villageProfile', $text->get('villageProfile'));
     $page->set('location_value', '[' . $l[0] . ',' . $l[1] . ']');
     $page->set('locX', $l[0]);
     $page->set('locY', $l[1]);
     // Owner
     $owner = $objVillage->getOwner();
     $page->set('owner', $text->get('owner'));
     $page->set('owner_value', Neuron_Core_Tools::output_varchar($owner->getNickname()));
     $page->set('pid', $owner->getId());
     // Ranking
     $rank = $objVillage->getRank();
     $page->set('rank', $text->get('rank'));
     $page->set('rank_value', Neuron_Core_Tools::putIntoText($text->get('ranking'), array($rank[0], $rank[1])));
     // Race
     $race = $objVillage->getRace();
     $page->set('race', $text->get('race'));
     $page->set('race_value', Neuron_Core_Tools::output_varchar($race->getRaceName()));
     $page->set('score', $objVillage->getNetworth());
     $me = Neuron_GameServer::getPlayer();
     if ($me && $objVillage->isActive()) {
         foreach ($me->getVillages() as $v) {
             if (!$v->equals($objVillage)) {
                 // Register the visit
                 $v->visits->registerVisit($objVillage);
                 $page->addListValue('challenges', array(Neuron_Core_Tools::putIntoText($text->get('challenge'), array(Neuron_Core_Tools::output_varchar($v->getName()))), htmlentities(json_encode(array('vid' => $v->getId(), 'target' => $objVillage->getId())))));
                 $distance = Dolumar_Map_Map::getDistanceBetweenVillages($v, $objVillage);
                 $page->addListValue('distances', array('id' => $v->getId(), 'name' => Neuron_Core_Tools::output_varchar($v->getName()), 'distance' => Neuron_Core_Tools::output_distance($distance, false, false)));
             }
         }
     } elseif (!$objVillage->isActive()) {
         $page->set('notActive', $text->get('notActive'));
     }
     // Set honour
     $page->set('honour_value', $objVillage->honour->getHonour());
     return $page->parse('villageProfile.tpl');
 }
예제 #21
0
 public static function getRandomNumber($x, $y)
 {
     /*
     srand (abs (10000 - ( $x * 1000) + $y) + RANDMAPFACTOR);
     return rand (-10000, 10000) / 10000;
     */
     return (Dolumar_Map_Map::getRandom($x, $y, 20000) - 10000) / 10000;
 }
예제 #22
0
파일: Squad.php 프로젝트: Toxicat/dolumar
 public function sendToVillage($target)
 {
     // For now: quick & dirty "instant arrival"
     $db = Neuron_DB_Database::__getInstance();
     // Take a look: is this squad traveling at the moment?
     $current = $db->query("\n\t\t\tSELECT\n\t\t\t\tUNIX_TIMESTAMP(s_start) AS vertrek,\n\t\t\t\tUNIX_TIMESTAMP(s_end) AS aankomst\n\t\t\tFROM\n\t\t\t\tsquad_commands\n\t\t\tWHERE\n\t\t\t\ts_id = " . $this->getId() . "\n\t\t\t\tAND s_end > FROM_UNIXTIME(" . NOW . ")\n\t\t\tORDER BY\n\t\t\t\ts_end DESC\n\t\t\tLIMIT 1\n\t\t");
     if (count($current) > 0) {
         // This squad is currently travelling, this is a recall.
         // Moveing back takes as long as moving overthere.
         $duration = NOW - $current[0]['vertrek'];
         // Remove all others
         $db->query("\n\t\t\t\tDELETE FROM\n\t\t\t\t\tsquad_commands\n\t\t\t\tWHERE\n\t\t\t\t\ts_end < FROM_UNIXTIME(" . NOW . ") OR\n\t\t\t\t\ts_id = " . $this->getId() . "\n\t\t\t");
     } else {
         // Calculate the distance & speed
         $speed = $this->getSpeed();
         $distance = Dolumar_Map_Map::getDistanceBetweenVillages($this->getCurrentLocation(), $target);
         $duration = $distance * 60 * 10 / ($speed * GAME_SPEED_MOVEMENT);
     }
     // Do the actual move
     $db->query("\n\t\t\tUPDATE\n\t\t\t\tvillages_squads\n\t\t\tSET\n\t\t\t\ts_village = " . $target->getId() . "\n\t\t\tWHERE\n\t\t\t\ts_id = " . $this->getId() . "\n\t\t");
     // Update the defense slots
     $db->query("\n\t\t\tUPDATE\n\t\t\t\tsquad_units\n\t\t\tSET\n\t\t\t\ts_slotId = 0,\n\t\t\t\ts_priority = 0\n\t\t\tWHERE\n\t\t\t\ts_id = " . $this->getId() . "\n\t\t");
     // Add the commands
     $db->query("\n\t\t\tINSERT INTO\n\t\t\t\tsquad_commands\n\t\t\tSET\n\t\t\t\ts_id = " . $this->getId() . ",\n\t\t\t\ts_action = 'move',\n\t\t\t\ts_start = FROM_UNIXTIME(" . NOW . "),\n\t\t\t\ts_end = FROM_UNIXTIME(" . (NOW + $duration) . "),\n\t\t\t\ts_from = " . $this->getCurrentLocation()->getId() . ",\n\t\t\t\ts_to = " . $target->getId() . "\n\t\t");
     reloadStatusCounters();
     reloadEverything();
 }
예제 #23
0
}
define('IMG_WIDTH', isset($_GET['width']) ? (int) $_GET['width'] : 800);
define('IMG_HEIGHT', isset($_GET['height']) ? (int) $_GET['height'] : 400);
define('IMG_ZOOM', isset($_GET['zoom']) ? (int) $_GET['zoom'] : 100);
// Check for data
if (isset($player_id)) {
    $player = Neuron_GameServer::getPlayerFromOpenID($player_id, true);
    if ($player && $player->isFound()) {
        $village = $player->getMainVillage();
        if ($village) {
            $loc = $village->buildings->getTownCenterLocation();
            define('LOC_X', $loc[0]);
            define('LOC_Y', $loc[1]);
        } else {
            define('LOC_X', isset($_GET['x']) ? (int) $_GET['x'] : 0);
            define('LOC_Y', isset($_GET['x']) ? (int) $_GET['y'] : 0);
        }
    } else {
        define('LOC_X', isset($_GET['x']) ? (int) $_GET['x'] : 0);
        define('LOC_Y', isset($_GET['x']) ? (int) $_GET['y'] : 0);
    }
} else {
    define('LOC_X', isset($_GET['x']) ? (int) $_GET['x'] : 0);
    define('LOC_Y', isset($_GET['x']) ? (int) $_GET['y'] : 0);
}
$disablecache = Neuron_Core_Tools::getInput('_GET', 'nocache', 'varchar');
$cache = Neuron_Core_Cache::__getInstance('snapshots/');
$name = isset($_GET['slogan']) ? $_GET['slogan'] : '';
$cachename = 'img' . LOC_X . '_' . LOC_Y . '_' . IMG_WIDTH . '_' . IMG_HEIGHT . '_' . IMG_ZOOM . '_' . strlen($name);
if ($cache->hasCache($cachename) && !$disablecache) {
    header("Content-type: image/png");
예제 #24
0
파일: Ranking.php 프로젝트: Toxicat/dolumar
 public function getVillageRanking()
 {
     $text = Neuron_Core_Text::__getInstance();
     $db = Neuron_Core_Database::__getInstance();
     $input = $this->getInputData();
     $page = new Neuron_Core_Template();
     $text->setFile('ranking');
     $text->setSection('ranking');
     $page->set('title', $text->get('villageRating'));
     $page->set('village', $text->get('village'));
     $page->set('value', $text->get('value'));
     $data = $this->getRequestData();
     $perPage = 25;
     $myDefaultPage = 1;
     if (isset($data['village'])) {
         $village = Dolumar_Players_Village::getVillageFromId($data['village']);
         $myVillageId = $data['village'];
         $myRank = $village->getRank();
         $myDefaultPage = floor($myRank[0] / $perPage) + 1;
     } else {
         $myVillageId = 0;
         // Load "main village" from this user
         $myself = Neuron_GameServer::getPlayer();
         if ($myself) {
             $village = $myself->getMainVillage();
             if ($village) {
                 $myVillageId = $village->getId();
                 $myRank = $village->getRank();
                 $myDefaultPage = floor($myRank[0] / $perPage) + 1;
             }
         }
     }
     $currentPage = isset($input['page']) ? $input['page'] : $myDefaultPage;
     $limit = Neuron_Core_Tools::splitInPages($page, Dolumar_Players_Ranking::countRanking(), $currentPage, $perPage, 6);
     $l = Dolumar_Players_Ranking::getRanking($limit['start'], $limit['perpage']);
     // Get my villages
     $myself = Neuron_GameServer::getPlayer();
     if ($myself && $myself->isPremium()) {
         $distances = $myself->getVillages();
     } else {
         $distances = array();
     }
     $i = $limit['start'];
     foreach ($l as $v) {
         $i++;
         // Calcualte the distances
         $w_distances = array();
         foreach ($distances as $k => $vv) {
             $w_distances[$k] = Neuron_Core_Tools::output_distance(Dolumar_Map_Map::getDistanceBetweenVillages($vv, $v), true, true);
         }
         $page->addListValue('ranking', array($i, Neuron_Core_Tools::output_varchar($v->getName()), $v->getId(), $v->getNetworth(), $v->getId() == $myVillageId, $w_distances));
         //$v->__destruct ();
     }
     // Add the footnote
     $t_distances = array();
     foreach ($distances as $k => $v) {
         $t_distances[$k] = Neuron_Core_Tools::output_varchar($v->getName());
     }
     $page->set('distances', $t_distances);
     return $page->parse('ranking/ranking.tpl');
 }
예제 #25
0
파일: Search.php 프로젝트: Toxicat/dolumar
 private function buildQuery($select, $distance = false, $limit = null)
 {
     $db = Neuron_DB_Database::getInstance();
     $hasFilter = false;
     $input = $this->getInputData();
     $p1 = $select;
     $p2 = "\n\t\t\tFROM\n\t\t\t\tn_players p\n\t\t\tLEFT JOIN\n\t\t\t\tvillages v ON p.plid = v.plid \n\t\t";
     $sql = "WHERE p.isPlaying = 1 AND p.isRemoved = 0 AND v.isActive = '1' AND ";
     $order = "";
     $hasLocation = false;
     // Distance
     if (!empty($input['search_ankerpoint'])) {
         $location = explode(',', $input['search_ankerpoint']);
         if (count($location) == 2) {
             $x = intval($location[0]);
             $y = intval($location[1]);
             if ($distance) {
                 $p1 .= ", SQRT(POWER(b.xas - {$x}, 2)+POWER(b.yas - {$y}, 2)) AS distance ";
             }
             $p2 .= "LEFT JOIN map_buildings b ON v.vid = b.village AND (b.buildingType = 1 OR b.buildingType = 3) ";
             $hasLocation = true;
         }
     } else {
         $p1 .= ", 0 AS distance ";
     }
     if (!empty($input['search_name'])) {
         $sql .= "p.nickname LIKE '%{$db->escape($input['search_name'])}%' AND ";
         $hasFilter = true;
     }
     if (!empty($input['search_village'])) {
         $sql .= "v.vname LIKE '%{$db->escape($input['search_village'])}%' AND ";
         $hasFilter = true;
     }
     if (!empty($input['search_race'])) {
         $sql .= "v.race = '{$db->escape($input['search_race'])}' AND ";
         $hasFilter = true;
     }
     if (!empty($input['search_online'])) {
         $sql .= "p.lastRefresh > FROM_UNIXTIME(" . (time() - intval($input['search_online'])) . ") AND ";
         $hasFilter = true;
     }
     // Distances.. pain in the ass
     if ((!empty($input['search_distance_min']) || !empty($input['search_distance_max'])) && !empty($input['search_ankerpoint']) && $hasLocation) {
         if (!empty($input['search_distance_min'])) {
             $d = floatval($input['search_distance_min']);
             $d = Dolumar_Map_Map::league2tile($d);
             $sql .= "SQRT(POWER(b.xas - {$x}, 2)+POWER(b.yas - {$y}, 2)) >= " . $d . " AND ";
         }
         if (!empty($input['search_distance_max'])) {
             $d = floatval($input['search_distance_max']);
             $d = Dolumar_Map_Map::league2tile($d);
             $sql .= "SQRT(POWER(b.xas - {$x}, 2)+POWER(b.yas - {$y}, 2)) <= " . $d . " AND ";
         }
         $hasFilter = true;
     }
     // Networth
     if (!empty($input['search_networth_min'])) {
         $sql .= "v.networth >= " . intval($input['search_networth_min']) . " AND ";
         $hasFilter = true;
     }
     if (!empty($input['search_networth_max'])) {
         $sql .= "v.networth <= " . intval($input['search_networth_max']) . " AND ";
         $hasFilter = true;
     }
     // Order
     $order = "p.nickname";
     if (!empty($input['search_order'])) {
         switch ($input['search_order']) {
             case 'villagename':
                 $order = "v.vname";
                 break;
             case 'lastonline':
                 $order = "p.lastRefresh";
                 break;
             case 'distance':
                 if ($hasLocation && $distance) {
                     $order = 'distance';
                 }
                 break;
             case 'nickname':
             default:
                 $order = "p.nickname";
                 break;
         }
     }
     if (!empty($input['search_order_dir'])) {
         switch (strtolower($input['search_order_dir'])) {
             case 'asc':
                 $order .= ' ASC';
                 break;
             case 'desc':
                 $order .= ' DESC';
                 break;
         }
     }
     $sql = substr($sql, 0, -4);
     $sLimit = "";
     if (isset($limit) && is_array($limit)) {
         $sLimit = 'LIMIT ' . $limit['limit'];
     }
     //customMail ('*****@*****.**', 'bla', $p1 . $p2 .  $sql . 'ORDER BY ' . $order . ' ' . $sLimit);
     if ($hasFilter) {
         return $p1 . $p2 . $sql . 'ORDER BY ' . $order . ' ' . $sLimit;
     } else {
         return false;
     }
 }
예제 #26
0
파일: Portals.php 프로젝트: Toxicat/dolumar
 private function isValidLocation($village, $x, $y)
 {
     if ($x == $this->lx && $y == $this->ly) {
         return false;
     }
     // Fetch location
     $location = Dolumar_Map_Map::getLocation($x, $y);
     if (!$location->canBuildBuilding()) {
         return false;
     }
     return !$village->buildings->isBuildingOnLocation($x, $y);
 }
예제 #27
0
 $y = $_GET['y'];
 $im = getBackgroundImage($x, $y, $tilesToLoad);
 $color_cache = array();
 // Build the new background image.
 $tileSizeX = 8;
 $tileSizeY = $tileSizeX / 2;
 $halfTileX = floor($tileSizeX / 2);
 $halfTileY = floor($tileSizeY / 2);
 $switchpoint = $tilesToLoad;
 $loadExtra = 1;
 $startX = ($x + $y) * $switchpoint;
 $startY = ($x - $y) * $switchpoint;
 $db = Neuron_Core_Database::__getInstance();
 $locations = array(array($startX + $switchpoint / 2, $startY - $switchpoint / 2));
 // Load buildings from SQL
 $buildingSQL = Dolumar_Map_Map::getBuildingsFromLocations($locations, $switchpoint + 25);
 foreach ($buildingSQL as $buildingV) {
     $race = Dolumar_Races_Race::getRace($buildingV['race']);
     $b = Dolumar_Buildings_Building::getBuilding($buildingV['buildingType'], $race, $buildingV['xas'], $buildingV['yas']);
     $b->setData($buildingV['bid'], $buildingV);
     //$buildings[floor ($buildingV['xas'])][floor ($buildingV['yas'])][] = $b;
     $x = floor($buildingV['xas']);
     $y = floor($buildingV['yas']);
     $color = color_cache($im, $b->getMapColor());
     $i = $x - $startX;
     $j = $startY - $y;
     $px = round(($i - $j) * floor($tileSizeX / 2));
     $py = round(($i + $j) * floor($tileSizeY / 2));
     $tileSizeX = 8;
     $tileSizeY = $tileSizeX / 2;
     $halfTileX = floor($tileSizeX / 2);