Function problem (hexagonal zone grid)

Get help using Construct 2

Post » Tue Nov 05, 2013 11:29 pm

I'm trying to make a system that spreads a player's control over the terrain. The terrain is pre-made of hexagons.

Each hexagon has a cost (like the one used in pathing). so when the player places a base in an hexagon with no owner, control spreads from the base out.
The base has "power" to determine how far can it's control reach in every direction.

example image 1

example image 2

CAPX V.1

I tried to use a function to make each owned hexagon spread to every non-owned hexagon around it using the base "power". However I don't know how the make construct differentiate between instances in functions when every object is actually the same.

Any ideas?

EDIT: I played around A LOT with it, and at least I got it to spread now... however it DOES NOT behave like i want it to =( CAPX v.2Sargas2013-11-06 21:17:47
B
43
S
12
G
6
Posts: 446
Reputation: 6,807

Post » Wed Nov 06, 2013 6:11 am

Hi,
I like the event setup in your first version. So I edited that slightly to get it working.
https://dl.dropboxusercontent.com/u/5426011/fixed/sargas_hexzones.capx
All I added was parameters for the functions. Functions don't keep track of what was picked when it's called, it only knows what was passed to it.
B
94
S
33
G
117
Posts: 5,387
Reputation: 75,335

Post » Wed Nov 06, 2013 3:44 pm

@R0J0hound woah! thanks :D!!! i'm not really up to speed with functions, but what you did really helped me out!! :DDD

However, the spread is not going all 5 in every direction =(, any idea why it might be?

V.2 (I tweeked the debug text, and some other things)Sargas2013-11-06 15:51:36
B
43
S
12
G
6
Posts: 446
Reputation: 6,807

Post » Wed Nov 06, 2013 5:14 pm

@R0J0hound it seems to be "prioritizing" certain hexagons over other that never get to spread D:
B
43
S
12
G
6
Posts: 446
Reputation: 6,807

Post » Fri Nov 08, 2013 6:52 am

@Sargas
In event 15 it has the condition "hex owner=0". This is where the seeming priority comes from. You can disable that condition and it will spread correctly, but base2 will overwrite areas base has and vise-versa. One idea for a remedy for that would be to add a Boolean variable to hex and call it say "owned" and replace that condition in event 15 with a "[negated] hex is owned". So with that it will spread correctly but we also need to set "owned" to true eventually so we do that by adding a sub-event to event 4:

system: Pick all hex
hex: owner != 0
---> hex: set owned to true
B
94
S
33
G
117
Posts: 5,387
Reputation: 75,335

Post » Fri Nov 08, 2013 11:02 am

@R0J0hound hey, that works perfectly ^^

fun fact, the original design of this had a "hasOwner" boolean on Hex -_-.
I find it super weird, in my mind the logic in "!owned" and "owner=0" is the same D:. which is why I ended up not using the boolean in the first place... are booleans more easily read?

btw, at this point I should put you in the credits for my game xD you've helped me several times already with my game ^^
B
43
S
12
G
6
Posts: 446
Reputation: 6,807


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 10 guests