Random Invisibility Mod

NP300

Prince
Joined
May 18, 2004
Messages
402
Location
North America
Random Invisibility Mod

I have been working on a mod to incorporate randomness into the invisibility system. For a long time I have thought that it is boring for destroyers to be able to see submarines 100% of the time. I thought it would be more fun if they only had a certain probability of spotting the sub, such as 25%.

Originally I based my mod on Primem0ver's Graded Invisibility Mod. However, primem0ver has not updated his mod for Beyond the Sword.

Recently, Thomas SG discovered that the newer versions of Beyond the Sword incorporate a graded invisibility system. Thus, I have been able to use this to build my Random Invisibility Mod.

I owe a debt to Primem0ver, since examining his code allowed me to figure out where I needed to make my changes.

In addition, I have incorporated Lethal Sea Bombard into my mod. Now any air units with an iAirCombatLimit above 50 can sink ships. For this, I am in debt to Gedemon and his Air Forces Mod, since examining his code allowed me to see where I needed to make the changes. I used Gedemon's code, and modified it to make it work with Beyond the Sword 3.13.

How does the Mod work? I have added three tags to GlobalDefines:

EXTRA_MAX_AIR_DAMAGE_TO_SEA
RANDOM_INVISIBILITY_NUMERATOR
RANDOM_INVISIBILITY_DENOMINATOR

EXTRA_MAX_AIR_DAMAGE_TO_SEA is from Gedemon's mod, and works in the same way. It controls how much the iAirCombat Limit is increased for attacks on sea units.

RANDOM_INVISIBILITY_NUMERATOR and RANDOM_INVISIBILITY_DENOMINATOR control the base probability of seeing an invisible unit. For example, if you want your units to have a 50% chance of seeing invisible units, you set the numerator=1 and the denominator=2.

The values should be greater than zero and not greater than 32,000.

If you use the SeeInvisible tags in Civ4UnitInfos carefully, you can give different units different probabilities of seeing different units. For example, in the sample Civ4UnitInfos that I have provided, the SeeInvisible for the Attack Sub reads as follows:

INVISIBLE_SUBMARINE,INVISIBLE_SUBMARINE,INVISIBLE_NUCLEAR_SUB

Notice that INVISIBLE_SUBMARINE appears twice. This makes the code give the Attack Sub two chances to spot Subs (instead of the default of one). Therefore, the Attack Sub has a greater chance of seeing Subs, than of seeing Attack Subs.

How can we calculate the odds of spotting an invisible unit? By default the numerator=1, and the denominator=8. This means that the base odds are 1/8. So you would think that the Attack Sub has 1/8 chance of spotting an Attack Sub, and about a 23% chance of spotting Subs.

Math:

Spoiler :


1 - [(1 - 1/8)*(1-1/8)] = 0.234375



However, it is not so simple, because the invisibility code is recalculated each time a unit moves. Therefore, the odds of seeing an invisible unit are higher than stated above in practice. By how much depends on how many moves a unit has, and how far away said unit can see.

With the default 1/8 base odds, the sample SeeInvisible tags, and a visibility range of 2, I have found that Attack Subs can see other Attack Subs about 23% of the time, and can see Subs about 40% of the time.

To increase the chances of a unit seeing an invisible unit, simply repeat the relevant SeeInvisible tag more times as in:

INVISIBLE_SUBMARINE,INVISIBLE_SUBMARINE,INVISIBLE_SUBMARINE,INVISIBLE_SUBMARINE

The above provides 4 passes, instead of 1. The more times you repeat the same tag, the greater the odds of seeing the invisible unit. As you add the same tag, the probability of spotting the unit will approach 100%, but will never actually get to 100%.

To reduce the chances of a unit seeing an invisible unit, you can reduce the base odds to be lower than 1/8.

Setting numerator=1 and denominator=1 reduces the Mod to the normal state, where units with SeeInvisible have 100% odds of seeing invisible.

I have not tested this sample mod very extensively. Thus, I expect that it may have some unexpected bugs. This is particularly true of the Lethal Sea Bombard, which I have barely tested.

Notes:

