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 7)
8 PagesFirst 5 6 7 8 
on Nov 10, 2010

I'd much rather you talk to us about the spells and the core changes that are coming to the game. I didn't even know that there was an issue with ZOC's.

I think its hard for either the community or the devs to really have a meaningful conversation about either spell or core changes until 1.1 is released. As far as pre 1.1 is concerned, I feel like we have all discussed it at great length and now we are simply waiting to see the changes they made. Personally, I like the idea of changes to ZOC as they have already stated that level 1 cities will not inherently generate influence. I think it will enhance the meaning of city shape, which is a good thing.

on Nov 10, 2010

Thank you, that was very interesting.

Sadly, i think the greatest problem involved with this topic is that ZOC, no matter how you implement its mechanics, is largely moot in the current build because it has an insignificant gameplay impact. If my ZOC is twice the size or half, rhomboid or mandelbrodian, encompasses 10000 tiles or 100, it really doesn't matter, because the only significant terrain modifiers in the game for which ZOC has a use are shards.

on Nov 10, 2010

One thing I've seen ZOC do is flip resources between different kingoms/empires.  If an outlying resource of mine ends up in another empire or kingdom's ZOC, it becomes theirs.  And vice versa if I boost my ZOC.

So I think Zone Of Control is the correct terminology in this case.

I actually like what's shown in the last pic.  This gives you another reason to 'push' a city towards another kingdom or empire, in an attempt to push back their zone of control.  Of course, your city is now closer to the border now, and hence more accessable for attack...

Someone posted up about buildings that boost influence in cities, and having these be used to determine the radius of said ZOC around that structure.  I like this idea. 

As an example:  I build the inn at the edge of the city, and the Inn has a two radius ZOC, as opposed to most structures that have just one, so the ZOC pushes out farther from the Inn. 

Building placement would be riskier if WHERE you attack a city determines which structures might be damaged in said attack, but that's a subject of another thread...

on Nov 10, 2010

I like the idea of effectively warring indirectly against another faction by tring to push your influence into their zone of control. However the AI needs to see this as a negative thing to do. For example it should modify their relationship with the perpetrator downwards and if it results in taking control of cties or important resources may even lead to war.

This being said it therefore needs to be controllable, since at the moment you can quite easily take control of a resource without actually intending too, therefore this would lead to a disgruntled neighbour, whom you didn't want to piss off. So maybe also a diplomatic option to relinquish control of certain squares. This could then also be used for diplomatic gain.

Taking this one step futher. Maybe you could trade whole resource control, which would then flip the resource to the ZOC of the new owner. For example you might have wargs that you can't use and an ally who can. You can diplomatically trade control of the tile (and maybe some tiles surrounding it) and those tiles would now show Empire influence too, within your Kingdom. This would not generate influence of it's own and would expire after a set period of time flipping control back to you.

on Nov 10, 2010

Gwenio1




It would have two cases for accessing the adjacent hexes. In AoWSM, the hexes line up into colums, and the X value offset for a hex in a given colum is the same as a square grid. Accessing the hexes above and below it are the same as a square grid (+/- 1 in the Y offset). Depending on if the colum is even or odd (which one it is depends on how the hexes are placed) will determine how to get the adjacent left/right above/below the target hex. In one case the ones above will have a Y offset that is one less that the current and those below will use the same Y offset. The other case will have those above have the same Y offset and those below have an offset that is 1 greater. Switching between these two cases would only add the overhead of an if statement that checks to see if the colum is even or odd (X % 2). If the hexes are oriented diffrently (like in HoMM 1 through 3 for the tactical combat) then row is interchangable for colum.

If you go back to old text games like atlantis, they had a hex grid where the hexes ran north south, and the vertical grid reference moved by 2 for each hex, if you moved north east the reference shifted by 1 column and 1(not 2) in the vertical direction.  This is effectively a square grid with holes but you can easily tell if the reference is valid as both coordinates have to be even or both have to be odd.

on Nov 10, 2010

Vhorthex
Although this all looks and sounds pretty nice, why is this being focused on?

I'd much rather you talk to us about the spells and the core changes that are coming to the game. I didn't even know that there was an issue with ZOC's.

But that's just me

Cheers,

V.

It's not "being focused on". It's one developer spending some time on solving a problem, and then finding it interesting enough to share with us.

That's why it's a "developer journal". They shouldn't have to pass it through marketing to make sure that it's "on message about 1.1" if it's just something interesting.  (In fact the single most interesting Sins developer journal was explaining in painstaking detail why a desync happens.)

on Nov 10, 2010

Ya, I love these tidbits. Even if it's not official 1.1 propaganda.

on Nov 10, 2010

Loren1350

