1. We have added the ability to collapse/expand forum categories and widgets on forum home.
    Dismiss Notice
  2. Photobucket has changed its policy concerning hotlinking images and now requires an account with a $399.00 annual fee to allow hotlink. More information is available at: this link.
    Dismiss Notice
  3. All Civ avatars are brought back and available for selection in the Avatar Gallery! There are 945 avatars total.
    Dismiss Notice
  4. To make the site more secure, we have installed SSL certificates and enabled HTTPS for both the main site and forums.
    Dismiss Notice
  5. Civ6 is released! Order now! (Amazon US | Amazon UK | Amazon CA | Amazon DE | Amazon FR)
    Dismiss Notice
  6. Dismiss Notice
  7. Forum account upgrades are available for ad-free browsing.
    Dismiss Notice

Dale's MOD Code Factory

Discussion in 'Civ4 - Mod Components' started by Dale, Jun 13, 2006.

  1. Dale

    Dale Chieftain

    Joined:
    Mar 14, 2002
    Messages:
    6,986
    Location:
    Melbourne
    Welcome to Dale's MOD Code Factory! :)

    I'm going to be placing here code that can be used in an advanced fashion by modders to enhance their own mods.

    NOTE: These code items WILL require you to modify and compile a new SDK DLL file! Do not attempt this if you are unsure what you are doing!

    NOTE2: Due to new features in my full combat mod to allow for turning each component on/off code and DLL's are not provided as seperate anymore. You only need one DLL and turn the game options off.

    Also note that I will not be providing support for how to compile or use the SDK. Those questions are for different threads in a different forum. :)

    --------------------------------------------------------------------------------------------------------

    Ranged Field Bombardment:
    SDK Code (Vanilla & Warlords): http://forums.civfanatics.com/downloads.php?do=file&id=2708

    What it does:

    Units that are given this ability lose the vanilla bombard ability of bombarding adjacent cities, and gain a ranged bombard ability on units, cities and improvements. The bomb range xml setting defines how far away the unit can bombard. Simple click the bombard icon and select the tile you wish to bombard. Allowed squares show in green when mousing over them, similar to the air bomb event.

    How to Implement:

    Step 1: Add the new code to the DLL and compile.
    Step 2: Modify the #define value in CvDefines.h to true or false (true turns on the mod) and re-compile.
    Step 3: Add the new interface to CIV4InterfaceModeInfos.xml
    Code:
    		<InterfaceModeInfo>
    			<Type>INTERFACEMODE_BOMBARD</Type>
    			<Description>Ranged Field Bombard</Description>
    			<Help>Ranged Field Bombard</Help>
    			<CursorType>CURSOR_AIRBOMB</CursorType>
    			<Mission>MISSION_BOMBARD</Mission>
    			<HotKey>KB_B</HotKey>
    			<bAltDown>0</bAltDown>
    			<bShiftDown>0</bShiftDown>
    			<bCtrlDown>0</bCtrlDown>
    			<iHotKeyPriority>0</iHotKeyPriority>
    			<HotKeyAlt/>
    			<bAltDownAlt>0</bAltDownAlt>
    			<bShiftDownAlt>0</bShiftDownAlt>
    			<bCtrlDownAlt>0</bCtrlDownAlt>
    			<iHotKeyPriorityAlt>0</iHotKeyPriorityAlt>
    			<bVisible>1</bVisible>
    			<bGotoPlot>0</bGotoPlot>
    			<bHighlightPlot>1</bHighlightPlot>
    			<bSelectType>0</bSelectType>
    			<bSelectAll>0</bSelectAll>
    			<Button>,Art/Interface/Buttons/Actions/Bombard.dds,Art/Interface/Buttons/Actions_Builds_LeaderHeads_Specialists_Atlas.dds,2,1</Button>
    		</InterfaceModeInfo>
    
    Step 4: Modify the MISSION_BOMBARD event in CIV4MissionInfos.xml
    Code:
    		<MissionInfo>
    			<Type>MISSION_BOMBARD</Type>
    			<Description>TXT_KEY_MISSION_BOMBARD</Description>
    			<Help>TXT_KEY_MISSION_BOMBARD_HELP</Help>
    			<Waypoint>NONE</Waypoint>
    			<EntityEventType>ENTEVENT_BOMBARD</EntityEventType>
    			<iTime>16</iTime>
    			<bTarget>0</bTarget>
    			<bBuild>0</bBuild>
    			<bSound>1</bSound>
    			<Button>,Art/Interface/Buttons/Actions/Bombard.dds,Art/Interface/Buttons/Actions_Builds_LeaderHeads_Specialists_Atlas.dds,2,1</Button>
    		</MissionInfo>
    
    Step 5: Add the new xml flags to the schema in CIV4UnitSchema.xml
    Code:
    	<ElementType name="bDCMBombard" content="textOnly" dt:type="boolean"/>
    	<ElementType name="iDCMBombRange" content="textOnly" dt:type="int"/>
    
    AND in the CvUnitInfo element:
    Code:
    		<element type="bDCMBombard" minOccurs="0"/>
    		<element type="iDCMBombRange" minOccurs="0"/>
    
    Step 6: Modify your units by adding the following code in Civ4UnitInfos.xml
    Code:
    			<bDCMBombard>1</bDCMBombard>
    			<iDCMBombRange>1</iDCMBombRange>
    
    NOTE: The value of iDCMBombRange is the number of tiles the unit can bombard. EG: Artillery with a iDCMBombRange of 2 can bombard 2 tiles away.

    --------------------------------------------------------------------------------------------------------

    Missiles (suicide units):
    SDK Code (Vanilla & Warlords): http://forums.civfanatics.com/downloads.php?do=file&id=2708

    What it does:

    The missile ability causes units to explode on contact with the enemy. This explosion is done during combat. One combat round will be processed (so a chance the missile itself could be hit for anti-air units you create [see below in notes]) and then the missile will explode. The nuke range ability has been enabled for non-special nuke units when they have the missile tag. This means your missile can be nuclear as well to create tactical nukes.

    How to Implement:

    Step 1: Add the new code to the DLL and compile.
    Step 2: Modify the #define value in CvDefines.h to true or false (true turns on the mod) and re-compile.
    Step 3: Add the new xml flags to the schema in CIV4UnitSchema.xml
    Code:
    	<ElementType name="bDCMMissile" content="textOnly" dt:type="boolean"/>
    
    AND in the CvUnitInfo element:
    Code:
    		<element type="bDCMMissile" minOccurs="0"/>
    
    Step 4: Modify your units by adding the following code in Civ4UnitInfos.xml (this will make them missile units)
    Code:
    			<bDCMMissile>1</bDCMMissile>
    
    NOTE: If you give a missile unit nuke abilities by change nuke range to: <iNukeRange>1</iNukeRange> the unit will become a nuclear missile. In this way by defining the air range and air bomb abilities for the unit you just click on air bomb mission and select the target in range. Your unit is now a tactical nuclear missile. :)

    NOTE2: Since one combat round is processed before the missile explodes, you could create your missile unit, then the anti-missile unit with a combat bonus against the missile unit. By testing and getting the correct values the anti-missile unit has the chance to destroy the missile before impact. Example: You could have a ballistic missile and a SDI unit with a combat bonus against the missile. The SDI unit has a chance to destroy the missile before the ballistic missile explodes.

    NOTE3: The missile ability and nuke range change can be made to any unit. You could give just the missile ability to a Japanese fighter in a world war 2 scenario to have kamikazee zeros, or give both abilities to a spearman to have a nuclear suicide spearmen troop. The options are endless.
     
  2. Dale

    Dale Chieftain

    Joined:
    Mar 14, 2002
    Messages:
    6,986
    Location:
    Melbourne
    MAD (pre-targetted nukes):
    SDK Code (Vanilla & Warlords): http://forums.civfanatics.com/downloads.php?do=file&id=2708

    What it does:

    This MAD nukes mod differs from TheLopez's MAD nukes mod in that this one allows for pre-targetted nukes. It makes no changes to how nukes destroy like TheLopez's mod. Basically, in peacetime click on the launch button, click on a potential enemies city and that city will be targetted by the nuke. If the owner of that city ever launches a nuke at you your early detection systems will detect the incoming nuke and automatically launch your MAD nukes at that player. In this way, you can ensure his destruction if caught in a nuclear war. But beware! Any MAD nukes of that player and his allies targetted at YOU will launch in retaliation to your retaliatory strike. Thus the 1960's cold war is born, with the assurance that if you get destroyed, you'll take a hellova lot of enemies out with you at the same time. ;)

    How to Implement:

    Step 1: Add the new code to the DLL and compile.
    Step 2: Modify the #define DCMMad value in CvDefines.h to true or false (true turns on the mod).
    Step 3: Modify the #define DCMMadMsgs value in CvDefines.h to true or false (true display messages, false turn messages off) and re-compile.

    NOTE: If you target your nuke (making it a MAD nuke) and then re-target that nuke at the same city, the MAD system will take it as a manual over-ride and allow the nuke to launch. You may however change the target of the nuke safetly without the MAD system launching it.

    NOTE2: The AI will target what it believes are its potential enemies. The AI's agenda may be different to what you actually think it is. :)

    NOTE3: The MAD system is connected with your team members, this is to ensure the continuance of the alliance, and mutual defense. So if a nuke is launched at you, your allies MAD nukes will launch back at that player and his team members. The actual MAD response to a nuke attack is done just before your turn.

    NOTE4: If you want to cancel a nuke's target simply click the nuke button and then on the nuke itself.

    NOTE5: If a nuke's target city is captured or destroyed (or becomes invalid any method) then the nuke's target will be reset and the nuke will be awoken (if sleeping or fortified). As a human (with DCMMadMsgs set to true) you will get a "target lost" message. Also, when the nuke goes to launch but the target city is invalid the nuke will reset and you'll receive a "target failed" message.

    NOTE6: Available python commands are
    - CyUnit::getDCMMad() returns true if nuke has a target
    - CyUnit::getDCMMadPlot() returns the target plot or NULL
    - CyUnit::getDCMPlotOwner() returns the owner of the target or NO_PLAYER (-1)
    - CyPlayer::getDCMIncoming() returns the number of incoming targets (own cities targetted by enemys)
    - CyPlayer::getDCMOutgoing() returns the number of your nukes with targets
    - CyPlayer::getDCMMadDeter() returns the value of the AI's MAD deterent level
    - CyPlayer::setDCMMadDeter(int value) sets the AI's MAD deterent level

    --------------------------------------------------------------------------------------------------------

    Combined Arms Stack Attack:
    SDK Code (Vanilla & Warlords): http://forums.civfanatics.com/downloads.php?do=file&id=2708

    What it does:

    This mod takes the stack attack element of Civ4 to a completely new level. This mod will simulate a combined arms stack attack against the enemy. Air units will scramble during a battle to intercept enemy planes and strike at enemy ground units (even fighters on carriers and in cities). Siege and ranged units will now fire on the enemy's units while being protected by their own frontline. Flanking units will attempt to go around the enemy frontline to harass the enemy's siege and ranged units. The graphic simulation will now correctly show the battle between the two stacks. For those who have played Call to Power 2 this will seem familiar. But the design of the combat resolution has been increased to better simulate a battle between two armies. I have included an example unit schema file and unit xml file in the compiled zip file. These are set for vanilla civ units.

    How to Implement:

    Step 1: Add the new code to the DLL and compile.
    Step 2: Modify the #define value in CvDefines.h to true or false (true turns on the mod) and re-compile.
    Step 3: Add the new xml flags to the schema in CIV4UnitSchema.xml
    Code:
    	<ElementType name="bDCMFlanker" content="textOnly" dt:type="boolean"/>
    	<ElementType name="bDCMRanged" content="textOnly" dt:type="boolean"/>
    	<ElementType name="bDCMBombard" content="textOnly" dt:type="boolean"/>
    
    AND in the CvUnitInfo element:
    Code:
    		<element type="bDCMFlanker" minOccurs="0"/>
    		<element type="bDCMRanged" minOccurs="0"/>
    		<element type="bDCMBombard" minOccurs="0"/>
    
    Step 4: Modify your units by adding ONLY ONE of the following code elements to a unit in Civ4UnitInfos.xml
    Code:
    			<bDCMFlanker>1</bDCMFlanker>
    			<bDCMRanged>1</bDCMRanged>
    			<bDCMBombard>1</bDCMBombard>
    
    NOTE: Combat is resolved via the following process:
    - Attackers sorted into 4 lines (15 units max including cargo)
    - Defenders sorted into 4 lines (15 units max including cargo)
    - Defender air units will attempt an air strike against the attacking stack with risk of interception
    - Defender siege units will process one round of combat to simulate a bombardment
    - Defender ranged units will process one round of combat to simulate an arrow storm
    - Attacker air units will attempt an air strike against the defending stack with risk of interception
    - Attacker siege units will process one round of combat to simulate a bombardment
    - Attacker ranged units will process one round of combat to simulate an arrow storm
    - Attacker melee and flanking units will attack the enemy melee and flanking units (if no enemy unit stands in front of them there is a breakthrough into the enemy ranged and siege lines)

    NOTE2: Stacks are limited to 10 units. However those units can have cargo. Only 15 units will participate in a battle though.

    NOTE3: Interception rates during a stack attack are at an increased value to vanilla Civ4. Beware of that.

    NOTE4: I know the outcome of the battles appear slowely in the message area. I am working on speeding that up. :)

    NOTE5: Fighters on carriers will now auto-scramble in defense and attack for the stack.

    Dale
     
  3. Serga

    Serga Civilized maniak

    Joined:
    Dec 5, 2005
    Messages:
    72
    Cool..
    Must have for any mod.
    Regards.
     
  4. Bill3000

    Bill3000 OOOH NOOOOOOO! Supporter

    Joined:
    Oct 31, 2005
    Messages:
    18,464
    Location:
    Quinquagesimusermia
    Two things:

    1) I am getting an error in the XML when I launch the game saying that "ENTITY_EVENT_BOMBARD" doesn't exist, basically. The others entity event entries are of the form ENTEVENT_NAME, so this might be the problem. Obviously, the game crashes when I click to bombard. :p (Selecting works, though) Changing it to ENTEVENT_BOMBARD works, though.

    2) Looking at the source code, it makes no references to iDCMBombRange, although it does make references to bDCMBombRange. Just wanted to let you know. The bombard icon only showed when I changed all iDCMBombRange references in the source code to bDCMBombRange.

    Either way, thanks. :)
     
  5. Dale

    Dale Chieftain

    Joined:
    Mar 14, 2002
    Messages:
    6,986
    Location:
    Melbourne
    Sorry mate. Forgot I hadn't uploaded the latest code with that change. :blush:

    Latest code uploaded with iDCMBombRange all correct. :)

    The mission event was a plain mistake. The reason for it will be clearer in the future. Original post fixed.

    Dale
     
  6. Dale

    Dale Chieftain

    Joined:
    Mar 14, 2002
    Messages:
    6,986
    Location:
    Melbourne
    Added missile (suicide units) code to first post.
     
  7. RogerBacon

    RogerBacon Chieftain

    Joined:
    Nov 16, 2003
    Messages:
    649
    Nice work on the missile. I had my own missile mod but it fougth a regular full combat before killing itself. It makes mre sense to die after one round of combat. I do have some questions though:

    Does a missile unit do it's normal one-round of combat damage if it wins the first round of combat, right? If it has collateral damage does it do that before it dies or is collateral damage done at the end of combat? If the missile loses the first round of combat it does no damage before dying, right? What about first strikes? If a missile has 2 first strikes does that mean it fights 3 combat rounds before dying?

    Roger Bacon
     
  8. Dale

    Dale Chieftain

    Joined:
    Mar 14, 2002
    Messages:
    6,986
    Location:
    Melbourne
    1. Yes, missile will do normal damage before impact.
    2. Collatoral damage is performed before the combat roll in combat, so yes, it will be processed.
    3. Correct, no damage will be done (but damage is done to the missile instead so with the right settings against it, it could be killed on that first combat round). This would require some good balancing though on the mod creators part.
    4. No, It will process one first strike (with a hit or a miss probability) and then die. The defending unit will not get a chance to hit the missile.

    I like the fact that the missile could do no damage. This simulates the high probability of missiles actually missing their target. Sure, modern day missiles have GPS and satellite guidence, but it's still not a 100% chance. Giving the missile unit first strike and a high combat value will counter this.

    So a V2 rocket (very unreliable world war 2 missile) would have a low combat strength and no first strikes, whereas a 2000AD+ cruise missile would have first strike plus a very high attack strength.

    Dale
     
  9. Dale

    Dale Chieftain

    Joined:
    Mar 14, 2002
    Messages:
    6,986
    Location:
    Melbourne
    MAD nukes SDK code uploaded. See the second post of this thread for details.

    Dale
     
  10. RogerBacon

    RogerBacon Chieftain

    Joined:
    Nov 16, 2003
    Messages:
    649
    While merging the missile code I noticed there was no change to CVUnit.h. Are you sure you uploaded the correct file? There is also no new variable in CVUnit to hold the bool missile value like there is for the bombardment code.

    Roger Bacon
     
  11. Caesium

    Caesium Radiant!

    Joined:
    Jan 14, 2006
    Messages:
    526
    Can I use your MAD Nukes together with TheLopez' nukes?
     
  12. Dale

    Dale Chieftain

    Joined:
    Mar 14, 2002
    Messages:
    6,986
    Location:
    Melbourne
    RogerBacon:

    The missile value is checked directly from CvUnitInfo not CvUnit.

    Caesium:

    Can't see why you couldn't.
     
  13. RogerBacon

    RogerBacon Chieftain

    Joined:
    Nov 16, 2003
    Messages:
    649
    Dale,

    I seem to be having a problem with the missiles. When I select a missile and choose to attack, I only see the targeting cursor on squares that have fog of war and I can never attack anything. Maybe I merged some of the code wrong. Can you tell me where in the code you check to see if a plot if a valid target?

    Thanks,
    Roger Bacon
     
  14. Dale

    Dale Chieftain

    Joined:
    Mar 14, 2002
    Messages:
    6,986
    Location:
    Melbourne
    Okay, the missile code can be a little grey around the edges here. The missile code uses the primary combat method of the unit in question.

    IE: If an air unit is designated a missile unit, then air combat (or air bomb combat) is used to determine validity. Thus, click on air bomb action, then air bomb whatever.

    IE2: If a land unit is designated a missile unit, then standard land combat is used to determine validity. Thus, "move" your unit onto the combat location like you would normally.

    Hope that clears it up. :) The actual missile code that you're thinking of is in CvSelctionGroup:: groupAttack and CvUnit::updateCombat.

    Dale

    PS: in other words, if having troubles with validity of an air unit missile (DOMAIN_AIR) then check in canAirBombAt and canAirStrikeAt.
     
  15. strategyonly

    strategyonly C2C Supreme Commander

    Joined:
    Mar 13, 2006
    Messages:
    19,752
    Gender:
    Male
    Location:
    MN
    Dang i have asked now for months how to get ranged bombardment from units on land, hope i understand how to do it correctly,:crazyeye: .
     
  16. Cheezy the Wiz

    Cheezy the Wiz Socialist In A Hurry

    Joined:
    Jul 18, 2005
    Messages:
    25,238
    Location:
    Freedonia
    haha, now revenge will be MINE! thanks for the cool MAD mod
     
  17. blacksam

    blacksam Chieftain

    Joined:
    Jun 17, 2006
    Messages:
    13
    Location:
    USA
    Hey nice code but when i added the MAD code, it let me target the nukes but on the next turn the nukes didnt appear targeted. in addition to that when i used python to force the other player into declaring war on me and nukeing me, instead of my nukes launching in retaliation, they didnt do anything and then the game crashed to desktop. did i compile wrong or what? could u send me an already compiled cvgamecore.dll with that in it?
     
  18. Jeckel

    Jeckel Great Reverend

    Joined:
    Nov 16, 2005
    Messages:
    1,637
    Location:
    Peoria, IL
    This all sounds pretty cool, especially the pretargeted nukes, but how about uploading some already-compiled versions for those without sdk skills.
     
  19. MaxRiga

    MaxRiga Chieftain

    Joined:
    Feb 1, 2004
    Messages:
    1,274
    Location:
    Riga/Montreal
    Dale, i'm noob in this, plz, asnwer me on this -

    absolutely don't get it :(((((

    don't get it too
    since i will get it i think i can try again, lol. hope u will answer on this and reexplain it easy language, lol
     
  20. Dale

    Dale Chieftain

    Joined:
    Mar 14, 2002
    Messages:
    6,986
    Location:
    Melbourne
    blacksam:

    I found a bug in the code listed above, so am working on v1.1 of the code. It fixes/enhances quite a bit of stuff.

    Jeckel:

    That could be done. I'll get it done soon.

    MaxRiga:

    Refer to this thread on how to install and use the SDK: http://forums.civfanatics.com/showthread.php?t=166933
     

Share This Page