1) Versions 0.2 and B 0.30 are for Beyond the Sword 3.17. Version C 0.60 is for BTS 3.19 and Better BTS AI 1.01.

2) Version B 0.30 is available here.

3) Version C 0.60 is available here.

4) If you use this mod in another mod, just give me credit. I would also appreciate it if you would let me know if you use this mod in your mod. I would like to know how people use this.

5) The SDK code is commented with "Random Invisibility" and "Lethal Sea Bombard" to let you know about the relevant alterations.
 

Attachments

Very nice. I'm also developing something similar for CCV 2.06 at the moment! :D And because I also thought about that feature I can tell you that you forgot some things. ;) What about units that doesn't move? Maybe a waiting sub under ice? It's harder to find it if it is not moving. But that's not the point. A sub not moving itself makes no noise and can so "see" more and not less!!! And you calculate every move. Right? That's even unfair. A human will move it's unit around as much as possible while the AI will stay or move direct to target.

Improvement:
If a unit ends its turn with movepoints left you must decrease movepoint by one and do the sight procedure again. If a new unit is found the unit must be able to move again with the rest of its movementpoints. Do so until there is no point left.

But nice mod. And faster than me... :mischief:

EDIT: I've finished my Advanced Invisibility System! You can find it in CCV.

EDIT 2: There is a new version of my Advanced Invisibility System in CCV 4.x or higher. It's easier to use. Just define an invisibility class, say what classes to see and what chance to see with an exact accuracy of 1%. That's it. And as a new feature since 4.x units can also have a defined chance to be total invisible in a turn. I use it for stealth naval units. And of course all information seen in the pedia.
 
Very nice. I'm also developing something similar for CCV 2.06 at the moment! :D And because I also thought about that feature I can tell you that you forgot some things. ;)

It's good to see that someone else is interested in randomized invisibility. I feared I was the only one. Think about it: how boring would it be if tanks would defeat infantry in the open 100% of the time? It is the same with invisibility! Why should it be all or nothing? Chance makes it more interesting.

Can you describe exactly what you are working on? I'm curious.

What about units that doesn't move? Maybe a waiting sub under ice? It's harder to find it if it is not moving. But that's not the point.

Well, I didn't deliberately code it to recalculate on each move. That is just a by-product of how the game code determines whether a unit is invisible or not.

I only know the basics of C++, so my modding abilities are limited. I should probably have put the DENOMINATOR and NUMERATOR in the invisible infos xml but I wasn't sure if I could make the data load from there.

A sub not moving itself makes no noise and can so "see" more and not less!!!

It is true that a sub that doesn't move should be harder to see. I have actually thought about a mod where one could keep the sub stationary and have it be very invisible, or move it and risk detection. But I don't know how to code this.

A human will move it's unit around as much as possible while the AI will stay or move direct to target.

It depends on how you look at it. I actually think it is realistic for the visibility to recalculate on each move. If your sub/destroyer (or whatever) is out there looking all over the place, it should stand a higher chance of seeing something.

I don't think the AI is as much of an issue here, because as long as you do move your unit, you stand an increased chance of detecting invisible units. What you say is only an issue if you keep the unit absolutely stationary. Also, the recalculation only affects ground/sea units. It does not affect air units doing recon.

It also introduces an interesting decision: Move the unit around one particular square to increase your chances of seeing an enemy sub in that square, and lose movement points. Or, move the unit a great distance to have a reduced chance of spotting a sub over a greater area.

Improvement:
If a unit ends its turn with movepoints left you must decrease movepoint by one and do the sight procedure again. If a new unit is found the unit must be able to move again with the rest of its movementpoints. Do so until there is no point left.

Again, I didn't code it in this way deliberately. If you would have a look at the code I altered, you would see why it happens this way.

Your ideas are good, and I have thought about some of them. But some are just beyond my modding skills at this point.

But nice mod. And faster than me... :mischief:

Thanks. One reason I modded it so fast is because I had actually made a similar mod for Primem0ver's mod. But, I was waiting for him to make a BTS version. So when I saw you post about the hidden graded invisibility system, I only had to adapt the work I had already done.

I also have another version that works slighly differently. Originally I had it set up as a list of invisibles in the SeeInvisible, like:

