Author Topic: Lua scripting in Eufloria - reference  (Read 163408 times)

0 Members and 1 Guest are viewing this topic.

ulfn

  • Guest
Re: Lua scripting in Eufloria - reference
« Reply #15 on: May 22, 2010, 02:26:26 AM »
Using the time-honored method of trial-and-error I found the following fields for the Asteroid type:

Fieldtypedescription
positionPositionThe position of the asteroid.
radiusfloatThe radius of the asteroid.
attribsAttributesAsteroid attributes (strength, energy, speed)

With the types

Position
Fieldtype
xfloat
yfloat

Attributes
Fieldtype
strengthfloat
energyfloat
speedfloat

The position and radius are really handy for instance for computing if one asteroid is reachable from another:
(click to show/hide)

Edit: The attribs and radius are in jh's userdata list, but the position field isn't.

Alex

  • Administrator
  • Ent
  • *****
  • Thank You
  • -Given: 3
  • -Receive: 14
  • Posts: 1,035
Re: Lua scripting in Eufloria - reference
« Reply #16 on: August 03, 2010, 05:47:48 AM »
Added to the list (these should be in and working in 2.05):
General game entities - these functions can be used on most anything in the game (seedlings, trees, asteroids, etc)
Function nameReturn valueDescription
SetVisible(int faction, bool visible)nilSets whether the entity can be seen by the given faction.
Regen(float time)niltells the entity to regenerate some of its energy. The parameter is delta time, so set it to e.g. 1 to regenerate a second's worth of energy. Normally this is called once a frame with the duration of the frame passed in.
DistanceSquaredTo(Entity other)floatreturns the squared distance from the centre of this entity to the centre of the one you passed in.
AttackedBy(Entity other)nilTells this entity that it was attacked by the one you pass in.
AttackedBy(Entity other, float time)nilTells this entity that it was attacked by the one you pass in for 'time' seconds. Normally the second value is the frame duration.
Field nameTypeDescription
PositionVector3Position of the entity - access individual coords with capital letters e.g. entity.Position.X or entity.Position.Y.
Radiusfloatradius of the entity.
OnScreenbooltells you whether the entity is on the screen or not.
ActiveboolTells whether the entity is still active. Set it to false to remove the entity from the game.

IDemon

  • Webdesigner/Developer and Magician
  • Shoot
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
  • Talent does what it can, Genius does what it must.
Re: Lua scripting in Eufloria - reference
« Reply #17 on: August 03, 2010, 07:32:20 AM »
Alex truly a massive thank you for publishing all this for us it has been no end of help in developing my map editor thus far.
Talent does what it can, Genius does what it must.

dragoonreas

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 35
  • Eufloria: Yes
Re: Lua scripting in Eufloria - reference
« Reply #18 on: August 03, 2010, 09:18:59 PM »
I was looking through the userdata structures list jhchrist posted and noticed the get_FacingAngle and get_Rotation functions for Asteroids. I'm assuming the FacingAngle parameter controls the absolute rotation of the asteroid, and the Rotation parameter controls how fast and in what direction the asteroid is spinning. Are these assumptions correct?

I tried using GetAsteroid(id).FacingAngle but it didn't seem to do anything. I might have been setting the facing angle using radians rather then degrees, which may explain why it didn't appear to have any affect if it's supposed to be set using degrees.

I also tried using GetAsteroid(id).Rotation but got an error saying there was no Set function for this parameter. Does this mean that the asteroid rotation (spin) isn't bound in Lua, or is there another way to set it?

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 21
  • Posts: 929
  • Eufloria: Yes
Re: Lua scripting in Eufloria - reference
« Reply #19 on: August 03, 2010, 09:21:17 PM »
Rotation doesn't work. I tried already, a while back.

Here's what Alex said:

...

for now, no rotating asteroids or even experiments with rotating asteroids - sorry!

dragoonreas

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 35
  • Eufloria: Yes
