--  Rings of Saturn
--  Map by DaMatta. Feel free to distribute this map so long as you credit the Creator.
--
-- Note:
-- If your browser doesn't download the files and just open them in the explorer window,
-- just copy/paste the text into any text editor like NotePad and save it to a file with
-- the name of the map and with the extension of ".level".
-- For example in the case of the first map we will create a file named Returning_Home.level
-- and remember to save it on the drive where you installed the game in the folder
-- ...Homeworld2\Data\LevelData\multiplayer\deathmatch\  and if you don't have yet those
-- subfolders you must create them first.
--  __________________________________________________________________________________________________________
--  THE HISTORY 
--  Chapter V - The Black Hole
--
--  _______________________________________________________________________________________________________
--  Version History:
--  v1.0 -Initial Release

levelDesc = "Chapter VI: Rings of Saturn"
maxPlayers = 6
--randomseed(0.1); with this set we dont get truly randoms ???

player = {}

player[0] = {
  id = 0,
  name = "Admiral DaMatta",
  resources = 5000,
  raceID = 0,
  startPos = 1,
}

player[1] = {
  id = 1,
  name = "",
  resources = 5000,
  raceID = 0,
  startPos = 1,
}

player[2] = {
  id = 2,
  name = "",
  resources = 5000,
  raceID = 0,
  startPos = 1,
}

player[3] = {
  id = 3,
  name = "",
  resources = 5000,
  raceID = 0,
  startPos = 1,
}

player[4] = {
  id = 4,
  name = "",
  resources = 5000,
  raceID = 0,
  startPos = 1,
}

player[5] = {
  id = 5,
  name = "",
  resources = 5000,
  raceID = 0,
  startPos = 1,
}