INVISIBLE_01,INVISIBLE_NUCLEAR_SUB,INVISIBLE_03,INVISIBLE_SUBMARINE,INVISIBLE_05,INVISIBLE_06,INVISIBLE_07,INVISIBLE_08

And the first, from left to right, would have 1/8 odds. The second would have 2/8 odds. The third would have 3/8 odds. The fourth would have 4/8 odds, and so on. So in this case, the unit would stand 1/4 odds of seeing nuclear subs, and 1/2 odds of seeing subs. Anything beyond the 8th position would have 100% odds of being seen.

However, it had the downside that you needed to use placeholder invisibilities (like INVISIBLE_01) and that you could not give the same invisibility level to two different units.

But it is very easy to implement, and works differently from the one I posted here. I'm not sure which system is better. I just didn't like having to use placeholders.

Ideally, I would like to load a list of numerators and denominators in the UnitInfos for each unit with SeeInvisible. For instance, a submarine could have:

SeeInvisible: INVISIBLE_SUBMARINE,INVISIBLE_NUCLEAR_SUB

Numerator: 1,1
Denominator: 2,4

Such that it would have 1/2 odds of seeing subs and 1/4 odds of seeing nuclear subs. Thus, you could specify the exact odds of seeing each invisible unit. This is how I would like to have my mod work. Alas, I don't know how to do this—yet.
 
You can use the same system I'm creating also at the moment for improved transport. It's very easy.

Just use two vectors (like SeeInvisible). The first vector is SeeInvisible and the Second SeeInvisibleChance.

vector 1: INVISIBLE_SUB,INVISIBLE_SILENTSUB,INVISIBLE_STEALTHSUB,...
vector 2: 20,10,5,... percent (easy to combine with randomnumber-system between 0 and 100)

Than call i=x from vector 1 for type and the same i from vector 2 for chance. So you can get rid of GlobalDefines. And it's easier and more powerfull. :D

That makes it very easy to give every unit every chance for every other unit.
 
You can use the same system I'm creating also at the moment for improved transport. It's very easy.

That's pretty much what I had in mind, ever since I saw the vector system for SeeInvisible. It's just that my C++ isn't good enough to be able to do this without seeing an example. I don't know enough about how the vector code works to be sure I program it correctly.

If I could see your code, I could probably figure it out, but then again, it sounds like you have this much done already.

What is the transport thing you are working on?
 
It depends on how you look at it. I actually think it is realistic for the visibility to recalculate on each move. If your sub/destroyer (or whatever) is out there looking all over the place, it should stand a higher chance of seeing something.

I can't agree. Here my example:

2 submarines, each has 4 movements (or more), sight 2

sub1: stayes where it is -> one chance to see units on the 20 plots around.

sub2: it moves up, right, down, left -> with every move it will see a lot of plots again and again. Although it has the same position at the end and made lots of noise (higher chance of being seen and normally decreased sight) it has a much better chance to see units on the 20 start plots. It sees

- 9 plots 5 times
- 5 plots 4 times
- 5 plots 3 times
- 1 plot 2 times

Remember the other sub saw them all only 1 time. That's absolutly crazy. :crazyeye:
 
Remember the other sub saw them all only 1 time. That's absolutly crazy. :crazyeye:

Like I said, I think it depends on your perspective. Remember that a plot in the game can easily represent a square 100 miles x 100 miles. In that case, we can't be sure that the "stationary" sub was actually completely stationary. In this case, the moving in circles represents probing different sectors of the square. Or it could represent being stationary and listening carefully with your own engines off, instead of moving.

Also, it does introduce the choice of using your movement points to examine one square carefully, or to use your movement points to actually move.

I'm not saying I disagree with you, though. I actually, thought of modding it in such a way that it would not recalculate on each move. But, I just have no idea how to program it at this point.
 
That's pretty much what I had in mind, ever since I saw the vector system for SeeInvisible. It's just that my C++ isn't good enough to be able to do this without seeing an example. I don't know enough about how the vector code works to be sure I program it correctly.

If I could see your code, I could probably figure it out, but then again, it sounds like you have this much done already.

What is the transport thing you are working on?

