Sign in to follow this  
Pussycat_669

Management of location effects

Recommended Posts

Pussycat_669    122
Hi y'all!

My situation is this: I'm working on a 2d grid. I've got a grid which stores all sorts of effects which can be triggered either by entering, exiting or resting/walking on a field with the same effect or a mixture of the three, depending on the parameters of the individual effect (so an effect can have both a trigger situation for being entered or being exited for example). Usually the same effect doesn't stack (hence can only be activated once by an object) although exceptions can be expected. This would probably be fairly easy, if the objects are always only one field large but it's not necessarily the case here. Hence every effect also either counts as full-count or part-count. To (poorly) visualize this for an enter sensitive effect as an example, think about a 2x2 field large object which moves forward.



[img]http://i290.photobucket.com/albums/ll259/Pussycat669_ToEE/Part-count.jpg[/img]

This step would activate the effect if it was part-count, the two coordinates of the dots would include the effect and no former coordinate of the object would share a field with the effect.

In contrast, an object has to be 'engulfed' by a full-count enter effect for it to actually trigger which would look like this.


[img]http://i290.photobucket.com/albums/ll259/Pussycat669_ToEE/Full-count.jpg[/img]

Difference being that the O's are coordinates of the object which already included the effect before it moved.


Is there any tested and proved Algorithm to get a validated list of all effects that would trigger after a step/rest? Because my attempts tend to break all the time. My shot at this was to go through every single coordinate of an object, get the effects there, get the effects of the field moving from that coordinate into the chosen direction, then validate/ invalidate all you can (at least the part-count effects), move to the next coordinate and repeat from step one but it is really hard for me to get some optimized code out of that for some reason.

Share this post


Link to post
Share on other sites
Tiblanc    560
I don't know if there's a proven algorithm for this, but have you tried working with zones instead of individual fields? Keep the relationship between objects and zones instead of fields and effects. Everytime your objects move, check if they enter a new zone or leave a zone and keep the list of occupied zones updated. The actual code to determine if an object is in or out of a zone can work with individual fields like you do right now, but you won't need the extra logic to keep track of entering and leaving an effect. It should speed things up in the end because you can use different logic in both cases. If currently in a zone, you know you left it if your object moved 1 field outside of the area, so you can start checking the frontal fields first. If entering, you can check the rear fields first and if they are not in the zone, you don't need to check the others.

Share this post


Link to post
Share on other sites
Pussycat_669    122
Thanks for getting my gears back into motion. I ended up storing currently occupied and partly occupied effects within the objects themselves (can't really store them in individual zones since the language I'm using doesn't allow dynamic creation/destruction of objects during runtime and creating every individual zone by hand before startup might get tedious very fast). That way I'm able to cast the frame of an object on the area I want to move it, get a copy from the effects there, compare them with the effects stored with the object and work my way from there. Is this close enough to your suggestion?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this