function DetermChunk()

  local Sol =
  {
    Class = "endor",
    Kind = "Star",
    Type = "byss",
    Position = {-20000000,0,-20000000},
    AtmosfereColor = {5, 0, 0, 1},
    Size = 300000,
    RUs = 0,
  }

  local Terra =
  {
    Class = "endor",
    Kind = "Planet",
    Type = "meg_earth",
    Position = {-300000,0,1200000},
    AtmosfereColor = {0, 0, 1, 1},
    Size = 130000,
    RUs = 0,
  }

  local Lua =
  {
    Class = "endor",
    Kind = "Moon",
    Type = "tatooine", --Type = "nalhutta",
    Position = {300000,0,1000000},
    AtmosfereColor = {0, 0, 0, 1},
    Size = 300000,
    RUs = 0,
  }

  local Venus =
  {
    Class = "endor",
    Kind = "Planet",
    Type = "tatooine", --Type = "nalhutta",
    Position = {0,0,0},
    AtmosfereColor = {1, 1, 0, 1},
    Size = 300000,
    RUs = 0,
  }

  local Mercurio =
  {
    Class = "endor",
    Kind = "Planet",
    Type = "Byss", --Type = "nalhutta",
    Position = {0,0,0},
    AtmosfereColor = {1, 0, 0, 1},
    Size = 350000,
    RUs = 0,
  }

  local Marte =
  {
    Class = "endor",
    Kind = "Planet",
    Type = "narshadda",
    Position = {0,0,0},
    AtmosfereColor = {1, 0, 0, 1},
    Size = 350000,
    RUs = 0,
  }

  local Saturno =
  {
    Class = "endor",
    Kind = "Planet",
    Type = "bilbringi",
    Position = {0,0,0},
    AtmosfereColor = {1, 0, 0, 1},
    Size = 350000,
    RUs = 0,
  }
  --addSquadron("endor", "endor", Endor.Position, -1, {0, 180, 0}, 0, 0); --earth like big one
  --addSquadron("endor", "tatooine", Endor.Position, -1, {0, 180, 0}, 0, 0); --arido rosa ? venus?
  --addSquadron("endor", "narshadda", Endor.Position, -1, {0, 180, 0}, 0, 0);  --red kind coruscant?
  --addSquadron("endor", "nalhutta", Endor.Position, -1, {0, 180, 0}, 0, 0); --rocky verde
  --addSquadron("endor", "Hoth", Endor.Position, -1, {0, 180, 0}, 0, 0); --blue ice big
  --addSquadron("endor", "coruscant", Endor.Position, -1, {0, 180, 0}, 0, 0);
  --addSquadron("endor", "Byss", Endor.Position, -1, {0, 180, 0}, 0, 0);  --red lisa for mercury min distance = 500Km
  --addSquadron("endor", "bilbringi", Endor.Position, -1, {0, 180, 0}, 0, 0);  --ice blue min distance = 500Km
  --addSquadron("endor", "Corellia", Endor.Position, -1, {0, 180, 0}, 0, 0);  --like earth min distance = 500Km

  addSquadron(Saturno.Class, "saturn", Saturno.Position, -1, {0, 270, 0}, 0, 0);

  --Constants and trie to keep those constants
  local RUsFactor = 2.5

  local UniverseRadius = 1800000;
  local UniverseCenter = {0,0,0}
  local FleetDistance = {1200000,0,1200000}; --distance of fleets from uuh... UniverseCenter

  local BlackEye =
  {
    Class = "Nebula",
    Kind = "m11_bentusi_radiation",
    Type = "m11_bentusi_radiation",
    RGBV = {0.1, 0.1, 0.1, 1},
    Size = 150000,
    RUs = 0,
  }

  local BlueIris =
  {
    Class = "Nebula",
    Kind = "m05_dustcloud_nebula",
    Type = "m05_dustcloud_nebula",
    RGBV = {0, 0, 255, 1},
    Size = 10000,
    RUs = 0,
  }

  local WhiteBall =
  {
    Class = "Nebula",
    Kind = "m05_dustcloud_nebula",
    Type = "m05_dustcloud_nebula",
    RGBV = {255, 255, 255, 1},
    Size = 10000,
    RUs = 0,
  }

  local BlueIris =
  {
    Class = "Nebula",
    Kind = "m05_dustcloud_nebula",
    Type = "m05_dustcloud_nebula",
    RGBV = {0, 0, 255, 1},
    Size = 10000,
    RUs = 0,
  }

  local GreenCloud =
  {
    Class = "Nebula",
    Kind = "m05_dustcloud_nebula",
    Type = "m05_dustcloud_nebula",
    RGBV = {0, 255, 0, 1},
    Size = 10000,
    RUs = 0,
  }

  local VioletCloud =
  {
    Class = "Nebula",
    Kind = "m05_dustcloud_nebula",
    Type = "m05_dustcloud_nebula",
    RGBV = {255, 0, 255, 1},
    Size = 30000,
    RUs = 0,
  }

  local CloudHide =
  {
    Class = "DustCloud",
    Kind = "polySurface2",
    Type = "DustCloud_0",
    RGBV = {255, 0, 255, 1},
    Size = 20000,
    RUs = 0,
  }

  local Rock5 =
  {
    Class = "Asteroid",
    Kind = "Asteroid_5",
    Type = "Asteroid_5",
    RGBV = {0, 0, 0, 0},
    Size = 0,
    RUs = 150,
  }

  local Rock4 =
  {
    Class = "Asteroid",
    Kind = "Asteroid_4",
    Type = "Asteroid_4",
    RGBV = {0, 0, 0, 0},
    Size = 0,
    RUs = 100,
  }

  local Rock3 =
  {
    Class = "Asteroid",
    Kind = "Asteroid_3",
    Type = "Asteroid_3",
    RGBV = {0, 0, 0, 0},
    Size = 0,
    RUs = 980,
  }

  local PebbleW =
  {
    Class = "Pebble",
    Kind = "starw",
    Type = "starw",
    RGBV = {0, 0, 0, 0},
    Size = 0,
    RUs = 0,
  }
  local PebbleR =
  {
    Class = "Pebble",
    Kind = "starr",
    Type = "starr",
    RGBV = {0, 0, 0, 0},
    Size = 0,
    RUs = 0,
  }
  local PebbleB =
  {
    Class = "Pebble",
    Kind = "starb",
    Type = "starb",
    RGBV = {0, 0, 0, 0},
    Size = 0,
    RUs = 0,
  }
  local PebbleO =
  {
    Class = "Pebble",
    Kind = "staro",
    Type = "staro",
    RGBV = {0, 0, 0, 0},
    Size = 0,
    RUs = 0,
  }
  local PebbleY =
  {
    Class = "Pebble",
    Kind = "stary",
    Type = "stary",
    RGBV = {0, 0, 0, 0},
    Size = 0,
    RUs = 0,
  }

 local RingBright =
  {
    Class = "Pebble",
    Kind = "ringsbright",
    Type = "ringsbright",
    RGBV = {0, 0, 0, 0},
    Size = 0,
    RUs = 0,
  }
local RingDim =
  {
    Class = "Pebble",
    Kind = "ringsdim",
    Type = "ringsdim",
    RGBV = {0, 0, 0, 0},
    Size = 0,
    RUs = 0,
  }
local RingDark =
  {
    Class = "Pebble",
    Kind = "ringsdark",
    Type = "ringsdark",
    RGBV = {0, 0, 0, 0},
    Size = 0,
    RUs = 0,
  }
  local StarDust =
  {
    Class = "Pebble",
    Kind = "pebble_0",
    Type = "pebble_0",
    RGBV = {0, 0, 0, 0},
    Size = 0,
    RUs = 0,
  }

  local Container =
  {
    Class = "Container",
    Kind = "StaticContainer",
    Type = "StaticContainer",
    RGBV = {0, 0, 0, 0},
    Size = 0,
    RUs = 2000,
  }

  local NULO =
  {
    Class = "NULO",
    Kind = "NULO",
    Type = "NULO",
    RGBV = {0, 0, 0, 0},
    Size = 0,
    RUs = 0,
  }

  local ObjDistance = {0,0,0}

  --Variables declaration
  local Fleet1Pos = {0,0,0};
  local Fleet2Pos = {0,0,0};

  local Player0 = {0, 0, 0};
  local Player1 = {0, 0, 0};
  local Player2 = {0, 0, 0};
  local Player3 = {0, 0, 0};
  local Player4 = {0, 0, 0};
  local Player5 = {0, 0, 0};

  local Xfactor = 0
  local Yfactor = 0
  local Zfactor = 0

  local Xpos = 0
  local Ypos = 0
  local Zpos = 0

  local Xpos1 = 0
  local Ypos1 = 0
  local Zpos1 = 0

  local ObjPos = {0,0,0};
  local ObjPos1 = {0,0,0};

  -- FLEETS LOCATION (random by each side)  ______________________________________________________________
  --local Fleet1Pie = {20, 160}; --a pie of 130º
  local FleetPitch = 0.12; --make pitch rings equal to this
  local Fleet1Pie = {0, 359};
  for n = 1, 3, 1 do
    local RndCircle = random(Fleet1Pie[1],Fleet1Pie[2]);  -- for a random position in a circle of 90º
    Xpos = UniverseCenter[1] + (FleetDistance[1] * cos(RndCircle));
    Ypos = UniverseCenter[2] + ((FleetDistance[1] * FleetPitch) * cos(RndCircle));
    Zpos = UniverseCenter[3] + (FleetDistance[3] * sin(RndCircle));

    --Ypos = Ypos + random(-20000,20000); --make them random in vertical plan between 20 Km
    Ypos = Ypos + 20000;

    if (n == 1) then
	    Fleet1Pos = {Xpos, Ypos, Zpos}; --position of fleet 1
	    Player0 = Fleet1Pos
      addPoint("StartPos0", Player0, {0, 90, 0})
  --can't select it ???????
  -- need to set the player ID EJ
  addSquadron("Reb_Republic_Destroyer", "Reb_Republic_Destroyer",{Player0[1], Player0[2] + 5000, Player0[3], }, 1, { 0, 90,0, }, 0, 0)
  createSOBGroup("Home_of_DaMatta")
  addToSOBGroup("Reb_Republic_Destroyer1", "Home_of_DaMatta")

    elseif (n == 2) then
	    Player1 = {Xpos, Ypos, Zpos}
      addPoint("StartPos1", Player1, {0, 90, 0})

    elseif (n == 3) then
	    Player2 = {Xpos, Ypos, Zpos}
      addPoint("StartPos2", Player2, {0, 90, 0})
    end
  end

  --local Fleet2Pie = {200, 340}; --a pie of 130º
  local Fleet2Pie = {0, 359};
  for n = 1, 3, 1 do
    local RndCircle = random(Fleet2Pie[1],Fleet2Pie[2]);  -- for a random position in a circle of 90º
    Xpos = UniverseCenter[1] + (FleetDistance[1] * cos(RndCircle));
    Ypos = UniverseCenter[2] + ((FleetDistance[1] * FleetPitch) * cos(RndCircle));
    Zpos = UniverseCenter[3] + (FleetDistance[3] * sin(RndCircle));

    --Ypos = Ypos + random(-20000,20000); --make them random in vertical plan between 20 Km
    Ypos = Ypos + 20000;

   if (n == 1) then
	    Fleet2Pos = {Xpos, Ypos, Zpos}; --position of fleet 1
	    Player3 = {Fleet2Pos[1], Fleet2Pos[2], Fleet2Pos[3]}
      addPoint("StartPos3", Player3, {0, 270, 0})

    elseif (n == 2) then
	    Player4 = {Xpos, Ypos, Zpos}
      addPoint("StartPos4", Player4, {0, 270, 0})

    elseif (n == 3) then
	    Player5 = {Xpos, Ypos, Zpos}
      addPoint("StartPos5", Player5, {0, 270, 0})
    end
  end  
  -- END FLEETS LOCATION  _______________________________________________________________________

  --Rings and resouces
  local Pitch = FleetPitch; --to make rings horizontal set value to 0
  local Carrosel = 'No'; --to do a carrousel efect set value to "Yes"
  ObjPos = {UniverseCenter[1],UniverseCenter[2],UniverseCenter[3]};
  ThePlate(ObjPos,{450000,85000},Pitch,Carrosel,{0,359,300},10,RingBright,RUsFactor)
 -- TheRing(ObjPos,549000,Pitch,{0,359,20},Rock5,"No",4000,0,{0,359,2},NULO,RUsFactor * 1.5)
  ThePlate(ObjPos,{550000,100000},Pitch,Carrosel,{0,359,300},12,RingDim,RUsFactor)
  ThePlate(ObjPos,{650000,100000},Pitch,Carrosel,{0,359,300},20,RingBright,RUsFactor)
  ThePlate(ObjPos,{740000,50000},Pitch,Carrosel,{0,359,300},12,RingDark,RUsFactor)
 -- TheRing(ObjPos,799000,Pitch,{0,359,30},Rock5,"No",4000,0,{0,359,3},NULO,RUsFactor)
  ThePlate(ObjPos,{800000,200000},Pitch,Carrosel,{0,359,300},20,RingDim,RUsFactor)


  setWorldBoundsInner({0, 0, 0}, {UniverseRadius, UniverseRadius / 1.5, UniverseRadius})

-------  by evillejedi
	local rdist =
	{
		starw = 2,
		starr = 1,
		starb = 1,
		staro = 1,
		stary = 1,
		stardim = 8,
		stardim2 = 6,
	}
--	StarField({0, 0, 0,}, rdist, 2500, UniverseRadius * 10, 500, 360, 360)

end --function

function NonDetermChunk()

  fogSetActive (0)
  fogSetStart (1000)
  fogSetEnd (10000)
  fogSetColour(0.347656, 0.197266, 0.074219, 1.0)
  fogSetType ("linear")
  fogSetDensity (0.5)

  setGlareIntensity(0.8)
  setLevelShadowColour(64,64,200, 5)

  setDustCloudAmbient({ 0.1, 0.5, 0.8, 1, })

  --loadBackground("singlesun")
  loadBackground("m12")  --15,12,11,10,2,3,		"planet", "quick", "singlesun", "tanis", "taniswstars", "black", "white",
  setSensorsManagerCameraDistances(20000, 2200000)  
  --setDefaultMusic("Data:sound/music/battle/bentus_arrival")
  setDefaultMusic("Data:sound/music/AMBIENT/amb_03")

--bypass the teaks of evillejedy
smTwkMinZoomOutDistance = 20000
smTwkMaxZoomOutDistance = 2000000
smTwkMaxMovementDistance = 50
horizonRadius = 2000000
end