I started with using vectors for the cargo of specialunits. It's just working in the second alpha of CCV 2.05e. Have a look at my signature.

I created a vector for specialunit cargo and more specialunittypes like SPECIALUNIT_MISSILE and SPECIALUNIT_ROCKET. So now for example my missile cruisers can carry both types but my stealth destroyers can carry only missiles. And you can do the same for fighters and jetfighters with early and late carriers. And...

That was step one.

Now I started working on two things. I want vectors for the cargo size (part1) and I want units to be able to be member of more than one specialunit type (part2).


That will do two things. Example:

my missile sub, can carry 4 missiles/rockets at the moment, no persons

The vector for cargosize will allow that:

type: Person, Missile, Rocket
cargo: 1,4,4

So, my missile sub will now carry one person + 4 missiles + 4 rockets. But that's bad because the total size for missiles and rockets is now 8 instead of 4. 2 + 2 is also bad. You see the point...

And here I need part two - units with more than one specialunit type.

If missiles are SPECIALUNIT_MISSILE, SPECIALUNIT_MISSILEANDROCKET and rockets are SPECIALUNIT_ROCKET, SPECIALUNIT_MISSILEANDROCKET

I can do

type: Person, Missile, Rocket
cargo: 1,4,4

type: Person, Missile
cargo: 1,4

type: Person, Rocket
cargo: 1,4

type: Person, MissileAndRocket
cargo: 1,4


-> one person, 4 missiles or rockets

That's all you need. :goodjob:
 
Like I said, I think it depends on your perspective.

No. If I want to stay at a plot I will still walk around and return to the plot and increase my chance to see units around. But the AI will only stay at the plot. It doesn't know that it is much better to move in a circle than to stay where you are. It's a human exploit!
 
Very good! I was looking for answers for these questions. Now I've found. I'll use!
 
I started with using vectors for the cargo of specialunits. It's just working in the second alpha of CCV 2.05e. Have a look at my signature.

I think I see what you are trying to accomplish. I had wished for the ability to carry multiple types of cargo in the past.

I downloaded the CCV mod, but it is an exe and it wants to be installed. I don't actually want to install it, I just want to look at the SDK code. Is there any way to do this? I'm a bit lost, as I am having to decipher the German.
 
Great discussion - and it sounds like a cool mod, NP300 :goodjob:

A few questions:

Does the game check this for all unit types or unit domains? What if all surface ships were "invisible", to simulate the possibility of one slipping past your sentries...

Is it possible to limit the vision range for subs if it moves? Or conversely give a +1 bonus to the numerator if it has 'Sentry' status?

How heavy is all this visibility checking on the game? Are there any slowdowns?
 
Great discussion - and it sounds like a cool mod, NP300 :goodjob:

Thank you!

Does the game check this for all unit types or unit domains? What if all surface ships were "invisible", to simulate the possibility of one slipping past your sentries...

How heavy is all this visibility checking on the game? Are there any slowdowns?

To answer your questions I'll post a segment of the code:

Spoiler :

