View Full Version : Revealing Invisible Units


TheLopez
Mar 31, 2006, 09:36 PM
Does anyone know how to programatically reveal an invisible unit?

Here is some pseudo code:


randNum = <get the random num>

if(<skill amount> >= randNum):
<reveal player1Spy to player0>



any ideas?

Bhruic
Mar 31, 2006, 10:29 PM
Only functions that might affect it would be the PyPlot.changeInvisibleVisibilityCount() and PyPlot.changeVisibilityCount() functions. Although I'll admit to not being entirely sure how they function. All the other invisibility functions look like they only read.

Bh

TheLopez
Mar 31, 2006, 10:34 PM
Yeah, that's what I thought, but I can't get those to work. I was hoping someone **cough** TGA **cough** 12monkeys **cough** would have an idea.

Thanks anyways Bhruic

Bhruic
Apr 01, 2006, 12:59 AM
Hmm. I did think of a way to reveal/hide them globally, but not by player. Just make a new promotion that grants (or removes, depending how you want to do it) invisibility. Then you just toggle that under the appropriate conditions. However, I'm pretty sure that as I said, that would be globally.

Bh

Lord Olleus
Apr 01, 2006, 02:03 AM
What invisibility are you talking about? the submarine type or the spy type?

snarko
Apr 01, 2006, 05:48 AM
Hmm. I did think of a way to reveal/hide them globally, but not by player. Just make a new promotion that grants (or removes, depending how you want to do it) invisibility. Then you just toggle that under the appropriate conditions. However, I'm pretty sure that as I said, that would be globally.
How would you do that? I remember trying to do it a long time ago, not finding any way. Only way I can think of to do it now is recreating the unit as another type which is exactly the same except invisible/not invisible... but having almost exact duplicates of one or several units in the XML file isn't a nice solution.

TheLopez
Apr 01, 2006, 06:28 AM
@Bhruic - I don't think you can grant invisibility in promotions. You can change how far a unit can see.

@Lord Olleus - Any type of invisibility spy, submarine, etc.

@snarko - yeah, that's what I was planning to do but I want to keep the solution generic.

TheLopez
Apr 01, 2006, 09:33 AM
TGA? 12monkeys?

any ideas?

The Great Apple
Apr 01, 2006, 09:51 AM
TGA? 12monkeys?

any ideas?Sorry, missed this one.

Nope - never played with invisibility. The only way that might work without XML bodges is Bhruic's method... which you've tried.

EDIT: Ok... a pretty far fetched idea here. Subs become visible when they pillage right? Maybe this could be exploited?

TheLopez
Apr 01, 2006, 10:11 AM
EDIT: Ok... a pretty far fetched idea here. Subs become visible when they pillage right? Maybe this could be exploited?

Huh, I did know that about subs. I see what I can do there. Do you know if they are visible only during the pillage action or until the end of the turn?

EDIT: It looks like the pillage code is in the core game engine... maybe the SDK will open the invisibility or pillage functionality up.

Also, Bhruics idea would work but it would break my "any unit with UNITCOMBAT_SNIPER as their unit combat can be a sniper" hopes.

12monkeys
Apr 01, 2006, 10:31 AM
There is a difference between the invisibility of a sub and the invisiblity of a spy. When looking into the UnitInfos.XML you can see, that the spy is not invisible, but has the bCounterSpy flag set.
To make the spy visible you have to change that attribute. I don't now, if this is possible with API, so Bhruic's method may be the only solution. I wouldn't wait for help of the SDK.

The Great Apple
Apr 01, 2006, 10:35 AM
Huh, I did know that about subs. I see what I can do there. Do you know if they are visible only during the pillage action or until the end of the turn?No idea.

EDIT: It looks like the pillage code is in the core game engine... maybe the SDK will open the invisibility or pillage functionality up.
CyUnit.NotifyEntity(MissionTypes.MISSION_PILLAGE)

The unit would have to be able to do the mission in the first place though (have moves, and something to pillage).

EDIT: This doesn't work. Don't even think about it.

Zuul
Apr 01, 2006, 11:01 AM
Was thinking about this the other day. A poor solution is to have the unit in the city it's built in, and move around a decoy others dont see (too small or something), and when the invisible unit is seen it will move from the city to the decoy.

The Great Apple
Apr 01, 2006, 11:03 AM
Was thinking about this the other day. A poor solution is to have the unit in the city it's built in, and move around a decoy others dont see (too small or something), and when the invisible unit is seen it will move from the city to the decoy.You can make things invisibly grapically without too much difficulty. The AI doesn't care about the graphics though. He also wants it to be seamless so you only have to add one item to the XML.

TheLopez
Apr 01, 2006, 11:27 AM
But the question now is how to make them temporarly visible.

12monkeys
Apr 01, 2006, 12:27 PM
Here's an idea :

