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

looks good

on Nov 08, 2010

Looking good, thanks for the very detailed explanation/journal entry. Can I assume this code will make it into the 1.1 beta?

on Nov 08, 2010

Sounds like this isnt quite ready for 1.1 or??

on Nov 08, 2010

I've been wondering how it worked out you influence zone, good to know and it does look much improved.

on Nov 08, 2010

Heh, I suppose I'm the only one who thinks the one with the jagged outline looks cool.  I always play evil civs, and like the idea of my cities looking like cancerous growths spreading on the map.

on Nov 08, 2010

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? 

on Nov 08, 2010

That's a great journal entry. I had great pleasure reading it... gotta love those technical/programming tidbits

on Nov 08, 2010

Bingjack
Heh, I suppose I'm the only one who thinks the one with the jagged outline looks cool.  I always play evil civs, and like the idea of my cities looking like cancerous growths spreading on the map.

Not the only one, and I usually play good civs LOL! I just like a good saw blade shaped border

 

CariElf, your development style sounds like mine. Change something - see what happens - get frustrated that it didn't work - change something else - etc.... I've spent the better part of the day fighting with a mouse move function

on Nov 08, 2010

but it's still using the Euclidean distance formula to set the powers

Of course! The Euclidean distance formula--why didn't I realize that before? My grasp on mathematics doesn't go past Pythagoras. Thanks for the detailed explanation, though. It gives me a deeper appreciation for the complexity of work that you guys are doing. This will be great once you get all the tweaking done.

I have to ask, however, if the AI can be taught the Euclidean distance formula, might you imbue it with some principles of  Sun Tzu, Clausewitz, or heck, maybe even Kahless. It might give the AI a little more boom boom pow.

 

PS I have no doubt that SD is addressing this issue and it's probably not as easy as it sounds. Keep up the good work!

on Nov 08, 2010

I might still be able to finish it in time for the first beta, but I really didn't expect it to take me as long as it did to get to this point either. I figured that all I'd have to do is make sure that all improvements had a radius of at least 1 and a default power.  If the adjacent zones just work, all I'll have to worry about is the line code, and I can always commit it with pointy lines at first.

on Nov 08, 2010

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.

on Nov 08, 2010

Nice, that looks promising.

on Nov 08, 2010

Lantros
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.

Aloriel

CariElf, your development style sounds like mine. Change something - see what happens - get frustrated that it didn't work - change something else - etc.... I've spent the better part of the day fighting with a mouse move function

Yeah, if I'm modifying code, I try to make changes in steps so that if I really break it, I can back out my latest changes and try another tack. If I'm writing completely new code, I tend to spend a lot more time just writing code, before I even hit compile.  But when writing new code, I've already done a lot of the code design even before I open up Visual Studio.

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.

Interesting.  We've been calling it ZOC at least since GalCiv2, possibly GalCiv1. 

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.

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

As long as I can tell what land I can use without ambiguity, it should be fine. Curved corners is a nice touch, but the game rules enforce squares, so things are going to look very squarish no matter what. It's all good.

8 Pages1 2 3  Last