Opened 12 years ago

Last modified 4 years ago

#994 new enhancement

Running / Charging Units

Reported by: historic_bruno Owned by:
Priority: Should Have Milestone: Backlog
Component: Simulation Keywords: run, charge, unit, motion
Cc: Patch:

Description (last modified by michael)


Change History (19)

comment:1 by michael, 12 years ago

Description: modified (diff)

First, the distinction between "run" and "charge":

Run: This occurs when a unit is moving quickly to "catch up" to a group of other units it was tasked to move with. This could also occur with input from the player to get units to move to another position quickly. Player can even task units to run to a resource to gather.

Charge: This is a fast movement initiated by the player against enemy units. The unit closes quickly with the enemy target unit (generally at 2x or 3x walking speed) and then the first attack is bonused (usually 2x).


This was how this was achieved in Sim1:

Units that could run/charge had a stamina value in their template file. This would drain at a steady rate while running or charging and would replenish when the unit was idle. If stamina was drained to 0, then the unit would not run or charge (except to run to catch up to a formation move command).

A double-right click initiated a run or charge.

Charging speed was the same as the run speed in the template file.


What I would look is to generally keep the same scheme as Sim1, with some differences:

Running speed and Charging speed should have two different components in the unit template file. I would generally make Running 2x walking speed and Charging 3x walking speed.

Charging should drain Stamina faster than Running.

I would like there to be a distance at which charging becomes more effective and then a further distance at which it becomes less effective. For instance, charge too close and the charge attack is only bonused 1.5x. Charge at the right distance and the unit gets the full 2x bonus. Charge too far and only get the 1.5x bonus.

It would be good to have acceleration if possible.

Please feel free to rip apart my ideas.

Last edited 12 years ago by michael (previous) (diff)

comment:2 by michael, 12 years ago

Here is the currently unused charge attack schema from Sim1, still in the unit templates. Example is from the Cavalry Spearman:

    <Charge>
      <Hack>15.0</Hack>
      <Pierce>30.0</Pierce>
      <Crush>0.0</Crush>
      <MaxRange>6.0</MaxRange>
      <MinRange>0.0</MinRange>
      <Bonuses>
	<ElephantStench>
	  <Classes>Elephant</Classes>
	  <Multiplier>0.5</Multiplier>
	</ElephantStench>
	<CamelStench>
	  <Classes>Camel</Classes>
	  <Multiplier>0.5</Multiplier>
	</CamelStench>
      </Bonuses>
      <PreferredClasses datatype="tokens">Organic Siege</PreferredClasses>
      <RestrictedClasses datatype="tokens">StoneWall</RestrictedClasses>
    </Charge>

The above is part of the Attack component, but separate from the Melee component.

Walk/Run(and Charge in Sim1) are here, in the UnitMotion component:

  <UnitMotion>
    <WalkSpeed>7.5</WalkSpeed>
    <Run>
      <Speed>15.0</Speed>
      <Range>50.0</Range>
      <RangeMin>0.0</RangeMin>
      <RegenTime>0.1</RegenTime>
      <DecayTime>0.2</DecayTime>
    </Run>
  </UnitMotion>

I am unsure what RegenTime and DecayTime are. But you can see that Run speed has been set to 2x WalkSpeed. Could be good to add a ChargeSpeed tag for either the UnitMotion or Attack/Charge component, so that it could be set a little faster.

comment:3 by Erik Johansson, 12 years ago

Have had this ticket sitting in a tab for weeks now, trying to think of something useful/indepth to say :P I can't find anything other to say than that as far as I understand them I agree with your proposed changes. Apart from maybe thinking the correct/wrong distance might be complicating things a bit too much (at least in terms of how much/how easily we can communicate it to the player). Maybe have a "charge timer" could work? E.g. to have a timer start ticking when the charge is initiated that multiplies the attack value. Coupled with stamina running out it would give essentially the same result as what you describe, i.e. if you initiate the charge too close it will not have much time to increase the timer (and thus the attack multiplier), if you initiate it too far away stamina will have run out before you reach the target and you will just attack normally. Perhaps that's complicating things more than what you are suggesting though :-/ And it's possibly harder to balance, at least effort vs result, since it's the same for all players it shouldn't matter much in human vs human games at least, AIs could of course be scripted to always charge at the optimal distance, but that applies to whichever method we'd use :) .

