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

[DLL] R.E.D. Combat

Discussion in 'Civ5 - Mod Components' started by Gedemon, Nov 8, 2012.

Thread Status:
Not open for further replies.
  1. Gedemon

    Gedemon Modder Moderator

    Joined:
    Oct 4, 2004
    Messages:
    9,271
    Location:
    France
    Compiled DLL for vanilla civ5 with combat events and functions.

    WARNING, This has not been updated after patch 1.0.3.18., it's not working with current version of the game and development has switched to Brave New World, so this mod is not supported anymore.

    See the R.E.D. DLL for BNW thread for the current version of the mod.


    Added in v.1:

    Spoiler :

    a new game event related to combats, GameEvents.CombatResult which gives the same variables in the same order as the old Events.RunCombatSim and Events.EndCombatSim and adds the following: iInterceptingPlayer, iInterceptingUnit, interceptorDamage, plotX, plotY.

    It fire before the combat is resolved.

    Example of Lua code:
    Code:
    function CombatResult (iAttackingPlayer, iAttackingUnit, attackerDamage, attackerFinalDamage, attackerMaxHP, iDefendingPlayer, iDefendingUnit, defenderDamage, defenderFinalDamage, defenderMaxHP, iInterceptingPlayer, iInterceptingUnit, interceptorDamage, plotX, plotY)
    
          -- your code here
    
    end
    GameEvents.CombatResult.Add( CombatResult )
    


    Added in v.2:

    Spoiler :
    - 2 Lua functions team:IsClosedBorder() and team:SetClosedBorder(bNewValue) to allow movement restriction to any unit on a civilization territory. R.E.D. WWII will use this to prevent entering neutral City States territory. When team:IsClosedBorder() return true, only civs with allied relation level can enter the CS territory.

    - Set GAMEOPTION_REBASE_IN_FRIENDLY_CITY to true to allows rebasing of aircraft in cities of civilization with which you share open borders. Include CS with allied relation level.

    - GameEvents.CombatEnded, same variables as GameEvents.CombatResult, fire after the combat is resolved. (may need to check if the defender is still alive there!)


    Added in v.3:

    Spoiler :

    - GameEvents.CanSendDiploStatement(iPlayer) that allows to prevent AI contact to the human player using the diplo screen.

    - define SUPPLY_PRODMOD_PER_UNIT used to calculate production penalty modifier per unit above the supply limit (was hardcoded at 10)

    - GameEvents.PlayerEndTurnInitiated(iPlayer) which is called when any player (human or AI) "ask" for end turn but before various reset functions are called (DoUnitReset, RespositionInvalidUnits, ...)and unitsGameEvents.PlayerEndTurnCompleted(iPlayer) which is called after those functions.

    - GameEvents.TurnComplete (iActivePlayer) called when a human player click "finish turn"

    - GameEvents.CanRangeStrikeAt(iPlayer, iUnit, x, y)

    - Balance embarked units combat by considering them DOMAIN_SEA (they were considered DOMAIN_LAND) and ignore all other bonus/penalties except a 100% bonus vs aircraft.

    - GameEvents.MustAbortAttack() with same parameters as GameEvents.CombatResult(), it's checked just before it and if true it will not resolve the planned combat. Be warned that it may have an influence on the Tactical AI, as it remove one of the planned attacking units of an objective. In R.E.D. it does so at such ratio that the unit should not have had a big impact anyway.

    - Make Embarked units double strength against air attack an option (GAMEOPTION_DOUBLE_EMBARKED_DEFENSE_AGAINST_AIR) to set via XML, SQL or Lua.

    SQL example:
    Code:
    INSERT INTO GameOptions (Type, "Default", Visible) VALUES ( 'GAMEOPTION_DOUBLE_EMBARKED_DEFENSE_AGAINST_AIR', 1, 0 );
    - GameEvents.PushingMissionTo(iPlayer, iUnit, x, y, iMission) and GameEvents.TacticalAILaunchUnitAttack(iPlayer, iUnit, x, y) to catch an attack just before it's launched. Used for "Supporting Fire" feature in R.E.D. WWII.

    - unit->isSpecialType(), unit->setIsSpecialType(bNewValue) to C++ and unit:IsSpecialType(), unit:SetIsSpecialType() to Lua. That allows a specific unit to stack with unit of same type (but not others "special type" units)

    - Hack to allow loading of WB maps with more than 255 unit types.

    - Crash fix: On move through, don't allow embarked special units to stack, and prevent AI sea units to stack with embarked units to prevent a crash occurring during auto-mission.


    Added in v.4:

    Spoiler :

    - Add unit->IsMarkedBestDefender(), unit->SetMarkedBestDefender( bNewValue ) to DLL and unit:IsMarkedBestDefender(), unit:SetMarkedBestDefender( bNewValue ) to Lua. It will override the game logic when choosing the best defender on a plot, used in R.E.D. WWII to temporary set an unit as the target of an attack (or counter-attack) even if there are better defending units on that plot.

    - Add "GAMEOPTION_CAN_ENTER_FOREIGN_CITY" and "GAMEOPTION_CAN_STACK_IN_CITY" to allow all unit types in foreign cities (must have allied level for minor civilizations cities) and multiple units of same type in one city.

    - Add "GAMEOPTION_NO_MINOR_DIPLO_SPAM" to prevent minor civilizations to send help request messages (and when the option is set to ON, it fixes an unresolved crash in R.E.D. WWII related to those messages...)

    - Add "GAMEOPTION_FREE_PLOTS" to prevent tiles from changing ownership on cities capture.

    v4.1:
    - Add "GAMEOPTION_UNIT_LIMIT_FIX" to trigger the hack to allow loading of WB maps with more than 255 unit types. (better to be an option...)



    Code source on Git-Hub (RED branch).


    Installation when using vanilla civ5:

    Download link
    Extract and replace CvGameCoreDLLFinal Release.dll in civ5 installation directory.
    Remember to make a backup first.


    Inclusion in a Mod for G+K:
    Just put the G+K DLL (CvGameCore_Expansion1.dll) in the root of your project in modbuddy and set that file VFS property to true.
     
  2. ww2commander

    ww2commander Emperor

    Joined:
    Aug 23, 2003
    Messages:
    1,243
    Location:
    Australia
    Sorry to ask an off topic question, but can this only be achieved through changing the DLL or is it something that can also be done via lua?

    I always thought rebasing in other civ cities was not possible (never got an opportunity to try it!).

    On topic - Is a G&K version likely?
     
  3. [to_xp]Gekko

    [to_xp]Gekko QCT junkie

    Joined:
    Dec 16, 2005
    Messages:
    7,943
    Location:
    Seyda Neen, Vvardenfell
    Spatzimaus I summon thee!
     
  4. Gorhaax

    Gorhaax Warlord

    Joined:
    Jul 30, 2011
    Messages:
    192
    What exactly are the GameEvents code for? Kind of confusing
     
  5. Gedemon

    Gedemon Modder Moderator

    Joined:
    Oct 4, 2004
    Messages:
    9,271
    Location:
    France
    There were 2 game events related to combat in the game before patch .674 that were used by some mods to add/control some features using Lua.

    Those 2 game events had completely changed their behavior with patch .674, before they were giving feedback before and after combat, and after the patch they were both fired after, and sometimes not at all.

    This had broken some mods pretty badly.

    The DLL add new game events to replace the previous one, even adding some more info (like attacked plot) that was not available. As it give the same first variables in the same order, it can directly replace the old events in the code of a mod.

    And a G&K version will be made, yes.
     
  6. Gedemon

    Gedemon Modder Moderator

    Joined:
    Oct 4, 2004
    Messages:
    9,271
    Location:
    France
    New version for R.E.D. WWII Edition v.32.

    You'll only have to download it separately of R.E.D. WWII Edition v.32 if you're not using G&K, it's automatically loaded when you have the extension. Note that anyway it's still based on vanilla code source, not G&K.

    It can be used alone with vanilla civ5.

    A full G&K version is planned when I got the time to patch it.

    Added in v.3:

    Spoiler :

    - GameEvents.CanSendDiploStatement(iPlayer) that allows to prevent AI contact to the human player using the diplo screen.

    - define SUPPLY_PRODMOD_PER_UNIT used to calculate production penalty modifier per unit above the supply limit (was hardcoded at 10)

    - GameEvents.PlayerEndTurnInitiated(iPlayer) which is called after end turn is pressed but before various reset functions are called (DoUnitReset, RespositionInvalidUnits, ...)and unitsGameEvents.PlayerEndTurnCompleted(iPlayer) which is called after those functions.

    - GameEvents.TurnComplete (iActivePlayer) called when the human player click "finish turn"

    - GameEvents.CanRangeStrikeAt(iPlayer, iUnit, x, y)

    - Balance embarked units combat by considering them DOMAIN_SEA (they were considered DOMAIN_LAND) and ignore all other bonus/penalties except a 100% bonus vs aircraft.

    - GameEvents.MustAbortAttack() with same parameters as GameEvents.CombatResult(), it's checked just before it and if true it will not resolve the planned combat. Be warned that it may have an influence on the Tactical AI, as it remove one of the planned attacking units of an objective. In R.E.D. it does so at such ratio that the unit should not have had a big impact anyway.

    - Make Embarked units double strength against air attack an option (GAMEOPTION_DOUBLE_EMBARKED_DEFENSE_AGAINST_AIR) to set via XML, SQL or Lua.

    SQL example:
    Code:
    INSERT INTO GameOptions (Type, "Default", Visible) VALUES ( 'GAMEOPTION_DOUBLE_EMBARKED_DEFENSE_AGAINST_AIR', 1, 0 );
    - GameEvents.PushingMissionTo(iPlayer, iUnit, x, y, iMission) and GameEvents.TacticalAILaunchUnitAttack(iPlayer, iUnit, x, y) to catch an attack just before it's launched. Used for "Supporting Fire" feature in R.E.D. WWII.

    - unit->isSpecialType(), unit->setIsSpecialType(bNewValue) to C++ and unit:IsSpecialType(), unit:SetIsSpecialType() to Lua. That allows a specific unit to stack with unit of same type (but not others "special type" units)

    - Hack to allow loading of WB maps with more than 255 unit types.

    - Crash fix: On move through, don't allow embarked special units to stack, and prevent AI sea units to stack with embarked units to prevent a crash occurring during auto-mission.


    Installation:

    Download link
    Extract and replace CvGameCoreDLLFinal Release.dll in civ5 installation directory.
    Remember to make a backup first.
    Source on Git-Hub.
     
  7. ww2commander

    ww2commander Emperor

    Joined:
    Aug 23, 2003
    Messages:
    1,243
    Location:
    Australia
    Thank you Gedemon very much for providing those useful functions in v3. A few questions:

    1. Is there any way to include this as a part of my mod without having player replace original dll files as per instructions?

    2. Do the end turn functions run consistently for all players in both normal and strategic map view or are they troublesome like some of the serial event functions?
     
  8. Gedemon

    Gedemon Modder Moderator

    Joined:
    Oct 4, 2004
    Messages:
    9,271
    Location:
    France
    1/ yes, I "just" have to convert the code to G+K DLL. But it's a "just" that may be time consuming so I won't give an ETA. Your mod is based on G+K or vanilla ?

    2/ from my tests they all seem to fire correctly even when using strategic view or quick combat.
     
  9. ww2commander

    ww2commander Emperor

    Joined:
    Aug 23, 2003
    Messages:
    1,243
    Location:
    Australia
    Good good on answer to both questions.

    I only mod in G&K.
     
  10. Gedemon

    Gedemon Modder Moderator

    Joined:
    Oct 4, 2004
    Messages:
    9,271
    Location:
    France
    v4 for vanilla uploaded.

    G+K version and update on GitHub when I'll be back from Christmas next week.
     
  11. Gedemon

    Gedemon Modder Moderator

    Joined:
    Oct 4, 2004
    Messages:
    9,271
    Location:
    France
    G+K version uploaded, code updated on GitHub.
     
  12. ww2commander

    ww2commander Emperor

    Joined:
    Aug 23, 2003
    Messages:
    1,243
    Location:
    Australia
    Gedemon, did you happen to check into that slow down when switching between units I reported via PM?
     
  13. Gedemon

    Gedemon Modder Moderator

    Joined:
    Oct 4, 2004
    Messages:
    9,271
    Location:
    France
    didn't notice it in my (quick) test in G+K. Doesn't happens with vanilla version on my mod (just finished a 200+ turn games with hundreds of units near the end.

    I must find time to try your version to check G+K with lots of units but I will do, I just can't say "when".
     
  14. Pazyryk

    Pazyryk Deity

    Joined:
    Jun 13, 2008
    Messages:
    3,584
    @Gedemon,

    A lot of this functionality would be extremely helpful in Éa. I still haven't decided whether to add your G&K dll to my mod or to make the jump into C++ coding myself (mostly inertia stopping me). Either way, I can profit from looking at your code in Git and understanding how it works.

    Some questions for now:

    If I understand correctly, the unlimited stacking is based on the Special tag in units (e.g., SPECIALUNIT_PEOPLE)? Am I out of luck if I want to allow all civilian units to stack with all other civilians? (Well, I guess I could make workers into SPECIALUNIT_PEOPLE, --Do you know if there would be any ill effects from that other than returning true for unit:IsGreatPerson()? )

    On entering foreign cities: Is this CS only or CS and major civ? And if I understand correctly, you have to be Allied (for CS) or have open borders (for major civ)?

    Just to spell out my dll needs explicitly (not that I expect you to mod for me, but maybe comment):
    1. [need] All GPs can violate 1upt, stack with any other units (even an enemy), and enter any city regardless of diplo status. Eventually I'll need event checks for the 3rd item and maybe the 2nd (if stacked with another civ's unit).
    2. [need] "Real invisibility" (for GPs). By that I mean that another civ just won't see it ... ever. If another unit happens to move onto an invisible unit, so be it. (I guess if the invisible unit is a military unit then one of the two will get forcefully moved at turn end [from my own experimentation]. But my item #1 gets me around this for GPs.)
    3. [want] All civilians ignore all stacking and can pass through all other units (except enemy unit). This is just an annoyance issue for me. I don't like having to go off-road to drive my worker around a foreign unit in my own territory. And there is no logical reason in my mod for workers to exclude a GP from a plot.

      (I've actually kludged #1 and 2 via Lua: GPs teleport into cities and disappear and reappear between turns. It's very ugly.)
     
  15. Gedemon

    Gedemon Modder Moderator

    Joined:
    Oct 4, 2004
    Messages:
    9,271
    Location:
    France
    The stacking here for "special" units is not unlimited, it's still 1UPT, with another "class" of units. It's not based on the "special unit" tag from base game (I've only seen after that the naming could be misleading there) and use a Lua function to mark the unit as "special" for the stacking rule.

    About entering foreign cities, it's open border for major and allied level for minor (allied level means the number of relation point needed to be allied, you can enter a CS city that is officially allied with someone else than you, because you're not the one with the most relation points, if you have reached the allied threshold.)

    about the rest:

    1: may be tricky because of 3
    2: no idea if it can be done
    3: would like that too, that must be somewhere in the path finding, but no luck so far.
     
  16. Blue Freaze

    Blue Freaze Chieftain

    Joined:
    Mar 3, 2013
    Messages:
    1
    Location:
    Minnesota
    Ok, so I don't have the Gods and Kings version so I'm having some issues, I've downloaded the R.E.D. dll but I can't figure out how to find the downloaded file, or the original civ. file. So basicly what I need to know is:

    1) What is the R.E.D. dll file name?

    2) What is the original civ. file name?

    Thanks
    Also I have Windows 8 if that means anything
     
  17. flyinghorse301

    flyinghorse301 Chieftain

    Joined:
    Nov 26, 2011
    Messages:
    20
    Hi Gedemon,

    I has problem with the CombatResult function in the DLL file. I downloaded the DLL from http://forums.civfanatics.com/downloads.php?do=file&id=20340. VFS= true. I tested a few functions: CombatResult, CombatEnded, TurnComplete... All functions work except the CombatResult. Below is my Lua:

    Code:
    function CombatResult (iAttackingPlayer, iAttackingUnit, attackerDamage, attackerFinalDamage, attackerMaxHP, iDefendingPlayer, iDefendingUnit, defenderDamage, defenderFinalDamage, defenderMaxHP, iInterceptingPlayer, iInterceptingUnit, interceptorDamage, plotX, plotY)
    	print("CombatResult")
    end
    GameEvents.CombatResult.Add( CombatResult )
    
    function Test (iActivePlayer)
    	print("ok")
    end
    GameEvents.TurnComplete.Add( Test )
    
    function CombatEnded (iAttackingPlayer, iAttackingUnit, attackerDamage, attackerFinalDamage, attackerMaxHP, iDefendingPlayer, iDefendingUnit, defenderDamage, defenderFinalDamage, defenderMaxHP, iInterceptingPlayer, iInterceptingUnit, interceptorDamage, plotX, plotY)
    	print("CombatEnded")
    end
    GameEvents.CombatEnded.Add( CombatEnded )
    Then I tried to run your R.E.D World War mode, the CombatResult works fine in your mode.
    I tried to use the CvGameCore_Expansion1.dll from your mod, but this time I can NOT start the game, many runtime errors are detected.

    Could you help me on this? Thank you.
     
  18. Gedemon

    Gedemon Modder Moderator

    Joined:
    Oct 4, 2004
    Messages:
    9,271
    Location:
    France
    Ho, yes, sorry, now I remember that whoward69 had warned me about that bug in my code.

    I'll fix that in next version of the DLL, for now you can fix the issue by also hooking to the MustAbortAttack event in your mod with a simple function returning false

    Code:
    function MustAbortAttack ()
    	return false
    end
    GameEvents.MustAbortAttack.Add( MustAbortAttack )
    
     
  19. flyinghorse301

    flyinghorse301 Chieftain

    Joined:
    Nov 26, 2011
    Messages:
    20
    Hi Gedemon,

    Thank you. I want to use your DLL to make the missile interception. Something like:

    Code:
    local intercept = false
    if ( aName == "UNIT_GUIDED_MISSILE" ) then
    	local Mchance = 20;
    	local diceroll = Map.Rand(100, "Missile Interception chance");
    	if ( diceroll < Mchance ) then
    		intercept = true;
    		aUnit:Kill();
    		Players[p]:AddNotification(NotificationTypes.NOTIFICATION_UNIT_DIED, "Missile was intercepted !!!", "Missile Interception", -1, -1, iAttackingUnit, -1);
    	end
    end
    if intercept == false then
    	return false
    else
    	return true
    end
    but I can't make it, the game crash when the missile is killed. How can I make it work :confused:

    Also, I found a bug. When perform a ranged attack, the "Approx DMG Inflicted" always gives 0.(see attachment)
     

    Attached Files:

    • bug.jpg
      bug.jpg
      File size:
      61.2 KB
      Views:
      78
  20. Gedemon

    Gedemon Modder Moderator

    Joined:
    Oct 4, 2004
    Messages:
    9,271
    Location:
    France
    Use GameEvents.MustAbortAttack in that case, it has the same parameters as GameEvents.CombatResult, but I think you should be able to kill the attacking unit without the game crashing at this moment.

    make your function return "true" if the attacking unit is dead.

    (the attack animation is played, but the damage are not given)
     
Thread Status:
Not open for further replies.

Share This Page