Lead Developer, Stardock Entertainment

The Zone of control (ZOC) code has always been a bit odd since it was written for GalCiv2, with weird little bubbles, twists, etc. But it mostly worked in GC2, and I didn't have time to give it a lot of love when porting it to the new engine. The code to update the ZOC is also fairly inefficient, which is why it only updates at the end of a turn. The ZOC expands based on the influence of the city and the player's influence ability.  It works by specifying a source, which has a power and a radius. The power determines how much influence the source is exerting on the tile, so that if there are two sources in the same area with different owners, the player who 'owns' the tile is the one who has the most power in that tile.

This is how the influence looks in 1.09e for a city hub which has a radius of 2: 

Current implementation - radius 2

Looks OK, right?  But wait, city hubs have a radius of 2, and that's only showing ZOC around tiles that are 1 tile away from the hub.  It turns out that the ZOC code was modifying the power of the source (the city hub) by its relative distance from the center using the Euclidean distance forumla  So the closer you were to the center, the higher the power was, and the tiles with distance 2 had a power of 0 because they were at the farthest edge. Also, adding an improvement on the edge of the ZOC didn't bump out the influence because most of them only have a radius of 1, which meant that the only tile that got influence was the one they were actually in, which tended to already have influence from the city hub.  Also, since you can have up to 4 improvements in one tile, each exuding their own influence, they were overwriting each other as sources. 

So first I changed it so that all tiles within the radius got the same power value.  If we cared about pixel distance instead of tile distance, having the influence fade out towards the edge of the range would make sense, but everything uses tile distance for calculations, and the descriptions for how much influence an improvement gives you says 2 tiles.  I also made it so that the influence was calculated from the city tiles instead of the improvements themselves, so that each tile would return the max influence radius and power for all the improvements on the tile.  This is what happened:

 

Per tile influence, constant influence

Well, rats.  The interpolation code is clearly just using the center point of each tile and it looks pretty lame.  The city hub is now starting with a radius of 1 and growing to 2 once it's built up a little more. But it looks lame, even with a radius of 2.  It must need more points.  Hmm, there are some extra points that are commented out in the code that calculates the edges. Maybe just uncommenting those will work?

Uncommented points

Nope.  That obviously isn't going to work. That must be why the points were commented out.  But why weren't they deleted when they clearly don't work? I hate that.  The developer who wrote the original ZOC code hasn't worked here for over 5 years, so there is no target for my crankiness.  

I commented out those lines again in case I needed them for reference and stared at the edge calculation code again.  I decided to simply outline the edges of the tiles, since that would be clear which tiles exactly were under your influence, and the filtering code should take care of adjacent zones.

Outlines

Well, that's better, I guess.  You can tell where your influence is--but wait, why isn't that fire shard in my influence? It's only two tiles away.  Oh, but it's still using the Euclidean distance formula to set the powers.  Well, that's lame, and it makes it look lame too.  No one is going to look at this and say, "Oh, it's calculating the Euclidean distance from the city hub." They're going to count the tiles.

So I made it not check the Euclidean distance and just check everything in the bounding rect with the source at its center and a radius of 2.

Using squares

I think it looks a lot better.  This is a city that has been built up a little, and has two improvements built. The first improvement, the farm, only has a radius of 1, so it was inside the 2 tile radius of the city hub.  It wasn't until I added the next improvement that it bumped out a bit.

I might need to do something with the line interpolation code though, because the leftmost corner of the zone always seems very pointy and we want the rounded squares for aesthetics.  Also, I haven't played very long with this code so I don't know how well it will react with adjacent zones yet. But I think it's headed in the right direction, and the calculations are a lot easier to read now, which is always good.  It's even a bit faster since it doesn't have to calculate the Euclidean distance anymore.  Now, to test and polish...

 


Comments (Page 5)
8 PagesFirst 3 4 5 6 7  Last
on Nov 09, 2010

I'd be happy with tetragons as a middle ground.

SinVraal
And yes, armies have a zone of control, I heard of that too...

Well, not in Elemental. Neither units nor armies have a ZOC there.

That's actually one of the main problems of tactical (and strategical) army stuffs. The shallowness of the system...

on Nov 09, 2010

Loved it, thx.

 

Re-commenting not working commented code is sth I do, too ... with my own code.

"I must have thought something about not deleting this ... can't remember what, now. Let's not delete it now ... "

on Nov 09, 2010

No. I was not referring to Elemental. I know that Elemental does not use zoc for armies. But the first addon will focus on tactical combat. Have to search for the link... I think Frogboy mentioned it somewhere.

Gazz, you're right it's important stuff escpecially because it's all about creating yours and bashing other armies. I saw your thread of suggestions but couldn't accomplish reading all of it.

EDIT: Just read some of your thread from September about Movement restrictions and unit Zone Of Control

on Nov 09, 2010

