How do i make an unit that can do both melee and ranged attacks?

ScoopJohn

Chieftain
Joined
Oct 30, 2015
Messages
47
Hi guys, i was wondering if you can make a unique unit that can also do a melee attack alongside a ranged attack, i'm doing a Crossbowman unique unit that removes the no-melee attack restriction, is this possible?
 
There was a thread that was started before:
http://forums.civfanatics.com/showthread.php?t=534641

But as I tested it out for my own unit by myself, removing the PROMOTION_ONLY_DEFENSIVE still does not allow the unit to melee attack. So you probably have to rely on Game Scripts (if it works).
 
Removing PROMOTION_ONLY_DEFENSIVE will allow the unit to make both mellee and ranged attacks, BUT it will always use the ranged one by default, so the AI will never mellee with it. The only time the unit will mellee attack is if the player clicks "move" on the unit action panel before clicking on the enemy.

Another option would be to give your unit the Zulu Impi promotion, so it always does both ranged and mellee with every attack.
 
Removing PROMOTION_ONLY_DEFENSIVE will allow the unit to make both mellee and ranged attacks, BUT it will always use the ranged one by default, so the AI will never mellee with it. The only time the unit will mellee attack is if the player clicks "move" on the unit action panel before clicking on the enemy.

Another option would be to give your unit the Zulu Impi promotion, so it always does both ranged and mellee with every attack.

And that might be the <RangedSupportFire> tag, is that right?
 
Removing PROMOTION_ONLY_DEFENSIVE will allow the unit to make both mellee and ranged attacks, BUT it will always use the ranged one by default, so the AI will never mellee with it. The only time the unit will mellee attack is if the player clicks "move" on the unit action panel before clicking on the enemy.

Another option would be to give your unit the Zulu Impi promotion, so it always does both ranged and mellee with every attack.

Wow, I didn't know you actually have to "move" your unit into the enemy to get this working. I always tried pressing [A] for the Melee attack, but it always cancels the action.

EDIT: Still doesn't work, as I tested and Kaspergm replied before.
 
Removing PROMOTION_ONLY_DEFENSIVE will allow the unit to make both mellee and ranged attacks, BUT it will always use the ranged one by default, so the AI will never mellee with it. The only time the unit will mellee attack is if the player clicks "move" on the unit action panel before clicking on the enemy.
Sadly, this does not seem to work. I tried this very thing literally just two days ago with doing some changes to naval units, and while removing the PROMOTION_ONLY_DEFENSIVE does make an "attack" option come up over the ranged attack option in the unit action menu, but clicking this option does not give you any possible targets, even when adjacent to the target unit, and also moving to the occupied target is not an option.

In case anybody are willing to try to check my code for errors, here's what I did. This DID make the Trireme become ranged, but like I said, melee attacking did not work.

Spoiler :
Code:
<GameData>
	<Units>
		<Delete Type="UNIT_TRIREME"/>
		<Row>
			<Class>UNITCLASS_TRIREME</Class>
			<Type>UNIT_TRIREME</Type>
			<PrereqTech>TECH_SAILING</PrereqTech>
			<Combat>10</Combat>
			<RangedCombat>8</RangedCombat>
			<Cost>45</Cost>
			<Moves>4</Moves>
			<Range>1</Range>
			<CombatClass>UNITCOMBAT_NAVALRANGED</CombatClass>
			<Domain>DOMAIN_SEA</Domain>
			<DefaultUnitAI>UNITAI_ASSAULT_SEA</DefaultUnitAI>
			<Description>TXT_KEY_UNIT_TRIREME</Description>
			<Civilopedia>TXT_KEY_CIV5_ANTIQUITY_TRIREME_TEXT</Civilopedia>
			<Strategy>TXT_KEY_UNIT_TRIREME_STRATEGY</Strategy>
			<Help>TXT_KEY_UNIT_HELP_TRIREME</Help>
			<MilitarySupport>true</MilitarySupport>
			<MilitaryProduction>true</MilitaryProduction>
			<Pillage>true</Pillage>
			<Mechanized>true</Mechanized>
			<ObsoleteTech>TECH_KEEL</ObsoleteTech>
			<AdvancedStartCost>30</AdvancedStartCost>
			<MinAreaSize>10</MinAreaSize>
			<XPValueAttack>3</XPValueAttack>
			<XPValueDefense>3</XPValueDefense>
			<UnitArtInfo>ART_DEF_UNIT_TRIREME</UnitArtInfo>
			<UnitFlagIconOffset>24</UnitFlagIconOffset>
			<IconAtlas>UNIT_ATLAS_1</IconAtlas>
			<PortraitIndex>24</PortraitIndex>
			<MoveRate>WOODEN_BOAT</MoveRate>
		</Row>
	</Units>
	<Unit_AITypes>
		<Delete UnitType="UNIT_TRIREME"/>
		<Row>
			<UnitType>UNIT_TRIREME</UnitType>
			<UnitAIType>UNITAI_ASSAULT_SEA</UnitAIType>
		</Row>
		<Row>
			<UnitType>UNIT_TRIREME</UnitType>
			<UnitAIType>UNITAI_ATTACK_SEA</UnitAIType>
		</Row>
		<Row>
			<UnitType>UNIT_TRIREME</UnitType>
			<UnitAIType>UNITAI_RESERVE_SEA</UnitAIType>
		</Row>
		<Row>
			<UnitType>UNIT_TRIREME</UnitType>
			<UnitAIType>UNITAI_ESCORT_SEA</UnitAIType>
		</Row>
		<Row>
			<UnitType>UNIT_TRIREME</UnitType>
			<UnitAIType>UNITAI_EXPLORE_SEA</UnitAIType>
		</Row>
	</Unit_AITypes>
	<Unit_ClassUpgrades>
		<Delete UnitType="UNIT_TRIREME"/>
		<Row>
			<UnitType>UNIT_TRIREME</UnitType>
			<UnitClassType>UNITCLASS_GALLEASS</UnitClassType>
		</Row>
	</Unit_ClassUpgrades>
	<Unit_FreePromotions>
		<Delete UnitType="UNIT_TRIREME"/>
		<Row>
			<UnitType>UNIT_TRIREME</UnitType>
			<PromotionType>PROMOTION_OCEAN_IMPASSABLE</PromotionType>
		</Row>
	</Unit_FreePromotions>