Well what I meant (re: gameplay and building placement) was that if influence/territory is a well-defined quality, perhaps the map tiles could be assigned ownership not only to a player but to a specific city. I am assuming that the "at least two tiles away" rule is meant to simplify the management of improvements-to-cities situation. If each city has its own territory influence that competes against other cities (even in the same nation), then ownership is simple. Granted, I don't know how you're representing these things internally but if it's doable, it would make for more natural feeling gameplay. The two tile limit feels very artificial, and the fact that it can in certain (and by no means exceptional) circumstances lock the player out of a resource tile is annoying; I'd rather not metagame my city placement.

In short, I don't like the two-tile limitation, and it seems to me that the influence boundary calculations might allow it to be removed.

But apart from that, I am curious about [player] boundaries: How will you break ties in influence conflicts?

The reason the limit exists, which is actually 5 tiles, is to prevent cities from connecting.  This would not help two cities with roughly the same influence could easily be built right next to each other.

Currently, it picks whoever has the lower player ID to break ties.  I'd like to change this to whoever has been influencing the tile the longest, if it doesn't slow down the calculations too much.

Fearzone
Okay I like the underlying concept but don't really like the "square" look in the bottom pic and am wondering if the "corners" in the border area can be softened more, if only for an aesthetic effect.  The spread of influence needs to look like an organic flow, IMHO, which is betrayed by hugging the lines of the grid too closely.

Yes, I'll be working on making the corners more rounded.

Vhorthex
Although this all looks and sounds pretty nice, why is this being focused on?

I'd much rather you talk to us about the spells and the core changes that are coming to the game. I didn't even know that there was an issue with ZOC's.

I wrote about what I was working on.  I continue to reply because people seem interested.

Tridus


It's not "being focused on". It's one developer spending some time on solving a problem, and then finding it interesting enough to share with us.

That's why it's a "developer journal". They shouldn't have to pass it through marketing to make sure that it's "on message about 1.1" if it's just something interesting.  (In fact the single most interesting Sins developer journal was explaining in painstaking detail why a desync happens.)

If I actually had wanted to write a dev journal about the spells, I would have had to ask marketing because that's more of a feature than a fix.

As it is, I find that many people are interested in a journal like this because it gives them insight into the development process, whatever the topic. 

on Nov 10, 2010

There's alot of talk about culture flipping in this thread, and I wanted to point out that the issue is more complex in a fantasy game than in a game like Civ. In Civ, your dealing with people whos culture changes according to their interest, while in fantasy games factions can sometimes be different species with completely irreconcilable needs and wants. 

For example, you wouldn't want your city to join another faction whos inhabitants survive by eating your species for breakfast... 

on Nov 10, 2010

CariElf

If I actually had wanted to write a dev journal about the spells, I would have had to ask marketing because that's more of a feature than a fix.

As it is, I find that many people are interested in a journal like this because it gives them insight into the development process, whatever the topic. 

And I"m glad you did, these are pretty interesting.

on Nov 10, 2010

The reason the limit exists, which is actually 5 tiles, is to prevent cities from connecting. This would not help two cities with roughly the same influence could easily be built right next to each other.

Currently, it picks whoever has the lower player ID to break ties. I'd like to change this to whoever has been influencing the tile the longest, if it doesn't slow down the calculations too much.

carielf, just a suggestion regarding the resource flip, why not have it as whichever has the MOST influence, so that we ( the players AND AI )can use influence as a peaceful(ie not declared war) means of gaining territory unless the resource is for one alignment only(eg horses & wargs)

harpo

 

on Nov 10, 2010

CariElf

I wrote about what I was working on.  I continue to reply because people seem interested.

I was just asking

I'm just anxious to see more about 1.1 and what it will entail. I had no idea that it couldn't be disclosed. My bad!

Cheers,

V.

on Nov 10, 2010

CariElf

Quoting Loren1350, reply 87
In short, I don't like the two-tile limitation, and it seems to me that the influence boundary calculations might allow it to be removed.

But apart from that, I am curious about [player] boundaries: How will you break ties in influence conflicts?

 

The reason the limit exists, which is actually 5 tiles, is to prevent cities from connecting.  This would not help two cities with roughly the same influence could easily be built right next to each other.

Fair enough (and I don't know where I got the 2 from). Now that I think about it, city merging could be pretty cool... but also really difficult to handle, given the way limits work. I just don't like being unable to build on a (possibly newly discovered) resource between two cities just because I failed to plan for it when I founded the cities. If someone can find a way around that (I admit I can't, at least not readily) and implement it, that would make me happy.

harpo99999

carielf, just a suggestion regarding the resource flip, why not have it as whichever has the MOST influence, so that we ( the players AND AI )can use influence as a peaceful(ie not declared war) means of gaining territory unless the resource is for one alignment only(eg horses & wargs)
 

This is the way it is intended; the playerID / "whoever has owned the tile longest" is only for breaking ties if both players have equal influence over the tile.

on Nov 11, 2010

Well that was very interesting! Very cool to see the thought process on how this type of stuff works! Thanks!

on Nov 12, 2010

"Euclidean distance"....yeah....just rolls of the tongue

 

Got no idea what it means but I'm always impressed when I see chicks talking about technical things like this.

8 PagesFirst 5 6 7 8