Euflorium: The Eufloria Community
Eufloria => Eufloria Classic => Eufloria Classic Mods => Topic started by: hitman271 on June 16, 2011, 06:33:00 AM
-
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
---------------------------------
---------------------------------
-
The third rally system, Good Job :)
-
Nice work dude. :> Welcome aboard by the way!
-
Finally got around checking this, looks great: but not very good if you want it in-game(really sucks to say that :/) because it tkaes minimum 4 seconds before any actions are being made atleast!
Maybe make it a triple/double tap then the green appears then do the same and the sam process, I love the dots that goes in and out of the cester of the screen :)
Though: this is damn good for a first code, unless you code else :P
EDIT: And to be honest, I don't think this can be called a rally system, it's more like a multisending function :)
-
Bump
I took Aino's advice and changed the control to a double-click for a much quicker and less accidental use.
A triple click now lives up to the thread's title; if you own all roids on screen, you can move them all at once!
-
This is awesome :D
Expecting, but not demanding, more from you :)
Good work on the rally system, though it is still not a rally system... I, atleast, consider a rally system as an automatic seed sender :)
-
(http://ploader.net/files/afa8ad86d4e71a22fdd59e7cc479e479.jpg)
(http://ploader.net/files/b1e66186f109193db768dd6bf187ee05.jpg)
Almost ready for beta testing :)
-
Looks shiny! :> And worthy of its own thread, when released..
-
is this finished now?
ill add it to the Custom levels and functions thread if its a finished article...
let me know.
thx
aws
-
It's finished now. I've added a deselection feature. Simply click on a roid for a second time to de-select it.
-
Nice, can't wait to see the finished product :D
-
Version 3 has been released. This update fixed a right-click bug and made code implementation MUCH easier. Leave any bugs, comments, etc. here. Thanks!
-
Version 3 has been released...made code implementation MUCH easier. Leave any bugs, comments, etc. here. Thanks!
lol - you say that, but.....
???!
-
It can't be that hard? o.O
Although, I can't download the file :S
-
It can't be that hard? o.O
Although, I can't download the file :S
lol - i understand it shouldnt be that hard and im sure its not. ive tried i can assure you ;)
its just when i add the code verbatum, i get both Hitman's level design as well as my own. obviously i only want the rally code, not the roids, etc.. which is the bit i cant make work- adding the rally code but not the roids, etc..
if you wanna take a look aino, ill be glad to send you my code as is....
??
-
I've already PM'd you about it, my answer was a clear yes :P
-
sorted!
-
Nice to hear :D