-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUniverseSeederClass.php
67 lines (66 loc) · 2.54 KB
/
UniverseSeederClass.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
class UniverseSeederClass
{
function __construct()
{
}
function addPlanetsToArea($xLocation1, $yLocation1, $xLocation2, $yLocation2, $planets)
{
$db = new DatabaseClass();
for($i = 0; $i < $planets; $i++)
{
$xRand = mt_rand($xLocation1,$xLocation2);
$yRand = mt_rand($yLocation1,$yLocation2);
$xRandDecimal = mt_rand(0,1000);
$yRandDecimal = mt_rand(0,1000);
$xRand *= 1000;
$yRand *= 1000;
$xRand += $xRandDecimal;
$yRand += $yRandDecimal;
$tempLow = mt_rand(-265,200);
$tempHighOffset = mt_rand(50,1000);
$tempHigh = $tempLow + $tempHighOffset;
$result = mysql_query("SELECT id FROM planets WHERE (ABS(xLocation - $xRand) < 50) AND (ABS(yLocation - $yRand) < 50)");
$numRows = mysql_numrows($result);
$query = "INSERT INTO planets (name, tempLow, tempHigh, xLocation, yLocation) VALUES ('Unnamed', $tempLow, $tempHigh, $xRand, $yRand)";
if($numRows == 0)
{
mysql_query($query);
}
}
}
function createAnimalTypes($numTypes)
{
$db = new DatabaseClass();
for($i = 0; $i < $numTypes; $i++)
{
$rarity = mt_rand(2,100);
$tempLow = mt_rand(-265,200);
$tempHigh = mt_rand(50, 1000);
$query = "INSERT INTO animalTypes (name, rarity, tempLow, tempHigh) VALUES ('Unnamed', $rarity, $tempLow, $tempHigh)";
echo $query;
mysql_query($query) or die(mysql_error());
}
}
function createPlanetAnimalTypes($numConnections)
{
$db = new DatabaseClass();
for($i = 0; $i < $numConnections; $i++)
{
$result = mysql_query("SELECT id FROM planets") or die(mysql_error());
$numPlanets = mysql_numrows($result);
$result = mysql_query("SELECT id FROM animalTypes") or die(mysql_error());
$numAnimalTypes = mysql_numrows($result);
$numPlanet = mt_rand(0,$numPlanets);
$numAnimalType = mt_rand(0,$numAnimalTypes);
$currPlanet = new PlanetClass($numPlanet);
$currAnimalType = new AnimalTypeClass($numAnimalType);
if($currPlanet->canPlanetSupport($currAnimalType))
{
$query = "INSERT INTO planetAnimalTypes (animalTypeID, planetID) VALUES ($numAnimalType, $numPlanet)";
mysql_query($query) or die(mysql_error());
}
}
}
}
?>