Skip to content

persist attack through attacker transformation - #341

Open
drbergman wants to merge 2 commits into
MathCancer:developmentfrom
drbergman:fix-stop-attack-on-transform
Open

persist attack through attacker transformation#341
drbergman wants to merge 2 commits into
MathCancer:developmentfrom
drbergman:fix-stop-attack-on-transform

Conversation

@drbergman

@drbergman drbergman commented Dec 2, 2024

Copy link
Copy Markdown
Collaborator

Rebased onto current development and inverted relative to this PR's original direction: transformation now keeps an in-progress attack running instead of ending it.

Background

  • pAttackTarget lives in phenotype.cell_interactions, so phenotype = cd.phenotype in convert_to_cell_definition drops it.
  • The other two halves of the attack link — the target's state.attacked_by and the shared spring — live in state, which transformation leaves alone.

Since #422 landed the symmetric attack link, convert_to_cell_definition resolved that mismatch by calling remove_self_from_attacked() to end the attack. This PR resolves it the other way: hold pAttackTarget across the assignment and put it back. All three parts of the link then stay consistent, and the spring is never touched.

This also makes transformation symmetric — attacks against a transforming cell already persisted, while attacks by it were ended.

total_damage_delivered is carried across too (second commit). It also lives in phenotype.cell_interactions, so transformation was resetting the attacker's lifetime damage tally to zero — visibly wrong now that the attack it was counting keeps running afterwards.

Verification

Built and ran interaction-sample with CD8+ T cell -> neutrophil transformation enabled and a 30 min attack duration. At each transformation of an attacking cell, all three parts of the link survive:

TRANSFORM_WITH_ATTACK now=24 newtype=neutrophil target=bacteria \
  pAttackTarget_kept=1 target_lists_me=1 spring_mine=1 spring_theirs=1

interactions and rules_sample are the only sample configs with both nonzero attack and transformation rates, and neither is SVG-diff-checked in CI, so no snapshot changes are expected.

Known gap

The same run shows the case worth flagging:

newtype=neutrophil attack_rate_vs_target=0 attack_damage_rate=1 attack_duration=0.1

The transformed cell keeps attacking a cell type its new definition has a zero attack rate against — an attack it could never have started — and with unset attack parameters the defaults (attack_damage_rate = 1.0, attack_duration = 30 min) let that run on.

Handled separately in #432, which warns about exactly this case without changing the simulation.

@drbergman

drbergman commented Dec 2, 2024

Copy link
Copy Markdown
Collaborator Author

Here's an example demonstrating the need. The attacker (grey cell) attacks the defender (red cell). The attacker transforms into an exhausted cell (yellow cell). Meanwhile, the defender is chemotaxing to the left and the spring attachment between the two persists even after the attack has ceased. I have also included the config and cells.csv to recreate from the template project.

https://github.com/user-attachments/assets/1ca37563-35df-4959-8374-b652a27bf8b4
PhysiCell_settings.txt
cells.csv

@heberlr heberlr mentioned this pull request Dec 5, 2024
@MathCancer
MathCancer deleted the branch MathCancer:development December 13, 2024 23:02
@MathCancer MathCancer closed this Dec 13, 2024
@heberlr heberlr reopened this Dec 20, 2024
@drbergman
drbergman marked this pull request as ready for review April 4, 2025 15:06
@drbergman
drbergman requested a review from Copilot April 4, 2025 15:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

core/PhysiCell_cell.cpp:1134

  • [nitpick] Consider using 'nullptr' instead of 'NULL' to align with modern C++ practices.
if ( phenotype.cell_interactions.pAttackTarget != NULL )

@drbergman drbergman self-assigned this May 22, 2025
@drbergman

Copy link
Copy Markdown
Collaborator Author

Came across this again and adding some more concrete code details.

  1. Attack target is part of the attacking cell's phenotype. See here
  2. On transformation, only a subset of phenotype fields are protected from conversion. See here
  3. This does not include phenotype.cell_interactions (again, this is where the pTarget info is stored)

Thus, the copied Cell_Definition& cd phenotype with a NULL pTarget erases our transformed cell's pTarget, but the this.state is unchanged, and this is where spring_attachments is located.

@drbergman

Copy link
Copy Markdown
Collaborator Author

Can we make attack a conserved vs not property?

@drbergman

Copy link
Copy Markdown
Collaborator Author

Need a new PR where the attack persists through transformation.

Invert the decision made earlier on this branch. Transformation now leaves an
in-progress attack running instead of ending it.

`pAttackTarget` lives in `phenotype.cell_interactions`, so `phenotype = cd.phenotype`
would drop it; hold it across the assignment and put it back. The other two halves of
the attack link -- the target's `attacked_by` and the shared spring -- live in `state`,
which transformation already leaves alone, so restoring `pAttackTarget` keeps all three
consistent without touching the spring.

This also makes transformation symmetric: attacks *against* a transforming cell already
persisted, while attacks *by* it were ended.
@drbergman
drbergman force-pushed the fix-stop-attack-on-transform branch from 92edcf9 to cc6b4ae Compare August 16, 2026 12:44
@drbergman drbergman changed the title detach attacker on transformation persist attack through attacker transformation Aug 16, 2026
It lives in phenotype.cell_interactions too, so the transformation reset the
attacker's lifetime damage tally to zero -- now visibly wrong when the attack
it was counting is still running afterwards.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants