Rally Release v3
-Code is now easier to implement
-Add DoRallyModeSetup to LevelSetup()
-Add DoRallyMode() between GameRunning() and coroutine.yield()
-Add everything after the LevelLogic() function to your code!
This is code for rallying seedlings in Eufloria, a feature I thought the game long needed.
"Rallying" is the movement of several asteroids' worth of seedlings at the same time.
This is much quicker than the usual method of selecting the destination for every planet.
The system is a one-time move and thus seedlings grown after the rally will not follow it.
Instructions are included in the demo, but...
The program's on mode is split into 3 different stages IDLE, SELECTION, and DESTINATION.
In idle, the program does nothing but monitor for input.
In selection, asteroids are clicked to select for rallying.
In destination, the destination asteroid is clicked. Once this stage is reached, the program returns to idle.
Changing the stages is done by double clicking the Left Mouse Button(LMB). A triple click of the LMB in idle mode will select ALL on-screen roids in SELECTION mode.
Sprites display the current stage.
Selected asteroids are shown in blue.
One RMB click turns the rally mode off and on.
Please leave suggestions, bugs, etc. in this thread.
--Created by Hitman271
--Special thanks to Pilchard123
function LevelSetup()
DoRallyModeSetup() ------------------------------------------------------------------- Important
-- Set Global Values
Globals.G.Asteroids=(0)
Globals.G.EnemyFactionsMin=(0)
Globals.G.EnemyFactionsMax=(0)
Globals.G.GreysProbability=(0)
SetDysonTreeButtonAvailable(true)
SetTreeInfoAvailable(true)
SetCoreInfoAvailable(true)
SetAttribsInfoAvailable(true)
SetEnemyInfoAvailable(true)
-- Create Map
-- Asteroid 0
a = AddAsteroidWithAttribs(200,-100, 0.4,0.4,0.6)
a.Owner = 1
a:AddSeedlings(75)
a:AddDysonTree()
-- Ai planets
a = AddAsteroidWithAttribs(0,12000, 0.7,0.7,0.4)
a.Owner = 2
a.Radius=800
a:AddSeedlings(300)
angle = math.rad(30)
for i= 1, 15 do
r = i*500 + 1700
x1 = math.cos( angle*i )*r
y1 = math.sin( angle*i )*r
a = AddAsteroidWithAttribs(x1,y1, 0.4,0.4,0.6)
a.Owner = 1
a:AddSeedlings(40)
a:AddDysonTree()
end
end
function LevelLogic()
for i=0,100 do
Roid = GetAsteroid(i)
if Roid~= nil then
Roid.SendDistance = 5000
else break end
end
GetAsteroid(4).SendDistance = 2500
GetAsteroid(0).SendDistance = 2000
Pause()
m=("Rally System by Hitman271")
MessageBox(m)
print(m)
WaitDialog()
Unpause()
Pause()
m=("Double-clicking LMB turns on GREEN/selection mode. Click the SENDING ASTEROIDS in GREEN mode."..
"A LMB triple click selects ALL asteroids on screen. Clicking an asteroid twice will deselect it.")
MessageBox(m)
print(m)
WaitDialog()
Unpause()
Pause()
m=("Another LMB double click turns on RED/destination mode. "..
"Click the DESTINATION ASTEROID in RED mode. Note: you must own this asteroid!")
MessageBox(m)
print(m)
WaitDialog()
Unpause()
Pause()
m=("RMB turns the RallyMode off/on. The mode begins turned off.")
MessageBox(m)
print(m)
WaitDialog()
Unpause()
Pause()
m=("Leave suggestions/comments/bugs in forum post!")
MessageBox(m)
print(m)
WaitDialog()
Unpause()
Pause()
m=("These instructions are printed in the console!")
MessageBox(m)
print(m)
WaitDialog()
Unpause()
print(" ")
while GameRunning() do
-------------------------------RallyModeSTART
DoRallyMode() --Add this function between GameRunning() and coroutine.yield()
--same placement as in this code
-------------------------------RallyModeEND
-- Time the game has been running
Timer = GetGameTime()
SetBackdropColour(240,255,240)
coroutine.yield()
if GetEmpire(1):GetNumOwnedAsteroids() == 0 then
Pause()
MessageBox("You lost a tech demo...")
WaitDialog()
Unpause()
Quit(false)
end
if GetAI(2):GetNumOwnedAsteroids() == 0 then
Pause()
MessageBox("You actually played to the end of a demonstration... well done?")
WaitDialog()
Unpause()
Quit(true)
end
end
end
--------------------------------
---------------------------------
---------------------------------RallyModeSTART
---------------------------------
---------------------------------
function DoRallyModeSetup()
----constants
MaxTimeBetweenClicks = 0.45 --length of time for triple or double click
numroids = -1 --calculated later
NoTripleClickList = {} --a list of planets that can never be triple clicked on
--due to Eufloria engine limitations, large off-screen roids are reported as being on screen
--so in other words, put the ids of very large roids in this list
--NoTripleClickList[ ID of roid ] = 1
----floats
RallyStatus = 0 -- 0 is idle, 1 is selection, 2 is destination selection , 3 is game movement of seedlings, then 0 again
TimeMouseDown = 0
TimeMouseUp = 0
ClickNumber=0
OldX = 0
OldY = 0
selectedid = -1
norally = 1 -- this is a check for if the player is clicking empty space or an asteroid
DoTripleClick = 0
-----selection variables
NumPlanetsSelected = 0
RallyPlanetList = {}
CheckDupes = 0
DestPlanet = -1
RallyModeInitialized = 1
end
function DoRallyMode()
if ( numroids <= 0 ) then
numroids = -1
for i = 0, 500 do
if GetAsteroid(i) ~= nil then
numroids = numroids + 1
else
break
end
end
end
if (DoTripleClick==1) then
NumPlanetsSelected = 0
for i = 0, numroids do
a = GetAsteroid(i)
if (a~= nil) then
if ( a.OnScreen == true and a.Owner == 1 and NoTripleClickList[i] == nil ) then
NumPlanetsSelected = NumPlanetsSelected + 1
RallyPlanetList[NumPlanetsSelected] = i
end
end
end
DoTripleClick=0
end
if (CheckDupes==1 ) then
CheckDupes=0
LastRoid = RallyPlanetList[ NumPlanetsSelected ]
for i=1,NumPlanetsSelected-1 do
if ( RallyPlanetList[ i ] == LastRoid ) then --we have a duplicate
RallyPlanetList[ i ] = -1
RallyPlanetList[ NumPlanetsSelected ] = -1
end
end
end
if (RallyStatus==3) then
if (DestPlanet ~= -1 ) then
for roidtocheck=1,NumPlanetsSelected do
whichRoid = GetAsteroid(RallyPlanetList[roidtocheck]) --this planet has the seedlings to send
if whichRoid ~= nil then
whichRoid:SendSeedlingsToTarget(1, whichRoid:GetNumSeedlings(1), GetAsteroid(DestPlanet) )
end
end
end
ResetRallyMode()
end
--Drawing function to show which roids are selected and the rallymode status
if ( RallyStatus >0 ) then
if (RallyStatus==1) then
r=0 g=1 b=0
elseif (RallyStatus==2) then
r=1 g=0 b=0
elseif (RallyStatus==3) then
r=0 g=0 b=1
else
r=1 g=1 b=1
end
Angle = math.rad(45)
Radius = (math.cos( Timer*3 )+1.5)*25/GetCameraScale()
Size = 7/GetCameraScale()
for i=1,8 do
Ang = Timer*2 + Angle*i
spriteX = math.cos( Ang )*Radius + GetCameraX()
spriteY = math.sin( Ang )*Radius + GetCameraY()
DrawSprite(1, spriteX, spriteY, r, g,b, 1, Size )
end
if (NumPlanetsSelected>0) then
for i=1,NumPlanetsSelected do
a = GetAsteroid(RallyPlanetList[i])
if (a ~= nil) then
spriteX = a.Position.X
spriteY = a.Position.Y
Size = a.Radius*( math.sin(GetGameTime()*3)*0.5 + 2.5 )
DrawSprite(6, spriteX, spriteY, 0, 0,1, 1, Size )
end
end
end
end
end
function OnMouseRightDownScreen(x,y)
if (RallyModeInitialized == 1 ) then
if norally==0 then
ResetRallyMode()
else
norally=0
end
end
end
function OnMouseLeftUpScreen(x,y)
if (RallyModeInitialized == 1 ) then
if (norally==0) then
TimeMouseUp = GetGameTime()
end
end
end
function OnMouseLeftDownScreen(x,y)
if (RallyModeInitialized == 1 ) then
if (norally==0) then
TimeMouseDown = GetGameTime()
MouseMovedDis = (OldX-x)^2 + (OldY-y)^2
if ( (TimeMouseDown - TimeMouseUp) > MaxTimeBetweenClicks or MouseMovedDis>1 ) then --restart it all
ClickNumber=0
else --update clicknumber
ClickNumber = ClickNumber+1
if (ClickNumber==2) then --do triple click selects all on screen planets
DoTripleClick = 1
end
if (ClickNumber==1) then
RallyStatus = RallyStatus+1
end
end
OldX = x
OldY = y
end
end
end
function OnAsteroidSelected(id)
if (RallyModeInitialized == 1 ) then
if GetEmpire(1):OwnsAsteroidID(id) then
selectedid = id
CheckDupes=1
end
if (RallyStatus==0) then
norally=1
elseif (RallyStatus==1) then --add the planets!
NumPlanetsSelected = NumPlanetsSelected+1
RallyPlanetList[NumPlanetsSelected] = selectedid
elseif (RallyStatus==2) then --select the destination
DestPlanet = id --planet doesn't have to be owned!
RallyStatus=3
end
end
end
function ResetRallyMode()
RallyStatus = 0
DestPlanet = -1
NumPlanetsSelected = 0
RallyPlanetList = {}
CheckDupes=0
DoTripleClick=0
OldX = 0
OldY = 0
end
---------------------------------
---------------------------------
---------------------------------RallyModeEND
---------------------------------
---------------------------------