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 4)
8 PagesFirst 2 3 4 5 6  Last
on Nov 09, 2010

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

on Nov 09, 2010

I like the "Shuriken" method =P

on Nov 09, 2010

another suggestion for the name of the area being 'My Space' MS, although a particular very large software company known for releasing buggy and flawed software and only patching  on a slow cycle might object to the short form,

then the alternate could be 'My Ground' MG which would suggest a old make of sports car.

and good work carielf, altering a previous programmer's work is twice as difficult as creating your own code for the job, but as the existing code has already had(should have) a significant amount of bug testing, and the new code has had almost none, it is always a hard choice, but I think the simpler solution is the better ie use the same method as a person would ie count the squares, with diagonals at approx 1.44 vs straight out at 2, OR the trigonometric distance from the edge of the town, and if a square has OVER 80% it is entirely in, 60% 3/4 in, 50% 1/2 in.

harpo

 

on Nov 09, 2010

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?

 

Now the otherwise dull feature of where you place your buildings (it only causes annoying hinerance if you get it wrong) now becomes potentially useful (of course we now need Brad to tell the AI how to use it!)

on Nov 09, 2010

Thank you for the insight into your work.

I like this kind of DevJournal very much. Keep it up.

on Nov 09, 2010

I must admit I don't really understand what this journal entry is all about as I'm putting off learning the game until 1.1 comes out, but I think it's great to see this kind of info coming direct from the devs when compared to the 2K forums where info seems really hard to come by. No disrespect to them as I'm sure they're doing a great job behind the scenes, but who knows what they're doing because there is like zero communication.

Big thumbs up to SD devs for being so open!

on Nov 09, 2010

(FSM) Flatulence Spread Matrix           ->         that's my favorite!!

 

I would like people to NOT link Wikipedia entries which do have this sentence presented on top:

This article does not cite any references or sources.

 
 

Thanks Cari for the insight on a programmers work. It will have a good impact on the game.

on Nov 09, 2010

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

on Nov 09, 2010

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.

on Nov 09, 2010

SinVraal
I would like people to NOT link Wikipedia entries which do have this sentence presented on top:

This article does not cite any references or sources.

I don't see why.
Such an entry is obviously stuff some guy has written. Any web reference would also be stuff some guy has written. But it's truer when it's not a wiki entry?
Some urban myths could cite tons of references and still not be worth the HDD space they are written on. =P

Never ever take a wiki entry at face value. Or anything at all on the internet. It's the world's biggest garbage dump. =P

Oh, and speaking of facts without stating sources:
If you fart consistently for 6 years and 9 months, enough gas is produced to create the energy of an atomic bomb.

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.

Yah, it's a classic simplification that was needed for boardgames. You could just as well use a "fractal" engine like Daggerfall's and have the entire land mass modeled in tactical-level 3D. Just a matter of zooming in and out (which the engine already does) and recording a stack's position in cm on the global map instead of having a strategic square that turns into a random tactical battle map.

But would that make the game better? I think not. Map tiles are a pretty standard abstraction in strategy games...

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.

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

Hexes are nice because they break the distances up into units that are easy for a player to follow at a glance. If you have an archer that can shoot 11 metres, what does that mean on screen? 2 hexes on the other hand is no problem. The difference matters for newbies.

 

Squares, though. Yech.

 

on Nov 09, 2010

But even with circles and distances you would in turn have to deal with a zone of control or zone of influence.

How would you deal with collision of armies or collision of "interests" diplomacy-wise?

on Nov 09, 2010

But they could be circles!

And then well... because!

on Nov 09, 2010

I don't see why

Simply because a quotation should be verified by a good reference to make it meaningful.

Anyway I think this whole discussion wether it's named zone of control or zone of influence is obsolete, because SD knows what they're talking about refering to Elemental and we all know what the zone of influence of a city is about in the game. And yes, armies have a zone of control, I heard of that too...

on Nov 09, 2010

But they could be circles!


Hehe yeah - I'll come up with dodecagons. That's some stylish sh...

8 PagesFirst 2 3 4 5 6  Last