Phobos icon indicating copy to clipboard operation
Phobos copied to clipboard

Techno attachment logic

Open Metadorius opened this issue 4 years ago • 119 comments

  • Technos now can be attached one to another in a tree like way. The attached units won't process any locomotion code and act like a part of a parent unit in a configurable.
    • Currently the attached techno may only be a vehicle.
    • When attached, the special Attachment ({C5D54B98-8C98-4275-8CE4-EF75CB0CBE3E}) locomotor is automatically casted on a unit. You may also specify it in the child unit types manually if the unit is not intended to move without a parent (f. ex. a turret).

In rulesmd.ini:

[AttachmentTypes]
0=MNT                                 ; (example)

[MNT]
RespawnAtCreation=true                ; boolean
RespawnDelay=-1                       ; integer, non-negative values enable the respawn timer
InheritOwner=true                     ; boolean, whether the child inherits owner of the parent while it's attached
InheritStateEffects=true              ; boolean (state effects = chaos, iron curtain etc.)
InheritCommands=true                  ; boolean
InheritCommands.StopCommand=true      ; boolean
InheritCommands.DeployCommand=true    ; boolean
LowSelectionPriority=true             ; boolean, whether the child is low priority while attached
YSortPosition=default                 ; Attachment YSort position enumeration - default|underparent|overparent
InheritDestruction=true               ; boolean
InheritHeightStatus=true              ; boolean, whether the layer and InAir/OnGround/IsSurfaced inherited from parent
OccupiesCell=true                     ; boolean
DestructionWeapon.Child=              ; WeaponType, detonated on child when parent is destroyed
DestructionWeapon.Parent=             ; WeaponType, detonated on parent when child is destroyed
ParentDestructionMission=             ; MissionType, queued to child when parent is destroyed
ParentDetachmentMission=              ; MissionType, queued to child when it's detached from parent

[SOMETECHNO]                          ; TechnoTypeClass
; used when this techno is attached
AttachmentTopLayerMinHeight=          ; integer
AttachmentUndergroundLayerMaxHeight=  ; integer
; used for attaching other technos
AttachmentX.Type=MNT                  ; AttachmentType (example)
AttachmentX.TechnoType=               ; TechnoType that can be attached, currently only units are supported
AttachmentX.FLH=0,0,0                 ; integer - Forward, Lateral, Height
AttachmentX.IsOnTurret=false          ; boolean
AttachmentX.RotationAdjust=0          ; rotation in DirType, from -255 to 255

[General]
AttachmentTopLayerMinHeight=500           ; integer,
AttachmentUndergroundLayerMaxHeight=-256  ; integer
  • The semantic locomotor alias feature is also supported for Phobos locomotors.
Alias CLSID
Attachment {C5D54B98-8C98-4275-8CE4-EF75CB0CBE3E}