</GameData>
 
I was having a look at LaBrie mod "advanced naval units" as I use it sometimes and I was curious as he has a corvette the has both melee and ranged attacks
here's part of the code if it's of any use for cross referencing purposes

Spoiler :
Code:
  <Units>
    <Row>
      <Type>UNIT_FLOWER_CLASS_CORVETTE888</Type>
      <Description>TXT_KEY_UNIT_FLOWER_CLASS_CORVETTE888</Description>
      <CombatClass>UNITCOMBAT_NAVALRANGED</CombatClass>
      <Domain>DOMAIN_SEA</Domain>
      <Class>UNITCLASS_FLOWER888</Class>
      <Cost>350</Cost>
      <AdvancedStartCost>54</AdvancedStartCost>
      <Combat>50</Combat>
      <RangedCombat>60</RangedCombat>
      <Range>2</Range>
      <IgnoreBuildingDefense>true</IgnoreBuildingDefense>
      <Moves>6</Moves>
      <AirInterceptRange>2</AirInterceptRange>
      <Strategy>TXT_KEY_UNIT_FLOWER_CLASS_CORVETTE888_STRATEGY</Strategy>
      <Help>TXT_KEY_UNIT_FLOWER_CLASS_CORVETTE888_HELP</Help>
      <Civilopedia>TXT_KEY_UNIT_FLOWER_CLASS_CORVETTE888_PEDIA</Civilopedia>
      <PrereqTech>TECH_BALLISTICS</PrereqTech>
      <Pillage>true</Pillage>
      <MoveRate>BOAT</MoveRate>
      <Mechanized>true</Mechanized>
      <UnitArtInfo>ART_DEF_UNIT_FLOWER_CLASS_CORVETTE888</UnitArtInfo>
      <IconAtlas>ATLAS_ICON_UNIT_FLOWER_CLASS_CORVETTE888</IconAtlas>
      <PortraitIndex>0</PortraitIndex>
      <UnitFlagAtlas>UNIT_FLAG_ATLAS</UnitFlagAtlas>
      <UnitFlagIconOffset>67</UnitFlagIconOffset>
      <RangedCombatLimit>100</RangedCombatLimit>
      <MinAreaSize>10</MinAreaSize>
      <MilitaryProduction>true</MilitaryProduction>
      <XPValueAttack>4</XPValueAttack>
      <XPValueDefense>4</XPValueDefense>
      <MilitarySupport>true</MilitarySupport>
      <DefaultUnitAI>UNITAI_ASSAULT_SEA</DefaultUnitAI>
    </Row>
  </Units>
  <Unit_AITypes>
    <Row>
      <UnitType>UNIT_FLOWER_CLASS_CORVETTE888</UnitType>
      <UnitAIType>UNITAI_ASSAULT_SEA</UnitAIType>
    </Row>
    <Row>
      <UnitType>UNIT_FLOWER_CLASS_CORVETTE888</UnitType>
      <UnitAIType>UNITAI_RESERVE_SEA</UnitAIType>
    </Row>
    <Row>
      <UnitType>UNIT_FLOWER_CLASS_CORVETTE888</UnitType>
      <UnitAIType>UNITAI_ESCORT_SEA</UnitAIType>
    </Row>
    </Unit_AITypes>
  <Unit_Flavors>
    <Row>
      <UnitType>UNIT_FLOWER_CLASS_CORVETTE888</UnitType>
      <FlavorType>FLAVOR_NAVAL</FlavorType>
      <Flavor>18</Flavor>
    </Row>
    <Row>
      <UnitType>UNIT_FLOWER_CLASS_CORVETTE888</UnitType>
      <FlavorType>FLAVOR_NAVAL_RECON</FlavorType>
      <Flavor>5</Flavor>
    </Row>
    </Unit_Flavors>
  <Unit_FreePromotions>
    <Row>
      <UnitType>UNIT_FLOWER_CLASS_CORVETTE888</UnitType>
      <PromotionType>PROMOTION_ANTI_SUBMARINE_I</PromotionType>
    </Row>
    <Row>
      <UnitType>UNIT_FLOWER_CLASS_CORVETTE888</UnitType>
      <PromotionType>PROMOTION_CAN_MOVE_AFTER_ATTACKING</PromotionType>
    </Row>
    <Row>
      <UnitType>UNIT_FLOWER_CLASS_CORVETTE888</UnitType>
      <PromotionType>PROMOTION_SEE_INVISIBLE_SUBMARINE</PromotionType>
    </Row>
    <Row>
      <UnitType>UNIT_FLOWER_CLASS_CORVETTE888</UnitType>
      <PromotionType>PROMOTION_STRONGER_VS_DAMAGED</PromotionType>
    </Row>
    <Row>
      <UnitType>UNIT_FLOWER_CLASS_CORVETTE888</UnitType>
      <PromotionType>PROMOTION_STEAM_POWERED</PromotionType>
    </Row>
	  <Row>
		  <UnitType>UNIT_FLOWER_CLASS_CORVETTE888</UnitType>
		  <PromotionType>PROMOTION_TARGETING_1</PromotionType>
	  </Row>
    <Row>
      <UnitType>UNIT_FLOWER_CLASS_CORVETTE888</UnitType>
      <PromotionType>PROMOTION_INTERCEPTION_II</PromotionType>
    </Row>
	  <Row>
		  <UnitType>UNIT_FLOWER_CLASS_CORVETTE888</UnitType>
		  <PromotionType>PROMOTION_CARGO_II</PromotionType>
	  </Row>
  </Unit_FreePromotions>
 
