Making an invisible unit

MerakSpielman

Warlord
Joined
Oct 27, 2005
Messages
217
I was making a unique unit for my Elf civilization that replaces the normal scout. The idea was to have an "invisible" scout, using the abilities of the submarine.

It shows up in-game as a promotion, but the unit isn't actually invisible. I can tell because barbarians seem to delight in destroying him.

so here's the code snippets that seem to work, as in they don't crash the game and they do show up in game as a promotion the scout possesses:

Spoiler :
Code:
<GameData>
	<Units>
		<Row>
			<Class>UNITCLASS_SCOUT</Class>
			<Type>UNIT_ELVEN_RANGER</Type>
			<Combat>4</Combat>
			<Cost>25</Cost>
			<Moves>3</Moves>
			<CombatClass>UNITCOMBAT_RECON</CombatClass>
			<Domain>DOMAIN_LAND</Domain>
			<DefaultUnitAI>UNITAI_EXPLORE</DefaultUnitAI>
			<Description>TXT_KEY_UNIT_ELVEN_RANGER</Description>
			<Civilopedia>TXT_KEY_CIV5_ELVEN_RANGER</Civilopedia>
			<Strategy>TXT_KEY_UNIT_ELVEN_RANGER_STRATEGY</Strategy>
			<Help>TXT_KEY_UNIT_HELP_ELVEN_RANGER</Help>
			<NoBadGoodies>true</NoBadGoodies>
			<Pillage>true</Pillage>
			<MilitarySupport>true</MilitarySupport>
			<MilitaryProduction>true</MilitaryProduction>
			<ObsoleteTech>TECH_SCIENTIFIC_THEORY</ObsoleteTech>
			<GoodyHutUpgradeUnitClass>UNITCLASS_ARCHER</GoodyHutUpgradeUnitClass>
			<AdvancedStartCost>10</AdvancedStartCost>
			<XPValueAttack>3</XPValueAttack>
			<XPValueDefense>3</XPValueDefense>
			<UnitArtInfo>ART_DEF_UNIT_SCOUT</UnitArtInfo>
			<UnitFlagIconOffset>5</UnitFlagIconOffset>
			<IconAtlas>UNIT_ATLAS_1</IconAtlas>
			<PortraitIndex>5</PortraitIndex>
		</Row>
	</Units>

	<Unit_AITypes>
		<Row>
			<UnitType>UNIT_ELVEN_RANGER</UnitType>
			<UnitAIType>UNITAI_EXPLORE</UnitAIType>
		</Row>
	</Unit_AITypes>

	<Unit_Flavors>
		<Row>
			<UnitType>UNIT_ELVEN_RANGER</UnitType>
			<FlavorType>FLAVOR_RECON</FlavorType>
			<Flavor>7</Flavor>
		</Row>
	</Unit_Flavors>

	<Unit_FreePromotions>
		<Row>
			<UnitType>UNIT_ELVEN_RANGER</UnitType>
			<PromotionType>PROMOTION_IGNORE_TERRAIN_COST</PromotionType>
		</Row>
		<Row>
			<UnitType>UNIT_ELVEN_RANGER</UnitType>
			<PromotionType>PROMOTION_INVISIBLE_ELVEN_RANGER</PromotionType>
		</Row>
	</Unit_FreePromotions>

	<UnitPromotions>
		<Row>
			<Type>PROMOTION_INVISIBLE_ELVEN_RANGER</Type>
			<Description>TXT_KEY_PROMOTION_INVISIBLE_ELVEN_RANGER</Description>
			<Help>TXT_KEY_PROMOTION_INVISIBLE_ELVEN_RANGER_HELP</Help>
			<Sound>AS2D_IF_LEVELUP</Sound>
			<Invisible>INVISIBLE_SUBMARINE</Invisible>
			<PortraitIndex>59</PortraitIndex>
			<IconAtlas>ABILITY_ATLAS</IconAtlas>
			<PediaType>PEDIA_ATTRIBUTES</PediaType>
			<PediaEntry>TXT_KEY_PEDIA_PROMOTION_INVISIBLE_ELVEN_RANGER</PediaEntry>
		</Row>
	</UnitPromotions>

