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

Fort Attack

Discussion in 'Civ4 - Mod Components' started by Archid, Jun 12, 2013.

  1. Archid

    Archid Warlord

    Joined:
    Oct 30, 2009
    Messages:
    287
    Location:
    North Wales, UK
    Free Fort Attack

    Synopsis
    Allows units in forts, and optionally cities, a free attack against enemies in the surrounding plots

    Download
    The file is available for download at CF here

    Gameplay
    Configured units that are stationed in a fort at the end of a turn can perform a free attack against enemy troops in the surrounding squares. The attackers also need some movement points at the end of the turn.

    The potential targets of attack varies depending on the ownership of the fort plot. If the fort is on a plot that is owned by a player then only enemies of the owners team are potential targets. If the fort is in neutral territory then all units in surrounding squares are considered potential targets.

    At the end of a turn each attacker picks one of its teams enemies at random and performs the attack. The damage that these attacks can give uses a configurable base value (percentage of targets full health) with a multiplier based on the relative strength of the attacker and target. There is a configurable cap on the maximum percentage damage that a target can have at the end of the attack, and any units that have less than this value are not considred potential targets. The attackers are never damaged in a fort attack.

    The configurable values are set in the GlobalDefinesAlt file.

    Situation before the end of turn
    Spoiler :




    Catherine & Qin decided on a suicide attack with one of their archers before the fort attack began so the attackers strength had changed before the fort attack began
    Spoiler :

    Qin gets attacked 3 times and Catherins once



    and rinse and repeat
    Spoiler :

    Both attacked twice this time, Catherine was attacked by SB & Monte who were both damaged during the suicide attackes so you can see the power ratio being applied to the damage



    Modders
    The types of units who can attack is based on a new optional tag in the UnitCombatInfo type so is fully configurable.

    SDK Changes marked with Archid

    Added XML tags
    -------------------
    ++ UnitCombatInfo
    bFortAttack - If units of this combat type get a free attack from forts. Defaults to 0


    Revision History
    -------------------
    v1.1 Fixed CTD bug if a potential attacker has no UnitCombatType
    Added message to players if they are the attackers

    v1.0 Initial release
     
  2. vincentz

    vincentz Programmer

    Joined:
    Feb 4, 2009
    Messages:
    3,556
    Gender:
    Male
    Location:
    Denmark
    Looks very interesting :goodjob:

    I'm adding this to my VIP and considering using it for cities as well.
    The optimal solution would be if city had XX building (i.e. citywalls and/or castle), but donno how to code.
    Guess its around here ? :
    PHP:
    bool CvPlot::isCanFortAttack() const
    {
        return 
    getImprovementType() != NO_IMPROVEMENT && GC.getImprovementInfo(getImprovementType()).isActsAsCity();
    }
    another thing that would be pure awesome, was if the iAirRange was considered also for landunits. (using airRange for my siegeweapons in VIP).


    edit : Also a message when one of your own units have attacked a unit would be nice :D
     
  3. platyping

    platyping Sleeping Dragon

    Joined:
    Oct 22, 2010
    Messages:
    4,626
    Location:
    Emerald Dreams
    Would be more realistic if only ranged units can perform the free attacks
     
  4. vincentz

    vincentz Programmer

    Joined:
    Feb 4, 2009
    Messages:
    3,556
    Gender:
    Male
    Location:
    Denmark
    yup, my plan was to set only sieges, which is really easy with the mod. Its set in CIV4UnitCombatInfos.xml, so its pretty easy to limit it to ranged sieges only
     
  5. Archid

    Archid Warlord

    Joined:
    Oct 30, 2009
    Messages:
    287
    Location:
    North Wales, UK
    If you want it to act for both forts and cities then the following should work.

    PHP:
    bool CvPlot::isCanFortAttack() const
    {
        return 
    isCity(true);
    }
    passing true to the method tells it to also check improvements. I am in the middle of helping someone else out with their mod for now so I am a bit busy, but I'll see if I can find some time to code up having a building tag enable cities to have a free attack. It shouldn't be that difficult.
     
  6. vincentz

    vincentz Programmer

    Joined:
    Feb 4, 2009
    Messages:
    3,556
    Gender:
    Male
    Location:
    Denmark
    Thanks :D I'll try it out.

    just happy that I get a response of a 1½ year old mod :D
    nevermind with the buildingthing, but a message when one of your own units have made an attack would be nice :D
     
  7. vincentz

    vincentz Programmer

    Joined:
    Feb 4, 2009
    Messages:
    3,556
    Gender:
    Male
    Location:
    Denmark
    I gave it a go, but unfortunately the mod crashes with 25-50 turns in.
    Replacing with the old code makes it work again.
     
  8. Archid

    Archid Warlord

    Joined:
    Oct 30, 2009
    Messages:
    287
    Location:
    North Wales, UK
    Thanks for giving it a go, I'll have a look at it this weekend if I can grab some time from RL.
     
  9. Archid

    Archid Warlord

    Joined:
    Oct 30, 2009
    Messages:
    287
    Location:
    North Wales, UK
    Cities can now optionally (GlobalDefinesAlt) attack in the same way as forts. I have also added a message for each attacker when they have damaged an enemy.
     

Share This Page