Allowing Naval Melee Unit To Range Attack

Laurana Kanan

Don’t underestimate who I am.
Moderator
Joined
Apr 10, 2014
Messages
4,405
Location
Near the Greatest Snow on Earth
In @Wolfdog 's Expanded Warfare mod there is a Missile Destroyer upgrade to the Vanilla Destroyer unit. Unfortunately, since it's a Naval Melee unit you can't execute long range attacks. It has to pull alongside it's opponent to attack. It's easy enough to give it a ranged attack, but that creates other issues.

The problem is if you give it a ranged attack and it's ranged strength is higher than it's melee strength, the game treats it as a ranged unit and you lose the ability to capture cities, but you can still range attack land units, cities, and naval units. Conversely, if it's melee strength is higher than it's ranged strength, the game treats it as a melee unit, but you still lose the ability to capture cities. You'll also be unable to range attack land units, though you can still range attack cities and naval units.

I found, however, that in the second scenario where the melee attack is higher, simply attaching the "CLASS_IMMORTAL" tag to the unit will again grant the ability to capture cities and still be able to execute ranged attacks against other naval units and cities themselves. However, it's still unable to range attack land units. This is mirrored by the Persian Immortal's inability to range attack naval units.

I was mostly satisfied with this solution as it seemed to work well enough - except for the land unit attacks, but still wanted to ask if anyone might have an idea for a work-a-round to accomplish this.
 
The only thing I can think of is to create your own custom unit ability like CLASS_MISSILE_DESTROYER and see how that goes. It is quite painful creating custom abilities but I think it will work.
 
The only thing I can think of is to create your own custom unit ability like CLASS_MISSILE_DESTROYER and see how that goes. It is quite painful creating custom abilities but I think it will work.
Thanks for the response, Wolfdog. That was my initial solution as well, but I'm stuck on how to actually allow the attack. Here's my code so far:
Spoiler :
Code:
INSERT INTO Types
            (Type,                            Kind)
VALUES
            ('ABILITY_MISSILE_DESTROYER',    'KIND_ABILITY');
           
INSERT INTO Tags      
            (Tag,                        Vocabulary)
VALUES      
            ('CLASS_MISSILE_DESTROYER',    'ABILITY_CLASS');

INSERT INTO TypeTags  
            (Type,                            Tag)
VALUES
            ('UNIT_MISSILE_DESTROYER',        'CLASS_MISSILE_DESTROYER'),
            ('ABILITY_MISSILE_DESTROYER',    'CLASS_MISSILE_DESTROYER'),
            ('ABILITY_IMMORTAL',            'CLASS_MISSILE_DESTROYER');

INSERT INTO UnitAbilities
            (UnitAbilityType,                Name,                        Description)
VALUES      
            ('ABILITY_MISSILE_DESTROYER',    'LOC_ABILITY_MISSILE_DESTROYER_NAME',    'LOC_ABILITY_MISSILE_DESTROYER_DESCRIPTION');

INSERT INTO UnitAbilityModifiers  
            (UnitAbilityType,                ModifierId)
VALUES  
            ('ABILITY_MISSILE_DESTROYER',    'MISSILE_DESTROYER_RANGED_ATTACK_BONUS');
           
INSERT INTO Modifiers  
            (ModifierId,                                ModifierType,                            SubjectRequirementSetId)
VALUES      
            ('MISSILE_DESTROYER_RANGED_ATTACK_BONUS',    'MODIFIER_UNIT_ADJUST_COMBAT_STRENGTH',    'MISSILE_DESTROYER_RANGED_ATTACK_BONUS_REQUIREMENTS');  
   
INSERT INTO ModifierArguments
            (ModifierId,                                Name,                Value)
VALUES      
            ('MISSILE_DESTROYER_RANGED_ATTACK_BONUS',    'OperationType',    'UNITOPERATION_RANGE_ATTACK'),
            ('MISSILE_DESTROYER_RANGED_ATTACK_BONUS',    'Amount',            30);

INSERT INTO RequirementSets
            (RequirementSetId,                                        RequirementSetType)
VALUES      
            ('MISSILE_DESTROYER_RANGED_ATTACK_BONUS_REQUIREMENTS',    'REQUIREMENTSET_TEST_ALL');

INSERT INTO RequirementSetRequirements
            (RequirementSetId,                                        RequirementId)
VALUES      
            ('MISSILE_DESTROYER_RANGED_ATTACK_BONUS_REQUIREMENTS',    'OPPONENT_IS_LAND_UNIT_REQUIREMENTS'),
            ('MISSILE_DESTROYER_RANGED_ATTACK_BONUS_REQUIREMENTS',    'PLAYER_IS_ATTACKER_REQUIREMENTS');
           
INSERT INTO ModifierStrings
            (ModifierId,                                Context,        Text)
VALUES      
            ('MISSILE_DESTROYER_RANGED_ATTACK_BONUS',    'Preview',    'LOC_ABILITY_MISSILE_DESTROYER_RANGED_ATTACK_BONUS_MODIFIER_DESC');
So right now as just test numbers, I have the Melee Attack set to 95 and the Ranged Attack to 80. I've assigned the "ABILITY_IMMORTAL" to "CLASS_MISSILE_DESTROYER". So the game considers this a Melee unit and allows it to Melee Attack ships and cities along with capturing cities. Also, it is allowed to Range Attack ships and cities.

I thought if I could get the Ranged Attack to be higher than the Melee Attack and set requirements for the opponent to be a land unit, the game would then think it was a Ranged unit and allow a Ranged Attack on the land unit. Unfortunately, that only partially works as I can hover over a land unit and the combat preview successfully shows the Ranged Attack plus the modified amount. So in this case 110 (+30 modifier). However, it won't actually allow the attack. So I'm at a loss as to what I'm missing. If @LeeS or @Gedemon or someone else could at least tell me if this is even possible or it I'm just :wallbash:, I'd appreciate the advice.
 
Top Bottom