Why did I leave it saying "<Invisible>INVISIBLE_SUBMARINE</Invisible>" you say? I'm glad you asked. I figure that's where the problem is.

There's another file, called InvisibleInfos.xml. It contains the INVISIBLE_SUBMARINE data, plus a dire warning:

Spoiler :
Code:
	<!--
	Very Important: If you change this at all you will need to change
	NUM_INVISIBLE_TYPES in CvPlot and recompile (this was done for memory allocation efficiency)
	-->
So I erred on the side of caution and didn't create an INVISIBLE_ELVEN_RANGER row in that table. I am unable to change things in CvPlot. It doesn't sound like I can use any sort of function in LUA to change this variable, because it says I should recompile afterwards. This leads me to believe that NUM_INVISIBLE_TYPES is a hard-coded variable that can only be changed manually in the source code.

So I left my Elven Ranger pointing to the INVISIBLE_SUBMARINE definition, hoping it would work. But he fails to turn invisible (and for all I know, I broke the Submarine too, since there are now 2 invisible units).


Does anybody have any ideas? Workarounds? Or should I just come up with a different unit until we get access to the code?
 
Just out of curiosity, can you make a unit with domain_sea that has the invisible promotion? Or what about making the scout a unit class_submarine with all the stats of the land unit you want?
 
OK I got it working... I decided to test editing the file with the Dire Warning. I added an entry for INVISIBLE_ELVEN_RANGER and it seems to be working perfectly.

That is to say, it WORKS. Which made me realize how massively broken it is.

The scout is invisible, but he can attack. If that wasn't enough, if he hits a goody hut, he turns into an invisible archer. Capable of ranged attacks, where the opponent doesn't even get a chance to do any damage. He can just sit there and plink anybody to death with no fear of retaliation.

So I made my Elven Ranger have no Strength score, so he can't attack. And I turned off his goody hut promotion ability.
 
Thanks for figuring it out and linking this thread in the other thread.

I think I have it working ... so far its great. I wonder if there will be an unexplained crash later on when someone makes submarines? Not sure what "NUM_INVISIBLE_TYPES in CvPlot" means ... I cant even find the file.

I will post my unit in this thread later on when I am finished tweaking it.
 
That is to say, it WORKS. Which made me realize how massively broken it is.

The scout is invisible, but he can attack. If that wasn't enough, if he hits a goody hut, he turns into an invisible archer. Capable of ranged attacks, where the opponent doesn't even get a chance to do any damage. He can just sit there and plink anybody to death with no fear of retaliation.

Amazing. :lol: What a great find.
 
CvPlot was a file within the DLL (it's C++) in Civ IV, chance is they reused the setup and kept a few file names. This will be editable when they release the DLL for Civ V.
 
I would guess that yes, NUM_INVISIBLE_TYPES is hardcoded, but no, it's not set to 1. That means there is some hard limit to NUM_INVISIBLE_TYPES, but we have no idea what it is as yet, and may run into it if we add invisible types willy-nilly. I'm planning a modern/near future tech/unit suite (using existing 3D graphics for now, of course) with some invisibility capabilities for irregulars, but I'll make sure to make it a single type just to be careful.
 
I would prefer to do something more weird, where I could let him be invisible until he attacks, then he has to be out of sight of enemy units for 3 turns straight before he can turn invisible again...

But that'll just have to wait. :P
 
I would prefer to do something more weird, where I could let him be invisible until he attacks, then he has to be out of sight of enemy units for 3 turns straight before he can turn invisible again...

But that'll just have to wait. :P
That's what I'd like for my modern-era Irregulars, too. Instead, I have to think hard about what will be able to see them.
 
Back
Top Bottom