Jump to content

Attack/RestrictedClasses: Prevent ranged units from attacking Fields.


Recommended Posts

Does anyone know a quick way to restrict ranged units from attacking fields?

The template_unit_dog shows that such things can be done, but I wouldn't want to update every single template.

 

Also, I would like to ban Archers/Javelineers from attacking completed structures with their ranged attack. Attacking uncompleted structures is something I would consider a gamplay mechanic. But banning Archers/Javelineers from attacking completed only structures with their ranged attack, would seem tedious. Any suggestions if that can be done in an efficient way?

Link to comment
Share on other sites

19 minutes ago, Atrik said:

The unit template is not suitable: It seems to mess with units that don't have a ranged attack (healers, fishing ships&trades escpecially)

I could edit many parent templates, but that is not what I was looking for.

Link to comment
Share on other sites

@Stan` Any suggestion on modding the Attack.js script?

I tried the code below, but it did not work. I suppose the code does not return the "Field" string/token/whatever correctly

 

Attack.prototype.GetRestrictedClasses = function(type)
{
    if (this.template[type] && this.template[type].RestrictedClasses &&
        this.template[type].RestrictedClasses._string)
        { let max = +this.template[type].MaxRange;
        if ( max > 55 ) {
        return ["Field"];}
        else
         {return this.template[type].RestrictedClasses._string.split(/\s+/);}}
    return [];
};

 

Link to comment
Share on other sites

DE does this in the templates and prevents units from attacking the Shrine and Merc Camp map objects.

 

In template_unit_cavalry_melee.xml


  <Attack>
    <Melee>
      <AttackName>Knife</AttackName>
      <Damage>
        <Hack>8.0</Hack>
        <Pierce>0.0</Pierce>
        <Crush>0.0</Crush>
      </Damage>
      <MaxRange>6.0</MaxRange>
      <PrepareTime>500</PrepareTime>
      <RepeatTime>1000</RepeatTime>
      <Bonuses>
        <ElephantStench>
          <Classes>Elephant</Classes>
          <Multiplier>0.5</Multiplier>
        </ElephantStench>
        <CamelStench>
          <Classes>Camel</Classes>
          <Multiplier>0.5</Multiplier>
        </CamelStench>
        <BonusSiege>
          <Classes>Siege</Classes>
          <Multiplier>2.0</Multiplier>
        </BonusSiege>
      </Bonuses>
      <PreferredClasses datatype="tokens">Ranged+Unit Siege</PreferredClasses>
      <RestrictedClasses datatype="tokens">Permanent Ship</RestrictedClasses>
    </Melee>
  </Attack>

I have a custom class called Permanent for certain things in DE. You can put Field there instead.

  • Like 2
Link to comment
Share on other sites

On 27/07/2024 at 7:35 PM, LetswaveaBook said:

The template_unit_dog shows that such things can be done, but I wouldn't want to update every single template.

I dont fancy updating every template, especially since I would also consider not allowing ranged units to attack rams or siege towers. Doing it template by template means that with every change of mind, I need to change all the templates again.

The templates would be inf_skirm_sling_crossbow_archer Jav archer and javelin champion archer, cav archer and crossbow, the hero templates for archers, cav archers javelineer and mounted javelineer and of course the bolt shooter.

Link to comment
Share on other sites

On 28/07/2024 at 10:49 PM, wowgetoffyourcellphone said:

To piggyback on what @Stan` has said, imagine it's a hierarchal structure. Everything you do on a higher level of the pyramid trickles down to the templates on the lower levels unless you specify something different in those templates. 

Maybe I don't fully understand.

But in order to fix the "restricted classes", I assign an "attack" element to the unit template while some units shouldn't get any attack element. Am I wrong on this?

The unit template is not suitable: It seems to mess with units that don't have a ranged attack (healers, fishing ships&trades escpecially)

Link to comment
Share on other sites

33 minutes ago, LetswaveaBook said:

But in order to fix the "restricted classes", I assign an "attack" element to the unit template while some units shouldn't get any attack element. Am I wrong on this?

The unit template is not suitable: It seems to mess with units that don't have a ranged attack (healers, fishing ships&trades escpecially)

I assume you're referring to the template_unit.xml  file. Obviously that would be the easiest thing to do, one file to change, and boom. Unfortunately all the template_unit_*.xml  files for units inherit from it.

The templates you're interested in are in that folder https://trac.wildfiregames.com/browser/ps/trunk/binaries/data/mods/public/simulation/templates

No need to go down, all the templates in the subfolder inherit from those.

The files you should change are probably:

For cavalry

template_unit_cavalry_ranged_archer.xml    
template_unit_cavalry_ranged_crossbowman.xml    
template_unit_cavalry_ranged_javelineer.xml

For infantry

template_unit_infantry_ranged_archer.xml    
template_unit_infantry_ranged_crossbowman.xml   
template_unit_infantry_ranged_javelineer.xml   
template_unit_infantry_ranged_slinger.xml

You might be able to get away with only editing those two files

template_unit_infantry_ranged.xml    
template_unit_cavalry_ranged.xml   

As you can see by looking at https://trac.wildfiregames.com/browser/ps/trunk/binaries/data/mods/public/simulation/templates/template_unit_infantry_ranged_archer.xml

<Entity parent="template_unit_infantry_ranged">

This line indicates the template inherits from all the stuff you put in the parent, here template_unit_infantry_ranged.xml
 

It sadly seems no one unified the champion templates for ranged so you need to edit:

template_unit_champion_cavalry_archer.xml
template_unit_champion_cavalry_crossbowman.xml
template_unit_champion_cavalry_javelineer.xml
template_unit_champion_infantry_archer.xml
template_unit_champion_infantry_crossbowman.xml
template_unit_champion_infantry_javelineer.xml

I have not tested, but you should only have to add

  <Attack>
    <Ranged>
      <RestrictedClasses datatype="tokens">Field</RestrictedClasses>
    </Ranged>
  </Attack>

in each of the templates.

 

Does that make more sense to you?

 

Link to comment
Share on other sites

Assuming you'd want to go nuts, or only change classes in one place you can use what we call mixins (basically small part of templates, that can be reused)

Here is an example for the african elephants, that stacks modifiers on top of normal elephants https://trac.wildfiregames.com/browser/ps/trunk/binaries/data/mods/public/simulation/templates/mixins/elephant_african.xml

This mixin is referenced in https://trac.wildfiregames.com/browser/ps/trunk/binaries/data/mods/public/simulation/templates/units/kush/champion_elephant.xml

like this:

<Entity parent="elephant_african|template_unit_champion_elephant_melee">

 

Yours would look like this maybe called ranged_restrictions.xml in the mixins  directory

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Entity>
  <Attack>
    <Ranged>
      <RestrictedClasses datatype="tokens">Field</RestrictedClasses>
    </Ranged>
  </Attack>
</Entity>

and be referenced like this:

<Entity parent="ranged_restrictions|original_parent">

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...