comment:4 by FeXoR, 11 years ago

In general I like the idea of charging (base speed x3) is faster than running (base speed x2). Charging should drain stamina 2 times as fast as running does (because it really drives the unit to it limits).

That will result in a strangeness though: If 2 "fresh" (with full stamina) units get close to each other (say both with charge capabilities, so melee likely) it will be impossible to flee. Running for their live however should push the individual units to their limit as well, though. Determining if a unit is "running for it's life" would be hard to determine though.

So in the end (though I like the idea) I think there should be only 1 "faster" speed (2x). That would mean an "exhausted" unit can not run from a fresh unit but a fresh unit can (if in general faster or equal fast as the unit "charging" it).

It may be easiest if "charge" would be an active ability with a maximum and minimum range. If the player clicks "charge" and then on an enemy unit the unit would walk (or run, depending on the command) untill it reaches the maximum charge distance. Then it will start charging if it has enough stamina. If it reaches the target it will execute the charge attack. If the "charge" button is right-clicked the unit will (if enough stamina) start to charge an enemy unit automatically (like "autocast" in warcraft 3). Same with running.

Another thing to think of is when are units regaining stamina? I think they shouldn't if they are fighting/gathering/walking etc. so they should only regain stamina if they are idle. That means that stamina is mostly wasted if used for gatherers. If not used it can then be used in case of an raid to bring the gatherers to safety. Formations with stamina could indeed start to make sense (at least to me) if the unitAI tries to keep all units in the formation to keep stamina by sending fresh units to the outside of the formation while fighting and draw exhausted units inside the safety of the formation (same with units high/low on health, especially good with healers in the formation).

One thing I'm opposed to is that units can "cheat" by running without stamina consumption if catching up to a formation!

Other thoughts: Another thing to consider is that stamina could be widely used for special abilities e.g. throwing spears would be cool to be rare, not the default attack, units with shields could use stamina to block attacks, heroes could boost close allies attack with a warcry with stamina consumption, healers could loose stamina with their heal ability, some units could attack faster/harder for stamina and so on. That way it might be good not to "waste" stamina on running.

Last edited 11 years ago by FeXoR (previous) (diff)

comment:5 by scythetwirler, 11 years ago

I'm somewhat opposed to the idea of stamina (I feel that's one thing too many to keep track of). I think to discourage units from charging all the time, we should have something similar to the charge ability in Battle for Wesnoth:

Charge

This attack deals double damage to the target. It also causes this unit to take double damage from the target's counterattack.

That way, a cavalry swordsman/spearman is still toast against infantry spearmen. It also does expose another gameplay mechanic: melee units (which are slightly underpowered IMO) charging against ranged/support units (who have little or no melee attack) is devastating.

comment:6 by michael, 10 years ago

I agree that stamina as a bar in the UI is a little much to keep track of. Instead of stamina, we could just have distance modifiers that affect how a charge is used and works.

Example:

  1. Your Melee Cavalry unit is 40 meters away from its target that you just double-right-clicked on to initiate a charge.
  1. 40 meters is too far for a charge, so your Melee Cavalry will walk (perhaps we can have a 4th speed called "trot" which is 1.5x walk?) to within "charge distance" of 20 meters, then begin to run (2x walk).
  1. Within 10 meters of the target your Melee Cavalry accelerates to charge speed (3x walk) and deals the charge bonus upon contact with the enemy target unit.

If the enemy target unit moves closer to your Melee Cavalry in the intervening time between your charge command (double-right-click), it's possible that your cavalry would not have the time to accelerate to charge speed and is instead only at run speed, which case your Melee Cavalry's charge bonus will be reduced somewhat.

Also, maybe the targeted unit will move further away from your Melee Cavalry in the intervening time, so your Melee Cavalry's charge is blunted in some way. Perhaps there would be an "effective" distance there as well. Your Melee Cavalry starts his charge and if he doesn't make contact with an enemy (any enemy) within 20 meters, then he negatively accelerates for 10 meters back to walk. None of this necessitates "stamina" or a stamina bar. It's just intuitive as the player intuits that a charge too far or too close is less effective (see: Rome Total War).

