View Full Version : My Mod Components


Mylon
Mar 16, 2011, 11:27 AM
Here's a central place for my mod components.

Culture Per Population, Forum thread (http://forums.civfanatics.com/showthread.php?t=414050) Download (http://forums.civfanatics.com/downloads.php?do=file&id=16680)

This component adjusts the culture buildings to give culture based on the population in the city. Now the optimum number of cities for focusing in culture is 1, where before building a few more cities would speed up the acquisition of Social Policies.

Flanking XP, Download (http://forums.civfanatics.com/downloads.php?do=file&id=16769)

This component awards exp to units that assist an attacker in flanking. Even if a unit is not directly involved in combat they are still passively helping and this rewards that.

Naval Counterattack, Download (http://forums.civfanatics.com/downloads.php?do=file&id=16773)

This mod allows naval units to fire back when attacked. This is primarily meant to be a test run for allowing land-based ranged units to return fire. There is no melee in naval combat, so it makes sense to test this change on sea first.

Wealth to Happiness boost

This component gives civilizations a bonus to happiness based on the amount of cash in their treasury. Current formula is +1 per (gold / 100 ) ^ 0.7. As of yet unreleased as I'm unsure of how to convey this information accurately to the player.

Comments are appreciated! Feel free to study my code to see how I perform these tasks, or include them in your own modpacks.

Moriboe
Mar 17, 2011, 08:35 PM
Nice work! I'm planning to use the Culture per Population code later for a couple of new buildings. The concept makes a great addition :goodjob:

Mylon
Mar 17, 2011, 11:00 PM
Glad to hear it. :)

Mentos
Mar 18, 2011, 11:30 AM
About Counterattacking:

According to your lua-code, you don't seem to check for the Attack Range.
What if the other unit doesn't have that reach? It wouldn't be plausible to fight back then.

In general, it sounds nice but on the other hand it turns units into whirling dervishes possibly destroying several weak units in one turn.
No battleship could ever be defeated by several weaker destroyers or possibly submarines which rely on stealthy attacks; at least not with a hefty cost.

Mylon
Mar 18, 2011, 12:33 PM
I tested attack range. A ship with range 3 will not be fired back upon. The way the attack is forced automatically checks for that. It also checks to see if the attacker has attacked already, which is why I needed to unflag the defender as having attacked.

As for the "whirling dervish", this is already the case with land melee units. Get one powerful unit in a strong defensive position and it can devastate many weaker units simply because it gets to defend itself multiple times. I figured this was a pleasant alternative to the current person-to-shoot-first-wins style of vanilla naval engagements. As for submarines, the battleship should only be able to return fire if the battleship can see the submarine. Though to be honest I haven't tested that possibility. The mod is mostly a concept and it does need some evaluation.

Mentos
Mar 18, 2011, 04:15 PM
I'm currently doing a test run with my rampaging Barbarians! mod on a small island map.

My Frigate with two "vs Naval" upgrades just confronted two daring Barbarian Caravels who "thought" it might my cool to damage it safely.
Unfortunately, they had no idea I could counter-attack and both sunk in return. My Frigate got way with only 3 HP lost.

See, that's an example of the AI not knowing how to deal with Ranged attacks. It is not coded to receive damage in return.
You can easily roundhouse kick many units this way without the AI knowning what hit it.

Mylon
Mar 18, 2011, 05:03 PM
You were using a frigate versus a caravel. And they were barbarian units, so you probably had some extra bonuses on top of that. Barbarians are stupid and aren't playing to win, so seeing them suicide is about what they'd do even without this mod. I hardly see what the problem is.

The other side of the coin is without this mod you can charge at an enemy fleet, focus fire 1/2 to 1/3rd of their ships down and when they return fire they have a lot less guns to fire, so you've already won.

Mylon
Apr 20, 2011, 09:59 AM
So I discovered that the naval counterattack and flanking XP mods don't work when quick-combat is on, as the function isn't called. Looks like I'm going to have to find a better hook.

mattpilot
Jul 04, 2011, 02:06 AM
wow... why are the best mods hidden?

Thanks for the counter attack mod - awesome change that definitely was needed for naval warfare.

One recommendation though - Perhaps the counter-attacking unit should only be allowed to return fire at 50% strength. This still gives the attacker the advantage by engaging first (surprise effect) and reflects 'superior positioning', while still ensuring that it isn't a 'risk free' attack.


Can't wait for this to be added to landbased artillery - though judging by the date of last post, i might be waiting for a long while :(.



A few more thoughts about improving this -> Add upgrades that can enhance the effects of return fire? Maybe start at 25% strength, and add 2 upgrade paths that add 25% each for a max total of 75%?

killmeplease
Jul 04, 2011, 10:26 PM
great! :goodjob:
i have to try these

Pouakai
Jul 08, 2011, 12:09 AM
Awesome! Would it be possible for Counter attacking to be available through a promotion instead of always being available?

killmeplease
Jul 08, 2011, 12:26 AM
it also could be a preventive counter attack promotion (x%)

mattpilot
Jul 08, 2011, 12:52 AM
think its vital for ships to have this without a promotion, as it does improve naval combat substantially.

Perhaps a default counterattack damage of 25%/strength for ships, 0% for land based and it can be increased 2 times with promotions for 25% each for a total of 50% land and 75% ships


now who's gunna make this since mylon is awol? :)

mattpilot
Jan 01, 2012, 07:35 AM
BUMP :P




It seems this mod is now 'broken' - perhaps with the recent patch? I haven't played civ in a while, but it did work back when this mod was released.


Possible for the latest patch to screw things up? Here's the script - someone please have a look:

-- Lua Script1
-- Author: Jeff
-- DateCreated: 16-Mar-11 13:56:17
--------------------------------------------------------------

print("Naval Counterattack Loaded")

function NavalCounterAttack(iAttackingPlayer, iAttackingUnit, iAttackingUnitDamage, iAttackingUnitFinalDamage, iAttackingUnitMaxHP, iDefendingPlayer, iDefendingUnit, iDefendingUnitDamage, iDefendingUnitFinalDamage, iDefendingUnitMaxHP)

-- First, let's make sure we're looking at a naval vs naval engagement
if iAttackingUnit > 0 and iDefendingUnit > 0 then

local AttackingUnit = Players[iAttackingPlayer]:GetUnitByID( iAttackingUnit )
local DefendingUnit = Players[iDefendingPlayer]:GetUnitByID( iDefendingUnit )

if (AttackingUnit:GetDomainType() == DomainTypes.DOMAIN_SEA and DefendingUnit:GetDomainType() == DomainTypes.DOMAIN_SEA) then
if (AttackingUnit:GetBaseRangedCombatStrength() > 0 and DefendingUnit:GetBaseRangedCombatStrength() > 0) then

--We're in business. Let's launch a counter-attack.
-- Initialize the attack-tracking if this is the first attack of the turn.
--if HasAttackedThisTurn == nil then
HasAttackedThisTurn = {}
--end

--On an initial attack, neither ship will have the flag, so let's flag the attacker.
if HasAttackedThisTurn[DefendingUnit] ~= true and HasAttackedThisTurn[AttackingUnit] ~= true then
HasAttackedThisTurn[AttackingUnit] = true
end

--If the defending unit has the flag, then this will prevent a counter-counter attack.
if HasAttackedThisTurn[DefendingUnit] ~= true then
--print("Qualifies for a counterattack.")
DefendingUnit:RangeStrike( AttackingUnit:GetX(), AttackingUnit:GetY() )
--Now that the attack has been made, let's reset the defender's attack flag so that it may defend from another attack.
DefendingUnit:SetMadeAttack(false)
-- By this point, the attacker will already have been checked to make a counter-counter attack, so let's delete our table.
HasAttackedThisTurn = nil
else
--print("This unit is flagged as having attacked already, unable to counter-attack.")
end

end
end
end
end

--function ClearCombatMemory()
--HasAttackedThisTurn = nil
--end

Events.EndCombatSim.Add( NavalCounterAttack )
--Events.PlayerDoTurn.Add( ClearCombatMemory )