function StarField(tPosition, rDistribution, iNumResources, fAxis1, fWidth, fArc, farx)
	local rel = 0
	for k, iCount in rDistribution do
		rel = rel + iCount
	end
	local num = floor(iNumResources/rel)
	for k, iCount in rDistribution do
		for i = 1, num*iCount do
			local majA = fAxis1
			local theta = random(0, fArc)
			local phi = random(0, farx)
			local radiusV = majA-- + random(fWidth/-2, fWidth/2)
			local deltaX = radiusV * cos(phi-20) * sin(theta-20) 
			local deltaY = radiusV * sin(phi) 
			local deltaZ = radiusV * cos(phi) * cos(theta)
			addPebble(k, {tPosition[1] + deltaX, tPosition[2] + deltaZ, tPosition[3] + deltaY,}, 0, 0, 0)
		end
	end
end

--Function by DaMatta draw a circle of objects and recursively a circle around each object too
--will trace a ring of objects
--pObjPos = coordenates of center of ring
--pFactor = distance from center, ray of ring
--pFlat = 1 the ring will be in the horizontal plan, try 1.1, 1.2, 1.3,... for make it diagonal
--pLoop = 1º:first value 2º:last value  3:number of objects(or loops) around ring make it a impar number
--pObjPos = coordenates of center of ring
--Astro1 = collection for kind of asteroid for 1ºring
--pFlagRing2 = we draw a ring of objects around each main object? 1=yes call the function itself recursively with the second set of parameters
function TheRing(pObjPos,pFactor,pFlat,pLoop,pAstro1,pFlagRing2,pFactor2,pFlat2,pLoop2,pAstro2,pRUsFactor)
  --declarations
  local lXfactor = 0;
  local lYfactor = 0;
  local lZfactor = 0;
  local lXpos = 0;
  local lYpos = 0;
  local lZpos = 0;
  local lObjPos = {0,0,0};

  local lStep = floor((pLoop[2] - pLoop[1]) / pLoop[3]) + 1;  --this is the number of step for FOR to give a loop for each object

  for i = pLoop[1], pLoop[2], lStep do

    lXfactor = pFactor;
    lYfactor = pFactor * pFlat;
    lZfactor = pFactor;

    lXpos = pObjPos[1] + (lXfactor * cos(i));
    lYpos = pObjPos[2] + (lYfactor * cos(i));
    lZpos = pObjPos[3] + (lZfactor * sin(i));

    lObjPos = {lXpos,lYpos,lZpos}; --this is the position of the object

    AddObjecto(pAstro1,lObjPos,pRUsFactor)
    --trace a 2º ring around each object ?
    if (pFlagRing2 == "Yes") then
      --recursivse call to do a ring around each object of the ring
      TheRing(lObjPos,pFactor2,pFlat2,pLoop2,pAstro2,"No",0,0,0,NULO,pRUsFactor)
    end --if
  end  --Ring1