I also like the idea that the targeted melee unit also gets a bonus attack against the charging unit. Maybe half of the charge bonus (e.g., 1.5x instead of 2x)?

Last edited 10 years ago by michael (previous) (diff)

comment:7 by michael, 10 years ago

Milestone: BacklogAlpha 16

comment:8 by scythetwirler, 10 years ago

Perhaps running units take more damage (1.5x or 1.25x) than when they are standing still or walking? (To provide a use for walking).

comment:9 by michael, 10 years ago

Some possibilities to remove micro without adding too much auto, after some discussion with Sanderd (who felt all the ideas so far were too much micro):

If we go with battalion combat, then all charging can be manual. Battalions would remove enough micro that charging can remain manual. This is the most tactical option, IMHO.

If we stick with mosh-pit combat, then charging can be part of the effect of setting units to 'Aggressive' stance. Units default to Defensive Stance (attack units within 50% of their vision range) and don't normally charge. But if set to Aggressive Stance they will automatically charge enemies within vision range.

Or something completely different: We can have 'commands' similar to how Age of Mythology had God Powers. A 'Charge' command would be one of them, where you cast this command onto a group of troops and they will initiate the command.

Last edited 10 years ago by michael (previous) (diff)

comment:10 by BranKaLeon, 10 years ago

I like the idea of running & charging, so I start thinking about it.
Thought a stamina attribute might enable lots of additional feature, I agree that It may lead to major changes, that this simple feature should not require.

So, I imagine a clock counter-clock (or double-timer) mechanism to manage running/charging and somehow balancing it.

Double-right-clicking an enemy unit should be automatically interpreted as run toward/charge the target, according the following conditions:

[optionally,different animations and/or speed might be used for charging and running].

The charge bonus is "loaded" at the mouse-click instant, if the InitialDistance > MinChargingDistance(=distance at the moment of mouse-click is greater than a minimum threshold).

To avoid units running all the time, a "fresh" unit can ran for MaxTimeRun seconds (here a clock/timer). Whenever the running-action ends (the user stop it, or the maximum time is reached) the unit becomes "tired". the unit stays tired for an amount of time equal to the time spent running (here the counterclock). when tired, a unit cannot run, and also it moves slowly (e.g., TiredSpeed = 0.5x walk) [optionally, it may also combat "slowly" or less efficiently - TiredCombactMultiplier < 1]

Varying MaxTimeRun, TiredSpeed, TiredCombactMultiplier and ChargeBonus one should be able to balance running vs walking.

This approach is not too different from the "distance modifiers" idea of michael, which I like, even though the "acceleration part" seems unnecessary to me and also it hasn't any mechanism to discourage unit to charge (almost) always.

Last edited 10 years ago by BranKaLeon (previous) (diff)

comment:11 by sanderd17, 10 years ago

Looks good, but there should also be some sort of minimum distance. You can't charge a target while standing next to it.

comment:12 by BranKaLeon, 10 years ago

Yes, indeed there is a minimum distance (MinChargingDistance):

if distance at mouse-click istant is lower than MinChargingDistance, no charge bonus is added; the unit just run to the target, then start fighting.

comment:13 by wraitii, 10 years ago

Some points and ideas:

if we separate walking and running — and trotting — by speed the player has no incentive to use walking. It is always better to run. This leads to micro hell.
If we say units need to rest after running, either walking is always better over long distances, or running is, or they're equal. This is either micro hell or a useless feature.