for(int i=0;i<(int)aSeeInvisibleTypes.size();i++)
{
for (int dx = -iRange; dx <= iRange; dx++)
{
for (int dy = -iRange; dy <= iRange; dy++)
{
//check if in facing direction
if (shouldProcessDisplacementPlot(dx, dy, iRange - 1, eFacingDirection))
{
bool outerRing = false;
if ((abs(dx) == iRange) || (abs(dy) == iRange))
{
outerRing = true;
}

//check if anything blocking the plot
if (canSeeDisplacementPlot(eTeam, dx, dy, dx, dy, true, outerRing))
{
CvPlot* pPlot = plotXY(getX_INLINE(), getY_INLINE(), dx, dy);
if (NULL != pPlot)
//Random Invisibility START
{
if (( (rand()) % denominator) < (numerator) )
//Random Invisibility END
{
pPlot->changeVisibilityCount(eTeam, ((bIncrement) ? 1 : -1), aSeeInvisibleTypes, bUpdatePlotGroups);
}
//Random Invisibility START
else
{
pPlot->changeVisibilityCount(eTeam, ((bIncrement) ? 1 : -1), NO_INVISIBLE, bUpdatePlotGroups);
}
}
//Random Invisibility END
}
}


Notice the vector aSeeInvisibleTypes. That vector contains the SeeInvisible types. That code is in a loop that increases the value of i on each run. So the more SeeInvisible types you have, the more times that loop runs.

Thus, it is possible that if you used a lot of SeeInvisible types you would see slowdowns.

If a unit has no invisible types in there, the code assigns the following:

Spoiler :

if(aSeeInvisibleTypes.size() == 0)
{
aSeeInvisibleTypes.push_back(NO_INVISIBLE);
}


So it just assigns it the NO_INVISIBLE value, which means that it cannot see any invisible units. Most units don't have any SeeInvisible, so that is what they get.

I have considered the possibility of giving all surface ships some invisibility to simulate slipping past sentries and the like. If you choose to do that you must take into account that you will be using a lot of SeeInvisible types. That may result in a slowdown. But I can't tell you by how much because I haven't tried it. You would have to try it and test it to see if the slowdowns would be noticeable.

Another problem you may have is that the way I have the mod coded, you can never get 100% probability of seeing an invisible unit, unless you set the base probability at 100%. You can get arbitrarily close to 100% but to do so you need to add many repeat SeeInvisible types.

I had another version of the mod that easily allowed 100% visibility but at the expense of requiring placeholder invisibilities, which I didn't like.

Is it possible to limit the vision range for subs if it moves? Or conversely give a +1 bonus to the numerator if it has 'Sentry' status?

I don't know how to change the visibility range. Fanatic Demon was working on a mod to allow this, but it appears to have been abandoned:

Here is a list of basic XML elements:
- <iVisibilityRange> (see normal unit range)
- <iSeeInvisibilityRange> (see invisibility unit range)

As for giving +1 to the numerator if the unit has sentry, I don't see why it shouldn't be doable. I would need to learn how to call for information on what promotions a unit has, which I don't know how to do. However, adding or subtracting to the numerator/denominator is easy, and is the way in which my first test version worked.

I do believe this should work for units on any domain. I haven't tried it with ground units. But all I did was make a slight alteration of the game's invisibility code. So if the game's default invisibility code works for ground units, my mod should work for them as well.
 
I want to tell you that the random graded invisibility system of CCV 3.00 (for BTS 3.17) is nearly finished. The pre-tests gave me good results. Should be working with all features in 48 hours.

CCV features:
- give each unitclass an easy to define chance to see every possible invisibleclass
- independent chance for each invisibleclass
- independent chance for units of the same unitclass
- independent chance for units of different unitclasses
- accuracy of 1%*
- small benefit from patroling**
- increased chance to see walking around invisible units**

*) pre-test accuracy 50%
**) not working in pre-tests
 
As I promised it's done. Here you can test the new CCV feature. I've done it as a standalone mod for BTS 3.17. Here is the preview.
 
Hey NP300,

Any changes coming to this mod anytime soon? :) I plan to use it in the next release of Merged Mod, so if you have any updates to it, please let me know what's coming.

EDIT: Never mind on the second question. I'm in testing now, and this looks really good! :goodjob: I'm using 1/6 as a base, to not get too many passes on each move for the more advanced units.

CCV features:
- give each unitclass an easy to define chance to see every possible invisibleclass
- independent chance for each invisibleclass
- independent chance for units of the same unitclass
- independent chance for units of different unitclasses
- accuracy of 1%*
- small benefit from patroling**
- increased chance to see walking around invisible units**

*) pre-test accuracy 50%
**) not working in pre-tests

Thomas SG, did you get the two last points to work in your version?
 
Hey NP300,

Any changes coming to this mod anytime soon? :) I plan to use it in the next release of Merged Mod, so if you have any updates to it, please let me know what's coming.

I have another version that uses a slightly different calculation method. I haven't posted it because I didn't know there was interest in this mod. But now that you ask for it, I could post it when I have some free time to edit the files into a "presentable" form.
 
Well in its current form, it works great. :goodjob: The only annoyance is the way that units display their spotting ability in the civilopedia. If a unit has 4 chances to spot an invisibility type, it will state this four times in the civilopedia.
 
Back
Top Bottom