end  --function TheRing

--Function by DaMatta same as TheRing but in a vertical plan
function TheRingVertical(pObjPos,pFactor,pLoop,pAstro1,pFlagRing2,pFactor2,pLoop2,pAstro2,pRUsFactor)

  --declarations
  local lXfactor = 0;
  local lYfactor = 0;
  local lZfactor = 0;
  local lXpos = 0;
  local lYpos = 0;
  local lZpos = 0;
  local lObjPos = {0,0,0};

  local lStep = floor((pLoop[2] - pLoop[1]) / pLoop[3]) + 1;  --this is the number of step for FOR to give a loop for each object

  for i = pLoop[1], pLoop[2], lStep do

    lXfactor = 0;--pFactor;
    lYfactor = pFactor;
    lZfactor = pFactor;

    lXpos = pObjPos[1] + (lXfactor * cos(i));
    lYpos = pObjPos[2] + (lYfactor * cos(i));
    lZpos = pObjPos[3] + (lZfactor * sin(i));

    lObjPos = {lXpos,lYpos,lZpos}; --this is the position of the object

    if (pAstro1.Class == "Asteroid") then
      addAsteroid( pAstro1.Type, {lObjPos[1],lObjPos[2],lObjPos[3]}, pAstro1.RUs * pRUsFactor, 0, 0, 0, 0)
    elseif (pAstro1.Class == "Pebble") then
      addPebble( pAstro1.Type, {lObjPos[1],lObjPos[2],lObjPos[3]}, 0,0,0)
    elseif (pAstro1.Class == "Nebula") then
      addNebula(pAstro1.Kind, pAstro1.Type, {lObjPos[1],lObjPos[2],lObjPos[3]}, pAstro1.RGBV, 0, pAstro1.Size)
    elseif (pAstro1.Class == "Cloud") then
      addDustCloud(pAstro1.Kind, pAstro1.Type, {ObjPos[1], ObjPos[2], ObjPos[3]}, pAstro1.RGBV,1, pAstro1.Size)
    elseif (pAstro1.Class == "Container") then
      addSalvage(pAstro1.Type,{lObjPos[1], lObjPos[2], lObjPos[3]}, pAstro1.RUs * pRUsFactor, 0, 0, 0, 0)
    end

    --trace a 2º ring around each object ?
    if (pFlagRing2 == "Yes") then
      --recursivse call to do a ring around each object of the ring
      TheRing(lObjPos,pFactor2,pLoop2,pAstro2,"No",0,0,0,NULO,pRUsFactor)
    end --if
  end  --Ring1
end  --function


function ThePlate(pObjPos,pFactor,pFlat,pCarrousel,pLoop,pDensity,pAstro1,pRUsFactor)
  --declarations
  local lXfactor = 0;
  local lYfactor = 0;
  local lZfactor = 0;
  local lXpos = 0;
  local lYpos = 0;
  local lZpos = 0;
  local lObjPos = {0,0,0};

  local lStep = floor((pLoop[2] - pLoop[1]) / pLoop[3]) + 1;  --this is the number of step for FOR to give a loop for each object

  for i = pLoop[1], pLoop[2], lStep do
    lXfactor = pFactor[1];
    lYfactor = pFactor[1] * pFlat; -- * cos(i) activate to a carrousel efect
    lZfactor = pFactor[1];
    if (pCarrosel == 'Yes') then  --activate for a carrousel efect
      lYfactor = lYfactor * cos(i);
    end

    for x = 1, pDensity, 1 do
	    lXpos = pObjPos[1] + ((lXfactor + random(0,pFactor[2])) * cos(i));
	    lYpos = pObjPos[2] + (lYfactor * cos(i));
	    lZpos = pObjPos[3] + ((lZfactor + random(0,pFactor[2])) * sin(i));

	    lObjPos = {lXpos,lYpos,lZpos}; --this is the position of the object
      AddObjecto(pAstro1,lObjPos,pRUsFactor)

    end
  end  --Ring