Thanx ... seems identical to what I did in terms of what I would immediately assume had any relevance in this case (CombatClass, DefaultUnitAI). :confused:
 
Just done a quick test of my own with the following code:

Code:
<GameData>
	<Unit_FreePromotions>
		<Delete UnitType="UNIT_ARCHER" PromotionType="PROMOTION_ONLY_DEFENSIVE"/>
	</Unit_FreePromotions>
</GameData>
and it worked perfectly. Screenshots attached.

The archer no longer has PROMOTION_ONLY_DEFENSIVE.
When clicking the Ranged Attack button: all enemies within 2 hexes are highlighted and can be hit with a ranged attack, as per usual for archers.
When clicking the Attack button instead: only adjacent enemies are highlighted, and can be hit with a melee attack which causes the archer to enter the enemy's hex when it kills one.

Not sure why the same didn't work for other people :confused:. In case it's relevant, I have both Gods & Kings and Brave New World, and have no other mods running.
 

Attachments

  • ArcherTestMelee.jpg
    ArcherTestMelee.jpg
    344 KB · Views: 130
  • ArcherTestRanged.jpg
    ArcherTestRanged.jpg
    345.7 KB · Views: 81
Interesting, thanx for testing this. Can you try to test it for naval units also, if not too much trouble? Just to see if this is a special case for naval units?

Either way, it may be a mod conflict. I'm using the CP, so maybe there are some changes in the .dll that somehow interferes with this? I guess that's worth looking into if it works also for naval units for you.
 
Sure, just tried removing the promotion from all units in the game:
Code:
<GameData>
	<Unit_FreePromotions>
		<Delete PromotionType="PROMOTION_ONLY_DEFENSIVE"/>
	</Unit_FreePromotions>
</GameData>
and it works the same for naval units as for land units (tested: gallilass, battleship, ironclad, submarine, crossbowman, bazooka, artillery, catapult, trebuchet). Siege units that must set up before a ranged attack can use their melee attack without setting up.

It could well be the Community Patch that's stopping this working for you. I've never used that mod, so am not familliar with exactly what it does, but if it's changing the dll or the unit panel lua then it's quite possible that it's interfering with this behaviour.

As I said before, this is not an ideal solution since the AI won't use it (AI will always use ranged attacks if the unit is capable of it), but if you don't care about that then it's an option. (... unless you're using the CP, apparently).
 
Thanx for the effort in testing this. I might look into if this is a CP thing or something else not making it work for me.
 
Back
Top Bottom