CIV4BasicInfo.XML
- add a new Invisible Type INVISBLE_SPY, similar to the already existing INVISIBLE_SUBMARINE (look for it in there)

UnitInfos.XML
- set the <bInvisible> flag of the spy to 0 -> this makes the spy visible.
- set the <Invisible> of the spy to the new Invisiblity type INVISBLE_SPY -> this makes the spy invisible again and now the above mentioned PyPlot functions should work for spies, as long as you call them with INVISIBLE_SPY

- Optional : set the <SeeInvisible> of the spy to the new Invisiblity type INVISBLE_SPY -> now spies should always be able to see other spies.

Have no time to try that, but it could work.

TheLopez
Apr 01, 2006, 01:27 PM
Here's an idea :

CIV4BasicInfo.XML
- add a new Invisible Type INVISBLE_SPY, similar to the already existing INVISIBLE_SUBMARINE (look for it in there)

UnitInfos.XML
- set the <bInvisible> flag of the spy to 0 -> this makes the spy visible.
- set the <Invisible> of the spy to the new Invisiblity type INVISBLE_SPY -> this makes the spy invisible again and now the above mentioned PyPlot functions should work for spies, as long as you call them with INVISIBLE_SPY

- Optional : set the <SeeInvisible> of the spy to the new Invisiblity type INVISBLE_SPY -> now spies should always be able to see other spies.

Have no time to try that, but it could work.

I've tried that already, I have a new invisible type: INVISIBLE_SNIPER. But I did set the <bInvisible> flag to 1. I'll try setting the <bInvisible> flag to 0 and calling the methods to see if it works and report back.

TheLopez
Apr 01, 2006, 02:02 PM
Here's an idea :

CIV4BasicInfo.XML
- add a new Invisible Type INVISBLE_SPY, similar to the already existing INVISIBLE_SUBMARINE (look for it in there)

UnitInfos.XML
- set the <bInvisible> flag of the spy to 0 -> this makes the spy visible.
- set the <Invisible> of the spy to the new Invisiblity type INVISBLE_SPY -> this makes the spy invisible again and now the above mentioned PyPlot functions should work for spies, as long as you call them with INVISIBLE_SPY

- Optional : set the <SeeInvisible> of the spy to the new Invisiblity type INVISBLE_SPY -> now spies should always be able to see other spies.

Have no time to try that, but it could work.


As promised, I am reporting back my results. :bounce: :banana:
It worked!!!



# Show the hidden unit
objTargetPlot.changeInvisibleVisibilityCount(gc.ge tPlayer(0).getTeam(), gc.getInfoTypeForString("INVISIBLE_SNIPER"), 1)

# Hide the hidden unit
objTargetPlot.changeInvisibleVisibilityCount(gc.ge tPlayer(0).getTeam(), gc.getInfoTypeForString("INVISIBLE_SNIPER"), -1)


Thanks 12monkeys for providing that great lead and to everyone else for all your help!!!

TheLopez
Apr 01, 2006, 02:15 PM
Hmmmm.... here's an interesting problem. using those methods reveals all units with the invisibility type on the plot.

12monkeys
Apr 01, 2006, 03:32 PM
Doesn't suprise me, tbh. The method definition doesn't restrict something to a single unit. Only team and invisibility type as parameters.

I have an idea, which MAY work :
- lets say you have 3 units of the same ivisibility type and you want to reveal only one of them.
- first you have to determine the unit you want to reveal.
- then move away (with CyUnit.setXY()) the other two to any plot (eg: x+1, y+1).
- next apply the CyPlot.changeInvisibleVisibilityCount() methods
- move back the two other units.

I used that solution on a similar problem in my plot list enhancements. But it could be, that it will not work here, it the changeInvisibleVisibilityCount() sets a plot attribute.

TheLopez
Apr 01, 2006, 05:31 PM
Doesn't suprise me, tbh. The method definition doesn't restrict something to a single unit. Only team and invisibility type as parameters.

I have an idea, which MAY work :
- lets say you have 3 units of the same ivisibility type and you want to reveal only one of them.
- first you have to determine the unit you want to reveal.
- then move away (with CyUnit.setXY()) the other two to any plot (eg: x+1, y+1).
- next apply the CyPlot.changeInvisibleVisibilityCount() methods
- move back the two other units.

I used that solution on a similar problem in my plot list enhancements. But it could be, that it will not work here, it the changeInvisibleVisibilityCount() sets a plot attribute.


That doesn't work... we are changing the visibility of units at a plot not the visibility of the units themselves. I removed the units that I thought I made visibile through python using the WB then I added two more and they were still visible. So it is the plot that controls the visibility not the units themselves.

12monkeys
Apr 01, 2006, 05:39 PM
I was afraid of that. Sorry, no further ideas on this.

TheLopez
Apr 01, 2006, 06:12 PM
Its going to have to be good enough for now. I'll have just have to put it in the known issues.