TODO:

  • [x] Handling different locomotors being attached
    • [x] TunnelLoco currently leaves the initial place as if it was left there, crashes the game on destruction
    • [x] Jumpjets stay invincible when attached
    • [x] Review the possibility of adding a custom attachment locomotor instead of a locomotor + skipping Loco process code and changing to it and back
    • [ ] loosely related - turret is rendered wrong for TunnelLocoClass when going up
  • [x] Sync up the phasing in state for Teleport locomotor
  • [x] IsOnTurret is broken visually
  • [x] Shadows need to be fixed too
  • [x] Latest build crashes on release/devbuild but not on debug when children is yeeted, most likely some piggybacking refcount screwery
  • [x] Jumpjets crash improperly when they are crashable=yes and destroyed with children destruction
  • [ ] Handle placing the detached children into the correct place (they are not centered at the cell or the correct position for inf atm)
  • [ ] Add a flag to force same mission and target to attachments, shouldn't be mixed with commandability
  • [ ] Make attached units untargetable and non-damageable using regular weapons via a tag
  • [ ] Check AI shenanigans
  • [x] Make attached units unselectable (transparent to selection) via a tag
  • [x] Make attached units be transparent for pathfinding and building placement but still targetable and damageable
  • [x] Handle movement command issued with command inheritance enabled (i.e. optionally reset targets like vanilla units do). possibly just reset the mission when movement command is given and recursed into children instead of doing nothing for that command
  • [ ] The source of destruction on parent unit specifically appears to be null for cargo (and consequently the children), see 0x7384AB which later calls Kill_Cargo. Needs context and/or earlier Kill_Cargo/On_Destroyed call
  • [x] Rotation adjustment tag
  • [x] Non-omnifire units without turret rotate and snap back even though the code, test if still happens
  • [x] Units now could clip into each other for some reason sometimes, need to review the passability hook again to see what changed
  • [ ] When ordering a vehicle with attachments that offset the "center of mass" to move arrives at offset cell
  • [ ] ConsideredAircraft still crashes when combined with AttachmentLocomotion, something related to AircraftTracker
  • [x] Attachment loco does not provide sensors or sight currently
  • [ ] Sort out speed=0 while being attached interaction (may just block speed=0 features if attached) and review similar hooks with Techno Attachment
  • [ ] Investigate Per_Cell_Process for useful stuff for TA
  • [ ] Check interaction with cloak inheritance and other state effect inheritance
  • [x] Improve scatter when something tries to enter the cell on cell-occupying attached technos to make the parent scatter instead
  • [ ] Weird bug when cell stays semi-occupied after the children gets destoyed with parent on that cell? might be related to RotE's husks
  • [x] Implement handling of deploy
  • [ ] Implement handling of conversion
    • #1259 to be reviewed and worked upon
  • [x] Implement building upgrades support
  • [ ] Implement children appearing/disappearing on buildup end (or selldown start)
  • [x] Fix bugged loading of unrelated units into transport when multiple units are on cell
  • [ ] AttachmentX.IsOnBarrel (?)
  • [x] Units still clip into each other sometimes (unconfirmed)
  • [ ] Shadow scale on children of jumpjets is incorrect
  • [x] Units with attachment at 0, 0, 0 can't exit War Factory once again for some reason despite the handling code existing and working previously

Known issues:

  • The attachment jitter when they are offset from the 0,0,0 point. This is most likely a precision issue that is impossible to fix without a lot of code to draw the voxel relative to the main point and canvas enlargement. Prototype code exists but commented out and a bit outdated due to locomotors, it needs further work.
  • Shadows currently don't behave like parts of the same unit (aka being on one single plane). If that's undesirable - disable children shadows and make shadows via main unit VXL (maybe shadow section hack with transparent voxels).
  • Sight may be hacky as it abuses the in-air sight timer, might need testing, especially with height changes.

Metadorius avatar Aug 29 '21 12:08 Metadorius

