You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- PR #340 put the correct check in the wrong place to prevent detachment when a cell is attacking another cell.
This fixes that by first moving the check into the spring attachments function as an attack produces a spring attachment.
Second, it moves the check into the detachment block rather than the attachment block.
- also, fix bug iterating over the attached cells.
when detaching cells, the for loop would skip checking the last cell in the list if any cells were detached.
So, instead iterate backwards through the list of attached cells.
if (phenotype.cell_interactions.pAttackTarget==pTest || pTest->phenotype.cell_interactions.pAttackTarget==pCell) // do not let attackers detach randomly
for( int j=0; j < pCell->state.spring_attachments.size(); j++ )
1469
+
// detach_cells_as_spring swaps the detached cell with the last cell in the vector, so we need to iterate backwards
1470
+
for( int j=pCell->state.spring_attachments.size()-1; j >= 0; j-- )
1471
1471
{
1472
-
Cell* pTest = pCell->state.spring_attachments[j];
1472
+
Cell* pTest = pCell->state.spring_attachments[j];
1473
+
if (phenotype.cell_interactions.pAttackTarget==pTest || pTest->phenotype.cell_interactions.pAttackTarget==pCell) // do not let attackers detach randomly
0 commit comments