end  --function ThePlate


function TheLine(pObjPos,pFactor,pDir,pStep,pAstro1,pFlagRing2,pFactor2,pDir2,pStep2,pAstro2,pRUsFactor)
  --declarations
  local lXpos = 0;
  local lYpos = 0;
  local lZpos = 0;
  local lObjPos = {0,0,0};

  local lStep = floor((270 - 90) / pStep) + 1;  --this is the number of step for FOR to give a loop for each object

  for i = 90, 270, lStep do

    lXpos = pObjPos[1];
    lYpos = pObjPos[2];
    lZpos = pObjPos[3];

    if pDir == 'X' then
      lXpos = lXpos + (pFactor* sin(i));
    elseif pDir == 'Y' then
      lYpos = lYpos + (pFactor* sin(i));
    elseif pDir == 'Z' then
      lZpos = lZpos + (pFactor* sin(i));
    end

    lObjPos = {lXpos,lYpos,lZpos}; --this is the position of the object

    if (pAstro1.Class == "Asteroid") then
      addAsteroid( pAstro1.Type, lObjPos, pAstro1.RUs * pRUsFactor, 0, 0, 0, 0)
    elseif (pAstro1.Class == "Pebble") then
      addPebble( pAstro1.Type, lObjPos, 0,0,0)
    elseif (pAstro1.Class == "Nebula") then
      addNebula(pAstro1.Kind, pAstro1.Type, lObjPos, pAstro1.RGBV, 0, pAstro1.Size)
    elseif (pAstro1.Class == "Cloud") then
      addDustCloud(pAstro1.Kind, pAstro1.Type, lObjPos, pAstro1.RGBV,0, pAstro1.Size)
    elseif (pAstro1.Class == "Container") then
      addSalvage(pAstro1.Type,lObjPos, pAstro1.RUs * pRUsFactor, 0, 0, 0, 0)
    end

    --trace a 2º ring around each object ?
    if (pFlagRing2 == "Yes") then
      --recursivse call to do a ring around each object of the ring
      TheRing(lObjPos,pFactor2,pDir2,pStep2,pAstro2,"No",0,0,0,NULO)
    end --if
  end  --Ring1
end  --function TheRing