ok yet another TODO with current things to finish

  • [x] Handling different locomotors being attached
    • [x] TunnelLoco currently leaves the initial place as if it was left there, crashes the game on destruction
    • [x] Jumpjets stay invincible when attached
    • [x] Review the possibility of adding a custom attachment locomotor instead of a locomotor + skipping Loco process code and changing to it and back
    • [ ] loosely related - turret is rendered wrong for TunnelLocoClass when going up
  • [x] Sync up the phasing in state for Teleport locomotor
  • [x] IsOnTurret is broken visually
  • [x] Shadows need to be fixed too
  • [x] Latest build crashes on release/devbuild but not on debug when children is yeeted, most likely some piggybacking refcount screwery
  • [x] Jumpjets crash improperly when they are crashable=yes and destroyed with children destruction
  • [ ] Handle placing the detached children into the correct place (they are not centered at the cell or the correct position for inf atm)
  • [ ] Add a flag to force same mission and target to attachments (piss easy, probably 6 lines in total), shouldn't be mixed with commandability
  • [ ] Make attached units untargetable and non-damageable using regular weapons via a tag
  • [ ] Check AI shenanigans
  • [x] Make attached units unselectable (transparent to selection) via a tag
  • [x] Make attached units be transparent for pathfinding and building placement but still targetable and damageable
  • [x] Handle movement command issued with command inheritance enabled (i.e. optionally reset targets like vanilla units do). possibly just reset the mission when movement command is given and recursed into children instead of doing nothing for that command
  • [ ] The source of destruction on parent unit specifically appears to be null for cargo (and consequently the children), see 0x7384AB which later calls Kill_Cargo. Needs context and/or earlier Kill_Cargo/On_Destroyed call
  • [x] Rotation adjustment tag
  • [ ] Non-omnifire units without turret rotate and snap back even though the code, test if still happens
  • [x] Units now could clip into each other for some reason sometimes, need to review the passability hook again to see what changed
  • [ ] When ordering a vehicle with attachments that offset the "center of mass" to move arrives at offset cell
  • [ ] ConsideredAircraft still crashes when combined with AttachmentLocomotion, something related to AircraftTracker
  • [x] Attachment loco does not provide sensors or sight currently
  • [ ] Sort out speed=0 while being attached interaction (may just block speed=0 features if attached) and review similar hooks with Techno Attachment
  • [ ] Investigate Per_Cell_Process for useful stuff for TA
  • [ ] Check interaction with cloak inheritance and other state effect inheritance
  • [x] Improve scatter when something tries to enter the cell on cell-occupying attached technos to make the parent scatter instead
  • [ ] Weird bug when cell stays semi-occupied after the children gets destoyed with parent on that cell? might be related to RotE's husks
  • [ ] Implement handling of deploy/conversion
  • [x] Implement building upgrades support
  • [ ] Implement children appearing/disappearing on buildup end (or selldown start)
  • [ ] Fix bugged loading of unrelated units into transport when multiple units are on cell
  • [ ] AttachmentX.IsOnBarrel
  • [ ] Units still clip into each other sometimes (unconfirmed)

Known issues:

  • The attachment jitter when they are offset from the 0,0,0 point. This is most likely a precision issue that is impossible to fix without a lot of code to draw the voxel relative to the main point and canvas enlargement. Prototype code exists but commented out and a bit outdated due to locomotors, it needs further work.
  • Shadows currently don't behave like parts of the same unit (aka being on one single plane). If that's undesirable - disable children shadows and make shadows via main unit VXL (maybe shadow section hack with transparent voxels).
  • Sight may be hacky as it abuses the in-air sight timer, might need testing, especially with height changes.

Metadorius avatar Aug 29 '21 12:08 Metadorius

Nightly build for this pull request:

github-actions[bot] avatar Aug 29 '21 12:08 github-actions[bot]

Q: How do I make turrets that don't act like a separate unit? (can't be targeted, destroyed, don't have health) A: Use HealthBar.Hide, Selectable and a custom armor type with some HP that is destroyed with DestructionWeapon.Child.

Metadorius avatar Aug 29 '21 12:08 Metadorius

TODO:

  • sort out the damage/exp sync system (taking suggestions on this)
  • child creation at certain health?
  • proper state effects sync if it doesn't work
  • sort out mission/order inheritance
  • custom selection graphics? etc.

Taking suggestions on logics, tags, hacks etc. for this.

Metadorius avatar Aug 29 '21 12:08 Metadorius

<none> on *Weapons doesn't work.

Metadorius avatar Aug 29 '21 14:08 Metadorius

chrono: on parent: works but only children in the sw range actually teleport with the parent, rest get stuck in limbo; they die once the parent dies or is sent to a grinder on child: doenst have any effect

ic: on parent: works; affects all children too on child: no effect

