+ struct fish *fish = &world.fishes[i];
+ struct cell *cell_current = pcell( fish->pos );
+
+ if( fish->alive == -1 )
+ fish->alive = 0;
+
+ if( fish->alive != 1 )
+ continue;
+
+ // Apply to output
+ if( cell_current->state & FLAG_OUTPUT )
+ {
+ for( int j = 0; j < arrlen( world.io ); j ++ )
+ {
+ struct cell_terminal *term = &world.io[j];
+
+ if( term->id == fish->pos[1]*world.w + fish->pos[0] )
+ {
+ term->recv[ term->recv_count ++ ] = fish->payload;
+ break;
+ }
+ }
+
+ fish->alive = 0;
+ continue;
+ }
+
+ if( cell_current->config == k_cell_type_split )
+ {
+ // Flip flop L/R
+ fish->dir[0] = cell_current->state&FLAG_FLIP_FLOP?1:-1;
+ fish->dir[1] = 0;
+
+ cell_current->state ^= FLAG_FLIP_FLOP;
+ }
+ else if( cell_current->config == k_cell_type_merge )
+ {
+ // Can only move up
+ fish->dir[0] = 0;
+ fish->dir[1] = -1;
+ }
+ else
+ {
+ struct cell *cell_next = pcell( (v2i){ fish->pos[0]+fish->dir[0], fish->pos[1]+fish->dir[1] } );
+ if( !(cell_next->state & (FLAG_CANAL|FLAG_OUTPUT)) )
+ {
+ // Try other directions for valid, so down, left, right..
+ v2i dirs[] = {{1,0},{-1,0},{0,-1}};
+ vg_info( "Trying some other directions...\n" );
+
+ for( int j = 0; j < vg_list_size(dirs); j ++ )
+ {
+ if( (dirs[j][0] == -fish->dir[0]) && (dirs[j][1] == -fish->dir[1]) )
+ continue;
+
+ if( pcell( (v2i){ fish->pos[0]+dirs[j][0], fish->pos[1]+dirs[j][1] } )->state & (FLAG_CANAL|FLAG_OUTPUT) )
+ {
+ fish->dir[0] = dirs[j][0];
+ fish->dir[1] = dirs[j][1];
+ }
+ }
+ }
+ }
+
+ fish->pos[0] += fish->dir[0];
+ fish->pos[1] += fish->dir[1];
+
+ struct cell *cell_entry = pcell( fish->pos );
+
+ if( !(cell_entry->state & (FLAG_INPUT|FLAG_CANAL|FLAG_OUTPUT) ))
+ fish->alive = 0;
+ else
+ {
+ if( fish->dir[0] )
+ {
+ if( cell_entry->config == k_cell_type_split ||
+ cell_entry->config == k_cell_type_ramp_right ||
+ cell_entry->config == k_cell_type_ramp_left )
+ {
+ // Special death (FALL)
+ v2_sub( fish->physics_co, fish->physics_v, fish->physics_v );
+ v2_divs( fish->physics_v, vg_time_delta, fish->physics_v );
+
+ fish->alive = -2;
+ vg_warn( "Special death (fall)\n" );
+ continue;
+ }
+ }
+
+ if( cell_entry->config == k_cell_type_split )
+ {
+ sfx_set_playrnd( &audio_splitter, &audio_system_balls_important, 0, 1 );
+ cell_entry->state |= FLAG_FLIP_ROTATING;
+ }
+ }