Opened 10 years ago

Last modified 3 years ago

#2577 new enhancement

[PATCH] Turrets and/or sub-units

Reported by: Annar Hiid Owned by: Freagarach
Priority: Nice to Have Milestone: Work In Progress
Component: Simulation Keywords: patch rfc
Cc: leper Patch: Phab:D1958

Description (last modified by Freagarach)

Currently an unit cannot have several pieces that animate independently, which is a great downside of the animation and unit system.

Adding some sub-unit system that could do this would greatly improve the usefulness of the engine and allow a lot of interesting stuff to happen, for example:

  • Units capable of attacking on move without looking silly, e.g horse archers, chariot archers and modern tanks.
  • Possibly, multi-actor animation stances (if one unit is allowed to assume ownership of another to achieve perfect visual position sync) - i.e, TotalWar or Dawn of War-like combined combat choreography sequences.

I do realise that the current state of 0ad the game can live without it well enough, and that implementing this feature would require visiting upon some rather innermost alcoves of pyrogenesis the engine. So "Nice to have" :)

Attachments (6)

turrets.diff (16.9 KB ) - added by sanderd17 10 years ago.
A proposal
turrets_scripted.diff (21.3 KB ) - added by sanderd17 10 years ago.
turrets_scripted.2.diff (21.0 KB ) - added by sanderd17 10 years ago.
2577 Atlas Todo.patch (24.8 KB ) - added by Stan 9 years ago.
Rebased version for r17136
2577.diff (30.8 KB ) - added by Stan 9 years ago.
This patch follows the order of the the parent, so it can capture, and attack while moving. Since the parent is always sending attack commands though, it will only be able to attack on unit at a time. Still need the fix for atlas, and * maur champion chariot * hero darius * hero xerxes Apart from that it's functionnal
2577 - MauryanArcherBugFix.patch (5.6 KB ) - added by Stan 9 years ago.
Attached patch fix the bug quoted above. It's totally unrelated to the ticket so can be commited separately.

Download all attachments as: .zip

Change History (33)

by sanderd17, 10 years ago

Attachment: turrets.diff added

A proposal

comment:1 by sanderd17, 10 years ago

Keywords: patch review added; animation removed
Summary: Turrets and/or sub-units[PATCH] Turrets and/or sub-units

Here I have a proposal for turrets. IMO, the simulation position of turrets is important. It could have a separate attack (and mostly will), with a separate range etc. As the prop positions are not synchronised, it can't be derived from that. So I made a TurretHolder where you have to define the turret position relative to the main entity.

The CmpPosition is also made aware of turrets, and updates the turret position based on the parent position in the simulation. The visual position is calculated separately though, it uses the same transformation matrix as prop points, so non-network synchronised stuff (like position interpolation, or terrain alignment) doesn't cause visual problems. It is possible however that the visual and real position are slightly different.

By allowing complete entities as props, you can also make them selectable (e.g. to view some stats specifically for those turrets, like a different attack). You can give them health (so make it possible to first kill the turret, and then the main entity), and a whole bunch of other stuff.

I made the TurretHolder so that entities can have default turrets, but other components (like GarrisonHolder) can add any entity they want to it on a certain position (and also take them off again).

comment:2 by sanderd17, 10 years ago

In 15246:

Add the Engine code for turrets + use them to get units on walls. The scripted TurretHolder isn't included due to lack of usability for now. Refs #2577

comment:3 by sanderd17, 10 years ago

Keywords: review removed

comment:4 by Annar Hiid, 10 years ago

Resolution: fixed
Status: newclosed

comment:5 by sanderd17, 10 years ago

Resolution: fixed
Status: closedreopened

Not completely fixed yet. The map saving problems in atlas aren't resolved yet for objects that should start with a turret. So you currently can't create units with turrets by default at all.

by sanderd17, 10 years ago

Attachment: turrets_scripted.diff added

comment:6 by sanderd17, 10 years ago

Added some scripted stuff to turrets. Including a TurretHolder. Note that for working with Atlas, the init should be refined. There's also a TurretAI, based off BuildingAI. I see the diff is a bit messed up, so you might first want to copy BuildingAI.js to a file named TurretAI.js before applying the diff.

The TurretAI now works like BuildingAI, in that the Turret automatically chooses its targets. But once a target is chosen, it rotates towards that target, and sticks with it (to not rotatte like a mad man every second).

It needs refinement for sure, so I'm not eager to commit it without having some unit where it's really needed.

by sanderd17, 10 years ago

Attachment: turrets_scripted.2.diff added

comment:7 by sanderd17, 10 years ago

Cc: leper added
Keywords: review added

New patch, here turrets are not selectable, the main entity can't attack, but the attacks go through the turrets. The turrets will always attack anything near, but listen to attack commands from the main entity.

I'm not too happy with my changes to Attack.js. But disabling the attack for the main entity, while letting UnitAI believe it can still attack required either lots of changes to UnitAI, or a duplicated prototype under the IID_Attack interface. I think the changes to Attack.js cause as few problems as possible.

I also modified all chariots with at least two people on it. One is the driver, and can't attack. The others are turrets and can attack. Notice that it works with multiple turrets, see Ashoka. Tell me if I forgot a chariot.

comment:8 by historic_bruno, 10 years ago

Milestone: BacklogAlpha 17

comment:9 by Josh, 10 years ago

  1. The TurretsOnly option seems useless. I can't think of any case where an entity should only be attackable by a turret.
  2. Attack.js never updates latestTarget so GetLatestTarget will always return INVALID_ENTITY, but as latestTarget is only used in TurretAI it shouldn't be stored in Attack.js anyway.
  3. There are some extra brackets starting line 174 in TurretAI.js (on your if and for blocks).
  4. More Doxygen style function documentation never hurts.

comment:10 by Stan, 10 years ago

Don't know if it's linked to what Josh said but if you play in atlas, garrison units in a wall and save, then reload the map, units are said to be in an invalid state.

comment:11 by Josh, 10 years ago

Keywords: review removed

comment:12 by Itms, 10 years ago

Milestone: Alpha 17Alpha 18

Hi Sander, given that you have less time to dedicate to the game currently, I'll push that to A18. Feel free to revert the change if you want to commit this patch before freeze.

comment:13 by Stan, 10 years ago

It seems we already use it in a mod : this topic is relevant http://www.wildfiregames.com/forum/index.php?showtopic=18452

in reply to:  9 comment:14 by leper, 9 years ago

Replying to Josh:

  1. The TurretsOnly option seems useless. I can't think of any case where an entity should only be attackable by a turret.

You got that wrong. The flag is so a unit can only attack with its turrets.

In addition to the other comments:

  • TurretAI.js has a strange comment on line 102.
  • Some cleaning up of comments couldn't hurt (starting with capital letters and related issues).
  • s/var/let/g This changed since the patch, but I wouldn't add new code without that now.
  • SM now supports default values for parameters (TurretAI.SelectAnimation)
  • There is still the TODO for Atlas.
  • Are there some changes in UnitAI needed that aren't included?

comment:15 by Itms, 9 years ago

Milestone: Alpha 18Alpha 19

comment:16 by Itms, 9 years ago

Milestone: Alpha 19Backlog

Backlogging due to lack of progress.

by Stan, 9 years ago

Attachment: 2577 Atlas Todo.patch added

Rebased version for r17136

comment:17 by Stan, 9 years ago

Remaining :

  • Atlas Todo (I need help)
  • Best way to get the attack
  • This could be extended to every cavalry units would fix the stuttering units.
  • This needs to be extended to every turret compatible units (chariots,elephants)
Last edited 9 years ago by Stan (previous) (diff)

comment:18 by Stan, 9 years ago

Owner: set to Stan
Status: reopenednew

comment:19 by Stan, 9 years ago

Status: newassigned

comment:20 by elexis, 9 years ago

Component: Core engineUI & Simulation

by Stan, 9 years ago

Attachment: 2577.diff added

This patch follows the order of the the parent, so it can capture, and attack while moving. Since the parent is always sending attack commands though, it will only be able to attack on unit at a time. Still need the fix for atlas, and * maur champion chariot * hero darius * hero xerxes Apart from that it's functionnal

comment:21 by elexis, 9 years ago

Notice the men on the mauryan war chariots also walk when the chariot is being moved. Sounds like this ticket would/could solve this issue then too.

by Stan, 9 years ago

Attached patch fix the bug quoted above. It's totally unrelated to the ticket so can be commited separately.

comment:22 by elexis, 8 years ago

In 17346:

Fixes a bug in the mauryan warchariot walk-animation. They were walking instead of standing on the chariot when it moves.
Patch by Stan. Refs #2577.

comment:23 by bb, 7 years ago

Keywords: rfc added
Milestone: BacklogWork In Progress

Based on patches above I made some system for subunits where the turret has its own unitAI, so it can take orders and stuff. See https://github.com/bb-bb/0ad/tree/t2577_subunit

The concept I try to achieve is to have a turretHolder (with a unitAI or BuildingAI) and on top of that turrets. These turret may also be turretHolder of themselves. The turretHolder and turret can communictate with eachother via TurretHolder and TurretManager, turretHolder for messages from holder to turret and TurretManager for the opposite direction. The turrets of themselves also have a unitAI or BuildingAI. The turrets for now can't be selected (as they would cause some problems in the gui) but they do get orders from input.

Some notes:

  • The git has template changes for all champion cavalry as test, but this can be extended, this is just a test.
  • Test fails, but playtest works
  • Patch have some deprecated logic e.g. the CanMove logic can be removed I guess.
  • In this approach all units need the TurretManager component, maybe this can be changed.
  • Visible garrison (wall) should be done the same way.

refs #4000

comment:24 by Stan, 7 years ago

Owner: changed from Stan to bb_
Status: assignednew

Hey thanks for working on it, I really appreciate it :)

comment:25 by Imarok, 5 years ago

Component: UI & SimulationSimulation

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

comment:26 by Freagarach, 4 years ago

Description: modified (diff)
Owner: changed from bb_ to Freagarach
Patch: Phab:D1958

comment:27 by Freagarach, 3 years ago

In 25192:

Allow to specify subunits on creation.

This basically does two things:

  • Allow turrets on moving entities (fixes serialisation in cmpPos).
  • Allow an entity to be present on another when the other is created.

That makes it basically a boiled down version of a prior patch, omitting the part where orders could be passed on.
This does allow e.g. ranged units on chariots that fire while the chariot moves.

Original diff by: @sanderd17
Redone by: @Stan
Differential revision: D1958
Comments by: @Alexandermb, @Angen, @bb, @Langbart, @Nescio, @Stan, @wraitii
Refs. #2577 by implementing the entity on platform case.

Note: See TracTickets for help on using tickets.