chaos: on parent: colours all children but only parents and children in range of the weap are affected, sometimes children who are really far away (3k leptons) are affected too even tho the weap only has a range and cell spread of 1 on children: only affects children in range of the weap, they dont get coloured tho, and they seem to target themselves

temporal weaps: parent: targeting affects all children, stopping the attack makes them stuck in place, if u target them with a temporal weap then stop the go back to being attached like normally, if u kill the parent the game crashes child: gets stuck in place, stopping the atk returns the child to the parent like youd expect

Talafhah1 avatar Aug 29 '21 15:08 Talafhah1

BuildingTypes have several bugs.

Attached BuildingTypes keep their anims when removed from the map if deployed and BuildingTypes attached to a movable techno will be placed at the position the parent was created until the parent techno deploys or is destroyed. Chronosphere-ing a unit with attached BuildingTypes will also rarely create impassible/unbuildable terrain when the parent deploys/is destroyed. Video

Having a child techno be important to the game ending (e.g. being the last building) the game will simply not end when destroyed.

4SGX avatar Aug 29 '21 19:08 4SGX

Attach passanger to a projectiles:

  • Magnetron pulls its target, absorbs, then launches it away with inviso V3
  • RA3 Bullfrogs

gangster-ppm avatar Sep 04 '21 00:09 gangster-ppm

Crash on having attached base destroyed and continuing-despite-short-game-on bug I mentioned earlier then creating a new attached building. Code, video, and snapshot in link below. https://discord.com/channels/338055131666972683/773636942775582720/883466977761435668

4SGX avatar Sep 04 '21 11:09 4SGX

Wish: Could all units (master & attached) optionally share Ammo=?

FS-21 avatar Sep 04 '21 13:09 FS-21

Added initial docs and stop command handling for all subtechnos.

Metadorius avatar Apr 22 '22 21:04 Metadorius

Scope shrunk, now the initial version would only support:

  • attachment of vehicletypes;
  • commandability of individual turrets but also command inheritance;
  • state effect inheritance;
  • destruction of children with their parent.

Also

  • Limited attachment to vehicles
  • Fixed destruction handling
  • Disabled reading of not implemented tags
  • Fixed missing MassAction entries
  • Fixed missing InvalidatePointer checks
  • Handled movement cursor and partially movement order for attached technos

Metadorius avatar Jul 12 '22 14:07 Metadorius

  • Fixed rotation of attached technos
  • Fixed scatter crash
  • Fixed Locomotor warheads screwing up attachments

Metadorius avatar Jul 12 '22 19:07 Metadorius

For now only the following tags on attachmenttypes work:

InheritTilt=yes                       ; boolean, whether the child tilts with the parent
InheritOwner=yes                      ; boolean, whether the child inherits owner of the parent while it's attached
InheritStateEffects=yes               ; boolean (state effects = chaos, iron curtain etc.)
InheritCommands=yes                   ; boolean

Metadorius avatar Jul 12 '22 19:07 Metadorius

I'm sorry to bother you.

I noticed that the technical attachment seems to crash and exit the game when the game reads the file, but it doesn't show any text prompts.

Fly-Star-him avatar Jul 13 '22 03:07 Fly-Star-him

If except.txt and extcrashdump.dmp get generated, send them here.

Metadorius avatar Jul 13 '22 06:07 Metadorius

If except.txt and extcrashdump.dmp get generated, send them here.

It can't be done. Because it doesn't show a FatalError, it just quits the game. The only file it generates is the "debug.log":

image

Apparently, it ends when it gets here.

Fly-Star-him avatar Jul 13 '22 07:07 Fly-Star-him

Are you trying the save/load (that may be broken still), or just reading from the INI file? If the latter, then please show me how did you configure the attachment.

Metadorius avatar Jul 13 '22 07:07 Metadorius

Swizzle TechnoClass*, TechnoTypeClass* will be nullptr. And.. AttachmentData* is a pointer to TechnoTypeExt::ExtData's member, I'm sure there won't call SwizzleManagerClass::Here_I_Am, after swizzle it will be nullptr too. As add Debug::Log, I find after loaded, it crashed in AttachmentClass::AI, most members of this are nullptr. I solve this problem like pr#658, load ChildAttachments and ParentAttachment after Ares, and add this hook.

DEFINE_HOOK(0x6CF316, SwizzleManagerClass_Here_I_Am, 0x4)
{
	GET_STACK(void*, oldP, 0x8);
	GET_STACK(void*, newP, 0xC);
	PointerMapper::AddMapping(oldP, newP);
	return 0;
}

PointerMapper avoid ares clear mapping.

ststl-s avatar Jul 13 '22 07:07 ststl-s

JumpjetTurn=no makes attached units move at random and attached units can create an invincibility cheat by being fired at by the unit they are attached to. Respectively: image image Units attached to a Subterranean unit are still visible underground. image

4SGX avatar Jul 26 '22 11:07 4SGX

TODO:

  • Unbreak the drawing relative to parent's origin, currently a mess (check out earlier commits if you work on sth)
  • Draw order specification relative to parent
  • Handle movement command issued with command inheritance enabled (i.e. optionally reset targets like vanilla units do). possibly just reset the mission when movement command is given and recursed into children instead of doing nothing for that command
  • If you have command inheritance, order to attack something (all children with inheritance will also get an order to attack), the waypoints will merge, and when you place a next waypoint to move - the child technos will try to execute that waypointed movement order constantly and ignore all subsequent waypoints. this needs to be handled somehow, either by skipping the movement if such occurs or by not merging the waypoints somehow
  • Sync locomotor attacked status (not selectable, does not attack etc)
  • Sync subterranean stuff (not being able to fire, not drawn, detach all etc)
  • Possibly sync more loco stuff

Metadorius avatar Sep 30 '22 21:09 Metadorius

Right now, the child won't have any lag, great job!

NetsuNegi avatar Oct 22 '22 14:10 NetsuNegi

image

Metadorius avatar Oct 22 '22 16:10 Metadorius

TODO based on today's testing

  • fix improper handling of TunnelLoco, it currently occupies tunnelling sequence start cell and crashes the game when the unit is destroyed
  • physical position of a techno lags 1 frame behind, might be due to an order of draw/real stuff
  • make attached units lose target on moving like turrets
  • make AddSelectable work with real location as well, currently bugged

Metadorius avatar Oct 22 '22 20:10 Metadorius

selectables are fixed new TODO: for some reason getting a crash when releasing a locomotor in Approach_Target (attack mission)

Metadorius avatar Oct 23 '22 13:10 Metadorius

More test are always welcome btw.

Metadorius avatar Oct 23 '22 14:10 Metadorius

Pathfinding freeze still happens by the way. 2022-10-23 22 04 23

brsajo avatar Oct 23 '22 14:10 brsajo

image This will be called when techno cloaked.

ststl-s avatar Oct 24 '22 05:10 ststl-s

I don't know if it happens with other types of vehicles, but attaching a jumpjet to a ground vehicle and moving the parent makes the attachment invulnerable.

I wanted to check if it's possible to make a unit like the Colossus from SC2 (something that can be attacked by both anti-ground and anti-air) so i attached a jumpjet to a ground vehicle, then made ground anti-air attack the attachment. It all worked fine as long as the parent stayed immobile, but once i moved the parent outside of their range and they started to chase to be able to fire, their projectiles stopped dealing any damage to the attachment. At that point it didn't matter if the parent was immobile or moving, the attachment wasn't taking any damage from their attacks anymore.

mevitar avatar Oct 26 '22 20:10 mevitar

Oh that actually explains a bug Dmitry Volkov has shown me once and I couldn't reproduce. That means that I didn't handle jumpjet loco properly too (yet). Thanks for the report!

Metadorius avatar Oct 26 '22 20:10 Metadorius