With that in mind, I can see no simple system where we could have walking and running be player-decided and make sense. So it has to be automatic. Let's eliminate something already: most infantry won't ever run in their normal state because that makes no sense. It's exhausting to run. Particularly in armor.
On the other hand, cavalry can have a default "trot" speed, or slow gallop, that it will use to travel everywhere (those units don't do nearly enough walking that it would be exhausting for the horse IRL). When in a formation where their walking speed is reduced, they default to a walking anim. We could have several anims based on general formation speed.
Some units might see their speed reduced in certain cases (gatherers carrying stuff or whatever), either now or in the future. In that case, we could also have some speed-defined changes in animation. This more or less exists already, but we might have some units where the difference is drastic enough that a completely different "state" is required.
Finally, units could run when they are fleeing from an enemy. Which is basically just charging into emptiness. So it should definitely use the same system (perhaps a different animation though). Probably the same speed too. Not all units would flee.

With that in mind, the unitMotion component should probably have a few different states (walk, trot, run…) with corresponding max/min speeds. Fully auto. No micro, no brainstorming. "Run" state would be special as it would be used for charging and fleeing.

On to charging: it makes sense to charge an enemy for various reasons, including getting there quickly (most animals right now will walk to an archer attacking them which is just dumb). This should imo also be automatic: as soon as a unit decides it "attacks" an enemy, it will charge. That's just logical. Units should use their fastest unitMotion state (often "Run", the same as for fleeing), with a custom animation or not (this can be defined in unitMotion imo). This behavior doesn't apply to formations, where imo it should be user decided as formations are coherent and logical.

How to decide when to stop? Simple: you have a max speed, a sustain time, an acceleration, a deceleration, and a recovery time. They will go from their "base" speed (possibly faster) to their maxspeed at the "acceleration" rate, hit their top speed, stay there for "sustain time", and decelerate to their walking speed where they will stay for "recovery time".
If we make charging bonus based on % of top speed, this easily defines a perfect charging range that the unit can automatically determine (possibly only champions/elite units do this). Charge for too short a time and you're not at top speed. Charge for too long and you're not either. Charge for way too long and you're not charging anymore. For formations, the player might need a GUI help, and if there are different units in a formation, this might be unit-specific.
A charging/fleeing unit is not controllable (unless it has gone in recovery mode). It has a target (possibly a position or an entity). Some units might be able to turn while charging, others not (but most won't be able to turn much, we'd need some inertia in there.) They act like rockets. Whatever they hit in their path sustains damage. If they hit an unmovable obstruction, they sustain damage/die spectacularly. Units should probably check that the path is clear from static obstructions before charging. Once they've hit something, they end the charge (decelerate at "decelerate" speed and break the charge).

For proper animation, this would likely require the game to switch between walking modes dynamically, and possibly have some specific animations (sudden horse stop…) For more advanced behavior, we might want units to try to evade charges. This is, however, more complicated.

Technically this requires quite a few changes. We'd want speed to be dynamic (more than it is now). We'd want animations depending on speed (automatically). We'd want fake physics (see #2319). This wouldn't require pathfinding change as those units wouldn't really pathfind, maybe adjust slightly to the left or the right and wait and see.

To clarify: a unit above a certain speed is charging (fleeing is charging). Charging gives an attack bonus and a defense malus (possibly actually an HP malus). Charges should probably be instakill for some units (a cavalry unit taking an arrow while charging will fall down and die. A cav unit hitting a swordman at full speed kills the swordman. A cav unit hitting an elephant at full speed dies.) This is all fully auto except for formations where it would have to be triggered.

Last edited 10 years ago by wraitii (previous) (diff)

comment:14 by michael, 10 years ago

I like this line of thinking, wraitii. It is definitely important to keep as much of it automatic as possible. I think Cavalry should always approach the enemy at the fastest possible speed. Infantry, I think they should approach at a middle speed, between walk and charge, unless directly ordered by the player to charge, in which case they would approach at charge speed and charge animation, giving the charge bonus upon contact.

I like the idea of seeing cavalry "throttle down" to walk animation when in a slower formation. Excellent.

comment:15 by leper, 10 years ago

Milestone: Alpha 16Backlog

comment:16 by fatherbushido, 8 years ago

I have a naive question.

Why units don't simply charge by default (automatic) when they have the good class (melee cavalry, elephants...) and a distance between min and max ?

comment:17 by Imarok, 5 years ago

Component: UI & SimulationSimulation

Move tickets to Simulation as UI & Simulation got some sub components.

in reply to:  16 comment:18 by Freagarach, 4 years ago

Replying to fatherbushido:

I have a naive question.

Why units don't simply charge by default (automatic) when they have the good class (melee cavalry, elephants...) and a distance between min and max ?

Because that can be abused: charging to the closest enemy, when appropriately close click an enemy further away, next click one even further away. It could let units charge past a whole lot of enemies.

comment:19 by fatherbushido, 4 years ago

Thanks to not reply to 4 years old past me.

Note: See TracTickets for help on using tickets.