Advertisement
Tkap1

Untitled

Oct 2nd, 2022
989
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.04 KB | None | 0 0
  1. // vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv     CHAIN LIGHTNING START       vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  2. {
  3.     m_timed_block("Chain lightning");
  4.     auto chain_lightnings = &game->chain_lightnings;
  5.     for(int i = 0; i < chain_lightnings->count; i++)
  6.     {
  7.         s_chain_lightning* cl = arr_get(chain_lightnings, i);
  8.         assert(cl->times_chained < cl->max_chains);
  9.  
  10.         b8 remove = false;
  11.  
  12.         int target = get_closest_non_hit_enemy(enemies, cells, cl->pos.xy, cl->already_hit.elements, cl->already_hit.count, cl->chain_range, frame_arena);
  13.         if(target == invalid_entity)
  14.         {
  15.             remove = true;
  16.         }
  17.         else
  18.         {
  19.             assert(enemies->active[target]);
  20.             assert(enemies->flags[target][e_entity_flag_hittable]);
  21.  
  22. #if IS_CLIENT
  23.             take_damage(game, enemies, map, target, cl->damage, cl->armor_pen, cl->source, cl->push_dir, network, false, cl->crit_count, game->towers.kill_count);
  24.  
  25.             s_visual_effect ve = zero;
  26.             ve.type = e_visual_effect_lightning;
  27.             ve.duration = 0.25f;
  28.  
  29.             ve.from = enemies->pos[target] + rand_v3(&game->client_rng) * 0.1f + v3(0, 0, enemies->size[target].z * 0.6f);
  30.             ve.to = cl->pos + rand_v3(&game->client_rng) * 0.1f + v3(0, 0, enemies->size[target].z * 0.6f);
  31.  
  32.             ve.color = BLUE;
  33.  
  34.             add_visual_effect(&game->transient.visual_effects, &ve);
  35.  
  36. #else // IS_CLIENT
  37.             take_damage(game, enemies, map, target, cl->damage, cl->armor_pen, cl->source, cl->push_dir, frame_arena, network, false, cl->crit_count, game->towers.kill_count);
  38. #endif // NOT IS_CLIENT
  39.  
  40.             arr_add(&cl->already_hit, s_enemy_ref(enemies, target));
  41.             // @Note(tkap, 15/06/2022): This means there is a cap of 64 chains on chain lightning
  42.             if(cl->already_hit.count >= cl->already_hit.max_elements)
  43.             {
  44.                 remove = true;
  45.             }
  46.  
  47.             cl->pos = enemies->pos[target];
  48.             cl->times_chained += 1;
  49.  
  50.         }
  51.  
  52.         if(cl->times_chained >= cl->max_chains)
  53.         {
  54.             remove = true;
  55.         }
  56.  
  57.         if(remove)
  58.         {
  59.             arr_remove_and_swap(chain_lightnings, i);
  60.             i -= 1;
  61.         }
  62.     }
  63. }
  64. // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^     CHAIN LIGHTNING END     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement