The Forums Are Now Closed!

The content will remain as a historical reference, thank you.

Fixing the Zone of Control (Influence)

By on November 8, 2010 3:56:15 PM from Elemental Forums Elemental Forums

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

 

+52 Karma | 107 Replies
November 8, 2010 4:06:19 PM from Elemental Forums Elemental Forums

looks good

November 8, 2010 4:11:07 PM from Elemental Forums Elemental Forums

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

November 8, 2010 4:23:01 PM from Elemental Forums Elemental Forums

Sounds like this isnt quite ready for 1.1 or??

November 8, 2010 4:24:35 PM from Elemental Forums Elemental Forums

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

November 8, 2010 4:30:37 PM from Elemental Forums Elemental Forums

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.

November 8, 2010 4:54:32 PM from Elemental Forums Elemental Forums

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? 

November 8, 2010 4:55:32 PM from Elemental Forums Elemental Forums

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

November 8, 2010 4:57:10 PM from Elemental Forums Elemental Forums

Quoting 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

November 8, 2010 4:59:51 PM from Elemental Forums Elemental Forums

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!

November 8, 2010 5:02:28 PM from Elemental Forums Elemental Forums

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.

November 8, 2010 5:05:57 PM from Elemental Forums Elemental Forums

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.

November 8, 2010 5:16:25 PM from Elemental Forums Elemental Forums

Nice, that looks promising.

November 8, 2010 5:20:13 PM from Elemental Forums Elemental Forums

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

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

November 8, 2010 5:23:58 PM from Elemental Forums Elemental Forums

Quoting _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. 

November 8, 2010 5:29:14 PM from Elemental Forums Elemental Forums

Quoting _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.

November 8, 2010 5:35:49 PM from Elemental Forums Elemental Forums

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.

November 8, 2010 5:36:51 PM from Elemental Forums Elemental Forums

Quoting 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" )

November 8, 2010 5:37:23 PM from Elemental Forums Elemental Forums

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.

November 8, 2010 5:42:18 PM from Elemental Forums Elemental Forums

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

November 8, 2010 5:53:57 PM from Elemental Forums Elemental Forums

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

November 8, 2010 6:23:04 PM from Elemental Forums Elemental Forums

Quoting 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).

November 8, 2010 6:29:28 PM from Elemental Forums Elemental Forums

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?

November 8, 2010 6:56:41 PM from Elemental Forums Elemental Forums



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.

November 8, 2010 7:25:15 PM from Elemental Forums Elemental Forums

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!

November 8, 2010 7:41:54 PM from Elemental Forums Elemental Forums

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.

Stardock Forums v1.0.0.0    #108435  walnut2   Server Load Time: 00:00:00.0000344   Page Render Time:

Stardock Magazine | Register | Online Privacy Policy | Terms of Use

Copyright ?? 2012 Stardock Entertainment and Gas Powered Games. Demigod is a trademark of Gas Powered Games. All rights reserved. All other trademarks and copyrights are the properties of their respective owners. Windows, the Windows Vista Start button and Xbox 360 are trademarks of the Microsoft group of companies, and 'Games for Windows' and the Windows Vista Start button logo are used under license from Microsoft. ?? 2012 Advanced Micro Devices, Inc. All rights reserved. AMD, the AMD Arrow logo and combinations thereof are trademarks of Advanced Micro Devices, Inc.