ZOC in its traditional sense does provide some opportunities to inject strategy into a game. Elemental does not currently use ZOC in that sense but it might some day. Its good to have ways beyond direct damage to manipulate your opponent. I also prefer 'Sphere of Influence'. 'Flatulence Spread Matrix' seems too faction specific.

on Nov 09, 2010

I dunno, I kinda liked the shuriken shaped ZOC.

on Nov 09, 2010

Nice & well detailed journal entry. Thanks, Cari!

on Nov 09, 2010

Tridus

Squares, though. Yech.

 

 

Squares are easy as well. Just apply the Pythagorean Theorem, and you get a distance multiplier of 1.4 from corner to far corner. Of course, its not as "easy" to count 1.4, 2.8, 3.2, 4.6 as it is to count 1,2,3,4, but it is still no herculean effort.

on Nov 09, 2010

Fearzone
I don't recall anyone complaining about influence calculations.  Except for occasional funkiness where lines criss-cross, it seems okay to me as it stands, and I'm not sure what problem this solution is solving. 

The main issue would be the implementation of influence.  It is part of the fluff and one of the more enjoyable graphical elements of the game.  It offers some movement and combat bonuses to the "home" team, and the wider the influence more the more resources you can grab so it is worthwhile there. 

But it would be nice is there were something more to it.  If for example if you had another city surrounded with your influence, (plus a trade route perhaps), that you would conquer the city in x number of turns, then influence and city building could contribute toward a conquest victory, or something like that.

Or something like: pioneers and sovereigns can only build cities in areas of influence.  Since the sovereign would be limited in his ability to restore land, that would make city building and things like prestige a more important part of the game.

The main problem was when you'd get to the edge of your influence, and build an improvement there, it wouldn't increase the ZOC.  I could have just made it so that all sources had a radius of at least 2, but I'd rather have What-you-see-is-what-you-get so that the data matches what you can see visibly.  

It would be cool if we made influence a bigger part of the game.  I used to love to "Culture flip

abomination5

quoting post

Nope.  That obviously isn't going to work. That must be why the points were commented out.  But why weren't they deleted when they clearly don't work? I hate that.  The developer who wrote the original ZOC code hasn't worked here for over 5 years, so there is no target for my crankiness.  

I commented out those lines again in case I needed them for reference and stared at the edge calculation code again.  I decided to simply outline the edges of the tiles, since that would be clear which tiles exactly were under your influence, and the filtering code should take care of adjacent zones.




I'm not sure if this was a joke but it made me laugh.

No, not intentionally.  I just wanted to make sure that I wasn't duplicating bad code.  I took them out entirely once I got the points to where I wanted them.  The only reason I ever leave un-working code in comments is if it partially worked and maybe could just use some tweaking, but I always try to leave comments about why that code is commented out. 

KingHobbit
I laughed almost completely through this Cari-Elf.  I have know idea what you are talking about. 

However, is it going to help the city spamming.

Not sure if it will help city spamming, but it will make it easier for you to get to resources that are just outside your influence lines.

on Nov 09, 2010

Malsqueek

Squares are easy as well. Just apply the Pythagorean Theorem, and you get a distance multiplier of 1.4 from corner to far corner. Of course, its not as "easy" to count 1.4, 2.8, 3.2, 4.6 as it is to count 1,2,3,4, but it is still no herculean effort.

But you can't do that, really. Something with a range of 1 when going along a diagonal has a range of 1.4, etc. It's worse with movement because stuff doesn't move the same speed depending on direction, whereas with hexes you avoid the problem.

Squares suck, but we're stuck with them.

on Nov 09, 2010

With hexes you just get different problems - mainly with graphical content.

Fake angles only work in a fixed isometrical view, not with a mobile camera, and without them your cities look more like beehives.

on Nov 09, 2010

Alstein
This is going to be a nice new feature, which everyone will like, but no one will really give notice to since it seems really minor at first glance.
 
Still, it's a good change.

The question- will the AI be able to make use of this, and could autoplacement of tiles be set to make use of this?  For me, that's the key to how useful this feature will be- though that may take work from Brad as well.

It's really just a tweaked feature that exists in game already.  I don't think that the AI currently tries to expand its influence by building improvements, but since it will include more tiles, it will get some benefit indirectly.

 

RavenX
Cari, you're a certified genius darlin, rock on .

Though I do gotta say the ZoC with all the odd points on it reminds me of a shuriken, which are used by Ninjas, which automatically makes it cool...

 

Seriously though, well done. In the final pic there are one or two tiles that are 2 spaces away but still not in the ZoC. If you look above the middle building you see the glow of a dropped pouch or something. The tile above that should be in the ZoC as well since it's within the two tile range. It's looking a lot better and will make more sense and work better too IMO. The chief should give you a raise. Keep up the great work.

