SDI like Spatz?

Larsenex

King
Joined
Oct 31, 2005
Messages
774
Location
Longview, Texas
HI there. I am really looking for a lighter-weight mod that has only a few tweaks in it but more importantly the SDI which WORKS like Crazy Spatz. Dont get my wrong, I like Spatz mod but I didnt want to jump in such a large change of concepts/units/buildings so fast.

I wanted to get Mech Inf to use oil, Modern Tanks to use oil+alum (have more moves and/or Amph)

SDI to tone down the amount of glowing yellow dirt later in game. I was going to simply see if the cost of Nukes could be made to 4 or 5 uranium but I suppose that wont fix the issue much.

Any advice or direction would be great.
 
First of all, this shouldn't go in this forum (only completed modfiles go here). A Moderator should move this, either to the general C&C forum, or to the SDK/Lua section.

Second, you could have just asked me. The code is in two main parts. I'll give you the code so that you can tweak it to your own tastes, but you'll have to build your own mod out of it. (Should be easy if you've done any modding at all.)

Start with the XML definitions. You need to create a Project that adds nuke interception ability; while the Nuke Interception stubs don't DO anything, the game does keep track of them, so they make a handy way to do this. Okay, technically you don't HAVE to, and could just make a flat amount or check for projects individually, but it works better that way. Something like:
Spoiler :
Code:
<GameData>
	<Projects>
		<Row>
			<Type>PROJECT_SDI</Type>
			<Description>TXT_KEY_PROJECT_SDI</Description>
			<Help>TXT_KEY_PROJECT_SDI_HELP</Help>
			<Civilopedia>TXT_KEY_PROJECT_SDI_PEDIA</Civilopedia>
			<Strategy>TXT_KEY_PROJECT_SDI_STRATEGY</Strategy>
			<TechPrereq>TECH_DOCTRINE_FLEXIBILITY</TechPrereq>
			<Cost>1200</Cost>
			<NukeInterception>40</NukeInterception>
			<MaxGlobalInstances>-1</MaxGlobalInstances>
			<MaxTeamInstances>1</MaxTeamInstances>
			<IconAtlas>UNIT_ATLAS_SMAC</IconAtlas>
			<PortraitIndex>23</PortraitIndex>
		</Row>
	</Projects>
	<Project_Flavors>
		<Row>
			<ProjectType>PROJECT_SDI</ProjectType>
			<FlavorType>FLAVOR_DEFENSE</FlavorType>
			<Flavor>50</Flavor>
		</Row>
		<Row>
			<ProjectType>PROJECT_SDI</ProjectType>
			<FlavorType>FLAVOR_NUKE</FlavorType>
			<Flavor>50</Flavor>
		</Row>
	</Project_Flavors>
</GameData>
You'd need to change the technology it's assigned to, because the one I listed there is unique to my mod. And you'll have to change the text keys and provide your own icon, of course.
In my mod there are actually two nuke-defense projects. Just repeat this process as necessary; nuke interception chances stack between multiple projects, so you could split it into two parts if you wanted.

Then, there's the Lua part:
Spoiler :
Code:
function SpatzStartCombat(iAttackingPlayer, iAttackingUnit, iAttackingUnitDamage, iAttackingUnitFinalDamage, iAttackingUnitMaxHitPoints, iDefendingPlayer, iDefendingUnit, iDefendingUnitDamage, iDefendingUnitFinalDamage, iDefendingUnitMaxHitPoints, bContinuation)
	if( iAttackingPlayer ~= -1 ) then
		aPlayer = Players[iAttackingPlayer];
	end

	if( iAttackingUnit ~= -1 ) then
		aUnit = aPlayer:GetUnitByID(iAttackingUnit);
		aType = aUnit:GetUnitType();
		aName = GameInfo.Units[aType].Type;
		aText = Locale.ConvertTextKey(GameInfo.Units[aType].Description);

		aNuke = GameInfo.Units[aType].NukeDamageLevel;
		if( aNuke > 0 ) then
			print( "It's a NUKE!!!! ",aName );
			local chance = 0;
			local numwars = 0;
			aTeam = aPlayer:GetTeam();
			for index,oPlayer in pairs(Players) do
				if( oPlayer ~= nil and oPlayer:IsAlive() and not oPlayer:IsMinorCiv() and not oPlayer:IsBarbarian() ) then
					oTeam = oPlayer:GetTeam();
					if (Teams[aTeam]:IsAtWar(oTeam) ) then
						chance = chance + Teams[oTeam]:GetNukeInterception();
						numwars = numwars + 1;
					end
				end
			end
			if(numwars > 1) then
				chance = chance * ( (numwars + 1) / (2*numwars) ); -- this gives weightings of 1.0, 1.5, 2.0, 2.5, and so on.
			end

			if(aName == "UNIT_ATOMIC_BOMB") then
				chance = chance * 1.50;
				minChance = 30;
				maxChance = 90;
			end
			if(aName == "UNIT_NUCLEAR_MISSILE") then
--				chance = chance * 1.0;
				minChance = 20;
				maxChance = 75;
			end
			if(chance < minChance) then
				chance = minChance;
			end
			if(chance > maxChance) then
				chance = maxChance;
			end
			print("Chance of interception: ",chance );

			if(chance > 0) then
				local diceroll = Map.Rand(100, "Nuke Interception chance");
				if (diceroll < chance) then
					aUnit:Kill();

					toolTip = "The "..aText.." belonging to "..aPlayer:GetName().." was intercepted.";
print(toolTip);
				end -- if we intercepted it
			end -- if we CAN intercept it
		end -- if it's a nuke
	end -- if it's an attacking unit
end
Events.RunCombatSim.Add( SpatzStartCombat );

That'll do it. What's there is very trimmed down from my version, since I add two additional nuke weapons (Planet Busters and the Subspace Generator), but all of the essential logic is there.

The way it works is:
> SDI gives a 60% chance of intercepting an Atomic Bomb, and a 40% chance of intercepting a Nuclear Missile.
> If you're at war with more than one civ that has SDI, the effects partially stack; two SDIs are x1.5, three are x2.0, and so on.
> Atomic Bombs always have a 30% chance of failing, and Nuclear Missiles a 20% chance, even if there's no SDI involved.
> Atomic Bombs always have a 10% chance of getting through your defenses, and Nuclear Missiles a 25% chance, no matter how high your interceptions stack.

Obviously, if you don't like those later bits you can tweak the numbers for yourself. But there's one thing to be aware of: the event being used here, RunCombatSim, will have no information about which civ is the target of the nuke. That's the reason for the second part above (the x1.5, x2.0, etc.); the only way to do this in any reasonably balanced way is to have every civ at war with the launching civ contribute to the defense.

A few other tidbits:
> There's no in-game notification when the nuke gets shot down, just a line in the FireTuner console. I'm still working on creating a better notification for my own mod.
> If the player has Quick Combat or Strategic View turned on, it won't work.
> If you decide to open a war with a nuke, then even if it's shot down the target will be at war with you.
> If you nuke a city-state, the major empires you're at war with will help defend it. If you're not at war with any major empires, the city-state (which has no projects) would only have that minimum 30%/20% chance of failure.
 
Spatz I apologize. I ment no offense. I think your mod is great. On that note I will send you a PM on some things..

Thank you very much for your response.
 
Top Bottom