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 2)
8 Pages1 2 3 4  Last
on Nov 08, 2010

Quoting Lantros,
reply 6
Last picture looks really good.

My english isn´t good, so i have to ask to be sure i understand it right. ZOC grows in the direction i build my citys, right?

Yes, it will with this new code. In the build currently available on Impulse, it doesn't really do that.

 

Fantastic! Thx.

on Nov 08, 2010

cephalo



I agree with this. ZOC as a gaming term is definately taken. We need a new word for a factions territory/borders.

 

SOI? "Sphere of influence"?

(This has the benefit of actually being the textbook definition for the concept at hand:

sphere of influence:

A territorial area over which political or economic influence is wielded by one nation.)

 

 

Colored Blob of Doom?

(Or perhaps the more politically correct term would be," A Doom Blob of Color" )

on Nov 08, 2010

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.

on Nov 08, 2010

In GalCiv that was called "within influence" if I'm not mistaken. I never heard the term ZOC used there.

With cities, "special stuff" happens within the ZOC - which also happens to be adjacent to the city. So what's non-ZOCic about it?
There is no clear definition of what must happen in a ZOC. It varies between games.

But yes, I also used it here. It's an old school term so *shrug*.
It's true that it's ambiguous if it's also used for the city ZOC but I've heard worse.

Zone Of Influence should have been the more obvious term in any case. (it's rarely a sphere

on Nov 08, 2010

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.

 

Imho it solves no problem. But it gives us more to think about and makes city building more interresting. I dont have to wait for a *blopp*- Influence increased - to reach a ressource. I can build my city in the direction of the ressource i want/need...

on Nov 08, 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 problem comes when you build your city to the edge of the zone (and possibly even beyond).

on Nov 08, 2010

couldn't you just use the original code, but double the zone of control values, so that city hub = 4, buildings = 2, and get the same effect?

on Nov 08, 2010



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.

on Nov 08, 2010

This kinda of sounds like much of anything, it sucks being hired to fix other peoples crap work. Way to go Cari, I would have been tempted strongly to tear the thing down and start over! Also I was wondering if there is in the works an alarm system that lets you know when some one or some thing crosses your zone of control.Could be a Tech or Skill that you need to research or learn but that would be cool. My thinking is when the game gets huge, you can forget your focus dealing with some other thing and leave your backdoor wide open. It would be nice to have noise makers or some sort of essence skill that would let you know when your line has been crossed!

Area Of Influence works just as well, might need to tell the new kids!

on Nov 08, 2010

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.

on Nov 08, 2010

(Insert words of encouragement and praise here)

on Nov 08, 2010

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.

Meh, I much prefer using the Euclidean distance than the min(|,|y|) distance (like you used in the last screenshot). The problem with the using the minimum of the x- and y-distances is that it creates square instead of circular ZoC, which is much too blocky for my taste.

Anyway, if you use Euclidean distance, and you want to avoid the ugly cross you got in second-to-last screenshot, you should always add one-half to your distances, instead of using integers distance only. For instance, by using a radius of 2.5, you will get the "fat cross" that is well known by any Civilization 1,2,3,4 player. (Note: using radius + 1/2 is equivalent to rounding the distance between tiles, instead of taking the integer part.)

on Nov 08, 2010

Which reminds me that I made some test with pariden and I got weird behaviors il the previous system.

For example, each city level up seemed to grow the city radius by approximately 2 square, but when a city reached level 4 in increased by 4 squares.

---

Personally I prefer a radius where diagonals count as 1.5 for radius calculations. Without diagonals, the range is too short. You can also round down or up the value for larger/smaller radius.

The current radius shape calculation does not see so bad, it just seem very large with a very weird incrementation which is hard to predict.

on Nov 08, 2010

Can't wait to try this! Keep it up!

on Nov 08, 2010

_PawelS_
I think calling a player's territory/area of influence "Zone of Control" is confusing, because this name is usually used for a completely different concept in gaming.

Lol. I opened the thread excitedly thinking, "Zones of control in Tactical Battles."

8 Pages1 2 3 4  Last