I was looking into having structures that only function or run at full capacity when within range of specific other structures. What I'm wondering is if it's more efficient to run a check for structures that the central structure empowers as part of that unit's code or if the empowered structures should check to see if they are within range of the central structure and then set their own values.
Perhaps some sort of hybrid solution is the best answer, or maybe there are quirks in Spring I'm not yet aware of, I do know that someone mentioned that checking the range from one thing to another was an expensive thing to do, but it seems like it would be okay upon either attempting to build something, or build completion. (Not sure if I wanna let people 'pre-build' outside of the central structures yet, among other things.)
Thanks for any information you can provide.
LUA Efficiency
Moderator: Moderators
Re: LUA Efficiency
It's certainly doable. Check out KDR's Fibre. It's a game with features similar to what you outlined.
PS: It's Lua, not lua or LUA.
PS: It's Lua, not lua or LUA.

Re: LUA Efficiency
If there's only a few central structures then it's certainly faster to just store the positions of the central structures in some array, and for all empowered structures, calculate distances to these positions to see if they are in range of (one of the) central structures.deveyus wrote:I was looking into having structures that only function or run at full capacity when within range of specific other structures. What I'm wondering is if it's more efficient to run a check for structures that the central structure empowers as part of that unit's code or if the empowered structures should check to see if they are within range of the central structure and then set their own values.
Recalculate everything whenever central structure is created / destroyed / changes team. (Re)calculate for empowered structure when it is created / changes team.
This definitely applies if the range is pretty big and there are usually lots of irrelevant units within this range.
Re: LUA Efficiency
I'd suggest looking at the code for supply giving structures in S44, only the code (game_ammo.lua) is really just dreadful and shouldn't be viewed by anyone other than me the next time it breaks.
Re: LUA Efficiency
Excellent, I'll do that with storing the information in an array and then pulling it for the structures that need to know. (which is a -large- percent of the structures.)
From what I understand, just about anything we want to do is possible (though, perhaps impractical) through Lua, correct?
While I've got your ear, is there a gameplay reason why the commander in many mods (not all, as I'm well aware) is a 'kbot' type? Is it to be able to play on rough maps (i.e. a starting vehicle wouldn't be able to do so because of the slopes) or is it merely an old aesthetic left over from OTA?
From what I understand, just about anything we want to do is possible (though, perhaps impractical) through Lua, correct?
While I've got your ear, is there a gameplay reason why the commander in many mods (not all, as I'm well aware) is a 'kbot' type? Is it to be able to play on rough maps (i.e. a starting vehicle wouldn't be able to do so because of the slopes) or is it merely an old aesthetic left over from OTA?
Re: LUA Efficiency
you can change the slope tolerance of various units. If you wanted, you could have an all-terrain vehicle! It's merely a TA holdover. Some games, like GRTS, S44, and KP have buildings as starting units.
Re: LUA Efficiency
It's a holdover from TA when you couldn't select your start position, and the set positions may be on hilly terrain or under water, so the start unit/commander (btw, no need to start with just 1 unit in Spring - S44 spawns multiple units in addition to the Headquarters building which is what the engine sees as the commander, at game start) traditionally has very high slope tolerance and amphibious capability of some kind.
Re: LUA Efficiency
there is a lua callin to block start points
Re: LUA Efficiency
structures within range of other structures.
You shouldnt need to recheck since structures do not move!
Run an initial test on startup, and then whenever the influencing structure is built, on the unitfinished check, test if it is within range to make a difference, and if so, recalc. Same on UnitDestroyed.
No need for second by second updates unless you're a mobile unit..
You shouldnt need to recheck since structures do not move!
Run an initial test on startup, and then whenever the influencing structure is built, on the unitfinished check, test if it is within range to make a difference, and if so, recalc. Same on UnitDestroyed.
No need for second by second updates unless you're a mobile unit..