If we're looking at the same tile, it's 3 squares away from the city hub, which has the radius of 2.  The other improvements only have a radius of 1, so the pouch is in the zone, but not the square above it.  Individual improvements can specify different radii in their xml, but the default is 1. I also made it so that different improvements can exude stronger or weaker influence.  Right now, only resource improvements that are not adjacent to a city will "flip" based on the influence, but even that is useful.

SmilingSpectre
Wow! At last!!

Thank you, CariElf for fixing it!

But... there is several little questions remains.

 

1. We have actually "half-square" improvements. Maybe it worth to have 1/2 radius for it? I think, it could be better, because 1. It will be complement to existing "City-size ZOC" and 2. Give more "flexible" margins of ZOC. Also it reduce "overpower" of line building and will look more like existing one (but more sane).

 

2. So now this +1 ZOC works for everyone? What about second bug - with no-working "+1 ZOC" ability? (I presume now, it was because the same Euclidian calculations.) It will be +another square?

 

3. Will you fix also "End of turn ZOC" to "Immediate ZOC"? Because now I can simply extend almost-here-ZOC by save/load game. It looks very strange for me.

1) Even if you build a quarter tile improvement, it claims that tile for the city, so I think it makes sense to have the radius still be based on the whole tile.  I currently have it using the max radius and max power of all the improvements so that you get the maximum benefit of all the improvements on the tile.

2) It will add more than just one tile, depending on how big the radius of the improvement is.  For a radius of 2 tiles, you actually get an additional 12 tiles than you would if using the Euclidean distance.

3) I'd like to do that soon, but making it instant is a lower priority right now.

random_target
Just to clarify, does that mean that the way you build your cities matter now?

For example, if I have a resource north of my city outside the ZOC (or whatever name you use), building houses and other improvements toward the resource will also help expending the ZOC to that area?

Also, besides catching resources and preventing random enemies from spawning, what advantages does the ZOC give?

Anything new planned for 1.1?

Yes, now if you build towards a resource, it will extend your influence towards it.  It also makes it so that people have to declare war on you or negotiate a treaty to come into your lands.  Also, if you get into a battle on your lands, your sovereign can escape death and teleport back to the nearest city.  However, if behind enemy borders, he will die.   No new influence related features are planned for 1.1 at the moment, but even just being able to properly extend your borders will be helpful.

alaknebs
does that mean a lvl 0 settlement founded will immediately get the 1 ring instead of waiting until next turn?

No, it still only recalculates influence at the end of a turn.

 

 

 

 

on Nov 09, 2010

I hope the AI can take advantage of this new feature. Otherwise it's just a player bonus.

on Nov 09, 2010

puntarenas
A screenshot comparsion showing the outcome of different player's influence abilities would be nice or is this still to be balanced first?

If I have time to play without cheating, I'll make some additional screenshots to show the borders, etc.  The way that the player's influence abilities work is that for every 100%, the radius of all your improvements will increase by 1.  So if you have 200%, your city hub will eventually expand to a radius of 4 tiles, and the improvements will expand to a radius of 3 tiles, unless the improvement def specifies a smaller max ZOC radius.

Black-Knight
Strategy games and wargames don't need square tiles anymore nor they need hexes, we could have circles and distances now. All those absurdities are the result of an obsolete way of thinking.

But that doesn't mean you aren't doing a good job.

Grids are still extremely useful for judging relative distances, directions, etc.  Squares aren't so bad since we allow 8 directions of movement rather than just 4 like most games that use square tiles, and more than 6 which hexes give you.  It's also far easier to represent the coordinates mathematically, and easier to store stuff on a per tile basis.  I think that you'd probably have to use some kind of tree instead of a 2x2 array, which adds more overhead.  

on Nov 09, 2010

I would like to see ZOC graphics after capturing city work more like AoW (just don`t change land image in one turn, maybe some new valuable "faction power" could be good here).

on Nov 09, 2010

Black-Knight
Strategy games and wargames don't need square tiles anymore nor they need hexes, we could have circles and distances now. All those absurdities are the result of an obsolete way of thinking.

.

 

I disagree. Grids are very useful in  highly abstracted turn based games, to provide easy digestible chunks of visual information for players to be able to quickly understand the game concepts and *plan* exact movements and actions based on them.  Hex grids in particular are useful for advanced tactical concepts like directional facing and flanking in a non-real-time environment.  Sure, in a real time game these things can all be calculated behind the scenes as players execute strategy in a "ballpark" fashion, where players can make instant adjustments.  But turn based games aren't about the ballpark. They are based on absolutes that players need to be able to predict, and plan out precisely, on a turn by turn basis.

So no, they don't absolutely *need* grids. But you're still going to need some system in place for players to be able to easily calculate and predict all these abstracted action concepts to the digit, one, two, and three turns in advance, in a chess like fashion. In many cases, the easiest way to do this is with a grid.

 

8 PagesFirst 3 4 5 6 7  Last