Re: Lua scripting in Eufloria - reference
« Reply #20 on: August 03, 2010, 09:46:22 PM »
That's a shame, spinning asteroids would have looked cool in the level I'm making. :(

I think the FacingAngle still retained the value I gave it though, so at least I won't have to create a separate array to store the angle values I'm using for my tree fractal algorithm. I'll also be making use of that new DistanceSquaredTo function in my algorithm too. :)

EDIT: Nope, the FacingAngle parameter stays at 0 no matter what you set it to. The DistanceSquaredTo function is also not working for me, as I get the following error message when I try to use it "Object reference not set to an instance of an object."
« Last Edit: August 04, 2010, 03:59:23 AM by dragoonreas »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Lua scripting in Eufloria - reference
« Reply #21 on: August 04, 2010, 11:00:47 PM »
You CAN rotate asteroids, but the trees and shrubbery and seedlings and everything else do not rotate with it.  Therefore because asteroids are circular, it effectively does nothing.

spywhere

  • Eufloria != Euroflia
  • Seedling
  • **
  • Thank You
  • -Given: 1
  • -Receive: 3
  • Posts: 27
  • CEO of DP
    • Senior Design Interactive Official Website
  • Eufloria: Yes
Re: Lua scripting in Eufloria - reference
« Reply #22 on: October 21, 2010, 10:21:39 PM »
Is "Globals.Flowers.MaxVolume" exist in the game?

I just make a commands database in my Tools and set default value as in the game and found that only one field is not used which is Globals.Flowers.MaxVolume

I use default.xml to set default value.

Thanks...

PS. Sorry for my bad English
Euroflia : Online graphic Eufloria level editor now temporary dropped...
http://sdcenter.ispace.in.th/euroflia
http://sdcenter.zoka.cc/euroflia

Alex

  • Administrator
  • Ent
  • *****
  • Thank You
  • -Given: 3
  • -Receive: 14
  • Posts: 1,035
Re: Lua scripting in Eufloria - reference
« Reply #23 on: October 28, 2010, 02:51:35 AM »
It does exist - it's used when flowers and mines are plucked, and for the flowers and mines loop sounds.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Lua scripting in Eufloria - reference
« Reply #24 on: December 21, 2010, 06:24:02 AM »
Alex, what does GetLeafColour(int) do?

I saw it in somebody's code.  I had no idea it was a command!  I gather it must be run on a tree.  What does it return?

If this could be used to check what colour a particular empire is, that would be very useful to me!

Alex

  • Administrator
  • Ent
  • *****
  • Thank You
  • -Given: 3
  • -Receive: 14
  • Posts: 1,035
Re: Lua scripting in Eufloria - reference
« Reply #25 on: December 21, 2010, 09:21:08 PM »
It's a function in "Structure" (i.e. trees), takes an integer from 0 to 4 inclusive and returns a colour. Each team has 5 colours that represent it, and trees store an internal version of it so that when tree ownership changes, the leaves that it bears can smoothly change colour instead of changing immediately.

If you want to get a team colour... here's a tasty bit for you.
Code: [Select]
Game = luanet.import_type("Eufloria.ColonyGame");
team1red0 = Game.GetFactionColour(1,0)
team1red1 = Game.GetFactionColour(1,1)
team4red3 = Game.GetFactionColour(4,3)

luanet.import_type gives you access to a class type theoretically giving you the opportunity to create instances of this type as well, though I am not sure what it would mean to do this in many cases for Eufloria's classes.

GetFactionColour is a static function of ColonyGame so you only need the type to be able to access it, not the ColonyGame instance. Hence the code above assigns the type ColonyGame to the variable CG, and this makes available the static functions of that type.

The base game class (that handles the front end etc) is Eufloria.Game, and has a static instance called Eufloria.Game.Instance from which various things are available (including Game.Instance.ColonyGame if the game is running).

e.g.
Code: [Select]
Program = luanet.import_type("Eufloria.Game")
ProgramInstance = Program.Instance
Game = luanet.import_type("Eufloria.ColonyGame")
GameInstance = ProgramInstance.ColonyGame
if (GameInstance ~= nil) -- use some part of colonygame instance e.g. call ApplyDarkModeSettings()!

All very untested and unsupported I must hasted to add!





Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 21
  • Posts: 929
  • Eufloria: Yes
Re: Lua scripting in Eufloria - reference
« Reply #26 on: December 21, 2010, 09:28:15 PM »
Can you set the colours with this too?

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Lua scripting in Eufloria - reference
« Reply #27 on: December 21, 2010, 10:13:20 PM »
Even with just what Alex has given me, I could effectively "set" colours.  I could develop a script that checks what the colour is, and changes the asteroid to a different empire number if it's a colour I don't like.  :>

This is freaking awesome... if it works, this will finally give me the ability to produce maps that look exactly how I intend them to look, every time they are played.  :>

Alex

  • Administrator
  • Ent
  • *****
  • Thank You
  • -Given: 3
  • -Receive: 14
  • Posts: 1,035
Re: Lua scripting in Eufloria - reference
« Reply #28 on: December 21, 2010, 11:00:30 PM »
I don't think you can set them at the moment, maybe there's a way but as ColorF (the data returned by GetFactionColour) is a struct not a class, you don't get passed back a reference, so going GetFactionColour(1,4).R = 0.8 won't do anything. Same for GetLeafColour. The changing empire plan ought to work though. Just bear in mind that the leaf colours may not be close to any of the team colours if the asteroid was recently taken over.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Lua scripting in Eufloria - reference
« Reply #29 on: January 03, 2011, 07:15:15 AM »
I'm currently working on an extremely large and complicated level and I'm looking for ways to increase the FPS ingame.  I've already been able to make drastic improvements to some parts of the code by breaking out of loops early, using cheaper calculations to rule things out more quickly, avoiding math.sqrt wherever possible, trying to spot large inefficiencies in the looping structures, and so on.

I was wondering if you know if there are any Eufloria functions that are particularly expensive?  EG, does it cost more CPU cycles to draw a sprite, or a line?  Is "GetAsteroid" expensive?  What about "GetNumSeedlings"?  If there are any obvious cases where you can accomplish something in two different ways, and one is much cheaper than the other, I'd really like to know about them.. :>