Merge pull request #415 from Shadowss/patch-86

Fix area and location like real travian
This commit is contained in:
yi12345
2013-10-31 05:29:45 -07:00
+41 -21
View File
@@ -352,27 +352,47 @@ class MYSQL_DB {
} }
} }
function generateBase($sector) { function generateBase($sector, $mode) {
switch($sector) { if (!$mode) {
case 1: $gamesday=time()-COMMENCE;
$q = "Select * from ".TB_PREFIX."wdata where fieldtype = 3 and x < 0 and y > 0 and occupied = 0"; if ($gamesday<3600*24*10) { //10 day
break; $wide1=1;
case 2: $wide2=20;
$q = "Select * from ".TB_PREFIX."wdata where fieldtype = 3 and x > 0 and y > 0 and occupied = 0"; } elseif ($gamesday<3600*24*20) { //20 day
break; $wide1=20;
case 3: $wide2=40;
$q = "Select * from ".TB_PREFIX."wdata where fieldtype = 3 and x < 0 and y < 0 and occupied = 0"; } elseif ($gamesday<3600*24*30) { //30 day
break; $wide1=40;
case 4: $wide2=80;
$q = "Select * from ".TB_PREFIX."wdata where fieldtype = 3 and x > 0 and y < 0 and occupied = 0"; } else { // over 30 day
break; $wide1=80;
} $wide2=120;
$result = mysql_query($q, $this->connection); }
$num_rows = mysql_num_rows($result); }
$result = $this->mysql_fetch_all($result); else {
$base = rand(0, ($num_rows-1)); $wide1=1;
return $result[$base]['id']; $wide2=WORLD_MAX;
} }
switch($sector) {
case 1:
$q = "Select * from ".TB_PREFIX."wdata where fieldtype = 3 and (x < -$wide1 and x > -$wide2) and (y > $wide1 and y < $wide2) and occupied = 0"; //x- y+
break;
case 2:
$q = "Select * from ".TB_PREFIX."wdata where fieldtype = 3 and (x > $wide1 and x < $wide2) and (y > $wide1 and y < $wide2) and occupied = 0"; //x+ y+
break;
case 3:
$q = "Select * from ".TB_PREFIX."wdata where fieldtype = 3 and (x < -$wide1 and x > -$wide2) and (y < -$wide1 and y > -$wide2) and occupied = 0"; //x- y-
break;
case 4:
$q = "Select * from ".TB_PREFIX."wdata where fieldtype = 3 and (x > $wide1 and x < $wide2) and (y < -$wide1 and y > -$wide2) and occupied = 0"; //x+ y-
break;
}
$result = mysql_query($q, $this->connection);
$num_rows = mysql_num_rows($result);
$result = $this->mysql_fetch_all($result);
$base = rand(0, ($num_rows-1));
return $result[$base]['id'];
}
function setFieldTaken($id) { function setFieldTaken($id) {
$q = "UPDATE " . TB_PREFIX . "wdata set occupied = 1 where id = $id"; $q = "UPDATE " . TB_PREFIX . "wdata set occupied = 1 where id = $id";