1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

My Mod Components

Discussion in 'Civ5 - Mod Components' started by Mylon, Mar 16, 2011.

  1. Mylon

    Mylon Amateur Game Designer

    Joined:
    Nov 4, 2005
    Messages:
    1,013
    Here's a central place for my mod components.

    Culture Per Population, Forum thread Download

    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

    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

    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.
     
  2. Moriboe

    Moriboe King

    Joined:
    Nov 30, 2010
    Messages:
    659
    Location:
    Belgium
    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:
     
  3. Mylon

    Mylon Amateur Game Designer

    Joined:
    Nov 4, 2005
    Messages:
    1,013
  4. Mentos

    Mentos Prince

    Joined:
    Sep 29, 2010
    Messages:
    377
    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.
     
  5. Mylon

    Mylon Amateur Game Designer

    Joined:
    Nov 4, 2005
    Messages:
    1,013
    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.
     
  6. Mentos

    Mentos Prince

    Joined:
    Sep 29, 2010
    Messages:
    377
    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.
     
  7. Mylon

    Mylon Amateur Game Designer

    Joined:
    Nov 4, 2005
    Messages:
    1,013
    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.
     
  8. Mylon

    Mylon Amateur Game Designer

    Joined:
    Nov 4, 2005
    Messages:
    1,013
    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.
     
  9. mattpilot

    mattpilot Warlord

    Joined:
    Jan 29, 2004
    Messages:
    184
    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%?
     
  10. killmeplease

    killmeplease Mk Z on Steam

    Joined:
    Nov 22, 2007
    Messages:
    2,794
    Location:
    Samara
    great! :goodjob:
    i have to try these
     
  11. Pouakai

    Pouakai It belongs in a museum. Moderator

    Joined:
    Jun 16, 2010
    Messages:
    7,151
    Location:
    Aotearoa
    Awesome! Would it be possible for Counter attacking to be available through a promotion instead of always being available?
     
  12. killmeplease

    killmeplease Mk Z on Steam

    Joined:
    Nov 22, 2007
    Messages:
    2,794
    Location:
    Samara
    it also could be a preventive counter attack promotion (x%)
     
  13. mattpilot

    mattpilot Warlord

    Joined:
    Jan 29, 2004
    Messages:
    184
    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? :)
     
  14. mattpilot

    mattpilot Warlord

    Joined:
    Jan 29, 2004
    Messages:
    184
    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:

    Spoiler :
    Code:
    -- 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 )
     

Share This Page