--pStep raiz quadrada do numero de objectos pretendidos
function TheShape(pShape,pObjPos,pRadius,pStep,pAstro1,pRUsFactor)
  --declarations
  local lXpos = 0;
  local lYpos = 0;
  local lZpos = 0;
  local lObjPos = {0,0,0};

  local lStep = floor(360 / pStep);-- + 1;  --this is the number of step for FOR to give a loop for each object

  for x = 90, 270, lStep / 2 do --for sin between 1 an -1
    for y = 0, 360 - lStep, lStep do

	    if (pShape == "Square") then
    	  lXpos = pObjPos[1] + (pRadius * cos(x) * cos(y))
		  	lYpos = pObjPos[2]
				lZpos = pObjPos[3] + (pRadius * sin(x) * sin(y))
	    elseif (pShape == "Star") then
    	  lXpos = pObjPos[1] + (pRadius * sin(y)* sin(x))
		  	lYpos = pObjPos[2]
				lZpos = pObjPos[3] + (pRadius * cos(y) * sin(x))
	    elseif (pShape == "Star2") then
    	  lXpos = pObjPos[1] + (pRadius * cos(y) * sin(x))
		  	lYpos = pObjPos[2] + (pRadius * sin(y) * sin(x))
				lZpos = pObjPos[3]
	    elseif (pShape == "Egg") then
    	  lXpos = pObjPos[1] + (pRadius * sin(y))
		  	lYpos = pObjPos[2] + (pRadius * cos(x) * cos(y))
				lZpos = pObjPos[3] + (pRadius * sin(y))
	    elseif (pShape == "Almofada") then
    	  lXpos = pObjPos[1] + (pRadius * sin(x))
		  	lYpos = pObjPos[2] + (pRadius * cos(y) * cos(x))
				lZpos = pObjPos[3] + (pRadius * sin(y))
	    elseif (pShape == "Tube") then
    	  lXpos = pObjPos[1] + (pRadius * cos(y))
		  	lYpos = pObjPos[2] + (pRadius * sin(y))
				lZpos = pObjPos[3] + (2 * pRadius * sin(x))
	    elseif (pShape == "Buterfly") then
    	  lXpos = pObjPos[1] + (pRadius * cos(x))
		  	lYpos = pObjPos[2] + (pRadius * cos(x) * sin(y))
				lZpos = pObjPos[3] + (pRadius * cos(x))
	    elseif (pShape == "Buterfly2") then
    	  lXpos = pObjPos[1] + (pRadius * cos(x))
		  	lYpos = pObjPos[2] + (pRadius * cos(x))
				lZpos = pObjPos[3] + (pRadius * cos(x) * sin(y))
	    elseif (pShape == "Cube2") then
    	  lXpos = pObjPos[1] + (pRadius * sin(x) * cos(y))
		  	lYpos = pObjPos[2] + (pRadius * cos(y) * cos(x))
				lZpos = pObjPos[3] + (pRadius * sin(x) * sin(y))
	    elseif (pShape == "Adn") then
    	  lXpos = pObjPos[1] + (pRadius * sin(x) * cos(y))
		  	lYpos = pObjPos[2] + (pRadius * cos(y))
				lZpos = pObjPos[3] + (pRadius * sin(x) * sin(y))
	    elseif (pShape == "Sphere") then
    	  lXpos = pObjPos[1] + (pRadius * cos(x) * sin(y))
		  	lYpos = pObjPos[2] + (pRadius * sin(x))
				lZpos = pObjPos[3] + (pRadius * cos(x) * cos(y))
	    end
    
      lObjPos = {lXpos,lYpos,lZpos}; --this is the position of the object
    
	    if (pAstro1.Class == "Asteroid") then
	      addAsteroid( pAstro1.Type, lObjPos, pAstro1.RUs * pRUsFactor, 0, 0, 0, 0)
	    elseif (pAstro1.Class == "Pebble") then
	      addPebble( pAstro1.Type, lObjPos, 0,0,0)
	    elseif (pAstro1.Class == "Nebula") then
	      addNebula(pAstro1.Kind, pAstro1.Type, lObjPos, pAstro1.RGBV, 0, pAstro1.Size)
	    elseif (pAstro1.Class == "Cloud") then
        addDustCloud(pAstro1.Kind, pAstro1.Type, lObjPos, pAstro1.RGBV,0, pAstro1.Size)
	    elseif (pAstro1.Class == "Container") then
        addSalvage(pAstro1.Type,lObjPos, pAstro1.RUs * pRUsFactor, 0, 0, 0, 0)
	    end

    end
  end

end

function AddObjecto(pAstro,pObjPos,pRUsFactor)
    if (pAstro.Class == "Asteroid") then
      addAsteroid( pAstro.Type, pObjPos, pAstro.RUs * pRUsFactor, 0, 0, 0, 0)
    elseif (pAstro.Class == "Pebble") then
      addPebble( pAstro.Type, pObjPos, 0,0,0)
    elseif (pAstro.Class == "Nebula") then
      addNebula(pAstro.Kind, pAstro.Type, pObjPos, pAstro.RGBV, 0, pAstro.Size)
    elseif (pAstro.Class == "Container") then
      addSalvage(pAstro.Type,pObjPos, pAstro.RUs * pRUsFactor, 0, 0, 0, 0)
    end
end